Example usage for java.awt Point setLocation

List of usage examples for java.awt Point setLocation

Introduction

In this page you can find the example usage for java.awt Point setLocation.

Prototype

public void setLocation(double x, double y) 

Source Link

Document

Sets the location of this point to the specified double coordinates.

Usage

From source file:uk.ac.babraham.BamQC.Graphs.ScatterGraph.java

public void showToolTip(int index, Point p) {
    if (GraphicsEnvironment.isHeadless()) {
        return;//from ww  w  .  j av a  2  s  .  c o m
    }
    p.setLocation(p.getX() + 10, p.getY() + 25);
    label.setText(tips.get(index));
    toolTip.pack();
    toolTip.setLocation(p);
    toolTip.setVisible(true);
}

From source file:edu.ku.brc.specify.plugins.imgproc.ImageProcessorPanel.java

/**
 * //www .  ja  v a  2 s  .  c  om
 */
protected void doProcLayout() {
    Dimension size = getSize();
    int margin = 20;

    Point p = new Point(margin, margin);
    for (int i = 0; i < 4; i++) {
        switch (i) {
        case 0:
            p.setLocation(margin, margin * 2);
            break;
        case 1:
            p.setLocation(size.width - PROC_ICON_SIZE - margin, margin * 2);
            break;
        case 2:
            p.setLocation(size.width - PROC_ICON_SIZE - margin, size.height - PROC_ICON_SIZE - margin);
            break;
        case 3:
            p.setLocation(margin, size.height - PROC_ICON_SIZE - margin);
            break;
        }
        add(procObjs.get(i));
        procObjs.get(i).setLocation(p);
        procObjs.get(i).setVisible(true);
    }
}

From source file:edmondskarp.Controller.EdmondsKarpController.java

public void openState(String s) throws JSONException {
    if (s == null || s.equals("")) {
        graph.clearGraph();//  w w w.  j a v a2s .  c  o m
        gui.getCircles().clear();
        name = 0;
        gui.update();
        return;
    }

    Map<String, Circle> circles = new HashMap<>();
    graph.clearGraph();

    int maxIndex = 0;
    JSONObject jNodeEdge = new JSONObject(s); // Parse the JSON to a JSONObject
    JSONArray jNodes = jNodeEdge.getJSONArray("Node");
    JSONArray jEdges = jNodeEdge.getJSONArray("Edge");

    for (int i = 0; i < jNodes.length(); i++) { // Loop over each each row of node
        Circle circle = new Circle();
        Point point = new Point();

        JSONObject jNode = jNodes.getJSONObject(i);

        point.setLocation(jNode.getInt("PosX"), jNode.getInt("PosY"));
        circle.setFirstPoint(point);
        circle.addNode(graph.addNode("" + jNode.getString("ID")));

        circles.put(jNode.getString("ID"), circle);
        if (jNode.getInt("ID") > maxIndex) {
            maxIndex = jNode.getInt("ID");
        }
    }

    name = ++maxIndex;

    for (int i = 0; i < jEdges.length(); i++) { // Loop over each each row of edge
        JSONObject jEdge = jEdges.getJSONObject(i);
        Edge e = graph.connect(jEdge.getString("From"), jEdge.getString("To"), jEdge.getInt("Capacity"), 0);
        if (e == null) {
            graph.checkInverseArrowConnection(jEdge.getString("From"), jEdge.getString("To"),
                    jEdge.getInt("Capacity"));
        } else {
            Arrow arrow = new Arrow(circles.get(jEdge.getString("From")), circles.get(jEdge.getString("To")));
            arrow.setEdge(e);
            circles.get(jEdge.getString("From")).addArrowFrom(arrow);
            circles.get(jEdge.getString("To")).addArrowTo(arrow);
        }

    }

    if (!jNodeEdge.getString("Source").equals("")) {
        graph.setSource(graph.getNode(jNodeEdge.getString("Source")));
    }
    if (!jNodeEdge.getString("Sink").equals("")) {
        graph.setSink(graph.getNode(jNodeEdge.getString("Sink")));
    }

    gui.setCircles(new ArrayList(circles.values()));
    gui.update();
    System.gc();
}

From source file:net.chaosserver.timelord.swingui.Timelord.java

/**
 * Gets back the point location where the frame was last saved.
 *
 * @return location where the frame was last saved
 *///from  www.  ja  v a 2 s .com
