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:it.unibas.spicygui.vista.listener.ScrollPaneAdjustmentListener.java

private Point findNewLocationForTree(ICaratteristicheWidget icaratteristicheWidget, JTree albero) {
    CaratteristicheWidgetTree caratteristicheWidget = (CaratteristicheWidgetTree) icaratteristicheWidget;
    Point oldPoint = caratteristicheWidget.getPosizione();

    if (logger.isTraceEnabled())
        logger.trace("oldPoint: " + oldPoint);
    TreePath treePath = caratteristicheWidget.getTreePath();
    Rectangle rect = albero.getPathBounds(treePath);
    if (rect != null && this.type.equalsIgnoreCase(caratteristicheWidget.getTreeType())) {
        Point newPoint = albero.getPathBounds(treePath).getLocation();
        Point convertedPoint = SwingUtilities.convertPoint(source, newPoint, glassPane);
        if (logger.isTraceEnabled())
            logger.trace(" -- newPoint: " + convertedPoint);
        if (caratteristicheWidget.getTreeType().equalsIgnoreCase(Costanti.TREE_SOURCE)) {
            return new Point(
                    convertedPoint.x + (albero.getPathBounds(treePath).width - Costanti.OFFSET_X_WIDGET_SOURCE),
                    convertedPoint.y/*from   w w w . jav  a 2 s .  c o  m*/
                            + (albero.getPathBounds(treePath).height / Costanti.OFFSET_Y_WIDGET_SOURCE));
        }
        return new Point(convertedPoint.x, convertedPoint.y + 5);

    } else if (this.type.equalsIgnoreCase(caratteristicheWidget.getTreeType())) {
        TreePath treePathInterno = treePath;
        Rectangle rectInterno = albero.getPathBounds(treePathInterno);
        while (rectInterno == null) {
            if (treePathInterno == null) {
                return null;
            }
            treePathInterno = treePathInterno.getParentPath();
            rectInterno = albero.getPathBounds(treePathInterno);
        }
        Point newPoint = albero.getPathBounds(treePathInterno).getLocation();
        Point convertedPoint = SwingUtilities.convertPoint(source, newPoint, glassPane);
        if (logger.isTraceEnabled())
            logger.trace(" -- newPoint: " + convertedPoint);
        if (caratteristicheWidget.getTreeType().equalsIgnoreCase(Costanti.TREE_SOURCE)) {
            return new Point(
                    convertedPoint.x
                            + (albero.getPathBounds(treePathInterno).width - Costanti.OFFSET_X_WIDGET_SOURCE),
                    convertedPoint.y
                            + (albero.getPathBounds(treePathInterno).height / Costanti.OFFSET_Y_WIDGET_SOURCE));
        }
        return new Point(convertedPoint.x, convertedPoint.y + 5);
    }
    return null;
}

From source file:cz.cuni.mff.ksi.jinfer.autoeditor.automatonvisualizer.layouts.graphviz.GraphvizLayoutFactory.java

