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:ltsa.jung.TreeLikeGraphLayout.java

/**
 * Set locations of nodes for subtree from {v} within rectangle such that
 * top-left corner is ({x}, {y}).  Ignore nodes in {alreadyDone}.
 *///from  ww  w  .j a  v  a 2s. c o m
protected void buildTree(V v, int x, int y) {
    assert !alreadyDone.contains(v);
    int depth = depths.get(v);
    {
        alreadyDone.add(v);
        int currentwidth = treeWidth.get(v);
        Point p = new Point(x + currentwidth * distX / 2, y);
        locations.get(v).setLocation(p);

        int lastX = x;

        List<V> successors = new ArrayList<V>(graph.getSuccessors(v));
        Collections.shuffle(successors); // for diversity
        for (V element : successors) {
            if (depths.get(element) == depth + 1 && !alreadyDone.contains(element)) {
                // this is a successor in the tree
                buildTree(element, lastX, y + distY);
                lastX = lastX + (treeWidth.get(element) + 1) * distX;
            }
        }
    }
}

From source file:gda.images.GUI.CmuCameraDisplayPanel.java

@Override
public void configure() {
    //logger.info("Cmu Camera Panel config called");
    samplePanel = new RTPCameraClient();
    samplePanel.setPreferredSize(ImageSize);
    samplePanel.setMinimumSize(ImageSize);
    samplePanel.setMaximumSize(ImageSize);
    samplePanel.getImageModifier().setDisplayCrossHair(true);

    samplePanel.addMouseListener(new MouseListener() {

        @Override//from w ww.  j  a  va 2 s.  c  om
        public void mouseClicked(MouseEvent mevt) {
            //logger.info("mouse clicked at " + mevt.getLocationOnScreen());
            //samplePanel.setCentre(mevt.getLocationOnScreen());
            if (mevt.isControlDown()) {
                Point p = mevt.getPoint();
                x = p.x;
                y = p.y;
                samplePanel.getImageModifier().setCentre(p);
                save();
            }
            //samplePanel.revalidate();

        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mousePressed(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseReleased(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

    });
    try {
        config = LocalParameters.getXMLConfiguration();
    } catch (ConfigurationException e) {
        logger.error("unable to configure beam centre values ", e);

    } catch (IOException e) {
        logger.error("unable to read beam centre values ", e);
    }
    this.load();
    //samplePanel.setDisplayCrossHair(true);
    //samplePanel.setDisplayBeamSize(true);

    //
    samplePanel.getImageModifier().setCentre(new Point(x, y));
    //samplePanel.setBeamSize(new Point(50, 50), new Point(200, 200));

    this.setLayout(new BorderLayout());
    this.add(samplePanel, BorderLayout.CENTER);
    this.add(getButtonPanel(), BorderLayout.SOUTH);

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            CmuCameraDisplayPanel.this.add(samplePanel);
            //samplePanel.setXScale(0.9);
            //samplePanel.setYScale(1.1);
            //samplePanel.setDisplayScale(true);
            //samplePanel.start();
        }
    });

    videoReceiver.addImageListener(this);
}

From source file:es.emergya.ui.base.BasicWindow.java

/**
 * Initialize the window with default values.
 *//*from ww  w . j a  v a 2s. co  m*/
private void inicializar() {
    frame = new JFrame(i18n.getString("title")); //$NON-NLS-1$
    getFrame().setBackground(Color.WHITE);
    getFrame().setIconImage(ICON_IMAGE); //$NON-NLS-1$
    getFrame().addWindowListener(new RemoveClientesConectadosListener());

    getFrame().setMinimumSize(new Dimension(900, 600));
    getFrame().addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            resize();
        }

    });

    busyCursor = new Cursor(Cursor.WAIT_CURSOR);
    defaultCursor = new Cursor(Cursor.DEFAULT_CURSOR);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image = getImageIcon("/images/hand.gif");
    if (image != null)
        handCursor = toolkit.createCustomCursor(image, new Point(0, 0), "hand"); //$NON-NLS-1$
}

From source file:net.bioclipse.model.ScatterPlotMouseHandler.java

