Example usage for javax.swing.event ChangeListener ChangeListener

List of usage examples for javax.swing.event ChangeListener ChangeListener

Introduction

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

Prototype

ChangeListener

Source Link

Usage

From source file:richtercloud.reflection.form.builder.typehandler.NumberTypeHandler.java

@Override
public Pair<JComponent, ComponentHandler<?>> handle(Type type, Number fieldValue, String fieldName,
        Class<?> declaringClass, final FieldUpdateListener<FieldUpdateEvent<Number>> updateListener,
        ReflectionFormBuilder reflectionFormBuilder)
        throws IllegalArgumentException, IllegalAccessException, FieldHandlingException {
    //@TODO: handle validaton annotations (should cover all cases, so no
    // need to develop own annotations
    JSpinner retValue = new JSpinner(new SpinnerNumberModel(fieldValue, null, null, 1));
    retValue.addChangeListener(new ChangeListener() {

        @Override//from ww  w  .  j a v  a  2  s .  com
        public void stateChanged(ChangeEvent e) {
            updateListener.onUpdate(new FieldUpdateEvent<>((Number) ((JSpinner) e.getSource()).getValue()));
        }
    });
    return new ImmutablePair<JComponent, ComponentHandler<?>>(retValue, this);
}

From source file:ro.nextreports.designer.querybuilder.QueryBuilderPanel.java