@SuppressWarnings("PMD")
private <T> Map<State<T>, Point2D> getGraphvizPositions(final byte[] graphInDotFormat,
        final Set<State<T>> automatonStates) throws GraphvizException, IOException {
    final Map<State<T>, Point2D> result = new HashMap<State<T>, Point2D>();

    // creates new dot process.
    final ProcessBuilder processBuilder = new ProcessBuilder(Arrays.asList(GraphvizUtils.getPath(), "-Tplain"));
    final Process process = processBuilder.start();

    // write our graph into dot binary standart input
    process.getOutputStream().write(graphInDotFormat);
    process.getOutputStream().flush();//from  w w w  . ja  v  a 2  s .c o  m

    // read from dot binary standard output
    final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    process.getOutputStream().close();

    final Scanner scanner = new Scanner(reader);
    // jumps some unnecessary information from output
    scanner.next();
    scanner.next();

    // get width and height of graph
    windowWidth = 100 + (int) Double.parseDouble(scanner.next());
    windowHeight = 100 + (int) Double.parseDouble(scanner.next());

    // parse output for graph vertex positions
    while (scanner.hasNext()) {
        final String n = scanner.next();
        if (n.equals("node")) {
            final int nodeName = Integer.parseInt(scanner.next());
            final double x = Double.parseDouble(scanner.next());
            final double y = Double.parseDouble(scanner.next());
            boolean found = false;
            for (State<T> state : automatonStates) {
                if (state.getName() == nodeName) {
                    result.put(state, new Point(50 + (int) (x), 50 + (int) (y)));
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new GraphvizException("Node with name " + nodeName + " was not found in automaton.");
            }
        }
    }

    return result;
}

From source file:GraphicsUtil.java

/**
 * Creates a new raster that has a <b>copy</b> of the data in
 * <tt>ras</tt>.  This is highly optimized for speed.  There is
 * no provision for changing any aspect of the SampleModel.
 * However you can specify a new location for the returned raster.
 *
 * This method should be used when you need to change the contents
 * of a Raster that you do not "own" (ie the result of a
 * <tt>getData</tt> call)./*from   w  ww  . jav  a  2 s  .c  o m*/
 *
 * @param ras The Raster to copy.
 *
 * @param minX The x location for the upper left corner of the
 *             returned WritableRaster.
 *
 * @param minY The y location for the upper left corner of the
 *             returned WritableRaster.
 *
 * @return    A writable copy of <tt>ras</tt>
 */
public static WritableRaster copyRaster(Raster ras, int minX, int minY) {
    WritableRaster ret = Raster.createWritableRaster(ras.getSampleModel(), new Point(0, 0));
    ret = ret.createWritableChild(ras.getMinX() - ras.getSampleModelTranslateX(),
            ras.getMinY() - ras.getSampleModelTranslateY(), ras.getWidth(), ras.getHeight(), minX, minY, null);

    // Use System.arraycopy to copy the data between the two...
    DataBuffer srcDB = ras.getDataBuffer();
    DataBuffer retDB = ret.getDataBuffer();
    if (srcDB.getDataType() != retDB.getDataType()) {
        throw new IllegalArgumentException("New DataBuffer doesn't match original");
    }
    int len = srcDB.getSize();
    int banks = srcDB.getNumBanks();
    int[] offsets = srcDB.getOffsets();
    for (int b = 0; b < banks; b++) {
        switch (srcDB.getDataType()) {
        case DataBuffer.TYPE_BYTE: {
            DataBufferByte srcDBT = (DataBufferByte) srcDB;
            DataBufferByte retDBT = (DataBufferByte) retDB;
            System.arraycopy(srcDBT.getData(b), offsets[b], retDBT.getData(b), offsets[b], len);
            break;
        }
        case DataBuffer.TYPE_INT: {
            DataBufferInt srcDBT = (DataBufferInt) srcDB;
            DataBufferInt retDBT = (DataBufferInt) retDB;
            System.arraycopy(srcDBT.getData(b), offsets[b], retDBT.getData(b), offsets[b], len);
            break;
        }
        case DataBuffer.TYPE_SHORT: {
            DataBufferShort srcDBT = (DataBufferShort) srcDB;
            DataBufferShort retDBT = (DataBufferShort) retDB;
            System.arraycopy(srcDBT.getData(b), offsets[b], retDBT.getData(b), offsets[b], len);
            break;
        }
        case DataBuffer.TYPE_USHORT: {
            DataBufferUShort srcDBT = (DataBufferUShort) srcDB;
            DataBufferUShort retDBT = (DataBufferUShort) retDB;
            System.arraycopy(srcDBT.getData(b), offsets[b], retDBT.getData(b), offsets[b], len);
            break;
        }
        }
    }

    return ret;
}

From source file:ancat.visualizers.UndirectedModelVisualizer.java

private void produce(String fileName) {
    _currentLayout.setSize(new Dimension(600, 600));

    VisualizationImageServer<V, E> vv = new VisualizationImageServer<V, E>(_currentLayout,
            new Dimension(600, 600));

    vv.setPreferredSize(new Dimension(600, 600));

    // Setup up a new vertex to paint transformer...
    Transformer<V, Paint> vertexPaint = new Transformer<V, Paint>() {
        public Paint transform(V v) {
            //return Color.GREEN;
            ancat.common.Vertex vertex = (Vertex) v;

            if (vertex instanceof ancat.common.ExecutableFile)
                return Color.BLUE;

            if (vertex instanceof ancat.common.DynamicLibrary)
                return Color.YELLOW;

            if (vertex instanceof ancat.common.ConfigurationFile)
                return Color.ORANGE;

            if (vertex instanceof ancat.common.Unspecified)
                return Color.RED;

            return Color.darkGray;
        }//w  w  w .  j  a  va 2s . c o m
    };
    // Set up a new stroke Transformer for the edges
    float dash[] = { 10.0f };

    final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash,
            0.0f);

    Transformer<E, Stroke> edgeStrokeTransformer = new Transformer<E, Stroke>() {
        public Stroke transform(E s) {
            return edgeStroke;
        }
    };

    Transformer<E, Font> edgeFontTransformer = new Transformer<E, Font>() {
        public Font transform(E e) {
            return new Font("Dialog", Font.PLAIN, 10);
        }
    };

    Transformer<E, String> lblTransformer = new Transformer<E, String>() {
        public String transform(E e) {
            Edge edge = (Edge) e;
            //return edge.getXMLId();
            return edge.getXMLId() != null ? edge.getXMLId() : "";
        }
    };

    Transformer<V, Font> vertexFontTransformer = new Transformer<V, Font>() {
        public Font transform(V v) {
            return new Font("Dialog", Font.PLAIN, 10);
        }
    };

    Transformer<V, String> vLblTransformer = new Transformer<V, String>() {
        public String transform(V v) {
            Vertex vertex = (Vertex) v;
            return vertex.getElementID();
        }
    };

    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<V>());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<E>());
    // ---->
    vv.getRenderContext().setEdgeFontTransformer(edgeFontTransformer);
    vv.getRenderContext().setLabelOffset(20);
    vv.getRenderContext().setEdgeLabelTransformer(lblTransformer);

    vv.getRenderContext().setVertexFontTransformer(vertexFontTransformer);
    vv.getRenderContext().setVertexLabelTransformer(vLblTransformer);

    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.N);

    BufferedImage img = new BufferedImage((int) _currentLayout.getSize().getWidth(),
            (int) _currentLayout.getSize().getHeight(), BufferedImage.TYPE_INT_ARGB);

    vv.getImage(new Point(0, 0), new Dimension(700, 700));

    Graphics2D g2d = (Graphics2D) img.getGraphics();

    vv.paint(g2d);

    setDisclaimer(g2d);

    g2d.dispose();

    try {
        File file = new File(fileName);

        ImageIO.write(img, "png", file);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java

private void initBooksTable() {
    booksTable.getColumnModel().getColumn(2)
            .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy")));
    booksTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {

        @Override/*w  w w.  j  a  v a 2s. c o m*/
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected,
                boolean hasFocus, int row, int column) {

            if (value instanceof Date) {

                // You could use SimpleDateFormatter instead
                value = new SimpleDateFormat("dd. MM. yyyy").format(value);

            }

            return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column);

        }
    });
    booksTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JPopupMenu booksPopupMenu = new JPopupMenu();
    JMenuItem deleteBook = new JMenuItem("Delete");
    booksPopupMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    int rowAtPoint = booksTable.rowAtPoint(
                            SwingUtilities.convertPoint(booksPopupMenu, new Point(0, 0), booksTable));
                    if (rowAtPoint > -1) {
                        booksTable.setRowSelectionInterval(rowAtPoint, rowAtPoint);
                    }
                }
            });
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    deleteBook.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (booksTable.getSelectedRow() == -1) {
                JOptionPane.showMessageDialog(MainWindow.this, "You haven't selected any book.");
                return;
            }
            Book book = booksTableModel.getBooks().get(booksTable.getSelectedRow());
            new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                    log.debug("Deleting book: " + book.getName() + " from database.");
                    bookManager.deleteBook(book);
                    return null;
                }

                @Override
                protected void done() {
                    try {
                        get();
                    } catch (Exception e) {
                        log.error("There was an exception thrown while deleting a book.", e);
                        return;
                    }

                    updateModel();
                }

            }.execute();

        }
    });
    booksPopupMenu.add(deleteBook);
    booksTable.setComponentPopupMenu(booksPopupMenu);
}

