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:eu.transkribus.swt_canvas.util.GeomUtils.java

/**
 * Computes the intersection between two lines. The calculated point is
 * approximate, since integers are used. If you need a more precise result,
 * use doubles everywhere. (c) 2007 Alexander Hristov. Use Freely (LGPL
 * license). http://www.ahristov.com//w ww  .j  ava  2 s  . c  o m
 * 
 * @param x1
 *            Point 1 of Line 1
 * @param y1
 *            Point 1 of Line 1
 * @param x2
 *            Point 2 of Line 1
 * @param y2
 *            Point 2 of Line 1
 * @param x3
 *            Point 1 of Line 2
 * @param y3
 *            Point 1 of Line 2
 * @param x4
 *            Point 2 of Line 2
 * @param y4
 *            Point 2 of Line 2
 * @return Point where the segments intersect, or null if they don't
 */
public static Point intersection(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
    int d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
    if (d == 0)
        return null;

    int xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
    int yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;

    return new Point(xi, yi);
}

From source file:com.mycompany.complexity.tool.mvn.TreeLayoutDois.java

protected void buildTree() {
    this.m_currentPoint = new Point(0, 20);
    Collection<V> roots = TreeUtils.getRoots(graph);
    if (roots.size() > 0 && graph != null) {
        calculateDimensionX(roots);//  w w w. jav a  2 s  .  c  om
        for (V v : roots) {
            calculateDimensionX(v);
            m_currentPoint.x += this.basePositions.get(v) / 2 + this.distX;
            buildTree(v, this.m_currentPoint.x);
        }
    }
    int width = 0;
    for (V v : roots) {
        width += basePositions.get(v);
    }
}

From source file:com.anrisoftware.prefdialog.miscswing.lists.PopupMenuList.java

@SuppressWarnings("serial")
private void setupPopup() {
    popup.setMouseFilter(new MouseFilter() {

        @Override/*  w w  w.  j a  v  a  2  s .c o m*/
        public boolean allow(MouseEvent e) {
            if (selectedIndex == -1) {
                return false;
            }
            int mouseIndex = list.locationToIndex(e.getPoint());
            return selectedIndex == mouseIndex && isRightMouseButton(e);
        }
    });
    popup.setPopupMenuPosition(new PopupMenuPosition() {

        @Override
        public Point getPosition(Component c, Point mouseLocation) {
            return new Point(mouseLocation.x, mouseLocation.y);
        }
    });
}

From source file:charts.PieChart3D.java

/**
 * Creates a chart.// ww  w  .ja  v  a 2  s  . c  o  m
 *
 * @param dataset
 *            the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset, PieChartModel model) {

    JFreeChart chart = ChartFactory.createPieChart(model.getTitle(), // chart
            // title
            dataset, // data
            false, // no legend
            true, // tooltips
            false // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("FCA", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("FCH", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("FCS", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("FCG", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setSectionPaint("FCJ", createGradientPaint(new Color(200, 255, 200), Color.BLACK));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {1} ({2}) "));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);

    // add a subtitle giving the data source
    TextTitle source = new TextTitle(model.getSubTitle(), new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

From source file:RMOS.PieChart.java

/**
 * Creates a chart./*from www .j a va 2 s  . com*/
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Eco Systems Statistics", // chart title
            dataset, // data
            false, // no legend
            true, // tooltips
            false // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    plot.setSectionPaint(f1.getStationInGroup().get(1), Color.blue);
    plot.setSectionPaint(f1.getStationInGroup().get(1), Color.GREEN);

    // use gradients and white borders for the section colours
    /*plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));*/
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);

    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: Eco Recycle Station", new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

From source file:com.diversityarrays.kdxplore.heatmap.HeatMapModelData.java