private void initUI() {
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.setDividerLocation(250);/*from  www .  j  a  va  2s .  c o m*/
    split.setOneTouchExpandable(true);

    JToolBar toolBar = new JToolBar();
    toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders
    toolBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
    toolBar.setBorderPainted(false);

    // add refresh action
    toolBar.add(new AbstractAction() {

        public Object getValue(String key) {
            if (AbstractAction.SMALL_ICON.equals(key)) {
                return ImageUtil.getImageIcon("refresh");
            } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) {
                return I18NSupport.getString("querybuilder.refresh");
            }

            return super.getValue(key);
        }

        public void actionPerformed(ActionEvent e) {
            try {
                if (Globals.getConnection() == null) {
                    return;
                }

                // refresh tables, views, procedures
                TreeUtil.refreshDatabase();

                // add new queries to tree
                TreeUtil.refreshQueries();

                // add new reports to tree
                TreeUtil.refreshReports();

                // add new charts to tree
                TreeUtil.refreshCharts();

            } catch (Exception ex) {
                Show.error(ex);
            }
        }

    });

    // add expand action
    toolBar.add(new AbstractAction() {

        public Object getValue(String key) {
            if (AbstractAction.SMALL_ICON.equals(key)) {
                return ImageUtil.getImageIcon("expandall");
            } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) {
                return I18NSupport.getString("querybuilder.expand.all");
            }

            return super.getValue(key);
        }

        public void actionPerformed(ActionEvent e) {
            TreeUtil.expandAll(dbBrowserTree);
        }

    });

    // add collapse action
    toolBar.add(new AbstractAction() {

        public Object getValue(String key) {
            if (AbstractAction.SMALL_ICON.equals(key)) {
                return ImageUtil.getImageIcon("collapseall");
            } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) {
                return I18NSupport.getString("querybuilder.collapse.all");
            }

            return super.getValue(key);
        }

        public void actionPerformed(ActionEvent e) {
            TreeUtil.collapseAll(dbBrowserTree);
        }

    });

    // add properties button
    /*
      JButton propButton = new MagicButton(new AbstractAction() {
            
      public Object getValue(String key) {
          if (AbstractAction.SMALL_ICON.equals(key)) {
              return ImageUtil.getImageIcon("properties");
          }
            
          return super.getValue(key);
      }
            
      public void actionPerformed(ActionEvent e) {
          DBBrowserPropertiesPanel joinPanel = new DBBrowserPropertiesPanel();
          JDialog dlg = new DBBrowserPropertiesDialog(joinPanel);
          dlg.pack();
          dlg.setResizable(false);
          Show.centrateComponent(Globals.getMainFrame(), dlg);
          dlg.setVisible(true);
      }
            
      });
      propButton.setToolTipText(I18NSupport.getString("querybuilder.properties"));
      */
    //browserButtonsPanel.add(propButton);

    //        ro.nextreports.designer.util.SwingUtil.registerButtonsForFocus(browserButtonsPanel);

    browserPanel = new JXPanel(new BorderLayout());
    browserPanel.add(toolBar, BorderLayout.NORTH);

    // browser tree
    JScrollPane scroll = new JScrollPane(dbBrowserTree);
    browserPanel.add(scroll, BorderLayout.CENTER);
    split.setLeftComponent(browserPanel);

    tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
    //        tabbedPane.putClientProperty(Options.EMBEDDED_TABS_KEY, Boolean.TRUE); // look like eclipse

    JSplitPane split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    split2.setResizeWeight(0.66);
    split2.setOneTouchExpandable(true);

    // desktop pane
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    desktop.setDropTarget(
            new DropTarget(desktop, DnDConstants.ACTION_MOVE, new DesktopPaneDropTargetListener(), true));

    // create the toolbar
    JToolBar toolBar2 = new JToolBar();
    toolBar2.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders
    toolBar2.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
    toolBar2.setBorderPainted(false);

    Action distinctAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            if (distinctButton.isSelected()) {
                selectQuery.setDistinct(true);
            } else {
                selectQuery.setDistinct(false);
            }
        }

    };
    distinctAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("query.distinct"));
    distinctAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.distinct"));
    toolBar2.add(distinctButton = new JToggleButton(distinctAction));

    Action groupByAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            groupBy = groupByButton.isSelected();
            Globals.getEventBus().publish(new GroupByEvent(QueryBuilderPanel.this.desktop, groupBy));
        }

    };
    groupByAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("query.group_by"));
    groupByAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.group.by"));
    toolBar2.add(groupByButton = new JToggleButton(groupByAction));

    Action clearAction = new AbstractAction() {

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

    };
    clearAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("clear"));
    clearAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.clear"));
    toolBar2.add(clearAction);

    // add separator
    SwingUtil.addCustomSeparator(toolBar2);

    // add run button
    Action runQueryAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            selectSQLViewTab();
            sqlView.doRun();
        }

    };
    runQueryAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("run"));
    KeyStroke ks = KeyStroke.getKeyStroke(ShortcutsUtil.getShortcut("query.run.accelerator", "control 4"));
    runQueryAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("run.query") + " ("
            + ShortcutsUtil.getShortcut("query.run.accelerator.display", "Ctrl 4") + ")");
    runQueryAction.putValue(Action.ACCELERATOR_KEY, ks);
    toolBar2.add(runQueryAction);
    // register run query shortcut
    GlobalHotkeyManager hotkeyManager = GlobalHotkeyManager.getInstance();
    InputMap inputMap = hotkeyManager.getInputMap();
    ActionMap actionMap = hotkeyManager.getActionMap();
    inputMap.put((KeyStroke) runQueryAction.getValue(Action.ACCELERATOR_KEY), "runQueryAction");
    actionMap.put("runQueryAction", runQueryAction);

    JScrollPane scroll2 = new JScrollPane(desktop, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll2.setPreferredSize(DBTablesDesktopPane.PREFFERED_SIZE);
    DecoratedScrollPane.decorate(scroll2);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new GridBagLayout());
    topPanel.add(toolBar2, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    topPanel.add(scroll2, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

    split2.setTopComponent(topPanel);
    designPanel = new DesignerTablePanel(selectQuery);
    split2.setBottomComponent(designPanel);
    split2.setDividerLocation(400);

    tabbedPane.addTab(I18NSupport.getString("querybuilder.query.designer"), ImageUtil.getImageIcon("designer"),
            split2);
    tabbedPane.setMnemonicAt(0, 'D');

    sqlView = new SQLViewPanel();
    sqlView.getEditorPane().setDropTarget(new DropTarget(sqlView.getEditorPane(), DnDConstants.ACTION_MOVE,
            new SQLViewDropTargetListener(), true));
    tabbedPane.addTab(I18NSupport.getString("querybuilder.query.editor"), ImageUtil.getImageIcon("sql"),
            sqlView);
    tabbedPane.setMnemonicAt(1, 'E');

    split.setRightComponent(tabbedPane);

    // register a change listener
    tabbedPane.addChangeListener(new ChangeListener() {

        // this method is called whenever the selected tab changes
        public void stateChanged(ChangeEvent ev) {
            if (ev.getSource() == QueryBuilderPanel.this.tabbedPane) {
                // get current tab
                int sel = QueryBuilderPanel.this.tabbedPane.getSelectedIndex();
                if (sel == 1) { // sql view
                    String query;
                    if (!synchronizedPanels) {
                        query = sqlView.getQueryString();
                        synchronizedPanels = true;
                    } else {
                        if (Globals.getConnection() != null) {
                            query = getSelectQuery().toString();
                        } else {
                            query = "";
                        }
                        //                     if (query.equals("")) {
                        //                        query = sqlView.getQueryString();
                        //                     }
                    }
                    if (resetTable) {
                        sqlView.clear();
                        resetTable = false;
                    }
                    //System.out.println("query="+query);
                    sqlView.setQueryString(query);
                } else if (sel == 0) { // design view
                    if (queryWasModified(false)) {
                        Object[] options = { I18NSupport.getString("optionpanel.yes"),
                                I18NSupport.getString("optionpanel.no") };
                        String m1 = I18NSupport.getString("querybuilder.lost");
                        String m2 = I18NSupport.getString("querybuilder.continue");
                        int option = JOptionPane.showOptionDialog(Globals.getMainFrame(),
                                "<HTML>" + m1 + "<BR>" + m2 + "</HTML>",
                                I18NSupport.getString("querybuilder.confirm"), JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

                        if (option != JOptionPane.YES_OPTION) {
                            synchronizedPanels = false;
                            tabbedPane.setSelectedIndex(1);
                        } else {
                            resetTable = true;
                        }
                    }
                } else if (sel == 2) { // report view

                }
            }
        }

    });

    //        this.add(split, BorderLayout.CENTER);

    parametersPanel = new ParametersPanel();
}

From source file:ro.nextreports.designer.querybuilder.RuntimeParametersPanel.java

private void initUI() {
    setLayout(new GridBagLayout());

    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    components = new ArrayList<JComponent>();
    checks = new ArrayList<JCheckBox>();

    int size = paramList.size();
    boolean shouldExpand = false;
    boolean needScroll = false;
    for (int i = 0; i < size; i++) {
        final int pos = i;
        final QueryParameter param = paramList.get(i);
        if (param.isHidden()) {
            components.add(null);/*from   w w  w  . ja v  a 2s.c  o m*/
            checks.add(null);
            initHiddenParameterValues(param);
            continue;
        }
        String source = param.getSource();
        String defaultSource = param.getDefaultSource();

        if ((defaultSource != null) && !defaultSource.trim().equals("")) {
            try {
                param.setDefaultSourceValues(Globals.getDBViewer().getDefaultSourceValues(con, param));
            } catch (NextSqlException e) {
                Show.error(e);
            }
        }

        final JComponent component;
        int anchor = GridBagConstraints.WEST;
        double y = 0.0;
        int expand = GridBagConstraints.HORIZONTAL;
        if ((source != null) && !source.equals("")) {
            List<IdName> values = new ArrayList<IdName>();
            try {
                if (param.isManualSource()) {
                    if (!param.isDependent()) {
                        values = Globals.getDBViewer().getValues(con, source, true, param.getOrderBy());
                    }
                } else {
                    int index = source.indexOf(".");
                    int index2 = source.lastIndexOf(".");
                    String tableName = source.substring(0, index);
                    String columnName;
                    String shownColumnName = null;
                    if (index == index2) {
                        columnName = source.substring(index + 1);
                    } else {
                        columnName = source.substring(index + 1, index2);
                        shownColumnName = source.substring(index2 + 1);
                    }
                    values = Globals.getDBViewer().getColumnValues(con, param.getSchema(), tableName,
                            columnName, shownColumnName, param.getOrderBy());
                }
            } catch (NextSqlException e) {
                error = true;
                Show.error(e);
            } catch (InvalidSqlException e) {
                String m = I18NSupport.getString("source.dialog.valid");
                Show.info(m + " : \"select <exp1> , <exp2> from ...\"");
            }
            if (param.getSelection().equals(ParameterEditPanel.SINGLE_SELECTION)) {
                component = new JComboBox();
                final JComboBox combo = (JComboBox) component;
                combo.setRenderer(new IdNameRenderer());
                combo.addItem("-- " + I18NSupport.getString("parameter.value.select") + " --");
                for (int j = 0, len = values.size(); j < len; j++) {
                    combo.addItem(values.get(j));
                }

                combo.addItemListener(new ItemListener() {
                    public void itemStateChanged(ItemEvent e) {
                        if (e.getStateChange() == ItemEvent.SELECTED) {
                            IdName in = null;
                            if (combo.getSelectedIndex() > 0) {
                                in = (IdName) combo.getSelectedItem();
                            }
                            parameterSelection(pos, in);
                        }
                    }
                });
                AutoCompleteDecorator.decorate(combo);
                needScroll = false;
            } else {
                anchor = GridBagConstraints.NORTHWEST;
                y = 1.0;
                expand = GridBagConstraints.BOTH;

                DefaultListModel model = new DefaultListModel();
                for (int j = 0, len = values.size(); j < len; j++) {
                    model.addElement(values.get(j));
                }
                List srcList = Arrays.asList(model.toArray());
                component = new ListSelectionPanel(srcList, new ArrayList(), "", "", true, false) {
                    protected void onAdd() {
                        selection();
                    }

                    protected void onRemove() {
                        selection();
                    }

                    // needed for saved parameters on rerun
                    protected void onSetRight() {
                        selection();
                    }

                    private void selection() {
                        if (ParameterManager.getInstance().getChildDependentParameters(param).size() > 0) {
                            Object[] values = getDestinationElements().toArray();
                            if (values.length == 0) {
                                values = new Object[] { ParameterUtil.NULL };
                            }
                            parameterSelection(pos, values);
                        }
                    }
                };
                ((ListSelectionPanel) component).setListSize(scrListDim);
                ((ListSelectionPanel) component).setRenderer(new IdNameRenderer(),
                        new IdNameComparator(param.getOrderBy()));

                shouldExpand = true;
            }

        } else {
            if (param.getSelection().equals(QueryParameter.MULTIPLE_SELECTION)) {
                anchor = GridBagConstraints.NORTHWEST;
                y = 1.0;
                expand = GridBagConstraints.BOTH;
                ;
                component = new ListAddPanel(param) {
                    protected void onAdd() {
                        selection();
                    }

                    protected void onRemove() {
                        selection();
                    }

                    private void selection() {
                        if (ParameterManager.getInstance().getChildDependentParameters(param).size() > 0) {
                            Object[] values = getElements().toArray();
                            parameterSelection(pos, values);
                        }
                    }
                };
            } else {
                needScroll = false;
                if (param.getValueClassName().equals("java.util.Date")) {
                    component = new JXDatePicker();
                    ((JXDatePicker) component).addPropertyChangeListener(new PropertyChangeListener() {
                        public void propertyChange(PropertyChangeEvent e) {
                            if ("date".equals(e.getPropertyName())) {
                                parameterSelection(pos, ((JXDatePicker) component).getDate());
                            }
                        }
                    });
                    // hack to fix bug with big popup button
                    JButton popupButton = (JButton) component.getComponent(1);
                    //popupButton.setMargin(new Insets(2, 2, 2, 2));
                    popupButton.setMinimumSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                    popupButton.setPreferredSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                    popupButton.setBorder(BorderFactory.createLineBorder(Color.GRAY));
                } else if (param.getValueClassName().equals("java.sql.Timestamp")
                        || param.getValueClassName().equals("java.sql.Time")) {
                    component = new JDateTimePicker() {
                        protected void onChange() {
                            parameterSelection(pos, getDate());
                        }
                    };
                    // hack to fix bug with big popup button
                    JButton popupButton = (JButton) (((JDateTimePicker) component).getDatePicker())
                            .getComponent(1);
                    //popupButton.setMargin(new Insets(2, 2, 2, 2));
                    popupButton.setMinimumSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                    popupButton.setPreferredSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                    popupButton.setBorder(BorderFactory.createLineBorder(Color.GRAY));
                } else if (param.getValueClassName().equals("java.lang.Boolean")) {
                    component = new JCheckBox();
                    ((JCheckBox) component).addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent actionEvent) {
                            AbstractButton abstractButton = (AbstractButton) actionEvent.getSource();
                            boolean selected = abstractButton.getModel().isSelected();
                            parameterSelection(pos, selected);
                        }
                    });
                } else {
                    component = new JTextField(25);
                    ((JTextField) component).getDocument().addDocumentListener(new DocumentListener() {

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

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

                        @Override
                        public void removeUpdate(DocumentEvent e) {
                            updateFromTextField(e);
                        }

                        private void updateFromTextField(DocumentEvent e) {
                            java.awt.EventQueue.invokeLater(new Runnable() {

                                @Override
                                public void run() {
                                    Object value = null;
                                    try {
                                        if ("".equals(((JTextField) component).getText().trim())) {
                                            value = null;
                                        } else {
                                            value = ParameterUtil.getParameterValueFromString(
                                                    param.getValueClassName(),
                                                    ((JTextField) component).getText());
                                        }
                                        parameterSelection(pos, value);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        LOG.error(e.getMessage(), e);
                                    }
                                }
                            });
                        }
                    });
                }
            }
        }
        components.add(component);
        final JCheckBox cb = new JCheckBox(I18NSupport.getString("run.parameter.ignore"));
        checks.add(cb);

        final JLabel label = new JLabel(getRuntimeParameterName(param));
        panel.add(label, new GridBagConstraints(0, i, 1, 1, 0.0, 0.0, anchor, GridBagConstraints.NONE,
                new Insets(5, 5, 5, 5), 0, 0));
        final JComponent addComponent;
        if (needScroll) {
            JScrollPane scr = new JScrollPane(component, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            scr.setPreferredSize(listDim);
            addComponent = scr;
        } else {
            addComponent = component;
        }
        panel.add(addComponent, new GridBagConstraints(1, i, 1, 1, 1.0, y, GridBagConstraints.WEST, expand,
                new Insets(5, 0, 5, 5), 0, 0));
        int checkAnchor = GridBagConstraints.WEST;
        if ((addComponent instanceof JScrollPane) || (addComponent instanceof ListSelectionPanel)) {
            checkAnchor = GridBagConstraints.NORTHWEST;
        }

        if (Globals.getParametersIgnore()) {
            panel.add(cb, new GridBagConstraints(2, i, 1, 1, 0.0, 0.0, checkAnchor, GridBagConstraints.NONE,
                    new Insets(5, 0, 5, 5), 0, 0));
        }

        cb.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                if (cb.isSelected()) {
                    if (addComponent instanceof JScrollPane) {
                        component.setEnabled(false);
                    }
                    label.setEnabled(false);
                    addComponent.setEnabled(false);
                    param.setIgnore(true);
                } else {
                    if (addComponent instanceof JScrollPane) {
                        component.setEnabled(true);
                    }
                    label.setEnabled(true);
                    addComponent.setEnabled(true);
                    param.setIgnore(false);
                }
            }
        });
    }

    // populate hidden dependent parameters (this will be done if a parameter depends only on a single hidden parameter)
    // if a parameter depends on a hidden parameter and other parameters, it cannot be populated here
    for (int i = 0; i < size; i++) {
        final QueryParameter param = paramList.get(i);
        if (param.isHidden()) {
            populateDependentParameters(param, false);
        }
    }

    if (!shouldExpand) {
        panel.add(new JLabel(), new GridBagConstraints(0, size, 3, 1, 1.0, 1.0, GridBagConstraints.WEST,
                GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    }

    JScrollPane scrPanel = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrPanel.setPreferredSize(scrDim);
    scrPanel.setMinimumSize(scrDim);

    add(scrPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0), 0, 0));
    setParameterValues(parametersValues);
    setParameterIgnore(parametersIgnore);
}

