Example usage for javax.swing JComboBox setEditable

List of usage examples for javax.swing JComboBox setEditable

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "If true, the user can type a new value in the combo box.")
public void setEditable(boolean aFlag) 

Source Link

Document

Determines whether the JComboBox field is editable.

Usage

From source file:net.pandoragames.far.ui.swing.dialog.SettingsDialog.java

private void init() {
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
    this.setResizable(false);

    JPanel basePanel = new JPanel();
    basePanel.setLayout(new BoxLayout(basePanel, BoxLayout.Y_AXIS));
    basePanel.setBorder(/*ww w.  j  av a2  s . co m*/
            BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING));
    registerCloseWindowKeyListener(basePanel);

    // sink for error messages
    MessageLabel errorField = new MessageLabel();
    errorField.setMinimumSize(new Dimension(100, swingConfig.getStandardComponentHight()));
    errorField.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING));
    TwoComponentsPanel lineError = new TwoComponentsPanel(errorField,
            Box.createRigidArea(new Dimension(1, swingConfig.getStandardComponentHight())));
    lineError.setAlignmentX(Component.LEFT_ALIGNMENT);
    basePanel.add(lineError);

    // character set
    JLabel labelCharset = new JLabel(swingConfig.getLocalizer().localize("label.default-characterset"));
    labelCharset.setAlignmentX(Component.LEFT_ALIGNMENT);
    basePanel.add(labelCharset);

    JComboBox listCharset = new JComboBox(swingConfig.getCharsetList().toArray());
    listCharset.setAlignmentX(Component.LEFT_ALIGNMENT);
    listCharset.setSelectedItem(swingConfig.getDefaultCharset());
    listCharset.setEditable(true);
    listCharset.setMaximumSize(
            new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight()));

    listCharset.addActionListener(new CharacterSetListener(errorField));
    listCharset.setEditor(new CharacterSetEditor(errorField));
    basePanel.add(listCharset);

    basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING)));

    // select the group selector
    JPanel selectorPanel = new JPanel();
    selectorPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    selectorPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    // linePattern.setAlignmentX( Component.LEFT_ALIGNMENT );
    JLabel labelSelector = new JLabel(swingConfig.getLocalizer().localize("label.group-ref-indicator"));
    selectorPanel.add(labelSelector);
    JComboBox selectorBox = new JComboBox(FARConfig.GROUPREFINDICATORLIST);
    selectorBox.setSelectedItem(Character.toString(groupReference));
    selectorBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            JComboBox cbox = (JComboBox) event.getSource();
            String indicator = (String) cbox.getSelectedItem();
            groupReference = indicator.charAt(0);
        }
    });
    selectorPanel.add(selectorBox);
    basePanel.add(selectorPanel);

    basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING)));

    // checkbox DO BACKUP
    JCheckBox doBackupFlag = new JCheckBox(swingConfig.getLocalizer().localize("label.create-backup"));
    doBackupFlag.setAlignmentX(Component.LEFT_ALIGNMENT);
    doBackupFlag.setHorizontalTextPosition(SwingConstants.LEADING);
    doBackupFlag.setSelected(replaceForm.isDoBackup());
    doBackupFlag.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            doBackup = ItemEvent.SELECTED == event.getStateChange();
            backupFlagEvent = event;
        }
    });
    basePanel.add(doBackupFlag);

    JTextField backupDirPathTextField = new JTextField();
    backupDirPathTextField.setPreferredSize(
            new Dimension(SwingConfig.COMPONENT_WIDTH, swingConfig.getStandardComponentHight()));
    backupDirPathTextField.setMaximumSize(
            new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight()));
    backupDirPathTextField.setText(backupDirectory.getPath());
    backupDirPathTextField.setToolTipText(backupDirectory.getPath());
    backupDirPathTextField.setEditable(false);
    JButton openBaseDirFileChooserButton = new JButton(swingConfig.getLocalizer().localize("button.browse"));
    BrowseButtonListener backupDirButtonListener = new BrowseButtonListener(backupDirPathTextField,
            new BackUpDirectoryRepository(swingConfig, findForm, replaceForm, errorField),
            swingConfig.getLocalizer().localize("label.choose-backup-directory"));
    openBaseDirFileChooserButton.addActionListener(backupDirButtonListener);
    TwoComponentsPanel lineBaseDir = new TwoComponentsPanel(backupDirPathTextField,
            openBaseDirFileChooserButton);
    lineBaseDir.setAlignmentX(Component.LEFT_ALIGNMENT);
    basePanel.add(lineBaseDir);

    basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING)));

    JPanel fileInfoPanel = new JPanel();
    fileInfoPanel
            .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
                    swingConfig.getLocalizer().localize("label.default-file-info")));
    fileInfoPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    fileInfoPanel.setLayout(new BoxLayout(fileInfoPanel, BoxLayout.Y_AXIS));
    JLabel fileInfoLabel = new JLabel(swingConfig.getLocalizer().localize("message.displayed-in-info-column"));
    fileInfoLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
    fileInfoPanel.add(fileInfoLabel);
    fileInfoPanel.add(Box.createHorizontalGlue());
    JRadioButton nothingRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.nothing"));
    nothingRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    nothingRadio.setActionCommand(SwingConfig.DefaultFileInfo.NOTHING.name());
    nothingRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.NOTHING);
    fileInfoOptions.add(nothingRadio);
    fileInfoPanel.add(nothingRadio);
    JRadioButton readOnlyRadio = new JRadioButton(
            swingConfig.getLocalizer().localize("label.read-only-warning"));
    readOnlyRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    readOnlyRadio.setActionCommand(SwingConfig.DefaultFileInfo.READONLY.name());
    readOnlyRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.READONLY);
    fileInfoOptions.add(readOnlyRadio);
    fileInfoPanel.add(readOnlyRadio);
    JRadioButton sizeRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.filesize"));
    sizeRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    sizeRadio.setActionCommand(SwingConfig.DefaultFileInfo.SIZE.name());
    sizeRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.SIZE);
    fileInfoOptions.add(sizeRadio);
    fileInfoPanel.add(sizeRadio);
    JCheckBox showPlainBytesFlag = new JCheckBox(
            "  " + swingConfig.getLocalizer().localize("label.show-plain-bytes"));
    showPlainBytesFlag.setAlignmentX(Component.LEFT_ALIGNMENT);
    showPlainBytesFlag.setHorizontalTextPosition(SwingConstants.LEADING);
    showPlainBytesFlag.setSelected(swingConfig.isShowPlainBytes());
    showPlainBytesFlag.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            showBytes = ItemEvent.SELECTED == event.getStateChange();
        }
    });
    fileInfoPanel.add(showPlainBytesFlag);
    JRadioButton lastModifiedRadio = new JRadioButton(
            swingConfig.getLocalizer().localize("label.last-modified"));
    lastModifiedRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    lastModifiedRadio.setActionCommand(SwingConfig.DefaultFileInfo.LAST_MODIFIED.name());
    lastModifiedRadio
            .setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.LAST_MODIFIED);
    fileInfoOptions.add(lastModifiedRadio);
    fileInfoPanel.add(lastModifiedRadio);
    basePanel.add(fileInfoPanel);

    // buttons
    JPanel buttonPannel = new JPanel();
    buttonPannel.setAlignmentX(Component.LEFT_ALIGNMENT);
    buttonPannel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    // cancel
    JButton cancelButton = new JButton(swingConfig.getLocalizer().localize("button.cancel"));
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            SettingsDialog.this.dispose();
        }
    });
    buttonPannel.add(cancelButton);
    // save
    JButton saveButton = new JButton(swingConfig.getLocalizer().localize("button.save"));
    saveButton.addActionListener(new SaveButtonListener());
    buttonPannel.add(saveButton);
    this.getRootPane().setDefaultButton(saveButton);

    this.add(basePanel);
    this.add(buttonPannel);
    placeOnScreen(swingConfig.getScreenCenter());
}

