Example usage for java.awt Point Point

List of usage examples for java.awt Point Point

Introduction

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

Prototype

public Point(int x, int y) 

Source Link

Document

Constructs and initializes a point at the specified (x,y) location in the coordinate space.

Usage

From source file:net.sf.mcf2pdf.mcfelements.util.ImageUtil.java

/**
 * Rotates the given buffered image by the given angle, and returns a newly
 * created image, containing the rotated image.
 *
 * @param img Image to rotate.//from   www  .  j a v  a  2s .c om
 * @param angle Angle, in radians, by which to rotate the image.
 * @param drawOffset Receives the offset which is required to draw the image,
 * relative to the original (0,0) corner, so that the center of the image is
 * still on the same position.
 *
 * @return A newly created image containing the rotated image.
 */
public static BufferedImage rotateImage(BufferedImage img, float angle, Point drawOffset) {
    int w = img.getWidth();
    int h = img.getHeight();

    AffineTransform tf = AffineTransform.getRotateInstance(angle, w / 2.0, h / 2.0);

    // get coordinates for all corners to determine real image size
    Point2D[] ptSrc = new Point2D[4];
    ptSrc[0] = new Point(0, 0);
    ptSrc[1] = new Point(w, 0);
    ptSrc[2] = new Point(w, h);
    ptSrc[3] = new Point(0, h);

    Point2D[] ptTgt = new Point2D[4];
    tf.transform(ptSrc, 0, ptTgt, 0, ptSrc.length);

    Rectangle rc = new Rectangle(0, 0, w, h);

    for (Point2D p : ptTgt) {
        if (p.getX() < rc.x) {
            rc.width += rc.x - p.getX();
            rc.x = (int) p.getX();
        }
        if (p.getY() < rc.y) {
            rc.height += rc.y - p.getY();
            rc.y = (int) p.getY();
        }
        if (p.getX() > rc.x + rc.width)
            rc.width = (int) (p.getX() - rc.x);
        if (p.getY() > rc.y + rc.height)
            rc.height = (int) (p.getY() - rc.y);
    }

    BufferedImage imgTgt = new BufferedImage(rc.width, rc.height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = imgTgt.createGraphics();

    // create a NEW rotation transformation around new center
    tf = AffineTransform.getRotateInstance(angle, rc.getWidth() / 2, rc.getHeight() / 2);
    g2d.setTransform(tf);
    g2d.drawImage(img, -rc.x, -rc.y, null);
    g2d.dispose();

    drawOffset.x += rc.x;
    drawOffset.y += rc.y;

    return imgTgt;
}

From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java

public InteractiveColumnsResults generateInteractiveColumn(Dataset dataset, int[] selection) {

    interactiveColumnImg = null;//from  ww  w. ja  v a 2  s.c om
    interactiveColumnImg = new BufferedImage(squareW + squareW, (sideTree.getHeight()),
            BufferedImage.TYPE_INT_ARGB);

    BufferedImage navgBackGroungImg = new BufferedImage(400, 10, BufferedImage.TYPE_INT_ARGB);
    Graphics navGr = navgBackGroungImg.getGraphics();
    int navUnit = (dataset.getDataLength() / 200) + 1;

    Graphics g = interactiveColumnImg.getGraphics();
    g.setFont(getTableFont(5));
    drawTable(g, new Point(0, 0), dataset, selection, navGr, navUnit);
    navgBackGroungImg = rotateImage(navgBackGroungImg, 180);
    navgStringImg = this.generateEncodedImg(navgBackGroungImg);
    InteractiveColumnsResults results = new InteractiveColumnsResults();
    results.setInteractiveColumn(splitImage(interactiveColumnImg));
    results.setNavgUrl(navgStringImg);
    return results;
}

From source file:com.sshtools.common.ui.SshToolsApplicationFrame.java

/**
 *
 *
 * @param application/* w  ww . j  a  v a2 s  .  c  o m*/
 * @param panel
 *
 * @throws SshToolsApplicationException
 */
public void init(final SshToolsApplication application, SshToolsApplicationPanel panel)
        throws SshToolsApplicationException {
    this.panel = panel;
    this.application = application;

    if (application != null) {
        setTitle(ConfigurationLoader.getVersionString(application.getApplicationName(),
                application.getApplicationVersion())); // + " " + application.getApplicationVersion());
    }

    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    // Register the File menu
    panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File", 'f', 0));
    // Register the Exit action
    if (showExitAction && application != null) {
        panel.registerAction(exitAction = new ExitAction(application, this));

        // Register the New Window Action
    }
    if (showNewWindowAction && application != null) {
        panel.registerAction(newWindowAction = new NewWindowAction(application));

        // Register the Help menu
    }
    panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Help", "Help", 'h', 99));

    // Register the About box action
    if (showAboutBox && application != null) {
        panel.registerAction(aboutAction = new AboutAction(this, application));

    }

    // Register the Changelog box action
    if (showChangelogBox && application != null) {
        panel.registerAction(changelogAction = new ChangelogAction(this, application));

    }
    panel.registerAction(faqAction = new FAQAction());
    panel.registerAction(beginnerAction = new BeginnerAction());
    panel.registerAction(advancedAction = new AdvancedAction());

    getApplicationPanel().rebuildActionComponents();

    JPanel p = new JPanel(new BorderLayout());

    if (panel.getJMenuBar() != null) {
        setJMenuBar(panel.getJMenuBar());
    }

    if (panel.getToolBar() != null) {
        JPanel t = new JPanel(new BorderLayout());
        t.add(panel.getToolBar(), BorderLayout.NORTH);
        t.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH);
        toolSeparator.setVisible(panel.getToolBar().isVisible());

        final SshToolsApplicationPanel pnl = panel;
        panel.getToolBar().addComponentListener(new ComponentAdapter() {
            public void componentHidden(ComponentEvent evt) {
                log.debug("Tool separator is now " + pnl.getToolBar().isVisible());
                toolSeparator.setVisible(pnl.getToolBar().isVisible());
            }
        });
        p.add(t, BorderLayout.NORTH);
    }

    p.add(panel, BorderLayout.CENTER);

    if (panel.getStatusBar() != null) {
        p.add(panel.getStatusBar(), BorderLayout.SOUTH);
    }

    getContentPane().setLayout(new GridLayout(1, 1));
    getContentPane().add(p);

    // Watch for the frame closing
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            if (application != null) {
                application.closeContainer(SshToolsApplicationFrame.this);
            } else {
                int confirm = JOptionPane.showOptionDialog(SshToolsApplicationFrame.this,
                        "Close " + getTitle() + "?", "Close Operation", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, null, null);
                if (confirm == 0) {
                    hide();
                }

            }
        }
    });

    // If this is the first frame, center the window on the screen
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    boolean found = false;

    if (application != null && application.getContainerCount() != 0) {
        for (int i = 0; (i < application.getContainerCount()) && !found; i++) {
            SshToolsApplicationContainer c = application.getContainerAt(i);

            if (c instanceof SshToolsApplicationFrame) {
                SshToolsApplicationFrame f = (SshToolsApplicationFrame) c;
                setSize(f.getSize());

                Point newLocation = new Point(f.getX(), f.getY());
                newLocation.x += 48;
                newLocation.y += 48;

                if (newLocation.x > (screenSize.getWidth() - 64)) {
                    newLocation.x = 0;
                }

                if (newLocation.y > (screenSize.getHeight() - 64)) {
                    newLocation.y = 0;
                }

                setLocation(newLocation);
                found = true;
            }
        }
    }

    if (!found) {
        // Is there a previous stored geometry we can use?
        if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) {
            setBounds(PreferencesStore.getRectangle(PREF_LAST_FRAME_GEOMETRY, getBounds()));
        } else {
            pack();
            UIUtil.positionComponent(SwingConstants.CENTER, this);
        }
    }
}