@Override
public void mouseDragged(MouseEvent e) {
    super.mouseDragged(e);

    ChartPanel chartPanel = getChartPanel(e);
    JFreeChart selectedChart = chartPanel.getChart();
    ChartDescriptor cd = ChartUtils.getChartDescriptor(selectedChart);
    int[] indices = cd.getSourceIndices();

    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();

    //Create double buffer
    Image buffer = chartPanel.createImage(chartPanel.getWidth(), chartPanel.getHeight());
    Graphics bufferGraphics = buffer.getGraphics();
    chartPanel.paint(bufferGraphics);/*  w w w  .  j  a va 2s . c o  m*/

    if (lastX == 0 && lastY == 0) {
        lastX = e.getX();
        lastY = e.getY();
    }

    drawRect = new Rectangle();
    int x1 = Math.min(Math.min(e.getX(), lastX), startX);
    int y1 = Math.min(Math.min(e.getY(), lastY), startY);
    int x2 = Math.max(Math.max(e.getX(), lastX), startX);
    int y2 = Math.max(Math.max(e.getY(), lastY), startY);

    drawRect.x = x1;
    drawRect.y = y1;
    drawRect.width = x2 - drawRect.x;
    drawRect.height = y2 - drawRect.y;

    //Create a clipping rectangle
    Rectangle clipRect = new Rectangle(drawRect.x - 100, drawRect.y - 100, drawRect.width + 200,
            drawRect.height + 200);

    //Check for selected points
    for (int j = 0; j < plot.getDataset().getItemCount(plot.getDataset().getSeriesCount() - 1); j++) {
        for (int i = 0; i < plot.getDataset().getSeriesCount(); i++) {
            Number xK = plot.getDataset().getX(i, j);
            Number yK = plot.getDataset().getY(i, j);
            Point2D datasetPoint2D = new Point2D.Double(domainValueTo2D(chartPanel, plot, xK.doubleValue()),
                    rangeValueTo2D(chartPanel, plot, yK.doubleValue()));

            if (drawRect.contains(datasetPoint2D)) {
                PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel());
                boolean pointAdded = mouseDragSelection.addPoint(cp);
                if (pointAdded) {
                    ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(j, i);
                    selectedChart.plotChanged(new PlotChangeEvent(plot));
                }
            } else if (!mouseDragSelection.isEmpty()) {
                PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel());
                boolean pointRemoved = mouseDragSelection.removePoint(cp);
                if (pointRemoved) {
                    ((ScatterPlotRenderer) plot.getRenderer()).removeMarkedPoint(new Point(j, i));
                    selectedChart.plotChanged(new PlotChangeEvent(plot));
                }
            }
        }
    }

    Iterator<PlotPointData> iterator = currentSelection.iterator();
    while (iterator.hasNext()) {
        PlotPointData next = iterator.next();
        Point dataPoint = next.getDataPoint();
        ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(dataPoint);
    }

    lastX = e.getX();
    lastY = e.getY();

    Graphics graphics = chartPanel.getGraphics();
    graphics.setClip(clipRect);

    //Draw selection rectangle
    bufferGraphics.drawRect(drawRect.x, drawRect.y, drawRect.width, drawRect.height);

    graphics.drawImage(buffer, 0, 0, chartPanel.getWidth(), chartPanel.getHeight(), null);
}

From source file:simMPLS.scenario.TLink.java

/**
 * Este mtodo calcula las coordenadas donde debe dibujarse un paquete que ha
 * recorrido ya un porcentaje concreto de su trnsito.
 * @since 1.0//from  ww w. j av  a2s.  c  o  m
 * @param porcentaje Porcentaje recorrido ya por el paquete en el enlace.
 * @return Coordenadas donde dibujar el paquete.
 */
public Point obtenerCoordenadasPaquete(long porcentaje) {
    Point coordenadas = new Point(0, 0);
    int x1 = extremo1.obtenerPosicion().x + 24;
    int y1 = extremo1.obtenerPosicion().y + 24;
    int x2 = extremo2.obtenerPosicion().x + 24;
    int y2 = extremo2.obtenerPosicion().y + 24;
    coordenadas.x = x1;
    coordenadas.y = y1;
    int distanciaX = (x2 - x1);
    int distanciaY = (y2 - y1);
    coordenadas.x += (int) ((double) distanciaX * (double) porcentaje / (double) 100);
    coordenadas.y += (int) ((double) distanciaY * (double) porcentaje / (double) 100);
    return coordenadas;
}

From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java

protected Point getDialogLocation(JDialog dialog, Component c) {
    Frame frame = JOptionPane.getFrameForComponent(c);
    int x = frame.getX() + (frame.getWidth() - dialog.getWidth()) / 2;
    int y = frame.getY() + (frame.getHeight() - dialog.getHeight()) / 2;
    return new Point(x, y);
}

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

