1 42 43 package org.jfree.ui; 44 45 import java.awt.BorderLayout ; 46 import java.awt.GridLayout ; 47 import java.awt.event.MouseEvent ; 48 import java.awt.event.MouseListener ; 49 50 import javax.swing.JPanel ; 51 import javax.swing.JTextField ; 52 import javax.swing.SwingConstants ; 53 54 59 public class Spinner extends JPanel implements MouseListener { 60 61 62 private int value; 63 64 65 private JTextField textField; 66 67 68 private JPanel buttonPanel; 69 70 71 private ArrowPanel upButton; 72 73 74 private ArrowPanel downButton; 75 76 81 public Spinner(final int value) { 82 super(new BorderLayout ()); 83 this.value = value; 84 this.textField = new JTextField (Integer.toString(this.value)); 85 this.textField.setHorizontalAlignment(SwingConstants.RIGHT); 86 add(this.textField); 87 this.buttonPanel = new JPanel (new GridLayout (2, 1, 0, 1)); 88 this.upButton = new ArrowPanel(ArrowPanel.UP); 89 this.upButton.addMouseListener(this); 90 this.downButton = new ArrowPanel(ArrowPanel.DOWN); 91 this.downButton.addMouseListener(this); 92 this.buttonPanel.add(this.upButton); 93 this.buttonPanel.add(this.downButton); 94 add(this.buttonPanel, BorderLayout.EAST); 95 } 96 97 102 public int getValue() { 103 return this.value; 104 } 105 106 111 public void mouseClicked(final MouseEvent e) { 112 if (e.getSource() == this.upButton) { 113 this.value++; 114 this.textField.setText(Integer.toString(this.value)); 115 firePropertyChange("value", this.value - 1, this.value); 116 } 117 else if (e.getSource() == this.downButton) { 118 this.value--; 119 this.textField.setText(Integer.toString(this.value)); 120 firePropertyChange("value", this.value + 1, this.value); 121 } 122 } 123 124 129 public void mouseEntered(final MouseEvent e) { 130 } 132 133 138 public void mouseExited(final MouseEvent e) { 139 } 141 142 147 public void mousePressed(final MouseEvent e) { 148 } 150 151 156 public void mouseReleased(final MouseEvent e) { 157 } 159 160 } 161 | Popular Tags |