From source file:fr.fg.server.contract.NpcHelper.java

public static Point getNearestFreeTile(Fleet fleet) {
    return getNearestFreeTile(fleet.getArea(), new Point(fleet.getX(), fleet.getY()));
}

From source file:com.projity.pm.graphic.graph.GraphInteractor.java

protected Cursor getSplitCursor() {
    if (splitCursor == null) {
        try {/*from www.  jav  a  2 s . c o m*/
            splitCursor = Toolkit.getDefaultToolkit().createCustomCursor(
                    IconManager.getImage("gantt.split.cursor"), new Point(10, 4), "splitCursor");
        } catch (Exception e) {
            splitCursor = new Cursor(Cursor.HAND_CURSOR);
        }
    }
    return splitCursor;
}

From source file:org.gwaspi.gui.reports.ManhattanPlotZoom.java

public void initChart(boolean usePhysicalPosition) {

    //<editor-fold defaultstate="expanded" desc="PLOT DEFAULTS">
    this.threshold = Config.getSingleton().getDouble(GenericReportGenerator.PLOT_MANHATTAN_THRESHOLD_CONFIG,
            GenericReportGenerator.PLOT_MANHATTAN_THRESHOLD_DEFAULT);
    this.manhattan_back = Config.getSingleton().getColor(
            GenericReportGenerator.PLOT_MANHATTAN_BACKGROUND_CONFIG,
            GenericReportGenerator.PLOT_MANHATTAN_BACKGROUND_DEFAULT);
    this.manhattan_dot = Config.getSingleton().getColor(GenericReportGenerator.PLOT_MANHATTAN_MAIN_CONFIG,
            GenericReportGenerator.PLOT_MANHATTAN_MAIN_DEFAULT);
    //</editor-fold>

    final MarkerKey toUseMarkerKey;
    final long toUseRequestedPosWindow;
    if (usePhysicalPosition) {
        toUseMarkerKey = null;/*from w w w  .  ja  v a  2 s .com*/
        toUseRequestedPosWindow = requestedPosWindow;
    } else {
        toUseMarkerKey = origMarkerKey;
        toUseRequestedPosWindow = requestedSetSize; // XXX should this be requestedPosWindow instead?
    }
    initXYDataset = GenericReportGenerator.getManhattanZoomByChrAndPos(this, testOpKey, origChr, toUseMarkerKey,
            startPhysPos, toUseRequestedPosWindow);

    zoomChart = createChart(initXYDataset, currentChr);
    zoomPanel = new ChartPanel(zoomChart);
    zoomPanel.setInitialDelay(10);
    zoomPanel.setDismissDelay(5000);
    zoomPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            int mouseX = event.getTrigger().getX();
            int mouseY = event.getTrigger().getY();
            final Point2D point = zoomPanel.translateScreenToJava2D(new Point(mouseX, mouseY));
            XYPlot plot = (XYPlot) zoomChart.getPlot();
            ChartRenderingInfo info = zoomPanel.getChartRenderingInfo();
            Rectangle2D dataArea = info.getPlotInfo().getDataArea();

            ValueAxis domainAxis = plot.getDomainAxis();
            RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
            long chartX = (long) domainAxis.java2DToValue(point.getX(), dataArea, domainAxisEdge);
            //            ValueAxis rangeAxis = plot.getRangeAxis();
            //            RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
            //            double chartY = rangeAxis.java2DToValue(p.getY(), dataArea,
            //                  rangeAxisEdge);
            try {
                if (LinksExternalResouces.checkIfRsNecessary(cmb_SearchDB.getSelectedIndex())) { // THE SELECTED EXTERNAL RESOURCE NEEDS RSID INFO
                    String tooltip = zoomPanel.getToolTipText(event.getTrigger());
                    if (tooltip == null || tooltip.isEmpty()) { // CHECK IF THERE IS AN RSID
                        Dialogs.showWarningDialogue(Text.Reports.warnExternalResource);
                    } else {
                        String rsId = tooltip.substring(6, tooltip.indexOf('<', 6));
                        URLInDefaultBrowser.browseGenericURL(LinksExternalResouces.getResourceLink(
                                cmb_SearchDB.getSelectedIndex(), currentChr, // chr
                                rsId, // rsId
                                chartX) // pos
                        );
                    }
                } else { // THE SELECTED EXTERNAL RESOURCE ONLY NEEDS CHR+POS INFO
                    URLInDefaultBrowser.browseGenericURL(
                            LinksExternalResouces.getResourceLink(cmb_SearchDB.getSelectedIndex(), currentChr, // chr
                                    "", // rsId
                                    chartX) // pos
                    );
                }
                //               URLInDefaultBrowser.browseGenericURL(LinkEnsemblUrl.getHomoSapiensLink(currentChr, (int) chartX));
            } catch (IOException ex) {
                log.error(Text.Reports.cannotOpenEnsembl, ex);
            }
        }

        /**
         * Receives chart mouse moved events.
         *
         * @param event the event.
         */
        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            // ignore
        }
    });

    initGUI();
}

