Example usage for javax.swing Box createGlue

List of usage examples for javax.swing Box createGlue

Introduction

In this page you can find the example usage for javax.swing Box createGlue.

Prototype

public static Component createGlue() 

Source Link

Document

Creates an invisible "glue" component that can be useful in a Box whose visible components have a maximum width (for a horizontal box) or height (for a vertical box).

Usage

From source file:savant.view.swing.BookmarkSheet.java

public BookmarkSheet(Container c) {

    // set the layout of the data sheet
    c.setLayout(new BorderLayout());
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    /**//from  w  ww . jav  a 2  s.com
     * Create a toolbar. 
     */
    JMenuBar toolbar = new JMenuBar();
    toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
    c.add(toolbar, BorderLayout.NORTH);

    JButton previousButton = new JButton();
    previousButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.UP));
    previousButton.setToolTipText("Go to previous bookmark [ Ctrl+( ]");
    previousButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    previousButton.putClientProperty("JButton.segmentPosition", "first");
    previousButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            goToPreviousBookmark();
        }

    });
    toolbar.add(previousButton);

    JButton nextButton = new JButton();
    nextButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.DOWN));
    nextButton.setToolTipText("Go to next bookmark [ Ctrl+) ]");
    nextButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    nextButton.putClientProperty("JButton.segmentPosition", "last");
    nextButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            goToNextBookmark();
        }

    });
    toolbar.add(nextButton);

    JButton goButton = new JButton("Go");
    goButton.setToolTipText("Go to selected bookmark");
    goButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    goButton.putClientProperty("JButton.segmentPosition", "only");
    goButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            goToSelectedBookmark();
        }

    });
    toolbar.add(goButton);

    toolbar.add(Box.createGlue());

    addButton = new JButton();
    addButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.BKMK_ADD));
    addButton.setToolTipText("Add bookmark for current range");
    addButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    addButton.putClientProperty("JButton.segmentPosition", "first");
    addButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            BookmarkController fc = BookmarkController.getInstance();
            fc.addCurrentRangeToBookmarks();
        }
    });
    toolbar.add(addButton);

    JButton deleteButton = new JButton();
    deleteButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.BKMK_RM));
    deleteButton.setToolTipText("Delete selected bookmarks");
    deleteButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    deleteButton.putClientProperty("JButton.segmentPosition", "last");
    deleteButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            BookmarkController fc = BookmarkController.getInstance();
            int[] selectedRows = table.getSelectedRows();
            Arrays.sort(selectedRows);
            boolean delete = false;

            if (selectedRows.length > 0 && confirmDelete) {
                Object[] options = { "Yes", "No", "Yes, don't ask again" };
                JLabel message = new JLabel(
                        "Are you sure you want to delete " + selectedRows.length + " item(s)?");
                message.setPreferredSize(new Dimension(300, 20));
                int confirmDeleteDialog = JOptionPane.showOptionDialog(DialogUtils.getMainWindow(), message,
                        "Confirm Delete", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                        options, options[0]);

                if (confirmDeleteDialog == 0) {
                    delete = true;
                } else if (confirmDeleteDialog == 2) {
                    delete = true;
                    confirmDelete = false;
                }
            } else if (selectedRows.length > 0 && !confirmDelete) {
                delete = true;
            }

            if (delete) {
                for (int i = selectedRows.length - 1; i >= 0; i--) {
                    fc.removeBookmark(selectedRows[i]);
                }
            }
        }
    });
    toolbar.add(deleteButton);

    toolbar.add(Box.createGlue());

    JButton loadButton = new JButton();
    loadButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.OPEN));
    loadButton.setToolTipText("Load bookmarks from file");
    loadButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    loadButton.putClientProperty("JButton.segmentPosition", "first");
    loadButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            loadBookmarks(table);
        }
    });
    toolbar.add(loadButton);

    JButton saveButton = new JButton();
    saveButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SAVE));
    saveButton.setToolTipText("Save bookmarks to file");
    saveButton.putClientProperty("JButton.buttonType", "segmentedRoundRect");
    saveButton.putClientProperty("JButton.segmentPosition", "last");
    saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            saveBookmarks(table);
        }
    });
    toolbar.add(saveButton);

    // create a table (the most important component)
    table = new JTable(new BookmarksTableModel());
    table.setAutoCreateRowSorter(true);
    table.setFillsViewportHeight(true);
    table.setShowGrid(true);
    table.setGridColor(Color.gray);
    //table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

    // add the table and its header to the subpanel
    c.add(table.getTableHeader());

    add(table);

    final JScrollPane sp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    sp.setWheelScrollingEnabled(false);
    sp.addMouseWheelListener(new MouseWheelListener() {
        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            sp.getVerticalScrollBar().setValue(sp.getVerticalScrollBar().getValue() + e.getUnitsToScroll() * 2);
        }
    });

    c.add(sp);

    // add glue to fill the remaining space
    add(Box.createGlue());
}

