/** * This method initializes jComboBoxPagoResto * * <p>return javax.swing.JComboBox */ private JComboBox getJComboBoxPagoResto() { if (jComboBoxPagoResto == null) { jComboBoxPagoResto = new JComboBox(); jComboBoxPagoResto.setBackground(new java.awt.Color(224, 224, 222)); jComboBoxPagoResto.setPreferredSize(new java.awt.Dimension(50, 20)); jComboBoxPagoResto.addItem(new LabelValueBean("SI", "0")); jComboBoxPagoResto.addItem(new LabelValueBean("NO", "99")); jComboBoxPagoResto.addKeyListener(this); } return jComboBoxPagoResto; }
public AutoFilterCombo(final String[] data, boolean editable) { // set data in combo to be a copy of the data input. This is required due to behaviour of // removeAllItems() // method in JComboBox which results in removal of elements from the data source also. By making // a copy, only // the elements in the copy are removed, not the original source. super(data == null ? new String[] {""} : data.clone()); // make combo editable super.setEditable(editable); UIHelper.setJComboBoxAsHeavyweight(this); // add key listener to the combobox editor to listen for input from user. super.getEditor() .getEditorComponent() .addKeyListener( new KeyAdapter() { public void keyReleased(KeyEvent e) { super.keyPressed(e); // as long as the key pressed isnt up arrow, down arrow, or return, the proceed if ((e.getKeyCode() != 38) && (e.getKeyCode() != 40) && (e.getKeyCode() != 10)) { String entered = getEditor().getItem().toString().toLowerCase(); removeAllItems(); int itemCount = 0; for (String aData : data) { if (aData.toLowerCase().contains(entered)) { addItem(aData); itemCount++; } } getEditor().setItem(entered); JTextField textField = (JTextField) e.getSource(); textField.setCaretPosition(textField.getDocument().getLength()); hidePopup(); if (itemCount != 0 && isDisplayable()) { showPopup(); } } } }); }
public CyComboBoxPropertyEditor() { pcs = new PropertyChangeSupport(this); final JComboBox combo = new JComboBox(); editor = combo; combo.setRenderer(new Renderer()); combo.addPopupMenuListener( new PopupMenuListener() { @Override public void popupMenuCanceled(PopupMenuEvent e) {} @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { try { if ((combo.getSelectedItem() == null) && (combo.getItemCount() != 0)) { combo.setSelectedIndex(0); firePropertyChange(oldValue, combo.getItemAt(0)); } else firePropertyChange(oldValue, combo.getSelectedItem()); } catch (Exception ex) { ex.printStackTrace(); } } @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { oldValue = combo.getSelectedItem(); } }); combo.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) CyComboBoxPropertyEditor.this.firePropertyChange(oldValue, combo.getSelectedItem()); } }); combo.setSelectedIndex(-1); }
private void initGui(AnnotatedFeatureI annot) { translationViewer = new TranslationViewer(editorPanel); translationViewer.setBackground(Color.black); transcriptComboBox = new JComboBox(); lengthLabel = new JLabel("Translation length: <no feature selected>"); lengthLabel.setForeground(Color.black); findButton = new JButton("Find sequence..."); clearFindsButton = new JButton("Clear search hits"); // Disable until we actually get search results clearFindsButton.setEnabled(false); goToButton = new JButton("GoTo..."); showIntronBox = new JCheckBox("Show introns in translation viewer", true); showIntronBox.setBackground(Color.white); followSelectionCheckBox = new JCheckBox("Follow external selection", false); followSelectionCheckBox.setBackground(Color.white); upstream_button = new JButton(); downstream_button = new JButton(); colorSwatch = new JPanel(); setSize(824, 500); JScrollPane pane = new JScrollPane(editorPanel); pane.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); // RAY: SET SCROLL POLICY HERE! WAS // HORIZONTAL_SCROLLBAR_NEVER // pane.setColumnHeaderView(new BaseFineEditorRowHeader(editorPanel)); // RAY: setRowHeader need // to create column header pane.setColumnHeaderView(new BaseFineEditorHorizontalColHeader(editorPanel)); viewport = pane.getViewport(); colorSwatch.setPreferredSize(new Dimension(10, 10)); getContentPane().setBackground(Color.white); getContentPane().setLayout(new BorderLayout()); getContentPane().add(colorSwatch, "North"); getContentPane().add(pane, "Center"); Box transcriptListBox = new Box(BoxLayout.X_AXIS); JLabel tranLabel; // 1 LEVEL ANNOT if (annot.isAnnotTop()) tranLabel = new JLabel("Annotation: "); else // 3-level tranLabel = new JLabel("Transcript: "); tranLabel.setForeground(Color.black); transcriptListBox.add(Box.createHorizontalStrut(5)); transcriptListBox.add(tranLabel); transcriptListBox.setBackground(Color.white); transcriptComboBox.setMaximumSize(new Dimension(300, 30)); transcriptListBox.add(transcriptComboBox); transcriptListBox.add(Box.createHorizontalGlue()); transcriptListBox.add(Box.createHorizontalStrut(5)); transcriptListBox.add(lengthLabel); transcriptListBox.add(Box.createHorizontalGlue()); Box checkboxesTop = new Box(BoxLayout.X_AXIS); checkboxesTop.setBackground(Color.white); checkboxesTop.add(Box.createHorizontalStrut(5)); checkboxesTop.add(findButton); checkboxesTop.add(Box.createHorizontalStrut(10)); checkboxesTop.add(clearFindsButton); checkboxesTop.add(Box.createHorizontalStrut(15)); checkboxesTop.add(goToButton); checkboxesTop.add(Box.createHorizontalGlue()); Box checkboxesBottom = new Box(BoxLayout.X_AXIS); checkboxesBottom.add(showIntronBox); checkboxesBottom.add(Box.createHorizontalGlue()); checkboxesBottom.add(Box.createHorizontalStrut(10)); checkboxesBottom.add(followSelectionCheckBox); Box checkboxes = new Box(BoxLayout.Y_AXIS); checkboxes.add(checkboxesTop); checkboxes.add(checkboxesBottom); Box labelPanel = new Box(BoxLayout.Y_AXIS); labelPanel.setBackground(Color.white); labelPanel.add(transcriptListBox); labelPanel.add(Box.createVerticalStrut(5)); labelPanel.add(checkboxes); Box navPanel = new Box(BoxLayout.Y_AXIS); navPanel.setBackground(Color.white); navPanel.add(upstream_button); navPanel.add(Box.createVerticalStrut(10)); navPanel.add(downstream_button); navPanel.add(Box.createVerticalGlue()); Box textBoxes = new Box(BoxLayout.X_AXIS); textBoxes.setBackground(Color.white); textBoxes.add(labelPanel); textBoxes.add(navPanel); Box detailPanel = new Box(BoxLayout.Y_AXIS); detailPanel.setBackground(Color.white); detailPanel.add(translationViewer); detailPanel.add(textBoxes); getContentPane().add(detailPanel, "South"); validateTree(); scrollListener = new FineEditorScrollListener(); viewport.addChangeListener(scrollListener); transcriptComboBox.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_U && (e.getModifiers() & KeyEvent.CTRL_MASK) != 0) { CurationManager.getActiveCurationState().getTransactionManager().undo(this); } } }); }
@Override protected void init() { GridBagLayout layout = new GridBagLayout(); setLayout(layout); setPreferredSize(new Dimension(275, 275)); String[] months = { "September", "October", "November", "December", "January", "February", "March", "April", "May", "June" }; JComboBox<String> courseSelectorinit; if (AllCourses.getInstance().getNames().length == 0) { String[] defaultOption = {"No Course"}; courseSelectorinit = new JComboBox<>(defaultOption); } else { courseSelectorinit = new JComboBox<>(AllCourses.getInstance().getNames()); } final JComboBox<String> courseSelector = courseSelectorinit; JLabel name = new JLabel("Name"), units = new JLabel("Units"); final JTextField nameField = new JTextField(), unitsField = new JTextField(); final JTextField orderField = new JTextField(); JLabel orderLabel = new JLabel("Order"); final JTextField weightField = new JTextField(); JLabel weightLabel = new JLabel("Weight"); final JCheckBox finished = new JCheckBox("Finished"); JLabel monthLabel = new JLabel("Month completed"); final JComboBox<String> month = new JComboBox<>(months); done = new JButton("Done"); cancel = new JButton("Cancel"); name.setHorizontalAlignment(SwingConstants.CENTER); units.setHorizontalAlignment(SwingConstants.CENTER); orderLabel.setHorizontalAlignment(SwingConstants.CENTER); weightLabel.setHorizontalAlignment(SwingConstants.CENTER); monthLabel.setHorizontalAlignment(SwingConstants.CENTER); courseSelector.setSelectedItem(currentWork.getCourseName()); nameField.setText(currentWork.getName()); nameField.setCaretPosition(0); unitsField.setText(String.valueOf(currentWork.getUnits())); orderField.setText(String.valueOf(currentWork.getOrder())); weightField.setText(String.valueOf(currentWork.getWeight())); finished.setSelected(currentWork.isComplete()); if (currentWork.isComplete()) { month.setSelectedIndex(currentWork.getMonthComplete()); } else { month.setSelectedIndex(Workload.convertMonth(DateTime.now().getMonthOfYear())); } courseSelector.addKeyListener(doneListener); nameField.addKeyListener(doneListener); unitsField.addKeyListener(doneListener); orderField.addKeyListener(doneListener); weightField.addKeyListener(doneListener); finished.addKeyListener(doneListener); month.addKeyListener(doneListener); done.addKeyListener(doneListener); cancel.addKeyListener(doneListener); done.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { editWork( courseSelector.getSelectedItem().toString(), nameField.getText(), Integer.parseInt(unitsField.getText()), Integer.parseInt(orderField.getText()), finished.isSelected(), month.getSelectedIndex(), Integer.parseInt(weightField.getText())); dispose(); } catch (NumberFormatException ex) { new ErrorMessage(ex, "Please input real numbers").createAndViewGUI(); } } }); cancel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; constraints.insets = new Insets(5, 8, 5, 8); constraints.weightx = 1; constraints.weighty = 1; constraints.gridwidth = 2; layout.addLayoutComponent(courseSelector, constraints); constraints.gridy = 1; constraints.gridx = 0; constraints.gridwidth = 1; layout.addLayoutComponent(name, constraints); constraints.gridx = 1; layout.addLayoutComponent(nameField, constraints); constraints.gridy = 2; constraints.gridx = 0; layout.addLayoutComponent(units, constraints); constraints.gridx = 1; layout.addLayoutComponent(unitsField, constraints); constraints.gridy = 3; constraints.gridx = 0; layout.addLayoutComponent(orderLabel, constraints); constraints.gridx = 1; layout.addLayoutComponent(orderField, constraints); constraints.gridx = 0; constraints.gridy = 4; layout.addLayoutComponent(weightLabel, constraints); constraints.gridx = 1; layout.addLayoutComponent(weightField, constraints); constraints.gridwidth = 2; constraints.gridy = 5; constraints.gridx = 1; constraints.insets = new Insets(0, 0, 0, 0); layout.addLayoutComponent(monthLabel, constraints); constraints.gridy = 6; constraints.gridx = 0; constraints.gridwidth = 1; constraints.insets = new Insets(5, 8, 5, 8); layout.addLayoutComponent(finished, constraints); constraints.gridx = 1; layout.addLayoutComponent(month, constraints); constraints.gridy = 7; constraints.gridx = 0; layout.addLayoutComponent(done, constraints); constraints.gridx = 1; layout.addLayoutComponent(cancel, constraints); add(courseSelector); add(name); add(nameField); add(units); add(unitsField); add(orderField); add(orderLabel); add(weightLabel); add(weightField); add(monthLabel); add(finished); add(month); add(done); add(cancel); }