Example usage for java.awt Rectangle Rectangle

List of usage examples for java.awt Rectangle Rectangle

Introduction

In this page you can find the example usage for java.awt Rectangle Rectangle.

Prototype

public Rectangle(Point p, Dimension d) 

Source Link

Document

Constructs a new Rectangle whose upper-left corner is specified by the Point argument, and whose width and height are specified by the Dimension argument.

Usage

From source file:org.exist.xquery.modules.jfreechart.render.SVGrenderer.java

@Override
public void render(JFreeChart chart, Configuration config, OutputStream os) throws IOException {

    Rectangle bounds = new Rectangle(config.getImageWidth(), config.getImageHeight());

    // Get a DOMImplementation and create an XML document
    DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
    Document document = domImpl.createDocument(null, "svg", null);

    // Create an instance of the SVG Generator
    SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

    // draw the chart in the SVG generator
    chart.draw(svgGenerator, bounds);/* w w  w. java  2  s .  co m*/

    Writer out = new OutputStreamWriter(os, "UTF-8");
    svgGenerator.stream(out, true /* use css */);
    os.flush();
    os.close();
}

From source file:de.unibayreuth.bayeos.goat.chart.StatusXYPlot.java

private void addLegendItem(String text, Color col) {

    legendcol.add(new LegendItem(text, text, new Rectangle(10, 10), true, col, col, new BasicStroke(2.0f)));

}

From source file:de.cebitec.readXplorer.plotting.ChartExporter.java

@Override
public void run() {
    notifyObservers(ChartExportStatus.RUNNING);
    Rectangle bounds = new Rectangle(1920, 1080);
    DOMImplementation dom = GenericDOMImplementation.getDOMImplementation();
    Document document = dom.createDocument(null, "svg", null);
    SVGGraphics2D generator = new SVGGraphics2D(document);
    chart.draw(generator, bounds);/* w ww  . j  av a  2  s  .c  o m*/
    try (OutputStream outputStream = Files.newOutputStream(file, StandardOpenOption.CREATE)) {
        Writer out = new OutputStreamWriter(outputStream, "UTF-8");
        generator.stream(out, true);
        outputStream.flush();
        notifyObservers(ChartExportStatus.FINISHED);
    } catch (IOException ex) {
        notifyObservers(ChartExportStatus.FAILED);
    }
}

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

public Rectangle getRectangle() {
    return new Rectangle(getLocation(), getSize());
}

From source file:GUIUtils.java

/**
 * Centers passed internal frame within its desktop area. If centering would
 * cause the title bar to go off the top of the screen then move the window
 * down./*from w  w  w  . jav a2 s.  c o m*/
 * 
 * @param frame
 *          The internal frame to be centered.
 * 
 * @throws IllegalArgumentException
 *           If <TT>frame</TT> is <TT>null</TT>.
 */
public static void centerWithinDesktop(JInternalFrame frame) {
    if (frame == null) {
        throw new IllegalArgumentException("null JInternalFrame passed");
    }
    final Container parent = frame.getDesktopPane();
    if (parent != null && parent.isVisible()) {
        center(frame, new Rectangle(new Point(0, 0), parent.getSize()));
    }
}

From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeChartData.java

public void writeGraphics(Graphics2D g) throws Exception {
    getCustomisedJFreeChart().draw(g, new Rectangle(DEFAULT_X_SIZE, DEFAULT_Y_SIZE));
    //throw new UnsupportedOperation("JFreeChart does not support SVG");
}

From source file:esprit.rt.gui.StatistiquesRestaurateur.java

/**
 * Creates new form StatistiquesRestaurateur
 *//*from   www .  j  a  v  a  2  s . c  om*/
