1 /*
2  * CDDL HEADER START
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  *
24  * ident	"%Z%%M%	%I%	%E% SMI"
25  *
26  * Copyright (c) 1999 by Sun Microsystems, Inc.
27  * All rights reserved.
28  *
29  * helpTest.java
30  * Test harness for help subsystem
31  */
32 
33 package com.sun.admin.pm.client;
34 
35 import java.util.*;
36 import java.awt.*;
37 import java.awt.event.*;
38 import java.util.*;
39 import javax.swing.JPanel;
40 import javax.swing.border.*;
41 import javax.swing.event.*;
42 import javax.swing.*;
43 import com.sun.admin.pm.server.*;
44 
45 class helpTest {
46     static private pmHelpFrame helpFrame = null;
47 
main(String args[])48     public static void main(String args[]) {
49 
50         Debug.setDebugLevel(Debug.ERROR);
51 
52         JFrame frame = new JFrame("Help Test Tool");
53         frame.addWindowListener(new WindowAdapter() {
54             public void windowClosing(WindowEvent e) {System.exit(0); }
55         });
56 
57         helpFrame = new pmHelpFrame();
58         helpFrame.setLocation(180, 180);
59 
60 
61         JList theList = new JList();
62         theList.addMouseListener(new MouseAdapter() {
63             public void mouseClicked(MouseEvent e) {
64                 if (e.getClickCount() == 2) {
65                     JList l = (JList) e.getSource();
66                     int i = l.locationToIndex(e.getPoint());
67                     Debug.message("doubleclick index: " + i);
68                     if (i >= 0) {
69                         String s = (String) l.getModel().getElementAt(i);
70                         Debug.message("doubleclick: " + s);
71                         helpFrame.showHelp(s);
72                     }
73                 }
74             }
75         });
76 
77         JScrollPane scrollPane = new JScrollPane();
78         scrollPane.getViewport().setView(theList);
79 
80 	JPanel tp = new JPanel();
81 	tp.setLayout(new GridBagLayout());
82 	GridBagConstraints pc = new GridBagConstraints();
83 	pc.insets = new Insets(5, 5, 0, 5);
84 	// pc.fill = GridBagConstraints.HORIZONTAL;
85 	pc.weightx = 1.0;
86 	pc.anchor = GridBagConstraints.WEST;
87 	pc.gridx = 0;
88 	pc.gridy = GridBagConstraints.RELATIVE;
89 
90 	tp.add(new JLabel("Double-click a tag to load it."), pc);
91 	pc.insets = new Insets(0, 5, 5, 5);
92 	tp.add(new JLabel(""), pc);
93 
94         JPanel p = new JPanel();
95 	p.setLayout(new GridBagLayout());
96 
97         GridBagConstraints c = new GridBagConstraints();
98 	c.insets = new Insets(5, 5, 5, 5);
99         c.gridwidth = GridBagConstraints.REMAINDER;
100         c.fill = GridBagConstraints.HORIZONTAL;
101 	c.gridheight = 1;
102         c.gridx = 0;
103         c.gridy = 0;
104         c.weightx = 1.0;
105         c.weighty = 0.0;
106 
107         c.anchor = GridBagConstraints.NORTH;
108 	p.add(tp, c);
109 
110 	JPanel pp = new JPanel();
111 	pp.setLayout(new BorderLayout());
112 	pp.add(scrollPane, "Center");
113 
114 	c.gridy = GridBagConstraints.RELATIVE;
115 	c.gridheight = 0;
116 	c.weighty = 1.0;
117 	c.weightx = 0.0;
118 	c.fill = GridBagConstraints.BOTH;
119 	c.anchor = GridBagConstraints.EAST;
120 
121 	p.add(pp, c);
122 
123 	p.setBorder(BorderFactory.createEtchedBorder());
124 
125         frame.getContentPane().add("Center", p);
126 
127         helpTestButtonPanel bp = new helpTestButtonPanel();
128         frame.getContentPane().add("South", bp);
129 
130         p = new JPanel();
131         Vector v = new Vector();
132 
133 	ResourceBundle bundle = null;
134 
135 	try {
136             bundle = ResourceBundle.getBundle(
137 		"com.sun.admin.pm.client.pmHelpResources");
138         } catch (MissingResourceException e) {
139             System.out.println("Could not load pmHelpResources file");
140             System.exit(-1);
141         }
142 
143 	Enumeration e = bundle.getKeys();
144 	while (e.hasMoreElements()) {
145             String key = (String) e.nextElement();
146             if (key.endsWith(".tag")) {
147                 String tagName = null;
148                 try {
149                     tagName = bundle.getString(key);
150                 } catch (MissingResourceException x) {
151                     System.out.println("Unable to find tag for " + key);
152                     continue;
153                 }
154                 v.addElement(tagName);
155             }
156         }
157 
158         theList.setListData(v);
159 		theList.removeSelectionInterval(
160 			theList.getMinSelectionIndex(),
161 			theList.getMaxSelectionIndex());
162 		// theList.addSelectionInterval(3, 5);
163 		// theList.disable();
164 
165         frame.pack();
166         frame.setVisible(true);
167         frame.repaint();
168         System.err.println("Hello from main");
169 
170     }
171 
showHelpItem(String tag)172     public void showHelpItem(String tag) {
173         helpFrame.showHelp(tag);
174     }
175 
176 }
177 
178     class helpTestButtonPanel extends JPanel {
179         JButton dismiss;
180 
helpTestButtonPanel()181         public helpTestButtonPanel() {
182             add(dismiss = new JButton("Done"));
183             dismiss.addActionListener(new ActionListener() {
184                 public void actionPerformed(ActionEvent e) {
185                     System.exit(0);
186                 }
187             });
188         }
189     }
190 
191 
192 
193 
194 
195 
196 
197