From source file:edu.harvard.mcz.imagecapture.VerbatimClassifyDialog.java

/**
 * This method initializes jTableNumbers   
 *    // w  w w .  j  ava2  s .  co  m
 * @return javax.swing.JTable   
 */
private JTable getJTableNumbers() {
    if (jTableNumbers == null) {
        jTableNumbers = new JTable(new NumberTableModel());
        JComboBox<String> jComboNumberTypes = new JComboBox<String>();
        jComboNumberTypes.setModel(new DefaultComboBoxModel<String>(NumberLifeCycle.getDistinctTypes()));
        jComboNumberTypes.setEditable(true);
        TableColumn typeColumn = jTableNumbers.getColumnModel().getColumn(NumberTableModel.COLUMN_TYPE);
        DefaultCellEditor comboBoxEditor = new DefaultCellEditor(jComboNumberTypes);
        //TODO: enable autocomplete for numbertypes picklist.
        //AutoCompleteDecorator.decorate((JComboBox) comboBoxEditor.getComponent());
        typeColumn.setCellEditor(comboBoxEditor);
        DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
        renderer.setToolTipText("Click for pick list of number types.");
        typeColumn.setCellRenderer(renderer);
    }
    return jTableNumbers;
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java

/**
 * Creates the proper UI component for the Mapping item.
 * @param dbFieldType the field type//from   w w w . j  a v a 2  s .co m
 * @param caption the caption
 * @param fieldName the name of the field
 * @param dataFieldLength the length of the definition for that field
 * @param fieldType the field type
 * @return a UI component for editing
 */
protected JComponent createUIComp(final Class<?> dbFieldTypeArg, final String caption, final String fieldName,
        final Short fieldType, final Short fieldLength, final short columns, final short rows,
        final WorkbenchTemplateMappingItem wbtmi) {
    short uiType = WorkbenchTemplateMappingItem.UNKNOWN;
    //System.out.println(wbtmi.getCaption()+" "+wbtmi.getDataType()+" "+wbtmi.getFieldLength());
    Class<?> dbFieldType = dbFieldTypeArg;
    if (dbFieldType == null) {
        // if we can't find a class for the field (i.e. Genus Species, or other 'fake' fields), we say it's a string
        dbFieldType = String.class;
    }

    JComponent comp;
    Component focusComp;

    // handle dates
    if (dbFieldType.equals(Calendar.class) || dbFieldType.equals(Date.class)) {
        //ValFormattedTextField txt = new ValFormattedTextField("Date"); 
        //txt.setColumns(columns == -1 ? DEFAULT_TEXTFIELD_COLS : columns);
        ValTextField txt = new ValTextField(columns);
        txt.getDocument().addDocumentListener(docListener);
        comp = txt;
        focusComp = comp;
        uiType = WorkbenchTemplateMappingItem.TEXTFIELD_DATE;
    }
    //        else if (dbFieldType.equals(Boolean.class)) // strings
    //        {
    //            ValCheckBox checkBox = new ValCheckBox(caption, false, false);
    //            checkBox.addChangeListener(changeListener);
    //            comp      = checkBox;
    //            focusComp = comp;
    //            uiType = WorkbenchTemplateMappingItem.CHECKBOX;
    //        }
    else if (useComboBox(wbtmi)) {
        //ValComboBox comboBox = new ValComboBox(getValues(wbtmi), true);

        final JComboBox comboBox = new JComboBox(getValues(wbtmi));
        comboBox.setName("Form Combo");
        comboBox.setEditable(true);
        comboBox.addActionListener(new ActionListener() {

            /* (non-Javadoc)
             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
             */
            @Override
            public void actionPerformed(ActionEvent arg0) {
                if (arg0.getSource() == comboBox) {
                    //System.out.println("ComboBox Action!" + ((JComboBox )arg0.getSource()).getName());
                    stateChange();
                }
            }

        });
        //           comboBox.getEditor().getEditorComponent().addFocusListener(new FocusListener() {
        //
        //            /* (non-Javadoc)
        //             * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
        //             */
        //            @Override
        //            public void focusGained(FocusEvent arg0) {
        //               System.out.println("FOCUS GAINED");
        //               
        //            }
        //
        //            /* (non-Javadoc)
        //             * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
        //             */
        //            @Override
        //            public void focusLost(FocusEvent arg0) {
        //               System.out.println("FOCUS LOST");
        //               
        //            }
        //              
        //           });
        comp = comboBox;
        focusComp = comp;
        uiType = WorkbenchTemplateMappingItem.COMBOBOX;
    } else if (useTextField(fieldName, fieldType, fieldLength)) {
        ValTextField txt = new ValTextField(columns);
        txt.getDocument().addDocumentListener(docListener);
        txt.setInputVerifier(new LengthInputVerifier(caption, fieldLength));
        comp = txt;
        focusComp = comp;
        uiType = WorkbenchTemplateMappingItem.TEXTFIELD;

    } else {
        JScrollPane taScrollPane = createTextArea(columns, rows);
        ((JTextArea) taScrollPane.getViewport().getView())
                .setInputVerifier(new LengthInputVerifier(caption, fieldLength));
        comp = taScrollPane;
        focusComp = taScrollPane.getViewport().getView();
        uiType = WorkbenchTemplateMappingItem.TEXTAREA;
    }

    wbtmi.setFieldType(uiType);

    focusComp.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
            selectControl(e.getSource());
        }

        public void focusLost(FocusEvent e) {
            //stateChange();
        }
    });

    comp.setEnabled(!readOnly);
    focusComp.setEnabled(!readOnly);

    comp.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (!readOnly) {
                if ((e.isControlDown() || e.isMetaDown()) && e.getKeyCode() == KeyEvent.VK_N) {
                    workbenchPane.addRowAfter();
                }
            }
            super.keyTyped(e);
        }

    });
    return comp;
}