public StatistiquesRestaurateur() {
    initComponents();
    setLocationRelativeTo(null);
    dataset = new DefaultPieDataset();
    //Statique
    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} places rservs ({2})",
            new DecimalFormat("0"), new DecimalFormat("0%"));
    PieSectionLabelGenerator gen2 = new StandardPieSectionLabelGenerator("{0}: {1} DT de revenue ({2})",
            new DecimalFormat("0"), new DecimalFormat("0%"));
    for (Entry e : new StatistiqueDAO().mostBooked().entrySet()) {
        if (Float.parseFloat((String) e.getValue()) > max1) {
            i1 = j;
            max1 = Float.parseFloat((String) e.getValue());
        }

        dataset.setValue((Comparable) e.getKey(), Float.parseFloat((String) e.getValue()));
        j++;
    }

    graphe = ChartFactory.createPieChart3D("Les restaurant les plus rserv", dataset, true, true, false);
    PiePlot plot = (PiePlot) graphe.getPlot();
    plot.setLabelGenerator(gen);
    cp = new ChartPanel(graphe);
    cp.setBounds(new Rectangle(490, 400));
    PieChart.getContentPane().add(cp);
    cp.setVisible(true);
    PieChart.setVisible(true);

    title.setHorizontalAlignment(JLabel.CENTER);
    try {
        title.setFont(new FontsPartieRestaurateur().getFont(FontsPartieRestaurateur.TITLE, 70));
    } catch (FontFormatException ex) {
        Logger.getLogger(ConsultRestaurant.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ConsultRestaurant.class.getName()).log(Level.SEVERE, null, ex);
    }
    dataset2 = new DefaultPieDataset();
    //Statique
    for (Entry e : new StatistiqueDAO().mostPayed().entrySet()) {
        if (Float.parseFloat((String) e.getValue()) > max2) {
            i2 = k;
            max2 = Float.parseFloat((String) e.getValue());
        }
        dataset2.setValue((Comparable) e.getKey(), Float.parseFloat((String) e.getValue()));
        k++;
    }

    graphe2 = ChartFactory.createPieChart3D("Restaurant avec le meilleur revenue", dataset2, true, true, false);
    PiePlot plot2 = (PiePlot) graphe2.getPlot();
    plot2.setLabelGenerator(gen2);
    cp2 = new ChartPanel(graphe2);
    cp2.setBounds(new Rectangle(490, 400));
    Pie2.add(cp2);
    cp2.setVisible(true);
    Pie2.setVisible(true);
    try {
        if (i1 == i2) {
            conseil.setForeground(Color.green);
            conseil.setText(
                    "Vos statistiques sont parfaites! Votre restaurant le plus rserv est celui avec le plus de revenue!");
        } else {
            conseil.setForeground(Color.red);
            conseil.setText(
                    "Le restaurant le plus rserv n'est pas celui avec le plus revenue! Verifier votre stratgie de prix!");
        }
    } catch (Exception e) {
        conseil.setVisible(false);
    }

}

From source file:daylightchart.daylightchart.chart.DaylightChartLegendItemSource.java

private LegendItem createLegendItem(final String label, final Paint paint, final boolean isLine) {
    final LegendItem legendItem = new LegendItem(label, /* description */
            null, /* toolTipText */null, /* urlText */
            null, /* shapeVisible */!isLine, /* shape */new Rectangle(10, 10), /* shapeFilled */true, paint,
            /* shapeOutlineVisible */true, /* outlinePaint */Color.black,
            /* outlineStroke */new BasicStroke(0.2f), /* lineVisible */isLine, /* line */new Rectangle(10, 3),
            /* lineStroke */new BasicStroke(0.6f), /* linePaint */Color.black);

    return legendItem;
}

From source file:org.dkpro.lab.reporting.ChartUtil.java

/**
 * Exports a JFreeChart to a scalable PDF file.
 *
 * @param chart JFreeChart to export/*from www  .  j  ava2  s . c  om*/
 * @param aOS stream to write to.
 * @param aWidth width of the chart in pixels
 * @param aHeight height of the chart in pixels
 * @throws IOException if writing the svgFile fails.
 */
public static void writeChartAsPDF(OutputStream aOS, JFreeChart chart, int aWidth, int aHeight)
        throws IOException {
    // Create an instance of the SVG Generator
    PDFDocumentGraphics2D pdfGenerator = new PDFDocumentGraphics2D(true, aOS, aWidth, aHeight);
    pdfGenerator.setDeviceDPI(PDFDocumentGraphics2D.NORMAL_PDF_RESOLUTION);
    pdfGenerator.setGraphicContext(new GraphicContext());
    pdfGenerator.setSVGDimension(aWidth, aHeight);
    pdfGenerator.setClip(0, 0, aWidth, aHeight);
    pdfGenerator.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
    pdfGenerator.setRenderingHint(KEY_INTERPOLATION, VALUE_INTERPOLATION_BILINEAR);
    chart.setBackgroundPaint(Color.white);
    chart.getPlot().setBackgroundPaint(Color.white);
    // draw the chart in the SVG generator
    chart.draw(pdfGenerator, new Rectangle(aWidth, aHeight));
    pdfGenerator.finish();
}

