Example usage for javax.swing DefaultListCellRenderer DefaultListCellRenderer

List of usage examples for javax.swing DefaultListCellRenderer DefaultListCellRenderer

Introduction

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

Prototype

public DefaultListCellRenderer() 

Source Link

Document

Constructs a default renderer object for an item in a list.

Usage

From source file:captureplugin.drivers.DeviceCreatorDialog.java

/**
 * Create the GUI//from  ww w . j  a v  a  2 s . co  m
 */
private void createGUI() {
    UiUtilities.registerForClosing(this);

    DriverIf[] drivers = DriverFactory.getInstance().getDrivers();

    mDriverCombo = new JComboBox(drivers);
    mDriverCombo.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {

            if (value instanceof DriverIf) {
                value = ((DriverIf) value).getDriverName();
            }

            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });

    JPanel panel = (JPanel) getContentPane();

    panel.setLayout(new GridBagLayout());

    GridBagConstraints label = new GridBagConstraints();

    label.insets = new Insets(5, 5, 5, 5);
    label.anchor = GridBagConstraints.NORTHWEST;

    GridBagConstraints input = new GridBagConstraints();

    input.fill = GridBagConstraints.HORIZONTAL;
    input.weightx = 1.0;
    input.gridwidth = GridBagConstraints.REMAINDER;
    input.insets = new Insets(5, 5, 5, 5);

    panel.add(new JLabel(mLocalizer.msg("Name", "Name")), label);

    mName = new JTextField();
    panel.add(mName, input);

    panel.add(new JLabel(mLocalizer.msg("Driver", "Driver")), label);
    panel.add(mDriverCombo, input);

    mDesc = UiUtilities.createHtmlHelpTextArea("");
    mDesc.setEditable(false);

    panel.add(new JLabel(mLocalizer.msg("Description", "Description")), input);

    GridBagConstraints descC = new GridBagConstraints();
    descC.weightx = 1.0;
    descC.weighty = 1.0;
    descC.fill = GridBagConstraints.BOTH;
    descC.gridwidth = GridBagConstraints.REMAINDER;
    descC.insets = new Insets(5, 5, 5, 5);

    panel.add(new JScrollPane(mDesc, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), descC);

    final Font font = new JLabel().getFont();

    String desc = ((DriverIf) mDriverCombo.getSelectedItem()).getDriverDesc();
    desc = "<html><div style=\"color:#000000;font-family:" + font.getName() + "; font-size:" + font.getSize()
            + ";\">" + desc + "</div></html>";
    mDesc.setText(desc);
    mDesc.setFont(font);

    mDriverCombo.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            String description = ((DriverIf) mDriverCombo.getSelectedItem()).getDriverDesc();
            description = "<html><div style=\"color:#000000;font-family:" + font.getName() + "; font-size:"
                    + font.getSize() + ";\">" + description + "</div></html>";
            mDesc.setText(description);
            mDesc.setFont(font);
        }

    });

    final JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK));
    ok.setEnabled(false);
    final JButton cancel = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL));
    ok.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            okPressed();
        }
    });

    cancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            setVisible(false);
        }
    });

    mName.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            updateButtons();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateButtons();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateButtons();
        }

        private void updateButtons() {
            ok.setEnabled(!mName.getText().trim().isEmpty());
        }
    });

    ButtonBarBuilder2 builder = new ButtonBarBuilder2();
    builder.addGlue();
    builder.addButton(new JButton[] { ok, cancel });

    getRootPane().setDefaultButton(ok);

    input.insets = new Insets(5, 5, 5, 5);

    panel.add(builder.getPanel(), input);

    setSize(400, 300);

}

From source file:de.codesourcery.jasm16.ide.ui.views.EmulationOptionsView.java

