Example usage for javax.swing JComboBox setSelectedItem

List of usage examples for javax.swing JComboBox setSelectedItem

Introduction

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

Prototype

@BeanProperty(bound = false, preferred = true, description = "Sets the selected item in the JComboBox.")
public void setSelectedItem(Object anObject) 

Source Link

Document

Sets the selected item in the combo box display area to the object in the argument.

Usage

From source file:org.nuclos.client.ui.collect.component.CollectableComboBox.java

@Override
protected void updateView(CollectableField clctfValue) {
    if (hasAdditionalEntry()) {
        removeAdditionalEntry();//from  www  . jav a 2 s.  c o  m
    }

    final JComboBox cb = getJComboBox();
    final DefaultComboBoxModel cbm = getDefaultComboBoxModel();

    int iIndex = cbm.getIndexOf(clctfValue);
    // If the value could not be found, it might be the mnemonic, so look for the value id
    if (iIndex < 0 && clctfValue.isIdField() && clctfValue.getValueId() != null) {
        for (int i = 0; i < cbm.getSize(); i++) {
            final CollectableField cf = (CollectableField) cbm.getElementAt(i);
            if (!cf.isIdField())
                continue;
            final Long valueId = IdUtils.toLongId(cf.getValueId());
            final Long vid = IdUtils.toLongId(clctfValue.getValueId());
            if (LangUtils.equals(vid, valueId)) {
                iIndex = i;
                break;
            }
        }
    }
    if (iIndex >= 0) {
        cb.setSelectedIndex(iIndex);
        // Note that setSelectedItem doesn't work here, as clctf might have no label.
    } else {
        assert iIndex == -1;

        final Long vid = !clctfValue.isIdField() ? null : IdUtils.toLongId(clctfValue.getValueId());
        Long oValueId = null;
        if (clctfValue.isIdField()) {
            oValueId = vid;
            // sbWarning.append(" (Id: ").append(oValueId).append(")");
        }

        if (isInsertable() && (oValueId == null) && (vid != null)) {
            final String sText = clctfValue.toString();
            cb.setSelectedItem(sText);
        } else {
            addAdditionalEntry(clctfValue);
            cb.setSelectedIndex(cbm.getIndexOf(clctfValue));
        }
    }
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.ImportDialog.java

/**
 * Initializes the components composing the display.
 * //  ww  w . ja v  a  2  s.co m
 * @param filters The filters to handle.
 * @param importerAction The cancel-all-imports action.
 */
private void initComponents(FileFilter[] filters, ImporterAction importerAction) {
    canvas = new QuotaCanvas();
    sizeImportLabel = new JLabel();
    diskSpacePane = new JPanel();
    diskSpacePane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));
    diskSpacePane.add(UIUtilities.setTextFont(TEXT_FREE_SPACE));
    diskSpacePane.add(canvas);

    showThumbnails = new JCheckBox(TEXT_SHOW_THUMBNAILS);
    showThumbnails.setVisible(false);

    Registry registry = ImporterAgent.getRegistry();

    Boolean loadThumbnails = (Boolean) registry.lookup(LOAD_THUMBNAIL);

    if (loadThumbnails != null) {
        if (loadThumbnails.booleanValue()) {
            showThumbnails.setVisible(true);
            showThumbnails.setSelected(loadThumbnails.booleanValue());
        }
    }

    if (!isFastConnection()) // slow connection
        showThumbnails.setSelected(false);
    long groupId = -1;
    if (model.getSelectedGroup() != null)
        groupId = model.getSelectedGroup().getGroupId();
    if (groupId < 0)
        groupId = ImporterAgent.getUserDetails().getGroupId();

    locationDialog = new LocationDialog(owner, selectedContainer, type, objects, model, groupId, true);
    locationDialog.addPropertyChangeListener(this);

    int plugin = ImporterAgent.runAsPlugin();

    if (plugin == LookupNames.IMAGE_J_IMPORT || plugin == LookupNames.IMAGE_J) {
        detachedDialog = new LocationDialog(owner, selectedContainer, type, objects, model, groupId, false);
        detachedDialog.addPropertyChangeListener(this);
    }
    tagSelectionListener = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Object src = e.getSource();
            if (src instanceof JButton) {
                TagAnnotationData tag = tagsMap.get(src);
                if (tag != null) {
                    tagsMap.remove(src);
                    handleTagsSelection(tagsMap.values());
                }
            }
        }
    };

    tabbedPane = new JTabbedPane();
    numberOfFolders = new NumericalTextField();
    numberOfFolders.setMinimum(0);
    numberOfFolders.setText("0");
    numberOfFolders.setColumns(3);
    numberOfFolders.addPropertyChangeListener(this);
    tagsMap = new LinkedHashMap<JButton, TagAnnotationData>();

    IconManager icons = IconManager.getInstance();

    refreshFilesButton = new JButton(TEXT_REFRESH_FILES);
    refreshFilesButton.setBackground(UIUtilities.BACKGROUND);
    refreshFilesButton.setToolTipText(TOOLTIP_REFRESH_FILES);
    refreshFilesButton.setActionCommand("" + CMD_REFRESH_FILES);
    refreshFilesButton.addActionListener(this);

    tagButton = new JButton(icons.getIcon(IconManager.PLUS_12));
    UIUtilities.unifiedButtonLookAndFeel(tagButton);
    tagButton.addActionListener(this);
    tagButton.setActionCommand("" + CMD_TAG);
    tagButton.setToolTipText(TOOLTIP_ADD_TAGS);
    tagsPane = new JPanel();
    tagsPane.setLayout(new BoxLayout(tagsPane, BoxLayout.Y_AXIS));

    overrideName = new JCheckBox(TEXT_OVERRIDE_FILE_NAMING);
    overrideName.setToolTipText(UIUtilities.formatToolTipText(WARNING));
    overrideName.setSelected(true);
    ButtonGroup group = new ButtonGroup();
    fullName = new JRadioButton(TEXT_NAMING_FULL_PATH);
    group.add(fullName);
    partialName = new JRadioButton();
    partialName.setText(TEXT_NAMING_PARTIAL_PATH);
    partialName.setSelected(true);
    group.add(partialName);

    table = new FileSelectionTable(this);
    table.addPropertyChangeListener(this);
    chooser = new GenericFileChooser();
    JList list = (JList) UIUtilities.findComponent(chooser, JList.class);
    KeyAdapter ka = new KeyAdapter() {

        /**
         * Adds the files to the import queue.
         * 
         * @see KeyListener#keyPressed(KeyEvent)
         */
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                handleEnterKeyPressed(e.getSource());
            }
        }
    };
    if (list != null)
        list.addKeyListener(ka);
    if (list == null) {
        JTable t = (JTable) UIUtilities.findComponent(chooser, JTable.class);
        if (t != null)
            t.addKeyListener(ka);
    }

    try {
        File f = UIUtilities.getDefaultFolder();
        if (f != null)
            chooser.setCurrentDirectory(f);
    } catch (Exception e) {
        // Ignore: could not set the default container
    }

    chooser.addPropertyChangeListener(this);
    chooser.setMultiSelectionEnabled(true);
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setControlButtonsAreShown(false);
    chooser.setApproveButtonText(TEXT_IMPORT);
    chooser.setApproveButtonToolTipText(TOOLTIP_IMPORT);

    bioFormatsFileFilters = new ArrayList<FileFilter>();

    if (filters != null) {
        chooser.setAcceptAllFileFilterUsed(false);

        for (FileFilter fileFilter : filters) {
            if (fileFilter instanceof ComboFileFilter) {
                bioFormatsFileFiltersCombined = fileFilter;

                ComboFileFilter comboFilter = (ComboFileFilter) fileFilter;
                FileFilter[] extensionFilters = comboFilter.getFilters();

                for (FileFilter combinedFilter : extensionFilters) {
                    bioFormatsFileFilters.add(combinedFilter);
                }
                break;
            }
        }

        chooser.addChoosableFileFilter(bioFormatsFileFiltersCombined);

        for (FileFilter fileFilter : bioFormatsFileFilters) {
            chooser.addChoosableFileFilter(fileFilter);
        }

        chooser.setFileFilter(bioFormatsFileFiltersCombined);
    } else {
        chooser.setAcceptAllFileFilterUsed(true);
    }

    closeButton = new JButton(TEXT_CLOSE);
    closeButton.setToolTipText(TOOLTIP_CLOSE);
    closeButton.setActionCommand("" + CMD_CLOSE);
    closeButton.addActionListener(this);

    cancelImportButton = new JButton(importerAction);
    importerAction.setEnabled(false);

    importButton = new JButton(TEXT_IMPORT);
    importButton.setToolTipText(TOOLTIP_IMPORT);
    importButton.setActionCommand("" + CMD_IMPORT);
    importButton.addActionListener(this);
    importButton.setEnabled(false);

    pixelsSize = new ArrayList<NumericalTextField>();
    NumericalTextField field;
    for (int i = 0; i < 3; i++) {
        field = new NumericalTextField();
        field.setNumberType(Double.class);
        field.setColumns(2);
        pixelsSize.add(field);
    }

    List<Component> boxes = UIUtilities.findComponents(chooser, JComboBox.class);
    if (boxes != null) {
        JComboBox box;
        JComboBox filterBox = null;
        Iterator<Component> i = boxes.iterator();
        while (i.hasNext()) {
            box = (JComboBox) i.next();
            Object o = box.getItemAt(0);
            if (o instanceof FileFilter) {
                filterBox = box;
                break;
            }
        }
        if (filterBox != null) {
            filterBox.addKeyListener(new KeyAdapter() {

                public void keyPressed(KeyEvent e) {
                    String value = KeyEvent.getKeyText(e.getKeyCode());
                    JComboBox box = (JComboBox) e.getSource();
                    int n = box.getItemCount();
                    FileFilter filter;
                    FileFilter selectedFilter = null;
                    String d;
                    for (int j = 0; j < n; j++) {
                        filter = (FileFilter) box.getItemAt(j);
                        d = filter.getDescription();
                        if (d.startsWith(value)) {
                            selectedFilter = filter;
                            break;
                        }
                    }
                    if (selectedFilter != null)
                        box.setSelectedItem(selectedFilter);
                }
            });
        }
    }
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.LocationDialog.java