From source file:edu.ku.brc.ui.GraphicsUtils.java

/**
 * Calculates the location of a point that is a given percentage of the distance
 * from <code>start</code> to <code>end</code>.
 * /*from  w w  w .j a v  a 2  s . com*/
 * @param start the start of the line
 * @param end the end of the line
 * @param percent the percentage distance
 * @return the point
 */
public static Point getPointAlongLine(Point start, Point end, float percent) {
    int x = start.x + (int) (percent * (end.x - start.x));
    int y = start.y + (int) (percent * (end.y - start.y));
    return new Point(x, y);
}

From source file:org.nekorp.workflow.desktop.view.AutoDamageView.java

private void resizeCurrentView() {
    boundsX = (content.getWidth() - currentView.getShapeWidth()) / 2;
    //boundsX = 60;
    boundsY = (content.getHeight() - currentView.getShapeHeight()) / 2;
    //boundsY = 50;
    currentView.setBounds(boundsX, boundsY, currentView.getShapeWidth(), currentView.getShapeHeight());
    for (DamageDetailGraphicsView x : damageDetail) {
        x.setBounds(0, 0, content.getWidth(), content.getHeight());
        x.setContexto(new Point(boundsX, boundsY));
    }// w  w w.j a  va 2s. c om
}

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

/**
 * Description of the scenario: We are to reverse engineer two tables into the playpen.
 * There exists one relationship between the two tables. After the first reverse engineering
 * process, we reverse engineering the parent table again into the playpen. Now we shoud
 * expect 3 tables in total lying on playpen, and 1 relationship between the first two tables.
 *//*from ww  w  . j  a  v a2s.  c om*/