public EmulationOptionsView() {
    emulatorPanel.setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = constraints(0, 0, false, false, GridBagConstraints.NONE);
    emulatorPanel.add(new JLabel("Emulation speed"), cnstrs);

    cnstrs = constraints(1, 0, true, true, GridBagConstraints.NONE);
    cnstrs.anchor = GridBagConstraints.WEST;
    emulatorPanel.setBorder(BorderFactory.createTitledBorder("General options"));

    speedBox.setRenderer(new DefaultListCellRenderer() {

        public Component getListCellRendererComponent(javax.swing.JList<?> list, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            final java.awt.Component result = super.getListCellRendererComponent(list, value, index, isSelected,
                    cellHasFocus);/*from   ww  w  .j  a v a 2 s .  co m*/

            if (value != null) {
                switch ((EmulationSpeed) value) {
                case MAX_SPEED:
                    setText("Max.");
                    break;
                case REAL_SPEED:
                    setText("100 kHz");
                    break;
                default:
                    setText(value.toString());
                    break;
                }
            }
            return result;
        };
    });

    emulatorPanel.add(speedBox, cnstrs);

    // disk drive panel
    selectedFileField.setColumns(25);

    diskDrivePanel.setLayout(new GridBagLayout());
    cnstrs = constraints(0, 0, false, true, GridBagConstraints.NONE);
    cnstrs.anchor = GridBagConstraints.CENTER;

    diskDrivePanel.setBorder(BorderFactory.createTitledBorder("Disk drive"));
    diskDrivePanel.add(selectedFileField, cnstrs);

    cnstrs = constraints(1, 0, false, true, GridBagConstraints.NONE);
    cnstrs.anchor = GridBagConstraints.CENTER;
    diskDrivePanel.add(fileChooserButton, cnstrs);

    fileChooserButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final JFileChooser chooser;
            if (getSelectedFile() != null) {
                chooser = new JFileChooser(getSelectedFile().getParentFile());
            } else {
                chooser = new JFileChooser();
            }
            final int result = chooser.showOpenDialog(null);
            if (result == JFileChooser.APPROVE_OPTION && chooser.getSelectedFile().isFile()) {
                selectedFileField.setText(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });

    cnstrs = constraints(2, 0, false, true, GridBagConstraints.NONE);
    cnstrs.anchor = GridBagConstraints.CENTER;
    diskDrivePanel.add(writeProtected, cnstrs);
}

From source file:filterviewplugin.FilterViewSettingsTab.java

