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:PieChartDemo1.java

/**
 * Creates a chart./*www .  ja va2  s  .c o  m*/
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", // 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("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: 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;

}

From source file:br.jabuti.graph.layout.jung.HierachicalGraphLayout.java

protected void buildTree() {
    m_currentPoint = new Point(0, 20);
    Collection<V> roots = new ArrayList<V>();
    roots.add(rootVertex);//from   w w w.j a v  a2 s  . c  o m
    if (roots.size() > 0) {
        calculateDimensionX(roots);
        for (V v : roots) {
            calculateDimensionX(v);
            m_currentPoint.x += basePositions.get(v) / 2 + 50;
            buildTree(v, m_currentPoint.x);
        }
    }

    int width = 0;
    for (V v : roots) {
        width += basePositions.get(v);
    }
}

From source file:de.mfo.jsurf.grid.RotationGrid.java

static BufferedImage createBufferedImageFromRGB(ImgBuffer ib) {
    int w = ib.width;
    int h = ib.height;

    DirectColorModel colormodel = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    SampleModel sampleModel = colormodel.createCompatibleSampleModel(w, h);
    DataBufferInt data = new DataBufferInt(ib.rgbBuffer, w * h);
    WritableRaster raster = WritableRaster.createWritableRaster(sampleModel, data, new Point(0, 0));
    return new BufferedImage(colormodel, raster, false, null);
}

From source file:icaro.aplicaciones.recursos.recursoEstadistica.jFreeChart.demo.PieChartDemo1.java

/**
 * Creates a chart.// w ww  . j a v  a  2 s . co m
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", // 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("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: 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;

}

From source file:TextFormat.java

public void paint(Graphics g) {
    if (text == null || text.length() == 0)
        return;/*  w ww .jav a 2  s .c  o  m*/
    if (layouts == null)
        getLayouts(g);

    Point pen = new Point(0, 0);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(java.awt.Color.black); // or a property
    g2d.setFont(font);

    Iterator it = layouts.iterator();
    while (it.hasNext()) {
        TextLayout layout = (TextLayout) it.next();
        pen.y += (layout.getAscent());
        g2d.setFont(font);
        layout.draw(g2d, pen.x, pen.y);
        pen.y += layout.getDescent();
        //pen.y += leading;
    }
}

From source file:LayeredPaneDemo.java

public LayeredPaneDemo() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    // Create and load the duke icon.
    final ImageIcon icon = new ImageIcon("yourFile.gif");

    // Create and set up the layered pane.
    layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(300, 310));
    layeredPane.setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke"));
    layeredPane.addMouseMotionListener(this);

    // This is the origin of the first label added.
    Point origin = new Point(10, 20);

    // This is the offset for computing the origin for the next label.
    int offset = 35;

    // Add several overlapping, colored labels to the layered pane
    // using absolute positioning/sizing.
    for (int i = 0; i < layerStrings.length; i++) {
        JLabel label = createColoredLabel(layerStrings[i], layerColors[i], origin);
        layeredPane.add(label, new Integer(i));
        origin.x += offset;/*w  w w .j  a v a 2 s . c  o  m*/
        origin.y += offset;
    }

    // Create and add the Duke label to the layered pane.
    dukeLabel = new JLabel(icon);
    if (icon != null) {
        dukeLabel.setBounds(15, 225, icon.getIconWidth(), icon.getIconHeight());
    } else {
        System.err.println("Duke icon not found; using black square instead.");
        dukeLabel.setBounds(15, 225, 30, 30);
        dukeLabel.setOpaque(true);
        dukeLabel.setBackground(Color.BLACK);
    }
    layeredPane.add(dukeLabel, new Integer(2), 0);

    // Add control pane and layered pane to this JPanel.
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(createControlPanel());
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(layeredPane);
}

From source file:ded.model.Entity.java

/** Return the point at the center of the Entity's bounding box. */
public Point getCenter() {
    return new Point(this.loc.x + this.size.width / 2, this.loc.y + this.size.height / 2);
}

From source file:com.threerings.media.tile.tools.xml.SwissArmyTileSetRuleSet.java