public void testImportTableCopyHijacksProperly() throws SQLObjectException {

    SQLDatabase sourceDB = new SQLDatabase();
    pp.getSession().getRootObject().addChild(sourceDB);
    SQLTable sourceParentTable = new SQLTable(sourceDB, true);
    sourceParentTable.setName("parent");
    sourceParentTable.addColumn(new SQLColumn(sourceParentTable, "key", Types.BOOLEAN, 1, 0));
    sourceParentTable.addToPK(sourceParentTable.getColumn(0));
    sourceDB.addChild(sourceParentTable);

    SQLTable sourceChildTable = new SQLTable(sourceDB, true);
    sourceChildTable.setName("child");
    sourceChildTable.addColumn(new SQLColumn(sourceChildTable, "key", Types.BOOLEAN, 1, 0));
    sourceDB.addChild(sourceChildTable);

    SQLRelationship sourceRel = new SQLRelationship();
    sourceRel.attachRelationship(sourceParentTable, sourceChildTable, true);

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

    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++;
        }
    }
    // The behaviour of the reverse engineering is slightly modified. When reverse engineer copy(ies)
    // of related tables to the playpen. The relationship is not pointed to the old tables.   
    assertEquals("Expected three tables in pp", 3, tabCount);
    assertEquals("Expected two relationships in pp", 1, relCount); //changed from 2 to 1
    assertEquals("Found junk in playpen", 0, otherCount);

    TablePane importedChild = pp.findTablePaneByName("child");
    assertEquals("Incorrect reference count on imported child col", 2,
            importedChild.getModel().getColumn(0).getReferenceCount()); //changed from 3 to 2
}

From source file:it.unibas.spicygui.vista.listener.WidgetMoveExpansionListener.java