public JPanel createSettingsPanel() {
    final EnhancedPanelBuilder panelBuilder = new EnhancedPanelBuilder(FormFactory.RELATED_GAP_COLSPEC.encode()
            + ',' + FormFactory.PREF_COLSPEC.encode() + ',' + FormFactory.RELATED_GAP_COLSPEC.encode() + ','
            + FormFactory.PREF_COLSPEC.encode() + ", fill:default:grow");
    final CellConstraints cc = new CellConstraints();

    final JLabel label = new JLabel(mLocalizer.msg("daysToShow", "Days to show"));

    panelBuilder.addRow();//from ww w  . j a  v  a  2  s  .c  o m
    panelBuilder.add(label, cc.xy(2, panelBuilder.getRow()));

    final SpinnerNumberModel model = new SpinnerNumberModel(3, 1, 7, 1);
    mSpinner = new JSpinner(model);
    mSpinner.setValue(mSettings.getDays());
    panelBuilder.add(mSpinner, cc.xy(4, panelBuilder.getRow()));

    panelBuilder.addParagraph(mLocalizer.msg("filters", "Filters to show"));

    mFilterList = new SelectableItemList(mSettings.getActiveFilterNames(),
            FilterViewSettings.getAvailableFilterNames());
    mIcons.clear();
    for (String filterName : FilterViewSettings.getAvailableFilterNames()) {
        mIcons.put(filterName, mSettings.getFilterIconName(mSettings.getFilter(filterName)));
    }
    mFilterList.addCenterRendererComponent(String.class, new SelectableItemRendererCenterComponentIf() {
        private DefaultListCellRenderer mRenderer = new DefaultListCellRenderer();

        public void calculateSize(JList list, int index, JPanel contentPane) {
        }

        public JPanel createCenterPanel(JList list, Object value, int index, boolean isSelected,
                boolean isEnabled, JScrollPane parentScrollPane, int leftColumnWidth) {
            DefaultListCellRenderer label = (DefaultListCellRenderer) mRenderer
                    .getListCellRendererComponent(list, value, index, isSelected, false);
            String filterName = value.toString();
            String iconFileName = mIcons.get(filterName);
            Icon icon = null;
            if (!StringUtils.isEmpty(iconFileName)) {
                try {
                    icon = FilterViewPlugin.getInstance().getIcon(
                            FilterViewSettings.getIconDirectoryName() + File.separatorChar + iconFileName);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                label.setIcon(icon);
            }
            String text = filterName;
            if (icon == null) {
                text += " (" + mLocalizer.msg("noIcon", "no icon") + ')';
            }
            label.setText(text);
            label.setHorizontalAlignment(SwingConstants.LEADING);
            label.setVerticalAlignment(SwingConstants.CENTER);
            label.setOpaque(false);

            JPanel panel = new JPanel(new BorderLayout());
            if (isSelected && isEnabled) {
                panel.setOpaque(true);
                panel.setForeground(list.getSelectionForeground());
                panel.setBackground(list.getSelectionBackground());
            } else {
                panel.setOpaque(false);
                panel.setForeground(list.getForeground());
                panel.setBackground(list.getBackground());
            }
            panel.add(label, BorderLayout.WEST);
            return panel;
        }
    });

    panelBuilder.addGrowingRow();
    panelBuilder.add(mFilterList, cc.xyw(2, panelBuilder.getRow(), panelBuilder.getColumnCount() - 1));

    panelBuilder.addRow();
    mFilterButton = new JButton(mLocalizer.msg("changeIcon", "Change icon"));
    mFilterButton.setEnabled(false);
    panelBuilder.add(mFilterButton, cc.xyw(2, panelBuilder.getRow(), 1));

    mRemoveButton = new JButton(mLocalizer.msg("deleteIcon", "Remove icon"));
    mRemoveButton.setEnabled(false);
    panelBuilder.add(mRemoveButton, cc.xyw(4, panelBuilder.getRow(), 1));

    mFilterButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            SelectableItem item = (SelectableItem) mFilterList.getSelectedValue();
            String filterName = (String) item.getItem();
            chooseIcon(filterName);
        }
    });

    mFilterList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            mFilterButton.setEnabled(mFilterList.getSelectedValue() != null);
            mRemoveButton.setEnabled(mFilterButton.isEnabled());
        }
    });

    mRemoveButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            SelectableItem item = (SelectableItem) mFilterList.getSelectedValue();
            String filterName = (String) item.getItem();
            mIcons.put(filterName, "");
            mFilterList.updateUI();
        }
    });

    return panelBuilder.getPanel();
}

From source file:au.com.jwatmuff.eventmanager.gui.main.LoadCompetitionWindow.java

/** Creates new form LoadCompetitionWindow */
public LoadCompetitionWindow(DatabaseManager dbManager, LicenseManager licenseManager,
        PeerManager peerManager) {/*from  w  w w.  j  a va2  s  . com*/
    initComponents();
    setIconImage(Icons.MAIN_WINDOW.getImage());

    this.dbManager = dbManager;
    this.licenseManager = licenseManager;
    this.peerManager = peerManager;
    this.getRootPane().setDefaultButton(okButton);

    chatPanelContainer.setLayout(new GridLayout(1, 1));
    chatPanelContainer.add(new ChatPanel(peerManager));

    competitionList.setCellRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object obj, int arg2, boolean arg3,
                boolean arg4) {
            if (obj instanceof DatabaseInfo) {
                DatabaseInfo di = (DatabaseInfo) obj;
                JLabel label = (JLabel) super.getListCellRendererComponent(list, di.name, arg2, arg3, arg4);
                label.setIcon((!Main.VERSION.equals(di.version)) ? Icons.NO
                        : (di.peers > 0) ? Icons.REMOTE : Icons.LOCAL);
                return label;
            }
            return super.getListCellRendererComponent(list, obj, arg2, arg3, arg4);
        }

    });

    this.competitionList.setModel(dbListModel);
    updateDatabaseList();
    updateLicenseInfo();

    updateOkButton();

    // center window on screen
    setLocationRelativeTo(null);
}

From source file:com.epiq.bitshark.ui.FrequencyDomainPanel.java

