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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * 23 * ident "%Z%%M% %I% %E% SMI" 24 * 25 * Copyright(c) 1999 by Sun Microsystems, Inc. 26 * All rights reserved. 27 * 28 * pmHelpIndexPanel.java 29 * Search help titles 30 */ 31 32 package com.sun.admin.pm.client; 33 34 import java.awt.*; 35 import java.awt.event.*; 36 import java.util.*; 37 import javax.swing.JPanel; 38 import javax.swing.border.*; 39 import javax.swing.event.*; 40 import javax.swing.*; 41 42 import com.sun.admin.pm.server.*; 43 44 45 public class pmHelpIndexPanel extends JPanel { 46 47 pmHelpController controller; 48 pmHelpIndexQueryPanel queryPanel; 49 pmHelpIndexResultPanel resultPanel; 50 JLabel textPanels[]; 51 pmHelpIndexPanel(pmHelpController ctrl)52 public pmHelpIndexPanel(pmHelpController ctrl) { 53 controller = ctrl; 54 55 // build subpanels 56 queryPanel = new pmHelpIndexQueryPanel(this); 57 resultPanel = new pmHelpIndexResultPanel(this); 58 59 textPanels = new JLabel[4]; 60 textPanels[0] = new JLabel( 61 pmUtility.getResource("To.search.the.index...")); 62 textPanels[1] = new JLabel( 63 pmUtility.getResource("type.your.query.below...")); 64 65 // lay out top panel 66 this.setLayout(new GridBagLayout()); 67 GridBagConstraints c = new GridBagConstraints(); 68 c.insets = new Insets(5, 5, 5, 5); 69 c.gridwidth = GridBagConstraints.REMAINDER; 70 71 c.gridx = 0; 72 c.gridy = 0; 73 74 c.gridheight = 1; // GridBagConstraints.REMAINDER; 75 c.fill = GridBagConstraints.BOTH; 76 c.weightx = 1.0; 77 c.weighty = 0.0; 78 79 JPanel p = new JPanel(); 80 p.setLayout(new GridBagLayout()); 81 GridBagConstraints pc = new GridBagConstraints(); 82 pc.insets = new Insets(5, 5, 0, 5); 83 // pc.fill = GridBagConstraints.HORIZONTAL; 84 pc.weightx = 1.0; 85 pc.anchor = GridBagConstraints.WEST; 86 pc.gridx = 0; 87 pc.gridy = GridBagConstraints.RELATIVE; 88 89 p.add(textPanels[0], pc); 90 pc.insets = new Insets(0, 5, 5, 5); 91 p.add(textPanels[1], pc); 92 // p.add(textPanels[2]); 93 94 this.add(p, c); 95 96 p = new JPanel(); 97 p.setLayout(new BorderLayout()); 98 p.add(queryPanel, "North"); 99 p.add(resultPanel, "Center"); 100 p.setBorder(BorderFactory.createEtchedBorder()); 101 102 c.gridy = GridBagConstraints.RELATIVE; 103 c.gridheight = 0; 104 c.weighty = 1.0; 105 c.weightx = 0.0; 106 c.fill = GridBagConstraints.BOTH; 107 c.anchor = GridBagConstraints.EAST; 108 109 this.add(p, c); 110 111 this.setBorder(BorderFactory.createEtchedBorder()); 112 113 114 // figure out when we are un-tabbed 115 controller.outerPanel.addChangeListener(new ChangeListener() { 116 public void stateChanged(ChangeEvent e) { 117 JTabbedPane tp = (JTabbedPane) e.getSource(); 118 Debug.info("HELP: Tab event!"); 119 if (!(tp.getSelectedComponent() instanceof 120 com.sun.admin.pm.client.pmHelpIndexPanel)) { 121 Debug.info("HELP: Tab event: resetting default"); 122 /* 123 * controller.frame.getRootPane(). 124 * setDefaultButton( 125 * controller.frame.dismiss); 126 */ 127 } else { 128 // allow tab to retain focus 129 // queryPanel.query.requestFocus(); 130 } 131 } 132 }); 133 134 135 } 136 137 138 // place item titles in search result panel setSearchResults(Vector items)139 public void setSearchResults(Vector items) { 140 Vector v = new Vector(); 141 142 if (items.size() == 0) { 143 resultPanel.setListEmpty(true); 144 v.addElement(pmUtility.getResource("Nothing.matched.")); 145 } else { 146 Enumeration e = items.elements(); 147 while (e.hasMoreElements()) { 148 pmHelpItem i = (pmHelpItem) e.nextElement(); 149 v.addElement(i); 150 } 151 resultPanel.setListEmpty(false); 152 } 153 154 resultPanel.setResultList(v); 155 } 156 157 } 158 159 160 161 class pmHelpIndexResultPanel extends JPanel { 162 163 JList resultList = null; 164 pmButton selectButton = null; 165 pmHelpIndexPanel parentPanel = null; 166 protected boolean listEmpty = true; 167 168 pmHelpIndexResultPanel(pmHelpIndexPanel p)169 public pmHelpIndexResultPanel(pmHelpIndexPanel p) { 170 171 parentPanel = p; 172 173 this.setLayout(new GridBagLayout()); 174 175 GridBagConstraints c = new GridBagConstraints(); 176 c.insets = new Insets(10, 10, 10, 10); 177 c.fill = GridBagConstraints.NONE; 178 c.weightx = c.weighty = 0.0; 179 c.gridx = 0; 180 c.gridy = 0; 181 c.anchor = GridBagConstraints.NORTHWEST; 182 183 JLabel promptLabel = new JLabel( 184 pmUtility.getResource("Matching.entries:")); 185 /* 186 * MNEMONIC 187 * promptLabel.setDisplayedMnemonic( 188 * pmUtility.getIntResource("Matching.entries:.mnemonic")); 189 */ 190 191 this.add(promptLabel, c); 192 193 c.gridy = 1; 194 c.anchor = GridBagConstraints.WEST; 195 196 selectButton = new pmButton( 197 pmUtility.getResource("Show")); 198 selectButton.setMnemonic( 199 pmUtility.getIntResource("Show.mnemonic")); 200 201 selectButton.setEnabled(false); 202 203 this.add(selectButton, c); 204 205 selectButton.addActionListener(new ActionListener() { 206 public void actionPerformed(ActionEvent e) { 207 pmHelpItem selectedItem = (pmHelpItem) 208 resultList.getSelectedValue(); 209 Debug.message("Selected " + selectedItem); 210 parentPanel.controller.showHelpItem(selectedItem); 211 } 212 }); 213 214 Vector resultItems = null; 215 try { 216 // resultItems = pmHelpIndexQueryPanel.helpDB.getPartialMatch(""); 217 resultItems = pmHelpRepository.helpItemsForString(""); 218 } catch (pmHelpException x) { 219 Debug.message("pmHelpIndexResultpanel init: " + x); 220 resultItems = new Vector(); 221 resultItems.addElement( 222 pmUtility.getResource("Nothing.matched.")); 223 } 224 225 resultList = new JList(resultItems); 226 JScrollPane scrollPane = new JScrollPane(); 227 scrollPane.getViewport().setView(resultList); 228 resultList.setVisibleRowCount(8); 229 230 promptLabel.setLabelFor(resultList); 231 232 resultList.addListSelectionListener(new ListSelectionListener() { 233 public void valueChanged(ListSelectionEvent e) { 234 if (!listEmpty) { 235 selectButton.setEnabled(true); 236 /* 237 * parentPanel.controller.frame. 238 * getRootPane().setDefaultButton(selectButton); 239 */ 240 selectButton.setAsDefaultButton(); 241 242 } 243 }}); 244 245 resultList.addMouseListener(new MouseAdapter() { 246 public void mouseClicked(MouseEvent e) { 247 if (e.getClickCount() == 2) { 248 JList l = (JList) e.getSource(); 249 int i = l.locationToIndex(e.getPoint()); 250 Debug.message("doubleclick index: " + i); 251 if (!listEmpty && i >= 0) { 252 pmHelpItem item = 253 (pmHelpItem) l.getModel().getElementAt(i); 254 Debug.message("doubleclick: " + item.tag); 255 parentPanel.controller.showHelpItem(item); 256 } 257 } 258 } 259 }); 260 261 c.gridwidth = 1; // 2; 262 c.gridx = 1; 263 c.gridy = 0; 264 c.weightx = c.weighty = 1.0; 265 c.fill = GridBagConstraints.BOTH; 266 c.anchor = GridBagConstraints.EAST; 267 268 this.add(scrollPane, c); 269 270 } 271 setResultList(Vector v)272 void setResultList(Vector v) { 273 274 resultList.setListData(v); 275 276 resultList.setSelectedValue(v.elementAt(0), true); 277 } 278 setListEmpty(boolean e)279 void setListEmpty(boolean e) { 280 listEmpty = e; 281 selectButton.setEnabled(false); 282 /* 283 * parentPanel.controller.frame.getRootPane(). 284 * setDefaultButton(parentPanel.controller.frame.dismiss); 285 */ 286 if (parentPanel.controller.frame.dismiss != null) 287 parentPanel.controller.frame.dismiss. 288 setAsDefaultButton(); 289 } 290 291 } 292 293 294 class pmHelpIndexQueryPanel extends JPanel { 295 296 JTextField query; 297 pmHelpIndexPanel parentPanel; 298 pmHelpIndexQueryPanel(pmHelpIndexPanel p)299 public pmHelpIndexQueryPanel(pmHelpIndexPanel p) { 300 301 parentPanel = p; 302 303 this.setLayout(new GridBagLayout()); 304 305 GridBagConstraints c = new GridBagConstraints(); 306 c.insets = new Insets(10, 10, 10, 10); 307 c.fill = GridBagConstraints.NONE; 308 c.weightx = c.weighty = 0.0; 309 c.anchor = GridBagConstraints.WEST; 310 311 c.gridx = 0; 312 c.gridy = 0; 313 c.gridwidth = 1; 314 c.gridheight = 1; 315 c.insets = new Insets(10, 10, 10, 10); 316 317 JLabel promptLabel = 318 new JLabel(pmUtility.getResource("Search.help.index.for:")); 319 /* 320 * MNEMONIC 321 * promptLabel.setDisplayedMnemonic( 322 * pmUtility.getIntResource("Search.help.index.for:.mnemonic")); 323 */ 324 325 this.add(promptLabel, c); 326 327 query = new JTextField(); 328 query.setEditable(true); 329 query.setText(""); 330 331 promptLabel.setLabelFor(query); 332 333 query.addActionListener(new ActionListener() { 334 public void actionPerformed(ActionEvent e) { 335 Debug.info("HELP: Action!"); 336 parentPanel.resultPanel.selectButton.doClick(); 337 } 338 }); 339 340 c.gridwidth = GridBagConstraints.REMAINDER; 341 c.gridx = 1; 342 c.weightx = 1.0; 343 c.fill = GridBagConstraints.HORIZONTAL; 344 c.anchor = GridBagConstraints.EAST; 345 346 this.add(query, c); 347 348 DocumentListener d = new DocumentListener() { 349 public void changedUpdate(DocumentEvent e) { 350 // ignore 351 } 352 353 public void insertUpdate(DocumentEvent e) { 354 handleText(query.getText()); 355 } 356 357 public void removeUpdate(DocumentEvent e) { 358 handleText(query.getText()); 359 } 360 }; 361 362 query.getDocument().addDocumentListener(d); 363 } 364 handleText(String txt)365 public void handleText(String txt) { 366 367 Debug.message("Got text " + txt); 368 369 Vector v = null; 370 371 try { 372 // v = helpDB.getPartialMatch(txt); 373 v = pmHelpRepository.helpItemsForString(txt); 374 } catch (pmHelpException x) { 375 Debug.warning("handleText: " + x); 376 } 377 parentPanel.setSearchResults(v); 378 379 } 380 381 // belongs in controller? 382 // static pmHelpRepository helpDB = new pmHelpRepository(); 383 } 384