From source file:savant.snp.SNPFinderPlugin.java

private void setupGUI(JPanel panel) {

    // add a toolbar
    JToolBar tb = new JToolBar();
    tb.setName("SNP Finder Toolbar");

    // add an ON/OFF checkbox
    JLabel lab_on = new JLabel("On/Off: ");
    JCheckBox cb_on = new JCheckBox();
    cb_on.setSelected(isSNPFinderOn);// w w  w.  j av  a 2  s. c o  m

    // what to do when a user clicks the checkbox
    cb_on.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // switch the SNP finder on/off
            setIsOn(!isSNPFinderOn);
            addMessage("Turning SNP finder " + (isSNPFinderOn ? "on" : "off"));
        }
    });
    // add a  Bookmarking ON/OFF checkbox
    JLabel lab_bm = new JLabel("Add Bookmarks: ");
    JCheckBox cb_bm = new JCheckBox();
    cb_bm.setSelected(addBookmarks);

    // what to do when a user clicks the checkbox
    cb_bm.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // switch the SNP finder on/off
            setBookmarking(!addBookmarks);
            addMessage("Turning Bookmarking " + (addBookmarks ? "on" : "off"));
        }
    });

    JLabel lab_sp = new JLabel("Heterozygosity: ");
    //add snp prior textfield
    final JTextField snpPriorField = new JTextField(String.valueOf(snpPrior), 4);
    snpPriorField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                setSNPPrior(Double.valueOf(snpPriorField.getText()));
            } catch (NumberFormatException ex) {
                snpPriorField.setText(String.valueOf(snpPrior));
            }
        }
    });
    int tfwidth = 35;
    int tfheight = 22;
    snpPriorField.setPreferredSize(new Dimension(tfwidth, tfheight));
    snpPriorField.setMaximumSize(new Dimension(tfwidth, tfheight));
    snpPriorField.setMinimumSize(new Dimension(tfwidth, tfheight));

    // add a sensitivity slider
    JLabel lab_confidence = new JLabel("Confidence: ");
    final JSlider sens_slider = new JSlider(0, 50);
    sens_slider.setValue(confidence);
    final JLabel lab_confidence_status = new JLabel("" + sens_slider.getValue());

    // what to do when a user slides the slider
    sens_slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            // set the snp finder's sensitivity
            lab_confidence_status.setText("" + sens_slider.getValue());
            setSensitivity(sens_slider.getValue());
        }
    });
    // don't report the new setting until the user stops sliding
    sens_slider.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            addMessage("Changed confidence to " + confidence);
        }
    });

    // add a transparency slider
    JLabel lab_trans = new JLabel("Transparency: ");
    final JSlider trans_slider = new JSlider(0, 100);
    trans_slider.setValue(transparency);
    final JLabel lab_transparency_status = new JLabel("" + trans_slider.getValue());

    // what to do when a user slides the slider
    trans_slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            // set the snp finder's transparency
            lab_transparency_status.setText("" + trans_slider.getValue());
            setTransparency(trans_slider.getValue());
        }
    });

    // don't report the new setting until the user stops sliding
    trans_slider.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            addMessage("Changed transparency to " + transparency);
        }
    });

    // add the components to the GUI
    panel.setLayout(new BorderLayout());
    tb.add(lab_on);
    tb.add(cb_on);
    tb.add(lab_bm);
    tb.add(cb_bm);
    tb.add(new JToolBar.Separator());
    tb.add(lab_sp);
    tb.add(snpPriorField);
    tb.add(new JToolBar.Separator());
    tb.add(lab_confidence);
    tb.add(sens_slider);
    tb.add(lab_confidence_status);

    tb.add(new JToolBar.Separator());

    tb.add(lab_trans);
    tb.add(trans_slider);
    tb.add(lab_transparency_status);

    panel.add(tb, BorderLayout.NORTH);

    // add a text area to the GUI
    info = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(info);
    panel.add(scrollPane, BorderLayout.CENTER);

}

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