/**
 * Populates the JComboBox with the items provided adding hover tooltips,
 * selecting the specified item and attaching the listener.
 * /*  w w  w. j av  a2  s  .  co  m*/
 * @param comboBox The JComboBox to populate
 * @param listItems The items to populate the box with
 * @param select The item to select in the JComboBox
 * @param itemListener An item listener to add for the JComboBox
 */
private void displayItems(JComboBox comboBox, List<DataNode> listItems, DataNode select,
        ItemListener itemListener) {
    if (comboBox == null || listItems == null)
        return;
    //Only add the item the user can actually select
    if (itemListener != null)
        comboBox.removeItemListener(itemListener);
    comboBox.removeAllItems();

    List<String> tooltips = new ArrayList<String>(listItems.size());
    List<String> lines;
    ExperimenterData exp;
    SelectableComboBoxModel model = new SelectableComboBoxModel();
    Selectable<DataNode> selected = null;

    GroupData group = getSelectedGroup();
    ExperimenterData user = getSelectedUser();
    long userID = -1;
    if (user != null)
        userID = user.getId();
    ExperimenterData loggedIn = ImporterAgent.getUserDetails();
    boolean isAdmin = ImporterAgent.isAdministrator();
    long loggedInID = loggedIn.getId();
    boolean userIsAdmin = isAdmin(userID);
    for (DataNode node : listItems) {
        exp = getExperimenter(node.getOwner());
        lines = new ArrayList<String>();
        if (exp != null) {
            lines.add("<b>Owner: </b>" + EditorUtil.formatExperimenter(exp));
        }
        lines.addAll(UIUtilities.wrapStyleWord(node.getFullName()));
        tooltips.add(UIUtilities.formatToolTipText(lines));

        boolean selectable = true;
        if (!node.isDefaultNode()) {
            selectable = canLink(node.getDataObject(), userID, group, loggedInID, isAdmin, userIsAdmin);
        }

        Selectable<DataNode> comboBoxItem = new Selectable<DataNode>(node, selectable);
        if (select != null && node.getDataObject().getId() == select.getDataObject().getId())
            selected = comboBoxItem;

        model.addElement(comboBoxItem);
    }

    ComboBoxToolTipRenderer renderer = createComboboxRenderer();
    renderer.setTooltips(tooltips);
    comboBox.setModel(model);
    comboBox.setRenderer(renderer);

    if (selected != null)
        comboBox.setSelectedItem(selected);

    if (itemListener != null)
        comboBox.addItemListener(itemListener);
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.LocationDialog.java

/**
 * Populates the JComboBox with the user details provided, 
 * selecting the logged in user and attaching the item listener.
 * /*from  ww w.j  a  v  a  2  s  . c o m*/
 * @param comboBox The JComboBox to populate
 * @param group The group being displayed
 * @param itemListener An item listener to add for the JComboBox
 * @param userID The id of the user.
 */
private void displayUsers(JComboBox comboBox, GroupData group, ItemListener itemListener, long userID) {

    if (comboBox == null || group == null)
        return;

    if (itemListener != null)
        comboBox.removeItemListener(itemListener);
    comboBox.removeAllItems();

    DefaultComboBoxModel model = new SelectableComboBoxModel();
    Selectable<ExperimenterDisplay> selected = null;

    List<ExperimenterData> members = sort(group.getExperimenters());
    boolean canImportAs;
    Selectable<ExperimenterDisplay> item;
    List<String> tooltips = new ArrayList<String>(members.size());
    List<String> lines;
    for (ExperimenterData user : members) {
        canImportAs = canImportForUserInGroup(user, group);
        item = new Selectable<ExperimenterDisplay>(new ExperimenterDisplay(user), canImportAs);
        if (user.getId() == userID)
            selected = item;
        lines = new ArrayList<String>();
        lines.addAll(UIUtilities.wrapStyleWord(EditorUtil.formatExperimenter(user)));
        tooltips.add(UIUtilities.formatToolTipText(lines));
        model.addElement(item);
    }
    ComboBoxToolTipRenderer renderer = createComboboxRenderer();
    renderer.setTooltips(tooltips);
    comboBox.setModel(model);
    comboBox.setRenderer(renderer);

    if (selected != null)
        comboBox.setSelectedItem(selected);

    if (itemListener != null)
        comboBox.addItemListener(itemListener);
}

From source file:org.pentaho.reporting.ui.datasources.jdbc.ui.JdbcDataSourceDialog.java

protected void setScriptingLanguage(final String lang, final JComboBox languageField) {
    if (lang == null) {
        languageField.setSelectedItem(null);
        return;// ww  w . ja va2 s .  c  o m
    }

    final ListModel model = languageField.getModel();
    for (int i = 0; i < model.getSize(); i++) {
        final ScriptEngineFactory elementAt = (ScriptEngineFactory) model.getElementAt(i);
        if (elementAt == null) {
            continue;
        }
        if (elementAt.getNames().contains(lang)) {
            languageField.setSelectedItem(elementAt);
            return;
        }
    }
}

From source file:org.tinymediamanager.ui.panels.MediaScraperConfigurationPanel.java

private JPanel createConfigPanel() {
    JPanel panel = new JPanel();
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 0 };
    gridBagLayout.rowHeights = new int[] { 0 };
    gridBagLayout.columnWeights = new double[] { Double.MIN_VALUE };
    gridBagLayout.rowWeights = new double[] { Double.MIN_VALUE };
    panel.setLayout(gridBagLayout);/* w w w .j ava 2s . c o m*/

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridy = 0;

    // build up the panel for being displayed in the popup
    MediaProviderConfig config = mediaProvider.getProviderInfo().getConfig();
    for (Entry<String, MediaProviderConfigObject> entry : config.getConfigObjects().entrySet()) {
        if (!entry.getValue().isVisible()) {
            continue;
        }

        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.ipadx = 20;

        // label
        JLabel label = new JLabel(entry.getValue().getKeyDescription());
        constraints.gridx = 0;
        panel.add(label, constraints);

        JComponent comp;
        switch (entry.getValue().getType()) {
        case BOOL:
            // display as checkbox
            JCheckBox checkbox = new JCheckBox();
            checkbox.setSelected(entry.getValue().getValueAsBool());
            checkbox.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    dirty = true;
                }
            });
            comp = checkbox;
            break;

        case SELECT:
        case SELECT_INDEX:
            // display as combobox
            JComboBox<String> combobox = new JComboBox<>(
                    entry.getValue().getPossibleValues().toArray(new String[0]));
            combobox.setSelectedItem(entry.getValue().getValueAsString());
            combobox.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    dirty = true;
                }
            });
            comp = combobox;
            break;

        default:
            // display as text
            JTextField tf;
            if (entry.getValue().isEncrypt()) {
                tf = new JPasswordField(config.getValue(entry.getKey()));
            } else {
                tf = new JTextField(config.getValue(entry.getKey()));
            }

            tf.setPreferredSize(new Dimension(100, 24));
            tf.getDocument().addDocumentListener(new DocumentListener() {
                @Override
                public void removeUpdate(DocumentEvent e) {
                    dirty = true;
                }

                @Override
                public void insertUpdate(DocumentEvent e) {
                    dirty = true;
                }

                @Override
                public void changedUpdate(DocumentEvent e) {
                    dirty = true;
                }
            });
            comp = tf;
            break;
        }

        comp.putClientProperty(entry.getKey(), entry.getKey());
        constraints.ipadx = 0;
        constraints.gridx = 1;
        panel.add(comp, constraints);

        // add a hint if a long text has been found
        try {
            String desc = BUNDLE.getString(
                    "scraper." + mediaProvider.getProviderInfo().getId() + "." + entry.getKey() + ".desc"); //$NON-NLS-1$
            if (StringUtils.isNotBlank(desc)) {
                JLabel lblHint = new JLabel(IconManager.HINT);
                lblHint.setToolTipText(desc);
                constraints.gridx = 2;
                panel.add(lblHint, constraints);
            }
        } catch (Exception ignored) {
        }
        constraints.gridy++;
    }
    return panel;
}

