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:simulador.controle.GeradorGraficos.java

private Map<Float, Float> obterValoresCelulasRadial(Point pontoInicial, Point pontoFinal) {

    if (DEBUG) {//from w  ww.j  a v a  2 s.com
        System.out.println("GeradorGraficos.obterValoresCelulasRadial");
    }

    // System.out.println("pontoInicial: ("+pontoInicial.x+", "+pontoInicial.y+")");
    // System.out.println("pontoFinal: ("+pontoFinal.x+", "+pontoFinal.y+")");
    float distanciaMaxPixels = (float) new Point(0, 0)
            .distance(new Point(painelDesign.getImagem().getWidth(), painelDesign.getImagem().getHeight()));
    float distanciaMaxMetros = (float) new Point2D.Float(0, 0)
            .distance(new Point2D.Float(ambiente.getLargura(), ambiente.getComprimento()));

    Map<Float, Float> valoresCelulasRadial = new HashMap();

    Line2D radial = new Line2D.Float(pontoInicial, pontoFinal);
    Rectangle boxRadial = radial.getBounds();

    int[] celRadialIncial = painelDesign.buscarCelula(new Point(boxRadial.x, boxRadial.y));
    int[] celRadialFinal = painelDesign
            .buscarCelula(new Point((int) boxRadial.getMaxX(), (int) boxRadial.getMaxY()));

    // System.out.println("celRadialInicial["+celRadialIncial[0]+"]["+celRadialIncial[1]+"]");
    // System.out.println("celRadialFinal["+celRadialFinal[0]+"]["+celRadialFinal[1]+"]");

    int linIncialRadial = celRadialIncial[0];
    int colIncialRadial = celRadialIncial[1];
    int linFinalRadial = celRadialFinal[0];
    int colFinalRadial = celRadialFinal[1];

    int[] coordCelPontoInicial = painelDesign.buscarCelula(pontoInicial);
    PainelDesign.Celula celPontoInicial = painelDesign.getMatrizCelulas().get(coordCelPontoInicial[0])
            .get(coordCelPontoInicial[1]);

    for (int i = linIncialRadial; i <= linFinalRadial; i++) {
        for (int j = colIncialRadial; j <= colFinalRadial; j++) {

            PainelDesign.Celula cel = painelDesign.getMatrizCelulas().get(i).get(j);

            //System.out.println("cel["+i+"]["+j+"]  interceptada ?");

            if (radial.intersects(cel)) {

                float distanciaPontosPixels = (float) new Point(celPontoInicial.x, celPontoInicial.y)
                        .distance(new Point(cel.x, cel.y));
                float distanciaPontosMetros = (float) ControladorDesign
                        .converterCoordenadas(distanciaPontosPixels, distanciaMaxPixels, distanciaMaxMetros);

                //System.out.println("sim");
                // System.out.println("potencia: "+cel.obterValor("potencia"));
                // System.out.println("distancia: "+distanciaPontosMetros);

                //cel.setCorFundoRGB(Color.BLUE.getRGB());

                valoresCelulasRadial.put(distanciaPontosMetros, //cel.obterValor("distancia"),
                        cel.obterValor("potencia"));

            }

        }
    }

    return valoresCelulasRadial;

}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * Translates mouse coordinates to chart coordinates (xy-axis)
 * // w  ww  .  j  ava 2s  .c  om
 * @param myChart
 * @param mouseX
 * @param mouseY
 * @return Range as chart coordinates
 * @throws Exception
 */
public static Point2D mouseXYToPlotXY(ChartPanel myChart, int mouseX, int mouseY) throws Exception {
    Point2D p = myChart.translateScreenToJava2D(new Point(mouseX, mouseY));

    XYPlot plot = null;
    // find plot as parent of axis
    ChartEntity entity = findChartEntity(myChart, mouseX, mouseY);
    if (entity instanceof AxisEntity) {
        Axis a = ((AxisEntity) entity).getAxis();
        if (a.getPlot() instanceof XYPlot)
            plot = (XYPlot) a.getPlot();
    }

    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    int subplot = info.getPlotInfo().getSubplotIndex(p);
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    if (subplot != -1)
        dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea();

    if (plot == null)
        plot = findXYSubplot(myChart.getChart(), info, p.getX(), p.getY());

    // coordinates
    double cx = 0;
    double cy = 0;
    if (plot != null) {
        // find axis
        ValueAxis domainAxis = plot.getDomainAxis();
        ValueAxis rangeAxis = plot.getRangeAxis();
        RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
        // parent?
        if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
            XYPlot pp = ((XYPlot) plot.getParent());
            domainAxis = pp.getDomainAxis();
            domainAxisEdge = pp.getDomainAxisEdge();
        }
        if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) {
            XYPlot pp = ((XYPlot) plot.getParent());
            rangeAxis = pp.getRangeAxis();
            rangeAxisEdge = pp.getRangeAxisEdge();
        }

        if (domainAxis != null)
            cx = domainAxis.java2DToValue(p.getX(), dataArea, domainAxisEdge);
        if (rangeAxis != null)
            cy = rangeAxis.java2DToValue(p.getY(), dataArea, rangeAxisEdge);
    } else {
        throw new Exception("no xyplot found");
    }
    return new Point2D.Double(cx, cy);

}

