3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * ident "%Z%%M% %I% %E% SMI"
24 *
25 * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
26 * All rights reserved.
27 */
28
29 import java.awt.*;
30 import java.awt.event.*;
31
32 /**
33 * Creates a panel with two buttons (+ and - side by side on it). The
34 * panel registers a DCListener with it that gets notified whenever
35 * these butons are clicked. <bold>The buttons may also be kept continously
36 * pressed for faster increments/decrements.</bold>
37 * <para>
38 * On a single click of the button, the listener is notified to
39 * increment/decrement itself by a small amount. When the button is kept
40 * pressed the following notifications are sent out for larger
41 * increments/decrements. (It is up to the listener to decide the
42 * increment/decrement corresponding to large/small.) Moreover, these
43 * notifications will be sent out much faster if the button is kept
44 * pressed.
73 bigTimer = new BigTimer();
74 smallTimer = new SmallTimer();
75
76 bigTimer.start();
77 smallTimer.start();
78
79 plusButton = new DCButton("+");
80 minusButton = new DCButton("-");
81
82 add(plusButton);
83 add(minusButton);
84
85 }
86
87 /**
88 * Ensures that this component is not brought into focus by
89 * tabbing. This prevents the tab focus from moving in here instead
90 * of going to a text field.
91 * @return false always.
92 */
93 public boolean isFocusTraversable() {
94 return false;
95 }
96
97 /**
98 * Sets the listener for this tab.
99 * @param listener the DCListener that needs to be notified when the
100 * buttons on this panel are pressed.
101 * @return the old listener
102 */
103 public DCListener setListener(DCListener listener) {
104 DCListener oldListener = this.listener;
105 this.listener = listener;
106 return oldListener;
107 }
108
109 /**
110 * Removes the listener when it no longer need to be notified.
111 * @return the old listener
112 */
113 public DCListener removeListener() {
284 DCPanel.this.stopAction();
285 }
286 }
287
288 /**
289 * The button used by this DCPanel.
290 */
291 private class DCButton extends Button {
292 public DCButton(String text) {
293 super(text);
294 if (text.equals("+"))
295 addMouseListener(new DCMouseListener(true));
296 else
297 addMouseListener(new DCMouseListener(false));
298 }
299
300 /**
301 * Make the button non-focus traversable so that it cannot be
302 * tabbed in to.
303 */
304 public boolean isFocusTraversable() {
305 return false;
306 }
307
308 } // DCButton
309
310
311 /**
312 * Test method for DCPanel class to see appearance.
313 */
314 public static void main(String args[]) {
315 Frame f = new Frame("Testing DCPanel");
316 f.add(new DCPanel());
317 f.setBounds(new Rectangle(100, 100, 100, 100));
318 f.setVisible(true);
319 }
320
321 }
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 import java.awt.*;
28 import java.awt.event.*;
29
30 /**
31 * Creates a panel with two buttons (+ and - side by side on it). The
32 * panel registers a DCListener with it that gets notified whenever
33 * these butons are clicked. <bold>The buttons may also be kept continously
34 * pressed for faster increments/decrements.</bold>
35 * <para>
36 * On a single click of the button, the listener is notified to
37 * increment/decrement itself by a small amount. When the button is kept
38 * pressed the following notifications are sent out for larger
39 * increments/decrements. (It is up to the listener to decide the
40 * increment/decrement corresponding to large/small.) Moreover, these
41 * notifications will be sent out much faster if the button is kept
42 * pressed.
71 bigTimer = new BigTimer();
72 smallTimer = new SmallTimer();
73
74 bigTimer.start();
75 smallTimer.start();
76
77 plusButton = new DCButton("+");
78 minusButton = new DCButton("-");
79
80 add(plusButton);
81 add(minusButton);
82
83 }
84
85 /**
86 * Ensures that this component is not brought into focus by
87 * tabbing. This prevents the tab focus from moving in here instead
88 * of going to a text field.
89 * @return false always.
90 */
91 public boolean isFocusable() {
92 return false;
93 }
94
95 /**
96 * Sets the listener for this tab.
97 * @param listener the DCListener that needs to be notified when the
98 * buttons on this panel are pressed.
99 * @return the old listener
100 */
101 public DCListener setListener(DCListener listener) {
102 DCListener oldListener = this.listener;
103 this.listener = listener;
104 return oldListener;
105 }
106
107 /**
108 * Removes the listener when it no longer need to be notified.
109 * @return the old listener
110 */
111 public DCListener removeListener() {
282 DCPanel.this.stopAction();
283 }
284 }
285
286 /**
287 * The button used by this DCPanel.
288 */
289 private class DCButton extends Button {
290 public DCButton(String text) {
291 super(text);
292 if (text.equals("+"))
293 addMouseListener(new DCMouseListener(true));
294 else
295 addMouseListener(new DCMouseListener(false));
296 }
297
298 /**
299 * Make the button non-focus traversable so that it cannot be
300 * tabbed in to.
301 */
302 public boolean isFocusable() {
303 return false;
304 }
305
306 } // DCButton
307
308
309 /**
310 * Test method for DCPanel class to see appearance.
311 */
312 public static void main(String args[]) {
313 Frame f = new Frame("Testing DCPanel");
314 f.add(new DCPanel());
315 f.setBounds(new Rectangle(100, 100, 100, 100));
316 f.setVisible(true);
317 }
318
319 }
|