Example usage for com.jgoodies.looks BorderStyle SEPARATOR

List of usage examples for com.jgoodies.looks BorderStyle SEPARATOR

Introduction

In this page you can find the example usage for com.jgoodies.looks BorderStyle SEPARATOR.

Prototype

BorderStyle SEPARATOR

To view the source code for com.jgoodies.looks BorderStyle SEPARATOR.

Click Source Link

Usage

From source file:at.lux.fotoannotation.AnnotationFrame.java

License:Open Source License

private void init() {
    try {/*from ww  w. j a  v a2 s  . co m*/
        LoggerInit.configureLog4j("log4j.properties", "INFO");
        this.setIconImage(ImageIO.read(AnnotationFrame.class.getResource("data/caliph-icon.png")));
        //            this.setIconImage(ImageIO.read(AnnotationFrame.class.getResource("data/icon.gif")));
    } catch (Exception e) {
        debug("Couldn't set Icon: IOException " + e.getMessage());
    }
    df = (DecimalFormat) DecimalFormat.getInstance();
    df.setMaximumFractionDigits(2);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent event) {
            super.windowClosing(event);
            exitApplication();
        }
    });
    // -------------------------------------------------------------------------------
    // Ueberpruefung ob das agent file existiert, sonst muss es angelegt werden ...
    // Eine sicherheitskopie befindet sich im package ...
    // -------------------------------------------------------------------------------
    debug("Checking if agentfile is here ...");
    File agentsFile = new File(AnnotationToolkit.AGENTS_FILE);
    if (!agentsFile.exists()) {
        try {
            debug("Generating sample agents file");
            Document d = new SAXBuilder().build(AnnotationFrame.class.getResource("data/agents.mp7.xml"));
            FileOutputStream fos = new FileOutputStream(agentsFile);
            OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
            new XMLOutputter(Format.getPrettyFormat()).output(d, osw);
            osw.close();
            fos.close();
            debug("Finished generating sample agents file");
        } catch (Exception e) {
            debug("Error generating sample agents file " + e.toString() + ", " + e.getMessage());
        }
    } else {
        debug("agentfile found :)");
    }
    debug("reading configurationfile ... ");
    // -------------------------------------------------------------------------------
    // Ueberpruefung ob das base-object file existiert, sonst muss es angelegt werden.
    // Eine sicherheitskopie befindet sich im package ...
    // -------------------------------------------------------------------------------
    debug("Checking if agentfile is here ...");
    File baseobjectsFile = new File("base-objects.mp7.xml");
    if (!baseobjectsFile.exists()) {
        try {
            debug("Generating sample base-objects file");
            Document d = new SAXBuilder().build(AnnotationFrame.class.getResource("data/base-objects.mp7.xml"));
            FileOutputStream fos = new FileOutputStream(baseobjectsFile);
            OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
            new XMLOutputter(Format.getPrettyFormat()).output(d, osw);
            osw.close();
            fos.close();
            debug("Finished generating sample base-objects file");
        } catch (Exception e) {
            debug("Error generating sample base-objects file " + e.toString() + ", " + e.getMessage());
        }
    } else {
        debug("base-objects file found :)");
    }
    debug("reading configurationfile ... ");
    // -------------------------------------------------------------------------------
    // Ueberpruefung ob das property file existiert, sonst muss es angelegt werden ...
    // Eine sicherheitskopie befindet sich im package ...
    // -------------------------------------------------------------------------------
    File pFile = new File("properties.xml");
    if (!pFile.exists()) {
        try {
            debug("Generating sample property file");
            Document d = new SAXBuilder().build(AnnotationFrame.class.getResource("data/properties.xml"));
            FileOutputStream fos = new FileOutputStream(pFile);
            OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
            new XMLOutputter(Format.getPrettyFormat()).output(d, osw);
            osw.close();
            fos.close();
            debug("Finished generating sample property file");
        } catch (Exception e) {
            debug("Error generating sample property file " + e.toString() + ", " + e.getMessage());
        }
    }
    properties = new AnnotationFrameProperties(new File("properties.xml"), this);
    debug("finished reading configurationfile");
    JMenuBar menuBar = properties.getMenuBar();
    // For JGoodies Look & Feel:
    menuBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
    menuBar.putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
    this.setJMenuBar(menuBar);
    debug("finished creating menu");

    fileTree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent tse) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tse.getNewLeadSelectionPath()
                    .getLastPathComponent();
            if (node.getUserObject() instanceof FileNodeObject) {
                File f = ((FileNodeObject) node.getUserObject()).getContent();
                if (!f.isDirectory()) {
                    try {
                        setCurrentFile(f);
                    } catch (IOException e) {
                        System.err.println("Error opening file: " + f.toString());
                        System.err.println(e.toString());
                        //                            e.printStackTrace();
                    }
                }
            }
        }
    });
    setToCurrentLocation(fileTree);

    // -------------------------------------
    // Initialising main Objects ...
    // -------------------------------------
    // TextChangeListener intialization for detecting changes of the document.
    TextChangesListener.createInstance(this);
    // -------------------------------------
    // Adding Components
    // -------------------------------------

    beePanel = new IMBeeApplicationPanel(this);
    colorPanel = new ColorLayoutPanel();

    lrSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    lrSplit.setBorder(BorderFactory.createEmptyBorder());
    lrSplit.setDividerSize(3);
    tbSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    tbSplit.setBorder(BorderFactory.createEmptyBorder());
    tbSplit.setDividerSize(3);

    mdPanel = new MetadataDescriptionPanel(new AgentComboBoxModel(this));
    imagePanel = new ImageThumbPanel();
    //        fp = new FilePanel(new File("."), this);
    qualityPanel = new QualityPanel(new AgentComboBoxModel(this));
    textPanel = new TextDescriptionPanel(this);
    creationPanel = new CreationPanel(new AgentComboBoxModel(this));
    shapePanel = new ShapePanel(this);

    JPanel qualTextPanel = new JPanel(new BorderLayout());
    qualTextPanel.add(qualityPanel, BorderLayout.SOUTH);
    qualTextPanel.add(textPanel, BorderLayout.CENTER);
    gridPanel1 = new JPanel(new GridLayout(0, 2));
    JPanel _leftPanel1 = new JPanel(new BorderLayout());
    //        gridPanel2.add(textPanel);
    _leftPanel1.add(qualTextPanel, BorderLayout.CENTER);
    _leftPanel1.add(mdPanel, BorderLayout.SOUTH);
    gridPanel1.add(_leftPanel1);
    gridPanel1.add(creationPanel);
    JPanel gridPanel3 = new JPanel(new GridLayout(0, 1));
    gridPanel3.add(colorPanel);
    //        gridPanel3.add(qualTextPanel);

    tabs = new JTabbedPane(JTabbedPane.TOP);
    tabs.setBorder(BorderFactory.createEmptyBorder());
    tabs.add("Image Information", gridPanel1);
    tabs.add("Semantics", beePanel);
    tabs.add("Shape", shapePanel);
    tabs.add("Visuals", gridPanel3);

    // file tree ....
    // ---------------
    JScrollPane fileTreeScrollPane = new JScrollPane(fileTree);
    JPanel filePanel = new JPanel(new BorderLayout());
    filePanel.add(fileTreeScrollPane, BorderLayout.CENTER);
    // TODO: remove error here ...
    fileComboBox = new JComboBox(File.listRoots());
    fileComboBox.setActionCommand("rootChanged");
    fileComboBox.addActionListener(this);
    filePanel.add(fileComboBox, BorderLayout.NORTH);
    tbSplit.add(filePanel, JSplitPane.TOP);
    tbSplit.add(imagePanel, JSplitPane.BOTTOM);

    lrSplit.add(tbSplit, JSplitPane.LEFT);
    lrSplit.add(tabs, JSplitPane.RIGHT);

    lrSplit.setDividerLocation(properties.getLrSplit());
    tbSplit.setDividerLocation(properties.getTbSplit());

    status = new JLabel(TITLE_BAR);
    status.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));
    garbageState = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100);
    garbageState.setStringPainted(true);
    garbageState.setPreferredSize(new Dimension(100, 18));
    garbageState.setToolTipText(
            "This bar shows the memory allocated by the VM and how much of it is already in use.");
    garbageState.setBorder(BorderFactory.createEmptyBorder());
    gtracker = new GarbageTracker(garbageState);

    JPanel sgcPanel = new JPanel(new BorderLayout());
    sgcPanel.add(garbageState, BorderLayout.EAST);
    sgcPanel.add(status, BorderLayout.CENTER);

    this.getContentPane().add(lrSplit, BorderLayout.CENTER);
    this.getContentPane().add(sgcPanel, BorderLayout.SOUTH);

    this.setSize(properties.getFrameWidth(), properties.getFrameHeigth());
    this.setLocation(properties.getFrameLocationX(), properties.getFrameLocationY());

    beePanel.reArrange();
    //beePanel.revalidate();
    gtracker.start();
    // call init from global configuration while splash is on screen :)
    IconCache.getInstance();
}