From source file:com.kbot2.scriptable.methods.wrappers.Interface.java

public boolean doAction(String actionContains) {
    Rectangle rect = getArea();/*from   w w  w.j  a va 2  s .c o  m*/
    int randomX = random(rect.x, rect.x + rect.width);
    int randomY = random(rect.y, rect.y + rect.height);
    botEnv.methods.moveMouse(new Point(randomX, randomY));
    return botEnv.methods.atMenu(actionContains);
}

From source file:com.kbot2.scriptable.methods.data.Bank.java

/**
 * Srolls using the up and down buttons.
 *
 * @param item//  w  w  w .ja va 2 s .co  m
 */
public void scrollTo(Interface item) {
    Mouse mouse = botEnv.mouse;

    Interface scrollbar = getBankInterfaceGroup().getInterface(BANK_SCROLLBAR);
    if (scrollbar == null)
        return;
    if (scrollbar.getChildren() == null)
        return;
    if (scrollbar.getChildren().length == 0)
        return;

    Interface arrow_up = scrollbar.getChild(BANK_SCROLLBAR_UP);
    Interface arrow_down = scrollbar.getChild(BANK_SCROLLBAR_DOWN);
    boolean pressing = false;
    Interface pressingInterface = null;
    Point pressingPoint = new Point(-1, -1);

    Rectangle bounds = getBankInterfaceGroup().getInterface(BANK_ITEMPANE).getArea();
    for (int i = 0; i < 100; i++) {
        Rectangle rect = item.getArea();
        // Must move
        if (rect.y < bounds.y) {
            // Move up
            if (pressing) {
                if (pressingInterface != arrow_up) {
                    mouse.releaseMouse(pressingPoint.x, pressingPoint.y, true);
                    pressingInterface = null;
                    pressing = false;
                }
                getMethods().sleep(40, 70);
            } else {
                pressingInterface = arrow_up;
                pressingPoint = pressingInterface.getRandomPointInside();
                mouse.moveMouse(pressingPoint.x, pressingPoint.y);
                getMethods().sleep(40, 70);
                mouse.pressMouse(pressingPoint.x, pressingPoint.y, true);
                getMethods().sleep(40, 70);
                pressing = true;
            }
        } else if (rect.y + rect.height > bounds.y + bounds.height) {
            // Move down
            if (pressing) {
                if (pressingInterface != arrow_down) {
                    mouse.releaseMouse(pressingPoint.x, pressingPoint.y, true);
                    pressingInterface = null;
                    pressing = false;
                }
                getMethods().sleep(40, 70);
            } else {
                pressingInterface = arrow_down;
                pressingPoint = pressingInterface.getRandomPointInside();
                mouse.moveMouse(pressingPoint.x, pressingPoint.y);
                getMethods().sleep(40, 70);
                mouse.pressMouse(pressingPoint.x, pressingPoint.y, true);
                getMethods().sleep(40, 70);
                pressing = true;
            }
        } else {
            if (pressing) {
                mouse.releaseMouse(pressingPoint.x, pressingPoint.y, true);
                pressing = false;
            }
            getMethods().sleep(40, 70);
            break;
        }
    }
}

