protected void attachTo(Component jc) { if (extListener != null && extListener.accept(jc)) { extListener.startListeningTo(jc, extNotifier); listenedTo.add(jc); if (wizardPage.getMapKeyFor(jc) != null) { wizardPage.maybeUpdateMap(jc); } return; } if (isProbablyAContainer(jc)) { attachToHierarchyOf((Container) jc); } else if (jc instanceof JList) { listenedTo.add(jc); ((JList) jc).addListSelectionListener(this); } else if (jc instanceof JComboBox) { ((JComboBox) jc).addActionListener(this); } else if (jc instanceof JTree) { listenedTo.add(jc); ((JTree) jc).getSelectionModel().addTreeSelectionListener(this); } else if (jc instanceof JToggleButton) { ((AbstractButton) jc).addItemListener(this); } else if (jc instanceof JFormattedTextField) { // JFormattedTextField must be tested before JTextCompoent jc.addPropertyChangeListener("value", this); } else if (jc instanceof JTextComponent) { listenedTo.add(jc); ((JTextComponent) jc).getDocument().addDocumentListener(this); } else if (jc instanceof JColorChooser) { listenedTo.add(jc); ((JColorChooser) jc).getSelectionModel().addChangeListener(this); } else if (jc instanceof JSpinner) { ((JSpinner) jc).addChangeListener(this); } else if (jc instanceof JSlider) { ((JSlider) jc).addChangeListener(this); } else if (jc instanceof JTable) { listenedTo.add(jc); ((JTable) jc).getSelectionModel().addListSelectionListener(this); } else { if (logger.isLoggable(Level.FINE)) { logger.fine( "Don't know how to listen to a " + // NOI18N jc.getClass().getName()); } } if (accept(jc) && !(jc instanceof JPanel)) { jc.addPropertyChangeListener("name", this); if (wizardPage.getMapKeyFor(jc) != null) { wizardPage.maybeUpdateMap(jc); } } if (logger.isLoggable(Level.FINE) && accept(jc)) { logger.fine("Begin listening to " + jc); // NOI18N } }
private void createYearAndMonthPanal() { Calendar c = getNowCalendar(); int currentYear = c.get(Calendar.YEAR); int currentMonth = c.get(Calendar.MONTH) + 1; int currentHour = c.get(Calendar.HOUR_OF_DAY); yearSpin = new JSpinner(new javax.swing.SpinnerNumberModel(currentYear, startYear, lastYear, 1)); monthSpin = new JSpinner(new javax.swing.SpinnerNumberModel(currentMonth, 1, 12, 1)); hourSpin = new JSpinner(new javax.swing.SpinnerNumberModel(currentHour, 0, 23, 1)); yearPanel.setLayout(new java.awt.FlowLayout()); yearPanel.setBackground(controlLineColor); yearSpin.setPreferredSize(new Dimension(48, 20)); yearSpin.setName("Year"); yearSpin.setEditor(new JSpinner.NumberEditor(yearSpin, "####")); yearSpin.addChangeListener(this); yearPanel.add(yearSpin); JLabel yearLabel = new JLabel("年"); yearLabel.setForeground(controlTextColor); yearPanel.add(yearLabel); monthSpin.setPreferredSize(new Dimension(35, 20)); monthSpin.setName("Month"); monthSpin.addChangeListener(this); yearPanel.add(monthSpin); JLabel monthLabel = new JLabel("月"); monthLabel.setForeground(controlTextColor); yearPanel.add(monthLabel); hourSpin.setPreferredSize(new Dimension(35, 20)); hourSpin.setName("Hour"); hourSpin.addChangeListener(this); yearPanel.add(hourSpin); JLabel hourLabel = new JLabel("日"); hourLabel.setForeground(controlTextColor); yearPanel.add(hourLabel); }
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(); } }); }
private JPanel makeInteriorAttributesPanel() { JPanel outerPanel = new JPanel(new BorderLayout(6, 6)); outerPanel.setBorder(this.createTitleBorder("Surface Attributes")); GridLayout nameLayout = new GridLayout(0, 1, 6, 6); JPanel namePanel = new JPanel(nameLayout); GridLayout valueLayout = new GridLayout(0, 1, 6, 6); JPanel valuePanel = new JPanel(valueLayout); namePanel.add(new JLabel("Style")); final JComboBox cb1 = new JComboBox(new String[] {"None", "Solid"}); cb1.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { currentInteriorStyle = (String) cb1.getSelectedItem(); update(); } }); cb1.setSelectedItem("Solid"); valuePanel.add(cb1); namePanel.add(new JLabel("Opacity")); JSpinner sp = new JSpinner(new SpinnerNumberModel(this.currentBorderOpacity, 0, 10, 1)); sp.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { currentInteriorOpacity = (Integer) ((JSpinner) changeEvent.getSource()).getValue(); update(); } }); valuePanel.add(sp); namePanel.add(new JLabel("Color")); final JComboBox cb2 = new JComboBox(new String[] {"Red", "Green", "Blue", "Yellow"}); cb2.setSelectedItem(currentInteriorColor); cb2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { currentInteriorColor = (String) ((JComboBox) actionEvent.getSource()).getSelectedItem(); update(); } }); valuePanel.add(cb2); namePanel.add(new JLabel("Border")); final JComboBox cb5 = new JComboBox(new String[] {"None", "Solid"}); cb5.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { currentBorderStyle = (String) cb5.getSelectedItem(); update(); } }); cb5.setSelectedItem("Solid"); valuePanel.add(cb5); namePanel.add(new JLabel("Border Width")); sp = new JSpinner(new SpinnerNumberModel(this.currentBorderWidth, 1d, 10d, 1d)); sp.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { currentBorderWidth = (Double) ((JSpinner) changeEvent.getSource()).getValue(); update(); } }); sp.setValue(currentBorderWidth); valuePanel.add(sp); namePanel.add(new JLabel("Border Color")); JComboBox cb4 = new JComboBox(new String[] {"Red", "Green", "Blue", "Yellow"}); cb4.setSelectedItem(currentBorderColor); cb4.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { currentBorderColor = (String) ((JComboBox) actionEvent.getSource()).getSelectedItem(); update(); } }); valuePanel.add(cb4); namePanel.add(new JLabel("Border Opacity")); sp = new JSpinner(new SpinnerNumberModel(this.currentBorderOpacity, 0, 10, 1)); sp.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { currentBorderOpacity = (Integer) ((JSpinner) changeEvent.getSource()).getValue(); update(); } }); valuePanel.add(sp); outerPanel.add(namePanel, BorderLayout.WEST); outerPanel.add(valuePanel, BorderLayout.CENTER); return outerPanel; }
private JPanel makePathAttributesPanel() { JPanel outerPanel = new JPanel(new BorderLayout(6, 6)); outerPanel.setBorder(this.createTitleBorder("Path Attributes")); GridLayout nameLayout = new GridLayout(0, 1, 6, 6); JPanel namePanel = new JPanel(nameLayout); GridLayout valueLayout = new GridLayout(0, 1, 6, 6); JPanel valuePanel = new JPanel(valueLayout); namePanel.add(new JLabel("Follow Terrain")); JCheckBox ckb = new JCheckBox(); ckb.setSelected(currentFollowTerrain); ckb.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { currentFollowTerrain = ((JCheckBox) actionEvent.getSource()).isSelected(); update(); } }); valuePanel.add(ckb); JLabel label; namePanel.add(label = new JLabel("Conformance")); int[] values = new int[] {1, 2, 4, 8, 10, 15, 20, 30, 40, 50}; String[] strings = new String[values.length]; for (int i = 0; i < values.length; i++) { strings[i] = Integer.toString(values[i]) + " pixels"; } JSpinner sp = new JSpinner(new SpinnerListModel(strings)); onTerrainOnlyItems.add(label); onTerrainOnlyItems.add(sp); sp.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { String v = (String) ((JSpinner) changeEvent.getSource()).getValue(); currentTerrainConformance = Integer.parseInt(v.substring(0, v.indexOf(" "))); update(); } }); sp.setValue(Integer.toString(currentTerrainConformance) + " pixels"); valuePanel.add(sp); namePanel.add(label = new JLabel("Subsegments")); sp = new JSpinner(new SpinnerListModel(new String[] {"1", "2", "5", "10", "20", "40", "50"})); offTerrainOnlyItems.add(label); offTerrainOnlyItems.add(sp); sp.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { String v = (String) ((JSpinner) changeEvent.getSource()).getValue(); currentNumSubsegments = Integer.parseInt(v); update(); } }); sp.setValue(Integer.toString(currentNumSubsegments)); valuePanel.add(sp); namePanel.add(new JLabel("Type")); final JComboBox cb = new JComboBox(new String[] {"Great Circle", "Linear", "Rhumb Line"}); cb.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { currentPathType = (String) cb.getSelectedItem(); update(); } }); cb.setSelectedItem("Great Circle"); valuePanel.add(cb); namePanel.add(new JLabel("Style")); final JComboBox cb1 = new JComboBox(new String[] {"None", "Solid", "Dash"}); cb1.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { currentPathStyle = (String) cb1.getSelectedItem(); update(); } }); cb1.setSelectedItem("Solid"); valuePanel.add(cb1); namePanel.add(new JLabel("Width")); sp = new JSpinner(new SpinnerNumberModel(this.currentPathWidth, 1d, 10d, 1d)); sp.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { currentPathWidth = (Double) ((JSpinner) changeEvent.getSource()).getValue(); update(); } }); sp.setValue(currentPathWidth); valuePanel.add(sp); namePanel.add(new JLabel("Color")); JComboBox cb2 = new JComboBox(new String[] {"Red", "Green", "Blue", "Yellow"}); cb2.setSelectedItem(currentPathColor); cb2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { currentPathColor = (String) ((JComboBox) actionEvent.getSource()).getSelectedItem(); update(); } }); valuePanel.add(cb2); namePanel.add(new JLabel("Opacity")); sp = new JSpinner(new SpinnerNumberModel(this.currentPathOpacity, 0, 10, 1)); sp.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { currentPathOpacity = (Integer) ((JSpinner) changeEvent.getSource()).getValue(); update(); } }); valuePanel.add(sp); namePanel.add(new JLabel("Offset")); sp = new JSpinner( new SpinnerListModel( new String[] {"0", "10", "100", "1000", "10000", "100000", "1000000"})); sp.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { currentOffset = Float.parseFloat((String) ((JSpinner) changeEvent.getSource()).getValue()); update(); } }); sp.setValue("0"); valuePanel.add(sp); outerPanel.add(namePanel, BorderLayout.WEST); outerPanel.add(valuePanel, BorderLayout.CENTER); return outerPanel; }
/** * Creates the video advanced settings. * * @return video advanced settings panel. */ private static Component createVideoAdvancedSettings() { ResourceManagementService resources = NeomediaActivator.getResources(); final DeviceConfiguration deviceConfig = mediaService.getDeviceConfiguration(); TransparentPanel centerPanel = new TransparentPanel(new GridBagLayout()); centerPanel.setMaximumSize(new Dimension(WIDTH, 150)); JButton resetDefaultsButton = new JButton(resources.getI18NString("impl.media.configform.VIDEO_RESET")); JPanel resetButtonPanel = new TransparentPanel(new FlowLayout(FlowLayout.RIGHT)); resetButtonPanel.add(resetDefaultsButton); final JPanel centerAdvancedPanel = new TransparentPanel(new BorderLayout()); centerAdvancedPanel.add(centerPanel, BorderLayout.NORTH); centerAdvancedPanel.add(resetButtonPanel, BorderLayout.SOUTH); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.anchor = GridBagConstraints.NORTHWEST; constraints.insets = new Insets(5, 5, 0, 0); constraints.gridx = 0; constraints.weightx = 0; constraints.weighty = 0; constraints.gridy = 0; centerPanel.add( new JLabel(resources.getI18NString("impl.media.configform.VIDEO_RESOLUTION")), constraints); constraints.gridy = 1; constraints.insets = new Insets(0, 0, 0, 0); final JCheckBox frameRateCheck = new SIPCommCheckBox(resources.getI18NString("impl.media.configform.VIDEO_FRAME_RATE")); centerPanel.add(frameRateCheck, constraints); constraints.gridy = 2; constraints.insets = new Insets(5, 5, 0, 0); centerPanel.add( new JLabel(resources.getI18NString("impl.media.configform.VIDEO_PACKETS_POLICY")), constraints); constraints.weightx = 1; constraints.gridx = 1; constraints.gridy = 0; constraints.insets = new Insets(5, 0, 0, 5); Object[] resolutionValues = new Object[DeviceConfiguration.SUPPORTED_RESOLUTIONS.length + 1]; System.arraycopy( DeviceConfiguration.SUPPORTED_RESOLUTIONS, 0, resolutionValues, 1, DeviceConfiguration.SUPPORTED_RESOLUTIONS.length); final JComboBox sizeCombo = new JComboBox(resolutionValues); sizeCombo.setRenderer(new ResolutionCellRenderer()); sizeCombo.setEditable(false); centerPanel.add(sizeCombo, constraints); // default value is 20 final JSpinner frameRate = new JSpinner(new SpinnerNumberModel(20, 5, 30, 1)); frameRate.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { deviceConfig.setFrameRate( ((SpinnerNumberModel) frameRate.getModel()).getNumber().intValue()); } }); constraints.gridy = 1; constraints.insets = new Insets(0, 0, 0, 5); centerPanel.add(frameRate, constraints); frameRateCheck.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (frameRateCheck.isSelected()) { deviceConfig.setFrameRate( ((SpinnerNumberModel) frameRate.getModel()).getNumber().intValue()); } else // unlimited framerate deviceConfig.setFrameRate(-1); frameRate.setEnabled(frameRateCheck.isSelected()); } }); final JSpinner videoMaxBandwidth = new JSpinner( new SpinnerNumberModel(deviceConfig.getVideoMaxBandwidth(), 1, Integer.MAX_VALUE, 1)); videoMaxBandwidth.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { deviceConfig.setVideoMaxBandwidth( ((SpinnerNumberModel) videoMaxBandwidth.getModel()).getNumber().intValue()); } }); constraints.gridx = 1; constraints.gridy = 2; constraints.insets = new Insets(0, 0, 5, 5); centerPanel.add(videoMaxBandwidth, constraints); resetDefaultsButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // reset to defaults sizeCombo.setSelectedIndex(0); frameRateCheck.setSelected(false); frameRate.setEnabled(false); frameRate.setValue(20); // unlimited framerate deviceConfig.setFrameRate(-1); videoMaxBandwidth.setValue(DeviceConfiguration.DEFAULT_VIDEO_MAX_BANDWIDTH); } }); // load selected value or auto Dimension videoSize = deviceConfig.getVideoSize(); if ((videoSize.getHeight() != DeviceConfiguration.DEFAULT_VIDEO_HEIGHT) && (videoSize.getWidth() != DeviceConfiguration.DEFAULT_VIDEO_WIDTH)) sizeCombo.setSelectedItem(deviceConfig.getVideoSize()); else sizeCombo.setSelectedIndex(0); sizeCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Dimension selectedVideoSize = (Dimension) sizeCombo.getSelectedItem(); if (selectedVideoSize == null) { // the auto value, default one selectedVideoSize = new Dimension( DeviceConfiguration.DEFAULT_VIDEO_WIDTH, DeviceConfiguration.DEFAULT_VIDEO_HEIGHT); } deviceConfig.setVideoSize(selectedVideoSize); } }); frameRateCheck.setSelected( deviceConfig.getFrameRate() != DeviceConfiguration.DEFAULT_VIDEO_FRAMERATE); frameRate.setEnabled(frameRateCheck.isSelected()); if (frameRate.isEnabled()) frameRate.setValue(deviceConfig.getFrameRate()); return centerAdvancedPanel; }
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); } }); }
InputFrame() { JPanel pane = new JPanel(); pane.setLayout(null); pane.setBackground(Color.LIGHT_GRAY); add(pane); // JTextField文字欄位元件 lblName = new JLabel("姓名:"); lblName.setBounds(10, 10, 40, 20); pane.add(lblName); text0.setBounds(50, 10, 80, 20); text0.addActionListener(textfield); pane.add(text0); // JSpinner數位序列元件 lblAge = new JLabel("年齡:"); lblAge.setBounds(170, 10, 40, 20); pane.add(lblAge); JSpinner spin = new JSpinner(new SpinnerNumberModel(20, 1, 100, 1)); spin.setBounds(210, 10, 80, 20); spin.addChangeListener(spinner); pane.add(spin); // JRadioButton選項圓鈕元件 lblSex = new JLabel("性別:"); lblSex.setBounds(10, 40, 40, 20); pane.add(lblSex); ButtonGroup group = new ButtonGroup(); JRadioButton rb1 = new JRadioButton("帥哥", false); rb1.setBounds(50, 40, 60, 20); JRadioButton rb2 = new JRadioButton("美女", false); rb2.setBounds(110, 40, 60, 20); rb1.setOpaque(false); rb2.setOpaque(false); // 秀出底色 rb1.addActionListener(radio); rb2.addActionListener(radio); group.add(rb1); group.add(rb2); pane.add(rb1); pane.add(rb2); // JCheckBox核對方塊元件 lblInter = new JLabel("興趣:"); lblInter.setBounds(10, 70, 50, 20); pane.add(lblInter); for (int i = 0; i < check.length; i++) { check[i] = new JCheckBox(checkItem[i]); check[i].setBounds(50 + 60 * i, 70, 60, 20); check[i].setOpaque(false); check[i].addActionListener(checkbox); pane.add(check[i]); } // JComboBox下拉式清單元件 lblAcad = new JLabel("學歷:"); lblAcad.setBounds(10, 100, 50, 20); pane.add(lblAcad); String[] items_c = {"博士", "碩士", "大學", "高中", "國中", "國小"}; JComboBox c_box = new JComboBox(items_c); c_box.setBounds(50, 100, 100, 20); c_box.addItemListener(cbo); pane.add(c_box); // JList清單元件 lblPlace = new JLabel("居住地區:"); lblPlace.setBounds(170, 100, 70, 20); pane.add(lblPlace); String[] items_p = { "台北", "桃園", "新竹", "苗栗", "台中", "彰化", "雲林", "嘉義", "台南", "高雄", "屏東", "花蓮", "台東", "澎湖" }; JList list = new JList(items_p); list.setVisibleRowCount(4); list.addListSelectionListener(list_p); JScrollPane scroll = new JScrollPane(list); scroll.setBounds(240, 100, 80, 80); pane.add(scroll); // JTextArea文字區域元件 texta.setBounds(10, 190, 330, 40); texta.setEditable(false); pane.add(texta); setTitle("輸入元件綜合應用"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(50, 50, 360, 280); setVisible(true); }
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); }
public ParameterConfigurationPanel(String name, SensorType type) { this.type = type; this.name = name; setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(new Label(name)); typeList = new JComboBox(controlTypes); typeList.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { setType((String) typeList.getSelectedItem()); configure(); } }); add(typeList); add(new Label("channel")); channel = new JSpinner(new SpinnerNumberModel(1, 1, 16, 1)); channel.setValue(1); channel.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { configure(); } }); add(channel); add(new Label("cc")); cc = new JSpinner(new SpinnerNumberModel(21, 1, 127, 1)); cc.setValue(21); cc.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { configure(); } }); add(cc); add(new Label("min")); min = new JSpinner(); min.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { configure(); } }); add(min); add(new Label("max")); max = new JSpinner(); max.setValue(127); max.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { configure(); } }); add(max); JButton button = new JButton("invert"); button.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { int saved = (Integer) min.getValue(); min.setValue(max.getValue()); max.setValue(saved); } }); add(button); modeList = new JComboBox(eventhandler.getModeNames()); modeList.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { configure(); } }); add(modeList); }
public NotePlayerConfigurationPanel() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JPanel panel = new JPanel(new MigLayout()); add(panel); play = new JCheckBox("Play notes", true); play.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { doPlay = !doPlay; if (doPlay) { pb.setEnabled(true); at.setEnabled(true); } else { pb.setEnabled(false); at.setEnabled(false); } configure(); } }); panel.add(play, "wrap"); pb = new JCheckBox("Pitch Bend", false); pb.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { doPb = !doPb; configure(); } }); panel.add(pb, "wrap"); at = new JCheckBox("Aftertouch", false); at.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { doAt = !doAt; configure(); } }); panel.add(at, "wrap"); panel = new JPanel(new MigLayout()); add(panel); panel.add(new Label("Follow Mode"), "label"); JComboBox box = new JComboBox(sender.getFollowModes()); box.setSelectedItem(eventhandler.getConfigurationMode(getOperationMode()).getFollowMode()); box.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { JComboBox box = (JComboBox) e.getSource(); String name = (String) box.getSelectedItem(); eventhandler.getConfigurationMode(getOperationMode()).setFollowMode(name); sender.setFollowMode(name); } }); panel.add(box, "wrap"); panel.add(new Label("Scale"), "label"); scale = new JComboBox(eventhandler.getScaleMapper().getScaleNames()); scale.setSelectedItem(eventhandler.getCurrentScale()); scale.addActionListener( new AbstractAction() { public void actionPerformed(ActionEvent e) { String scalename = (String) scale.getSelectedItem(); eventhandler.getScaleMapper(getOperationMode()).setScale(scalename); } }); panel.add(scale, "wrap"); panel.add(new Label("Basenote"), "label"); basenote = new JSpinner(new SpinnerNumberModel(1, 1, 127, 1)); basenote.setValue(eventhandler.getBaseNote()); basenote.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { Integer value = (Integer) basenote.getValue(); eventhandler.setBaseNote(getOperationMode(), value); } }); panel.add(basenote, "wrap"); }