private Point findNewLocationForTree(ICaratteristicheWidget icaratteristicheWidget, JTree albero) {
    CaratteristicheWidgetTree caratteristicheWidget = (CaratteristicheWidgetTree) icaratteristicheWidget;
    Point oldPoint = caratteristicheWidget.getPosizione();

    if (logger.isTraceEnabled())
        logger.trace("oldPoint: " + oldPoint);
    TreePath treePath = caratteristicheWidget.getTreePath();
    Rectangle rect = albero.getPathBounds(treePath);
    if (rect != null && this.type.equalsIgnoreCase(caratteristicheWidget.getTreeType())) {
        Point newPoint = albero.getPathBounds(treePath).getLocation();
        Point convertedPoint = SwingUtilities.convertPoint(source, newPoint, glassPane);
        if (logger.isTraceEnabled())
            logger.trace(" -- newPoint: " + convertedPoint);
        if (caratteristicheWidget.getTreeType().equalsIgnoreCase(Costanti.TREE_SOURCE)) {
            return new Point(
                    convertedPoint.x + (albero.getPathBounds(treePath).width - Costanti.OFFSET_X_WIDGET_SOURCE),
                    convertedPoint.y//from  www . j a va 2  s. co m
                            + (albero.getPathBounds(treePath).height / Costanti.OFFSET_Y_WIDGET_SOURCE));
        }
        return new Point(convertedPoint.x, convertedPoint.y + 5);
    } else if (this.type.equalsIgnoreCase(caratteristicheWidget.getTreeType())) {
        TreePath treePathInterno = treePath;
        Rectangle rectInterno = albero.getPathBounds(treePathInterno);
        while (rectInterno == null) {
            if (treePathInterno == null) {
                return null;
            }
            treePathInterno = treePathInterno.getParentPath();
            rectInterno = albero.getPathBounds(treePathInterno);
        }
        Point newPoint = albero.getPathBounds(treePathInterno).getLocation();
        Point convertedPoint = SwingUtilities.convertPoint(source, newPoint, glassPane);
        if (logger.isTraceEnabled())
            logger.trace(" -- newPoint: " + convertedPoint);
        if (caratteristicheWidget.getTreeType().equalsIgnoreCase(Costanti.TREE_SOURCE)) {
            return new Point(
                    convertedPoint.x
                            + (albero.getPathBounds(treePathInterno).width - Costanti.OFFSET_X_WIDGET_SOURCE),
                    convertedPoint.y
                            + (albero.getPathBounds(treePathInterno).height / Costanti.OFFSET_Y_WIDGET_SOURCE));
        }
        return new Point(convertedPoint.x, convertedPoint.y + 5);
    }
    return null;
}

From source file:org.jax.bham.test.PhylogenyAssociationTestGraphPanel.java

/**
 * Gets the index of the interval with the highest value that falls
 * under the given Java2D coordinates/*ww  w  .  jav a2 s  .  c  o m*/
 * @param x
 *          the Java2D X coordinate
 * @param y
 *          the Java2D Y coordinate
 * @return
 *          the interval index
 */
private int getMaximalIntervalIndex(int x, int y) {
    int clickIndex = -1;

    int[] chromosomes = this.getSelectedChromosomes();

    if (chromosomes.length == 1) {
        List<PhylogenyTestResult> selectedPhyloAssociationTests = this.chromosomeResultsCache
                .get(chromosomes[0]);

        if (selectedPhyloAssociationTests != null) {
            RealValuedBasePairInterval[] selectedValuesList = selectedPhyloAssociationTests
                    .toArray(new RealValuedBasePairInterval[selectedPhyloAssociationTests.size()]);

            Point2D clickedGraphPoint = JFreeChartUtil.java2DPointToGraphPoint(new Point(x, y),
                    this.chartPanel);

            // exhaustive search for the maximum clicked index (this could
            // be a binary search, but this seems to perform OK for now)
            double graphX = clickedGraphPoint.getX();
            int valueCount = selectedValuesList.length;
            double biggestClickedValue = Double.NEGATIVE_INFINITY;
            for (int i = 0; i < valueCount; i++) {
                RealValuedBasePairInterval currValue = selectedValuesList[i];
                if (currValue.getStartInBasePairs() < graphX && currValue.getEndInBasePairs() > graphX
                        && currValue.getRealValue() > biggestClickedValue) {
                    biggestClickedValue = currValue.getRealValue();
                    clickIndex = i;
                }
            }

            // if we didn't click on anything grab the nearest item
            // (again this could and should be faster)
            if (clickIndex == -1 && valueCount >= 1) {
                clickIndex = 0;
                double nearestDistance = Math.min(
                        Math.abs(selectedValuesList[0].getStartInBasePairs() - graphX),
                        Math.abs(selectedValuesList[0].getEndInBasePairs() - graphX));
                for (int i = 1; i < valueCount; i++) {
                    BasePairInterval currValue = selectedValuesList[i];
                    double currDistance = Math.min(Math.abs(currValue.getStartInBasePairs() - graphX),
                            Math.abs(currValue.getEndInBasePairs() - graphX));
                    if (currDistance < nearestDistance) {
                        nearestDistance = currDistance;
                        clickIndex = i;
                    }
                }
            }
        }
    }

    return clickIndex;
}