private Point findNewLocationForOther(ICaratteristicheWidget caratteristicheWidget, Widget widget) {
    CaratteristicheWidgetConstraint caratteristicheWidgetConstraint = (CaratteristicheWidgetConstraint) caratteristicheWidget;
    Widget originalWidget = caratteristicheWidgetConstraint.getWidgetOriginale();
    Point originalPoint = caratteristicheWidgetConstraint.getOriginalPoint();

    int x = (originalWidget.getPreferredLocation().x - originalPoint.x) + widget.getPreferredLocation().x;
    int y = (originalWidget.getPreferredLocation().y - originalPoint.y) + widget.getPreferredLocation().y;
    caratteristicheWidgetConstraint.setOriginalPoint(
            new Point(originalWidget.getPreferredLocation().x, originalWidget.getPreferredLocation().y));
    return new Point(x, y);
}

From source file:com.griddynamics.jagger.diagnostics.visualization.GraphVisualizationHelper.java

public static <V, E> Image renderGraph(Graph<V, E> graph, int width, int height, GraphLayout graphLayout,
        final ColorTheme colorTheme, final Map<V, Paint> customNodeColors) {

    Layout<V, E> layout;/*w w w .  j a v  a  2s.c  o  m*/
    switch (graphLayout) {
    case CIRCLE:
        layout = new CircleLayout<V, E>(graph);
        break;
    case ISOM:
        layout = new ISOMLayout<V, E>(graph);
        break;
    case FR:
        layout = new FRLayout<V, E>(graph);
        break;
    case KK:
        layout = new KKLayout<V, E>(graph);
        break;
    default:
        throw new RuntimeException("Unknown Graph Layout : [" + graphLayout + "]");
    }

    layout.setSize(new Dimension((int) (width * (1 - IMAGE_HORIZONTAL_MARGIN)),
            (int) (height * (1 - IMAGE_VERTICAL_MARGIN))));

    VisualizationImageServer<V, E> server = new VisualizationImageServer<V, E>(displacementLayout(layout,
            (int) (width * IMAGE_HORIZONTAL_MARGIN / 2), (int) (height * IMAGE_VERTICAL_MARGIN / 2)),
            new Dimension(width, height));

    final Color edgeColor;
    switch (colorTheme) {
    case LIGHT:
        server.setBackground(Color.WHITE);
        edgeColor = Color.BLACK;
        break;
    case DARK:
        server.setBackground(Color.BLACK);
        edgeColor = Color.LIGHT_GRAY;
        break;
    default:
        throw new RuntimeException("Unknown Color Theme : [" + colorTheme + "]");
    }

    Transformer<V, Paint> vertexPaint = new Transformer<V, Paint>() {
        public Paint transform(V v) {
            Paint paint = customNodeColors.get(v);
            if (paint == null) {
                paint = Color.LIGHT_GRAY;
            }
            return paint;
        }
    };

    Transformer<V, Paint> vertexBorderPaint = new Transformer<V, Paint>() {
        public Paint transform(V v) {
            return Color.DARK_GRAY;
        }
    };

    Transformer<E, Paint> edgePaint = new Transformer<E, Paint>() {
        public Paint transform(E e) {
            return edgeColor;
        }
    };

    server.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    server.getRenderContext().setEdgeDrawPaintTransformer(edgePaint);
    server.getRenderContext().setArrowDrawPaintTransformer(edgePaint);
    server.getRenderContext().setArrowFillPaintTransformer(edgePaint);

    server.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<V>());
    server.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<E>());
    server.getRenderContext().setVertexDrawPaintTransformer(vertexBorderPaint);

    server.getRenderContext().setVertexLabelTransformer(new ChainedTransformer<V, String>(
            new Transformer[] { new ToStringLabeller<V>(), new Transformer<String, String>() {
                public String transform(String input) {
                    return "<html><center><p>" + formatLabel(input, MAX_LABEL_LENGTH);
                }
            } }));
    VertexLabelAsShapeRenderer<V, E> vlasr = new VertexLabelAsShapeRenderer<V, E>(server.getRenderContext());
    server.getRenderContext().setVertexShapeTransformer(vlasr);
    server.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

    return server.getImage(new Point(0, 0), new Dimension(width, height));
}

From source file:cz.cuni.mff.ksi.jinfer.autoeditor.BububuEditor.java

/**
 * Draws automaton and waits until user picks two states and clicks
 * 'continue' button.//w  w  w  .ja v  a 2s.  c  o  m
 *
 * @param automaton automaton to be drawn
 * @return if user picks exactly two states returns Pair of them otherwise null
 */