public HeatMapModelData(CurationContext ctx, ValueRetriever<?> xvr, ValueRetriever<?> yvr,
        TraitInstanceValueRetriever<?> tivr) {
    context = ctx;/*from   w  w  w. ja  v a  2 s.c  o m*/
    xValueRetriever = xvr;
    yValueRetriever = yvr;
    traitInstanceValueRetriever = tivr;

    zTraitInstance = traitInstanceValueRetriever.getTraitInstance();

    String traitInstanceName = context.makeTraitInstanceName(zTraitInstance);

    columnRowLabelOffset = new Point(xValueRetriever.getAxisZeroValue(), yValueRetriever.getAxisZeroValue());

    Class<?> valueClass = traitInstanceValueRetriever.getComparableValueClass();

    Dimension size = new Dimension(xValueRetriever.getAxisValueCount(), yValueRetriever.getAxisValueCount());

    model = new DefaultHeatMapModel<PlotOrSpecimen>(size, traitInstanceName,
            traitInstanceValueRetriever.getDisplayName(), yValueRetriever.getDisplayName(),
            xValueRetriever.getDisplayName());

    if (Double.class == valueClass) {

        DoubleGenerator generator = new DoubleGenerator();

        ValueInfo<Double> valueInfo = generator.generate(context, xValueRetriever, yValueRetriever,
                traitInstanceValueRetriever, plotPointsByMark, columnRowLabelOffset);

        Map<Point, List<PlotOrSpecimen>> psListByPoint = valueInfo.plotSpecimensByPoint;

        Function<Point, PlotOrSpecimen> psArrayForPoint = new Function<Point, PlotOrSpecimen>() {
            @Override
            public PlotOrSpecimen apply(Point pt) {
                List<PlotOrSpecimen> list = psListByPoint.get(pt);
                return Check.isEmpty(list) ? null : list.get(0);
                //                    return list.toArray(new PlotOrSpecimen[list.size()]);
            }
        };

        Map<Point, PlotOrSpecimen> contentByPoint = psListByPoint.keySet().stream()
                .collect(Collectors.toMap(Function.identity(), psArrayForPoint));

        Map<PlotOrSpecimen, Double> valueByContent = new HashMap<>();
        for (Point pt : contentByPoint.keySet()) {
            PlotOrSpecimen pos = contentByPoint.get(pt);
            Double value = valueInfo.valuesByPoint.get(pt);
            if (value != null) {
                valueByContent.put(pos, value);
            }
        }

        Function<Double, String> formatter = new Function<Double, String>() {
            Map<Double, String> displayByValue = valueInfo.displayByValue;

            @Override
            public String apply(Double t) {
                return displayByValue.get(t);
            }
        };
        valueModel = new DoubleValueModel<>(valueByContent, formatter);

        model.setCellContent(contentByPoint);

        missingOrBad = valueInfo.missingOrBad;
        suppressed = valueInfo.suppressed;
    } else if (Integer.class == valueClass || traitInstanceValueRetriever.supportsGetAxisValue()) {

        IntegerGenerator generator = new IntegerGenerator();

        ValueInfo<Integer> valueInfo = generator.generate(context, xValueRetriever, yValueRetriever,
                traitInstanceValueRetriever, plotPointsByMark, columnRowLabelOffset);

        Map<Point, List<PlotOrSpecimen>> psListByPoint = valueInfo.plotSpecimensByPoint;

        Function<Point, PlotOrSpecimen> psArrayForPoint = new Function<Point, PlotOrSpecimen>() {
            @Override
            public PlotOrSpecimen apply(Point pt) {
                List<PlotOrSpecimen> list = psListByPoint.get(pt);
                return Check.isEmpty(list) ? null : list.get(0);
                //                    return list.toArray(new PlotOrSpecimen[list.size()]);
            }
        };
        // FIXME for Specimen, we DO want the multiple results
        Map<Point, PlotOrSpecimen> contentByPoint = psListByPoint.keySet().stream()
                .collect(Collectors.toMap(Function.identity(), psArrayForPoint));

        Map<PlotOrSpecimen, Integer> valueByContent = new HashMap<>();
        for (Point pt : contentByPoint.keySet()) {
            PlotOrSpecimen pos = contentByPoint.get(pt);
            Integer value = valueInfo.valuesByPoint.get(pt);
            if (value != null) {
                valueByContent.put(pos, value);
            }
        }

        model.setCellContent(contentByPoint);

        Function<Integer, String> formatter = new Function<Integer, String>() {
            Map<Integer, String> displayByValue = valueInfo.displayByValue;

            @Override
            public String apply(Integer t) {
                return displayByValue.get(t);
            }
        };
        valueModel = new IntegerValueModel<>(valueByContent, formatter);

        missingOrBad = valueInfo.missingOrBad;
        suppressed = valueInfo.suppressed;
    } else {
        throw new RuntimeException(
                "Unsupported Value Retriever: " + traitInstanceValueRetriever.getDisplayName()); //$NON-NLS-1$
    }

}

From source file:KjellDirdalNotepad.java