From source file:ca.sqlpower.architect.swingui.TestPlayPen.java

/**
 * Test to ensure that the self-referencing table gets imported properly into the PlayPen.
 * @throws Exception//from  w  ww.  j av a2  s  .  c  o m
 */
public void testImportTableCopyOnSelfReferencingTable() throws Exception {
    SQLDatabase sourceDB = new SQLDatabase();
    pp.getSession().getRootObject().addChild(sourceDB);
    SQLTable table = new SQLTable(sourceDB, true);
    table.setName("self_ref");
    SQLColumn pkCol = new SQLColumn(table, "key", Types.INTEGER, 10, 0);
    table.addColumn(pkCol);
    table.addToPK(table.getColumn(0));
    SQLColumn fkCol = new SQLColumn(table, "self_ref_column", Types.INTEGER, 10, 0);
    table.addColumn(fkCol);

    SQLRelationship rel = new SQLRelationship();
    rel.attachRelationship(table, table, false);
    rel.addMapping(pkCol, fkCol);
    sourceDB.addChild(table);

    pp.importTableCopy(table, new Point(10, 10), ASUtils.createDuplicateProperties(pp.getSession(), table));

    int relCount = 0;
    int tabCount = 0;
    int otherCount = 0;
    for (PlayPenComponent ppc : pp.getContentPane().getChildren()) {
        if (ppc instanceof Relationship) {
            relCount++;
        } else if (ppc instanceof TablePane) {
            tabCount++;
        } else {
            otherCount++;
        }
    }
    assertEquals("Expected one table in pp", 1, tabCount);
    assertEquals("Expected one relationship in pp", 1, relCount);
    assertEquals("Found junk in playpen", 0, otherCount);
}

From source file:com.kbot2.scriptable.methods.wrappers.Interface.java

public Point getScreenPos() {
    return new Point(getAbsoluteX(), getAbsoluteY());
}