From source file:main.java.gui.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - BOHDAN Korinnyi
    test = new JFrame();
    label1 = new JLabel();
    textField1 = new JTextField();
    label2 = new JLabel();
    textField2 = new JTextField();
    label3 = new JLabel();
    label4 = new JLabel();
    textField3 = new JTextField();
    textField4 = new JTextField();
    button1 = new JButton();
    button2 = new JButton();
    label5 = new JLabel();
    label6 = new JLabel();

    //======== test ========
    {/*w ww.jav a  2  s. c  o m*/
        test.setTitle("Pay mobile account");
        Container testContentPane = test.getContentPane();
        testContentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u0421\u0443\u043c\u0430");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 4f));
        testContentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(35, 30), label1.getPreferredSize()));

        //---- textField1 ----
        textField1.setColumns(10);
        testContentPane.add(textField1);
        textField1.setBounds(150, 30, 105, textField1.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u041d\u043e\u043c\u0435\u0440");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 4f));
        testContentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(35, 60), label2.getPreferredSize()));

        //---- textField2 ----
        textField2.setText("0674060606");
        textField2.setFont(textField2.getFont().deriveFont(textField2.getFont().getSize() + 2f));
        testContentPane.add(textField2);
        textField2.setBounds(150, 60, 105, textField2.getPreferredSize().height);

        //---- label3 ----
        label3.setText("\u041b\u043e\u0433\u0456\u043d");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 4f));
        testContentPane.add(label3);
        label3.setBounds(new Rectangle(new Point(35, 95), label3.getPreferredSize()));

        //---- label4 ----
        label4.setText("\u041f\u0430\u0440\u043e\u043b\u044c");
        label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 4f));
        testContentPane.add(label4);
        label4.setBounds(new Rectangle(new Point(35, 125), label4.getPreferredSize()));
        testContentPane.add(textField3);
        textField3.setBounds(150, 95, 105, textField3.getPreferredSize().height);
        testContentPane.add(textField4);
        textField4.setBounds(150, 125, 105, 20);

        //---- button1 ----
        button1.setText("\u041e\u043f\u043b\u0430\u0442\u0438\u0442\u0438");
        button1.setFont(button1.getFont().deriveFont(button1.getFont().getStyle() | Font.BOLD,
                button1.getFont().getSize() + 2f));
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String strTemp = textField1.getText();
                int cash = Integer.parseInt(strTemp);
                if (cash < 1) {
                    JOptionPane.showMessageDialog(null, "    '", "",
                            JOptionPane.OK_OPTION);
                    textField1.setText("0");
                } else if (textField3.getText().equals("test4") && textField4.getText().equals("12345")) {
                    check c = new check();
                    pay p = new pay();
                    getstatus g = new getstatus();
                    try {
                        c.connection(c.PaymentCollectionRequest("38" + getNumber(), getMoney()));
                        g.connection(c.PaymentStatusRequest());
                        p.connection(c.PaymentCollectionRequest("38" + getNumber(), getMoney()));
                        g.connection(c.PaymentStatusRequest());
                        information i = new information();
                        daoImplements h = new daoImplements();
                        long curTime = System.currentTimeMillis();
                        String curStringDate = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(curTime);

                        i.setIdTransaction(getTransaction.setGetTransaction());
                        i.setData(curStringDate);
                        i.setNumber(Integer.parseInt(getNumber()));
                        i.setSuma(Integer.parseInt(getMoney()));
                        i.setStatus(parserStatus.getStatusParsing());
                        h.addInfo(i);

                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (ParseException e2) {
                        // TODO Auto-generated catch block
                        e2.printStackTrace();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "    ", "",
                            JOptionPane.OK_OPTION);
                    System.exit(0);
                }
            }

        });
        testContentPane.add(button1);
        button1.setBounds(150, 155, 115, 25);

        //---- button2 ----
        button2.setText("\u0406\u0441\u0442\u043e\u0440\u0456\u044f");
        button2.setFont(button2.getFont().deriveFont(button2.getFont().getStyle() | Font.BOLD,
                button2.getFont().getSize() + 2f));
        button2.setActionCommand("\u0406\u0441\u0442\u043e\u0440\u0456\u044f");
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tableData t = new tableData();
            }
        });
        testContentPane.add(button2);
        button2.setBounds(15, 155, 115, 25);

        //---- label5 ----
        label5.setText(
                "\u0422\u0435\u0441\u0442\u043e\u0432\u0438\u0439 \u0441\u0435\u0440\u0432\u0456\u0441 \u043f\u043e\u043f\u043e\u0432\u043d\u0435\u043d\u043d\u044f \u043c\u043e\u0431\u0456\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0445\u0443\u043d\u043a\u0443");
        label5.setFont(label5.getFont().deriveFont(label5.getFont().getStyle() & ~Font.ITALIC));
        testContentPane.add(label5);
        label5.setBounds(15, 0, 255, 20);

        //---- label6 ----
        label6.setText("38");
        label6.setFont(label6.getFont().deriveFont(label6.getFont().getSize() + 4f));
        testContentPane.add(label6);
        label6.setBounds(new Rectangle(new Point(130, 60), label6.getPreferredSize()));

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for (int i = 0; i < testContentPane.getComponentCount(); i++) {
                Rectangle bounds = testContentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = testContentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            testContentPane.setMinimumSize(preferredSize);
            testContentPane.setPreferredSize(preferredSize);
        }
        test.pack();
        test.setLocationRelativeTo(test.getOwner());
    }
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}