From source file:com.salas.bb.views.mainframe.BBMenuBuilder.java

License:Open Source License

/**
 * Build BlogBridge menu bar.//from   w  ww. j  ava 2  s.c  o  m
 *
 * @return the resulting menu bar.
 */
public JMenuBar buildMenuBar() {
    JMenuBar myMenu = new JMenuBar();
    myMenu.setMargin(MENUBAR_MARGIN);

    // Apply some special style hints for JGoodies
    myMenu.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
    myMenu.putClientProperty(WindowsLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
    myMenu.putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);

    myMenu.add(buildGuidesMenu());
    myMenu.add(buildFeedsMenu());
    myMenu.add(buildArticlesMenu());
    myMenu.add(buildToolsMenu());
    myMenu.add(buildHelpMenu());
    return myMenu;
}

From source file:com.zeroc.IceGridGUI.LiveDeployment.GraphView.java

License:Open Source License

public GraphView(Coordinator coordinator, String title) {
    _coordinator = coordinator;//w  ww .j av a  2s .c o m
    setTitle(title);

    _preferences = Preferences.userNodeForPackage(getClass());

    //
    // Don't destroy JavaFX when the frame is disposed.
    //
    Platform.setImplicitExit(false);
    setIconImage(Utils.getIcon("/icons/16x16/metrics_graph.png").getImage());
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            close();
        }
    });

    //
    // Graph preferences.
    //
    Action preferences = new AbstractAction("Preferences") {
        @Override
        public void actionPerformed(ActionEvent event) {
            //
            // Set the title
            //
            JTextField title = new JTextField(getTitle());
            JPanel titlePanel;
            {
                DefaultFormBuilder builder = new DefaultFormBuilder(
                        new FormLayout("pref,2dlu,pref:grow", "pref"));
                builder.append("Title:", title);
                titlePanel = builder.getPanel();
            }

            //
            // SpinnerNumberModel to set a refresh period.
            //
            SpinnerNumberModel refreshPeriod = new SpinnerNumberModel(getRefreshPeriod(), _minRefreshPeriod,
                    _maxRefreshPeriod, 1);

            //
            // SpinnerNumberModel to set the maximum number of samples to keep in X axis.
            //
            final SpinnerNumberModel samples = new SpinnerNumberModel(_samples, _minSamples, _maxSamples, 1);

            JPanel refreshPanel;
            {
                DefaultFormBuilder builder = new DefaultFormBuilder(
                        new FormLayout("pref,2dlu,pref:grow", "pref"));
                builder.rowGroupingEnabled(true);
                final JSpinner spinner = new JSpinner(refreshPeriod);
                builder.append("Sample interval:", spinner);
                builder.append("", new JLabel("<html><p>Sample interval in seconds; must be between 1"
                        + "<br/>and 3600 seconds.</p></html>"));
                refreshPanel = builder.getPanel();
            }

            //
            // JComboBox to select time format used in X Axis
            //
            JComboBox<String> dateFormats = new JComboBox<>(_dateFormats);
            dateFormats.setSelectedItem(getDateFormat());
            JPanel xAxisPanel;
            {
                DefaultFormBuilder builder = new DefaultFormBuilder(
                        new FormLayout("pref,2dlu,pref:grow", "pref"));

                builder.append("Samples displayed:", new JSpinner(samples));
                builder.append("", new JLabel("<html><p>The number of samples displayed on a graph;"
                        + "<br/>must be between 2 and 300." + "</p></html>"));
                builder.append("Time format:", dateFormats);

                xAxisPanel = builder.getPanel();
            }

            FormLayout layout = new FormLayout("fill:pref:grow", "pref");
            final DefaultFormBuilder builder = new DefaultFormBuilder(layout);
            builder.border(Borders.DIALOG);
            builder.append(titlePanel);
            builder.nextLine();
            builder.append(refreshPanel);
            builder.nextLine();
            builder.append(xAxisPanel);

            if (JOptionPane.showConfirmDialog(GraphView.this, builder.getPanel(), "Metrics Graph Preferences",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) != JOptionPane.OK_OPTION) {
                return;
            }

            setTitle(title.getText());
            setRefreshPeriod(refreshPeriod.getNumber().intValue());
            setMaximumSamples(samples.getNumber().intValue());
            setDateFormat((String) dateFormats.getSelectedItem());
        }
    };

    _legendTable = new JTable(_legendModel) {
        //Implement table cell tool tips.
        @Override
        public String getToolTipText(java.awt.event.MouseEvent e) {
            if (convertColumnIndexToModel(columnAtPoint(e.getPoint())) == 6) {
                return _legendModel.getRows(new int[] { rowAtPoint(e.getPoint()) })[0].cell.getField()
                        .getColumnToolTip();
            } else {
                return null;
            }
        }
    };

    //
    // Adjust row height for larger fonts
    //
    int fontSize = _legendTable.getFont().getSize();
    int minRowHeight = fontSize + fontSize / 3;
    if (_legendTable.getRowHeight() < minRowHeight) {
        _legendTable.setRowHeight(minRowHeight);
    }

    //
    // Graph preferences.
    //
    final Action delete = new AbstractAction("Delete") {
        @Override
        public void actionPerformed(ActionEvent event) {
            int[] selectedRows = _legendTable.getSelectedRows();
            for (int i = 0; i < selectedRows.length; ++i) {
                selectedRows[i] = _legendTable.convertRowIndexToModel(selectedRows[i]);
            }
            //
            // Remove selected rows from the legend model.
            //
            final MetricsRow[] rows = _legendModel.removeRows(selectedRows);

            //
            // Remove rows from series hash maps
            //
            for (MetricsRow row : rows) {
                Map<String, Map<String, Map<String, MetricsRow>>> j = _series.get(row.info);
                Map<String, Map<String, MetricsRow>> k = j.get(row.cell.getField().getMetricsName());
                Map<String, MetricsRow> l = k.get(row.cell.getId());
                l.remove(row.cell.getField().getFieldName());
                if (l.size() == 0) {
                    k.remove(row.cell.getId());
                    if (k.size() == 0) {
                        j.remove(row.cell.getField().getMetricsName());
                        if (j.size() == 0) {
                            _series.remove(row.info);
                            if (_series.size() == 0) {
                                stopRefresh();
                            }
                        }
                    }
                }
            }

            //
            // Remove series from the chart, in JavaFx thread.
            //
            enqueueJFX(new Runnable() {
                @Override
                public void run() {
                    for (MetricsRow row : rows) {
                        for (int i = 0; i < row.series.size(); ++i) {
                            XYChart.Series<Number, Number> series = row.series.get(i);
                            String seriesClass = getSeriesClass(series);
                            if (seriesClass != null) {
                                _styles.remove(seriesClass);
                            }
                            //
                            // Don't remove the XYChart.Series object here, to avoid the series
                            // style classes to be reasign by JavaFX.
                            //
                            // _chart.getData().remove(row.series);
                            try {
                                series.getData().clear();
                            } catch (NullPointerException ex) {
                                // JavaFX bug
                            }
                        }
                    }
                }
            });
        }
    };
    delete.setEnabled(false);
    delete.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));

    _legendTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                delete.setEnabled(_legendTable.getSelectedRows().length > 0);
            }
        }
    });

    //
    // Create the tool bar
    //
    class ToolBar extends JToolBar {
        public ToolBar() {
            putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
            putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
            setFloatable(false);
            putClientProperty("JToolBar.isRollover", Boolean.TRUE);

            JButton button = new JButton(delete);
            button.setText(null);
            button.setIcon(Utils.getIcon("/icons/24x24/delete.png"));
            add(button);
        }
    }

    //
    // Create menus
    //
    JMenuBar menuBar = new JMenuBar();

    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(java.awt.event.KeyEvent.VK_F);
    fileMenu.add(preferences);
    menuBar.add(fileMenu);

    JMenu editMenu = new JMenu("Edit");
    editMenu.setMnemonic(java.awt.event.KeyEvent.VK_E);
    editMenu.add(delete);
    menuBar.add(editMenu);

    setJMenuBar(menuBar);

    //
    // Set default renderer for numeric values.
    //
    _legendTable.setDefaultRenderer(Double.class, new FormatedNumberRenderer("#0.000"));

    //
    // Set a combobox to edit the scale factors.
    //
    JComboBox<Double> scales = new JComboBox<>(_scales);
    scales.setRenderer(new DecimalRenderer(scales.getRenderer()));
    _legendTable.getColumnModel().getColumn(7).setCellEditor(new DefaultCellEditor(scales));

    //
    // Set default renderer and editor for Color.class column.
    //
    _legendTable.setDefaultRenderer(Color.class, new ColorRenderer(true));
    _legendTable.setDefaultEditor(Color.class, new ColorEditor());

    _legendTable.setAutoCreateRowSorter(true);

    final JFXPanel fxPanel = new JFXPanel();
    fxPanel.setMinimumSize(new Dimension(0, 200));
    fxPanel.setPreferredSize(new Dimension(800, 400));
    //
    // Build the split pane, with the chart graph and the legend table.
    //
    _splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    _splitPane.setTopComponent(fxPanel);
    JScrollPane scrollPane = new JScrollPane(_legendTable);
    scrollPane.setTransferHandler(new TransferHandler());
    scrollPane.setMinimumSize(new Dimension(0, 50));
    scrollPane.setPreferredSize(new Dimension(800, 200));
    _splitPane.setBottomComponent(scrollPane);

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("fill:pref:grow", "fill:pref:grow, pref"));
    builder.append(_splitPane);
    builder.nextLine();

    JPanel panel = builder.getPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(new ToolBar(), BorderLayout.PAGE_START);
    getContentPane().add(panel, BorderLayout.CENTER);
    setPreferredSize(new Dimension(800, 600));

    //
    // initialize the scene in JavaFX thread.
    //
    enqueueJFX(() -> {
        _xAxis = new NumberAxis();
        _yAxis = new NumberAxis();

        _chart = new LineChart<>(_xAxis, _yAxis);
        _chart.setCreateSymbols(false);
        _xAxis.setLabel("Time (" + getDateFormat() + ")");
        _xAxis.setTickLabelFormatter(_timeFormater);
        _xAxis.setForceZeroInRange(false);
        _chart.setAnimated(true);
        _chart.setLegendVisible(false);

        final Scene scene = new Scene(_chart);
        scene.setOnDragOver(new EventHandler<DragEvent>() {
            @Override
            public void handle(DragEvent event) {
                Dragboard db = event.getDragboard();
                if (event.getGestureSource() != scene && db.hasContent(LocalObjectMimeType)) {
                    Object object = db.getContent(LocalObjectMimeType);
                    if (object instanceof MetricsViewTransferableData) {
                        event.acceptTransferModes(TransferMode.COPY);
                    }
                }
                event.consume();
            }
        });

        scene.setOnDragDropped(new EventHandler<DragEvent>() {
            @Override
            public void handle(DragEvent event) {
                boolean success = false;
                Dragboard db = event.getDragboard();
                if (event.getGestureSource() != scene && db.hasContent(LocalObjectMimeType)) {
                    Object object = db.getContent(LocalObjectMimeType);
                    if (object instanceof MetricsViewTransferableData) {
                        addSeries((MetricsViewTransferableData) object);
                        success = true;
                    }
                }
                event.setDropCompleted(success);
                event.consume();
            }
        });
        fxPanel.setScene(scene);
    });

    pack();
    if (!loadPreferences()) {
        _splitPane.setDividerLocation(400);
    }
    setVisible(true);

    //
    // Show info dialog if required.
    //
    if (showInfo()) {
        JCheckBox checkbox = new JCheckBox("Do not show this message again.");
        String message = "Drop metrics cells to add them to the graph.";

        JOptionPane.showConfirmDialog(this, new Object[] { message, checkbox }, "Information",
                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (checkbox.isSelected()) {
            _preferences.node("GraphView").putBoolean("showInfo", false);
        }
    }
}