protected Point loadLastFrameLocation() {
    Preferences preferences = Preferences.userNodeForPackage(this.getClass());

    Point windowLocation = new Point();
    windowLocation.setLocation(preferences.getDouble(FRAME_X_LOCATION, 0),
            preferences.getDouble(FRAME_Y_LOCATION, 0));

    return windowLocation;
}

From source file:org.nuclos.client.ui.resplan.header.JHeaderGrid.java

@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;

    super.paintComponent(g2d);

    g2d.setPaint(gridColor);/*from   w  ww . j ava2 s. c o  m*/

    Rectangle clipBounds = g.getClipBounds();

    int[] indices = stripRangeForRect(clipBounds);
    int startIndex = indices[0];
    int endIndex = indices[1];

    Point p1, p2;
    p1 = new Point();
    p2 = new Point(getWidth(), getHeight());
    for (int i = startIndex; i <= endIndex; i++) {
        int gridLine = getGridLine(i);
        orientation.updateCoord(p1, gridLine);
        orientation.updateCoord(p2, gridLine);
        g2d.drawLine(p1.x, p1.y, p2.x, p2.y);
    }

    p1.setLocation(0, 0);
    p2.setLocation(getWidth(), getHeight());
    int groupGridLine = 0;
    for (CategoryView v : groupings) {
        groupGridLine += v.size;
        orientation.opposite().updateCoord(p1, groupGridLine);
        orientation.opposite().updateCoord(p2, groupGridLine);
        g2d.drawLine(p1.x, p1.y, p2.x, p2.y);
        groupGridLine += GRID_SIZE;
    }

    for (int level = 0, levelCount = groupings.length; level < levelCount; level++) {
        for (HeaderCell cell : groupings[level].cells) {
            if (cell.endIndex < startIndex || cell.startIndex >= endIndex)
                continue;
            Rectangle rect = getRect(level, cell.startIndex, cell.endIndex);
            if (clipBounds != null && !clipBounds.intersects(rect))
                continue;
            paintHeaderCell(g2d, rect, cell.levelValue);
        }
    }

    if (cellResizingRange != null) {
        Rectangle rect = new Rectangle(getWidth(), getHeight());
        orientation.updateRange(rect, cellResizingRange);
        rect.grow(orientation.select(GRID_SIZE, 0), orientation.select(0, GRID_SIZE));
        g2d.setColor(new Color(0x9999ff, false));
        g2d.draw(rect);
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f));
        g2d.fill(rect);
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java

/**
 * Creates all the UI form the Form. /*from w ww  .  jav a 2  s .  c  o  m*/
 */
