KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > directory > jxplorer > MainMenu


1 package com.ca.directory.jxplorer;
2
3 import javax.swing.*;
4 import javax.swing.event.*;
5 import java.awt.*;
6 import java.awt.event.*;
7 import java.util.*;
8 import java.util.logging.Logger JavaDoc;
9
10 import com.ca.directory.jxplorer.search.*;
11 import com.ca.commons.naming.*;
12 import com.ca.directory.jxplorer.tree.*;
13 import com.ca.commons.cbutil.*;
14 import com.ca.commons.security.KeystoreGUI;
15
16 import java.io.File JavaDoc;
17 import java.io.IOException JavaDoc;
18
19
20 public class MainMenu extends JMenuBar
21 {
22
23      //XXX in a fantasy alternate universe this could be rewritten as Action object
24
//thingumies so that enabling/disabling stuff could be echoed to the button bar. or not.
25
//XXX in the same fantasy universe instantiation of menuitems might be delayed until
26
// the user actually selected the main menu item, thus shaving a few milliseconds
27
// from the load lag time.
28

29     private static Logger JavaDoc log = Logger.getLogger(MainMenu.class.getName());
30
31     JXplorer jxplorer;
32     JXOpenConWin getConnection = null; // the connection window
33

34     JMenu fileMenu;
35     JMenuItem connect, disconnect, print, refreshTree, exit;
36
37     JMenu editMenu;
38     JMenuItem cut, copy, paste, delete, rename, copyDN, newEntry, pasteAlias;
39
40     JMenu ldifMenu;
41     JMenuItem fullExport, subExport, importFile, viewOffline;
42
43     JMenu searchMenu;
44     JMenuItem search, deleteFilter, attrList;
45
46     JMenu bookmarkMenu;
47     JMenuItem editBookmark, addBookmark, deleteBookmark;
48
49     JMenu lookAndFeelMenu;
50     JMenuItem refresh;
51
52     JMenu optionsMenu, toolsMenu;
53     JMenuItem advancedOptions;
54
55     JMenu sslMenu;
56     JMenuItem simpleSSL, authSSL, keystoreOptions;
57
58     JMenu helpMenu;
59     JMenuItem helpContents, helpSearch, helpAbout;
60
61     SmartTree tree;
62
63     String JavaDoc dirIcons;
64     String JavaDoc dirImages;
65     String JavaDoc dirTemplates;
66
67     public static Properties myProperties; // global variables for the browser, read from...
68
public static String JavaDoc propertyFile; // ...a user configurable file storing default properties.
69
public static String JavaDoc localDir; // local directory the browser is being run from...
70
public static String JavaDoc fileURLPrefix; // a prefix that converts local files into a url (e.g. file:///)
71

72     public MainMenu(JXplorer jxplorer)
73     {
74         super();
75         this.jxplorer = jxplorer;
76
77         setImageDirs(); //TE: gets the image and icon dirs.
78

79         /*
80          * This is a long ftn that sets up lots and lots
81          * of menu items.
82          */

83
84         // String constants for menu items
85

86         // Set up the file menu item
87
fileMenu = new JMenu(CBIntText.get("File"));
88         fileMenu.setMnemonic('F');
89         setupFileMenu(fileMenu);
90
91
92         editMenu = new JMenu(CBIntText.get("Edit"));
93         editMenu.setMnemonic('E');
94         setupEditMenu(editMenu);
95
96         // Set up the look and feel view menu
97
lookAndFeelMenu = new JMenu(CBIntText.get("View"));
98         lookAndFeelMenu.setMnemonic('V');
99         setupLookAndFeelMenu(lookAndFeelMenu);
100
101         // Set up the ldif menu item
102
ldifMenu = new JMenu(CBIntText.get("LDIF"));
103         ldifMenu.setMnemonic('L');
104         setupLdifMenu(ldifMenu);
105
106         // Set up the search menu item
107
searchMenu = new JMenu(CBIntText.get("Search"));
108         searchMenu.setMnemonic('S');
109         setupSearchMenu(searchMenu);
110
111          // Set up the bookmark menu item
112
bookmarkMenu = new JMenu(CBIntText.get("Bookmark"));
113         bookmarkMenu.setMnemonic('B');
114         setupBookmarkMenu(bookmarkMenu);
115
116         // Set up the options menu item
117
optionsMenu = new JMenu(CBIntText.get("Options"));
118         optionsMenu.setMnemonic('O');
119         setupOptionsMenu(optionsMenu);
120
121         // Set up the tools menu item
122
toolsMenu = new JMenu(CBIntText.get("Tools"));
123         toolsMenu.setMnemonic('T');
124         setupToolsMenu(toolsMenu);
125
126         // Set up the options menu item
127
sslMenu = new JMenu(CBIntText.get("Security"));
128         sslMenu.setMnemonic('i');
129         setupSSLMenu(sslMenu);
130
131         // Set up the help menu item
132
helpMenu = new JMenu(CBIntText.get("Help"));
133         helpMenu.setMnemonic('H');
134         setupHelpMenu(helpMenu);
135
136         // Set the overall Menu Bar
137
this.add(fileMenu);
138         this.add(editMenu);
139         this.add(lookAndFeelMenu);
140         this.add(bookmarkMenu);
141         this.add(searchMenu);
142         this.add(ldifMenu);
143         this.add(optionsMenu);
144         this.add(toolsMenu);
145         this.add(sslMenu);
146         this.add(helpMenu);
147
148         jxplorer.setJMenuBar(this);
149
150         setDisconnected();
151     }
152
153 /* protected void processEvent(AWTEvent e)
154     {
155 System.out.println(CBIntText.get("snaffled event ") + e.toString());
156         super.processEvent(e);
157
158     }
159 */

160
161     protected void setupFileMenu(JMenu fileMenu)
162     {
163         // setup common menu listener
164

165         ActionListener fileListener = new ActionListener()
166         {
167             public void actionPerformed(ActionEvent e)
168             {
169                 JMenuItem src = ((JMenuItem)e.getSource());
170
171                 tree = jxplorer.getActiveTree();
172
173                 if (src == connect)
174                     connect();
175                 else if (src == disconnect)
176                     disconnect();
177                 else if (src == print)
178                     print();
179                 else if (src == refreshTree)
180                     jxplorer.mrTree.collapse();
181                 else if (src == exit)
182                     jxplorer.shutdown();
183
184                 jxplorer.repaint();
185             }
186         };
187
188         // initialise menu items
189

190         connect = setMenuItem(fileMenu, fileListener,
191             new String JavaDoc[] {CBIntText.get("Connect"), "C", CBIntText.get("Connect to a directory server."), "E", dirImages+"connect.gif" } );
192
193         disconnect = setMenuItem(fileMenu, fileListener,
194             new String JavaDoc[] {CBIntText.get("Disconnect"), "D", CBIntText.get("Disconnect from a directory server."), "E", dirImages+"disconnect.gif" } );
195
196         print = setMenuItem(fileMenu, fileListener,
197             new String JavaDoc[] {CBIntText.get("Print"), "P", CBIntText.get("Print out the current entry."), "E", dirImages+"print.gif" } );
198
199         setMenuItem(fileMenu, fileListener, new String JavaDoc[] {"-", "", "", "" } );
200
201         refreshTree = setMenuItem(fileMenu, fileListener,
202             new String JavaDoc[] {CBIntText.get("Refresh Tree"), "R", CBIntText.get("Forces the tree to be reloaded from the directory."), "E", dirImages+"refresh_all.gif" } );
203
204         setMenuItem(fileMenu, fileListener, new String JavaDoc[] {"-", "", "", "" } );
205
206         exit = setMenuItem(fileMenu, fileListener,
207             new String JavaDoc[] {CBIntText.get("Exit"), "x", CBIntText.get("Quit the JXplorer application."), "E", dirImages+"blank.gif" } );
208
209         ButtonRegister br = JXplorer.getButtonRegister();
210         br.registerItem(br.CONNECT, connect);
211         br.registerItem(br.DISCONNECT, disconnect);
212         br.registerItem(br.PRINT, print);
213         br.registerItem(br.REFRESH_TREE, refreshTree);
214     }
215
216     public void connect()
217     {
218         CBCache.cleanCache(); //TE: deletes any temp files.
219

220         if (getConnection == null)
221         {
222             //TE: the new connection class extends CBOpenConWin...
223
getConnection = new JXOpenConWin(jxplorer, jxplorer.displayLabel,
224                                                 JXplorer.getProperty("option.ssl.clientcerts"),
225                                                 JXplorer.getProperty("option.ssl.cacerts"),
226                                                 JXplorer.getProperty("option.ldap.referral"),
227                                                 JXplorer.getProperty("option.ldap.searchAliasBehaviour"));
228             getConnection.setSize(450,340);
229             CBUtility.center(getConnection, jxplorer);
230         }
231         else
232         {
233             getConnection.reinit( JXplorer.getProperty("option.ssl.clientcerts"),
234                                   JXplorer.getProperty("option.ssl.cacerts"),
235                                   JXplorer.getProperty("option.ldap.referral"),
236                                   JXplorer.getProperty("option.ldap.searchAliasBehaviour"));
237
238         }
239
240         getConnection.resetTitleAndPassword();
241         getConnection.setVisible(true);
242     }
243
244     /**
245      * Called by JX to turn appropriate buttons on.
246      */

247
248     public void setConnected(boolean searchActive)
249     {
250         editMenu.setEnabled(true);
251         searchMenu.setEnabled(searchActive);
252         toolsMenu.setEnabled(true);
253         bookmarkMenu.setEnabled(true);
254     }
255
256     public void disconnect()
257     {
258         jxplorer.disconnect();
259     }
260
261     public void setDisconnected()
262     {
263         editMenu.setEnabled(false);
264         searchMenu.setEnabled(false);
265         toolsMenu.setEnabled(false);
266         bookmarkMenu.setEnabled(false);
267     }
268
269     public void print()
270     {
271         jxplorer.pushStatus("Printing...");
272         jxplorer.mainViewer.print();
273         jxplorer.popStatus();
274     }
275
276     public void setupEditMenu(JMenu editMenu)
277     {
278         // set up a common listener for this menu
279

280         ActionListener editListener = new ActionListener()
281         {
282             public void actionPerformed(ActionEvent e)
283             {
284                 JMenuItem item = (JMenuItem)e.getSource();
285
286                 tree = jxplorer.getActiveTree();
287
288                 if (item == cut)
289                     tree.getPopupTool().cut();
290                 else if (item == copy)
291                     tree.getPopupTool().copy();
292                 else if (item == paste)
293                     tree.getPopupTool().paste();
294                 else if (item == delete)
295                     tree.getPopupTool().delete();
296                 else if (item == rename)
297                     tree.getPopupTool().rename();
298                 else if (item == copyDN)
299                     tree.getPopupTool().copyDN();
300                 else if (item == newEntry)
301                     tree.getPopupTool().newEntry();
302                 else if (item == pasteAlias)
303                     tree.getPopupTool().pasteAlias();
304             }
305         };
306
307         // define the individual menu items
308

309         newEntry = setMenuItem(editMenu, editListener,
310             new String JavaDoc[] {CBIntText.get("New"), "Ctrl+N", CBIntText.get("Create a new entry."), "E", dirImages+"new.gif"} );
311
312         copyDN = setMenuItem(editMenu, editListener,
313             new String JavaDoc[] {CBIntText.get("Copy DN"), "Ctrl+Y", CBIntText.get("Copy the Distinguished Name of an entry to the clipboard."), "E", dirImages+"copy_dn.gif"} );
314
315         setMenuItem(editMenu, editListener, new String JavaDoc[] {"-", "", "", ""} );
316
317         cut = setMenuItem(editMenu, editListener,
318             new String JavaDoc[] {CBIntText.get("Cut Branch"), "Ctrl+U", CBIntText.get("Select a subtree to move."), "E", dirImages+"cut.gif"} );
319
320         copy = setMenuItem(editMenu, editListener,
321             new String JavaDoc[] {CBIntText.get("Copy Branch"), "Ctrl+O", CBIntText.get("Select a subtree to copy."), "E", dirImages+"copy.gif"});
322
323         paste = setMenuItem(editMenu, editListener,
324             new String JavaDoc[] {CBIntText.get("Paste Branch"), "Ctrl+P", CBIntText.get("Paste a previously selected subtree."), "E", dirImages+"paste.gif"} );
325
326         pasteAlias = setMenuItem(editMenu, editListener,
327             new String JavaDoc[] {CBIntText.get("Paste Alias"), "", CBIntText.get("Paste an Alias."), "E", dirIcons+"alias.gif"} );
328
329         setMenuItem(editMenu, editListener, new String JavaDoc[] {"-", "", "", ""} );
330
331         delete = setMenuItem(editMenu, editListener,
332             new String JavaDoc[] {CBIntText.get("Delete"), "Ctrl+D", CBIntText.get("Delete an entry."), "E", dirImages+"delete.gif"} );
333
334         rename = setMenuItem(editMenu, editListener,
335             new String JavaDoc[] {CBIntText.get("Rename"), "Ctrl+M", CBIntText.get("Rename an entry."), "E", dirImages+"rename.gif"} );
336
337         ButtonRegister br = JXplorer.getButtonRegister();
338         br.registerItem(br.PASTE, paste);
339         br.registerItem(br.PASTE_ALIAS, pasteAlias);
340         br.registerItem(br.COPY, copy);
341         br.registerItem(br.COPY_DN, copyDN);
342         br.registerItem(br.CUT, cut);
343         br.registerItem(br.DELETE, delete);
344         br.registerItem(br.NEW, newEntry);
345         br.registerItem(br.RENAME, rename);
346
347         br.setItemEnabled(br.PASTE, false);
348         br.setItemEnabled(br.PASTE_ALIAS, false);
349     }
350
351     public void setupLdifMenu(JMenu ldifMenu)
352     {
353         // define an listener for the ldif menu
354

355         ActionListener ldifListener = new ActionListener()
356         {
357             public void actionPerformed(ActionEvent e)
358             {
359                 JMenuItem item = (JMenuItem)e.getSource();
360
361                 SmartTree activeTree = jxplorer.getActiveTree();
362                 boolean usingSearch = (activeTree == jxplorer.searchTree);
363
364                 if (item == fullExport)
365                     ldifFullExport(activeTree, usingSearch);
366                 else if (item == subExport)
367                     ldifSubExport(activeTree, usingSearch);
368                 else if (item == importFile)
369                     importFile();
370                 else if (item == viewOffline)
371                     viewOffline();
372
373                 jxplorer.repaint();
374             }
375         };
376
377         // define the individual options.
378

379         fullExport = setMenuItem(ldifMenu, ldifListener,
380             new String JavaDoc[] {CBIntText.get("Export Full Tree"), "x", CBIntText.get("Export an LDIF file of the entire tree."), "E", ""} );
381
382         subExport = setMenuItem(ldifMenu, ldifListener,
383             new String JavaDoc[] {CBIntText.get("Export Subtree"), "p", CBIntText.get("Export an LDIF file of the current subtree."), "E", ""} );
384
385         importFile = setMenuItem(ldifMenu, ldifListener,
386             new String JavaDoc[] {CBIntText.get("Import File"), "I", CBIntText.get("Import an LDIF file into the directory."), "E", ""} );
387
388         viewOffline = setMenuItem(ldifMenu, ldifListener,
389             new String JavaDoc[] {CBIntText.get("View Offline"), "w", CBIntText.get("View an LDIF file off-Line, without adding to a directory."), "E", ""} );
390
391         ButtonRegister br = JXplorer.getButtonRegister();
392         br.registerItem(br.LDIF, fullExport);
393         br.registerItem(br.LDIF, subExport);
394         br.registerItem(br.LDIF, importFile);
395     }
396
397     public void ldifFullExport(SmartTree activeTree, boolean usingSearch)
398     {
399         DN base = activeTree.getRootDN();
400         DataSource datasource = activeTree.getDataSource();
401         LdifExport export = new LdifExport(base, datasource, jxplorer.searchTree, usingSearch, jxplorer, HelpIDs.LDIF_EXPORT_TREE);
402         export.setSize(360,120);
403         export.setTitle(CBIntText.get("Export Full Tree"));
404         CBUtility.center(export, jxplorer);
405         export.setVisible(true);
406     }
407
408     public void ldifSubExport(SmartTree activeTree, boolean usingSearch)
409     {
410         DN base = activeTree.getCurrentDN();
411         DataSource datasource = activeTree.getDataSource();
412         LdifExport export = new LdifExport(base, datasource, jxplorer.searchTree, usingSearch, jxplorer, HelpIDs.LDIF_EXPORT_SUBTREE);
413         export.setSize(360,120);
414         export.setTitle(CBIntText.get("Export Subtree"));
415         CBUtility.center(export, jxplorer);
416         export.setVisible(true);
417     }
418
419     public void importFile()
420     {
421         DataSource datamodifier;
422         if (jxplorer.workOffline)
423             datamodifier = (DataSource)jxplorer.offlineBroker;
424         else
425         {
426             if (jxplorer.jndiBroker.isActive())
427                 datamodifier = (DataSource)jxplorer.jndiBroker;
428             else
429             {
430                 CBUtility.error(jxplorer, "Error: Not Connected! (Did You Want to 'View Offline'?)");
431                 return;
432             }
433         }
434         LdifImport imp = new LdifImport(datamodifier, jxplorer.mrTree, jxplorer, null);
435     }
436
437     public void viewOffline()
438     {
439         disconnect();
440         jxplorer.setStatus("Working Offline");
441         jxplorer.workOffline = true ;
442         jxplorer.offlineBroker.clear();
443         jxplorer.mrTree.registerDataSource(jxplorer.offlineBroker);
444         jxplorer.mrTree.setRoot(new DN(SmartTree.NODATA));
445         LdifImport imp = new LdifImport(jxplorer.offlineBroker, jxplorer.mrTree, jxplorer, null);
446
447         // XXX This activates the rest of the LDIF menu, *but* it will leave the LDIF menu activated
448
// XXX even if the view offline load fails for some reason :-(. Not sure how to fix this
449
// XXX problem... - CB
450

451         ButtonRegister br = JXplorer.getButtonRegister();
452         br.setItemEnabled(br.LDIF, true);
453
454     }
455
456
457
458    /**
459     * Sets up the search menu with menu items and listeners. Dynamically adds search filter names to the
460     * menu. If there is more than 15, these names are added to a scrollable list. A search is conducted
461     * if a user selects one of these names.
462     * @param searchMenu the actual search menu that needs to be set up.
463     */

464
465     protected void setupSearchMenu(JMenu searchMenu)
466     {
467         final SearchModel sm = new SearchModel();
468
469         searchMenu.removeAll();
470
471         ArrayList list = sm.getFilterNames(SearchModel.FULLNAMES); //TE: get the full names of the saved search filters.
472
Object JavaDoc names[] = list.toArray();
473         Arrays.sort(names, new SearchModel.StringComparator()); //TE: sort the list alphabetically.
474

475         ActionListener searchListener = new ActionListener()
476         {
477             public void actionPerformed(ActionEvent e)
478             {
479                 JMenuItem item = (JMenuItem)e.getSource();
480
481                 if (item == search)
482                 {
483                     tree = jxplorer.getActiveTree();
484                     tree.openSearch(); //TE: open the search window (via Smart Tree).
485
}
486                 else if (item == deleteFilter)
487                 {
488                     if (sm.getFilterNames(SearchModel.ALLFILTERS).size()==0)
489                     {
490                         JOptionPane.showMessageDialog(jxplorer, CBIntText.get("There are no filters available to delete."), CBIntText.get("Nothing to Delete"), JOptionPane.INFORMATION_MESSAGE );
491                         return;
492                     }
493                     else
494                     {
495                         DeleteFilterGUI dfg = new DeleteFilterGUI(jxplorer); //TE: open the delete filter dialog.
496
dfg.setVisible(true);
497                     }
498                 }
499                 else if (item == attrList)
500                 {
501                      ReturnAttributesDialog rad = new ReturnAttributesDialog(jxplorer);
502                      rad.setVisible(true);
503                 }
504                 else
505                 {
506                     doSearch(item.getText(), ((myJMenuItem)item).getToolTipText());
507                 }
508
509                 jxplorer.repaint();
510             }
511         };
512
513         search = setMenuItem(searchMenu, searchListener,
514             new String JavaDoc[] {CBIntText.get("Search Dialog"), "Ctrl+F", CBIntText.get("Search the directory."), "E", dirImages+"find.gif"} );
515
516         deleteFilter = setMenuItem(searchMenu, searchListener,
517             new String JavaDoc[] {CBIntText.get("Delete Filter"), "", CBIntText.get("Delete an existing filter."), "E", dirImages+"delete.gif"} );
518
519         attrList = setMenuItem(searchMenu, searchListener,
520             new String JavaDoc[] {CBIntText.get("Return Attribute Lists"), "", CBIntText.get("Opens a dialog that lets you manage the attributes that you wish to be returned in a search."), "E", dirImages+"return_attrs.gif"} );
521
522         if(names.length > 0)
523             setMenuItem(searchMenu, searchListener, new String JavaDoc[] {"-", "", "", "", ""} );
524
525         ButtonRegister br = JXplorer.getButtonRegister();
526         br.registerItem(br.SEARCH, search);
527
528         String JavaDoc[] searchValues = new String JavaDoc[names.length];
529         String JavaDoc[] searchNames = new String JavaDoc[names.length];
530
531         for(int i=0; i<names.length;i++)
532         {
533             String JavaDoc key = names[i].toString();
534             searchNames[i] = key;
535             searchValues[i] = sm.getLDAPFilter(searchNames[i]);
536             searchNames[i] = searchNames[i].startsWith("JXFilter") ? searchNames[i].substring(9) : searchNames[i].substring(13); //TE: cut the prefix off (e.g: either 'JXFilter' or 'JXTextFilter').
537
}
538
539         if (names.length>15) //TE: add a scrollable list rather than a blown out menu!
540
{
541             searchMenu.add(getScrollList(searchNames, searchValues, searchMenu));
542         }
543         else
544         {
545             for(int i=0;i<names.length;i++)
546             {
547                 myJMenuItem searchMenuItem = new myJMenuItem(searchNames[i]);
548                 searchMenuItem.name = searchValues[i];
549                 setMenuItem(searchMenu, searchMenuItem, searchListener, new String JavaDoc[] {"", "", searchValues[i], "E", ""});
550             }
551         }
552     }
553
554
555
556    /**
557     * Runs the search. Uses the saved search params from the property file if there
558     * is any.
559     * @param name the name of the saved filter.
560     * @param filter the LDAP filter.
561     */

562
563     public void doSearch(String JavaDoc name, String JavaDoc filter)
564     {
565         SearchModel sm = new SearchModel();
566
567         //TE: base DN...
568
String JavaDoc baseDN = sm.getValue(name+"."+SearchModel.BASEDN);
569         DN dn = (baseDN==null) ? jxplorer.getActiveTree().getCurrentDN() : new DN(baseDN);
570
571         //TE: search level (base object, one level, full subtree)...
572
int searchLevel = 2;
573         try
574         {
575             searchLevel = Integer.parseInt(sm.getValue(name+"."+SearchModel.SEARCHLEVEL));
576         }
577         catch(NumberFormatException JavaDoc e)
578         {
579             searchLevel = 2;
580         }
581
582         //TE: Return attributes...
583
String JavaDoc retAttrs = sm.getValue(name+"."+SearchModel.RETATTRS);
584         String JavaDoc[] retAttrsList = null;
585
586         if (retAttrs == null) // CB if it isn't specified, just return object class
587
{
588             retAttrsList = new String JavaDoc[] {"objectClass"};
589         }
590         else if (retAttrs.equalsIgnoreCase(ReturnAttributesDialog.DEFAULT_RETURN_ATTRS)) // CB to return all attributes, use the magic value 'null' (see jndi.search() methods)
591
{
592             retAttrs = null;
593         }
594         else //TE: there is a list of return attributes so get it...
595
{
596             retAttrsList = ReturnAttributesDialog.getReturnAttributes(retAttrs);
597             sm.openRetAttrDisplay(jxplorer, retAttrsList, (jxplorer.getSearchTree()).getDataSource());
598         }
599
600         // Get the alias options...
601
String JavaDoc find = name+"."+SearchModel.FIND;
602         String JavaDoc search = name+"."+SearchModel.SEARCH;
603
604         String JavaDoc aliasOption = "always";
605
606         if (search.equalsIgnoreCase("false") && find.equalsIgnoreCase("false"))
607             aliasOption = "never";
608         else if (search.equalsIgnoreCase("true") && find.equalsIgnoreCase("false"))
609             aliasOption = "searching";
610         else if (search.equalsIgnoreCase("false") && find.equalsIgnoreCase("true"))
611             aliasOption = "finding";
612
613         log.info("Setting search alias option to: ["+aliasOption+"]");
614         JXplorer.setProperty("option.ldap.searchAliasBehaviour", aliasOption);
615
616         //TE: run the search...
617
SearchExecute.run(jxplorer.getSearchTree(),
618                             dn,
619                             filter,
620                             retAttrsList,
621                             searchLevel,
622                             jxplorer.getSearchBroker());
623
624         //TE: go to results tab...
625
jxplorer.getTreeTabPane().setSelectedComponent(jxplorer.getResultsPanel());
626     }
627
628
629
630    /**
631     * Enables or disables the search menu items (below the separator).
632     * @param state disabled if false, enabled if true.
633     */

634
635     public void setSearchEnabled(boolean state)
636     {
637         if(searchMenu==null)
638             return;
639
640         int items = searchMenu.getItemCount();
641
642         for(int i=0;i<items;i++)
643         {
644             JMenuItem temp = searchMenu.getItem(i);
645
646             if(temp instanceof myJMenuItem)
647                 temp.setEnabled(state);
648         }
649         searchMenu.repaint();
650     }
651
652
653
654    /**
655     * Calls the set up for the search menu. Used to dynamically update the filter names within the search menu.
656     */

657
658     public void updateSearchMenu()
659     {
660         setupSearchMenu(searchMenu);
661     }
662
663
664
665    /**
666     * Sets up a scrollable list with given items and tooltips. Adds a listener to each list item.
667     * @param items an array of things (usually strings that are added to the list.
668     * @param toolTips and array of strings used as the tooltips for the items (i.e. tooltip[x] goes with item[x]).
669     * @param menuType the menu that the listener is reponding to (either the search menu or the bookmark menu).
670     * @return the scroll pane with the list and listeners added.
671     */

672
673     protected JScrollPane getScrollList(Object JavaDoc[] items, String JavaDoc[] toolTips, JMenu menuType)
674     {
675         final Object JavaDoc[] names = items;
676         final String JavaDoc[] toolTps = toolTips;
677         final JMenu type = menuType;
678
679         final JList list = new JList(names)
680         {
681             public String JavaDoc getToolTipText(MouseEvent e) //TE: add a tool tip!
682
{
683                 int index = locationToIndex(e.getPoint());
684                 if (-1 < index)
685                     return toolTps[index];
686                 else
687                     return null;
688             }
689         };
690         list.setToolTipText("");
691         list.setBackground(Color.lightGray);
692
693         list.addListSelectionListener(new ListSelectionListener (){
694             public void valueChanged(ListSelectionEvent e){
695                 if (e.getSource() == list && !e.getValueIsAdjusting()) //TE: listener registers mouse down and mouse release! This is only to work on the mouse release!
696
{
697                     if (type==searchMenu) //TE: search menu action.
698
{
699                         doSearch(names[list.getSelectedIndex()].toString(), toolTps[list.getSelectedIndex()]);
700                         //SearchExecute.run(jxplorer.getSearchTree(), jxplorer.getActiveTree().getCurrentDN(), toolTps[list.getSelectedIndex()], null, 2, jxplorer.getSearchBroker());
701
//jxplorer.getTreeTabPane().setSelectedComponent(jxplorer.getResultsPanel());
702
searchMenu.getPopupMenu().setVisible(false); //TE: kill the menu (wont do it automatically with the list in it).
703
searchMenu.setSelected(false);
704                     }
705                     else if (type==bookmarkMenu) //TE: bookmark menu action.
706
{
707                         jxplorer.getTreeTabPane().setSelectedIndex(0);
708                         goToBookmark(toolTps[list.getSelectedIndex()].toString(), jxplorer.getActiveTree());
709                         bookmarkMenu.getPopupMenu().setVisible(false); //TE: kill the menu (wont do it automatically with the list in it).
710
bookmarkMenu.setSelected(false);
711                     }
712                 }
713         }});
714
715         JScrollPane sp = new JScrollPane(list);
716         sp.setPreferredSize(new Dimension(100, 300));
717         sp.setMinimumSize(new Dimension(100, 300));
718         sp.setAlignmentX(LEFT_ALIGNMENT);
719
720         return sp;
721     }
722
723
724
725    /**
726     * Sets up the bookmark menu with menu items and listeners. Dynamically adds bookmark names to the
727     * menu. If there is more than 15, these names are added to a scrollable list. If a user selects
728     * one of these names, the tree jumps to that entry.
729     * @param bookmarkMenu the bookmark menu.
730     */

731
732     protected void setupBookmarkMenu(JMenu bookmarkMenu)
733     {
734         bookmarkMenu.removeAll();
735
736         ActionListener bookmarkListener = new ActionListener()
737         {
738             public void actionPerformed(ActionEvent e)
739             {
740                 JMenuItem item = (JMenuItem)e.getSource();
741
742                 jxplorer.getTreeTabPane().setSelectedIndex(0);
743
744                 tree = jxplorer.getActiveTree();
745
746                 if (item == editBookmark)
747                     tree.openEditBookmarkDialog();
748                 else if (item == addBookmark)
749                     tree.openAddBookmarkDialog(jxplorer.mrTree.getCurrentDN());
750                 else if (item == deleteBookmark)
751                     tree.openDeleteBookmarkDialog();
752                 else
753                     goToBookmark(((myJMenuItem)item).name, tree);
754
755                 jxplorer.repaint();
756             }
757         };
758
759         addBookmark = setMenuItem(bookmarkMenu, bookmarkListener,
760         new String JavaDoc[] {CBIntText.get("Add Bookmark"), "Ctrl+B", CBIntText.get("Add a bookmark from the current DN."), "E", dirImages+"plus.gif"} );
761
762         deleteBookmark = setMenuItem(bookmarkMenu, bookmarkListener,
763         new String JavaDoc[] {CBIntText.get("Delete Bookmark"),"d", CBIntText.get("Delete a bookmark."), "E", dirImages+"delete.gif"} );
764
765         editBookmark = setMenuItem(bookmarkMenu, bookmarkListener,
766         new String JavaDoc[] {CBIntText.get("Edit Bookmark"),"i", CBIntText.get("Edit your bookmarks."), "E", dirImages+"edit.gif"} );
767
768
769         ButtonRegister br = JXplorer.getButtonRegister();
770         br.registerItem(br.BOOKMARKS, addBookmark);
771
772         Properties propertyList = CBUtility.readPropertyFile("bookmarks.txt");
773
774         DXNamingEnumeration keys = new DXNamingEnumeration(propertyList.keys());
775
776         if(keys.size() > 0)
777             setMenuItem(bookmarkMenu, bookmarkListener, new String JavaDoc[] {"-", "", "", "", ""} );
778
779         Hashtable bookmarkTable = new Hashtable();
780
781         while (keys.hasMoreElements())
782         {
783             String JavaDoc key = keys.nextElement().toString();
784             if (key.toLowerCase().startsWith("dn"))
785                 bookmarkTable.put(key.substring(key.indexOf(".")+1), propertyList.getProperty(key));
786         }
787
788         DXNamingEnumeration en = new DXNamingEnumeration(bookmarkTable.keys());
789         en.sort();
790
791         int size = en.size();
792
793         String JavaDoc[] bookmarkVals = new String JavaDoc[size];
794         String JavaDoc[] bookmarkNams = new String JavaDoc[size];
795
796         int j=0;
797         while(en.hasMore())
798         {
799             bookmarkNams[j] = (String JavaDoc)en.next();
800             bookmarkVals[j] = (String JavaDoc)bookmarkTable.get(bookmarkNams[j]);
801             j++;
802         }
803
804         if (size>15)
805         {
806             bookmarkMenu.add(getScrollList(bookmarkNams, bookmarkVals, bookmarkMenu));
807         }
808         else
809         {
810             for(int i=0; i<bookmarkVals.length; i++)
811             {
812                 myJMenuItem bookmarkMenuItem = new myJMenuItem(bookmarkNams[i]);
813                 bookmarkMenuItem.name = bookmarkVals[i];
814                 setMenuItem(bookmarkMenu, bookmarkMenuItem, bookmarkListener, new String JavaDoc[] {"", "", "Go to: " + bookmarkVals[i]+".", "E", ""});
815             }
816         }
817     }
818
819
820
821    /**
822     * Enables or disables the bookmark menu items (not the add or edit items - just the actual
823     * saved bookmarks).
824     * @param state disabled if false, enabled if true.
825     */

826
827     public void setBookmarksEnabled(boolean state)
828     {
829         if(bookmarkMenu==null)
830             return;
831
832         int items = bookmarkMenu.getItemCount();
833
834         for(int i=0;i<items;i++)
835         {
836             JMenuItem temp = bookmarkMenu.getItem(i);
837
838             if(temp instanceof myJMenuItem)
839                 temp.setEnabled(state);
840         }
841         bookmarkMenu.repaint();
842     }
843
844
845
846    /**
847     * Extends JMenuItem to add a public string that can be used to store the
848     * name of the menu item.
849     */

850
851     public class myJMenuItem extends JMenuItem
852     {
853
854
855         public String JavaDoc name;
856
857
858        /**
859         * Constructor that creates a menuItem with text.
860         */

861
862         public myJMenuItem(String JavaDoc s) { super(s); }
863     }
864
865
866
867    /**
868     * Calls the set up for the bookmark menu. Used to dynamically update the bookmark names within the bookmark menu.
869     */

870
871     public void updateBookmarkMenu()
872     {
873         setupBookmarkMenu(bookmarkMenu);
874     }
875
876
877
878    /**
879     * Tries to display the entry that the user asks for via a bookmark. It tries to
880     * expand the children of all the parents instead of just displaying the
881     * direct parents of the entry in question.
882     * @param dn the dn of the entry that is to be opened.
883     * @param tree the tree that holds all the entries.
884     *
885     */

886
887     public void goToBookmark(String JavaDoc dn, SmartTree tree)
888     {
889         tree.readAndExpandDN(new DN(dn));
890     }
891
892
893
894     /**
895      * View menu setup. Adds two check boxes; the first is for displaying the button bar
896      * and the second is for displaying the search bar in JX.
897      */

898     protected void setupLookAndFeelMenu(JMenu lookAndFeelMenu)
899     {
900        String JavaDoc status = ("false".equals(JXplorer.getProperty("gui.buttonbar")))?"U":"C";
901        setCheckBoxMenu(lookAndFeelMenu, new String JavaDoc[][] {{CBIntText.get("Show Button Bar"),"B", CBIntText.get("Display the shortcut button toolbar."), "E", status, dirImages+"blank.gif"}},
902             new ActionListener()
903             {
904                 public void actionPerformed(ActionEvent e)
905                 {
906                     boolean selected = ((JCheckBoxMenuItem)e.getSource()).isSelected();
907                     jxplorer.buttonBar.setVisible(selected);
908                     jxplorer.repaint();
909                     JXplorer.setProperty("gui.buttonbar", String.valueOf(selected));
910                 }
911             }
912         );
913
914
915         status = ("false".equals(JXplorer.getProperty("gui.searchbar")))?"U":"C";
916
917         setCheckBoxMenu(lookAndFeelMenu, new String JavaDoc[][] {{CBIntText.get("Show Search Bar"),"w", CBIntText.get("Show the quick search tool bar."), "E", status, dirImages+"blank.gif"}},
918             new ActionListener()
919             {
920                 public void actionPerformed(ActionEvent e)
921                 {
922                     boolean selected = ((JCheckBoxMenuItem)e.getSource()).isSelected();
923                     jxplorer.searchBar.setVisible(selected);
924                     jxplorer.repaint();
925                     JXplorer.setProperty("gui.searchbar", String.valueOf(selected));
926                 }
927             }
928         );
929
930         ActionListener viewListener = new ActionListener()
931         {
932             public void actionPerformed(ActionEvent e)
933             {
934                 JMenuItem item = (JMenuItem)e.getSource();
935
936                 tree = jxplorer.getActiveTree();
937
938                 if (item == refresh)
939                     tree.getPopupTool().refresh();
940
941                 jxplorer.repaint();
942             }
943         };
944
945         setMenuItem(lookAndFeelMenu, viewListener, new String JavaDoc[] {"-", "", "", "", ""} );
946
947         refresh = setMenuItem(lookAndFeelMenu, viewListener,
948             new String JavaDoc[] {CBIntText.get("Refresh"), "Ctrl+R",CBIntText.get("Refreshes an Entry."), "E", dirImages+"refresh.gif"} );
949
950         ButtonRegister br = JXplorer.getButtonRegister();
951         br.registerItem(br.REFRESH, refresh);
952     }
953
954
955
956     /**
957      * This is a bit evil - it links various options, saved in the
958      * dxconfig.txt java properties file, with user menu items. To
959      * do this requires a few quick utility classes derived from menu
960      * items, which automatically read and set various properties.
961      */

962     protected void setupOptionsMenu(JMenu optionsMenu)
963     {
964        // confirm tree operation check box.
965

966
967         //boolean initStatus = !("false".equalsIgnoreCase(jxplorer.myProperties.getProperty("option.confirmTreeOperations")));
968

969         /*
970          * A quickie inner class, to give us a JCheckBoxMenuItem that will check
971          * and update from a particular property before repainting (so that if
972          * the property has been changed elsewhere, the menu bar still displays
973          * the correct value...)
974          */

975
976         class PropertyCheckBoxMenuItem extends JCheckBoxMenuItem
977         {
978             final String JavaDoc propName;
979
980             public PropertyCheckBoxMenuItem(String JavaDoc s, String JavaDoc propertyName)
981             {
982                 super(CBIntText.get(s), true); // state reset on first paint (see below).
983
propName = propertyName;
984
985                 addActionListener(new ActionListener() {
986                     public void actionPerformed(ActionEvent e) {
987                         JXplorer.myProperties.setProperty(propName, String.valueOf(getState()));
988                         jxplorer.repaint();
989                     }
990                 });
991             }
992
993             // property may be externally changed: recheck every paint!
994
public void paint(Graphics g)
995             { // weird !("false"... syntax to force default case to be true...
996
boolean state = !("false".equalsIgnoreCase(JXplorer.myProperties.getProperty(propName)));
997                 if (state != getState()) setState(state); // nb - this triggers another paint...!
998
super.paint(g);
999             }
1000        }
1001
1002        final PropertyCheckBoxMenuItem confirmOps;
1003        final PropertyCheckBoxMenuItem confirmTableEditorUpdates;
1004        final PropertyCheckBoxMenuItem checkSchema;
1005        final JCheckBoxMenuItem browserSearchAliases;
1006
1007        confirmOps =
1008            new PropertyCheckBoxMenuItem(CBIntText.get("Confirm Tree Operations"), "option.confirmTreeOperations");
1009        setMenuItemState(optionsMenu, confirmOps, "C", CBIntText.get("Prompt the user whenever the tree will be modified?"), true);
1010
1011        confirmTableEditorUpdates =
1012            new PropertyCheckBoxMenuItem(CBIntText.get("Confirm Table Editor Updates"), "option.confirmTableEditorUpdates");
1013        setMenuItemState(optionsMenu, confirmTableEditorUpdates, "T", CBIntText.get("Display message to confirm successful updates in Table Editor?"), true);
1014
1015        checkSchema =
1016            new PropertyCheckBoxMenuItem(CBIntText.get("Ignore Schema Checking"), "option.ignoreSchemaOnSubmission");
1017        setMenuItemState(optionsMenu, checkSchema, "g", CBIntText.get("Don't check entry consistency before submission."), true);
1018
1019        browserSearchAliases =
1020            new JCheckBoxMenuItem(CBIntText.get("Resolve Aliases while Browsing"));
1021        setMenuItemState(optionsMenu, browserSearchAliases, "A", CBIntText.get("Whether to browse the referenced object, or the alias entry itself."), true);
1022        browserSearchAliases.setState("finding".equals(JXplorer.getProperty("option.ldap.browseAliasBehaviour")));
1023
1024        //TE: defines a listener for the Advanced Options menu item of the Options menu.
1025
ActionListener optionsListener = new ActionListener()
1026        {
1027            public void actionPerformed(ActionEvent e)
1028            {
1029                JMenuItem item = (JMenuItem)e.getSource();
1030
1031                if (item == advancedOptions)
1032                {
1033                    setUpAdvancedOptions(); //TE: sets up the AdvancedOptions dialog when user clicks on this menu item.
1034
}
1035                jxplorer.repaint();
1036            }
1037        };
1038
1039        advancedOptions = setMenuItem(optionsMenu, optionsListener,
1040                    new String JavaDoc[] {CBIntText.get("Advanced Options"), "d", CBIntText.get("Open the Advanced Options dialog."), "E", ""} );
1041
1042        // add *another* action listener for specific handling...
1043
browserSearchAliases.addActionListener(new ActionListener() {
1044            public void actionPerformed(ActionEvent e) {
1045                try
1046                {
1047                    if (browserSearchAliases.isSelected())
1048                    {
1049                        JXplorer.setProperty("option.ldap.browseAliasBehaviour", "finding");
1050                        if (jxplorer.jndiBroker.getDirContext() != null)
1051                        {
1052                            jxplorer.jndiBroker.getDirContext().addToEnvironment("java.naming.ldap.derefAliases", "finding");
1053                            //System.out.println("set to: " + jxplorer.jndiBroker.getDirContext().getEnvironment().get("java.naming.ldap.derefAliases"));
1054
}
1055                    }
1056                    else
1057                    {
1058                        JXplorer.setProperty("option.ldap.browseAliasBehaviour", "never");
1059                        if (jxplorer.jndiBroker.getDirContext() != null)
1060                        {
1061                            jxplorer.jndiBroker.getDirContext().addToEnvironment("java.naming.ldap.derefAliases", "never");
1062                            //System.out.println("set to: " + jxplorer.jndiBroker.getDirContext().getEnvironment().get("java.naming.ldap.derefAliases"));
1063
}
1064                    }
1065                }
1066                catch (Exception JavaDoc e2) {} // XXX probably never happen :-)
1067
}
1068        });
1069    }
1070
1071
1072
1073   /**
1074    * Sets up the advanced options dialog (written so that it is set up when the user clicks on the menu item
1075    * instead of being set up when JX starts. The problem with advanced options being set up when JX starts
1076    * (or really when MainMenu is set up) is that it forces CBHelpSystem to over ride the Thread priority so that
1077    * a Help Set is supplied.
1078    */

1079
1080    protected void setUpAdvancedOptions()
1081    {
1082        AdvancedOptions adOpt = new AdvancedOptions(jxplorer, this);
1083        CBUtility.center(adOpt, jxplorer);
1084        adOpt.setVisible(true);
1085    }
1086
1087
1088    protected void setupSSLMenu(JMenu sslMenu)
1089    {
1090        ActionListener sslListener = new ActionListener()
1091        {
1092            public void actionPerformed(ActionEvent e)
1093            {
1094                JMenuItem item = (JMenuItem)e.getSource();
1095
1096                if (item == simpleSSL)
1097                {
1098                    KeystoreGUI win = new KeystoreGUI(jxplorer, JXplorer.getMyProperties(),
1099                                                     JXplorer.getProperty(JXplorer.CA_PATH_PROPERTY),
1100                                                     null,
1101                                                     JXplorer.getProperty(JXplorer.CA_TYPE_PROPERTY),
1102                                                     CBIntText.get("Manage Your Trusted Server Certificates."),
1103                                                     false, HelpIDs.SSL_CERTS);
1104                    win.setSize(450,320);
1105                    CBUtility.center(win, jxplorer);
1106                    win.setVisible(true); // may modify jxplorer properties
1107
}
1108                else if (item == authSSL)
1109                {
1110                    KeystoreGUI win = new KeystoreGUI(jxplorer, JXplorer.getMyProperties(),
1111                                                     JXplorer.getProperty(JXplorer.CLIENT_PATH_PROPERTY),
1112                                                     null,
1113                                                     JXplorer.getProperty(JXplorer.CLIENT_TYPE_PROPERTY),
1114                                                     CBIntText.get("Manage Your Own Private Keys and Certificates."),
1115                                                     true, HelpIDs.SSL_CERTS);
1116                    win.setSize(450,440);
1117                    CBUtility.center(win, jxplorer);
1118                    win.setVisible(true); // may modify jxplorer properties
1119
}
1120
1121                /*
1122                 * allow the user to select which keystore files and keystore types to use.
1123                 */

1124
1125                else if (item == keystoreOptions)
1126                {
1127                    KeystoreOptions options = new KeystoreOptions(jxplorer, JXplorer.getMyProperties());
1128                    options.setSize(530,260);
1129                    CBUtility.center(options, jxplorer);
1130                    options.setVisible(true);
1131                }
1132                jxplorer.repaint();
1133            }
1134        };
1135
1136        simpleSSL = setMenuItem(sslMenu, sslListener,
1137            new String JavaDoc[] {CBIntText.get("Trusted Servers and CAs"),"u",
1138                          CBIntText.get("Setup which servers you trust for SSL."),
1139                          "E", dirImages+"sslcert.gif"} ); //TE: changed mnemonic from 'S' to 'u'.
1140

1141        authSSL = setMenuItem(sslMenu, sslListener,
1142            new String JavaDoc[] {CBIntText.get("Client Certificates"),"C",
1143                          CBIntText.get("Setup client authentication (if available)."),
1144                          ("none".equals(JXplorer.getProperty("authprovider"))?"D":"E"), dirImages+"sslkeycert.gif"} );
1145
1146        keystoreOptions = setMenuItem(sslMenu, sslListener,
1147            new String JavaDoc[] {CBIntText.get("Advanced Keystore Options"),"K",
1148                          CBIntText.get("Select your keystore locations and the type of keystore to use."),
1149                          "E", dirImages+"blankRec.gif"} );
1150
1151    }
1152
1153
1154    protected void setupToolsMenu(JMenu toolsMenu)
1155    {
1156        String JavaDoc [][] toolsMenuItems =
1157                { {CBIntText.get("Stop Action"),"A", CBIntText.get("Stop the currently executing browser action."), "E", dirImages+"stop.gif"} };
1158
1159        setMenu(toolsMenu, toolsMenuItems, new ActionListener()
1160        {
1161            public void actionPerformed(ActionEvent e)
1162            {
1163                String JavaDoc cmd = ((JMenuItem)e.getSource()).getName();
1164
1165                if (cmd.equals(CBIntText.get("Stop Action")))
1166                {
1167                    jxplorer.getStopMonitor().show();
1168                }
1169                jxplorer.repaint();
1170            }
1171        });
1172
1173        //TE: only enables the stop menu item if there is a query to stop. If the stop menu
1174
// item is repositioned up date the getItem(0) method to the appropriate index.
1175
jxplorer.getStopMonitor().addWatcher(toolsMenu.getItem(0));
1176    }
1177
1178
1179    protected void setupHelpMenu(JMenu helpMenu)
1180    {
1181        ActionListener helpListener = new ActionListener()
1182        {
1183            public void actionPerformed(ActionEvent e)
1184            {
1185                JMenuItem item = (JMenuItem)e.getSource();
1186
1187                if (jxplorer.helpSystem == null && item != helpAbout) // reality check - the help system
1188
{ // seems a bit flaky
1189
CBUtility.error(jxplorer, "Unable to open Help System", null);
1190                    return;
1191                }
1192
1193                if (item == helpContents)
1194                    jxplorer.helpSystem.openTab(HelpIDs.TAB_TOC); //TE: opens the help with the table of contents tab visible.
1195
else if (item == helpSearch) //TE: opens the help with the search tab visible.
1196
jxplorer.helpSystem.openTab(HelpIDs.TAB_SEARCH);
1197                else if (item == helpAbout)
1198                    showAboutMessage();
1199
1200                jxplorer.repaint();
1201            }
1202        };
1203
1204        helpContents = setMenuItem(helpMenu, helpListener,
1205            new String JavaDoc[] {CBIntText.get("Contents"), "C", CBIntText.get("Display the help index."), "E", dirImages+"content.gif" } );
1206
1207        helpSearch = setMenuItem(helpMenu, helpListener,
1208            new String JavaDoc[] {CBIntText.get("Search"), "r", CBIntText.get("Search help for a keyword."), "E", dirImages+"search.gif" } );
1209
1210        setMenuItem(helpMenu, helpListener, new String JavaDoc[] {"-", "", "", "", "" } ); // separator
1211

1212        helpAbout = setMenuItem(helpMenu, helpListener,
1213            new String JavaDoc[] {CBIntText.get("About"), "A", CBIntText.get("General information about JXplorer."), "E", dirImages+"about.gif" } );
1214
1215
1216
1217    }
1218
1219   /**
1220    * Displays an about dialog in the center of JXplorer.
1221    * Switch display depending on whether it is the open source version or the commercial version...
1222    */

1223    public void showAboutMessage()
1224    {
1225        // Open source license...
1226
File JavaDoc licence = new File JavaDoc(System.getProperty("user.dir") + File.separator + "licence.txt");
1227        if (licence.exists())
1228        {
1229            String JavaDoc textBody = JXplorer.version+"\n\nCopyright \u00a9 2005 CA. All rights reserved.";
1230
1231            try
1232            {
1233                textBody = CBUtility.readTextFile(licence);
1234                textBody = JXplorer.version + "\n" +
1235                           "\nWritten by: Chris Betts" +
1236                           "\n Trudi Ersvaer\n" +
1237                           "\nThanks to: Jason Paul" +
1238                           "\n Lachlan O'Dea" +
1239                           "\n Van Bui\n\n\n" +
1240                           textBody;
1241
1242            }
1243            catch (IOException JavaDoc e) {} // should still be set to original CA text.
1244

1245            CBAbout about = new CBAbout(jxplorer, textBody, new ImageIcon(dirTemplates + "JXAboutBottom.gif"),
1246                        new ImageIcon(dirTemplates + "JXAboutTop.gif"), CBIntText.get("OK"), CBIntText.get("Close this window"), CBIntText.get("About JXplorer"));
1247
1248            about.setSize(477, 350);
1249            about.setResizable(true);
1250            CBUtility.center(about, jxplorer);
1251            about.setVisible(true);
1252        }
1253        else
1254        {
1255            /* I don't think we can ship with the CA tau code?? - CB
1256            // CA license...
1257            File ca_licence = new File(System.getProperty("user.dir") + File.separator + "ca_license.txt");
1258            String textBody = null;
1259            try
1260            {
1261                textBody = CBUtility.readTextFile(ca_licence);
1262            }
1263            catch (IOException e)
1264            {
1265                e.printStackTrace();
1266            }
1267
1268            AboutBox about = new AboutBox(jxplorer, "eTrust™ Directory JXplorer", JXplorer.version, "", "", textBody, HelpIDs.CONTACT_SUPPORT);
1269            about.setVisible(true);
1270            */

1271        }
1272    }
1273
1274
1275
1276   /**
1277    * Utility function; sets up a menu with a bunch of menu items
1278    * defined as strings, with tooltips and enabled/disabled state.<p>
1279    *
1280    * ... assumes listeners will be created for them elsewhere, and registered
1281    * here.
1282    * @param menu the menu object to add this menu item to
1283    * @param menuItems an array of string arrays defining the various menu items: <br>
1284    * each string array should have 4 elements:
1285    * {"item name", "mnemonic", "tool tip text", enabled/disabled state ("E"/"D")}
1286    * @param listener - a thingumy to monitor the menu item, and do something if it's
1287    * checked.
1288    */

1289
1290    protected void setMenu(JMenu menu, String JavaDoc [][] menuItems, ActionListener listener)
1291    {
1292        for (int i=0;i<menuItems.length;i++)
1293        {
1294            JMenuItem item = setMenuItem(menu, listener, menuItems[i]);
1295        }
1296    }
1297
1298    /**
1299     * Sets up a menu item with a list of strings
1300     * @param menu the menu to add this menu item to
1301     * @param menuItems - an array of 4 strings; the name, the hot key, the tip, and a single letter 'E' or 'D' for enabled/disabled
1302     * @param listener an action listener for this menu item.
1303     * @return the created menu item
1304     */

1305
1306    protected JMenuItem setMenuItem(JMenu menu, ActionListener listener, String JavaDoc[] menuItems)
1307    {
1308        if (menuItems[0].equals("-"))
1309        {
1310            menu.add(new JSeparator());
1311            return null;
1312        }
1313        else
1314        {
1315            JMenuItem item = new JMenuItem(CBIntText.get(menuItems[0]), new ImageIcon(menuItems[4]));
1316            item.setName(menuItems[0]); //TE: gives the menu item a name...fixes bug 2447 re stop button (because stop button was not assigned with a name).
1317
return setMenuItem(menu, item, listener, menuItems);
1318        }
1319    }
1320
1321
1322   /**
1323    * Sets up a menu item with a list of strings
1324    * @param menu the menu to add this menu item to
1325    * @param menuItems - an array of 4 strings; the name, the hot key, the tip, and a single letter 'E' or 'D' for enabled/disabled
1326    * @param listener an action listener for this menu item.
1327    * @return the created menu item
1328    */

1329
1330    protected JMenuItem setMenuItem(JMenu menu, JMenuItem item, ActionListener listener, String JavaDoc[] menuItems)
1331    {
1332        //item.setName(menuItems[0]);
1333

1334        setMenuItemState(menu, item, menuItems[1], menuItems[2], (menuItems[3].charAt(0)=='E'));
1335        if (listener != null) item.addActionListener(listener);
1336        return item;
1337    }
1338
1339   /**
1340    * Similar to @setMenu, but for checkboxes. Note arguments; the string array is an
1341    * element longer (to allow setting of check box state).
1342    * @param menu the menu object to add this menu item to
1343    * @param menuItems an array of string arrays defining the various menu items: <br>
1344    * each string array should have 5 elements:
1345    * {"item name", "mnemonic", "tool tip text", enabled/disabled state ("E"/"D"), and
1346    * checked/unchecked state ("C"/"U") }
1347    * @param listener - a thingumy to monitor the menu item, and do something if it's
1348    * checked.
1349    */

1350
1351   protected void setCheckBoxMenu(JMenu menu, String JavaDoc [][] menuItems, ActionListener listener)
1352    {
1353        for (int i=0;i<menuItems.length;i++)
1354        {
1355            if (menuItems[i][0].equals("-"))
1356                menu.add(new JSeparator());
1357            else
1358            {
1359                JCheckBoxMenuItem tmp = new JCheckBoxMenuItem(menuItems[i][0], new ImageIcon(menuItems[i][5]), (menuItems[i][4].charAt(0)=='C'));
1360                setMenuItemState(menu, tmp, menuItems[i][1], menuItems[i][2], (menuItems[i][3].charAt(0)=='E'));
1361                if (listener != null) tmp.addActionListener(listener);
1362            }
1363        }
1364    }
1365
1366    /**
1367     * Takes a menu Item and sets up state information such as the mnemonic, the tool tip
1368     * text and the enabled/disabled state.
1369     * @param menu the parent menu.
1370     * @param menuItem the menu item being modified
1371     * @param mnemonic the hot key (alt-'key', or prefixed with "ctr"+'key')
1372     * @param toolTipText text displayed when the mouse hovers over component
1373     * @param enabled whether the menu item is active, or greyed out.
1374     */

1375
1376    protected void setMenuItemState(JMenu menu, JMenuItem menuItem, String JavaDoc mnemonic, String JavaDoc toolTipText, boolean enabled)
1377    {
1378        if (mnemonic.length()==1)
1379        {
1380            menuItem.setMnemonic(mnemonic.charAt(0));
1381        }
1382        else if (mnemonic.startsWith("Cnt")||mnemonic.startsWith("cnt")||mnemonic.startsWith("Ctr")||mnemonic.startsWith("ctr"))
1383        {
1384            char C = mnemonic.charAt(mnemonic.length()-1);
1385            menuItem.setAccelerator(KeyStroke.getKeyStroke(C, java.awt.Event.CTRL_MASK, false));
1386        }
1387        menuItem.setToolTipText(toolTipText);
1388        menuItem.setEnabled(enabled);
1389        menu.add(menuItem);
1390    }
1391
1392
1393
1394   /**
1395    * Sets the image & icon paths.
1396    */

1397
1398    public void setImageDirs()
1399    {
1400        dirImages = JXplorer.getProperty("dir.images");
1401        dirIcons = JXplorer.getProperty("dir.icons");
1402        dirTemplates = JXplorer.getProperty("dir.templates");
1403    }
1404}
Popular Tags