From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java

/**
 * @param fi//from  w w w.j  av  a2  s  . co m
 * @return
 */
protected FormPanelInfo createPanel(final FormInfo formInfo) {
    CellConstraints cc = new CellConstraints();

    JPanel panel = new JPanel(null);
    int maxWidth = 0;
    int maxHeight = 0;
    int maxCellWidth = 0;
    int maxCellHeight = 0;
    for (FormFieldInfo fi : formInfo.getFields()) {
        System.out.println(fi.getCaption());
        boolean addLbl = true;
        JComponent comp = null;
        switch (fi.getControlTypeNum()) {
        case 4:
            comp = createComboBox(); // 'Picklist'
            break;

        case 5: {
            JComboBox cbx = createComboBox(); //new ValComboBoxFromQuery(DBTableIdMgr.getInstance().getInfoById(1), "catalogNumber","CatalogNumber","CatalogNumber"," "," "," "," "," ",ValComboBoxFromQuery.CREATE_ALL);// 'QueryCombo'
            cbx.setEditable(true);
            cbx.getEditor().setItem(fi.getCaption());
            JPanel cPanel = new JPanel(new BorderLayout());
            cPanel.add(cbx, BorderLayout.CENTER);
            cPanel.add(createElipseBtn(), BorderLayout.EAST);
            comp = cPanel;
            addLbl = false;
            break;
        }

        case 7: {
            String uniqueKey = getUniqueKey(fi.getRelatedTableName(), "Embedded", fi.getParent().getFormType());
            FormInfo subForm = formHash.get(uniqueKey);
            if (subForm == null) {
                uniqueKey = getUniqueKey(fi.getRelatedTableName(), "Embedded", null);
                subForm = formHash.get(uniqueKey);
            }
            if (subForm != null) {
                Vector<String> headers = new Vector<String>();
                for (int i = 0; i < subForm.getFields().size(); i++) {
                    headers.add(subForm.getFields().get(i).getCaption());
                }
                JPanel p = new JPanel(new BorderLayout());
                p.add(UIHelper.createScrollPane(new JTable(new Vector<Vector<Object>>(), headers)),
                        BorderLayout.CENTER); // 'Grid'
                comp = p;
                addLbl = false;
            }
            break;
        }

        case 8: // 'EmbeddedForm'
        {
            String uniqueKey = getUniqueKey(fi.getRelatedTableName(), "Embedded", fi.getParent().getFormType());
            FormInfo subForm = formHash.get(uniqueKey);
            if (subForm == null) {
                uniqueKey = getUniqueKey(fi.getRelatedTableName(), "Embedded", null);
                subForm = formHash.get(uniqueKey);
            }
            comp = (subForm != null ? createPanel(subForm).getPanel() : new JPanel());
            addLbl = fi.getControlTypeNum() != 8;
            break;
        }
        case 9: {
            comp = createElipseBtn();
            break;
        }

        case 20:
            comp = createScrollPane(createTextArea()); // 'Memo'
            break;

        case 21:
            comp = null;//createComboBox(); // 'MenuItem'
            break;

        case 46:
            comp = createTextField("URL"); // 'URL'
            break;

        default:
            if (fi.getDataTypeNum() == 4) {
                comp = createCheckBox(" ");
            } else {
                comp = createTextField();
            }
        } // switch

        if (comp != null) {
            String toolTip = "Field: " + fi.getSp5FieldName()
                    + (StringUtils.isNotEmpty(fi.getSp6FieldName())
                            && fi.getSp6FieldName().equalsIgnoreCase(fi.getSp5FieldName())
                                    ? " Sp6: " + fi.getSp6FieldName()
                                    : "");
            comp.setToolTipText(toolTip);

            PanelBuilder pb = new PanelBuilder(new FormLayout("p,1px,f:p:g", "f:p:g,p,f:p:g"));

            pb.getPanel().setToolTipText(toolTip);
            pb.getPanel().setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
            if (addLbl) {
                pb.add(createLabel(fi.getCaption()), cc.xy(1, 2));
            }
            pb.add(comp, cc.xy(3, 2));
            panel.add(pb.getPanel());

            maxWidth = Math.max(maxWidth, fi.getLeft() + fi.getWidth());
            maxHeight = Math.max(maxHeight, fi.getTop() + fi.getHeight());

            maxCellWidth = Math.max(maxWidth, fi.getCellX() + fi.getCellWidth());
            maxCellHeight = Math.max(maxHeight, fi.getCellY() + fi.getCellHeight());

            boolean newWay = false;
            if (newWay) {
                Rectangle r = fi.getBoundsFromCellDim();
                pb.getPanel().setLocation(r.x, r.y);
                pb.getPanel().setSize(r.width, r.height);

            } else {
                pb.getPanel().setLocation(fi.getLeft(), fi.getTop());
                pb.getPanel().setSize(fi.getWidth(), fi.getHeight());
            }

            System.out.println("MaxW: " + maxWidth + "  " + maxCellWidth);
            System.out.println("MaxH: " + maxHeight + "  " + maxCellHeight);
        }
    }

    boolean newWay = false;
    if (newWay) {
        int cw = FormFieldInfo.getSegWidth();
        panel.setPreferredSize(new Dimension(maxCellWidth * cw, maxCellHeight * cw));
        panel.setSize(new Dimension(maxCellWidth * cw, maxCellHeight * cw));
    } else {
        panel.setPreferredSize(new Dimension(maxWidth, maxHeight));
        panel.setSize(new Dimension(maxWidth, maxHeight));
    }

    System.out.println("MaxW: " + maxWidth + "  " + maxCellWidth);
    System.out.println("MaxH: " + maxHeight + "  " + maxCellHeight);

    return new FormPanelInfo(formInfo.getTitle(), panel, maxWidth, maxHeight);
}