From source file:contactangle.ImageControl.java

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

    if (img != null)
        g.drawImage(img, 0, 0, this);
    else/* w w w  . j a va2 s.  c o m*/
        g.drawString("NO IMAGE", 0, 15);

    g.setColor(Color.RED);

    if (x1 < x2 && y1 < y2)
        g.drawRect(x1, y1, x2 - x1, y2 - y1);
    else if (x1 >= x2 && y1 < y2)
        g.drawRect(x2, y1, x1 - x2, y2 - y1);
    else if (x1 < x2 && y1 >= y2)
        g.drawRect(x1, y2, x2 - x1, y1 - y2);
    else
        g.drawRect(x2, y2, x1 - x2, y1 - y2);

    if (valid && img != null) {

        if (x1 >= x2) {
            int temp = x1;
            x1 = x2;
            x2 = temp;
        }
        if (y1 >= y2) {
            int temp = y1;
            y1 = y2;
            y2 = temp;
        }

        choosenPoints = new ArrayList<Point>();
        for (int y = y1; y < y2; y++) {
            for (int x = x1; x < x2; x++) {
                int pixelData = img.getRGB(x, y);
                if (pixelData == -1)
                    choosenPoints.add(new Point(x, y));
            }
        }

        SimpleRegression reg = new SimpleRegression();
        for (Point p : choosenPoints) {
            reg.addData(p.x, p.y);
        }

        int firstX = choosenPoints.get(0).x;
        int firstY = choosenPoints.get(0).y;
        double slope = reg.getSlope();
        g.setColor(Color.GREEN);
        g.drawLine(firstX, firstY, firstX + (70), firstY + (int) (slope * (70)));
        g.drawLine(firstX, firstY, firstX - (70), firstY - (int) (slope * (70)));

        double contactDegrees = (Math.atan(reg.getSlope()) / (2 * Math.PI)) * 360.0;

        DecimalFormat d = new DecimalFormat("##.###");

        g.drawString("Contact Angle = ", 25, 25);
        g.drawString(d.format(contactDegrees) + " degrees", 25, 38);
    }

}

From source file:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java

/**
 * Returns a point based on (x, y) but constrained to be within the bounds
 * of the given rectangle.  This method could be moved to JCommon.
 *
 * @param x  the x-coordinate.//w  w  w  .  ja  v a 2s  . c o  m
 * @param y  the y-coordinate.
 * @param area  the rectangle (<code>null</code> not permitted).
 *
 * @return A point within the rectangle.
 */
protected Point getPointInRectangle(int x, int y, Rectangle2D area) {
    x = (int) Math.max(Math.ceil(area.getMinX()), Math.min(x, Math.floor(area.getMaxX())));
    y = (int) Math.max(Math.ceil(area.getMinY()), Math.min(y, Math.floor(area.getMaxY())));
    return new Point(x, y);
}

From source file:Main.java

/**
 * @return//from w  w w .j  a v a  2s .c o m
 */
public static GraphicsDevice getScreenByLocation(int x, int y) {
    return getScreenByLocation(new Point(x, y));
}

From source file:app.bean.AdminPanelHandler.java

