How to make a selection rectangle with draggable handles

Hi,
I'm trying to write a program to visualize large trees in java. The idea is to have a thumbnail view of the tree with a movable selection rectangle that can be used to focus on certain parts of the tree. Parts inside the rectangle will be displayed in greater detail in another view.
I was wondering if there are any libraries available for making this kind of selection rectangle in Java2D (it'd also be nice to have 8 handles for changing the size of the rectangle) or if anyone has any implementation ideas. I'd appreciate any help. Thanks!
Wayne

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
public class DragLens extends JPanel
    Lens lens;
    public DragLens()
        lens = new Lens(this);
    protected void paintComponent(Graphics g)
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        lens.draw(g2);
    public static void main(String[] args)
        DragLens dragLens = new DragLens();
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(dragLens);
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
class Lens extends MouseInputAdapter
    DragLens dragLens;
    Point2D.Double[] centers;
    Rectangle2D hunter;
    int selectedIndex;
    Point2D.Double offset;
    boolean dragging;
    final int S = 10;
    public Lens(DragLens dl)
        dragLens = dl;
        dragLens.addMouseListener(this);
        dragLens.addMouseMotionListener(this);
        initPoints();
        hunter = new Rectangle2D.Double(0,0,S,S);
        offset = new Point2D.Double();
        dragging = false;
    public void draw(Graphics2D g2)
        // draw rects
        g2.setPaint(Color.blue);
        for(int j = 0; j < centers.length; j++)
            g2.draw(new Rectangle2D.Double(centers[j].x-S/2, centers[j].y-S/2, S, S));
        // draw lines
        g2.setPaint(Color.red);
        g2.draw(new Line2D.Double(centers[0].x+S/2, centers[0].y+S/2,  // west
                                  centers[1].x+S/2, centers[1].y-S/2));
        g2.draw(new Line2D.Double(centers[1].x+S/2, centers[1].y-S/2,  // south
                                  centers[2].x-S/2, centers[2].y-S/2));
        g2.draw(new Line2D.Double(centers[2].x-S/2, centers[2].y-S/2,  // east
                                  centers[3].x-S/2, centers[3].y+S/2));
        g2.draw(new Line2D.Double(centers[3].x-S/2, centers[3].y+S/2,  // north
                                  centers[0].x+S/2, centers[0].y+S/2));
    public void mousePressed(MouseEvent e)
        Point p = e.getPoint();
        hunter.setFrameFromCenter(p.x, p.y, p.x+S/2, p.y+S/2);
        for(int j = 0; j < centers.length; j++)
            if(hunter.contains(centers[j]))
                offset.x = p.x - centers[j].x;
                offset.y = p.y - centers[j].y;
                selectedIndex = j;
                dragging = true;
                break;
    public void mouseReleased(MouseEvent e)
        dragging = false;
    public void mouseDragged(MouseEvent e)
        if(dragging)
            double x = e.getX() - offset.x;
            double y = e.getY() - offset.y;
            translate(x, y);
            dragLens.repaint();
    private void translate(double x, double y)
        switch(selectedIndex)
            case 0:
                centers[3].y = y;
                centers[1].x = x;
                break;
            case 1:
                centers[0].x = x;
                centers[2].y = y;
                break;
            case 2:
                centers[1].y = y;
                centers[3].x = x;
                break;
            case 3:
                centers[2].x = x;
                centers[0].y = y;
        centers[selectedIndex].x = x;
        centers[selectedIndex].y = y;
    private void initPoints()
        int[] x = { 0, 0, 1, 1 };
        int[] y = { 0, 1, 1, 0 };
        centers = new Point2D.Double[x.length];
        for(int j = 0; j < centers.length; j++)
            centers[j] = new Point2D.Double(x[j], y[j]);
        AffineTransform at = AffineTransform.getScaleInstance(80,40);
        at.translate(1,2);
        at.transform(centers, 0, centers, 0, 4);
}