From source file:renderer.DependencyGrapher.java

/**
 * create an instance of a simple graph in two views with controls to
 * demo the features.//w w  w  .  j  ava 2s .  c  om
 * 
 */
public DependencyGrapher() {

    // create a simple graph for the demo
    final DependencyDirectedSparceMultiGraph<String, Number> graph = createGraph(); //TestGraphs.getOneComponentGraph();

    // the preferred sizes for the two views

    // create one layout for the graph
    final FRLayout2<String, Number> layout = new FRLayout2<String, Number>(graph);
    layout.setMaxIterations(500);

    VisualizationModel<String, Number> vm = new DefaultVisualizationModel<String, Number>(layout,
            preferredSize1);

    Transformer<Number, String> stringer = new Transformer<Number, String>() {
        public String transform(Number e) {
            if (graph.getEdgeAttributes(e) != null) {
                return graph.getEdgeAttributes(e).toString();
            }
            return null;
        }
    };
    // create 2 views that share the same model
    final VisualizationViewer<String, Number> vv = new VisualizationViewer<String, Number>(vm, preferredSize1);
    vv.setBackground(Color.white);
    vv.getRenderContext().setEdgeLabelTransformer(stringer);
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<String, Number>(vv.getPickedEdgeState(), Color.black, Color.cyan));
    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(vv.getPickedVertexState(), Color.red, Color.yellow));
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);

    // add default listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<String>());

    //      ToolTipManager.sharedInstance().setDismissDelay(10000);

    Container content = getContentPane();
    Container panel = new JPanel(new BorderLayout());

    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    panel.add(gzsp);

    helpDialog = new JDialog();
    helpDialog.getContentPane().add(new JLabel(instructions));

    RenderContext<String, Number> rc = vv.getRenderContext();
    AnnotatingGraphMousePlugin annotatingPlugin = new AnnotatingGraphMousePlugin(rc);
    // create a GraphMouse for the main view
    // 
    final AnnotatingModalGraphMouse graphMouse = new AnnotatingModalGraphMouse(rc, annotatingPlugin);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton filterReset = new JButton("Reset");
    filterReset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getModel().setGraphLayout(layout);
        }
    });
    JButton filterFilter = new JButton("Filter");
    filterReset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getModel().setGraphLayout(layout);
        }
    });
    JRadioButton filterDirectionInOut = new JRadioButton("In/Out");
    filterDirectionInOut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Dependency Direction: " + EdgeType.IN_OUT);
            _filterEdgeDirection = EdgeType.IN_OUT;
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }

    });
    JRadioButton filterDirectionIn = new JRadioButton("In");
    filterDirectionIn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Dependency Direction: " + EdgeType.IN);
            _filterEdgeDirection = EdgeType.IN;
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }

    });
    JRadioButton filterDirectionOut = new JRadioButton("Out");
    filterDirectionOut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Dependency Direction: " + EdgeType.OUT);
            _filterEdgeDirection = EdgeType.OUT;
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }

    });
    ButtonGroup filterRadios = new ButtonGroup();
    filterRadios.add(filterDirectionInOut);
    filterRadios.add(filterDirectionIn);
    filterRadios.add(filterDirectionOut);
    filterRadios.setSelected(filterDirectionInOut.getModel(), true);

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.setSelectedItem(ModalGraphMouse.Mode.PICKING);

    final JComboBox filterBox = new JComboBox(graph.getVertices().toArray());
    filterBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            _filterChoice = filterBox.getSelectedItem().toString();
            System.out.println(_filterChoice);
            filterLayout = getNewLayout(graph, layout);
            vv.getModel().setGraphLayout(filterLayout);
        }
    });

    JButton help = new JButton("Help");
    help.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            helpDialog.pack();
            helpDialog.setVisible(true);
        }
    });

    JPanel controls = new JPanel();

    JPanel modeControls = new JPanel();
    modeControls.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    modeControls.add(graphMouse.getModeComboBox());
    controls.add(modeControls);

    JPanel annotationControlPanel = new JPanel();
    annotationControlPanel.setBorder(BorderFactory.createTitledBorder("Annotation Controls"));

    AnnotationControls annotationControls = new AnnotationControls(annotatingPlugin);

    annotationControlPanel.add(annotationControls.getAnnotationsToolBar());
    controls.add(annotationControlPanel);

    JPanel helpControls = new JPanel();
    helpControls.setBorder(BorderFactory.createTitledBorder("Help"));
    helpControls.add(help);
    controls.add(helpControls);

    JPanel filterControls = new JPanel();
    filterControls.setBorder(BorderFactory.createTitledBorder("Filter"));
    filterControls.add(filterBox);
    filterControls.add(filterDirectionInOut);
    filterControls.add(filterDirectionIn);
    filterControls.add(filterDirectionOut);
    filterControls.add(filterReset);
    controls.add(filterControls);

    content.add(panel);
    content.add(controls, BorderLayout.SOUTH);

}

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