/**
 * Create interval height slider for commandBar
 *//*ww w .  java  2s  .c  o m*/
private JMenu createIntervalMenu() {
    JMenu menu = new JMenu("Interval Height");
    intervalSlider = new JSlider(JSlider.VERTICAL, 1, AVAILABLE_INTERVAL_HEIGHTS.length, 1);
    intervalSlider.setMinorTickSpacing(1);
    intervalSlider.setMajorTickSpacing(AVAILABLE_INTERVAL_HEIGHTS.length / 2);
    intervalSlider.setSnapToTicks(true);
    intervalSlider.setPaintTicks(true);
    intervalSlider.setValue(
            getSliderFromIntervalHeight(InterfaceSettings.getIntervalHeight(mainTrack.getDataFormat())));
    intervalSlider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            int h = getIntervalHeight();
            if (graphPane.isScaledToFit()) {
                graphPane.setUnitHeight(h);
                graphPane.setScaledToFit(false); // Forces rerender and repaint internally.
            } else if (graphPane.getUnitHeight() != h) {
                graphPane.setUnitHeight(h);
                graphPane.setRenderForced();
                graphPane.repaint();
            }
        }
    });
    menu.add(intervalSlider);

    return menu;
}

From source file:se.llbit.chunky.renderer.ui.RenderControls.java