From source file:IceGridGUI.LiveDeployment.GraphView.java

License:Open Source License

public GraphView(Coordinator coordinator, String title) {
    _coordinator = coordinator;//from  ww w .j  av a 2  s.  co  m
    setTitle(title);

    _preferences = Preferences.userNodeForPackage(getClass());

    //
    // Don't destroy JavaFX when the frame is disposed.
    //
    Platform.setImplicitExit(false);
    setIconImage(Utils.getIcon("/icons/16x16/metrics_graph.png").getImage());
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            close();
        }
    });

    //
    // Graph preferences.
    //
    Action preferences = new AbstractAction("Preferences") {
        @Override
        public void actionPerformed(ActionEvent event) {
            //
            // Set the title
            //
            JTextField title = new JTextField(getTitle());
            JPanel titlePanel;
            {
                DefaultFormBuilder builder = new DefaultFormBuilder(
                        new FormLayout("pref,2dlu,pref:grow", "pref"));
                builder.append("Title:", title);
                titlePanel = builder.getPanel();
            }

            //
            // SpinnerNumberModel to set a refresh period.
            //
            SpinnerNumberModel refreshPeriod = new SpinnerNumberModel(getRefreshPeriod(), _minRefreshPeriod,
                    _maxRefreshPeriod, 1);

            //
            // SpinnerNumberModel to set the maximum number of samples to keep in X axis.
            //
            final SpinnerNumberModel samples = new SpinnerNumberModel(_samples, _minSamples, _maxSamples, 1);

            JPanel refreshPanel;
            {
                DefaultFormBuilder builder = new DefaultFormBuilder(
                        new FormLayout("pref,2dlu,pref:grow", "pref"));
                builder.rowGroupingEnabled(true);
                final JSpinner spinner = new JSpinner(refreshPeriod);
                builder.append("Sample interval:", spinner);
                builder.append("", new JLabel("<html><p>Sample interval in seconds; must be between 1"
                        + "<br/>and 3600 seconds.</p></html>"));
                refreshPanel = builder.getPanel();
            }

            //
            // JComboBox to select time format used in X Axis
            //
            JComboBox<String> dateFormats = new JComboBox<String>(_dateFormats);
            dateFormats.setSelectedItem(getDateFormat());
            JPanel xAxisPanel;
            {
                DefaultFormBuilder builder = new DefaultFormBuilder(
                        new FormLayout("pref,2dlu,pref:grow", "pref"));
                builder.append("Samples displayed:", new JSpinner(samples));
                builder.append("", new JLabel("<html><p>The number of samples displayed on a graph;"
                        + "<br/>must be between 2 and 300." + "</p></html>"));
                builder.append("Time format:", dateFormats);

                xAxisPanel = builder.getPanel();
            }

            FormLayout layout = new FormLayout("fill:pref:grow", "pref");
            final DefaultFormBuilder builder = new DefaultFormBuilder(layout);
            builder.border(Borders.DIALOG);
            builder.append(titlePanel);
            builder.nextLine();
            builder.append(refreshPanel);
            builder.nextLine();
            builder.append(xAxisPanel);

            if (JOptionPane.showConfirmDialog(GraphView.this, builder.getPanel(), "Metrics Graph Preferences",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) != JOptionPane.OK_OPTION) {
                return;
            }

            setTitle(title.getText());
            setRefreshPeriod(refreshPeriod.getNumber().intValue());
            setMaximumSamples(samples.getNumber().intValue());
            setDateFormat((String) dateFormats.getSelectedItem());
        }
    };

    _legendTable = new JTable(_legendModel) {
        //Implement table cell tool tips.
        @Override
        public String getToolTipText(java.awt.event.MouseEvent e) {
            if (convertColumnIndexToModel(columnAtPoint(e.getPoint())) == 6) {
                return _legendModel.getRows(new int[] { rowAtPoint(e.getPoint()) })[0].cell.getField()
                        .getColumnToolTip();
            } else {
                return null;
            }
        }
    };

    //
    // Adjust row height for larger fonts
    //
    int fontSize = _legendTable.getFont().getSize();
    int minRowHeight = fontSize + fontSize / 3;
    if (_legendTable.getRowHeight() < minRowHeight) {
        _legendTable.setRowHeight(minRowHeight);
    }

    //
    // Graph preferences.
    //
    final Action delete = new AbstractAction("Delete") {
        @Override
        public void actionPerformed(ActionEvent event) {
            int[] selectedRows = _legendTable.getSelectedRows();
            for (int i = 0; i < selectedRows.length; ++i) {
                selectedRows[i] = _legendTable.convertRowIndexToModel(selectedRows[i]);
            }
            //
            // Remove selected rows from the legend model.
            //
            final MetricsRow[] rows = _legendModel.removeRows(selectedRows);

            //
            // Remove rows from series hash maps
            //
            for (MetricsRow row : rows) {
                Map<String, Map<String, Map<String, MetricsRow>>> j = _series.get(row.info);
                Map<String, Map<String, MetricsRow>> k = j.get(row.cell.getField().getMetricsName());
                Map<String, MetricsRow> l = k.get(row.cell.getId());
                l.remove(row.cell.getField().getFieldName());
                if (l.size() == 0) {
                    k.remove(row.cell.getId());
                    if (k.size() == 0) {
                        j.remove(row.cell.getField().getMetricsName());
                        if (j.size() == 0) {
                            _series.remove(row.info);
                            if (_series.size() == 0) {
                                stopRefresh();
                            }
                        }
                    }
                }
            }

            //
            // Remove series from the chart, in JavaFx thread.
            //
            enqueueJFX(new Runnable() {
                @Override
                public void run() {
                    for (MetricsRow row : rows) {
                        for (int i = 0; i < row.series.size(); ++i) {
                            XYChart.Series<Number, Number> series = row.series.get(i);
                            String seriesClass = getSeriesClass(series);
                            if (seriesClass != null) {
                                _styles.remove(seriesClass);
                            }
                            //
                            // Don't remove the XYChart.Series object here, to avoid the series
                            // style classes to be reasign by JavaFX.
                            //
                            // _chart.getData().remove(row.series);
                            try {
                                series.getData().clear();
                            } catch (NullPointerException ex) {
                                // JavaFX bug
                            }
                        }
                    }
                }
            });
        }
    };
    delete.setEnabled(false);
    delete.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));

    _legendTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                delete.setEnabled(_legendTable.getSelectedRows().length > 0);
            }
        }
    });

    //
    // Create the tool bar
    //
    class ToolBar extends JToolBar {
        public ToolBar() {
            putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
            putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
            setFloatable(false);
            putClientProperty("JToolBar.isRollover", Boolean.TRUE);

            JButton button = new JButton(delete);
            button.setText(null);
            button.setIcon(Utils.getIcon("/icons/24x24/delete.png"));
            add(button);
        }
    }

    //
    // Create menus
    //
    JMenuBar menuBar = new JMenuBar();

    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(java.awt.event.KeyEvent.VK_F);
    fileMenu.add(preferences);
    menuBar.add(fileMenu);

    JMenu editMenu = new JMenu("Edit");
    editMenu.setMnemonic(java.awt.event.KeyEvent.VK_E);
    editMenu.add(delete);
    menuBar.add(editMenu);

    setJMenuBar(menuBar);

    //
    // Set default renderer for numeric values.
    //
    _legendTable.setDefaultRenderer(Double.class, new FormatedNumberRenderer("#0.000"));

    //
    // Set a combobox to edit the scale factors.
    //
    JComboBox<Double> scales = new JComboBox<Double>(_scales);
    scales.setRenderer(new DecimalRenderer(scales.getRenderer()));
    _legendTable.getColumnModel().getColumn(7).setCellEditor(new DefaultCellEditor(scales));

    //
    //Set default renderer and editor for Color.class column.
    //
    _legendTable.setDefaultRenderer(Color.class, new ColorRenderer(true));
    _legendTable.setDefaultEditor(Color.class, new ColorEditor());

    _legendTable.setAutoCreateRowSorter(true);

    final JFXPanel fxPanel = new JFXPanel();
    fxPanel.setMinimumSize(new Dimension(0, 200));
    fxPanel.setPreferredSize(new Dimension(800, 400));
    //
    // Build the split pane, with the chart graph and the legend table.
    //
    _splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    _splitPane.setTopComponent(fxPanel);
    JScrollPane scrollPane = new JScrollPane(_legendTable);
    scrollPane.setTransferHandler(new TransferHandler());
    scrollPane.setMinimumSize(new Dimension(0, 50));
    scrollPane.setPreferredSize(new Dimension(800, 200));
    _splitPane.setBottomComponent(scrollPane);

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("fill:pref:grow", "fill:pref:grow, pref"));
    builder.append(_splitPane);
    builder.nextLine();

    JPanel panel = builder.getPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(new ToolBar(), BorderLayout.PAGE_START);
    getContentPane().add(panel, BorderLayout.CENTER);
    setPreferredSize(new Dimension(800, 600));

    //
    // initialize the scene in JavaFX thread.
    //
    enqueueJFX(new Runnable() {
        @Override
        public void run() {
            _xAxis = new NumberAxis();
            _yAxis = new NumberAxis();

            _chart = new LineChart<Number, Number>(_xAxis, _yAxis);
            _chart.setCreateSymbols(false);
            _xAxis.setLabel("Time (" + getDateFormat() + ")");
            _xAxis.setTickLabelFormatter(_timeFormater);
            _xAxis.setForceZeroInRange(false);
            _chart.setAnimated(true);
            _chart.setLegendVisible(false);

            final Scene scene = new Scene(_chart);
            scene.setOnDragOver(new EventHandler<DragEvent>() {
                @Override
                public void handle(DragEvent event) {
                    Dragboard db = event.getDragboard();
                    if (event.getGestureSource() != scene && db.hasContent(LocalObjectMimeType)) {
                        Object object = db.getContent(LocalObjectMimeType);
                        if (object instanceof MetricsViewTransferableData) {
                            event.acceptTransferModes(TransferMode.COPY);
                        }
                    }
                    event.consume();
                }
            });

            scene.setOnDragDropped(new EventHandler<DragEvent>() {
                @Override
                public void handle(DragEvent event) {
                    boolean success = false;
                    Dragboard db = event.getDragboard();
                    if (event.getGestureSource() != scene && db.hasContent(LocalObjectMimeType)) {
                        Object object = db.getContent(LocalObjectMimeType);
                        if (object instanceof MetricsViewTransferableData) {
                            addSeries((MetricsViewTransferableData) object);
                            success = true;
                        }
                    }
                    event.setDropCompleted(success);
                    event.consume();
                }
            });
            fxPanel.setScene(scene);
        }
    });

    pack();
    if (!loadPreferences()) {
        Rectangle otherRect = _coordinator.getMainFrame().getBounds();
        Rectangle thisRect = getBounds();
        if (otherRect.width < thisRect.width || otherRect.height < thisRect.height) {
            setLocationRelativeTo(null);
        } else {
            setLocationRelativeTo(_coordinator.getMainFrame());
        }
        _splitPane.setDividerLocation(400);
    }
    setVisible(true);

    //
    // Show info dialog if required.
    //
    if (showInfo()) {
        JCheckBox checkbox = new JCheckBox("Do not show this message again.");
        String message = "Drop metrics cells to add them to the graph.";

        JOptionPane.showConfirmDialog(this, new Object[] { message, checkbox }, "Information",
                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (checkbox.isSelected()) {
            _preferences.node("GraphView").putBoolean("showInfo", false);
        }
    }
}