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

/**
 * Attempts to determine the usable screen bounds of the default screen
 * device. If the require java.awt API is not available under the JVM we're
 * running in, this will simply return the screen bounds obtained via
 * <code>Toolkit.getScreenSize()</code>.
 *//*from   w  w  w .j a v a  2 s. co  m*/

public static Rectangle getUsableScreenBounds() {
    if (PlatformUtils.isJavaBetterThan("1.4")) {
        try {
            Class graphicsEnvironmentClass = Class.forName("java.awt.GraphicsEnvironment");
            Class graphicsDeviceClass = Class.forName("java.awt.GraphicsDevice");
            Class graphicsConfigurationClass = Class.forName("java.awt.GraphicsConfiguration");

            Class[] emptyClassArr = new Class[0];
            Method getLocalGraphicsEnvironmentMethod = graphicsEnvironmentClass
                    .getMethod("getLocalGraphicsEnvironment", emptyClassArr);
            Method getDefaultScreenDeviceMethod = graphicsEnvironmentClass.getMethod("getDefaultScreenDevice",
                    emptyClassArr);
            Method getDefaultConfigurationMethod = graphicsDeviceClass.getMethod("getDefaultConfiguration",
                    emptyClassArr);
            Method getBoundsMethod = graphicsConfigurationClass.getMethod("getBounds", emptyClassArr);
            Method getScreenInsetsMethod = Toolkit.class.getMethod("getScreenInsets",
                    new Class[] { graphicsConfigurationClass });

            Object[] emptyObjArr = new Object[0];
            Object graphicsEnvironment = getLocalGraphicsEnvironmentMethod.invoke(null, emptyObjArr);
            Object defaultScreenDevice = getDefaultScreenDeviceMethod.invoke(graphicsEnvironment, emptyObjArr);
            Object defaultConfiguration = getDefaultConfigurationMethod.invoke(defaultScreenDevice,
                    emptyObjArr);
            Rectangle bounds = (Rectangle) getBoundsMethod.invoke(defaultConfiguration, emptyObjArr);
            Insets insets = (Insets) getScreenInsetsMethod.invoke(Toolkit.getDefaultToolkit(),
                    new Object[] { defaultConfiguration });

            bounds.x += insets.left;
            bounds.y += insets.top;
            bounds.width -= insets.left + insets.right;
            bounds.height -= insets.top + insets.bottom;

            return bounds;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    return new Rectangle(new Point(0, 0), Toolkit.getDefaultToolkit().getScreenSize());
}

From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java

private Rectangle getSquaresBounds(Dataset dataset) {
    int[] upperArrangement = null;
    if (upperTree == null || upperTree.arrangement == null) {
        upperArrangement = new int[dataset.getDataWidth()];
    } else {/*from  w  ww. jav  a2  s .c om*/
        upperArrangement = upperTree.arrangement;
    }
    if (upperArrangement == null || sideTree == null) {
        return new Rectangle(0, 0);
    }
    return new Rectangle(upperArrangement.length * squareW + 1, (sideTree.actualLength * squareL) + 1);
}

From source file:org.squale.squaleweb.util.graph.ScatterMaker.java

/**
 * Construit (ou reconstruit) le diagramme puis le retourne
 * /*www.  j  a  v a 2  s  .  c o m*/
 * @return le diagramme JFreeChart.
 */
protected JFreeChart getChart() {
    LOG.debug(WebMessages.getString("method.entry"));
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        // Gnration du Scatterplot
        retChart = ChartFactory.createScatterPlot(mTitle, mXLabel, mYLabel, mDataSet, PlotOrientation.VERTICAL,
                mShowLegend, false, false);
        ValueAxis domainAxis = retChart.getXYPlot().getDomainAxis();
        ValueAxis rangeAxis = retChart.getXYPlot().getRangeAxis();

        // Dtermination des bornes en abscisse et en ordonne
        double maxDomain = Math.max(domainAxis.getUpperBound(),
                DEFAULT_VERTICAL_AXIS_POS + DEFAULT_AXIS_MARGIN);
        double minDomain = Math.min(domainAxis.getLowerBound(),
                DEFAULT_VERTICAL_AXIS_POS - DEFAULT_AXIS_MARGIN);
        double maxRange = Math.max(rangeAxis.getUpperBound(),
                DEFAULT_HORIZONTAL_AXIS_POS + DEFAULT_AXIS_MARGIN);
        double minRange = Math.min(rangeAxis.getLowerBound(),
                DEFAULT_HORIZONTAL_AXIS_POS - DEFAULT_AXIS_MARGIN);

        // Mise  l'chelle logarithmique des axes
        LogarithmicAxis newDomainAxis = new LogarithmicAxis(domainAxis.getLabel());
        LogarithmicAxis newRangeAxis = new LogarithmicAxis(rangeAxis.getLabel());

        // Affectation des bornes en abscisse et en ordonne
        newDomainAxis.setLowerBound(minDomain);
        newDomainAxis.setUpperBound(maxDomain);
        newRangeAxis.setLowerBound(minRange);
        newRangeAxis.setUpperBound(maxRange);
        retChart.getXYPlot().setDomainAxis(newDomainAxis);
        retChart.getXYPlot().setRangeAxis(newRangeAxis);

        // Le point a une taille fixe
        Shape shape = new Rectangle(DEFAULT_POINT_SIZE, DEFAULT_POINT_SIZE);
        retChart.getXYPlot().getRenderer().setShape(shape);

        // Annotations
        XYLineAnnotation horizontalAxis = new XYLineAnnotation(minDomain, DEFAULT_HORIZONTAL_AXIS_POS,
                maxDomain, DEFAULT_HORIZONTAL_AXIS_POS);
        XYLineAnnotation verticalAxis = new XYLineAnnotation(DEFAULT_VERTICAL_AXIS_POS, minRange,
                DEFAULT_VERTICAL_AXIS_POS, maxRange);
        retChart.getXYPlot().addAnnotation(horizontalAxis);
        retChart.getXYPlot().addAnnotation(verticalAxis);

        super.setChart(retChart);
    }
    LOG.debug(WebMessages.getString("method.exit"));
    return retChart;
}

From source file:com.esofthead.mycollab.community.ui.chart.JFreeChartWrapper.java

@Override
public Resource getSource() {
    if (res == null) {
        StreamSource streamSource = new StreamResource.StreamSource() {
            private ByteArrayInputStream bytestream = null;

            ByteArrayInputStream getByteStream() {
                if (chart != null && bytestream == null) {
                    int width = getGraphWidth();
                    int height = getGraphHeight();

                    if (mode == RenderingMode.SVG) {

                        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                        DocumentBuilder docBuilder = null;
                        try {
                            docBuilder = docBuilderFactory.newDocumentBuilder();
                        } catch (ParserConfigurationException e1) {
                            throw new RuntimeException(e1);
                        }/*w  w  w . j  a  v a  2 s.co  m*/
                        Document document = docBuilder.newDocument();
                        Element svgelem = document.createElement("svg");
                        document.appendChild(svgelem);

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

                        // draw the chart in the SVG generator
                        chart.draw(svgGenerator, new Rectangle(width, height));
                        Element el = svgGenerator.getRoot();
                        el.setAttributeNS(null, "viewBox", "0 0 " + width + " " + height + "");
                        el.setAttributeNS(null, "style", "width:100%;height:100%;");
                        el.setAttributeNS(null, "preserveAspectRatio", getSvgAspectRatio());

                        // Write svg to buffer
                        ByteArrayOutputStream baoutputStream = new ByteArrayOutputStream();
                        Writer out;
                        try {
                            OutputStream outputStream = gzipEnabled ? new GZIPOutputStream(baoutputStream)
                                    : baoutputStream;
                            out = new OutputStreamWriter(outputStream, "UTF-8");
                            /*
                            * don't use css, FF3 can'd deal with the result
                            * perfectly: wrong font sizes
                            */
                            boolean useCSS = false;
                            svgGenerator.stream(el, out, useCSS, false);
                            outputStream.flush();
                            outputStream.close();
                            bytestream = new ByteArrayInputStream(baoutputStream.toByteArray());
                        } catch (Exception e) {
                            log.error("Error while generating SVG chart", e);
                        }
                    } else {
                        // Draw png to bytestream
                        try {
                            byte[] bytes = ChartUtilities.encodeAsPNG(chart.createBufferedImage(width, height));
                            bytestream = new ByteArrayInputStream(bytes);
                        } catch (Exception e) {
                            log.error("Error while generating PNG chart", e);
                        }

                    }

                } else {
                    bytestream.reset();
                }
                return bytestream;
            }

            @Override
            public InputStream getStream() {
                return getByteStream();
            }
        };

        res = new StreamResource(streamSource, String.format("graph%d", System.currentTimeMillis())) {

            @Override
            public int getBufferSize() {
                if (getStreamSource().getStream() != null) {
                    try {
                        return getStreamSource().getStream().available();
                    } catch (IOException e) {
                        log.warn("Error while get stream info", e);
                        return 0;
                    }
                } else {
                    return 0;
                }
            }

            @Override
            public long getCacheTime() {
                return 0;
            }

            @Override
            public String getFilename() {
                if (mode == RenderingMode.PNG) {
                    return super.getFilename() + ".png";
                } else {
                    return super.getFilename() + (gzipEnabled ? ".svgz" : ".svg");
                }
            }

            @Override
            public DownloadStream getStream() {
                DownloadStream downloadStream = new DownloadStream(getStreamSource().getStream(), getMIMEType(),
                        getFilename());
                if (gzipEnabled && mode == RenderingMode.SVG) {
                    downloadStream.setParameter("Content-Encoding", "gzip");
                }
                return downloadStream;
            }

            @Override
            public String getMIMEType() {
                if (mode == RenderingMode.PNG) {
                    return "image/png";
                } else {
                    return "image/svg+xml";
                }
            }
        };
    }
    return res;
}

From source file:userinterface.graph.SeriesEditorDialog.java

/** Creates new form GUIConstantsPicker */
private SeriesEditorDialog(GUIPlugin plugin, JFrame parent, JPanel graph, java.util.List<SeriesKey> series) {
    super(parent, "Graph Series Editor", true);
    this.plugin = plugin;
    this.editors = new ArrayList<SeriesEditor>();

    initComponents();//  w  w w .  ja v  a2 s. c om

    AbstractAction cut = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            editors.get(tabbedPane.getSelectedIndex()).cut();
        }
    };
    cut.putValue(Action.LONG_DESCRIPTION, "Cut the current selection to the clipboard");
    //exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit");
    cut.putValue(Action.NAME, "Cut");
    cut.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallCut.png"));
    //cut.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    AbstractAction copy = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            editors.get(tabbedPane.getSelectedIndex()).copy();
        }
    };
    copy.putValue(Action.LONG_DESCRIPTION, "Copies the current selection to the clipboard");
    //exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit");
    copy.putValue(Action.NAME, "Copy");
    copy.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallCopy.png"));
    //copy.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    AbstractAction paste = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            editors.get(tabbedPane.getSelectedIndex()).paste();
        }
    };
    paste.putValue(Action.LONG_DESCRIPTION, "Pastes the clipboard to the current selection");
    //exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit");
    paste.putValue(Action.NAME, "Paste");
    paste.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallPaste.png"));
    //paste.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    AbstractAction delete = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            editors.get(tabbedPane.getSelectedIndex()).delete();
        }
    };
    delete.putValue(Action.LONG_DESCRIPTION, "Deletes the current");
    //exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit");
    delete.putValue(Action.NAME, "Delete");
    delete.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallDelete.png"));

    for (SeriesKey key : series) {
        SeriesSettings settings = null;
        if (graph instanceof Graph)
            settings = ((Graph) graph).getGraphSeries(key);
        if (graph instanceof Histogram)
            settings = ((Histogram) graph).getGraphSeries(key);
        if (graph instanceof Graph3D)
            settings = ((Graph3D) graph).getSeriesSettings();

        Object DataSeries = null;
        if (graph instanceof Graph)
            DataSeries = (PrismXYSeries) ((Graph) graph).getXYSeries(key);
        if (graph instanceof Histogram)
            DataSeries = ((Histogram) graph).getXYSeries(key);
        if (graph instanceof Graph3D)
            DataSeries = ((Graph3D) graph).getScatterSeries();

        SeriesEditor editor = new SeriesEditor(graph, DataSeries, settings, cut, copy, paste, delete);
        editor.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

        tabbedPane.addTab(settings.getSeriesHeading(), editor);
        editors.add(editor);
    }

    this.getRootPane().setDefaultButton(okayButton);

    toolBar.add(cut);
    toolBar.add(copy);
    toolBar.add(paste);
    toolBar.add(delete);

    this.add(toolBar, BorderLayout.NORTH);

    this.cancelled = false;

    super.setBounds(new Rectangle(550, 300));
    setResizable(true);
    setLocationRelativeTo(getParent()); // centre
}