From source file:savant.view.swing.NavigationBar.java

NavigationBar() {

    this.setOpaque(false);
    this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

    String buttonStyle = "segmentedCapsule";

    String shortcutMod = MiscUtils.MAC ? "Cmd" : "Ctrl";

    add(getRigidPadding());//from   ww  w  .  j av  a2  s.  c  om

    JButton loadGenomeButton = (JButton) add(new JButton(""));
    loadGenomeButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.GENOME));
    loadGenomeButton.setToolTipText("Load or change genome");
    loadGenomeButton.setFocusable(false);
    loadGenomeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Savant.getInstance().showOpenGenomeDialog();
        }
    });
    loadGenomeButton.putClientProperty("JButton.buttonType", buttonStyle);
    loadGenomeButton.putClientProperty("JButton.segmentPosition", "first");
    loadGenomeButton.setPreferredSize(ICON_SIZE);
    loadGenomeButton.setMinimumSize(ICON_SIZE);
    loadGenomeButton.setMaximumSize(ICON_SIZE);

    JButton loadTrackButton = (JButton) add(new JButton(""));
    loadTrackButton.setFocusable(false);
    loadTrackButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.TRACK));
    loadTrackButton.setToolTipText("Load a track");
    loadTrackButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Savant.getInstance().openTrack();
        }
    });
    loadTrackButton.putClientProperty("JButton.buttonType", buttonStyle);
    loadTrackButton.putClientProperty("JButton.segmentPosition", "last");
    loadTrackButton.setPreferredSize(ICON_SIZE);
    loadTrackButton.setMinimumSize(ICON_SIZE);
    loadTrackButton.setMaximumSize(ICON_SIZE);

    if (!Savant.getInstance().isStandalone()) {
        add(loadGenomeButton);
        add(loadTrackButton);
        add(getRigidPadding());
        add(getRigidPadding());
    } else {
        loadGenomeButton.setVisible(false);
        loadTrackButton.setVisible(false);
    }

    JLabel rangeText = new JLabel("Location ");
    add(rangeText);

    String[] a = { " ", " ", " ", " ", " ", " ", " ", " ", " ", " " };
    locationField = new JComboBox(a);
    locationField.setEditable(true);
    locationField.setRenderer(new ReferenceListRenderer());

    // When the item is chosen from the menu, navigate to the given feature/reference.
    locationField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if (!currentlyPopulating) {
                if (ae.getActionCommand().equals("comboBoxChanged")) {
                    // Assumes that combo-box items created by populateCombo() are of the form "GENE (chrX:1-1000)".
                    String itemText = locationField.getSelectedItem().toString();
                    int lastBracketPos = itemText.lastIndexOf('(');
                    if (lastBracketPos > 0) {
                        itemText = itemText.substring(lastBracketPos + 1, itemText.length() - 1);
                    }
                    setRangeFromText(itemText);

                }
            }
        }
    });

    // When the combo-box is popped open, we may want to repopulate the menu.
    locationField.addPopupMenuListener(new PopupMenuListener() {
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent pme) {
            String text = (String) locationField.getEditor().getItem();
            if (!text.equals(lastPoppedUp)) {
                try {
                    // Building the menu could take a while.
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    populateCombo();
                } finally {
                    setCursor(Cursor.getDefaultCursor());
                }
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent pme) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent pme) {
        }
    });

    // Add our special keystroke-handling to the JComboBox' text-field.
    // We have to turn off default tab-handling so that tab can pop up our list.
    Component textField = locationField.getEditor().getEditorComponent();
    textField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    textField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent evt) {
            if (evt.getKeyCode() == KeyEvent.VK_TAB) {
                locationField.showPopup();
            } else if (evt.getModifiers() == KeyEvent.SHIFT_MASK) {
                switch (evt.getKeyCode()) {
                case KeyEvent.VK_LEFT:
                    locationController.shiftRangeLeft();
                    evt.consume();
                    break;
                case KeyEvent.VK_RIGHT:
                    locationController.shiftRangeRight();
                    evt.consume();
                    break;
                case KeyEvent.VK_UP:
                    locationController.zoomIn();
                    evt.consume();
                    break;
                case KeyEvent.VK_DOWN:
                    locationController.zoomOut();
                    evt.consume();
                    break;
                case KeyEvent.VK_HOME:
                    locationController.shiftRangeFarLeft();
                    evt.consume();
                    break;
                case KeyEvent.VK_END:
                    locationController.shiftRangeFarRight();
                    evt.consume();
                    break;
                }
            }
        }
    });
    add(locationField);
    locationField.setToolTipText("Current display range");
    locationField.setPreferredSize(LOCATION_SIZE);
    locationField.setMaximumSize(LOCATION_SIZE);
    locationField.setMinimumSize(LOCATION_SIZE);

    add(getRigidPadding());

    JButton goButton = (JButton) add(new JButton("  Go  "));
    goButton.putClientProperty("JButton.buttonType", buttonStyle);
    goButton.putClientProperty("JButton.segmentPosition", "only");
    goButton.setToolTipText("Go to specified range (Enter)");
    goButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setRangeFromText(locationField.getEditor().getItem().toString());
        }
    });

    add(getRigidPadding());

    JLabel l = new JLabel("Length: ");
    add(l);

    lengthLabel = (JLabel) add(new JLabel());
    lengthLabel.setToolTipText("Length of the current range");
    lengthLabel.setPreferredSize(LENGTH_SIZE);
    lengthLabel.setMaximumSize(LENGTH_SIZE);
    lengthLabel.setMinimumSize(LENGTH_SIZE);

    add(Box.createGlue());

    double screenwidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth();

    JButton afterGo = null;
    //if (screenwidth > 800) {
    final JButton undoButton = (JButton) add(new JButton(""));
    afterGo = undoButton;
    undoButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.UNDO));
    undoButton.setToolTipText("Undo range change (" + shortcutMod + "+Z)");
    undoButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            locationController.undoLocationChange();
        }
    });
    undoButton.putClientProperty("JButton.buttonType", buttonStyle);
    undoButton.putClientProperty("JButton.segmentPosition", "first");
    undoButton.setPreferredSize(ICON_SIZE);
    undoButton.setMinimumSize(ICON_SIZE);
    undoButton.setMaximumSize(ICON_SIZE);

    final JButton redo = (JButton) add(new JButton(""));
    redo.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.REDO));
    redo.setToolTipText("Redo range change (" + shortcutMod + "+Y)");
    redo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            locationController.redoLocationChange();
        }
    });
    redo.putClientProperty("JButton.buttonType", buttonStyle);
    redo.putClientProperty("JButton.segmentPosition", "last");
    redo.setPreferredSize(ICON_SIZE);
    redo.setMinimumSize(ICON_SIZE);
    redo.setMaximumSize(ICON_SIZE);
    //}

    add(getRigidPadding());
    add(getRigidPadding());

    final JButton zoomInButton = (JButton) add(new JButton());
    if (afterGo == null) {
        afterGo = zoomInButton;
    }
    zoomInButton.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.ZOOMIN));
    zoomInButton.putClientProperty("JButton.buttonType", buttonStyle);
    zoomInButton.putClientProperty("JButton.segmentPosition", "first");
    zoomInButton.setPreferredSize(ICON_SIZE);
    zoomInButton.setMinimumSize(ICON_SIZE);
    zoomInButton.setMaximumSize(ICON_SIZE);
    zoomInButton.setToolTipText("Zoom in (Shift+Up)");
    zoomInButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            locationController.zoomIn();
            AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "zoomed"),
                    new NameValuePair("navigation-direction", "in"),
                    new NameValuePair("navigation-modality", "navbar") });
        }
    });

    final JButton zoomOut = (JButton) add(new JButton(""));
    zoomOut.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.ZOOMOUT));
    zoomOut.setToolTipText("Zoom out (Shift+Down)");
    zoomOut.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            locationController.zoomOut();
            AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "zoomed"),
                    new NameValuePair("navigation-direction", "out"),
                    new NameValuePair("navigation-modality", "navbar") });
        }
    });
    zoomOut.putClientProperty("JButton.buttonType", buttonStyle);
    zoomOut.putClientProperty("JButton.segmentPosition", "last");
    zoomOut.setPreferredSize(ICON_SIZE);
    zoomOut.setMinimumSize(ICON_SIZE);
    zoomOut.setMaximumSize(ICON_SIZE);

    add(getRigidPadding());
    add(getRigidPadding());

    final JButton shiftFarLeft = (JButton) add(new JButton());
    shiftFarLeft.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_FARLEFT));
    shiftFarLeft.putClientProperty("JButton.buttonType", buttonStyle);
    shiftFarLeft.putClientProperty("JButton.segmentPosition", "first");
    shiftFarLeft.setToolTipText("Move to the beginning of the genome (Shift+Home)");
    shiftFarLeft.setPreferredSize(ICON_SIZE);
    shiftFarLeft.setMinimumSize(ICON_SIZE);
    shiftFarLeft.setMaximumSize(ICON_SIZE);
    shiftFarLeft.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            locationController.shiftRangeFarLeft();
            AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"),
                    new NameValuePair("navigation-direction", "left"),
                    new NameValuePair("navigation-modality", "navbar") });
        }
    });

    final JButton shiftLeft = (JButton) add(new JButton());
    shiftLeft.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_LEFT));
    shiftLeft.putClientProperty("JButton.buttonType", buttonStyle);
    shiftLeft.putClientProperty("JButton.segmentPosition", "middle");
    shiftLeft.setToolTipText("Move left (Shift+Left)");
    shiftLeft.setPreferredSize(ICON_SIZE);
    shiftLeft.setMinimumSize(ICON_SIZE);
    shiftLeft.setMaximumSize(ICON_SIZE);
    shiftLeft.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            locationController.shiftRangeLeft();
            AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"),
                    new NameValuePair("navigation-direction", "left"),
                    new NameValuePair("navigation-modality", "navbar") });
        }
    });

    final JButton shiftRight = (JButton) add(new JButton());
    shiftRight.setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_RIGHT));
    shiftRight.putClientProperty("JButton.buttonType", buttonStyle);
    shiftRight.putClientProperty("JButton.segmentPosition", "middle");
    shiftRight.setToolTipText("Move right (Shift+Right)");
    shiftRight.setPreferredSize(ICON_SIZE);
    shiftRight.setMinimumSize(ICON_SIZE);
    shiftRight.setMaximumSize(ICON_SIZE);
    shiftRight.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            locationController.shiftRangeRight();
            AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"),
                    new NameValuePair("navigation-direction", "right"),
                    new NameValuePair("navigation-modality", "navbar") });
        }
    });

    final JButton shiftFarRight = (JButton) add(new JButton());
    shiftFarRight
            .setIcon(SavantIconFactory.getInstance().getIcon(SavantIconFactory.StandardIcon.SHIFT_FARRIGHT));
    shiftFarRight.putClientProperty("JButton.buttonType", buttonStyle);
    shiftFarRight.putClientProperty("JButton.segmentPosition", "last");
    shiftFarRight.setToolTipText("Move to the end of the genome (Shift+End)");
    shiftFarRight.setPreferredSize(ICON_SIZE);
    shiftFarRight.setMinimumSize(ICON_SIZE);
    shiftFarRight.setMaximumSize(ICON_SIZE);
    shiftFarRight.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            locationController.shiftRangeFarRight();
            AnalyticsAgent.log(new NameValuePair[] { new NameValuePair("navigation-event", "panned"),
                    new NameValuePair("navigation-direction", "right"),
                    new NameValuePair("navigation-modality", "navbar") });
        }
    });

    add(getRigidPadding());

    locationController.addListener(new Listener<LocationChangedEvent>() {
        @Override
        public void handleEvent(LocationChangedEvent event) {
            updateLocation(event.getReference(), (Range) event.getRange());
        }
    });

    // When the genome changes, we may need to invalidate our menu.
    GenomeController.getInstance().addListener(new Listener<GenomeChangedEvent>() {
        @Override
        public void handleEvent(GenomeChangedEvent event) {
            lastPoppedUp = "INVALID";
        }
    });

    this.addComponentListener(new ComponentListener() {
        @Override
        public void componentResized(ComponentEvent ce) {
            int width = ce.getComponent().getWidth();

            undoButton.setVisible(true);
            redo.setVisible(true);
            zoomInButton.setVisible(true);
            zoomOut.setVisible(true);
            shiftFarLeft.setVisible(true);
            shiftLeft.setVisible(true);
            shiftRight.setVisible(true);
            shiftFarRight.setVisible(true);

            // hide some components if the window isn't wide enough
            if (width < 1200) {
                undoButton.setVisible(false);
                redo.setVisible(false);
            }
            if (width < 1000) {
                shiftFarLeft.setVisible(false);
                shiftFarRight.setVisible(false);

                shiftRight.putClientProperty("JButton.segmentPosition", "last");
                shiftLeft.putClientProperty("JButton.segmentPosition", "first");
            } else {
                shiftRight.putClientProperty("JButton.segmentPosition", "middle");
                shiftLeft.putClientProperty("JButton.segmentPosition", "middle");
            }
        }

        public void componentMoved(ComponentEvent ce) {
        }

        @Override
        public void componentShown(ComponentEvent ce) {
        }

        @Override
        public void componentHidden(ComponentEvent ce) {
        }
    });
}

