@Override public void setEnabled(boolean value) { buttonUp.setEnabled(value); buttonDown.setEnabled(value); labelFigure.setEnabled(value); super.setEnabled(value); repaint(); }
public SpinnerFigure() { formatType = NumericFormatType.DECIAML; spinnerListeners = new ArrayList<IManualValueChangeListener>(); setRequestFocusEnabled(true); setFocusTraversable(true); addKeyListener( new KeyListener() { public void keyPressed(KeyEvent ke) { if (ke.keycode == SWT.ARROW_DOWN) stepDown(); else if (ke.keycode == SWT.ARROW_UP) stepUp(); else if (ke.keycode == SWT.PAGE_UP) pageUp(); else if (ke.keycode == SWT.PAGE_DOWN) pageDown(); } public void keyReleased(KeyEvent ke) {} }); addFocusListener( new FocusListener() { public void focusGained(FocusEvent fe) { repaint(); } public void focusLost(FocusEvent fe) { repaint(); } }); labelFigure = new TextFigure() { /** * If this button has focus, this method paints a focus rectangle. * * @param graphics Graphics handle for painting */ protected void paintBorder(Graphics graphics) { super.paintBorder(graphics); if (SpinnerFigure.this.hasFocus()) { graphics.setForegroundColor(ColorConstants.black); graphics.setBackgroundColor(ColorConstants.white); Rectangle area = getClientArea(); graphics.drawFocus(area.x, area.y, area.width - 1, area.height - 1); } } }; labelFigure.setText(format(value)); labelFigure.addMouseListener( new MouseListener.Stub() { @Override public void mousePressed(MouseEvent me) { if (!hasFocus()) requestFocus(); } }); add(labelFigure); ButtonBorder buttonBorder = new ButtonBorder( new ButtonScheme( new Color[] {ColorConstants.buttonLightest}, new Color[] {ColorConstants.buttonDarkest})); buttonUp = new RapArrowButton(); buttonUp.setBorder(buttonBorder); buttonUp.setDirection(Orientable.NORTH); buttonUp.setFiringMethod(Clickable.REPEAT_FIRING); buttonUp.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { stepUp(); if (!hasFocus()) requestFocus(); } }); add(buttonUp); buttonDown = new RapArrowButton(); buttonDown.setBorder(buttonBorder); buttonDown.setDirection(Orientable.SOUTH); buttonDown.setFiringMethod(Clickable.REPEAT_FIRING); buttonDown.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { stepDown(); if (!hasFocus()) requestFocus(); } }); add(buttonDown); }
/** * Set the value of the spinner. It will be coerced in the range. This only update the text. It * will not notify listeners about the value change. * * @param value the value to set * @return true if value changed. false otherwise. */ public void setValue(double value) { if (this.value == value) return; this.value = value; labelFigure.setText(format(value)); }
/** @param precision the precision to set */ public void setPrecision(int precision) { if (this.precision == precision) return; this.precision = precision; labelFigure.setText(format(value)); }
public void setFormatType(NumericFormatType formatType) { this.formatType = formatType; labelFigure.setText(format(value)); }
/** * Set the displayed value in the spinner. It may out of the range. * * @param value the value to be displayed */ public final void setDisplayValue(double value) { if (this.value == value) return; this.value = value; labelFigure.setText(format(value)); }
@Override protected void layout() { Rectangle clientArea = getClientArea(); if (arrowButtonsOnLeft) { if (arrowButtonsHorizontal) { labelFigure.setBounds( new Rectangle( clientArea.x + 1 + 2 * buttonWidth, clientArea.y, clientArea.width - 2 * buttonWidth - 1, clientArea.height)); buttonUp.setBounds( new Rectangle(clientArea.x, clientArea.y, buttonWidth, clientArea.height)); buttonDown.setBounds( new Rectangle( clientArea.x + buttonWidth, clientArea.y, buttonWidth, clientArea.height)); } else { labelFigure.setBounds( new Rectangle( clientArea.x + 1 + buttonWidth, clientArea.y, clientArea.width - buttonWidth - 1, clientArea.height)); buttonUp.setBounds( new Rectangle(clientArea.x, clientArea.y, buttonWidth, clientArea.height / 2)); buttonDown.setBounds( new Rectangle( clientArea.x, clientArea.y + clientArea.height / 2, buttonWidth, clientArea.height / 2)); } } else { if (arrowButtonsHorizontal) { labelFigure.setBounds( new Rectangle( clientArea.x, clientArea.y, clientArea.width - 2 * buttonWidth, clientArea.height)); buttonUp.setBounds( new Rectangle( clientArea.x + clientArea.width - 2 * buttonWidth, clientArea.y, buttonWidth, clientArea.height)); buttonDown.setBounds( new Rectangle( clientArea.x + clientArea.width - buttonWidth, clientArea.y, buttonWidth, clientArea.height)); } else { labelFigure.setBounds( new Rectangle( clientArea.x, clientArea.y, clientArea.width - buttonWidth, clientArea.height)); buttonUp.setBounds( new Rectangle( clientArea.x + clientArea.width - buttonWidth, clientArea.y, buttonWidth, clientArea.height / 2)); buttonDown.setBounds( new Rectangle( clientArea.x + clientArea.width - buttonWidth, clientArea.y + clientArea.height / 2, buttonWidth, clientArea.height / 2)); } } super.layout(); }