private void buildUI() {
    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    setModalityType(ModalityType.MODELESS);

    if (!ShutdownAlert.canShutdown()) {
        // disable the computer shutdown checkbox if we can't shutdown
        shutdownWhenDoneCB.setEnabled(false);
    }//w  w w. j  a va  2  s .c  o m

    addWindowListener(new WindowListener() {
        @Override
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }

        @Override
        public void windowClosing(WindowEvent e) {
            sceneMan.interrupt();
            RenderControls.this.dispose();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            // halt rendering
            renderMan.interrupt();

            // dispose of the 3D view
            view.setVisible(false);
            view.dispose();
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }
    });

    updateTitle();

    addTab("General", Icon.wrench, buildGeneralPane());
    addTab("Lighting", Icon.light, buildLightingPane());
    addTab("Sky", Icon.sky, buildSkyPane());
    addTab("Water", Icon.water, buildWaterPane());
    addTab("Camera", Icon.camera, buildCameraPane());
    addTab("Post-processing", Icon.gear, buildPostProcessingPane());
    addTab("Advanced", Icon.advanced, buildAdvancedPane());
    addTab("Help", Icon.question, buildHelpPane());

    JLabel sppTargetLbl = new JLabel("SPP Target: ");
    sppTargetLbl.setToolTipText("The render will be paused at this SPP count");

    JButton setDefaultBtn = new JButton("Make Default");
    setDefaultBtn.setToolTipText("Make the current SPP target the default");
    setDefaultBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            PersistentSettings.setSppTargetDefault(renderMan.scene().getTargetSPP());
        }
    });

    targetSPP.update();

    JLabel renderLbl = new JLabel("Render: ");

    setViewVisible(false);
    showPreviewBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (view.isViewVisible()) {
                view.hideView();
            } else {
                showPreviewWindow();
            }
        }
    });

    startRenderBtn.setText("START");
    startRenderBtn.setIcon(Icon.play.imageIcon());
    startRenderBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            switch (renderMan.scene().getRenderState()) {
            case PAUSED:
                renderMan.scene().resumeRender();
                break;
            case PREVIEW:
                renderMan.scene().startRender();
                break;
            case RENDERING:
                renderMan.scene().pauseRender();
                break;
            }
            stopRenderBtn.setEnabled(true);
        }
    });

    stopRenderBtn.setText("RESET");
    stopRenderBtn.setIcon(Icon.stop.imageIcon());
    stopRenderBtn.setToolTipText("<html>Warning: this will discard the "
            + "current rendered image!<br>Make sure to save your image " + "before stopping the renderer!");
    stopRenderBtn.setEnabled(false);
    stopRenderBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            renderMan.scene().haltRender();
        }
    });

    saveFrameBtn.setText("Save Current Frame");
    saveFrameBtn.addActionListener(saveFrameListener);

    sppLbl.setToolTipText("SPP = Samples Per Pixel, SPS = Samples Per Second");

    setRenderTime(0);
    setSamplesPerSecond(0);
    setSPP(0);
    setProgress("Progress:", 0, 0, 1);

    progressLbl.setText("Progress:");

    etaLbl.setText("ETA:");

    sceneNameLbl.setText("Scene name: ");
    sceneNameField.setColumns(15);
    AbstractDocument document = (AbstractDocument) sceneNameField.getDocument();
    document.setDocumentFilter(new SceneNameFilter());
    document.addDocumentListener(sceneNameListener);
    sceneNameField.addActionListener(sceneNameActionListener);
    updateSceneNameField();

    saveSceneBtn.setText("Save");
    saveSceneBtn.setIcon(Icon.disk.imageIcon());
    saveSceneBtn.addActionListener(saveSceneListener);

    JPanel panel = new JPanel();
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
            .createParallelGroup()
            .addGroup(layout.createSequentialGroup().addComponent(sceneNameLbl).addComponent(sceneNameField)
                    .addPreferredGap(ComponentPlacement.RELATED).addComponent(saveSceneBtn))
            .addComponent(tabbedPane)
            .addGroup(layout.createSequentialGroup().addGroup(targetSPP.horizontalGroup(layout))
                    .addPreferredGap(ComponentPlacement.RELATED).addComponent(setDefaultBtn))
            .addGroup(layout.createSequentialGroup().addComponent(renderLbl)
                    .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(startRenderBtn)
                    .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(stopRenderBtn))
            .addGroup(
                    layout.createSequentialGroup().addComponent(saveFrameBtn)
                            .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(showPreviewBtn))
            .addGroup(
                    layout.createSequentialGroup().addComponent(renderTimeLbl)
                            .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(sppLbl))
            .addGroup(
                    layout.createSequentialGroup().addComponent(progressLbl)
                            .addPreferredGap(ComponentPlacement.UNRELATED, GroupLayout.PREFERRED_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(etaLbl))
            .addComponent(progressBar)).addContainerGap());
    layout.setVerticalGroup(
            layout.createSequentialGroup().addContainerGap()
                    .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(sceneNameLbl)
                            .addComponent(sceneNameField).addComponent(saveSceneBtn))
                    .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(tabbedPane)
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                            .addGroup(targetSPP.verticalGroup(layout)).addComponent(setDefaultBtn))
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(renderLbl)
                            .addComponent(startRenderBtn).addComponent(stopRenderBtn))
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup().addComponent(saveFrameBtn)
                            .addComponent(showPreviewBtn))
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup().addComponent(renderTimeLbl).addComponent(sppLbl))
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup().addComponent(progressLbl).addComponent(etaLbl))
                    .addComponent(progressBar).addContainerGap());
    final JScrollPane scrollPane = new JScrollPane(panel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    setContentPane(scrollPane);

    scrollPane.getViewport().addChangeListener(new ChangeListener() {
        private boolean resized = false;

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!resized && scrollPane.getVerticalScrollBar().isVisible()) {
                Dimension vsbPrefSize = new JScrollPane().getVerticalScrollBar().getPreferredSize();
                Dimension size = getSize();
                setSize(size.width + vsbPrefSize.width, size.height);
                resized = true;
            }
        }
    });

    pack();

    setLocationRelativeTo(chunky.getFrame());

    setVisible(true);
}

