KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > dialogs > help > HelpNormal


1 package rero.dialogs.help;
2
3 import javax.swing.*;
4 import javax.swing.event.*;
5 import javax.swing.tree.*;
6
7 import java.awt.*;
8 import java.awt.event.*;
9
10 import rero.config.*;
11 import rero.dialogs.*;
12 import rero.gui.*;
13
14 import java.net.*;
15
16 import java.util.*;
17
18 public class HelpNormal extends HelperObject implements TreeSelectionListener
19 {
20     private static HashMap helpData = new HashMap();
21
22     public void valueChanged(TreeSelectionEvent e)
23     {
24        JTree theTree = (JTree)e.getSource();
25        DefaultMutableTreeNode node = (DefaultMutableTreeNode)theTree.getLastSelectedPathComponent();
26
27        if (node == null)
28           return;
29
30        showHelpOn(node.getUserObject().toString());
31     }
32
33     protected String JavaDoc lastKey = "";
34
35     public void showHelpOn(String JavaDoc key)
36     {
37         if (isTutorial(key))
38         {
39            if (lastKey.equals("IRC Tutorial"))
40            {
41               help.scrollTo(helpData.get(key).toString());
42            }
43            else
44            {
45               help.updateText(getHelpFor("IRC Tutorial"));
46            }
47         }
48         else if (isScriptTutorial(key))
49         {
50            if (lastKey.equals("Script Tutorial"))
51            {
52               help.scrollTo(helpData.get(key).toString());
53            }
54            else
55            {
56               help.updateText(getHelpFor("Script Tutorial"));
57            }
58         }
59         else
60         {
61            updateText(getHelpFor(key));
62         }
63     }
64
65     private String JavaDoc getHelpFor(String JavaDoc key)
66     {
67         lastKey = key;
68
69         if (helpData.get(key) == null)
70         {
71            String JavaDoc text = ClientState.getClientState().getHelpString(key);
72        
73            if (text != null)
74            {
75               helpData.put(key, text);
76               return text;
77            }
78
79            return null;
80     }
81         else
82         {
83
84            String JavaDoc data = helpData.get(key).toString();
85            return data;
86         }
87     }
88
89     private static boolean isTutorial(String JavaDoc key)
90     {
91         return key.equals("Introduction") || key.equals("Chatting") || key.equals("Beyond Basics");
92     }
93
94     private static boolean isScriptTutorial(String JavaDoc key)
95     {
96         return key.equals("Aliases") || key.equals("Events") || key.equals("Resources") || key.equals("Introduction ");
97     }
98
99     private DefaultMutableTreeNode initHelp()
100     {
101        DefaultMutableTreeNode category, option, items;
102        items = new DefaultMutableTreeNode("Help");
103
104        category = new DefaultMutableTreeNode("About"); items.add(category);
105           option = new DefaultMutableTreeNode("Contributors"); category.add(option);
106
107        category = new DefaultMutableTreeNode("General"); items.add(category);
108           option = new DefaultMutableTreeNode("Colored Text"); category.add(option);
109           option = new DefaultMutableTreeNode("KB Shortcuts"); category.add(option);
110
111 // category = new DefaultMutableTreeNode("IRC Tutorial"); items.add(category);
112
// option = new DefaultMutableTreeNode("Introduction"); category.add(option);
113
// option = new DefaultMutableTreeNode("Chatting"); category.add(option);
114
// option = new DefaultMutableTreeNode("Beyond Basics"); category.add(option);
115

116        category = new DefaultMutableTreeNode("Script Tutorial"); items.add(category);
117           option = new DefaultMutableTreeNode("Introduction "); category.add(option);
118           option = new DefaultMutableTreeNode("Aliases"); category.add(option);
119           option = new DefaultMutableTreeNode("Events"); category.add(option);
120           option = new DefaultMutableTreeNode("Resources"); category.add(option);
121
122        helpData.put("Introduction", "part1");
123        helpData.put("Chatting", "part2");
124        helpData.put("Beyond Basics", "part3");
125
126        helpData.put("Introduction ", "part1");
127        helpData.put("Aliases", "part2");
128        helpData.put("Events", "part3");
129        helpData.put("Resources", "part4");
130
131        return items;
132     }
133
134     public JComponent getNavigationComponent()
135     {
136         JTree genOptions = new JTree(initHelp());
137         genOptions.setRootVisible(false);
138         genOptions.setToggleClickCount(0); // 1 click to expand the tree...
139
genOptions.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
140
141         for (int x = 0; x < genOptions.getRowCount(); x++)
142            genOptions.expandPath(genOptions.getPathForRow(x));
143
144         genOptions.addTreeSelectionListener(this);
145
146         return genOptions;
147     }
148 }
149
150
151
152
Popular Tags