1 package com.instantbank.common.uiutils;
2
3 import java.awt.GridLayout;
4 import javax.swing.JPanel;
5 import javax.swing.SwingConstants;
6 import javax.swing.JButton;
7 import javax.swing.plaf.basic.BasicArrowButton;
8
9
14 class Spinner extends JPanel {
15
16
19 private int orientation = SwingConstants.VERTICAL;
20
21
24 private BasicArrowButton btnIncrement;
25
26
29 private BasicArrowButton btnDecrement;
30
31
32
35 public Spinner() {
36 createComponents();
37 }
38
39
40
45 public Spinner(int orientation) {
46 this.orientation = orientation;
47 createComponents();
48 }
49
50
51
56 public void setEnabled(boolean enable) {
57 btnIncrement.setEnabled(enable);
58 btnDecrement.setEnabled(enable);
59 }
60
61
62
67 public boolean isEnabled() {
68 return (btnIncrement.isEnabled() &&
69 btnDecrement.isEnabled());
70 }
71
72
73
76 protected void createComponents() {
77 if(orientation == SwingConstants.VERTICAL) {
78 setLayout(new GridLayout(2, 1));
79 btnIncrement = new BasicArrowButton(SwingConstants.NORTH);
80 btnDecrement = new BasicArrowButton(SwingConstants.SOUTH);
81 add(btnIncrement);
82 add(btnDecrement);
83 }
84 else if(orientation == SwingConstants.HORIZONTAL) {
85 setLayout(new GridLayout(1, 2));
86 btnIncrement = new BasicArrowButton(SwingConstants.EAST);
87 btnDecrement = new BasicArrowButton(SwingConstants.WEST);
88 add(btnDecrement);
89 add(btnIncrement);
90 }
91 }
92
93
94
100 public JButton getIncrementButton() {
101 return (btnIncrement);
102 }
103
104
105
111 public JButton getDecrementButton() {
112 return (btnDecrement);
113 }
114 }
115