protected void buildUI() {
    headers.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems());
    Collections.sort(headers);

    MouseAdapter clickable = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            selectControl(e.getSource());
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            selectedInputPanel = getInputPanel(e.getSource());
            controlPropsBtn.setEnabled(true);

            if (controlPropsDlg != null) {
                controlPropsDlg.setControl(selectedInputPanel);
            }

            if (e.getClickCount() == 2 && (controlPropsDlg == null || !controlPropsDlg.isVisible())) {
                UsageTracker.incrUsageCount("WB.FormPropsTool");
                showControlProps();
            }

        }
    };

    Point topLeftPnt = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);

    final int LAYOUT_SPACING = 4;
    short maxY = 0;
    Vector<InputPanel> delayedLayout = new Vector<InputPanel>();
    int maxWidthOffset = 0;
    for (WorkbenchTemplateMappingItem wbtmi : headers) {
        // Create the InputPanel and make it draggable
        InputPanel panel = new InputPanel(wbtmi, wbtmi.getCaption(), createUIComp(wbtmi), this, clickable);

        Dimension size = panel.getPreferredSize();
        panel.setSize(size);
        panel.setPreferredSize(size);

        // Finds the largest label
        maxWidthOffset = Math.max(panel.getTextFieldOffset(), maxWidthOffset);

        int x = wbtmi.getXCoord();
        int y = wbtmi.getYCoord();
        if (y < topLeftPnt.y || (y == topLeftPnt.y && x < topLeftPnt.x)) {
            firstComp = panel.getComp();
            topLeftPnt.setLocation(x, y);
        }

        // Add it to the Form (drag canvas)
        uiComps.add(panel);
        add(panel);

        // NOTE: that the constructor sets the x,y storage from WorkbenchTemplateMappingItem object
        // so the ones with XCoord and YCoord set do not need to be positioned
        if (wbtmi.getXCoord() == null || wbtmi.getYCoord() == null || wbtmi.getXCoord() == -1
                || wbtmi.getYCoord() == -1) {
            delayedLayout.add(panel); // remember this for later once we know the Max Y

        } else {
            maxY = (short) Math.max(wbtmi.getYCoord() + size.height, maxY);
        }
    }

    // Now align the control by their text fields and skips the ones that have actual positions defined.
    // NOTE: We set the X,Y into the Mapping so that each item knows where it is, then if the user
    // drags and drop anything or save the template everyone knows where they are suppose to be
    // 
    int inx = 0;
    int maxX = 0;
    int y = maxY + LAYOUT_SPACING;
    for (InputPanel panel : uiComps) {
        WorkbenchTemplateMappingItem wbtmi = headers.get(inx);
        if (delayedLayout.contains(panel)) {
            int x = maxWidthOffset - panel.getTextFieldOffset();
            panel.setLocation(x, y);
            wbtmi.setXCoord((short) x);
            wbtmi.setYCoord((short) y);

            Dimension size = panel.getPreferredSize();
            y += size.height + LAYOUT_SPACING;

        }
        Rectangle r = panel.getBounds();
        maxX = Math.max(maxX, r.x + r.width);
        inx++;
    }

    initialSize = new Dimension(maxX, y);

    controlPropsBtn = createIconBtn("ControlEdit", IconManager.IconSize.NonStd, "WB_EDIT_CONTROL", false,
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    UsageTracker.getUsageCount("WBFormPropsTool");
                    showControlProps();
                }
            });

    addArrowTraversalKeys();
}

From source file:org.openscience.jmol.app.Jmol.java

