Example usage for java.awt.geom Point2D getX

List of usage examples for java.awt.geom Point2D getX

Introduction

In this page you can find the example usage for java.awt.geom Point2D getX.

Prototype

public abstract double getX();

Source Link

Document

Returns the X coordinate of this Point2D in double precision.

Usage

From source file:net.sf.maltcms.chromaui.charts.events.XYPeakAnnotationOverlay.java

/**
 *
 * @param name/*  w ww .j  a  v  a2s.com*/
 * @param visible
 * @param min
 * @param max
 * @param cp
 */
public XYPeakAnnotationOverlay(String name, boolean visible, Point2D min, Point2D max, ChartPanel cp) {
    this.qt = new QuadTree<>(min.getX(), min.getY(), max.getX() - min.getX(), max.getY() - min.getY(), 3);
    this.cp = cp;
    this.name = name;
    this.visible = visible;
}

From source file:edu.uci.ics.jung.algorithms.layout.ISOMLayout.java

private synchronized void adjust() {
    //Generate random position in graph space
    Point2D tempXYD = new Point2D.Double();

    // creates a new XY data location
    tempXYD.setLocation(10 + Math.random() * getSize().getWidth(), 10 + Math.random() * getSize().getHeight());

    //Get closest vertex to random position
    V winner = elementAccessor.getVertex(this, tempXYD.getX(), tempXYD.getY());

    while (true) {
        try {//from   w  w  w  . j  a v a 2  s .c om
            for (V v : getGraph().getVertices()) {
                ISOMVertexData ivd = getISOMVertexData(v);
                ivd.distance = 0;
                ivd.visited = false;
            }
            break;
        } catch (ConcurrentModificationException cme) {
        }
    }
    adjustVertex(winner, tempXYD);
}

From source file:org.eclipse.titanium.graph.gui.layouts.BaseHierarchicalLayout.java

/**
 * Implementation of sum distance. This distance is defined as the sum of
 * individual distances to the predecessor nodes
 * /*www . j  ava2s. co m*/
 * @param pos
 *            : The suspected position of the node
 * @param neighbours
 *            : The list of used neighbour nodes (predecessors, or
 *            successors)
 * @return The distance
 */
protected double getSumDistance(final double pos, final Collection<V> neighbours) {
    double distance = 0;

    for (final V node : neighbours) {
        final Point2D pn = places.get(node);
        if (pn == null) {
            continue;
        }
        distance += Math.abs(pn.getX() - pos);
    }
    return distance;
}

From source file:edu.uci.ics.jung.algorithms.layout.SpringLayout.java

protected void relaxEdges() {
    try {//from  w  ww.  j  av  a2 s.c o m
        for (E e : getGraph().getEdges()) {
            Pair<V> endpoints = getGraph().getEndpoints(e);
            V v1 = endpoints.getFirst();
            V v2 = endpoints.getSecond();

            Point2D p1 = transform(v1);
            Point2D p2 = transform(v2);
            if (p1 == null || p2 == null)
                continue;
            double vx = p1.getX() - p2.getX();
            double vy = p1.getY() - p2.getY();
            double len = Math.sqrt(vx * vx + vy * vy);

            double desiredLen = lengthFunction.transform(e);

            // round from zero, if needed [zero would be Bad.].
            len = (len == 0) ? .0001 : len;

            double f = force_multiplier * (desiredLen - len) / len;

            f = f * Math.pow(stretch, (getGraph().degree(v1) + getGraph().degree(v2) - 2));

            // the actual movement distance 'dx' is the force multiplied by the
            // distance to go.
            double dx = f * vx;
            double dy = f * vy;
            SpringVertexData v1D, v2D;
            v1D = springVertexData.get(v1);
            v2D = springVertexData.get(v2);

            v1D.edgedx += dx;
            v1D.edgedy += dy;
            v2D.edgedx += -dx;
            v2D.edgedy += -dy;
        }
    } catch (ConcurrentModificationException cme) {
        relaxEdges();
    }
}

From source file:org.owasp.benchmark.score.report.ScatterHome.java

private void makeDataLabels(Set<Report> toolResults, XYPlot xyplot) {
    HashMap<Point2D, String> map = makePointList(toolResults);
    for (Entry<Point2D, String> e : map.entrySet()) {
        if (e.getValue() != null) {
            Point2D p = e.getKey();
            String label = sort(e.getValue());
            XYTextAnnotation annotation = new XYTextAnnotation(label, p.getX(), p.getY());
            annotation.setTextAnchor(p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER);
            annotation.setBackgroundPaint(Color.white);
            if (label.toCharArray()[0] == averageLabel) {
                annotation.setPaint(Color.magenta);
            } else {
                annotation.setPaint(Color.blue);
            }//from  w  ww  .  j av  a  2  s .com
            annotation.setFont(theme.getRegularFont());
            xyplot.addAnnotation(annotation);
        }
    }
}