From source file:org.vaadin.addon.JFreeChartWrapper.java

@Override
public Resource getSource() {
    if (res == null) {
        StreamSource streamSource = new StreamResource.StreamSource() {
            private ByteArrayInputStream bytestream = null;

            ByteArrayInputStream getByteStream() {
                if (chart != null && bytestream == null) {
                    int widht = getGraphWidth();
                    int height = getGraphHeight();

                    if (mode == RenderingMode.SVG) {

                        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                        DocumentBuilder docBuilder = null;
                        try {
                            docBuilder = docBuilderFactory.newDocumentBuilder();
                        } catch (ParserConfigurationException e1) {
                            throw new RuntimeException(e1);
                        }/*  www  .  java2 s.c om*/
                        Document document = docBuilder.newDocument();
                        Element svgelem = document.createElement("svg");
                        document.appendChild(svgelem);

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

                        // draw the chart in the SVG generator
                        chart.draw(svgGenerator, new Rectangle(widht, height));
                        Element el = svgGenerator.getRoot();
                        el.setAttributeNS(null, "viewBox", "0 0 " + widht + " " + height + "");
                        el.setAttributeNS(null, "style", "width:100%;height:100%;");
                        el.setAttributeNS(null, "preserveAspectRatio", getSvgAspectRatio());

                        // Write svg to buffer
                        ByteArrayOutputStream baoutputStream = new ByteArrayOutputStream();
                        Writer out;
                        try {
                            OutputStream outputStream = gzipEnabled ? new GZIPOutputStream(baoutputStream)
                                    : baoutputStream;
                            out = new OutputStreamWriter(outputStream, "UTF-8");
                            /*
                             * don't use css, FF3 can'd deal with the result
                             * perfectly: wrong font sizes
                             */
                            boolean useCSS = false;
                            svgGenerator.stream(el, out, useCSS, false);
                            outputStream.flush();
                            outputStream.close();
                            bytestream = new ByteArrayInputStream(baoutputStream.toByteArray());
                        } catch (UnsupportedEncodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (SVGGraphics2DIOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    } else {
                        // Draw png to bytestream
                        try {
                            byte[] bytes = ChartUtilities.encodeAsPNG(chart.createBufferedImage(widht, height));
                            bytestream = new ByteArrayInputStream(bytes);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                    }

                } else {
                    bytestream.reset();
                }
                return bytestream;
            }

            @Override
            public InputStream getStream() {
                return getByteStream();
            }
        };

        res = new StreamResource(streamSource, String.format("graph%d", System.currentTimeMillis())) {

            @Override
            public int getBufferSize() {
                if (getStreamSource().getStream() != null) {
                    try {
                        return getStreamSource().getStream().available();
                    } catch (IOException e) {
                        return 0;
                    }
                } else {
                    return 0;
                }
            }

            @Override
            public long getCacheTime() {
                return 0;
            }

            @Override
            public String getFilename() {
                if (mode == RenderingMode.PNG) {
                    return super.getFilename() + ".png";
                } else {
                    return super.getFilename() + (gzipEnabled ? ".svgz" : ".svg");
                }
            }

            @Override
            public DownloadStream getStream() {
                DownloadStream downloadStream = new DownloadStream(getStreamSource().getStream(), getMIMEType(),
                        getFilename());
                if (gzipEnabled && mode == RenderingMode.SVG) {
                    downloadStream.setParameter("Content-Encoding", "gzip");
                }
                return downloadStream;
            }

            @Override
            public String getMIMEType() {
                if (mode == RenderingMode.PNG) {
                    return "image/png";
                } else {
                    return "image/svg+xml";
                }
            }
        };
    }
    return res;
}

From source file:de.bund.bfr.jung.JungUtils.java

private static Paint mixWith(Paint paint, Color mix) {
    if (paint instanceof Color) {
        Color c = (Color) paint;

        return new Color((c.getRed() + mix.getRed()) / 2, (c.getGreen() + mix.getGreen()) / 2,
                (c.getBlue() + mix.getBlue()) / 2, (c.getAlpha() + mix.getAlpha()) / 2);
    } else if (paint instanceof TexturePaint) {
        BufferedImage texture = ((TexturePaint) paint).getImage();
        BufferedImage mixed = new BufferedImage(texture.getWidth(), texture.getHeight(), texture.getType());

        for (int x = 0; x < texture.getWidth(); x++) {
            for (int y = 0; y < texture.getHeight(); y++) {
                mixed.setRGB(x, y, ((Color) mixWith(new Color(texture.getRGB(x, y)), mix)).getRGB());
            }/*  ww  w.  j  a  v a 2 s.com*/
        }

        return new TexturePaint(mixed, new Rectangle(mixed.getWidth(), mixed.getHeight()));
    } else {
        return paint;
    }
}

From source file:com.iontorrent.vaadin.utils.JFreeChartWrapper.java

@Override
public Resource getSource() {
    if (res == null) {
        res = new ApplicationResource() {

            private ByteArrayInputStream bytestream = null;

            ByteArrayInputStream getByteStream() {
                if (chart != null && bytestream == null) {
                    int widht = getGraphWidth();
                    int height = getGraphHeight();
                    info = new ChartRenderingInfo();

                    if (mode == RenderingMode.SVG) {

                        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                        DocumentBuilder docBuilder = null;
                        try {
                            docBuilder = docBuilderFactory.newDocumentBuilder();
                        } catch (ParserConfigurationException e1) {
                            throw new RuntimeException(e1);
                        }//from   w  w w  .  j a  v a 2 s  . c  om
                        Document document = docBuilder.newDocument();
                        Element svgelem = document.createElement("svg");
                        document.appendChild(svgelem);

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

                        // draw the chart in the SVG generator

                        chart.draw(svgGenerator, new Rectangle(widht, height), info);
                        Element el = svgGenerator.getRoot();
                        el.setAttributeNS(null, "viewBox", "0 0 " + widht + " " + height + "");
                        el.setAttributeNS(null, "style", "width:100%;height:100%;");
                        el.setAttributeNS(null, "preserveAspectRatio", getSvgAspectRatio());

                        // Write svg to buffer
                        ByteArrayOutputStream baoutputStream = new ByteArrayOutputStream();
                        Writer out;
                        try {
                            OutputStream outputStream = gzipEnabled ? new GZIPOutputStream(baoutputStream)
                                    : baoutputStream;
                            out = new OutputStreamWriter(outputStream, "UTF-8");
                            /*
                             * don't use css, FF3 can'd deal with the result
                             * perfectly: wrong font sizes
                             */
                            boolean useCSS = false;
                            svgGenerator.stream(el, out, useCSS, false);
                            outputStream.flush();
                            outputStream.close();
                            bytestream = new ByteArrayInputStream(baoutputStream.toByteArray());
                        } catch (UnsupportedEncodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (SVGGraphics2DIOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    } else {
                        // Draw png to bytestream
                        try {

                            byte[] bytes = ChartUtilities.encodeAsPNG(chart.createBufferedImage(widht, height));
                            bytestream = new ByteArrayInputStream(bytes);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                    }

                } else {
                    bytestream.reset();
                }
                return bytestream;
            }

            public Application getApplication() {
                return JFreeChartWrapper.this.getApplication();
            }

            public int getBufferSize() {
                if (getByteStream() != null) {
                    return getByteStream().available();
                } else {
                    return 0;
                }
            }

            public long getCacheTime() {
                return 0;
            }

            public String getFilename() {
                if (mode == RenderingMode.PNG) {
                    return "graph.png";
                } else {
                    return gzipEnabled ? "graph.svgz" : "graph.svg";
                }
            }

            public DownloadStream getStream() {
                DownloadStream downloadStream = new DownloadStream(getByteStream(), getMIMEType(),
                        getFilename());
                if (gzipEnabled && mode == RenderingMode.SVG) {
                    downloadStream.setParameter("Content-Encoding", "gzip");
                }
                return downloadStream;
            }

            public String getMIMEType() {
                if (mode == RenderingMode.PNG) {
                    return "image/png";
                } else {
                    return "image/svg+xml";
                }
            }
        };
    }
    return res;
}

From source file:org.broad.igv.util.stats.KMPlotFrame.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner non-commercial license
    dialogPane = new JPanel();
    contentPanel = new JPanel();
    panel1 = new JPanel();
    panel2 = new JPanel();
    label2 = new JLabel();
    survivalColumnControl = new JComboBox();
    panel3 = new JPanel();
    label3 = new JLabel();
    censurColumnControl = new JComboBox();
    panel4 = new JPanel();
    label4 = new JLabel();
    groupByControl = new JComboBox();

    //======== this ========
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Kaplan-Meier Plot");
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    //======== dialogPane ========
    {/*w w w .  j  a  va2  s .  co m*/
        dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
        dialogPane.setLayout(new BorderLayout());

        //======== contentPanel ========
        {
            contentPanel.setLayout(new BorderLayout());

            //======== panel1 ========
            {
                panel1.setAlignmentX(0.0F);
                panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));

                //======== panel2 ========
                {
                    panel2.setAlignmentX(1.0F);
                    panel2.setLayout(null);

                    //---- label2 ----
                    label2.setText("Survival column");
                    panel2.add(label2);
                    label2.setBounds(new Rectangle(new Point(5, 10), label2.getPreferredSize()));

                    //---- survivalColumnControl ----
                    survivalColumnControl.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            survivalColumnControlActionPerformed(e);
                        }
                    });
                    panel2.add(survivalColumnControl);
                    survivalColumnControl.setBounds(120, 5, 235,
                            survivalColumnControl.getPreferredSize().height);

                    { // compute preferred size
                        Dimension preferredSize = new Dimension();
                        for (int i = 0; i < panel2.getComponentCount(); i++) {
                            Rectangle bounds = panel2.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 = panel2.getInsets();
                        preferredSize.width += insets.right;
                        preferredSize.height += insets.bottom;
                        panel2.setMinimumSize(preferredSize);
                        panel2.setPreferredSize(preferredSize);
                    }
                }
                panel1.add(panel2);

                //======== panel3 ========
                {
                    panel3.setAlignmentX(1.0F);
                    panel3.setLayout(null);

                    //---- label3 ----
                    label3.setText("Censure column");
                    panel3.add(label3);
                    label3.setBounds(new Rectangle(new Point(5, 10), label3.getPreferredSize()));

                    //---- censurColumnControl ----
                    censurColumnControl.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            survivalColumnControlActionPerformed(e);
                        }
                    });
                    panel3.add(censurColumnControl);
                    censurColumnControl.setBounds(120, 5, 235, censurColumnControl.getPreferredSize().height);

                    { // compute preferred size
                        Dimension preferredSize = new Dimension();
                        for (int i = 0; i < panel3.getComponentCount(); i++) {
                            Rectangle bounds = panel3.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 = panel3.getInsets();
                        preferredSize.width += insets.right;
                        preferredSize.height += insets.bottom;
                        panel3.setMinimumSize(preferredSize);
                        panel3.setPreferredSize(preferredSize);
                    }
                }
                panel1.add(panel3);

                //======== panel4 ========
                {
                    panel4.setAlignmentX(1.0F);
                    panel4.setLayout(null);

                    //---- label4 ----
                    label4.setText("Group by");
                    panel4.add(label4);
                    label4.setBounds(new Rectangle(new Point(5, 10), label4.getPreferredSize()));

                    //---- groupByControl ----
                    groupByControl.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            survivalColumnControlActionPerformed(e);
                        }
                    });
                    panel4.add(groupByControl);
                    groupByControl.setBounds(120, 5, 235, groupByControl.getPreferredSize().height);

                    { // compute preferred size
                        Dimension preferredSize = new Dimension();
                        for (int i = 0; i < panel4.getComponentCount(); i++) {
                            Rectangle bounds = panel4.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 = panel4.getInsets();
                        preferredSize.width += insets.right;
                        preferredSize.height += insets.bottom;
                        panel4.setMinimumSize(preferredSize);
                        panel4.setPreferredSize(preferredSize);
                    }
                }
                panel1.add(panel4);
            }
            contentPanel.add(panel1, BorderLayout.NORTH);
        }
        dialogPane.add(contentPanel, BorderLayout.CENTER);
    }
    contentPane.add(dialogPane, BorderLayout.CENTER);
    setSize(565, 510);
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:PhysicDrawing.PhysicGraph.java

/**
 * Creates a chart./*from w w  w  . j  ava2 s .  c  o  m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createVelocityChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart("Velocity", // chart title
            "X - Time (s)", // x axis label
            "Y - V (px/s)", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white); // vertical line 
    plot.setRangeGridlinePaint(Color.white); // horizontal line 

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true); // (index , value)
    renderer.setSeriesLinesVisible(1, true);
    // renderer.setSeriesShapesVisible(1, true);
    // renderer.setSeriesFillPaint(2, Color.black);
    renderer.setSeriesPaint(0, Color.RED, true);
    renderer.setSeriesPaint(1, Color.black, true);
    renderer.setSeriesPaint(2, Color.white, true);
    renderer.setSeriesShape(0, new Rectangle(1, 1));
    renderer.setSeriesShape(1, new Rectangle(1, 1));

    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}