From source file:savant.view.swing.Savant.java

private void initStatusBar() {
    toolbar_bottom.add(Box.createGlue(), 2);
    memorystatusbar = new MemoryStatusBarItem();
    memorystatusbar.setMaximumSize(new Dimension(100, 30));
    memorystatusbar.setFillColor(Color.lightGray);
    this.toolbar_bottom.add(memorystatusbar);

    setSpeedAndEfficiencyIndicatorsVisible(false);
}

From source file:semgen.extraction.RadialGraph.Clusterer.java

public void setUpView() throws IOException {
    setTitle(SemGenTab.formatTabName(extractor.semsimmodel.getName()));
    layout = new AggregateLayout<String, Number>(new SemGenFRLayout<String, Number>(mygraph));

    vv = new VisualizationViewer<String, Number>(layout);
    // this class will provide both label drawing and vertex shapes
    VertexLabelAsShapeRenderer<String, Number> vlasr = new VertexLabelAsShapeRenderer<String, Number>(
            vv.getRenderContext());/*from   w  w  w.ja  v a 2s . c om*/

    // customize the render context
    vv.getRenderContext().setVertexLabelTransformer(
            // this chains together Transformers so that the html tags
            // are prepended to the toString method output
            new ChainedTransformer<String, String>(
                    new Transformer[] { new ToStringLabeller<String>(), new Transformer<String, String>() {
                        public String transform(String input) {
                            return input;
                        }
                    } }));
    vv.getRenderContext().setVertexShapeTransformer(vlasr);
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red));
    vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.yellow));
    vv.getRenderContext().setEdgeStrokeTransformer(new ConstantTransformer(new BasicStroke(2.5f)));

    // customize the renderer
    vv.getRenderer().setVertexLabelRenderer(vlasr);

    vv.setBackground(Color.white);
    // Tell the renderer to use our own customized color rendering
    vv.getRenderContext()
            .setVertexFillPaintTransformer(MapTransformer.<String, Paint>getInstance(vertexPaints));
    vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<String, Paint>() {
        public Paint transform(String v) {
            if (vv.getPickedVertexState().isPicked(v)) {
                if (selectioncheckbox != null) {
                    extractor.clusterpanel.remove(selectioncheckbox);
                }
                Set<DataStructure> dsuris = new HashSet<DataStructure>();
                for (String dsname : vv.getPickedVertexState().getPicked()) {
                    dsuris.add(extractor.semsimmodel.getDataStructure(dsname));
                }
                Component[] clusters = extractor.clusterpanel.checkboxpanel.getComponents();
                extractor.clusterpanel.checkboxpanel.removeAll();
                for (int x = -1; x < clusters.length; x++) {
                    if (x == -1 && selectioncheckbox == null) {
                        selectioncheckbox = new ExtractorJCheckBox("Selected node(s)", dsuris);
                        selectioncheckbox.addItemListener(extractor);
                        extractor.clusterpanel.checkboxpanel.add(selectioncheckbox);
                    } else if (x > -1) {
                        extractor.clusterpanel.checkboxpanel.add(clusters[x]);
                    }
                }
                refreshModulePanel();
                return Color.cyan;
            } else {
                if (vv.getPickedVertexState().getPicked().isEmpty()) {
                    if (selectioncheckbox != null) {
                        extractor.clusterpanel.checkboxpanel.remove(selectioncheckbox);
                        selectioncheckbox = null;
                    }
                }
                refreshModulePanel();
                return Color.BLACK;
            }
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(MapTransformer.<Number, Paint>getInstance(edgePaints));

    vv.getRenderContext().setEdgeStrokeTransformer(new Transformer<Number, Stroke>() {
        protected final Stroke THIN = new BasicStroke(1);
        protected final Stroke THICK = new BasicStroke(2);

        public Stroke transform(Number e) {
            Paint c = edgePaints.get(e);
            if (c == Color.LIGHT_GRAY)
                return THIN;
            else
                return THICK;
        }
    });

    // add restart button
    JButton scramble = new JButton("Shake");
    scramble.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Layout<String, Number> layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }
    });

    DefaultModalGraphMouse<Object, Object> gm = new DefaultModalGraphMouse<Object, Object>();
    vv.setGraphMouse(gm);

    groupVertices = new JToggleButton("Group Clusters");

    // Create slider to adjust the number of edges to remove when clustering
    final JSlider edgeBetweennessSlider = new JSlider(JSlider.HORIZONTAL);
    edgeBetweennessSlider.setBackground(Color.WHITE);
    edgeBetweennessSlider.setPreferredSize(new Dimension(350, 50));
    edgeBetweennessSlider.setPaintTicks(true);
    edgeBetweennessSlider.setMaximum(mygraph.getEdgeCount());
    edgeBetweennessSlider.setMinimum(0);
    edgeBetweennessSlider.setValue(0);
    if (mygraph.getEdgeCount() > 10) {
        edgeBetweennessSlider.setMajorTickSpacing(mygraph.getEdgeCount() / 10);
    } else {
        edgeBetweennessSlider.setMajorTickSpacing(1);
    }
    edgeBetweennessSlider.setPaintLabels(true);
    edgeBetweennessSlider.setPaintTicks(true);

    // I also want the slider value to appear
    final JPanel eastControls = new JPanel();
    eastControls.setOpaque(true);
    eastControls.setLayout(new BoxLayout(eastControls, BoxLayout.Y_AXIS));
    eastControls.add(Box.createVerticalGlue());
    eastControls.add(edgeBetweennessSlider);

    final String COMMANDSTRING = "Edges removed for clusters: ";
    final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue();

    final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize);
    eastControls.setBorder(sliderBorder);
    eastControls.add(Box.createVerticalGlue());

    groupVertices.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            clusterAndRecolor(layout, edgeBetweennessSlider.getValue(), similarColors,
                    e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });

    edgeBetweennessSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                int numEdgesToRemove = source.getValue();
                clusterAndRecolor(layout, numEdgesToRemove, similarColors, groupVertices.isSelected());
                sliderBorder.setTitle(COMMANDSTRING + edgeBetweennessSlider.getValue());
                eastControls.repaint();
                vv.validate();
                vv.repaint();
            }
        }
    });

    clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected());

    clusterpanel = new JPanel();
    clusterpanel.setLayout(new BoxLayout(clusterpanel, BoxLayout.Y_AXIS));
    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    clusterpanel.add(gzsp);
    JPanel south = new JPanel();
    JPanel grid = new JPanel(new GridLayout(2, 1));
    grid.add(scramble);
    grid.add(groupVertices);
    south.add(grid);
    south.add(eastControls);
    JPanel p = new JPanel();
    p.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    p.add(gm.getModeComboBox());
    south.add(p);
    clusterpanel.add(south);
    clusterpanel.add(Box.createGlue());
    semscroller = new SemGenScrollPane(sempanel);
    splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, semscroller, clusterpanel);
    splitpane.setDividerLocation(initsempanelwidth);
    splitpane.setDividerLocation(initsempanelwidth + 10);
    this.add(splitpane);
    this.setPreferredSize(new Dimension(950, 800));
    this.pack();
    this.setLocationRelativeTo(null);
    this.setVisible(true);
}