/** Creates new form FrequencyDomainPanel */
public FrequencyDomainPanel() {
    initComponents();//from   w  w w.  ja v  a  2  s . c  o m

    initGraph();

    headerPanel.setBackgroundPainter(Common.getHeaderPainter());

    JPanel holderPanel = new JPanel() {
        @Override
        public void paint(Graphics g) {

            if (plot.getDomainAxis().isAutoRange()) {
                plot.getDomainAxis().setAutoRange(false);
                Range newDomain = new Range(0, FMCUartClient.BLOCK_SIZE - 1);
                plot.getDomainAxis().setRange(newDomain, true, false);
            }

            if (plot.getRangeAxis().isAutoRange()) {
                plot.getRangeAxis().setAutoRange(false);
                Range newRange = new Range(-50, 70);
                plot.getRangeAxis().setRange(newRange, true, false);
            }

            super.paint(g);
        }
    };
    holderPanel.setLayout(new BorderLayout());
    holderPanel.add(chartPanel, BorderLayout.CENTER);
    this.mainPanel.add(holderPanel, BorderLayout.CENTER);

    windowComboBox.setModel(new DefaultComboBoxModel(WindowFunction.values()));
    windowComboBox.setSelectedItem(WindowFunction.BLACKMAN_HARRIS);
    windowComboBox.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {

            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (c instanceof JLabel && value instanceof WindowFunction) {
                JLabel l = (JLabel) c;
                WindowFunction cw = (WindowFunction) value;
                l.setText(cw.getName());
            }

            return c;
        }

    });

    graphLabel.setUI(new BasicLabelUI());
    alphaLabel.setUI(new BasicLabelUI());
    windowLabel.setUI(new BasicLabelUI());
}

From source file:de.codesourcery.gittimelapse.MyFrame.java

public MyFrame(File file, GitHelper gitHelper) throws RevisionSyntaxException, MissingObjectException,
        IncorrectObjectTypeException, AmbiguousObjectException, IOException, GitAPIException {
    super("GIT timelapse: " + file.getAbsolutePath());
    if (gitHelper == null) {
        throw new IllegalArgumentException("gitHelper must not be NULL");
    }/*from  w  ww .  j  a  va 2s . c om*/

    this.gitHelper = gitHelper;
    this.file = file;
    this.diffPanel = new DiffPanel();

    final JDialog dialog = new JDialog((Frame) null, "Please wait...", false);
    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(new JLabel("Please wait, locating revisions..."), BorderLayout.CENTER);
    dialog.pack();
    dialog.setVisible(true);

    final IProgressCallback callback = new IProgressCallback() {

        @Override
        public void foundCommit(ObjectId commitId) {
            System.out.println("*** Found commit " + commitId);
        }
    };

    System.out.println("Locating commits...");
    commitList = gitHelper.findCommits(file, callback);

    dialog.setVisible(false);

    if (commitList.isEmpty()) {
        throw new RuntimeException("Found no commits");
    }
    setMenuBar(createMenuBar());

    diffModeChooser.setModel(new DefaultComboBoxModel<MyFrame.DiffDisplayMode>(DiffDisplayMode.values()));
    diffModeChooser.setSelectedItem(DiffDisplayMode.ALIGN_CHANGES);
    diffModeChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final ObjectId commit = commitList.getCommit(revisionSlider.getValue() - 1);
            try {
                diffPanel.showRevision(commit);
            } catch (IOException | PatchApplyException e1) {
                e1.printStackTrace();
            }
        }
    });

    diffModeChooser.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            Component result = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            DiffDisplayMode mode = (DiffDisplayMode) value;
            switch (mode) {
            case ALIGN_CHANGES:
                setText("Align changes");
                break;
            case REGULAR:
                setText("Regular");
                break;
            default:
                setText(mode.toString());
            }
            return result;
        }
    });

    revisionSlider = new JSlider(1, commitList.size());

    revisionSlider.setPaintLabels(true);
    revisionSlider.setPaintTicks(true);

    addKeyListener(keyListener);
    getContentPane().addKeyListener(keyListener);

    if (commitList.size() < 10) {
        revisionSlider.setMajorTickSpacing(1);
        revisionSlider.setMinorTickSpacing(1);
    } else {
        revisionSlider.setMajorTickSpacing(5);
        revisionSlider.setMinorTickSpacing(1);
    }

    final ObjectId latestCommit = commitList.getLatestCommit();
    if (latestCommit != null) {
        revisionSlider.setValue(1 + commitList.indexOf(latestCommit));
        revisionSlider.setToolTipText(latestCommit.getName());
    }

    revisionSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!revisionSlider.getValueIsAdjusting()) {
                final ObjectId commit = commitList.getCommit(revisionSlider.getValue() - 1);
                long time = -System.currentTimeMillis();
                try {
                    diffPanel.showRevision(commit);
                } catch (IOException | PatchApplyException e1) {
                    e1.printStackTrace();
                } finally {
                    time += System.currentTimeMillis();
                }
                if (Main.DEBUG_MODE) {
                    System.out.println("Rendering time: " + time);
                }
            }
        }
    });

    getContentPane().setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = new GridBagConstraints();
    cnstrs.gridx = 0;
    cnstrs.gridy = 0;
    cnstrs.gridwidth = 1;
    cnstrs.gridheight = 1;
    cnstrs.weightx = 0;
    cnstrs.weighty = 0;
    cnstrs.fill = GridBagConstraints.NONE;

    getContentPane().add(new JLabel("Diff display mode:"), cnstrs);

    cnstrs = new GridBagConstraints();
    cnstrs.gridx = 1;
    cnstrs.gridy = 0;
    cnstrs.gridwidth = 1;
    cnstrs.gridheight = 1;
    cnstrs.weightx = 0;
    cnstrs.weighty = 0;
    cnstrs.fill = GridBagConstraints.NONE;

    getContentPane().add(diffModeChooser, cnstrs);

    cnstrs = new GridBagConstraints();
    cnstrs.gridx = 2;
    cnstrs.gridy = 0;
    cnstrs.gridwidth = 1;
    cnstrs.gridheight = 1;
    cnstrs.weightx = 1.0;
    cnstrs.weighty = 0;
    cnstrs.fill = GridBagConstraints.HORIZONTAL;

    getContentPane().add(revisionSlider, cnstrs);

    cnstrs = new GridBagConstraints();
    cnstrs.gridx = 0;
    cnstrs.gridy = 1;
    cnstrs.gridwidth = 3;
    cnstrs.gridheight = 1;
    cnstrs.weightx = 1;
    cnstrs.weighty = 1;
    cnstrs.fill = GridBagConstraints.BOTH;

    getContentPane().add(diffPanel, cnstrs);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    if (latestCommit != null) {
        diffPanel.showRevision(latestCommit);
    }
}

