2 //Title: Geological editor
4 //Copyright: Copyright (c) 1998
5 //Author: User Interface Group (Nizhny Novgorod)
7 //Description: Prototype of BRGM project
13 import java.awt.event.*;
14 import java.awt.image.*;
19 public abstract class SpinBox extends JPanel implements ActionListener,
23 protected JButton btnUp = new JButton();
24 protected JButton btnDown = new JButton();
25 protected JTextField txtFld = new JTextField(1);
26 JPanel pnlBtn = new JPanel(new GridLayout(2, 1));
28 static Icon imgUp = getUpIcon();
29 static Icon imgDown = getDownIcon();
32 //*********************************************************************
44 txtFld.setCaretPosition(0);
47 //*********************************************************************
48 private void jbInit() throws Exception
50 this.setLayout(new BorderLayout());
51 this.add(txtFld, BorderLayout.CENTER);
53 Insets aIns = new Insets(1, 1, 1, 1);
54 btnUp.setMargin(aIns);
55 btnDown.setMargin(aIns);
58 btnDown.setIcon(imgDown);
59 btnUp.setFocusPainted(false);
60 btnDown.setFocusPainted(false);
62 btnUp.addActionListener(this);
63 btnDown.addActionListener(this);
67 this.add(pnlBtn, BorderLayout.EAST);
69 txtFld.addKeyListener(this);
70 txtFld.addFocusListener(this);
73 //*********************************************************************
74 private static Icon getUpIcon()
76 BufferedImage aImg = new BufferedImage(8, 4, BufferedImage.TYPE_INT_RGB);
77 Graphics2D aGr = aImg.createGraphics();
79 aGr.setColor(SystemColor.menu);
80 aGr.fillRect(0, 0, 8, 4);
83 aGr.setColor(Color.black);
84 aGr.fillPolygon(aX, aY, 3);
85 ImageIcon aNew = new ImageIcon(aImg);
89 //*********************************************************************
90 private static Icon getDownIcon()
92 BufferedImage aImg = new BufferedImage(8, 4, BufferedImage.TYPE_INT_RGB);
93 Graphics2D aGr = aImg.createGraphics();
95 aGr.setColor(SystemColor.menu);
96 aGr.fillRect(0, 0, 8, 4);
99 aGr.setColor(Color.black);
100 aGr.fillPolygon(aX, aY, 3);
101 ImageIcon aNew = new ImageIcon(aImg);
105 protected abstract void IncreaseValue();
106 protected abstract void DecreaseValue();
108 //*********************************************************************
109 public void setColumns(int aColumns)
111 txtFld.setColumns(aColumns);
114 //*********************************************************************
115 public int getColumns()
117 return txtFld.getColumns();
120 //*********************************************************************
121 public void setEnabled(boolean aState)
123 super.setEnabled(aState);
124 txtFld.setEnabled(aState);
125 btnDown.setEnabled(aState);
126 btnUp.setEnabled(aState);
129 //*********************************************************************
130 public void addFocusListener(FocusListener l)
132 super.addFocusListener(l);
133 if (txtFld != null) txtFld.addFocusListener(l);
134 if (btnUp != null) btnUp.addFocusListener(l);
135 if (btnDown != null) btnDown.addFocusListener(l);
138 //*********************************************************************
140 //*********************************************************************
141 public void actionPerformed(ActionEvent e)
143 if (e.getSource() instanceof JButton)
145 JButton aBtn = (JButton)e.getSource();
146 if (aBtn == btnUp) IncreaseValue();
147 else if (aBtn == btnDown) DecreaseValue();
151 //*********************************************************************
153 //*********************************************************************
154 public void keyPressed(KeyEvent e)
158 public void keyReleased(KeyEvent e)
162 public void keyTyped(KeyEvent e)
166 //*********************************************************************
168 //*********************************************************************
169 public void focusGained(FocusEvent e)
173 public void focusLost(FocusEvent e)