From source file:ffx.ui.ModelingPanel.java

private void initCommandComboBox(JComboBox commands) {
    commands.setActionCommand("FFXCommand");
    commands.setMaximumSize(xyzCommands.getPreferredSize());
    commands.setEditable(false);
    commands.setToolTipText("Select a Modeling Command");
    commands.setSelectedIndex(0);//  w w w  .j ava 2  s . c o m
    commands.addActionListener(this);
}

From source file:edu.harvard.mcz.imagecapture.SpecimenDetailsViewPane.java

/**
 * This method initializes jTable   /*  ww  w  . ja v a2s  . com*/
 *    
 * @return javax.swing.JTable   
 */
private JTable getJTable() {
    if (jTableNumbers == null) {
        jTableNumbers = new JTable(new NumberTableModel());
        JComboBox<String> jComboNumberTypes = new JComboBox<String>();
        jComboNumberTypes.setModel(new DefaultComboBoxModel<String>(NumberLifeCycle.getDistinctTypes()));
        jComboNumberTypes.setEditable(true);
        TableColumn typeColumn = jTableNumbers.getColumnModel().getColumn(NumberTableModel.COLUMN_TYPE);
        DefaultCellEditor comboBoxEditor = new DefaultCellEditor(jComboNumberTypes);
        //TODO: enable autocomplete for numbertypes picklist.
        //AutoCompleteDecorator.decorate((JComboBox) comboBoxEditor.getComponent());
        typeColumn.setCellEditor(comboBoxEditor);
        DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
        renderer.setToolTipText("Click for pick list of number types.");
        typeColumn.setCellRenderer(renderer);
        jTableNumbers.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent e) {
                thisPane.setStateToDirty();
            }
        });

        jTableNumbers.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnNumsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupNumbers.show(e.getComponent(), e.getX(), e.getY());
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnNumsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupNumbers.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        });

        jPopupNumbers = new JPopupMenu();
        JMenuItem mntmDeleteRow = new JMenuItem("Delete Row");
        mntmDeleteRow.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    if (clickedOnNumsRow >= 0) {
                        int ok = JOptionPane.showConfirmDialog(thisPane, "Delete the selected number?",
                                "Delete Number", JOptionPane.OK_CANCEL_OPTION);
                        if (ok == JOptionPane.OK_OPTION) {
                            log.debug("deleting numbers row " + clickedOnNumsRow);
                            ((NumberTableModel) jTableNumbers.getModel()).deleteRow(clickedOnNumsRow);
                            setStateToDirty();
                        } else {
                            log.debug("number row delete canceled by user.");
                        }
                    } else {
                        JOptionPane.showMessageDialog(thisPane,
                                "Unable to select row to delete.  Try empting number and type and pressing Save.");
                    }
                } catch (Exception ex) {
                    log.error(ex.getMessage());
                    JOptionPane.showMessageDialog(thisPane,
                            "Failed to delete a number row. " + ex.getMessage());
                }
            }
        });
        jPopupNumbers.add(mntmDeleteRow);
    }
    return jTableNumbers;
}

