📄 spinnernumbermodeleditor.java
字号:
/* * SpinnerListModelEditor.java * * Created on 2007年9月1日, 上午11:58 */package dyno.swing.designer.properties.editors;import dyno.swing.designer.properties.editors.accessibles.AccessibleEditor;import dyno.swing.designer.properties.ValidationException;import java.awt.Component;import javax.swing.SpinnerNumberModel;import javax.swing.event.ChangeListener;/** * * @author William Chen */public class SpinnerNumberModelEditor extends javax.swing.JPanel implements AccessibleEditor { /** Creates new form SpinnerListModelEditor */ public SpinnerNumberModelEditor() { initComponents(); spStepSize.setValue(1); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); cmbTypes = new javax.swing.JComboBox(); jLabel2 = new javax.swing.JLabel(); spInitValue = new javax.swing.JSpinner(); cbMin = new javax.swing.JCheckBox(); cbMax = new javax.swing.JCheckBox(); spMin = new javax.swing.JSpinner(); spMax = new javax.swing.JSpinner(); jLabel3 = new javax.swing.JLabel(); spStepSize = new javax.swing.JSpinner(); setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Spinner Number Model", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 12), java.awt.Color.black)); jLabel1.setText("Number Type:"); cmbTypes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "byte", "short", "integer", "long", "float", "double" })); cmbTypes.setSelectedIndex(2); jLabel2.setText("Initial Value:"); spInitValue.setPreferredSize(new java.awt.Dimension(29, 24)); cbMin.setText("Minimum:"); cbMin.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbMinActionPerformed(evt); } }); cbMax.setText("Maximum:"); cbMax.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbMaxActionPerformed(evt); } }); spMin.setEnabled(false); spMin.setPreferredSize(new java.awt.Dimension(29, 24)); spMax.setEnabled(false); spMax.setPreferredSize(new java.awt.Dimension(29, 24)); jLabel3.setText("Step Size:"); spStepSize.setPreferredSize(new java.awt.Dimension(29, 24)); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(cbMax) .addComponent(jLabel1) .addComponent(jLabel2) .addComponent(cbMin) .addComponent(jLabel3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(spStepSize, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(spMax, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(spMin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cmbTypes, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(spInitValue, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(cmbTypes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(spInitValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cbMin) .addComponent(spMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cbMax) .addComponent(spMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addComponent(spStepSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents private void cbMinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbMinActionPerformed spMin.setEnabled(cbMin.isSelected()); }//GEN-LAST:event_cbMinActionPerformed private void cbMaxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbMaxActionPerformed spMax.setEnabled(cbMax.isSelected()); }//GEN-LAST:event_cbMaxActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox cbMax; private javax.swing.JCheckBox cbMin; private javax.swing.JComboBox cmbTypes; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JSpinner spInitValue; private javax.swing.JSpinner spMax; private javax.swing.JSpinner spMin; private javax.swing.JSpinner spStepSize; // End of variables declaration//GEN-END:variables public void validateValue() throws ValidationException { } public Object getValue() { String number_type=(String)cmbTypes.getSelectedItem(); Number init_value=(Number)spInitValue.getValue(); boolean hasMin=cbMin.isSelected(); Number minimum=(Number)spMin.getValue(); boolean hasMax=cbMax.isSelected(); Number maximum=(Number)spMax.getValue(); Number step_size=(Number)spStepSize.getValue(); SpinnerNumberModel model; if(number_type.equals("byte")){ model=new SpinnerNumberModel( new Byte(init_value.byteValue()), hasMin?new Byte(minimum.byteValue()):null, hasMax?new Byte(maximum.byteValue()):null, new Byte(step_size.byteValue()) ); }else if(number_type.equals("short")){ model=new SpinnerNumberModel( new Short(init_value.shortValue()), hasMin?new Short(minimum.shortValue()):null, hasMax?new Short(maximum.shortValue()):null, new Short(step_size.shortValue()) ); }else if(number_type.equals("integer")){ model=new SpinnerNumberModel( new Integer(init_value.intValue()), hasMin?new Integer(minimum.intValue()):null, hasMax?new Integer(maximum.intValue()):null, new Integer(step_size.intValue()) ); }else if(number_type.equals("long")){ model=new SpinnerNumberModel( new Long(init_value.longValue()), hasMin?new Long(minimum.longValue()):null, hasMax?new Long(maximum.longValue()):null, new Long(step_size.longValue()) ); }else if(number_type.equals("float")){ model=new SpinnerNumberModel( new Float(init_value.floatValue()), hasMin?new Float(minimum.floatValue()):null, hasMax?new Float(maximum.floatValue()):null, new Float(step_size.floatValue()) ); }else if(number_type.equals("double")){ model=new SpinnerNumberModel( new Double(init_value.doubleValue()), hasMin?new Double(minimum.doubleValue()):null, hasMax?new Double(maximum.doubleValue()):null, new Double(step_size.doubleValue()) ); }else{ model=new SpinnerNumberModel(); } return model; } public void setValue(Object v) { } public Component getEditor() { return this; } public void addChangeListener(ChangeListener l) { } public void removeChangeListener(ChangeListener l) { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -