private void addListener(final JComponent component) { if (component instanceof JComboBox) { ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { JComboBox comboBox = (JComboBox) component; final Object selectedItem = comboBox.getSelectedItem(); _dotDefinitionDialogFrame .getScratchDisplayObjectType() .setValueOfStaticProperty(_primitiveForm.getName(), _property, selectedItem); } }; JComboBox comboBox = (JComboBox) component; comboBox.addItemListener(itemListener); } else if (component instanceof JSpinner) { javax.swing.event.ChangeListener changeListener = new javax.swing.event.ChangeListener() { public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) component; final Object value = spinner.getValue(); _dotDefinitionDialogFrame .getScratchDisplayObjectType() .setValueOfStaticProperty(_primitiveForm.getName(), _property, value); } }; JSpinner spinner = (JSpinner) component; spinner.addChangeListener(changeListener); } }
public SpinnerModelEditorDemo() { // Group labels JPanel panel1 = new JPanel(); panel1.setLayout(new GridLayout(4, 1)); panel1.add(new JLabel("Date")); panel1.add(new JLabel("Day")); panel1.add(new JLabel("Month")); panel1.add(new JLabel("Year")); // Group spinners JPanel panel2 = new JPanel(); panel2.setLayout(new GridLayout(4, 1)); panel2.add(jspDate); panel2.add(jspDay); panel2.add(jspMonth); panel2.add(spinnerYear); // Add spinner and label to the UI add(panel1, BorderLayout.WEST); add(panel2, BorderLayout.CENTER); // Set editor for date JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(jspDate, "MMM dd, yyyy"); jspDate.setEditor(dateEditor); // Set editor for year JSpinner.NumberEditor yearEditor = new JSpinner.NumberEditor(spinnerYear, "####"); spinnerYear.setEditor(yearEditor); // Update date to synchronize with the day, month, and year updateDate(); // Register and create a listener for jspDay jspDay.addChangeListener( new ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent e) { updateDate(); } }); // Register and create a listener for jspMonth jspMonth.addChangeListener( new ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent e) { updateDate(); } }); // Register and create a listener for spinnerYear spinnerYear.addChangeListener( new ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent e) { updateDate(); } }); }
private void addChangeListeners() { ChangeListener translationChangeListener = new ChangeListener() { public void stateChanged(ChangeEvent e) { _dotDefinitionDialogFrame.setSomethingChanged(true); } }; _translationFactorSpinner.addChangeListener(translationChangeListener); ChangeListener joinByLineChangeListener = new ChangeListener() { public void stateChanged(ChangeEvent e) { _dotDefinitionDialogFrame.setSomethingChanged(true); } }; _joinByLineCheckBox.addChangeListener(joinByLineChangeListener); }
private void addEventListener() { btn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); String date = lastLabel.getText(); String str2 = month + 1 + ""; String str3 = date; if (month + 1 < 10) { str2 = "0" + (month + 1); } if (Integer.valueOf(date) < 10) { str3 = "0" + date; } text.setText(year + "-" + str2 + "-" + str3); MySimpleCal.this.dispose(); } }); monthBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { resetPanel(); } }); yearSpi.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { resetPanel(); } }); }
public Component getCustomOptionComponent() { /* DEPTH */ final JSpinner jspnMaxDepth = new JSpinner(new SpinnerNumberModel(s_maxDepth + 1, 1, 100, 1)); jspnMaxDepth.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { Integer value = (Integer) ((JSpinner) e.getSource()).getValue(); s_maxDepth = value - 1; logger.debug("maxDepth " + (s_maxDepth + 1)); } }); final JRadioButton jrbMaxDepth = new JRadioButton("Depth"); final JLabel lblMaxDepth = new JLabel("Depth: "); final JPanel jpMaxDepthSub = new JPanel() { @Override public void setEnabled(boolean b) { super.setEnabled(b); jspnMaxDepth.setEnabled(b); lblMaxDepth.setEnabled(b); } }; jpMaxDepthSub.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); jpMaxDepthSub.add(lblMaxDepth); jpMaxDepthSub.add(jspnMaxDepth); /// final JPanel jpMaxDepth = new JPanel() { @Override public void setEnabled(boolean b) { super.setEnabled(b); jrbMaxDepth.setEnabled(b); jpMaxDepthSub.setEnabled(b); } }; jpMaxDepth.setLayout(new BoxLayout(jpMaxDepth, BoxLayout.Y_AXIS)); jpMaxDepth.add(GuiUtil.addComponentAsFlow(jrbMaxDepth, FlowLayout.LEFT)); jpMaxDepth.add(GuiUtil.addComponentAsFlow(jpMaxDepthSub, FlowLayout.RIGHT)); /* REPETITION */ final JSpinner jspnMaxRept = new JSpinner(new SpinnerNumberModel(s_maxRept, 1, 100, 1)); jspnMaxRept.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { s_maxRept = (Integer) ((JSpinner) e.getSource()).getValue(); logger.debug("maxRept " + s_maxRept); } }); final JRadioButton jrbMaxRept = new JRadioButton("Repetition"); final JLabel lblMaxRept = new JLabel("Count: "); final JPanel jpMaxReptSub = new JPanel() { @Override public void setEnabled(boolean b) { super.setEnabled(b); jspnMaxRept.setEnabled(b); lblMaxRept.setEnabled(b); } }; jpMaxReptSub.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); jpMaxReptSub.add(lblMaxRept); jpMaxReptSub.add(jspnMaxRept); final JPanel jpMaxRept = new JPanel() { @Override public void setEnabled(boolean b) { super.setEnabled(b); jrbMaxRept.setEnabled(b); jpMaxReptSub.setEnabled(b); } }; jpMaxRept.setLayout(new BoxLayout(jpMaxRept, BoxLayout.Y_AXIS)); jpMaxRept.add(GuiUtil.addComponentAsFlow(jrbMaxRept, FlowLayout.LEFT)); jpMaxRept.add(GuiUtil.addComponentAsFlow(jpMaxReptSub, FlowLayout.RIGHT)); /////////////////////////////////////// final JLabel lbl = new JLabel("Limit search by:", SwingConstants.LEFT); final JPanel panel = new JPanel() { @Override public void setEnabled(boolean b) { super.setEnabled(b); lbl.setEnabled(b); jpMaxDepth.setEnabled(b); jpMaxRept.setEnabled(b); } @Override public void setVisible(boolean b) { super.setVisible(b); final JPanel p = this; // SwingUtilities.invokeLater( new Runnable() { // public void run() { Window win = SwingUtilities.getWindowAncestor(p); System.err.println(win); if (win != null) { System.err.println("packing"); win.pack(); } // } // } ); } }; panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); panel.add(GuiUtil.addComponentAsFlow(lbl, FlowLayout.LEFT)); panel.add(jpMaxDepth); panel.add(jpMaxRept); ButtonGroup bg = new ButtonGroup(); bg.add(jrbMaxDepth); bg.add(jrbMaxRept); /* CHECKBOX */ final JCheckBox chboxRepeat = new JCheckBox("Allow subtask recursive repetition", s_isSubtaskRepetitionAllowed); chboxRepeat.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { if (s_isSubtaskRepetitionAllowed == chboxRepeat.isSelected()) return; s_isSubtaskRepetitionAllowed = chboxRepeat.isSelected(); panel.setVisible(s_isSubtaskRepetitionAllowed); logger.debug("m_isSubtaskRepetitionAllowed " + s_isSubtaskRepetitionAllowed); } }); panel.setVisible(s_isSubtaskRepetitionAllowed); final JCheckBox chboxIncremental = new JCheckBox("Incremental", s_isIncremental); chboxIncremental.setToolTipText("Incremental depth-first search"); chboxIncremental.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { if (s_isIncremental == chboxIncremental.isSelected()) return; s_isIncremental = chboxIncremental.isSelected(); logger.debug("isIncremental " + s_isIncremental); } }); final JCheckBox chboxOptimize = new JCheckBox("Disable optimization in subtasks", s_disableOptimizationInSubtasks); chboxOptimize.setToolTipText("Use for debugging purposes"); chboxOptimize.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { if (s_disableOptimizationInSubtasks == chboxOptimize.isSelected()) return; s_disableOptimizationInSubtasks = chboxOptimize.isSelected(); logger.debug("disableOptimizationInSubtasks " + s_disableOptimizationInSubtasks); } }); JPanel container1 = new JPanel(); container1.setLayout(new BoxLayout(container1, BoxLayout.Y_AXIS)); container1.setBorder(BorderFactory.createTitledBorder("Planning settings")); container1.add(GuiUtil.addComponentAsFlow(chboxOptimize, FlowLayout.LEFT)); container1.add(GuiUtil.addComponentAsFlow(chboxIncremental, FlowLayout.LEFT)); container1.add(GuiUtil.addComponentAsFlow(chboxRepeat, FlowLayout.LEFT)); container1.add(GuiUtil.addComponentAsFlow(panel, FlowLayout.LEFT)); JPanel container2 = new JPanel(new GridLayout(2, 0)); container2.setBorder(BorderFactory.createTitledBorder("Logging options")); final JCheckBox linear = new JCheckBox("Detailed linear planning", isLinearLoggingOn()); linear.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { setLinearLoggingOn(linear.isSelected()); } }); container2.add(linear); final JCheckBox subtask = new JCheckBox("Detailed subtask planning", isSubtaskLoggingOn()); subtask.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { setSubtaskLoggingOn(subtask.isSelected()); } }); container2.add(subtask); JPanel main = new JPanel(); main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); main.add(container1); main.add(container2); return main; }
FieldEditorHelper(FieldEditor fieldEditor) { this.fieldEditor = fieldEditor; fieldNameField = fieldEditor.getFieldNameField(); fieldNameField.getDocument().addDocumentListener(new FieldNameChangeListener()); dataTypeCombo = fieldEditor.getDataTypeCombo(); dataTypeCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dataTypeComboAction(e); } }); calcTypeCombo = fieldEditor.getCalcTypeCombo(); calcTypeCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { calcTypeComboAction(e); } }); lookupViewCombo = fieldEditor.getLookupViewCombo(); lookupViewCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { lookupViewComboAction(e); } }); lookupFieldCombo = fieldEditor.getLookupFieldCombo(); lookupFieldCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { lookupFieldComboAction(e); } }); objRelationshipCombo = fieldEditor.getObjRelationshipCombo(); objRelationshipCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { objRelationshipComboAction(e); } }); objAttributeCombo = fieldEditor.getObjAttributeCombo(); objAttributeCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { objAttributeComboAction(e); } }); defaultValueField = fieldEditor.getDefaultValueField(); defaultValueField.getDocument().addDocumentListener(new DefaultValueChangeListener()); captionField = fieldEditor.getCaptionField(); captionField.getDocument().addDocumentListener(new CaptionChangeListener()); editableCheckBox = fieldEditor.getEditableCheckBox(); editableCheckBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { editableCheckBoxAction(e); } }); visibleCheckBox = fieldEditor.getVisibleCheckBox(); visibleCheckBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { visibleCheckBoxAction(e); } }); displayClassField = fieldEditor.getDisplayClassField(); displayClassField.getDocument().addDocumentListener(new DisplayClassChangeListener()); displayPatternField = fieldEditor.getDisplayPatternField(); displayPatternField.getDocument().addDocumentListener(new DisplayPatternChangeListener()); editClassField = fieldEditor.getEditClassField(); editClassField.getDocument().addDocumentListener(new EditClassChangeListener()); editPatternField = fieldEditor.getEditPatternField(); editPatternField.getDocument().addDocumentListener(new EditPatternChangeListener()); preferredIndexField = fieldEditor.getPreferredIndexField(); preferredIndexField.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { preferredIndexFieldChanged(e); } }); }
public FloorEditorWindow() { previewModeBox.addActionListener( new ActionListener() { /** Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { previewBox.setMode( FloorPreviewPanel.FloorPreviewMode.values()[previewModeBox.getSelectedIndex()]); loadFloor(); } }); final ChangeListener cl = new ChangeListener() { public void stateChanged(ChangeEvent e) { if (currentFloor == null || isLoading) return; isDirty = true; currentFloor.occlude = blendingCheckbox.isSelected(); switch (previewBox.getMode()) { case RT3_GAME: currentFloor.colour2 = gameColour.getColour(); currentFloor.rgb2hls(currentFloor.colour2, true); currentFloor.texture = (Integer) gameTexture.getValue(); currentFloor.name = gameName.getText(); break; case RT3_MAP: currentFloor.minimapColour = gameColour.getColour(); currentFloor.rgb2hls(currentFloor.minimapColour, false); break; case RT4P_OVERLAY: currentFloor.hdColour = gameColour.getColour(); int hslColour = currentFloor.hslColour; currentFloor.rgb2hls(currentFloor.hdColour, false); currentFloor.hdOlHslColour = hslColour; currentFloor.hslColour = hslColour; currentFloor.hdTexture = (Integer) gameTexture.getValue(); // currentFloor.name = gameName.getText(); break; case RT4P_UNDERLAY: currentFloor.hdUlColour = gameColour.getColour(); hslColour = currentFloor.hslColour; currentFloor.rgb2hls(currentFloor.hdUlColour, false); currentFloor.hdHslColour = hslColour; currentFloor.hslColour = hslColour; currentFloor.hdUlTexture = (Integer) gameTexture.getValue(); // currentFloor.name = gameName.getText(); break; } previewBox.repaint(); } }; gameColour.addChangeListener(cl); gameTexture.addChangeListener(cl); blendingCheckbox.addChangeListener(cl); gameName.addFocusListener( new FocusListener() { String text = ""; public void focusGained(FocusEvent e) { text = gameName.getText(); } public void focusLost(FocusEvent e) { if (!gameName.getText().equals(text)) cl.stateChanged(null); } }); resetButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if ((!isDirty) || JOptionPane.showConfirmDialog( mainPane, "Are you sure you want to revert all changes to this floor?", "RuneScape Map Editor", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) currentFloor = loadedFloor.cloneFLO(); } }); saveButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { isDirty = false; loadedFloor.replace(currentFloor); Floor.cache[loadedFloor.id] = loadedFloor; for (ChangeListener l : listenerList) l.stateChanged(null); } }); saveAsNewButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { isDirty = false; int i = Floor.addNew(currentFloor); currentFloor.id = i; loadedFloor = Floor.cache[i]; for (ChangeListener l : listenerList) l.stateChanged(null); } }); }
public NumberField(NumberOption option) { super(option); panel = new JPanel(new GridBagLayout()); this.step = option.getStep(); Double min = option.getMin(); Double max = option.getMax(); Double defl = new Double(option.getDefault()); // Normalize parameters if (min != null && defl.compareTo(min) < 0) { defl = min; } else if (max != null && defl.compareTo(max) > 0) { defl = max; } if (min != null) { sliderMin = (int) (min.doubleValue() / step); } else { sliderMin = SLIDER_DEFAULT_MIN; } if (max != null) { sliderMax = (int) (max.doubleValue() / step); } else { sliderMax = SLIDER_DEFAULT_MAX; } // Create spinner SpinnerNumberModel spinnerModel = new SpinnerNumberModel(defl, min, max, new Double(step)); spinner = new JSpinner(spinnerModel); ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setColumns(FIELD_WIDTH); // Create slider slider = new JSlider(sliderMin, sliderMax, sliderIndex(defl)); slider.setPaintLabels(false); slider.setPaintTicks(false); slider.setSnapToTicks(false); // Add listeners. The spinner is the master and the slider is // the slave. spinner.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int newIndex = sliderIndex((Double) spinner.getValue()); if (slider.getValue() != newIndex) { slider.setValue(newIndex); } fireChangeEvent(); } }); slider.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int newIndex = slider.getValue(); if (newIndex != sliderIndex((Double) spinner.getValue())) { spinner.setValue(new Double(newIndex * step)); } } }); // Create enable checkbox configureEnableToggle( option.isInitiallyEnabled(), string(option.getDisabledValue()), Arrays.asList((JComponent) spinner, slider)); // Add to the panel panel.add(spinner); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(0, 8, 0, 0); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; panel.add(slider, c); }