/** * Moves the "..." button to either the left or right. * * @param left if true the button gets moved to the left, otherwise * to the right */ public void moveChooseButton(boolean left) { if (left) m_PanelPrefix.add(m_PanelButtons, BorderLayout.EAST); else add(m_PanelButtons, BorderLayout.EAST); }
/** * Lets the user choose and updates the current value if choosing was * successful. */ public void choose() { T value; value = doChoose(); if (m_Editable) { if (value != null) { setCurrent(value); fireCurrentValueChanged(); } } }
@Override public void focusLost(FocusEvent e) { super.focusLost(e); if (isInlineEditingEnabled()) setCurrent(fromString(m_TextSelection.getText())); } });
super.initGUI(); setLayout(new BorderLayout()); m_PanelPrefix.add(m_LabelPrefix, BorderLayout.CENTER); m_PanelPrefix.add(m_LabelPrefixSpacer, BorderLayout.EAST); add(m_PanelPrefix, BorderLayout.WEST); m_TextSelection = new JTextField(getSelectionColumns()); m_TextSelection.setTransferHandler(null); m_TextSelection.setText(getDefaultString()); m_TextSelection.setEditable(false); m_TextSelection.setPreferredSize( add(m_TextSelection, BorderLayout.CENTER); add(m_PanelButtons, BorderLayout.EAST); m_ButtonSelection.getPreferredSize().width, m_TextSelection.getPreferredSize().height)); m_ButtonSelection.addActionListener(e -> choose()); m_PanelButtons.add(m_ButtonSelection); updatePreferredSize();
clipboard = getStringFromClipboard(); if (isInlineEditingEnabled()) { caret += clipboard.length(); if (m_TextSelection.getSelectedText() == null) { text.replace(m_TextSelection.getSelectionStart(), m_TextSelection.getSelectionEnd(), clipboard); setCurrent(fromString(text.toString())); setCurrent(fromString(clipboard)); if (isInlineEditingEnabled()) { try { m_TextSelection.setCaretPosition(caret); notifyChangeListeners(new ChangeEvent(m_Self));
@Override public void mouseClicked(MouseEvent e) { if (MouseUtils.isDoubleClick(e) && !isInlineEditingEnabled()) { e.consume(); choose(); } else if (MouseUtils.isRightClick(e)) { e.consume(); JPopupMenu menu = getPopupMenu(); if (menu != null) menu.show(m_TextSelection, e.getX(), e.getY()); } else { super.mouseClicked(e); } } });
/** * Returns a popup menu when right-clicking on the edit field. * * @return the menu, null if non available */ protected JPopupMenu getPopupMenu() { JPopupMenu result; JMenuItem menuitem; result = new JPopupMenu(); menuitem = new JMenuItem("Copy", GUIHelper.getIcon("copy.gif")); menuitem.setAccelerator(KeyStroke.getKeyStroke("control pressed C")); menuitem.addActionListener(e -> copyToClipboard()); result.add(menuitem); menuitem = new JMenuItem("Paste", GUIHelper.getIcon("paste.gif")); menuitem.setAccelerator(KeyStroke.getKeyStroke("control pressed V")); menuitem.setEnabled(isEditable() && ClipboardHelper.canPasteStringFromClipboard()); menuitem.addActionListener(e -> pasteFromClipboard()); result.add(menuitem); if (m_PopupMenuCustomizer != null) { result.addSeparator(); m_PopupMenuCustomizer.customizePopupMenu(this, result); } return result; }
/** * Sets the current value. * * @param value the value to use, can be null * @return if successfully set */ public boolean setCurrent(T value) { boolean result; String str; result = true; str = getDefaultString(); if (value != null) { try { str = toString(value); } catch (Exception e) { e.printStackTrace(); str = getDefaultString(); result = false; } } m_TextSelection.setText(str); m_TextSelection.setCaretPosition(0); return result; }
@Override public void keyPressed(KeyEvent e) { if (KeyUtils.isCopy(e)) { e.consume(); copyToClipboard(); } else if (KeyUtils.isPaste(e) && ClipboardHelper.canPasteStringFromClipboard()) { e.consume(); pasteFromClipboard(); } if (!e.isConsumed()) super.keyPressed(e); } });
/** * Checks whether the value of text field is different from the default * value, i.e., a proper value. * * @return true if a proper value is available */ public boolean hasValue() { return (!m_TextSelection.getText().equals(getDefaultString())); }
/** * Returns the current value. * * @return the current value */ public T getCurrent() { return fromString(m_TextSelection.getText()); }
/** * Adds a change listener to the specified component. * * @param comp the component to add the listener to */ protected void addChangeListenerTo(Component comp) { if (comp instanceof AbstractChooserPanel) ((AbstractChooserPanel) comp).addChangeListener(this); else if (comp instanceof JTextComponent) ((JTextComponent) comp).getDocument().addDocumentListener(m_DocumentListener); else if (comp instanceof AbstractButton) ((AbstractButton) comp).addActionListener(m_ActionListener); else if (comp instanceof JComboBox) ((JComboBox) comp).addActionListener(m_ActionListener); else if (comp instanceof JSpinner) ((JSpinner) comp).addChangeListener(this); else if (comp instanceof PropertyEditor) ((PropertyEditor) comp).addPropertyChangeListener(m_PropertyChangeListener); //else // System.err.println("Failed to add change listener to component type: " + Utils.classToString(comp)); }
if (m_UseCheckBoxes) m_CheckBoxes.add(check); m_Labels.add(chooser.getPrefixLabel()); index = m_Parameters.size(); m_Parameters.add(chooser); if (m_UseCheckBoxes) m_CheckBoxes.add(index, check); m_Labels.add(index, chooser.getPrefixLabel()); m_Parameters.add(index, chooser);
/** * Sets the default value. */ public void setDefault() { m_TextSelection.setText(getDefaultString()); m_TextSelection.setCaretPosition(0); }