@SuppressWarnings("unchecked")
private void initParameterValue(JComponent component, Object value, String paramName,
        List<Serializable> defaultValues) {
    if (value == null) {
        return;/*from www  . ja v  a 2  s  .  c om*/
    }
    if (component instanceof JTextField) {
        ((JTextField) component).setText(value.toString());
    } else if (component instanceof JComboBox) {
        JComboBox combo = ((JComboBox) component);
        List<IdName> values = (List<IdName>) value;
        combo.removeAllItems();
        combo.addItem("-- " + I18NSupport.getString("parameter.value.select") + " --");
        for (int j = 0, len = values.size(); j < len; j++) {
            combo.addItem(values.get(j));
        }
        Object old = parametersValues.get(paramName);
        if (old != null) {
            combo.setSelectedItem(old);
        } else if ((defaultValues != null) && (defaultValues.size() > 0)) {
            Serializable id = defaultValues.get(0);
            if (id instanceof IdName) {
                id = ((IdName) id).getId();
            }
            combo.setSelectedItem(findIdName(combo.getModel(), id));
        }
    } else if (component instanceof ListSelectionPanel) {
        ListSelectionPanel lsp = (ListSelectionPanel) component;
        DefaultListModel model = new DefaultListModel();
        if (value != null) {
            List<IdName> values = (List<IdName>) value;
            for (int j = 0, len = values.size(); j < len; j++) {
                model.addElement(values.get(j));
            }
        }
        ArrayList srcList = new ArrayList(Arrays.asList(model.toArray()));

        Object old = parametersValues.get(paramName);
        Object[] selected = new Object[0];
        if (old != null) {
            selected = (Object[]) old;
        } else if ((defaultValues != null) && (defaultValues.size() > 0)) {
            selected = new Object[defaultValues.size()];
            for (int k = 0, len = selected.length; k < len; k++) {
                Serializable id = defaultValues.get(k);
                if (id instanceof IdName) {
                    id = ((IdName) id).getId();
                }
                IdName in = findIdName(srcList, id);
                selected[k] = in;
            }
        }
        List dstList = Arrays.asList(selected);

        if (!srcList.containsAll(dstList)) {
            dstList = new ArrayList();
            parametersValues.put(paramName, null);
        } else {
            srcList.removeAll(dstList);
        }
        if ((dstList.size() == 1) && ParameterUtil.NULL.equals(dstList.get(0))) {
            dstList = new ArrayList();
        }
        lsp.setLists(srcList, dstList);

    } else if (component instanceof ListAddPanel) {
        ListAddPanel lap = (ListAddPanel) component;
        DefaultListModel model = new DefaultListModel();
        if (value != null) {
            List<Object> values = (List<Object>) value;
            for (int j = 0, len = values.size(); j < len; j++) {
                model.addElement(values.get(j));
            }
        }
        ArrayList srcList = new ArrayList(Arrays.asList(model.toArray()));

        Object old = parametersValues.get(paramName);
        Object[] selected = new Object[0];
        if (old != null) {
            selected = (Object[]) old;
        } else if ((defaultValues != null) && (defaultValues.size() > 0)) {
            selected = new Object[defaultValues.size()];
            for (int k = 0, len = selected.length; k < len; k++) {
                Serializable id = defaultValues.get(k);
                if (id instanceof IdName) {
                    id = ((IdName) id).getId();
                }
                selected[k] = id;
            }
        }
        List dstList = Arrays.asList(selected);
        if (!srcList.containsAll(dstList)) {
            dstList = new ArrayList();
            parametersValues.put(paramName, null);
        } else {
            srcList.removeAll(dstList);
        }
        if ((dstList.size() == 1) && ParameterUtil.NULL.equals(dstList.get(0))) {
            dstList = new ArrayList();
        }

        lap.setElements(dstList);
    } else if (component instanceof JDateTimePicker) {
        ((JDateTimePicker) component).setDate((Date) value);
    } else if (component instanceof JXDatePicker) {
        ((JXDatePicker) component).setDate((Date) value);
    } else if (component instanceof JCheckBox) {
        ((JCheckBox) component).setSelected((Boolean) value);
    }
}