Similar Messages

  • How to make dynamic select list with time interval of 15 minutes

    Dear all,
    I've a question. I need a select list that contains time with intervals of 15 minutes from 08:00 till 16:00.
    example 8:00
    8:15
    8:30
    8:45
    9:00
    9:15
    and so on till 16:00
    The values or stored in a varchar column.
    Can someone please help me with this one?
    Best regards,
    Caroline

    I think the easiest way would be to create a table "INTERVALS" with one row and column "INT_PERIOD"? per 15 minute period description
    8:00
    8:15
    16:00
    Then create your select list item based on a Dynamic List, or Query as
    SELECT int_period d, int_period r
    FROM INTERVALS
    ORDER BY INT_PERIODYou could write something to load the table, but that might take about as long to just edit in the values.
    Making it a Dynamic LOV, you then have it available anywhere else you might need it.
    Edited by: Bob37 on May 4, 2012 8:57 AM

  • How to make a selection of a layer delete content and paste another content with Photoshop scripting..?

    how to make a selection of a layer delete content and paste another content with Photoshop scripting..?

    There is a more specific Forum …
    Photoshop Scripting

  • How to make it selected when clicked and open popup

    Hi,
    I 've a form in the parent page with many form elements.
    I've 2 radio buttons with values "Yes" and "No". I am opening a modal popup when clicked on "Yes" radio button. The modal popup is opening fine.
    But when I click "Yes", it' s not selected. After modal popup is closed, when I return to parent page, the option "Yes" is still not selected.
    How to make it selected when clicked and open popup?

    Perhaps try moving the application to your preferred desktop and then right-click it's dock icon > options > Assign to This Desktop.

  • How to make software select on UI

    May I know how to make software select. just click down the mouse and drag, then there will be a dot line square. After release the mouse,
    the things selected will change color to red.
    When move mouse over one object on UI, the mouse icon with change to the one with 4 arrow to 4 direction. If click down, the object will change to red color, other red
    color object will back to normal color.
    Any suggestion, thanks.

    As the attached vi, when in runtime, the selected 4 object need to change color. Or the click one need to change color. Thanks.
    Attachments:
    ss.JPG ‏67 KB

  • How to make SAP B1 connection with Windows Sharepoint Service 3.0

    how to make SAP B1 connection with Windows Sharepoint Service 3.0 through asp.net web part code.. I get the security error when i run that web part......
    public bool ConnectToCompany()
                oCompany = new SAPbobsCOM.Company();
                oCompany.Server = "192.168.1.58";
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005;
                oCompany.CompanyDB = "SBODemoUS";
                oCompany.DbUserName = "sa";
                oCompany.DbPassword = "abc";
                //oCompany.UseTrusted = true;
                oCompany.UserName = "manager";
                oCompany.Password = "manager";
                oCompany.language = SAPbobsCOM.BoSuppLangs.ln_English;
                oCompany.LicenseServer = "192.168.1.58:30000";
                int i = oCompany.Connect();
                if (i != 0)
                    return false;
                return true;
    protected override void RenderContents(HtmlTextWriter writer)
                if (conn.ConnectToCompany() == true)
                    writer.Write("Hello" + this.Context.User.Identity.Name);
    Edited by: bikalg on Nov 28, 2010 9:43 AM

    Hi.......
    Welcome to SAP Business One Forum.....
    Unfortunately this is the wrong forum you posted here.
    I would suggest you post it in SDK or System Administration Forum and definitely you get the solution and close this thread from here......
    Regards,
    Rahul

  • How to make a PDF form with expanding tabel or expanding fields, like in Word.

    How to make a PDF form with expanding tabel or expanding fields, like in Word.

    This is currently not possible in Formscentral. It is something we are working on for the future. Please stay tuned.
    Andrew Yarborough

  • Is their any tutorials on how to make a navigation bar with drop downs in Dreamweaver CC now ?

    Is their any tutorials on how to make a navigation bar with drop downs in Dreamweaver CC now that they do not have the spry option?

    bbull2005 wrote:
    Preran, why wouldn't Dreamweaver include it's own menu/navigation bar widget?
    I can't answer on Preran's or Adobe's behalf, but I think you'll find at least part of the answer here: http://wiki.jqueryui.com/w/page/38666403/Menubar
    Adobe decided to discontinue development of Spry in August last year, and Dreamweaver CC made the switch to using jQuery UI widgets and effects. One reason for dropping Spry was that it failed to work correctly in some browsers. Judging from the fact that the jQuery UI menubar is now "on ice", creating a flyout menu that works reliably across all devices is proving more difficult than originally envisaged.
    Because all other widgets in Dreamweaver CC use jQuery UI, it's a reasonable assumption that Adobe hoped the jQuery UI menubar would be ready in time, but it wasn't.

  • How to make row selection by checkbox in ADF table

    hello,
    using jdev11g TP4 , fusion web application
    when i drag my view object as ADF table into jsf page,
    i want to know how to make row selection by checkbox
    thanks
    greenApple
    Edited by: greenApple on Nov 10, 2008 11:33 AM

    Hi,
    the tree component has changed compared to 10.1.3. You no longer have a tableSelectmany component that renders as checkboxes. Instead you use the ctrl key and select the table rows
    Frank

  • How to display the selection screen with icons as well as with text element

    How to display the selection screen with icons as well as with texts (written in text elements) for PlantDate, OrderType,WareHouse..

    Report zex33.
    type-pools: icon.
    selection-screen begin of line.
    selection-screen comment 1(20) text_001.
    parameters: p_werks type marc-werks.
    selection-screen end of line.
    selection-screen begin of line.
    selection-screen comment 1(20) text_002.
    parameters: p_whouse(10).
    selection-screen end of line.
    selection-screen begin of line.
    selection-screen comment 1(20) text_003.
    parameters: p_auart like vbak-auart.
    selection-screen end of line.
    initialization.
      write ICON_PLANT  as icon to text_001.
    concatenate text_001 text-001 into text_001 separated by space.
      write ICON_WAREHOUSE  as icon to text_002.
    concatenate text_002 text-002 into text_002 separated by space.
      write ICON_ORDER  as icon to text_003.
    concatenate text_003 text-003 into text_003 separated by space.

  • How to make a SELECT LIST READONLY

    Hi,
    I have a form to update the existing values in a table. Primary column is based on a Select List.
    So when user goto update screen they SHOULD NOT BE ABLE TO CHANGE the primary filed(means the value display in the Select List).
    SO to make this one I have make that select list read only. But not like other items even when we make select list read only it still allow user to change the value. So basically read only property not working for select text.
    There are many post in this regading same issue. Some of them recomended to make it disabled. But when we make a item disabled then when user POST that form, Apex not POST any disabled item values. Basically disabled items values not passing next form. So making item dissable also not a solution.
    I have read almost 20 post in here regarrding this and didnt get any solution for this. So please let me know if anyone knows how to make a select list read only (which is working same as read only text boxes, means that value pass when user POST the form).
    Thanks in advance...
    mc

    You define a function(this is based aorund jQuery selectors) in the page header like
    <script>
      var makereadonly = function(selector, makeReadonly) {
          $(selector).filter("select").each(function(i){
              var select = $(this);
              //remove any existing readonly handler
              if(this.readonlyFn) select.unbind("change", this.readonlyFn);
              if(this.readonlyIndex) this.readonlyIndex = null;
              if(makeReadonly) {
                  this.readonlyIndex = this.selectedIndex;
                  $(this).css('background-color','#CDCDCD'); //Adds a background colour to readonly item
                  this.readonlyFn = function(){
                      this.selectedIndex = this.readonlyIndex;
                  select.bind("change", this.readonlyFn);
          //For input items
          $(selector).filter("input,textarea").attr('readOnly','readOnly');
          $(selector).filter("input,textarea").css('background-color','#CDCDCD');
    </script>and apply it using a jQuery selector (call it in the "execute on page load" or any other JS code)
      makereadonly('#ITEMNAME1,#ITEMNAME2,#ITEMNAME3',true);Not that all of these methods(that act at the client side) will only prevent the user from modifying it 'normally', they could manipulate these readonly items using Javascript(or using firebug or any tool like that). So its better to make sure that your don't use the item value(from the page) for processing.

  • How can i creat several rectangles with one draw rect.vi

    how can i creat several rectangles with one draw rect.vi? thanks
    Solved!
    Go to Solution.

    You can call it in a for loop, with an array of the rectangle coordinates you want to draw. Is this what you mean?
    CLA, LabVIEW Versions 2010-2013
    Attachments:
    rectangle.png ‏11 KB

  • How to make the wifi connection with Ipad in china since it requires user's name and password.

    How to make the wifi connection with Ipad in china since it requires user's name and password just like the dialed-up?

    The same way you would connect to a secure wifi network in any other country. Supply the username and password when prompted.

  • How to make a select list editable or searchable like the combobox

    Does anybody know, How to make a select list editable or searchable like the combobox? Do we need a plugin here, where I can get it.

    Hi Nilesh,
    If this is what you are looking for http://apex.oracle.com/pls/apex/f?p=32395:3:1202144397644679
    get the combobox plug-in
    http://www.apex-plugin.com/oracle-apex-plugins/item-plugin/searchable-combobox.html
    I have not tried this though. Found it while searching for some other plug-ins.
    Regards,
    -Senthil

  • HT4642 ios numbers:how to make cell height variable with auto line brake setting ?

    ipad numbers; How to make cell height variable with auto line break setting?

    That's strange. I responded earlier and the whole message got trashed. Hence the test post before retyping the entire thing again.
    Thanks for the reply.
    The video clip is a single screen capture video clip. This is what I've found by playing around with this more.
    The original clip resolution is greater than 640x480. If I use QT Pro to convert the original clip to 640x480 and then use either Flip4Mac or PE7, then the resolution looks good.
    Just trying to figure out if should keep all workflow on the MacOS side. There are several different version of Flip4Mac. $49 gives me 640x480, but if I ever want to make it slightly larger then I would need to go with the $99 or HD version.
    I also tried to export to AVI with QT Pro and the import with Windows MovieMaker but it didn't work really good. I liked the simplicity (since PE7 hogs a lot of resources especially through VMWare).

Maybe you are looking for

  • I updated IPOD and it deleted all of my music and apps, how do I get them back?

    I updated my IPod and and backed up the information to my computer, however,  after the update it set the IPod to original settings and I cannot find my apps nor my music.  HELP>

  • Really, really slow PDF creation

    A new development in the last couple days is that Acrobat PDF Printer and Distiller are starting to take a really long time to create PDF files. Basic system info: • Win 7 Home Premium • CS4 Design Premium (w/Acrobat 9 updated to 9.3.2) • Extensis Su

  • Report data download to excel file

    Hi experts,    My requirement is report data download to excel file and that file should be an attachment to send email to specified people. first i want to to download data to excel file and that file should be an attachment. Regards V.Venu

  • Turn on trace in ABAP Program

    Dear Gurus , Due to some reason ST05 is not supporting our cause and making us turning toward developing our own program where we trun the trace on,call the program - rsarfcex and turn off the trace and schedule the same as batch job . Appricate If y

  • AQ table for complex type creation

    I have a type containing nested tables, it looks like that: create or replace type aq_student_reg_queue_type as object ( XML_ID varchar2(16), trigger_name varchar2(32), tm_transaction_id varchar2(30), tm_transaction_type varchar2(30), person aq_perso