From source file:edu.uci.ics.jung.algorithms.layout.FRLayout.java

protected void calcRepulsion(V v1) {
    FRVertexData fvd1 = getFRData(v1);/*from   w  ww .  jav a  2s  . c  om*/
    if (fvd1 == null)
        return;
    fvd1.setLocation(0, 0);

    try {
        for (V v2 : getGraph().getVertices()) {

            //                if (isLocked(v2)) continue;
            if (v1 != v2) {
                Point2D p1 = transform(v1);
                Point2D p2 = transform(v2);
                if (p1 == null || p2 == null)
                    continue;
                double xDelta = p1.getX() - p2.getX();
                double yDelta = p1.getY() - p2.getY();

                double deltaLength = Math.max(EPSILON, Math.sqrt((xDelta * xDelta) + (yDelta * yDelta)));

                double force = (repulsion_constant * repulsion_constant) / deltaLength;

                if (Double.isNaN(force)) {
                    throw new RuntimeException(
                            "Unexpected mathematical result in FRLayout:calcPositions [repulsion]");
                }

                fvd1.offset((xDelta / deltaLength) * force, (yDelta / deltaLength) * force);
            }
        }
    } catch (ConcurrentModificationException cme) {
        calcRepulsion(v1);
    }
}

From source file:org.bigwiv.blastgraph.gui.graphvisualization.EWLayout.java

protected void calcAttraction(E e) {
    ValueEdge edge = (ValueEdge) e;/*from w  w  w  .  j  av  a 2s .  com*/

    double evalue = edge.getExpectValue();
    double ew; // edge weight

    if (evalue <= 0) {
        ew = 1;
    } else {
        ew = (Math.log10(maxEvalue) - Math.log10(evalue)) / (Math.log10(maxEvalue) - Math.log10(minEvalue));
    }

    Pair<V> endpoints = getGraph().getEndpoints(e);
    V v1 = endpoints.getFirst();
    V v2 = endpoints.getSecond();
    boolean v1_locked = isLocked(v1);
    boolean v2_locked = isLocked(v2);

    if (v1_locked && v2_locked) {
        // both locked, do nothing
        return;
    }
    Point2D p1 = transform(v1);
    Point2D p2 = transform(v2);
    if (p1 == null || p2 == null)
        return;
    double xDelta = p1.getX() - p2.getX();
    double yDelta = p1.getY() - p2.getY();

    double deltaLength = Math.max(EPSILON, Math.sqrt((xDelta * xDelta) + (yDelta * yDelta)));

    // force by edge weight
    double force = (deltaLength * deltaLength) * ew / attraction_constant;

    if (Double.isNaN(force)) {
        throw new IllegalArgumentException("Unexpected mathematical result in FRLayout:calcPositions [force]");
    }

    double dx = (xDelta / deltaLength) * force;
    double dy = (yDelta / deltaLength) * force;
    if (v1_locked == false) {
        VertexData fvd1 = getData(v1);
        fvd1.offset(-dx, -dy);
    }
    if (v2_locked == false) {
        VertexData fvd2 = getData(v2);
        fvd2.offset(dx, dy);
    }
}

From source file:org.jcurl.model.PathSegment.java

protected PathSegment(boolean isRockCoordinates, double t0, Point2D x0, Point2D v0, final R1R1Function[] c) {
    super(c);/*ww w.ja  v a2  s.co m*/
    if (c.length != 3)
        throw new IllegalArgumentException("rock path curve must have 3 dimensions, but had " + c.length);
    this.isRockCoordinates = isRockCoordinates;
    this.rc2wc = new AffineTransform();
    final double vabs = v0.distance(0, 0);
    if (vabs != 0.0)
        rc2wc.rotate(-Math.acos((v0.getX() * 0 + v0.getY() * 1) / vabs), x0.getX(), x0.getY());
    rc2wc.translate(x0.getX(), x0.getY());
    this.t0 = t0;
}

From source file:com.google.code.facebook.graph.sna.applet.VertexCollapseDemo.java