public static void run() {
    new Thread() {
        @Override/*  www  .  j  a v a2s.c  o m*/
        public void run() {
            while (true) {

                if (STOP_ALL_ROUNDS) {
                    HostGame.stopRounds();
                    STOP_ALL_ROUNDS = false;
                    Log.write("--ALL CURRENT ROUNDS STOPPED!");
                }

                if (RESET_ALL_GAME_DATA) {

                    HostGame.stopRounds();

                    while (!READY_TO_CLEAR_GAME_DATA) {
                    }
                    roundRepository.deleteAll();
                    playerRepository.deleteAll();
                    nodeRepository.deleteAll();
                    settingsRepository.deleteAll();
                    RESET_ALL_GAME_DATA = false;
                    READY_TO_CLEAR_GAME_DATA = false;
                    Log.write("--ALL GAME DATA CLEARED!");
                } else {
                    READY_TO_CLEAR_GAME_DATA = false;
                }

                if (SAVE_NEW_SETTINGS) {
                    SETTINGS_TO_BE_SET.setId(1L);
                    settingsRepository.save(SETTINGS_TO_BE_SET);
                    SAVE_NEW_SETTINGS = false;
                    Log.write("--NEW SETTINGS SAVED!");
                }

                if (ADD_MOCKED_ROUND) {
                    Settings settings = settingsRepository.findOne(1L);
                    Round round = new Round(settings);
                    roundRepository.save(round);
                    RoundMap map = new RoundMap(new Point(10, 10), round.getId());
                    round.setMap(map);

                    round.getPlayerIds().add(1L);
                    round.getPlayerIds().add(2L);
                    round.getMap().generate(round.getPlayerIds());
                    roundRepository.save(round);
                    HostGame.storeRound(round);
                    ADD_MOCKED_ROUND = false;
                    Log.write("Game " + round.getId() + " initiated manually.");
                }

                if (STOP_SELECTED_ROUND) {
                    int selected = TableActiveMatches.self.getSelectedRow();
                    HostGame.stopRound(selected);
                    STOP_SELECTED_ROUND = false;
                }

                try {
                    Thread.sleep(300);
                } catch (InterruptedException ex) {
                    Logger.getLogger(AdminPanelHandler.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }.start();
}

From source file:modelibra.designer.metaconceptgraphic.MetaConceptGraphic.java

public Point getCenter() {
    int cx = getLocation().x + (getSize().width / 2);
    int cy = getLocation().y + getSize().height / 2;
    return new Point(cx, cy);
}

From source file:net.sf.maltcms.chromaui.charts.tooltips.RTIXYTooltipGenerator.java

/**
 *
 * @param xyd//  w w w  .  j a v a 2 s.  co  m
 * @param i
 * @param i1
 * @return
 */
@Override
public String generateToolTip(XYDataset xyd, int i, int i1) {
    Point p = new Point(i, i1);
    if (hm.containsKey(p)) {
        SoftReference<String> sr = hm.get(p);
        if (sr.get() != null) {
            return sr.get();
        }
    } else {
        StringBuilder sb = new StringBuilder();
        int x = (int) xyd.getXValue(i, i1);
        int y = (int) xyd.getYValue(i, i1);
        double z = Double.NaN;
        if (xyd instanceof XYZDataset) {
            z = ((XYZDataset) xyd).getZValue(i, i1);
        }
        if (x >= 0 && x < lookup.length && y >= 0 && y < scansPerModulation) {
            sb.append("[ SCAN1: ");
            sb.append(x);
            sb.append(", SCAN2: " + y + " ]");
            sb.append(" at [ RT1: ");
            sb.append(lookup[x]);
            sb.append(" s, RT2: ");
            float off = (this.modulationTime * ((float) y / (float) (this.scansPerModulation)));
            sb.append(lookup[x] + off);
            sb.append("s ]");
            if (xyd instanceof XYZDataset) {
                sb.append(" = ");
                sb.append(z);
            }
            String s = sb.toString();
            SoftReference<String> sr = new SoftReference<>(s);
            hm.put(p, sr);
            return s;
        }
        return "";
    }
    return null;

}

From source file:statUtil.TurnMovementPlot.java

public TurnMovementPlot(String title) throws IOException {
    super(title);
    Data data = CSVData.getCSVData(TURN_CSV_LOG);
    JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y",
            XYDatasetGenerator.generateXYDataset(data.csvData));
    final XYPlot xyPlot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesStroke(0, new BasicStroke(3f));
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, true);
    Shape cross = ShapeUtilities.createDiagonalCross(2f, 0.5f);
    renderer.setSeriesShape(1, cross);/*from ww w.  j  a  v  a  2 s . co  m*/
    xyPlot.setRenderer(renderer);
    xyPlot.setQuadrantOrigin(new Point(0, 0));

    int i = 0;
    for (Double[] csvRow : data.csvData) {
        if (i % 20 == 1) {
            final XYTextAnnotation annotation = new XYTextAnnotation(Double.toString(csvRow[3]), csvRow[0],
                    csvRow[1]);
            annotation.setFont(new Font("SansSerif", Font.PLAIN, 10));
            xyPlot.addAnnotation(annotation);
        }
        i++;
    }

    int width = (int) Math.round(data.maxX - data.minX) + 50;
    int height = (int) Math.round(data.maxY - data.minY) + 50;
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(width, height));
    setContentPane(chartPanel);
    File XYChart = new File(FILE_PATH + "\\TurnMovementPlot.png");
    ChartUtilities.saveChartAsPNG(XYChart, chart, width, height);
}

From source file:uom.research.thalassemia.util.PieChartCreator.java

/**
 * Creates a chart./*from w  w  w .  j  a  va2  s  .c om*/
 *
 * @param dataset the dataset.
 *
 * @return A chart.
 */
private JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart(title, // chart title
            dataset, // data
            true, // 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
    int itemIndex = 0;
    for (Object col : pieDataset.getKeys()) {
        plot.setSectionPaint(col.toString(), gradientPaints[itemIndex]);
        if (itemIndex == pieDataset.getItemCount() - 1) {
            itemIndex = 0;
        }
        itemIndex++;
    }

    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: http://www.bbc.co.uk/news/business-15489523",
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}