KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > dialog > view > ClassSelector


1 /***
2  * FractalGUI: a graphical tool to edit Fractal component configurations.
3  * Copyright (C) 2003 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: fractal@objectweb.org
20  *
21  * Authors: Eric Bruneton, Patrice Fauvel
22  */

23
24 package org.objectweb.fractal.gui.dialog.view;
25
26 import java.awt.Color JavaDoc;
27 import java.awt.Container JavaDoc;
28 import java.awt.Dimension JavaDoc;
29 import java.awt.Font JavaDoc;
30 import java.awt.FontMetrics JavaDoc;
31 import java.awt.BorderLayout JavaDoc;
32 import java.awt.FlowLayout JavaDoc;
33 import java.awt.GridLayout JavaDoc;
34 import java.awt.GridBagConstraints JavaDoc;
35 import java.awt.GridBagLayout JavaDoc;
36 import java.awt.AWTEvent JavaDoc;
37 import java.awt.event.ActionEvent JavaDoc;
38 import java.awt.event.ActionListener JavaDoc;
39 import java.awt.event.WindowEvent JavaDoc;
40 import java.awt.Insets JavaDoc;
41 import java.awt.Component JavaDoc;
42
43 import java.util.Enumeration JavaDoc;
44 import java.util.Iterator JavaDoc;
45 import java.util.List JavaDoc;
46 import java.util.TreeMap JavaDoc;
47 import java.util.TreeSet JavaDoc;
48 import java.util.ArrayList JavaDoc;
49 import java.util.jar.JarFile JavaDoc;
50 import java.util.zip.ZipEntry JavaDoc;
51
52 import java.lang.reflect.Method JavaDoc;
53
54 import java.net.URL JavaDoc;
55
56 import java.io.File JavaDoc;
57 import java.io.FileInputStream JavaDoc;
58 import java.io.FileOutputStream JavaDoc;
59 import java.io.PrintStream JavaDoc;
60 import javax.swing.BorderFactory JavaDoc;
61 import javax.swing.ListCellRenderer JavaDoc;
62 import javax.swing.DefaultListModel JavaDoc;
63 import javax.swing.ImageIcon JavaDoc;
64 import javax.swing.JDialog JavaDoc;
65 import javax.swing.JLabel JavaDoc;
66 import javax.swing.JList JavaDoc;
67 import javax.swing.JMenu JavaDoc;
68 import javax.swing.JPanel JavaDoc;
69 import javax.swing.JTabbedPane JavaDoc;
70 import javax.swing.JTextArea JavaDoc;
71 import javax.swing.JButton JavaDoc;
72 import javax.swing.JScrollPane JavaDoc;
73 import javax.swing.text.Document JavaDoc;
74 import javax.swing.event.DocumentListener JavaDoc;
75 import javax.swing.event.DocumentEvent JavaDoc;
76 import javax.swing.event.ListSelectionListener JavaDoc;
77 import javax.swing.event.ListSelectionEvent JavaDoc;
78
79 public class ClassSelector extends JDialog JavaDoc implements
80   ActionListener JavaDoc,
81   DocumentListener JavaDoc
82 {
83   static String JavaDoc LS = new String JavaDoc (System.getProperty ("line.separator"));
84   static String JavaDoc FS = new String JavaDoc (System.getProperty ("file.separator"));
85   static String JavaDoc UD = new String JavaDoc (System.getProperty ("user.dir"));
86   static String JavaDoc CP = new String JavaDoc (System.getProperty ("java.class.path"));
87   static String JavaDoc PS = new String JavaDoc (System.getProperty ("path.separator"));
88
89   static String JavaDoc EXIT = "Exit";
90   static String JavaDoc UP = "Up";
91   static String JavaDoc SELECT = "Select";
92   static String JavaDoc SEARCH = "Implem.";
93
94   static int SEL_INT = 1;
95   static int SEL_CLA = 2;
96   int WIDTH = 600;
97   int HEIGHT = 600;
98
99   int filter = SEL_INT + SEL_CLA;
100
101   List JavaDoc lp = new ArrayList JavaDoc ();
102   List JavaDoc lpgen = new ArrayList JavaDoc ();
103
104   URL JavaDoc urlc, urli, urlp;
105
106   ImageIcon JavaDoc imgClasse;
107   ImageIcon JavaDoc imgInterface;
108   ImageIcon JavaDoc imgPackage;
109   JMenu JavaDoc menu, menuo;
110   File JavaDoc f;
111   FileInputStream JavaDoc fis;
112   FileOutputStream JavaDoc fos = null;
113   PrintStream JavaDoc of = null;
114   Container JavaDoc cp;
115 // Color buttonColor = new Color(202, 153, 153);
116
Color JavaDoc buttonColor = new Color JavaDoc(204, 255, 204);
117   Color JavaDoc buttonColor1 = new Color JavaDoc(180, 224, 180);
118   Color JavaDoc baseColor = new Color JavaDoc(200, 200, 164);
119   Color JavaDoc classColor = new Color JavaDoc (255, 255, 204);
120   Font JavaDoc buttonFont = new Font JavaDoc("Arial", Font.PLAIN, 9);
121   Font JavaDoc normalFont = new Font JavaDoc("Arial", Font.PLAIN, 11);
122   Font JavaDoc menuFont = new Font JavaDoc("Arial", Font.BOLD, 12);
123   Font JavaDoc listFont = new Font JavaDoc("MonoSpaced", Font.PLAIN, 11);
124   int nc = 0;
125   int MAX = 3;
126   JTabbedPane JavaDoc jtp;
127   TreeMap JavaDoc mapImport = new TreeMap JavaDoc ();
128
129   String JavaDoc [] path = new String JavaDoc[MAX];
130   CapLabel [] clb = new CapLabel [MAX];
131   DefaultListModel JavaDoc lmAll;
132   CapList cplAll;
133   DefaultListModel JavaDoc lmClass;
134   CapList cplClass;
135   CapTextArea transit;
136   CapButton b_up = new CapButton (UP, buttonColor1);
137   CapButton b_search = new CapButton (SEARCH, buttonColor1);
138   CapButton b_select = new CapButton (SELECT, buttonColor);
139   CapButton b_exit = new CapButton (EXIT, buttonColor);
140   String JavaDoc libIntrf = "(Interface)";
141   String JavaDoc libClass = "(Class)";
142   String JavaDoc libPackg = "(Package)";
143   String JavaDoc [] noms = {
144     "Packages, Classes and Interfaces",
145     "Looking for Implementation ",
146   };
147   String JavaDoc prefix = new String JavaDoc ("");
148   String JavaDoc curInterf = new String JavaDoc ("");
149   static String JavaDoc retour = "";
150   int z = 1;
151
152   public ClassSelector () {
153     this.setTitle("Please, make your selection");
154     this.setModal(true);
155
156     // ---
157
enableEvents (AWTEvent.WINDOW_EVENT_MASK);
158     // ---
159

160     urlc = getClass().getResource("/org/objectweb/fractal/gui/resources/classe.gif");
161     imgClasse = new ImageIcon JavaDoc(urlc);
162     urli = getClass().getResource("/org/objectweb/fractal/gui/resources/interface.gif");
163     imgInterface = new ImageIcon JavaDoc(urli);
164     urlp = getClass().getResource("/org/objectweb/fractal/gui/resources/package.gif");
165     imgPackage = new ImageIcon JavaDoc(urlp);
166
167     cp = getContentPane();
168     cp.setForeground (Color.black);
169
170     for (int i = 0; i < 2; i++) {
171       clb[i] = new CapLabel (noms[i]);
172     }
173     lmAll = new DefaultListModel JavaDoc();
174     lmClass = new DefaultListModel JavaDoc();
175     cplAll = new CapList (lmAll, "All");
176     cplClass = new CapList (lmClass, "Class");
177     cplAll.setCellRenderer(new MyRenderer(1024));
178     cplClass.setCellRenderer(new MyRenderer(1024));
179     cplClass.setBackground(classColor);
180
181     transit = new CapTextArea (true);
182     transit.getDocument().addDocumentListener(this);
183     GridBagLayout JavaDoc gbl = new GridBagLayout JavaDoc ();
184     GridBagConstraints JavaDoc gbc = new GridBagConstraints JavaDoc();
185     cp.setLayout (gbl);
186
187     gbc.insets = new Insets JavaDoc (5, 2, 2, 5);
188
189     // --- row #0
190

191     gbc.gridy = 0;
192     gbc.weightx = 0;
193     gbc.weighty = 0;
194     gbc.fill = GridBagConstraints.BOTH;
195     gbc.anchor = GridBagConstraints.NORTHWEST;
196     gbc.gridx = 0;
197     b_up.addActionListener(this);
198     JPanel JavaDoc jp = new JPanel JavaDoc ();
199     jp.setLayout(new BorderLayout JavaDoc());
200     jp.add(clb[0], BorderLayout.WEST);
201     jp.add(b_up, BorderLayout.EAST);
202     gbl.setConstraints(jp, gbc);
203     cp.add (jp);
204
205     // --- row #1
206

207     gbc.gridx = 0;
208     gbc.gridy = 1;
209     gbc.weightx = 1;
210     gbc.weighty = 0.8;
211     JPanel JavaDoc jp1 = new JPanel JavaDoc ();
212     jp1.setLayout(new FlowLayout JavaDoc(FlowLayout.LEFT, 0, 0));
213     jp1.add(cplAll);
214     jp1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
215     JScrollPane JavaDoc jsp = new JScrollPane JavaDoc (jp1);
216     jsp.setPreferredSize(new Dimension JavaDoc (WIDTH, 60));
217     //jsp.setWheelScrollingEnabled(true); // JDK1.4?
218
jsp.getVerticalScrollBar().setUnitIncrement(6);
219     jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
220     gbl.setConstraints(jsp, gbc);
221     cp.add (jsp);
222
223     // --- row #2
224

225     gbc.gridx = 0;
226     gbc.gridy = 2;
227     gbc.weightx = 0;
228     gbc.weighty = 0;
229     b_select.addActionListener(this);
230     b_search.addActionListener(this);
231     b_exit.addActionListener(this);
232     b_select.setUsable(false);
233     JPanel JavaDoc jpb = new JPanel JavaDoc (new GridLayout JavaDoc (1, 3));
234     jpb.add(b_exit);
235     jpb.add(b_select);
236     jpb.add(b_search);
237
238     JPanel JavaDoc jpi = new JPanel JavaDoc ();
239     jpi.setLayout(new BorderLayout JavaDoc());
240     jpi.add(clb[1], BorderLayout.WEST);
241     jpi.add(jpb, BorderLayout.EAST);
242     gbl.setConstraints(jpi, gbc);
243     cp.add (jpi);
244
245     // --- row #3
246

247     gbc.gridx = 0;
248     gbc.gridy = 3;
249     gbc.weightx = 0;
250     gbc.weighty = 1;
251
252     jtp = new JTabbedPane JavaDoc ();
253
254     JPanel JavaDoc jp1c = new JPanel JavaDoc ();
255     jp1c.setLayout(new FlowLayout JavaDoc(FlowLayout.LEFT, 0, 0));
256     jp1c.add(cplClass);
257     jp1c.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
258     JScrollPane JavaDoc jspc = new JScrollPane JavaDoc (jp1c);
259     jspc.setPreferredSize(new Dimension JavaDoc (WIDTH, 60));
260     //jspc.setWheelScrollingEnabled(true); // JDK1.4?
261
jspc.getVerticalScrollBar().setUnitIncrement(6);
262     jspc.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
263     jtp.addTab ("Implementation(s)", imgClasse, jspc);
264
265     JScrollPane JavaDoc jsinf = new JScrollPane JavaDoc (transit);
266     jtp.addTab ("interface's method(s)", jsinf);
267     b_up.setUsable(false);
268     b_search.setUsable(false);
269
270     gbl.setConstraints(jtp, gbc);
271     cp.add (jtp);
272
273     // ---------------------------------
274

275     initList();
276     remakeList ();
277
278     // ---------------------------------
279
pack ();
280     setSize (WIDTH, HEIGHT);
281     show ();
282   }
283
284   public static String JavaDoc initSelector () {
285     new ClassSelector ();
286     // ----
287
return (retour);
288   }
289
290   private void refreshLooking () {
291     clb[1].setText(noms[1]);
292     b_select.setUsable(false);
293     lmClass.clear();
294     transit.setText("");
295   }
296
297   // ------------------------------------------------------
298
// DocumentListener
299
// ------------------------------------------------------
300

301   public void insertUpdate(DocumentEvent JavaDoc e) {
302     modifyListCommand (e);
303   }
304
305   public void removeUpdate(DocumentEvent JavaDoc e) {
306     modifyListCommand (e);
307   }
308
309   public void changedUpdate(DocumentEvent JavaDoc e) {
310     modifyListCommand (e);
311   }
312
313   private void modifyListCommand (DocumentEvent JavaDoc e) {
314     try {
315       Document JavaDoc d = e.getDocument();
316       int i = 0;
317       String JavaDoc st = d.getText(0, d.getLength());
318       transit.setText(st);
319     } catch (Exception JavaDoc ex) { }
320   }
321
322   // ------------------------------------------------------
323
// Utilitaires internes
324
// ------------------------------------------------------
325

326
327   protected void processWindowEvent (WindowEvent JavaDoc e)
328   {
329     if (e.getID() == WindowEvent.WINDOW_CLOSING) {
330       super.processWindowEvent (e);
331 // System.exit(0);
332
}
333   }
334
335   // ------------------------------------------------------
336
// ActionListener
337
// ------------------------------------------------------
338

339   public void actionPerformed (ActionEvent JavaDoc e) {
340     if (e.getActionCommand().equals(EXIT)) {
341       if (of != null) of.close();
342       retour = "";
343       dispose ();
344     }
345     else if (e.getActionCommand().equals(SELECT)) {
346       if (of != null) of.close();
347       dispose ();
348     }
349     else if (e.getActionCommand().equals(UP)) {
350       int i = prefix.lastIndexOf('.');
351       if (i < 1) {
352         prefix = "";
353         b_up.setUsable(false);
354       }
355       else prefix = prefix.substring(0, i);
356       remakeList ();
357       refreshLooking ();
358     }
359     else if (e.getActionCommand().equals(SEARCH)) {
360       int i = curInterf.lastIndexOf('.');
361       if (i < 1) {
362         clb[1].setText(noms[1]+"of "+curInterf);
363       } else {
364         clb[1].setText(noms[1]+"of [...] "+curInterf.substring(i));
365       }
366       makeClassList ();
367       jtp.setSelectedIndex(0);
368       b_search.setUsable(false);
369     }
370   }
371
372   // ------------------------------------------------------
373
// initList
374
// ------------------------------------------------------
375

376   public void initList () {
377     int i = 999999;
378     String JavaDoc cp = new String JavaDoc (CP+PS.charAt(0));
379     lpgen.clear();
380
381     while (i > 0) {
382       i = cp.indexOf(PS.charAt(0)); if (i < 1) break;
383       lp.add(cp.substring(0, i));
384       cp = cp.substring(i+1);
385     }
386
387     for (i = 0; i < lp.size(); i++) {
388       String JavaDoc morcif = (String JavaDoc)lp.get(i);
389
390       // --- 1) jar files
391
if (morcif.endsWith(".jar")) {
392         try {
393           JarFile JavaDoc jf = new JarFile JavaDoc (morcif);
394           for (Enumeration JavaDoc zipe = jf.entries() ; zipe.hasMoreElements() ;) {
395             ZipEntry JavaDoc zip = (ZipEntry JavaDoc)zipe.nextElement();
396             if (zip.getName().endsWith(".class")) {
397               lpgen.add(zip.getName().replace('/', '.'));
398             }
399           }
400         }
401         catch (Exception JavaDoc ex) { ex.printStackTrace(); continue; }
402       }
403
404       // --- 2) directories
405
else {
406         try {
407           scanDir (morcif, morcif);
408         } catch (Exception JavaDoc ex) { ex.printStackTrace(); continue; }
409       }
410     }
411   }
412
413   // -----
414

415   public void scanDir (String JavaDoc namefile, String JavaDoc base) throws Exception JavaDoc {
416     if (namefile == null) return;
417     File JavaDoc f = new File JavaDoc (namefile);
418
419     if (f.isDirectory()) {
420       File JavaDoc []files = f.listFiles();
421       if (files == null) return;
422       for (int i = 0; i < files.length; i++) {
423         scanDir (namefile+FS+files[i].getName(), base);
424       }
425     } else {
426       if (!(namefile.endsWith(".class"))) return;
427       String JavaDoc classname = namefile.substring(base.length()+1);
428       lpgen.add (classname.replace(FS.charAt(0), '.'));
429     }
430   }
431
432   // ------------------------------------------------------
433
// remakeList
434
// ------------------------------------------------------
435

436   public void remakeList () {
437     TreeMap JavaDoc lcomb = new TreeMap JavaDoc ();
438     ClassLoader JavaDoc cl = this.getClass().getClassLoader();
439     b_search.setUsable(false);
440
441     // --- making and displaying lcomb
442

443     int len = prefix.length();
444
445     for (int i = 0; i < lpgen.size(); i++) {
446       String JavaDoc item = (String JavaDoc)lpgen.get(i);
447       if ((len > 0) && (!item.startsWith(prefix+"."))) continue;
448       if (item.length() <= len) continue;
449       String JavaDoc litem;
450       if (len == 0) litem = item;
451       else litem = item.substring(len+1);
452       char c = litem.charAt(0);
453       int d;
454       if (c > 'Z') d = (int)c-32;
455       else d = c;
456       try {
457         String JavaDoc subName = (char)d+litem.substring(0, litem.indexOf('.'));
458         String JavaDoc nature = (String JavaDoc)lcomb.get(subName);
459         if (nature != null) continue;
460         lcomb.put(subName, item);
461       } catch (Exception JavaDoc ignore) { continue; }
462     }
463     lmAll.clear();
464
465     TreeSet JavaDoc ts = new TreeSet JavaDoc (lcomb.keySet());
466     for (Iterator JavaDoc it = ts.iterator(); it.hasNext();) {
467       String JavaDoc sta = (String JavaDoc)it.next();
468       String JavaDoc st = sta.substring(1);
469       if ((st.charAt(0) < 'A') || (st.charAt(0) > 'Z')) {
470         lmAll.addElement (new JLabel JavaDoc(putLabel(st, libPackg),
471           imgPackage, JLabel.LEFT));
472       } else {
473         if (prefix.length() > 1) st = prefix+"."+st;
474           try {
475             Class JavaDoc cla = cl.loadClass (st);
476           if (cla.isInterface()) {
477             if ((filter & SEL_INT) == 0) continue;
478             lmAll.addElement (new JLabel JavaDoc(putLabel(st, libIntrf),
479               imgInterface, JLabel.LEFT));
480           } else {
481             if ((filter & SEL_CLA) == 0) continue;
482             lmAll.addElement (new JLabel JavaDoc(putLabel(st, libClass),
483               imgClasse, JLabel.LEFT));
484           }
485         }
486         catch (Error JavaDoc er) { continue; }
487         catch (Exception JavaDoc ex) { continue; }
488       }
489     }
490     int z = lmAll.getSize();
491     while (z < 20) {
492       lmAll.addElement(new JLabel JavaDoc("", JLabel.LEFT));
493       z++;
494     }
495   }
496
497   private String JavaDoc putLabel (String JavaDoc st, String JavaDoc label) {
498     String JavaDoc white =
499       " ";
500     FontMetrics JavaDoc fm = cplAll.fm;
501     int space = fm.charWidth(' ');
502     int d = 0;
503     for (int z = 0; z < st.length(); z++) d = d + fm.charWidth(st.charAt(z));
504     int n = (WIDTH - 140 - d)/space;
505     if (n < 1) n = 1;
506     return (st+white.substring(0, n)+label);
507   }
508
509   // ------------------------------------------------------
510
// makeClassList
511
// ------------------------------------------------------
512

513   public void makeClassList () {
514     TreeMap JavaDoc lcomb = new TreeMap JavaDoc ();
515     ClassLoader JavaDoc cl = this.getClass().getClassLoader();
516
517     // --- making and displaying lcomb
518

519     for (int i = 0; i < lpgen.size(); i++) {
520       String JavaDoc item = (String JavaDoc)lpgen.get(i);
521
522       int j = item.indexOf(".class");
523       if (j < 1) continue;
524
525       try {
526           Class JavaDoc cla = cl.loadClass (item.substring(0, j));
527         if (cla.isInterface()) continue;
528
529         Class JavaDoc[] lcl = cla.getInterfaces();
530         for (int z = 0; z < lcl.length; z++) {
531           if (lcl[z].getName().equals(curInterf)) {
532             lcomb.put (item, "zz");
533             break;
534           }
535         }
536       }
537       catch (Error JavaDoc er) { continue; }
538       catch (Exception JavaDoc ex) { continue; }
539     }
540     lmClass.clear();
541
542     // -----
543

544     TreeSet JavaDoc ts = new TreeSet JavaDoc (lcomb.keySet());
545     for (Iterator JavaDoc it = ts.iterator(); it.hasNext();) {
546       String JavaDoc sta = (String JavaDoc)it.next();
547       String JavaDoc st = sta.substring(0);
548       lmClass.addElement (new JLabel JavaDoc(st, JLabel.LEFT));
549     }
550     int z = lmClass.getSize();
551     while (z < 20) {
552       lmClass.addElement(new JLabel JavaDoc("", JLabel.LEFT));
553       z++;
554     }
555   }
556
557   // ------------------------------------------------------
558
// display of interface's method(s)
559
// ------------------------------------------------------
560

561   public void display () {
562     ClassLoader JavaDoc cl = this.getClass().getClassLoader();
563     transit.setText("");
564     mapImport.clear();
565
566     try {
567       Class JavaDoc cla = cl.loadClass (curInterf);
568       int in = cla.getName().lastIndexOf('.');
569       if (in < 1) {
570         transit.append(" interface "+cla.getName()+" ");
571       }
572       else {
573         transit.append(" package "+cla.getName().substring(0, in)+";"+LS+LS);
574         transit.append(" interface "+cla.getName().substring(in+1)+" ");
575       }
576
577       Class JavaDoc[] interf = cla.getInterfaces();
578       if (interf.length == 0) transit.append("{"+LS);
579       else transit.append("extends "+LS);
580       for (int i = 0; i < interf.length; i++) {
581         transit.append(" "+reduc(interf[i].getName()));
582         if (i == interf.length-1) transit.append (" {");
583         transit.append (LS);
584       }
585       transit.append (LS);
586
587       Method JavaDoc[] mets = cla.getDeclaredMethods();
588       for (int i = 0; i < mets.length; i++) {
589         transit.append(" "+reduc(mets[i].getReturnType().getName())+" "
590           +reduc(mets[i].getName()));
591
592         Class JavaDoc [] param = mets[i].getParameterTypes();
593         if (param.length == 0) {
594           transit.append (" ();"+LS+LS);
595           continue;
596         }
597         transit.append(" (");
598         char virgule = ',';
599         for (int j = 0; j < param.length; j++) {
600           if (j == param.length-1) virgule = ')';
601           if (j != 0) transit.append(" ");
602           transit.append (reduc(param[j].getName())+" p"+j+virgule+LS);
603         }
604         transit.append(LS);
605       }
606       transit.append(" }"+LS);
607
608       if (mapImport.size() == 0) return;
609
610       String JavaDoc total = transit.getText();
611       transit.setText("");
612       TreeSet JavaDoc ts = new TreeSet JavaDoc (mapImport.keySet());
613       int d = 0;
614       for (Iterator JavaDoc it = ts.iterator(); it.hasNext();) {
615         transit.append (" import "+(String JavaDoc)it.next()+";"+LS);
616       }
617       transit.append(LS);
618       transit.append(total);
619     }
620     catch (Error JavaDoc er) { }
621     catch (Exception JavaDoc ex) { }
622   }
623
624   private String JavaDoc reduc (String JavaDoc st) {
625     int i = st.lastIndexOf('.');
626     if (i < 1) return st;
627     if (st.substring(0, i).equals("java.lang")) return st;
628     mapImport.put(st, "zz");
629     return st.substring(i+1);
630   }
631
632   // ------------------------------------------------------
633
// Inner Class : CapLabel
634
// ------------------------------------------------------
635

636   class CapLabel extends JLabel JavaDoc {
637     CapLabel (String JavaDoc nom) {
638       super (" "+nom);
639       this.setFont(new Font JavaDoc ("Arial", Font.PLAIN, 12));
640       this.setForeground(Color.black);
641     }
642   }
643
644   // ------------------------------------------------------
645
// Inner Class : CapTextArea
646
// ------------------------------------------------------
647

648   class CapTextArea extends JTextArea JavaDoc {
649     CapTextArea (boolean editable) {
650       super ("", 80, 80);
651       this.setBackground (Color.white);
652       this.setFont(listFont);
653       this.setBorder(BorderFactory.createLoweredBevelBorder());
654       this.setEditable(editable);
655     }
656   }
657
658   // ------------------------------------------------------
659
// Inner Class : CapButton
660
// ------------------------------------------------------
661

662   class CapButton extends JButton JavaDoc {
663     CapButton (String JavaDoc lib, Color JavaDoc color) {
664       super (lib);
665 // setBackground (buttonColor);
666
this.setBackground (color);
667       this.setForeground (Color.black);
668       this.setFont(buttonFont);
669       FontMetrics JavaDoc fm = this.getFontMetrics(buttonFont);
670           int d = 0;
671         for (int z = 0; z< lib.length(); z++) d = d + fm.charWidth(lib.charAt(z));
672       this.setPreferredSize (new Dimension JavaDoc (36+d, 10));
673       this.setEnabled(true);
674     }
675
676     public void setUsable (boolean b) {
677       this.setEnabled (b);
678       this.setOpaque (b);
679     }
680   }
681
682   // ------------------------------------------------------
683
// Inner Class : CapList
684
// ------------------------------------------------------
685

686   class CapList extends JList JavaDoc implements ListSelectionListener JavaDoc {
687     DefaultListModel JavaDoc listmodel;
688     String JavaDoc ident = null;
689     FontMetrics JavaDoc fm;
690
691     CapList (DefaultListModel JavaDoc listModel, String JavaDoc id) {
692       super (listModel);
693       this.setBackground (Color.white);
694       this.setFont(listFont);
695       fm = this.getFontMetrics(this.getFont());
696       setBorder(BorderFactory.createLoweredBevelBorder());
697       listmodel = listModel;
698       this.addListSelectionListener(this);
699       ident = new String JavaDoc (id);
700     }
701
702     // ----- ListSelectionListener
703

704     public void valueChanged (ListSelectionEvent JavaDoc e) {
705       if (e.getValueIsAdjusting() == false) {
706
707         if (this.getSelectedIndex() > -1) {
708           JLabel JavaDoc jlab = (JLabel JavaDoc)listmodel.getElementAt(this.getSelectedIndex());
709           String JavaDoc texte = jlab.getText();
710
711           String JavaDoc util = null;
712           int i = texte.indexOf(' ');
713           if (i > 0) util = texte.substring(0, i);
714           else util = texte;
715
716           // -- Package
717
if (texte.endsWith(libPackg)) {
718             if (prefix.length() < 1) {
719               prefix = prefix.concat(util);
720             } else {
721               prefix = prefix.concat("."+util);
722             }
723             remakeList ();
724             b_up.setUsable(true);
725             refreshLooking ();
726             retour = "";
727           }
728
729           // -- Interface
730
else if (texte.endsWith(libIntrf)) {
731             b_search.setUsable(true);
732             curInterf = util;
733             retour = "";
734             jtp.setSelectedIndex(1);
735             refreshLooking ();
736             display ();
737           }
738
739           // -- Class
740
else {
741             if (ident.equals("Class")) retour = new String JavaDoc(texte);
742             else retour = new String JavaDoc (util);
743             b_select.setUsable(true);
744           }
745         }
746       }
747     }
748   }
749
750   // ------------------------------------------------------
751
// Inner Class : MyRenderer
752
// ------------------------------------------------------
753

754   class MyRenderer extends JLabel JavaDoc implements ListCellRenderer JavaDoc {
755     int w;
756
757     public MyRenderer (int width) {
758       setOpaque(true);
759       setHorizontalAlignment(LEFT);
760       setVerticalAlignment(CENTER);
761       w = width;
762     }
763
764     public Component JavaDoc getListCellRendererComponent (
765       JList JavaDoc list,
766       Object JavaDoc value,
767       int index,
768       boolean isSelected, boolean cellHasFocus) {
769
770       if (isSelected) {
771         this.setBackground(list.getSelectionBackground());
772         this.setForeground(list.getSelectionForeground());
773       } else {
774         this.setBackground(list.getBackground());
775         this.setForeground(list.getForeground());
776       }
777
778       if (value instanceof JLabel JavaDoc) {
779         JLabel JavaDoc jlab = (JLabel JavaDoc)value;
780         ImageIcon JavaDoc icon = (ImageIcon JavaDoc)jlab.getIcon();
781         setText((String JavaDoc)jlab.getText());
782         setIcon (icon);
783         this.setFont (listFont);
784         setPreferredSize(new Dimension JavaDoc(w, 17));
785       }
786       return this;
787     }
788   }
789   // ----- fin classe
790
}
791
Popular Tags