public VertexCollapseDemo() {

    // create a simple graph for the demo
    graph = TestGraphs.getOneComponentGraph();
    collapser = new GraphCollapser(graph);

    layout = new FRLayout(graph);

    Dimension preferredSize = new Dimension(400, 400);
    final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize);
    vv = new VisualizationViewer(visualizationModel, preferredSize);

    vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction());

    final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance();
    final Set exclusions = new HashSet();
    eif.setPredicate(new Predicate() {

        public boolean evaluate(Object e) {

            return exclusions.contains(e);
        }//from  ww w.  j  av a  2s .c  om
    });

    vv.getRenderContext().setParallelEdgeIndexFunction(eif);

    vv.setBackground(Color.white);

    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller() {

        /* (non-Javadoc)
         * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction#getToolTipText(java.lang.Object)
         */
        @Override
        public String transform(Object v) {
            if (v instanceof Graph) {
                return ((Graph) v).getVertices().toString();
            }
            return super.transform(v);
        }
    });

    /**
     * the regular graph mouse for the normal view
     */
    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    vv.setGraphMouse(graphMouse);

    Container content = getContentPane();
    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    content.add(gzsp);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(graphMouse.getModeListener());
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JButton collapse = new JButton("Collapse");
    collapse.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = new HashSet(vv.getPickedVertexState().getPicked());
            if (picked.size() > 1) {
                Graph inGraph = layout.getGraph();
                Graph clusterGraph = collapser.getClusterGraph(inGraph, picked);

                Graph g = collapser.collapse(layout.getGraph(), clusterGraph);
                double sumx = 0;
                double sumy = 0;
                for (Object v : picked) {
                    Point2D p = (Point2D) layout.transform(v);
                    sumx += p.getX();
                    sumy += p.getY();
                }
                Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size());
                vv.getRenderContext().getParallelEdgeIndexFunction().reset();
                layout.setGraph(g);
                layout.setLocation(clusterGraph, cp);
                vv.getPickedVertexState().clear();
                vv.repaint();
            }
        }
    });

    JButton compressEdges = new JButton("Compress Edges");
    compressEdges.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = vv.getPickedVertexState().getPicked();
            if (picked.size() == 2) {
                Pair pair = new Pair(picked);
                Graph graph = layout.getGraph();
                Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst()));
                edges.retainAll(graph.getIncidentEdges(pair.getSecond()));
                exclusions.addAll(edges);
                vv.repaint();
            }

        }
    });

    JButton expandEdges = new JButton("Expand Edges");
    expandEdges.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = vv.getPickedVertexState().getPicked();
            if (picked.size() == 2) {
                Pair pair = new Pair(picked);
                Graph graph = layout.getGraph();
                Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst()));
                edges.retainAll(graph.getIncidentEdges(pair.getSecond()));
                exclusions.removeAll(edges);
                vv.repaint();
            }

        }
    });

    JButton expand = new JButton("Expand");
    expand.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Collection picked = new HashSet(vv.getPickedVertexState().getPicked());
            for (Object v : picked) {
                if (v instanceof Graph) {

                    Graph g = collapser.expand(layout.getGraph(), (Graph) v);
                    vv.getRenderContext().getParallelEdgeIndexFunction().reset();
                    layout.setGraph(g);
                }
                vv.getPickedVertexState().clear();
                vv.repaint();
            }
        }
    });

    JButton reset = new JButton("Reset");
    reset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            layout.setGraph(graph);
            exclusions.clear();
            vv.repaint();
        }
    });

    JButton help = new JButton("Help");
    help.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog((JComponent) e.getSource(), instructions, "Help",
                    JOptionPane.PLAIN_MESSAGE);
        }
    });

    JPanel controls = new JPanel();
    JPanel zoomControls = new JPanel(new GridLayout(2, 1));
    zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom"));
    zoomControls.add(plus);
    zoomControls.add(minus);
    controls.add(zoomControls);
    JPanel collapseControls = new JPanel(new GridLayout(3, 1));
    collapseControls.setBorder(BorderFactory.createTitledBorder("Picked"));
    collapseControls.add(collapse);
    collapseControls.add(expand);
    collapseControls.add(compressEdges);
    collapseControls.add(expandEdges);
    collapseControls.add(reset);
    controls.add(collapseControls);
    controls.add(modeBox);
    controls.add(help);
    content.add(controls, BorderLayout.SOUTH);
}

From source file:org.jfree.experimental.chart.plot.dial.StandardDialFrame.java

/**
 * Returns the shape for the window for this dial.  Some dial layers will
 * request that their drawing be clipped within this window.
 *
 * @param frame  the reference frame (<code>null</code> not permitted).
 *
 * @return The shape of the dial's window.
 *///from  w w  w  .j a  v a 2  s  . c om
public Shape getWindow(Rectangle2D frame) {

    Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, this.innerRadius, this.innerRadius);
    Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, this.outerRadius, this.outerRadius);
    Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle, this.extent, Arc2D.OPEN);
    Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle + this.extent, -this.extent, Arc2D.OPEN);
    GeneralPath p = new GeneralPath();
    Point2D point1 = inner.getStartPoint();
    p.moveTo((float) point1.getX(), (float) point1.getY());
    p.append(inner, true);
    p.append(outer, true);
    p.closePath();
    return p;

}