KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > testbed > workbench > util > gui > Cursors


1 package org.enhydra.barracuda.testbed.workbench.util.gui;
2
3
4 import java.awt.*;
5 import javax.swing.*;
6
7
8 /**
9  * Cursors utility
10  */

11 public class Cursors {
12
13     /**
14      * This method basically runs through all the components
15      * in the heirarchy and sets the cursor for them
16      * depending on the value of isWorking.
17      *
18      * @param cont - The container in question
19      * @param isWorking - True if we want to show that we're working
20      */

21     public static void setWorking(Container cont, boolean isWorking) {
22         //eliminate the obvious
23
if (cont==null) return;
24
25         //get all the components in this container
26
Component comps[] = cont.getComponents();
27         setWorking(comps, isWorking);
28     }
29
30     /**
31      * This method basically runs through all the components
32      * in the heirarchy and sets the cursor for them
33      * depending on the value of isWorking.
34      *
35      * @param comps - An array of components in questions
36      * @param isWorking - True if we want to show that we're working
37      */

38     public static void setWorking(Component comps[], boolean isWorking) {
39         setWorking_private(comps, isWorking);
40     }
41
42     /**
43      * This is the method that gets called recursively and does all the work
44      *
45      * @param comps
46      * @param isWorking
47      */

48     public static void setWorking_private(Component comps[], boolean isWorking) {
49
50         //look for specifics
51
Cursor defaultCursor = Cursor.getDefaultCursor();
52         Cursor handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
53         Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
54         for (int i = 0, max = comps.length; i<max; i++) {
55             Component comp = comps[i];
56             if (comp==null) continue;
57             if (isWorking) {
58                 comp.setCursor(waitCursor);
59             } else {
60                 if (comp instanceof AbstractButton) comp.setCursor(handCursor);
61                 else if (comp instanceof Button) comp.setCursor(handCursor);
62                 else comp.setCursor(defaultCursor);
63             }
64
65             //Now see if the component happens to be a container. If so, we'll
66
//need to iterate through that as well
67
if (comp instanceof Container) setWorking((Container) comp, isWorking);
68         }
69     }
70
71
72 }
73
Popular Tags