public Component add(JInternalFrame frame) {
    JInternalFrame[] array = getAllFrames();
    Point p;/*w w  w .  jav a  2  s .  co m*/
    int w;
    int h;

    Component retval = super.add(frame);
    checkDesktopSize();
    if (array.length > 0) {
        p = array[0].getLocation();
        p.x = p.x + FRAME_OFFSET;
        p.y = p.y + FRAME_OFFSET;
    } else {
        p = new Point(0, 0);
    }
    frame.setLocation(p.x, p.y);
    if (frame.isResizable()) {
        w = getWidth() - (getWidth() / 3);
        h = getHeight() - (getHeight() / 3);
        if (w < frame.getMinimumSize().getWidth())
            w = (int) frame.getMinimumSize().getWidth();
        if (h < frame.getMinimumSize().getHeight())
            h = (int) frame.getMinimumSize().getHeight();
        frame.setSize(w, h);
    }
    moveToFront(frame);
    frame.setVisible(true);
    try {
        frame.setSelected(true);
    } catch (PropertyVetoException e) {
        frame.toBack();
    }
    return retval;
}

From source file:edu.ku.brc.af.prefs.PrefsToolbar.java

@Override
protected void paintComponent(final Graphics g) {
    super.paintComponent(g);

    Color base = getBackground();
    Dimension size = getSize();// www  .  j a v a  2s  .c  om

    Color grad_top = base;
    Color grad_bot = UIHelper.makeDarker(base, UIHelper.isMacOS() ? 0.15 : 0.1);
    GradientPaint bg = new GradientPaint(new Point(0, 0), grad_top, new Point(0, size.height), grad_bot);
    Graphics2D g2 = (Graphics2D) g;
    g2.setPaint(bg);
    g2.fillRect(0, 0, size.width, size.height);

    g.setColor(UIHelper.makeDarker(base, 0.5));
    g.drawLine(0, size.height - 1, size.width, size.height - 1);
}

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

/**
 * Test method for/*w  w w . j a v  a2  s  . c  o m*/
 * {@link CollectionUtils2#transformIntoSet(java.lang.Iterable, Transformer)}
 * {@link CollectionUtils2#transformIntoSet(java.lang.Iterable, Function)} .
 */
@Test
public void testTransformIntoSetIterableOfITransformerOfIO() {
    try {
        List<Point> points = new ArrayList<>();
        points.add(new Point(1, 2));
        points.add(new Point(2, 0));
        points.add(null);

        Set<String> strPoints = CollectionUtils2.transformIntoSet(points, TRANSFORMER);

        assertThat(strPoints, Matchers.containsInAnyOrder("1, 2", "2, 0", null));

        strPoints = CollectionUtils2.transformIntoSet(points, FUNCTION);

        assertThat(strPoints, Matchers.containsInAnyOrder("1, 2", "2, 0", null));
    } catch (IllegalArgumentException e) {
        fail("The test isn't correct");
    }
}

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

public void setModelo(List<DamageDetailsVB> model) {
    this.modelo = model;
    for (DamageDetailGraphicsView x : damageDetail) {
        content.remove(x);//w  w w  .  j a v  a  2  s.c  o  m
    }
    damageDetail = new LinkedList<>();
    for (DamageDetailsVB x : modelo) {
        DamageDetailGraphicsView obj = new DamageDetailGraphicsView();
        obj.setPosicion(new Point(x.getX(), x.getY()));
        obj.setContexto(new Point(boundsX, boundsY));
        obj.setBounds(0, 0, content.getWidth(), content.getHeight());
        //obj.setOrientacion(DamageDetailGraphicsView.InferiorIzquierda);
        if (x.getX() <= currentView.getShapeWidth() / 2) {
            if (x.getY() <= currentView.getShapeHeight() / 2) {
                obj.setOrientacion(DamageDetailGraphicsView.SuperiorIzquierda);
                //obj.setOrientacion(DamageDetailGraphicsView.SuperiorDerecha);
            } else {
                obj.setOrientacion(DamageDetailGraphicsView.InferiorIzquierda);
                //obj.setOrientacion(DamageDetailGraphicsView.InferiorDerecha);
            }
        } else {
            if (x.getY() <= currentView.getShapeHeight() / 2) {
                obj.setOrientacion(DamageDetailGraphicsView.SuperiorDerecha);
                //obj.setOrientacion(DamageDetailGraphicsView.SuperiorIzquierda);
            } else {
                obj.setOrientacion(DamageDetailGraphicsView.InferiorDerecha);
                //obj.setOrientacion(DamageDetailGraphicsView.InferiorIzquierda);
            }
        }
        obj.setCategoria(x.getCategoria());
        obj.setCaracteristica(x.getCaracteristica());
        damageDetail.add(obj);
        content.add(obj, 1, 0);
    }
    content.repaint();
}