List of usage examples for javax.swing JComponent addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
From source file:Main.java
public static void linkEnabled(JComponent watcher, final JComponent... actor) { watcher.addPropertyChangeListener(new PropertyChangeListener() { @Override/*from w w w . j a va 2 s . c o m*/ public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("enabled")) { Boolean newValue = (Boolean) evt.getNewValue(); if (newValue) { for (JComponent j : actor) { j.setEnabled(true); } } else { for (JComponent j : actor) { j.setEnabled(false); } } } } }); }
From source file:FormattedTextFieldExample.java
public void installUI(JComponent c) { super.installUI(c); if (c instanceof FormattedTextField) { c.addPropertyChangeListener(this); editor = (FormattedTextField) c; formatSpec = editor.getFormatSpec(); }/*w w w . j a va 2 s . c o m*/ }
From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptingDialog.java
/** Initializes the components. */ private void initComponents() { sorter = new ViewerSorter(); cancelButton = new JButton("Cancel"); cancelButton.setToolTipText("Close the dialog."); cancelButton.setActionCommand("" + CANCEL); cancelButton.addActionListener(this); applyButton = new JButton("Run Script"); applyButton.setToolTipText("Run the selected script."); applyButton.setActionCommand("" + APPLY); applyButton.addActionListener(this); IconManager icons = IconManager.getInstance(); menuButton = new JButton(icons.getIcon(IconManager.FILTER_MENU)); menuButton.setText("Script"); menuButton.setHorizontalTextPosition(JButton.LEFT); menuButton.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { Object src = e.getSource(); if (src instanceof Component) { Point p = e.getPoint(); createOptionMenu().show((Component) src, p.x, p.y); }// w w w . j av a2 s. c o m } }); components = new LinkedHashMap<String, ScriptComponent>(); componentsAll = new LinkedHashMap<String, ScriptComponent>(); Map<String, ParamData> types = script.getInputs(); if (types == null) return; List<ScriptComponent> results = new ArrayList<ScriptComponent>(); Entry<String, ParamData> entry; ParamData param; JComponent comp; ScriptComponent c; String name; Class<?> type; Object defValue; Iterator<Entry<String, ParamData>> i = types.entrySet().iterator(); List<Object> values; Number n; String details = ""; String text = ""; String grouping; String parent; Map<String, List<ScriptComponent>> childrenMap = new HashMap<String, List<ScriptComponent>>(); List<ScriptComponent> l; int length; boolean columnsSet; while (i.hasNext()) { text = ""; columnsSet = false; comp = null; entry = i.next(); param = entry.getValue(); name = entry.getKey(); type = param.getPrototype(); values = param.getValues(); defValue = param.getDefaultValue(); if (CollectionUtils.isNotEmpty(values)) { comp = createValuesBox(values, defValue); } if (Long.class.equals(type) || Integer.class.equals(type) || Float.class.equals(type) || Double.class.equals(type)) { if (comp == null) { if (script.isIdentifier(name)) { comp = new NumericalTextField(); ((NumericalTextField) comp).setNumberType(type); ((NumericalTextField) comp).setNegativeAccepted(false); if (CollectionUtils.isNotEmpty(refObjects)) { //support of image type DataObject object = refObjects.get(0); if (script.isSupportedType(object, name)) { defValue = object.getId(); } } } else { comp = new NumericalTextField(); ((NumericalTextField) comp).setNumberType(type); n = param.getMinValue(); if (n != null) { if (Long.class.equals(type)) { text += "Min: " + n.longValue() + " "; ((NumericalTextField) comp).setMinimum(n.longValue()); } else if (Integer.class.equals(type)) { text += "Min: " + n.intValue() + " "; ((NumericalTextField) comp).setMinimum(n.intValue()); } else if (Double.class.equals(type)) { text += "Min: " + n.doubleValue() + " "; ((NumericalTextField) comp).setMinimum(n.doubleValue()); } else if (Float.class.equals(type)) { text += "Min: " + n.floatValue() + " "; ((NumericalTextField) comp).setMinimum(n.floatValue()); } } else { ((NumericalTextField) comp).setNegativeAccepted(true); } n = param.getMaxValue(); if (n != null) { if (Long.class.equals(type)) { text += "Max: " + n.longValue() + " "; ((NumericalTextField) comp).setMaximum(n.longValue()); } else if (Integer.class.equals(type)) { text += "Max: " + n.intValue() + " "; ((NumericalTextField) comp).setMaximum(n.intValue()); } else if (Double.class.equals(type)) { text += "Max: " + n.doubleValue() + " "; ((NumericalTextField) comp).setMaximum(n.doubleValue()); } else if (Float.class.equals(type)) { text += "Max: " + n.floatValue() + " "; ((NumericalTextField) comp).setMaximum(n.floatValue()); } } } if (defValue != null) ((NumericalTextField) comp).setText("" + defValue); } } else if (String.class.equals(type)) { if (comp == null) { comp = new JTextField(); if (defValue != null) { length = defValue.toString().length(); String s = defValue.toString().trim(); ((JTextField) comp).setColumns(length); ((JTextField) comp).setText(s); columnsSet = s.length() > 0; } } } else if (Boolean.class.equals(type)) { if (comp == null) { comp = new JCheckBox(); if (defValue != null) ((JCheckBox) comp).setSelected((Boolean) defValue); } } else if (Map.class.equals(type)) { if (comp == null) comp = new ComplexParamPane(param.getKeyType(), param.getValueType()); else comp = new ComplexParamPane(param.getKeyType(), (JComboBox) comp); } else if (List.class.equals(type)) { if (script.isIdentifier(name)) { identifier = new IdentifierParamPane(Long.class); identifier.setValues(refObjects); identifier.addDocumentListener(this); comp = identifier; } else { if (comp == null) comp = new ComplexParamPane(param.getKeyType()); else comp = new ComplexParamPane((JComboBox) comp); } } if (comp != null) { if (comp instanceof JTextField) { if (!columnsSet) ((JTextField) comp).setColumns(ScriptComponent.COLUMNS); ((JTextField) comp).getDocument().addDocumentListener(this); } if (comp instanceof ComplexParamPane) comp.addPropertyChangeListener(this); comp.setToolTipText(param.getDescription()); c = new ScriptComponent(comp, name); if (text.trim().length() > 0) c.setUnit(text); if (!(comp instanceof JComboBox || comp instanceof JCheckBox)) c.setRequired(!param.isOptional()); if (details != null && details.trim().length() > 0) c.setInfo(details); if (comp instanceof JComboBox && script.isDataType(name)) { dataTypes = (JComboBox) comp; dataTypes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleDataTypeChanges(); } }); } grouping = param.getGrouping(); parent = param.getParent(); c.setParentIndex(parent); if (parent.length() > 0) { l = childrenMap.get(parent); if (l == null) { l = new ArrayList<ScriptComponent>(); childrenMap.put(parent, l); } l.add(c); } if (grouping.length() > 0) { c.setGrouping(grouping); c.setNameLabel(grouping); } else { c.setNameLabel(name); } if (c.hasChildren() || parent.length() == 0) { results.add(c); } componentsAll.put(c.getParameterName(), c); } } ScriptComponent key; Iterator<ScriptComponent> k = results.iterator(); while (k.hasNext()) { key = k.next(); grouping = key.getGrouping(); l = childrenMap.get(grouping); childrenMap.remove(grouping); if (l != null) key.setChildren(sorter.sort(l)); } if (childrenMap != null && childrenMap.size() > 0) { Iterator<String> j = childrenMap.keySet().iterator(); ScriptComponent sc; while (j.hasNext()) { parent = j.next(); sc = new ScriptComponent(); sc.setGrouping(parent); sc.setNameLabel(parent); sc.setChildren(sorter.sort(childrenMap.get(parent))); results.add(sc); } } List<ScriptComponent> sortedKeys = sorter.sort(results); k = sortedKeys.iterator(); while (k.hasNext()) { key = k.next(); components.put(key.getParameterName(), key); } setSelectedDataType(); if (identifier != null) identifier.addPropertyChangeListener(this); canRunScript(); }