From source file:se.trixon.jota.client.ui.MainFrame.java

private void requestConnect() throws NotBoundException {
    String[] hosts = mOptions.getHosts().split(";");
    Arrays.sort(hosts);/*from  w w w. j a  v  a  2 s  . c o  m*/
    DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(hosts);
    JComboBox hostComboBox = new JComboBox(comboBoxModel);
    hostComboBox.setEditable(true);

    hostComboBox.setSelectedItem(mClient.getHost());
    JTextField portTextField = new JTextField(String.valueOf(mClient.getPortHost()));
    final JComponent[] inputs = new JComponent[] { new JLabel(Dict.HOST.toString()), hostComboBox,
            new JLabel(Dict.PORT.toString()), portTextField, };

    Object[] options = { Dict.CONNECT.toString(), Dict.CANCEL.toString() };
    int retval = JOptionPane.showOptionDialog(this, inputs, Dict.CONNECT_TO_HOST.toString(),
            JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);

    if (retval == 0) {
        String currentHost = mClient.getHost();
        int currentPort = mClient.getPortHost();
        String host = (String) hostComboBox.getSelectedItem();
        String portString = portTextField.getText();

        try {
            int port = Integer.valueOf(portString);
            mManager.disconnect();
            mManager.connect(host, port);

            if (comboBoxModel.getIndexOf(host) == -1) {
                comboBoxModel.addElement(host);
            }
            mOptions.setHosts(SwingHelper.comboBoxModelToString(comboBoxModel));
        } catch (NumberFormatException e) {
            Message.error(this, Dict.ERROR.toString(), String.format(Dict.INVALID_PORT.toString(), portString));
        } catch (NotBoundException | MalformedURLException | RemoteException | SocketException ex) {
            Message.error(this, Dict.ERROR.toString(), ex.getLocalizedMessage());
            mClient.setHost(currentHost);
            mClient.setPortHost(currentPort);
        }
    }
}