From source file:typoscript.TypoScriptPluginOptions.java

protected void _init() {
    // Take a copy of the current sites config
    localSitesConfig = (Vector) TypoScriptPlugin.siteConfig.clone();

    listModel = new DefaultListModel();
    Iterator iter = localSitesConfig.iterator();
    while (iter.hasNext()) {
        listModel.addElement(iter.next());
    }//from  ww  w  . j a  v a 2 s.c  o m

    setLayout(new BorderLayout());

    add(BorderLayout.NORTH, new JLabel("TYPO3 Sites"));

    JPanel sites = new JPanel(new BorderLayout());
    siteList = new JList(listModel);
    siteList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    siteList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            updateButtons();
        }
    });

    siteList.addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            // Edit if doubleclick
            if (e.getClickCount() == 2) {
                new AddEditSiteDialog(TypoScriptPluginOptions.this,
                        (T3Site) localSitesConfig.get(siteList.getSelectedIndex()));
            }
        }

        public void mouseEntered(MouseEvent e) {
            ;
        }

        public void mousePressed(MouseEvent e) {
            ;
        }

        public void mouseReleased(MouseEvent e) {
            ;
        }

        public void mouseExited(MouseEvent e) {
            ;
        }

    });
    JScrollPane scrollPane = new JScrollPane(siteList);
    sites.add(scrollPane);
    this.add(sites);

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
    buttons.setBorder(new EmptyBorder(6, 0, 0, 0));

    add = new RolloverButton(GUIUtilities.loadIcon("Plus.png"));
    add.setToolTipText("Add Site");
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // Open the add/edit dialog in add mode
            new AddEditSiteDialog(TypoScriptPluginOptions.this, null);
        }
    });

    buttons.add(add);
    remove = new RolloverButton(GUIUtilities.loadIcon("Minus.png"));
    remove.setToolTipText("Remove Site");
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            localSitesConfig.remove(siteList.getSelectedIndex());
            listModel.removeElementAt(siteList.getSelectedIndex());
        }
    });

    buttons.add(remove);
    edit = new RolloverButton(GUIUtilities.loadIcon("ButtonProperties.png"));
    edit.setToolTipText("Edit Site");
    edit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // Open add/edit dialog in edit mode
            new AddEditSiteDialog(TypoScriptPluginOptions.this,
                    (T3Site) localSitesConfig.get(siteList.getSelectedIndex()));
        }
    });

    buttons.add(edit);
    buttons.add(Box.createGlue());

    updateButtons();
    add(BorderLayout.SOUTH, buttons);
}