UIUtils { public static JSpinner createSpinner(final Parameter param, final Number spinnerStep, final String formatPattern) { final Number v = (Number) param.getValue(); final ParamProperties properties = param.getProperties(); final Comparable min = (Comparable) properties.getMinValue(); final Comparable max = (Comparable) properties.getMaxValue(); final Double bigStep = spinnerStep.doubleValue() * 10; final JSpinner spinner = createSpinner(v, min, max, spinnerStep, bigStep, formatPattern); spinner.setName(properties.getLabel()); spinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { param.setValue(spinner.getValue(), null); } }); param.addParamChangeListener(new ParamChangeListener() { public void parameterValueChanged(ParamChangeEvent event) { spinner.setValue(param.getValue()); } }); param.getEditor().getEditorComponent().addPropertyChangeListener("enabled", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { spinner.setEnabled(((Boolean) evt.getNewValue()).booleanValue()); } }); properties.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (ParamProperties.MAXVALUE_KEY.equals(evt.getPropertyName())) { ((SpinnerNumberModel) spinner.getModel()).setMaximum((Comparable) properties.getMaxValue()); } if (ParamProperties.MINVALUE_KEY.equals(evt.getPropertyName())) { ((SpinnerNumberModel) spinner.getModel()).setMinimum((Comparable) properties.getMinValue()); } } }); final JSpinner.NumberEditor editor = ((JSpinner.NumberEditor) spinner.getEditor()); final JFormattedTextField textField = editor.getTextField(); textField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { textField.selectAll(); } public void focusLost(FocusEvent e) { } }); return spinner; } private  UIUtils(); static ImageIcon loadImageIcon(String resourcePath); static ImageIcon loadImageIcon(String resourcePath, Class callerClass); static URL getImageURL(String resourcePath); static URL getImageURL(String resourcePath, Class callerClass); static Dimension getScreenSize(); static int getScreenWidth(); static int getScreenHeight(); static void centerComponent(Component comp); static void centerComponent(Component comp, Component alignComp); static void showPopup(JPopupMenu popup, MouseEvent event); static Window getRootWindow(Component component); static Border createGroupBorder(String title); static Frame getRootFrame(Component component); static JFrame getRootJFrame(Component component); static Cursor setRootFrameWaitCursor(Component component); static Cursor setRootFrameDefaultCursor(Component component); static Cursor setRootFrameCursor(Component component, Cursor newCursor); static JMenu findMenu(JMenuBar menuBar, String name, boolean deepSearch); static int findMenuItemPosition(JPopupMenu popupMenu, String name); static JMenu findSubMenu(JPopupMenu popupMenu, String name); static String getUniqueFrameTitle(final JInternalFrame[] frames, final String titleBase); static JSpinner createSpinner(final Parameter param, final Number spinnerStep, final String formatPattern); static JSpinner createDoubleSpinner(final double value, final double rangeMinimum,
                                               final double rangeMaximum,
                                               final double stepSize, final double bigStepSize,
                                               final String formatPattern); static JSpinner createSpinner(final Number value, final Comparable rangeMinimum, final Comparable rangeMaximum,
                                         final Number stepSize, final Number bigStepSize, final String formatPattern); static final String PROPERTY_SOURCE_PRODUCT; static final String IMAGE_RESOURCE_PATH; static final Color COLOR_DARK_RED; static final Color COLOR_DARK_BLUE; static final Color COLOR_DARK_GREEN; }
@Test public void testCreateSpinner_WithParameter() { final String labelname = "paramLabel"; final ParamProperties properties = new ParamProperties(Integer.class, Integer.valueOf(3)); properties.setLabel(labelname); final Parameter parameter = new Parameter("paramName", properties); final JSpinner spinner = UIUtils.createSpinner(parameter, Integer.valueOf(10), "#0"); assertEquals(labelname, spinner.getName()); }