From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java

public AsciidocBrowserApplication(final String[] args) {
    super("Asciidoc Browser");
    setIconImage(Icons.APPLICATION.image());

    setSize(1200, 1024);/*from  w w  w .j  av a 2s  .c  o m*/

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent e) {
            actionExit();
        }
    });

    JPanel buttonPanel = new JPanel();
    backButton = new JButton("");
    backButton.setIcon(Icons.BACK.icon());
    backButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionBack();
        }
    });
    buttonPanel.setLayout(new MigLayout("", "[1px][][][][]", "[1px]"));

    JButton btnOptionsbutton = new JButton("");
    btnOptionsbutton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            settingsDialog.setVisible(true);
        }
    });
    btnOptionsbutton.setIcon(Icons.OPTIONS.icon());
    buttonPanel.add(btnOptionsbutton, "flowx,cell 0 0");
    backButton.setEnabled(false);
    buttonPanel.add(backButton, "cell 0 0,grow");
    forwardButton = new JButton("");
    forwardButton.setIcon(Icons.FORWARD.icon());
    forwardButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionForward();
        }
    });
    forwardButton.setEnabled(false);
    buttonPanel.add(forwardButton, "cell 0 0,grow");
    getContentPane().setLayout(new MigLayout("", "[793.00px,grow]", "[44px][930px]"));
    getContentPane().add(buttonPanel, "cell 0 0,growx,aligny top");
    locationTextField = new JTextField(65);
    locationTextField.setText("");
    locationTextField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB) {
                actionGo();
                refreshDocumentTree();
            }
        }
    });
    locationTextField.setTransferHandler(
            new TextFieldTransferHandler(locationTextField.getTransferHandler(), new Runnable() {
                @Override
                public void run() {
                    locationTextField.setText("");
                }
            }, new Runnable() {

                @Override
                public void run() {
                    actionGo();
                    refreshDocumentTree();
                }
            }));

    homebutton = new JButton("");
    homebutton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            locationTextField.setText(Settings.getHome());
            actionGo();
            refreshDocumentTree();
        }
    });

    refreshButton = new JButton("");
    refreshButton.setToolTipText("Refresh");
    refreshButton.setEnabled(false);
    refreshButton.setIcon(Icons.REFRESH.icon());
    refreshButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionGo();
            refreshPreview();
        }
    });
    buttonPanel.add(refreshButton, "cell 1 0");

    homebutton.setIcon(Icons.HOME.icon());
    buttonPanel.add(homebutton, "cell 2 0");
    buttonPanel.add(locationTextField, "cell 3 0,grow");

    treeSourceSplitPane = new JSplitPane();
    treeSourceSplitPane.setResizeWeight(0.3);
    getContentPane().add(treeSourceSplitPane, "cell 0 1,grow");

    treeScrollPane = new JScrollPane();
    treeScrollPane.setMinimumSize(new Dimension(200, 200));
    treeSourceSplitPane.setLeftComponent(treeScrollPane);

    documentTree = new DocumentTree(documentModel);
    documentTree.setCellRenderer(new TooltipsTreeCellRenderer());
    ToolTipManager.sharedInstance().registerComponent(documentTree);
    ToolTipManager.sharedInstance().setInitialDelay(INITIAL_TOOLTIP_DELAY);
    ToolTipManager.sharedInstance().setReshowDelay(0);
    documentTree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(final TreeSelectionEvent tse) {
            TreePath newLeadSelectionPath = tse.getNewLeadSelectionPath();
            if (newLeadSelectionPath != null && !newLeadSelectionPath.equals(currentSelectionPath)) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) newLeadSelectionPath
                        .getLastPathComponent();
                FileWrapper file = (FileWrapper) node.getUserObject();
                showFile(file, true);
                refreshPreview();
            }
        }
    });
    treeScrollPane.setViewportView(documentTree);

    sourceEditorPane = new JEditorPane();
    sourceEditorPane.setContentType("text/html");
    sourceEditorPane.setEditable(false);
    sourceEditorPane.addHyperlinkListener(new HandleHyperlinkUpdate());
    JScrollPane fileScrollPane = new JScrollPane(sourceEditorPane);
    fileScrollPane.setMinimumSize(new Dimension(600, 600));

    documentTabbedPane = new JTabbedPane(SwingConstants.BOTTOM);
    documentTabbedPane.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(final ChangeEvent ce) {
            refreshPreview();
        }
    });
    sourceLogSplitPane = new JSplitPane();
    sourceLogSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    treeSourceSplitPane.setRightComponent(sourceLogSplitPane);
    sourceLogSplitPane.setTopComponent(documentTabbedPane);
    documentTabbedPane.add(fileScrollPane);
    documentTabbedPane.setTitleAt(0, "Source");

    browserPane = new BrowserPane();

    previewScrollPane = new JScrollPane(browserPane);
    documentTabbedPane.addTab("Preview", null, previewScrollPane, null);

    console = new JConsole();
    System.setErr(console.getErr());
    System.setOut(console.getOut());
    sourceLogSplitPane.setBottomComponent(console);

    executor = new AsciidocExecutor();
}

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());// ww w  . j ava2  s . c o m

    // 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:test.visualization.ClusteringDemo.java