Jmol(Splash splash, JFrame frame, Jmol parent, int startupWidth, int startupHeight, String commandOptions,
        Point loc) {/*from w  w w  .ja va 2 s. c  om*/
    super(true);
    this.frame = frame;
    this.startupWidth = startupWidth;
    this.startupHeight = startupHeight;
    numWindows++;

    try {
        say("history file is " + historyFile.getFile().getAbsolutePath());
    } catch (Exception e) {
    }

    frame.setTitle("Jmol");
    frame.getContentPane().setBackground(Color.lightGray);
    frame.getContentPane().setLayout(new BorderLayout());

    this.splash = splash;

    setBorder(BorderFactory.createEtchedBorder());
    setLayout(new BorderLayout());
    language = GT.getLanguage();

    status = (StatusBar) createStatusBar();
    say(GT._("Initializing 3D display..."));
    //
    display = new DisplayPanel(status, guimap, haveDisplay.booleanValue(), startupWidth, startupHeight);
    String adapter = System.getProperty("model");
    if (adapter == null || adapter.length() == 0)
        adapter = "smarter";
    if (adapter.equals("smarter")) {
        report("using Smarter Model Adapter");
        modelAdapter = new SmarterJmolAdapter();
    } else if (adapter.equals("cdk")) {
        report("the CDK Model Adapter is currently no longer supported. Check out http://bioclipse.net/. -- using Smarter");
        // modelAdapter = new CdkJmolAdapter(null);
        modelAdapter = new SmarterJmolAdapter();
    } else {
        report("unrecognized model adapter:" + adapter + " -- using Smarter");
        modelAdapter = new SmarterJmolAdapter();
    }
    appletContext = commandOptions;
    viewer = JmolViewer.allocateViewer(display, modelAdapter);
    viewer.setAppletContext("", null, null, commandOptions);

    if (display != null)
        display.setViewer(viewer);

    say(GT._("Initializing Preferences..."));
    preferencesDialog = new PreferencesDialog(frame, guimap, viewer);
    say(GT._("Initializing Recent Files..."));
    recentFiles = new RecentFilesDialog(frame);
    if (haveDisplay.booleanValue()) {
        say(GT._("Initializing Script Window..."));
        scriptWindow = new ScriptWindow(viewer, frame);
    }

    MyStatusListener myStatusListener;
    myStatusListener = new MyStatusListener();
    viewer.setJmolStatusListener(myStatusListener);

    say(GT._("Initializing Measurements..."));
    measurementTable = new MeasurementTable(viewer, frame);

    // Setup Plugin system
    // say(GT._("Loading plugins..."));
    // pluginManager = new CDKPluginManager(
    //     System.getProperty("user.home") + System.getProperty("file.separator")
    //     + ".jmol", new JmolEditBus(viewer)
    // );
    // pluginManager.loadPlugin("org.openscience.cdkplugin.dirbrowser.DirBrowserPlugin");
    // pluginManager.loadPlugin("org.openscience.cdkplugin.dirbrowser.DadmlBrowserPlugin");
    // pluginManager.loadPlugins(
    //     System.getProperty("user.home") + System.getProperty("file.separator")
    //     + ".jmol/plugins"
    // );
    // feature to allow for globally installed plugins
    // if (System.getProperty("plugin.dir") != null) {
    //     pluginManager.loadPlugins(System.getProperty("plugin.dir"));
    // }

    if (haveDisplay.booleanValue()) {

        // install the command table
        say(GT._("Building Command Hooks..."));
        commands = new Hashtable();
        if (display != null) {
            Action[] actions = getActions();
            for (int i = 0; i < actions.length; i++) {
                Action a = actions[i];
                commands.put(a.getValue(Action.NAME), a);
            }
        }

        menuItems = new Hashtable();
        say(GT._("Building Menubar..."));
        executeScriptAction = new ExecuteScriptAction();
        menubar = createMenubar();
        add("North", menubar);

        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add("North", createToolbar());

        JPanel ip = new JPanel();
        ip.setLayout(new BorderLayout());
        ip.add("Center", display);
        panel.add("Center", ip);
        add("Center", panel);
        add("South", status);

        say(GT._("Starting display..."));
        display.start();

        //say(GT._("Setting up File Choosers..."));

        /*      pcs.addPropertyChangeListener(chemFileProperty, exportAction);
         pcs.addPropertyChangeListener(chemFileProperty, povrayAction);
         pcs.addPropertyChangeListener(chemFileProperty, writeAction);
         pcs.addPropertyChangeListener(chemFileProperty, toWebAction);
         pcs.addPropertyChangeListener(chemFileProperty, printAction);
         pcs.addPropertyChangeListener(chemFileProperty,
         viewMeasurementTableAction);
         */

        if (menuFile != null) {
            menuStructure = viewer.getFileAsString(menuFile);
        }
        jmolpopup = JmolPopup.newJmolPopup(viewer, true, menuStructure, true);

    }

    // prevent new Jmol from covering old Jmol
    if (loc != null) {
        frame.setLocation(loc);
    } else if (parent != null) {
        Point location = parent.frame.getLocationOnScreen();
        int maxX = screenSize.width - 50;
        int maxY = screenSize.height - 50;

        location.x += 40;
        location.y += 40;
        if ((location.x > maxX) || (location.y > maxY)) {
            location.setLocation(0, 0);
        }
        frame.setLocation(location);
    }
    frame.getContentPane().add("Center", this);

    frame.addWindowListener(new Jmol.AppCloser());
    frame.pack();
    frame.setSize(startupWidth, startupHeight);
    ImageIcon jmolIcon = JmolResourceHandler.getIconX("icon");
    Image iconImage = jmolIcon.getImage();
    frame.setIconImage(iconImage);

    // Repositionning windows
    if (scriptWindow != null)
        historyFile.repositionWindow(SCRIPT_WINDOW_NAME, scriptWindow, 200, 100);

    say(GT._("Setting up Drag-and-Drop..."));
    FileDropper dropper = new FileDropper();
    final JFrame f = frame;
    dropper.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            //System.out.println("Drop triggered...");
            f.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            if (evt.getPropertyName().equals(FileDropper.FD_PROPERTY_FILENAME)) {
                final String filename = evt.getNewValue().toString();
                viewer.openFile(filename);
            } else if (evt.getPropertyName().equals(FileDropper.FD_PROPERTY_INLINE)) {
                final String inline = evt.getNewValue().toString();
                viewer.openStringInline(inline);
            }
            f.setCursor(Cursor.getDefaultCursor());
        }
    });

    this.setDropTarget(new DropTarget(this, dropper));
    this.setEnabled(true);

    say(GT._("Launching main frame..."));
}