From source file:com.liveperson.infra.akka.actorx.ui.DisplayGraph.java

public static JPanel getGraphPanel() {

    final VisualizationViewer<String, String> vv = new VisualizationViewer<String, String>(new FRLayout(graph));

    vv.setBackground(Color.white);

    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(vv.getPickedVertexState(), Color.blue, Color.yellow));
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<String, String>() {
        @Override/*from  w  w  w  .  j av a 2  s .com*/
        public String transform(String s) {
            return getClassName(s);
        }
    });
    vv.setVertexToolTipTransformer(new Transformer<String, String>() {
        @Override
        public String transform(String s) {
            return getClassName(s);
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<String>(vv.getPickedEdgeState(), Color.black, Color.green));
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<String, String>());
    vv.setEdgeToolTipTransformer(new Transformer<String, String>() {
        @Override
        public String transform(String edge) {
            StringBuffer buffer = new StringBuffer();
            buffer.append("<html>");
            int index = edge.indexOf(Main.DELIMITER);
            String fromActor = edge.substring(0, index);
            String toActor = edge.substring(index + Main.DELIMITER.length());
            Map<String, Set<String>> connections = castConnectionList.get(fromActor);
            Set<String> messages = connections.get(toActor);
            for (String msg : messages) {
                buffer.append("<p>").append(getClassName(msg));
            }
            buffer.append("</html>");
            return buffer.toString();
        }
    });
    ToolTipManager.sharedInstance().setDismissDelay(60000);

    final DefaultModalGraphMouse<String, String> graphMouse = new DefaultModalGraphMouse<String, String>();
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
    vv.setGraphMouse(graphMouse);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });
    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Layout<String, String> layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                //            if(layout instanceof IterativeContext) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }
    });

    JPanel jp = new JPanel();
    jp.setBackground(Color.WHITE);
    jp.setLayout(new BorderLayout());
    jp.add(vv, BorderLayout.CENTER);
    Class[] combos = getCombos();
    final JComboBox jcb = new JComboBox(combos);
    // use a renderer to shorten the layout name presentation
    jcb.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            String valueString = value.toString();
            valueString = valueString.substring(valueString.lastIndexOf('.') + 1);
            return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus);
        }
    });
    jcb.addActionListener(new LayoutChooser(jcb, vv));
    jcb.setSelectedItem(FRLayout.class);

    JPanel control_panel = new JPanel(new GridLayout(2, 1));
    JPanel topControls = new JPanel();
    JPanel bottomControls = new JPanel();
    control_panel.add(topControls);
    control_panel.add(bottomControls);
    jp.add(control_panel, BorderLayout.NORTH);

    topControls.add(jcb);
    bottomControls.add(plus);
    bottomControls.add(minus);
    bottomControls.add(reset);
    return jp;
}