@Override
public void addRuleInstances(Digester digester) {
    super.addRuleInstances(digester);

    digester.addRule(_path + "/widths", new CallMethodSpecialRule() {
        @Override/* w w w .j  a  v  a 2  s. c om*/
        public void parseAndSet(String bodyText, Object target) {
            int[] widths = StringUtil.parseIntArray(bodyText);
            ((SwissArmyTileSet) target).setWidths(widths);
        }
    });

    digester.addRule(_path + "/heights", new CallMethodSpecialRule() {
        @Override
        public void parseAndSet(String bodyText, Object target) {
            int[] heights = StringUtil.parseIntArray(bodyText);
            ((SwissArmyTileSet) target).setHeights(heights);
        }
    });

    digester.addRule(_path + "/tileCounts", new CallMethodSpecialRule() {
        @Override
        public void parseAndSet(String bodyText, Object target) {
            int[] tileCounts = StringUtil.parseIntArray(bodyText);
            ((SwissArmyTileSet) target).setTileCounts(tileCounts);
        }
    });

    digester.addRule(_path + "/offsetPos", new CallMethodSpecialRule() {
        @Override
        public void parseAndSet(String bodyText, Object target) {
            int[] values = StringUtil.parseIntArray(bodyText);
            SwissArmyTileSet starget = (SwissArmyTileSet) target;
            if (values.length == 2) {
                starget.setOffsetPos(new Point(values[0], values[1]));
            } else {
                log.warning("Invalid 'offsetPos' definition '" + bodyText + "'.");
            }
        }
    });

    digester.addRule(_path + "/gapSize", new CallMethodSpecialRule() {
        @Override
        public void parseAndSet(String bodyText, Object target) {
            int[] values = StringUtil.parseIntArray(bodyText);
            SwissArmyTileSet starget = (SwissArmyTileSet) target;
            if (values.length == 2) {
                starget.setGapSize(new Dimension(values[0], values[1]));
            } else {
                log.warning("Invalid 'gapSize' definition '" + bodyText + "'.");
            }
        }
    });
}

From source file:net.pandoragames.far.ui.swing.dialog.SubWindow.java

/**
 * Positions this FileWindow on the screen. The position is choosen with respect to
 * the specified screen center, the position of the owner and the position of the last 
 * visible subwindow of the owner, if any.
 * @param screenCenter coordinates of the screen center
 *//*  ww w . j a  v  a 2  s  .  c om*/
protected void placeOnScreen(Point screenCenter) {
    Window parent = getOwner();
    Point indent = parent.getLocationOnScreen();
    Point leftUpper = new Point(200, 50);
    Window sister = getLatestPeer();
    if (sister != null) {
        try {
            leftUpper = sister.getLocationOnScreen();
            indent = new Point(25, 25);
        } catch (IllegalComponentStateException icsx) {
            leftUpper = new Point(screenCenter);
        }
    }
    //      
    //      Window[] peers = parent.getOwnedWindows();
    //      if( peers.length > 1 ) {
    //         int count = peers.length -2;
    //         Window sister = null;
    //         do {
    //            sister = peers[count];
    //            count--;
    //         } while ((count >= 0) 
    //                     && ((sister == null) || (! sister.isShowing())));
    //         if((sister != null) && (sister.isShowing())) {
    //            try {
    //               leftUpper = sister.getLocationOnScreen();
    //               indent = new Point(25,25);
    //            } catch (IllegalComponentStateException icsx) {
    //               leftUpper = new Point(screenCenter);
    //            }
    //         }
    //      } 
    if (leftUpper == null) {
        logger.warn("Location was null, using screen center");
        leftUpper = new Point(screenCenter);
    }
    if (leftUpper.x > screenCenter.x)
        indent.x = -indent.x;
    if (leftUpper.y > screenCenter.y)
        indent.y = -indent.y;
    setLocation(leftUpper.x + indent.x, leftUpper.y + indent.y);
}

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

public void testRedoAddTable() throws SQLObjectException {
    SQLTable t = new SQLTable(ppdb, "test_me", "", "TABLE", true);

    TablePane tp = new TablePane(t, pp.getContentPane());

    final SPObject root = SQLPowerUtils.getAncestorList(ppdb).get(0);
    root.setMagicEnabled(false);//from ww  w.  ja v a2s .c  o m
    root.begin("Testing transaction");
    ppdb.addChild(t);
    pp.addTablePane(tp, new Point(99, 98));
    root.commit();
    root.setMagicEnabled(true);

    // this isn't the point of the test, but adding the tablepane has to work!
    assertNotNull(ppdb.getTableByName("test_me"));
    assertNotNull(pp.findTablePane(t));
    //undo the add child and the move table pane
    System.out.println("Undo action is " + session.getUndoManager().getUndoPresentationName());
    session.getUndoManager().undo();
    System.out.println("After undo, undo action is " + session.getUndoManager().getUndoPresentationName());
    assertNull(ppdb.getTableByName("test_me"));
    assertNull(pp.findTablePane(t));
    // redo the add table and the move
    session.getUndoManager().redo();
    tp = pp.findTablePane(t);
    assertNotNull("Table pane didn't come back!", tp);
    assertEquals("Table came back, but in wrong location", new Point(99, 98), tp.getLocation());
}