@Override
public List<State<T>> drawAutomatonToPickStates(final Automaton<T> automaton) {

    final DirectedSparseMultigraph<State<T>, Step<T>> graph = new DirectedSparseMultigraph<State<T>, Step<T>>();
    final Map<State<T>, Set<Step<T>>> automatonDelta = automaton.getDelta();

    // Get vertices = states of automaton
    for (Entry<State<T>, Set<Step<T>>> entry : automatonDelta.entrySet()) {
        graph.addVertex(entry.getKey());
    }

    // Get edges of automaton
    for (Entry<State<T>, Set<Step<T>>> entry : automatonDelta.entrySet()) {
        for (Step<T> step : entry.getValue()) {
            graph.addEdge(step, step.getSource(), step.getDestination());
        }
    }

    Map<State<T>, Point2D> positions = new HashMap<State<T>, Point2D>();

    ProcessBuilder p = new ProcessBuilder(Arrays.asList("/usr/bin/dot", "-Tplain"));
    try {
        Process k = p.start();
        k.getOutputStream().write((new AutomatonToDot<T>()).convertToDot(automaton, symbolToString).getBytes());
        k.getOutputStream().flush();
        BufferedReader b = new BufferedReader(new InputStreamReader(k.getInputStream()));
        k.getOutputStream().close();

        Scanner s = new Scanner(b);
        s.next();
        s.next();
        double width = s.nextDouble();
        double height = s.nextDouble();
        double windowW = 500;
        double windowH = 300;

        while (s.hasNext()) {
            if (s.next().equals("node")) {
                int nodeName = s.nextInt();
                double x = s.nextDouble();
                double y = s.nextDouble();
                for (State<T> state : automatonDelta.keySet()) {
                    if (state.getName() == nodeName) {
                        positions.put(state,
                                new Point((int) (windowW * x / width), (int) (windowH * y / height)));
                        break;
                    }
                }
            }
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    Transformer<State<T>, Point2D> trans = TransformerUtils.mapTransformer(positions);

    // TODO rio find suitable layout
    final Layout<State<T>, Step<T>> layout = new StaticLayout<State<T>, Step<T>>(graph, trans);

    //layout.setSize(new Dimension(300,300)); // sets the initial size of the space

    visualizationViewer = new VisualizationViewer<State<T>, Step<T>>(layout);
    //visualizationViewer.setPreferredSize(new Dimension(350,350)); //Sets the viewing area size

    visualizationViewer.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<State<T>>());
    visualizationViewer.getRenderContext().setEdgeLabelTransformer(new Transformer<Step<T>, String>() {
        @Override
        public String transform(Step<T> i) {
            return BububuEditor.this.symbolToString.toString(i.getAcceptSymbol());
        }
    });

    final PluggableGraphMouse gm = new PluggableGraphMouse();
    gm.add(new PickingUnlimitedGraphMousePlugin<State<T>, Step<T>>());
    visualizationViewer.setGraphMouse(gm);

    // Call GUI in a special thread. Required by NB.
    synchronized (this) {
        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {

            @Override
            public void run() {
                // Pass this as argument so the thread will be able to wake us up.
                AutoEditorTopComponent.findInstance().drawAutomatonBasicVisualizationServer(BububuEditor.this,
                        visualizationViewer, "Please select two states to be merged together.");
            }
        });

        try {
            // Sleep on this.
            this.wait();
        } catch (InterruptedException e) {
            return null;
        }
    }

    /* AutoEditorTopComponent wakes us up. Get the result and return it.
     * VisualizationViewer should give us the information about picked vertices.
     */
    final Set<State<T>> pickedSet = visualizationViewer.getPickedVertexState().getPicked();
    List<State<T>> lst = new ArrayList<State<T>>(pickedSet);
    return lst;
}

From source file:fr.landel.utils.commons.CollectionUtils2Test.java

/**
 * Test method for/*www  . j a v  a2s  .  c om*/
 * {@link CollectionUtils2#transformIntoList(java.lang.Iterable)}.
 */
@Test
public void testTransformIntoListIterableOfI() {
    try {
        List<Point> points = new ArrayList<>();
        points.add(new Point(1, 2));
        points.add(new Point(2, 0));
        points.add(null);

        List<String> strPoints = CollectionUtils2.transformIntoList(points);

        assertThat(strPoints, Matchers.contains("java.awt.Point[x=1,y=2]", "java.awt.Point[x=2,y=0]", null));
    } catch (IllegalArgumentException e) {
        fail("The test isn't correct");
    }
}