From source file:CSSDFarm.UserInterface.java

/**
 * Displays the Manager Screen //from ww w.j  a  v  a  2s . co m
 */
public void selectManagerView() {
    //remove old panel details
    if (panelReport.isVisible()) {
        comboReportFieldStations.setModel(new DefaultComboBoxModel());
    }

    //Disable the other panels
    panelReport.setVisible(false);
    panelManager.setVisible(true);
    userFieldStations = server.loadData();

    //Set the user lists renderer
    listUserStations.setCellRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            Component renderer = super.getListCellRendererComponent(list, value, index, isSelected,
                    cellHasFocus);
            if (renderer instanceof JLabel && value instanceof FieldStation) {
                // Here value will be of the Type 'FieldStation'
                ((JLabel) renderer).setText(((FieldStation) value).getName());
            }
            return renderer;
        }
    });

    //If users is a food processing manager then disable the farmer buttons
    if (server.getUsersRole() == 1) {
        btnAddSensor.setVisible(false);
        btnRemoveSensor.setVisible(false);
        btnAddFieldStation.setVisible(false);
        btnRemoveFieldStation.setVisible(false);
    }

    //Set the manager panel to visible
    panelManager.setVisible(true);

    //Load the users last selected values
    int pos = loadUserData("data/userSettings.ser");
    try {
        listUserStations.setSelectedIndex(pos);
    } catch (Exception eX) {

    }

}

From source file:cimat.tesis.sna.visualization.ShowLayouts.java

private static JPanel getGraphPanel() {
    g_array = (Graph<? extends Object, ? extends Object>[]) new Graph<?, ?>[graph_names.length];

    Factory<Graph<Integer, Number>> graphFactory = new Factory<Graph<Integer, Number>>() {
        public Graph<Integer, Number> create() {
            return new SparseMultigraph<Integer, Number>();
        }//from w  w  w .j  a  v  a  2 s. co m
    };

    Factory<Integer> vertexFactory = new Factory<Integer>() {
        int count;

        public Integer create() {
            return count++;
        }
    };
    Factory<Number> edgeFactory = new Factory<Number>() {
        int count;

        public Number create() {
            return count++;
        }
    };

    g_array[0] = TestGraphs.createTestGraph(false);
    g_array[1] = MixedRandomGraphGenerator.generateMixedRandomGraph(graphFactory, vertexFactory, edgeFactory,
            new HashMap<Number, Number>(), 20, true, new HashSet<Integer>());
    g_array[2] = TestGraphs.getDemoGraph();
    g_array[3] = TestGraphs.createDirectedAcyclicGraph(4, 4, 0.3);
    g_array[4] = TestGraphs.getOneComponentGraph();
    g_array[5] = TestGraphs.createChainPlusIsolates(18, 5);
    g_array[6] = TestGraphs.createChainPlusIsolates(0, 20);

    Graph<? extends Object, ? extends Object> g = g_array[4]; // initial graph

    final VisualizationViewer<Integer, Number> vv = new VisualizationViewer<Integer, Number>(new FRLayout(g));

    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.red, Color.yellow));

    final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>();
    vv.setGraphMouse(graphMouse);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });
    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Layout<Integer, Number> layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                //            if(layout instanceof IterativeContext) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }
    });

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener());

    JPanel jp = new JPanel();
    jp.setBackground(Color.WHITE);
    jp.setLayout(new BorderLayout());
    jp.add(vv, BorderLayout.CENTER);
    Class[] combos = getCombos();
    final JComboBox jcb = new JComboBox(combos);
    // use a renderer to shorten the layout name presentation
    jcb.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            String valueString = value.toString();
            valueString = valueString.substring(valueString.lastIndexOf('.') + 1);
            return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus);
        }
    });
    jcb.addActionListener(new LayoutChooser(jcb, vv));
    jcb.setSelectedItem(FRLayout.class);

    JPanel control_panel = new JPanel(new GridLayout(2, 1));
    JPanel topControls = new JPanel();
    JPanel bottomControls = new JPanel();
    control_panel.add(topControls);
    control_panel.add(bottomControls);
    jp.add(control_panel, BorderLayout.NORTH);

    final JComboBox graph_chooser = new JComboBox(graph_names);

    graph_chooser.addActionListener(new GraphChooser(jcb));

    topControls.add(jcb);
    topControls.add(graph_chooser);
    bottomControls.add(plus);
    bottomControls.add(minus);
    bottomControls.add(modeBox);
    bottomControls.add(reset);
    return jp;
}