private void setUpView(BufferedReader br) throws IOException {

    Factory<Number> vertexFactory = new Factory<Number>() {
        int n = 0;

        public Number create() {
            return n++;
        }/*from  ww w.  j  a v  a2 s  .  c o  m*/
    };
    Factory<Number> edgeFactory = new Factory<Number>() {
        int n = 0;

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

    PajekNetReader<Graph<Number, Number>, Number, Number> pnr = new PajekNetReader<Graph<Number, Number>, Number, Number>(
            vertexFactory, edgeFactory);

    final Graph<Number, Number> graph = new SparseMultigraph<Number, Number>();

    pnr.load(br, graph);

    //Create a simple layout frame
    //specify the Fruchterman-Rheingold layout algorithm
    final AggregateLayout<Number, Number> layout = new AggregateLayout<Number, Number>(
            new FRLayout<Number, Number>(graph));

    vv = new VisualizationViewer<Number, Number>(layout);
    vv.setBackground(Color.white);
    //Tell the renderer to use our own customized color rendering
    vv.getRenderContext()
            .setVertexFillPaintTransformer(MapTransformer.<Number, Paint>getInstance(vertexPaints));
    vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<Number, Paint>() {
        public Paint transform(Number v) {
            if (vv.getPickedVertexState().isPicked(v)) {
                return Color.cyan;
            } else {
                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("Restart");
    scramble.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Layout layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }

    });

    DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
    vv.setGraphMouse(gm);

    final JToggleButton 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(210, 50));
    edgeBetweennessSlider.setPaintTicks(true);
    edgeBetweennessSlider.setMaximum(graph.getEdgeCount());
    edgeBetweennessSlider.setMinimum(0);
    edgeBetweennessSlider.setValue(0);
    edgeBetweennessSlider.setMajorTickSpacing(10);
    edgeBetweennessSlider.setPaintLabels(true);
    edgeBetweennessSlider.setPaintTicks(true);

    //      edgeBetweennessSlider.setBorder(BorderFactory.createLineBorder(Color.black));
    //TO DO: edgeBetweennessSlider.add(new JLabel("Node Size (PageRank With Priors):"));
    //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(eastSize);
    eastControls.add(Box.createVerticalGlue());

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

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

    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();
            }
        }
    });

    Container content = getContentPane();
    content.add(new GraphZoomScrollPane(vv));
    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);
    content.add(south, BorderLayout.SOUTH);
}