From source file:shuffle.fwk.service.roster.EditRosterService.java

private JPanel createRosterComponent(Species s) {
    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.gridx = 1;/*from  w w w . j a v a2  s  . c om*/
    c.gridy = 1;
    c.anchor = GridBagConstraints.CENTER;

    MouseAdapter ma = new PressOrClickMouseAdapter() {

        @Override
        protected void onRight(MouseEvent e) {
            onLeft(e);
        }

        @Override
        protected void onLeft(MouseEvent e) {
            setSelected(s, ret);
            selectedDisplayLabel.repaint();
        }

        @Override
        protected void onEnter() {
            // Do nothing
        }
    };
    SpeciesPaint sp = new SpeciesPaint(s, false, getMegaFilter());
    ImageIcon icon = getUser().getImageManager().getImageFor(sp);
    JLabel iconLabel = new JLabel(icon);
    iconLabel.addMouseListener(ma);
    ret.add(iconLabel, c);
    c.gridy += 1;
    JLabel jLabel = new JLabel(s.getLocalizedName(getMegaFilter()));
    jLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    jLabel.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel.addMouseListener(ma);
    ret.add(jLabel, c);
    JComboBox<Integer> level = new JComboBox<Integer>();
    for (int i = 0; i <= Species.MAX_LEVEL; i++) {
        level.addItem(i);
    }
    Integer thisLevel = getLevelFor(s);
    level.setSelectedItem(thisLevel);
    level.setToolTipText(getString(KEY_POKEMON_LEVEL_TOOLTIP));
    c.gridy += 1; // put the level selector below the icon.
    ret.add(level, c);
    level.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            int index = level.getSelectedIndex();
            myData.setLevelForSpecies(s, index);
            rebuildSelectedLabel();
        }
    });
    return ret;
}