From source file:edu.uci.ics.jung.samples.ShowLayouts.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private static JPanel getGraphPanel() {
    g_array = (Graph<? extends Object, ? extends Object>[]) new Graph<?, ?>[graph_names.length];

    Factory<Graph<Integer, Number>> graphFactory = new Factory<Graph<Integer, Number>>() {
        public Graph<Integer, Number> create() {
            return new SparseMultigraph<Integer, Number>();
        }//www .j av a  2 s .  c  om
    };

    Factory<Integer> vertexFactory = new Factory<Integer>() {
        int count;

        public Integer create() {
            return count++;
        }
    };
    Factory<Number> edgeFactory = new Factory<Number>() {
        int count;

        public Number create() {
            return count++;
        }
    };

    g_array[0] = TestGraphs.createTestGraph(false);
    g_array[1] = MixedRandomGraphGenerator.generateMixedRandomGraph(graphFactory, vertexFactory, edgeFactory,
            new HashMap<Number, Number>(), 20, true, new HashSet<Integer>());
    g_array[2] = TestGraphs.getDemoGraph();
    g_array[3] = TestGraphs.createDirectedAcyclicGraph(4, 4, 0.3);
    g_array[4] = TestGraphs.getOneComponentGraph();
    g_array[5] = TestGraphs.createChainPlusIsolates(18, 5);
    g_array[6] = TestGraphs.createChainPlusIsolates(0, 20);

    Graph<? extends Object, ? extends Object> g = g_array[4]; // initial graph

    final VisualizationViewer<Integer, Number> vv = new VisualizationViewer<Integer, Number>(new FRLayout(g));

    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.red, Color.yellow));

    final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>();
    vv.setGraphMouse(graphMouse);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });
    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Layout<Integer, Number> layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                //            if(layout instanceof IterativeContext) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }
    });

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener());

    JPanel jp = new JPanel();
    jp.setBackground(Color.WHITE);
    jp.setLayout(new BorderLayout());
    jp.add(vv, BorderLayout.CENTER);
    Class[] combos = getCombos();
    final JComboBox jcb = new JComboBox(combos);
    // use a renderer to shorten the layout name presentation
    jcb.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            String valueString = value.toString();
            valueString = valueString.substring(valueString.lastIndexOf('.') + 1);
            return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus);
        }
    });
    jcb.addActionListener(new LayoutChooser(jcb, vv));
    jcb.setSelectedItem(FRLayout.class);

    JPanel control_panel = new JPanel(new GridLayout(2, 1));
    JPanel topControls = new JPanel();
    JPanel bottomControls = new JPanel();
    control_panel.add(topControls);
    control_panel.add(bottomControls);
    jp.add(control_panel, BorderLayout.NORTH);

    final JComboBox graph_chooser = new JComboBox(graph_names);

    graph_chooser.addActionListener(new GraphChooser(jcb));

    topControls.add(jcb);
    topControls.add(graph_chooser);
    bottomControls.add(plus);
    bottomControls.add(minus);
    bottomControls.add(modeBox);
    bottomControls.add(reset);
    return jp;
}