From source file:the.bytecode.club.bytecodeviewer.gui.WorkPane.java

public WorkPane(final FileChangeNotifier fcn) {
    super("WorkPanel");
    setTitle("Work Space");

    this.tabs = new JTabbedPane();
    this.fcn = fcn;

    getContentPane().setLayout(new BorderLayout());

    getContentPane().add(tabs, BorderLayout.CENTER);

    buttonPanel = new JPanel(new FlowLayout());

    refreshClass = new JButton("Refresh");
    refreshClass.addActionListener(this);

    buttonPanel.add(refreshClass);//w w w. j a v a2  s  .co m

    //Xposed 
    generateXposedClass = new JButton("Generate Xposed Module");
    generateXposedClass.addActionListener(this);
    buttonPanel.add(generateXposedClass);

    buttonPanel.setVisible(false);

    getContentPane().add(buttonPanel, BorderLayout.SOUTH);

    tabs.addContainerListener(new ContainerListener() {

        @Override
        public void componentAdded(final ContainerEvent e) {
        }

        @Override
        public void componentRemoved(final ContainerEvent e) {
            final Component c = e.getChild();
            if (c instanceof ClassViewer) {
                ClassViewer cv = (ClassViewer) c;
                workingOn.remove(cv.container + "$" + cv.name);
            }
            if (c instanceof FileViewer) {
                FileViewer fv = (FileViewer) c;
                workingOn.remove(fv.container + "$" + fv.name);
            }
        }

    });
    tabs.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(final ChangeEvent arg0) {
            buttonPanel.setVisible(tabs.getSelectedIndex() != -1);
        }
    });

    this.setVisible(true);

}