From source file:edu.harvard.mcz.imagecapture.SpecimenDetailsViewPane.java

private void setValues() {
    log.debug("invoking setValues()");
    jTextFieldStatus.setText("Loading");

    jTextFieldBarcode.setText(specimen.getBarcode());
    jComboBoxLocationInCollection.setSelectedItem(specimen.getLocationInCollection());
    cbTypeStatus.setSelectedItem(specimen.getTypeStatus());
    jTextFieldDrawerNumber.setText(specimen.getDrawerNumber());
    jComboBoxFamily.setSelectedItem(specimen.getFamily());
    jComboBoxSubfamily.setSelectedItem(specimen.getSubfamily());
    jTextFieldTribe.setText(specimen.getTribe());
    jTextFieldGenus.setText(specimen.getGenus());
    jTextFieldSpecies.setText(specimen.getSpecificEpithet());
    jTextFieldSubspecies.setText(specimen.getSubspecificEpithet());
    jTextFieldInfraspecificEpithet.setText(specimen.getInfraspecificEpithet());
    jTextFieldInfraspecificRank.setText(specimen.getInfraspecificRank());
    jTextFieldAuthorship.setText(specimen.getAuthorship());

    jTextFieldIdRemarks.setText(specimen.getIdentificationRemarks());
    jTextFieldDateDetermined.setText(specimen.getDateIdentified());

    MCZbaseAuthAgentName selection = new MCZbaseAuthAgentName();
    selection.setAgent_name(specimen.getIdentifiedBy());
    ((AgentNameComboBoxModel) jCBDeterminer.getModel()).setSelectedItem(selection);
    jCBDeterminer.getEditor().setItem(jCBDeterminer.getModel().getSelectedItem());

    jComboBoxNatureOfId.setSelectedItem(specimen.getNatureOfId());

    jTextFieldUnnamedForm.setText(specimen.getUnNamedForm());
    jTextFieldVerbatimLocality.setText(specimen.getVerbatimLocality());
    // Specimen record contains a string, delegate handling of lookup of object to the combo box model.
    log.debug(specimen.getHigherGeography());
    ((HigherGeographyComboBoxModel) comboBoxHigherGeog.getModel())
            .setSelectedItem(specimen.getHigherGeography());
    //TODO ? set model not notifying listeners?       
    comboBoxHigherGeog.getEditor().setItem(comboBoxHigherGeog.getModel().getSelectedItem());
    jTextFieldCountry.setText(specimen.getCountry());
    if (specimen.getValidDistributionFlag() != null) {
        jCheckBoxValidDistributionFlag.setSelected(specimen.getValidDistributionFlag());
    } else {/*  w  w  w . j a  v a  2  s. co  m*/
        jCheckBoxValidDistributionFlag.setSelected(false);
    }
    jTextFieldPrimaryDivision.setText(specimen.getPrimaryDivison());
    jTextFieldLocality.setText(specimen.getSpecificLocality());

    // Elevations  **********************************************************************
    try {
        jTextFieldMinElevation.setText(Long.toString(specimen.getMinimum_elevation()));
    } catch (Exception e) {
        jTextFieldMinElevation.setText("");
    }
    try {
        textFieldMaxElev.setText(Long.toString(specimen.getMaximum_elevation()));
    } catch (Exception e) {
        textFieldMaxElev.setText("");
    }
    if (specimen.getElev_units() != null) {
        comboBoxElevUnits.setSelectedItem(specimen.getElev_units());
    } else {
        comboBoxElevUnits.setSelectedItem("");
    }

    jTextFieldCollectingMethod.setText(specimen.getCollectingMethod());
    jTextFieldISODate.setText(specimen.getIsoDate());
    jTextFieldDateNos.setText(specimen.getDateNos());
    jTextFieldDateCollected.setText(specimen.getDateCollected());
    jTextFieldDateEmerged.setText(specimen.getDateEmerged());
    jTextFieldDateCollectedIndicator.setText(specimen.getDateCollectedIndicator());
    jTextFieldDateEmergedIndicator.setText(specimen.getDateEmergedIndicator());
    jComboBoxCollection.setSelectedItem(specimen.getCollection());
    //jTextFieldPreparationType.setText(specimen.getPreparationType());
    jTextFieldAssociatedTaxon.setText(specimen.getAssociatedTaxon());
    jTextFieldHabitat.setText(specimen.getHabitat());
    jTextAreaSpecimenNotes.setText(specimen.getSpecimenNotes());
    jComboBoxFeatures.setSelectedItem(specimen.getFeatures());
    jComboBoxLifeStage.setSelectedItem(specimen.getLifeStage());
    jComboBoxSex.setSelectedItem(specimen.getSex());
    jTextFieldCitedInPub.setText(specimen.getCitedInPublication());
    jTextFieldQuestions.setText(specimen.getQuestions());
    jComboBoxWorkflowStatus.setSelectedItem(specimen.getWorkFlowStatus());
    if (specimen.isStateDone()) {
        jLabelMigrationStatus.setText("http://mczbase.mcz.harvard.edu/guid/MCZ:Ent:" + specimen.getCatNum());
    } else {
        jLabelMigrationStatus.setText("");
    }
    jTextFieldInferences.setText(specimen.getInferences());
    jTextFieldCreator.setText(specimen.getCreatedBy());
    if (specimen.getDateCreated() != null) {
        jTextFieldDateCreated.setText(specimen.getDateCreated().toString());
    }
    jTextFieldLastUpdatedBy.setText(specimen.getLastUpdatedBy());
    if (specimen.getDateLastUpdated() != null) {
        jTextFieldDateLastUpdated.setText(specimen.getDateLastUpdated().toString());
    }

    jTableNumbers.setModel(new NumberTableModel(specimen.getNumbers()));
    // Setting the model will overwrite the existing cell editor bound 
    // to the column model, so we need to add it again.
    JTextField field1 = new JTextField();
    field1.setInputVerifier(MetadataRetriever.getInputVerifier(edu.harvard.mcz.imagecapture.data.Number.class,
            "Number", field1));
    field1.setVerifyInputWhenFocusTarget(true);
    jTableNumbers.getColumnModel().getColumn(0).setCellEditor(new ValidatingTableCellEditor(field1));
    JComboBox<String> jComboNumberTypes = new JComboBox<String>();
    jComboNumberTypes.setModel(new DefaultComboBoxModel<String>(NumberLifeCycle.getDistinctTypes()));
    jComboNumberTypes.setEditable(true);
    TableColumn typeColumn = jTableNumbers.getColumnModel().getColumn(NumberTableModel.COLUMN_TYPE);
    typeColumn.setCellEditor(new DefaultCellEditor(jComboNumberTypes));

    jTableCollectors.setModel(new CollectorTableModel(specimen.getCollectors()));
    // Setting the model will overwrite the existing cell editor bound 
    // to the column model, so we need to add it again.
    // JTextField field = new JTextField();
    FilteringAgentJComboBox field = new FilteringAgentJComboBox();
    //field.setInputVerifier(MetadataRetriever.getInputVerifier(Collector.class, "CollectorName", field));
    //jTableCollectors.getColumnModel().getColumn(0).setCellEditor(new PicklistTableCellEditor(field, true));
    jTableCollectors.getColumnModel().getColumn(0).setCellEditor(new ComboBoxCellEditor(field));
    //field.setInputVerifier(MetadataRetriever.getInputVerifier(Collector.class, "CollectorName", field));
    //field.setVerifyInputWhenFocusTarget(true);
    //jTableCollectors.getColumnModel().getColumn(0).setCellEditor(new ValidatingTableCellEditor(field));

    jTableSpecimenParts.setModel(new SpecimenPartsTableModel(specimen.getSpecimenParts()));
    jTableSpecimenParts.getColumnModel().getColumn(0).setPreferredWidth(90);
    for (int i = 0; i < jTableSpecimenParts.getColumnCount(); i++) {
        TableColumn column = jTableSpecimenParts.getColumnModel().getColumn(i);
        if (i == 0) {
            column.setPreferredWidth(120);
        } else {
            column.setPreferredWidth(50);
        }
    }
    setSpecimenPartsTableCellEditors();

    updateDeterminationCount();

    if (specimen.getICImages() != null) {
        int imageCount = specimen.getICImages().size();
        jTextFieldImageCount.setText("Number of Images=" + imageCount);
        if (imageCount > 1) {
            jTextFieldImageCount.setForeground(Color.RED);
        } else {
            jTextFieldImageCount.setForeground(Color.BLACK);
        }
    }

    setWarnings();
    this.setStateToClean();
    jTextFieldStatus.setText("Loaded");
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * @param wbtmi/*  w  w  w  . j  av  a 2s.  c o m*/
 * @return
 */
protected GridCellEditor getCellEditor(WorkbenchTemplateMappingItem wbtmi, int fieldWidth, JButton theSaveBtn,
        Element uploadDefs) {
    PickListDBAdapterIFace pickList = null;
    DBTableInfo tblInfo = DBTableIdMgr.getInstance().getInfoByTableName(wbtmi.getTableName());
    if (tblInfo != null) {
        String fldName = wbtmi.getFieldName();
        @SuppressWarnings("unchecked")
        List<Object> flds = uploadDefs.selectNodes("field");
        for (Object fld : flds) {
            String table = XMLHelper.getAttr((Element) fld, "table", null);
            String field = XMLHelper.getAttr((Element) fld, "name", null);
            if (wbtmi.getTableName().equalsIgnoreCase(table) && wbtmi.getFieldName().equalsIgnoreCase(field)) {
                fldName = XMLHelper.getAttr((Element) fld, "actualname", fldName);
                break;
            }
        }
        DBFieldInfo fldInfo = tblInfo.getFieldByName(fldName);
        if (fldInfo != null) {
            if (!StringUtils.isEmpty(fldInfo.getPickListName())) {
                pickList = PickListDBAdapterFactory.getInstance().create(fldInfo.getPickListName(), false);
            } else if (RecordTypeCodeBuilder.isTypeCodeField(fldInfo)) {
                pickList = RecordTypeCodeBuilder.getTypeCode(fldInfo);
            }
        }
        if (tblInfo.getTableId() == Preparation.getClassTableId()) {
            fldName = wbtmi.getFieldName();
            if (fldName.startsWith("prepType") && StringUtils.isNumeric(fldName.replace("prepType", ""))) {
                pickList = PickListDBAdapterFactory.getInstance().create("prepType", false);
            }

        }
    }
    if (pickList == null) {
        return new GridCellEditor(new JTextField(), wbtmi.getCaption(), fieldWidth, theSaveBtn);
    }
    JComboBox<PickListItemIFace> comboBox = new JComboBox<PickListItemIFace>(pickList.getList());
    comboBox.setEditable(true);
    return new GridCellListEditor(comboBox, wbtmi.getCaption(), fieldWidth, theSaveBtn);
}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java

public void updateAvailableConcepts() {
    if (!isUpdatingAvailableConcepts.get() && this.isExportMapping) {
        isUpdatingAvailableConcepts.set(true);
        try {/*ww  w  . java2  s .  c om*/
            List<SpExportSchemaItem> available = this.getAvailableConcepts();
            for (QueryFieldPanel qfp : queryFieldItems) {
                JComboBox bx = qfp.getSchemaItemCBX();
                if (bx != null) {
                    DefaultComboBoxModel bxm = (DefaultComboBoxModel) bx.getModel();
                    bxm.removeAllElements();
                    for (SpExportSchemaItem i : available) {
                        bxm.addElement(i);
                    }
                    SpExportSchemaItem qi = qfp.getSchemaItem();
                    if (qi != null && qi.getSpExportSchemaItemId() != null) {
                        SpExportSchemaItem unMappedItem = new SpExportSchemaItem();
                        unMappedItem.setFieldName(getResourceString("QueryBldrPane.UnmappedSchemaItemName"));
                        bxm.insertElementAt(unMappedItem, 0);
                        bxm.insertElementAt(qi, 1);
                        bx.setSelectedIndex(1);
                    } else {
                        //System.out.println("Setting unmapped concept field name to " + qfp.getExportedFieldName());
                        SpExportSchemaItem unMappedItem = new SpExportSchemaItem();
                        String expFldName = qfp.getExportedFieldName();
                        if (StringUtils.isBlank(expFldName)) {
                            if (available.size() > 0) {
                                unMappedItem.setFieldName(
                                        getResourceString("QueryBldrPane.UnmappedSchemaItemName"));
                            } else {
                                unMappedItem.setFieldName(qfp.getFieldTitle());
                            }
                        } else {
                            unMappedItem.setFieldName(expFldName);
                        }
                        bxm.insertElementAt(unMappedItem, 0);
                        bx.setSelectedIndex(0);
                    }
                    bx.setEditable(qi == null || qi.getSpExportSchemaItemId() == null);
                }
            }
        } finally {
            isUpdatingAvailableConcepts.set(false);
        }
    }
}

From source file:nl.ru.ai.projects.parrot.biomav.editor.BehaviorEditor.java

private void setNewSelectedParameterControlInterface(ParameterControlInterface pcInterface) {
    pcInterfacePanelContents.removeAll();
    selectedPCInterface = null;//  w  w  w  .j  a  va 2 s.c  om

    if (pcInterface != null) {
        selectedPCInterface = pcInterface;
        final ParameterControlInterface fpcInterface = pcInterface;

        String[] parameterNames = pcInterface.getParameterNames();
        ParameterControlInterface.ParameterTypes[] parameterTypes = pcInterface.getParameterTypes();

        for (int i = 0; i < parameterTypes.length; i++) {
            JLabel label = new JLabel(parameterNames[i]);
            pcInterfacePanelContents.add(label);

            final int index = i;
            switch (parameterTypes[i]) {
            case OPTIONS:
                final JComboBox optionComboBox = new JComboBox(pcInterface.getParameterOptions(i));
                optionComboBox.setEditable(false);
                optionComboBox.setSelectedItem(pcInterface.getParameterValue(i));

                optionComboBox.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        fpcInterface.setParameterValue(index, optionComboBox.getSelectedItem());
                        repaint();
                    }
                });

                pcInterfacePanelContents.add(optionComboBox);

                break;
            }
        }
    }

    pcInterfacePanel.validate();
}