Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/memoire/bu/BuCommonImplementation.java


1   /**
2    * @modification $Date: 2002/12/20 19:05:15 $
3    * @statut       unstable
4    * @file         BuCommonImplementation.java
5    * @version      0.36
6    * @author       Guillaume Desnoix
7    * @email        guillaume@desnoix.com
8    * @license      GNU General Public License 2 (GPL2)
9    * @copyright    1998-2001 Guillaume Desnoix
10   */
11  
12  package com.memoire.bu;
13  
14  import com.memoire.bu.*;
15  import com.memoire.dnd.*;
16  import com.memoire.fu.*;
17  import com.memoire.re.*;
18  
19  
20  import java.awt.*;
21  import java.awt.event.*;
22  import java.beans.*;
23  import java.lang.reflect.*;
24  import java.net.*;
25  import java.util.*;
26  
27  import javax.swing.*;
28  import javax.swing.event.*;
29  import javax.swing.border.*;
30  import javax.swing.plaf.metal.*;
31  
32  /**
33   * Main part of the code to manage BuApplets and BuApplications.
34   * Use to avoid redundant code.
35   */
36  
37  public class BuCommonImplementation
38         implements BuCommonInterface,
39                    ContainerListener, WindowListener, InternalFrameListener
40  {
41    protected BuCommonInterface app_;
42    protected JComponent        content_;
43    protected BuMainPanel       main_panel_;
44    protected BuMenuBar         main_menubar_;
45    protected BuToolBar         main_toolbar_;
46    protected BuSplashScreen    splash_screen_;
47  
48    public BuCommonImplementation()
49    {
50      super();
51  
52      app_         =null;
53      content_     =null;
54      main_panel_  =null;
55      main_menubar_=null;
56      main_toolbar_=null;
57    }
58  
59    // Implementation
60  
61    public BuCommonImplementation getImplementation()
62    { return this; }
63  
64    // App (Application ou Applet)
65  
66    public BuCommonInterface getApp()
67    { return app_; }
68  
69    public void setApp(BuCommonInterface _app)
70    {
71      app_=_app;
72    }
73  
74    /**
75     * Mise en place des elements.
76     * (Panneau principal, barres de menu et de boutons).
77     */
78    public void init()
79    {
80      BuSplashScreen ss=getSplashScreen();
81  
82      if(ss!=null)
83      {
84        ss.setText("Initialisation de l'application");
85        ss.setProgression(20);
86      }
87  
88      content_=new BuPanel();
89      content_.setLayout(new BuBorderLayout());
90      setContentPane(content_);
91  
92      BuMainPanel mp=new BuMainPanel();
93      setMainPanel(mp);
94  
95      if(ss!=null)
96      {
97        ss.setText("Menus");
98        ss.setProgression(30);
99      }
100 
101     BuMenuBar mb=BuMenuBar.buildBasicMenuBar();
102     setMainMenuBar(mb);
103     mb.computeMnemonics();
104     mb.addActionListener(this);
105 
106     if(ss!=null)
107     {
108       ss.setText("Barre d'outils");
109       ss.setProgression(40);
110     }
111 
112     BuToolBar tb=BuToolBar.buildBasicToolBar();
113     setMainToolBar(tb);
114     tb.addActionListener(this);
115 
116     if(ss!=null)
117     {
118       ss.setText("Liste des fenêtres");
119       ss.setProgression(45);
120     }
121 
122     BuMenuInternalFrames mw=(BuMenuInternalFrames)mb.getMenu("LISTE_FENETRES");
123     if(mw!=null) mw.setDesktop(mp.getDesktop());
124   }
125 
126   public void start()
127   {
128     getMainPanel().updateSplits();
129     menusOrganisationFenetres();
130   }
131 
132   public String toString()
133   { return "implementation "+getInformationsSoftware().name; }
134 
135   // CommonInterface
136 
137   public void doLayout()
138   { app_.doLayout(); }
139 
140   public void validate()
141   { app_.validate(); }
142 
143   public void setTitle(String _s)
144   { app_.setTitle(_s); }
145 
146   public BuInformationsSoftware getInformationsSoftware()
147   { return new BuInformationsSoftware(); }
148 
149   public void setJMenuBar(JMenuBar _mb)
150   { app_.setJMenuBar(_mb); }
151 
152   public void setContentPane(Container _c)
153   { app_.setContentPane(_c); }
154 
155   public JRootPane getRootPane()
156   { return app_.getRootPane(); }
157 
158   public Frame getFrame()
159   { return app_.getFrame(); }
160 
161   // Main Panel
162 
163   public BuMainPanel getMainPanel()
164   { return main_panel_; }
165 
166   public void setMainPanel(BuMainPanel _p)
167   {
168     main_panel_=_p; 
169     content_.add(main_panel_,BuBorderLayout.CENTER);
170     content_.doLayout();
171     content_.validate();
172     main_panel_.getDesktop().addContainerListener(this);
173   }
174 
175   // Main MenuBar
176 
177   public BuMenuBar getMainMenuBar()
178   { return main_menubar_; }
179 
180   public void setMainMenuBar(BuMenuBar _mb)
181   {
182     main_menubar_=_mb; 
183     setJMenuBar(main_menubar_);
184   }
185 
186   // Main ToolBar
187 
188   public BuToolBar getMainToolBar()
189   { return main_toolbar_; }
190 
191   public void setMainToolBar(BuToolBar _tb)
192   {
193     main_toolbar_=_tb;
194     if(!(getApp() instanceof BuSubApp))
195     {
196       if((content_.getComponentCount()>1)&&(content_.getComponent(1)!=null))
197   content_.remove(1);
198 
199       if(main_toolbar_!=null)
200       {
201   content_.add(main_toolbar_,BuBorderLayout.NORTH);
202   main_toolbar_.revalidate();
203   // content_.doLayout();
204   // content_.validate();
205       }
206     }
207   }
208 
209   // Specific Bar
210 
211   public BuSpecificBar getSpecificBar()
212   { return getMainPanel().getSpecificBar(); }
213 
214   public void setSpecificBar(BuSpecificBar _sb)
215   { getMainPanel().setSpecificBar(_sb); }
216 
217   // Splash Screen
218 
219   public BuSplashScreen getSplashScreen()
220   { return splash_screen_; }
221 
222   public void setSplashScreen(BuSplashScreen _ss)
223   { splash_screen_=_ss; }
224 
225   // Internal Frames
226 
227   public void addInternalFrame(final JInternalFrame _f)
228   {
229     final InternalFrameListener l=this;
230 
231     Runnable runnable=new Runnable()
232     {
233       public void run()
234       {
235   _f.removeInternalFrameListener(l);
236   _f.addInternalFrameListener(l);
237 
238   BuMainPanel mp=getMainPanel();
239   mp.addInternalFrame(_f);
240 
241   menusOrganisationFenetres();
242       }
243     };
244 
245     if(!SwingUtilities.isEventDispatchThread())
246       SwingUtilities.invokeLater(runnable);
247     else
248       runnable.run();
249   }
250 
251   public void removeInternalFrame(final JInternalFrame _f)
252   {
253     final InternalFrameListener l=this;
254 
255     Runnable runnable=new Runnable()
256     {
257       public void run()
258       {
259   BuMainPanel mp=getMainPanel();
260   mp.removeInternalFrame(_f);
261 
262   _f.removeInternalFrameListener(l);
263 
264   menusOrganisationFenetres();
265       }
266     };
267 
268     if(!SwingUtilities.isEventDispatchThread())
269       SwingUtilities.invokeLater(runnable);
270     else
271       runnable.run();
272   }
273 
274   public void activateInternalFrame(final JInternalFrame _f)
275   {
276     final InternalFrameListener l=this;
277 
278     Runnable runnable=new Runnable()
279     {
280       public void run()
281       {
282   BuMainPanel mp=getMainPanel();
283   mp.activateInternalFrame(_f);
284 
285   menusOrganisationFenetres();
286       }
287     };
288 
289     if(!SwingUtilities.isEventDispatchThread())
290       SwingUtilities.invokeLater(runnable);
291     else
292       runnable.run();
293   }
294 
295   public JInternalFrame getCurrentInternalFrame()
296   {
297     return getMainPanel().getCurrentInternalFrame();
298   }
299   
300   public JInternalFrame[] getAllInternalFrames()
301   {
302     return getMainPanel().getAllInternalFrames();
303   }
304   
305   // Action
306 
307   public void action(String _action)
308   {
309     try
310     {
311       if(_action!=null)
312   actionPerformed(new ActionEvent
313       (this,ActionEvent.ACTION_PERFORMED,_action));
314     }
315     catch(Exception ex) { }
316   }
317 
318   public void actionPerformed(ActionEvent _evt)
319   {
320     String                 action=_evt.getActionCommand();
321     String                 arg   ="";
322     BuMainPanel            mp    =getMainPanel();
323     BuInformationsSoftware il    =getInformationsSoftware();
324 
325     int i=action.indexOf('(');
326     if(i>=0)
327     {
328       arg   =action.substring(i+1,action.length()-1);
329       action=action.substring(0,i);
330     }
331 
332     // System.err.println("BuImplementation: ACTION="+action); 
333     // System.err.println("BuImplementation: ARG   ="+arg); 
334 
335          if(action.equals("FERMER"             )) close();
336     else if(action.equals("IMPRIMER"           )) print();
337     else if(action.equals("PREVISUALISER"      )) preview();
338     else if(action.equals("QUITTER"            )) exit();
339 
340     else if(action.equals("DEFAIRE"            )) undo();
341     else if(action.equals("REFAIRE"            )) redo();
342 
343     else if(action.equals("COUPER"             )) cut();
344     else if(action.equals("COPIER"             )) copy();
345     else if(action.equals("COLLER"             )) paste();
346     else if(action.equals("DUPLIQUER"          )) duplicate();
347 
348     else if(action.equals("TOUTSELECTIONNER"   )) select();
349     else if(action.equals("RECHERCHER"         )) find();
350     else if(action.equals("REMPLACER"          )) replace();
351 
352     else if(action.equals("PLEINECRAN"         )) fullscreen();
353     else if(action.equals("CASCADE"            )) mp.waterfall();
354     else if(action.equals("MOSAIQUE"           )) mp.tile();
355     else if(action.equals("RANGERICONES"       )) mp.arrangeIcons();
356     else if(action.equals("RANGERPALETTES"     )) mp.arrangePalettes();
357     else if(action.equals("ECHANGER_COLONNES"  )) mp.swapColumns();
358 
359     else if(action.equals("ASPECT_AMIGA"       )) setLookAndFeel("swing.addon.plaf.threeD.ThreeDLookAndFeel");
360  // else if(action.equals("ASPECT_BASIC"       )) setLookAndFeel("BuBasicLookAndFeel");
361     else if(action.equals("ASPECT_KUNSTSTOFF"  )) setLookAndFeel("com.incors.plaf.kunststoff.KunststoffLookAndFeel");
362     else if(action.equals("ASPECT_MAC"         )) setLookAndFeel("com.sun.java.swing.plaf.mac.MacLookAndFeel");
363     else if(action.equals("ASPECT_METAL"       )) setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
364     else if(action.equals("ASPECT_METOUIA"     )) setLookAndFeel("net.sourceforge.mlf.metouia.MetouiaLookAndFeel");
365     else if(action.equals("ASPECT_MOTIF"       )) setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
366  // else if(action.equals("ASPECT_MULTI"       )) setLookAndFeel("javax.swing.plaf.multi.MultiLookAndFeel");
367     else if(action.equals("ASPECT_NEXT"        )) setLookAndFeel("nextlf.plaf.NextLookAndFeel");
368     else if(action.equals("ASPECT_ORGANIC"     )) setLookAndFeel("javax.swing.plaf.organic.OrganicLookAndFeel");
369     else if(action.equals("ASPECT_OYOAHA"      )) setLookAndFeel("com.oyoaha.swing.plaf.oyoaha.OyoahaLookAndFeel");
370     else if(action.equals("ASPECT_SKINLF"      )) setLookAndFeel("com.l2fprod.gui.plaf.skin.SkinLookAndFeel");
371     else if(action.equals("ASPECT_SLAF"        )) setLookAndFeel("com.memoire.slaf.SlafLookAndFeel");
372     else if(action.equals("ASPECT_WINDOWS"     )) setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
373 
374     else if(action.startsWith("THEME_METAL"    )) setMetalTheme(arg);
375     else if(action.startsWith("THEME_SLAF"     )) setSlafTheme (arg);
376 
377     else if(action.equals("VISIBLE_SPECIFICBAR")) showOrHide(action,getSpecificBar());
378     else if(action.equals("VISIBLE_LEFTCOLUMN" )) showOrHide(action,mp.getLeftColumn());
379     else if(action.equals("VISIBLE_RIGHTCOLUMN")) showOrHide(action,mp.getRightColumn());
380     else if(action.equals("VISIBLE_STATUSBAR"  )) showOrHide(action,mp.getStatusBar());
381 
382     else if(action.equals("AIDE"               )) displayURL(null);
383     else if(action.equals("AIDE_INDEX"         )) displayURL(il.baseManUrl());
384     else if(action.equals("INDEX_ALPHA"        )) displayURL(il.baseManUrl()+"alphabetique.html");
385     else if(action.equals("INDEX_THEMA"        )) displayURL(il.baseManUrl()+"thematique.html");
386     else if(action.equals("TEXTE_LICENCE"      )) license();
387 
388     else if(action.equals("WWW_ACCUEIL"        )) displayURL(il.http);
389     // else if(action.equals("FTP_ACCUEIL"        )) displayURL(il.ftp);
390 
391     else if(action.startsWith("AIDE_CONTEXTUELLE")) contextHelp(arg);
392     else if(action.equals("POINTEURAIDE"         )) pointerHelp();
393     else if(action.equals("APROPOSDE"            )) about();
394 
395     else if(action.equals("DEBUTER"    )) ;
396     else if(action.equals("QUITTER"    )) exit();
397     else if(action.startsWith("FILLE_" )) daughter(action.substring(6),arg);
398 
399     else System.err.println("UNKNOWN ACTION: "+action);
400   }
401 
402   public void showOrHide(String _a, JComponent _c)
403   {
404     getMainPanel().showOrHide(_c);
405     setCheckedForAction(_a,_c.isVisible());
406   }
407 
408   public void removeAction(String _cmd)
409   {
410     BuActionRemover.removeAction(getMainMenuBar(),_cmd);
411     BuActionRemover.removeAction(getMainToolBar(),_cmd);
412     //BuActionRemover.removeAction(getSpecificBar(),_cmd);
413   }
414 
415   public void setEnabledForAction(String _cmd, boolean _enabled)
416   {
417     BuActionEnabler.setEnabledForAction(getMainMenuBar(),_cmd,_enabled);
418     BuActionEnabler.setEnabledForAction(getMainToolBar(),_cmd,_enabled);
419     //BuActionEnabler.setEnabledForAction(getSpecificBar(),_cmd,_enabled);
420   }
421 
422   public void setCheckedForAction(String _cmd, boolean _checked)
423   {
424     BuActionChecker.setCheckedForAction(getMainMenuBar(),_cmd,_checked);
425     BuActionChecker.setCheckedForAction(getMainToolBar(),_cmd,_checked);
426     //BuActionChecker.setCheckedForAction(getSpecificBar(),_cmd,_checked);
427   }
428 
429   // Divers
430 
431   public void daughter(String _action, String _name)
432   {
433     JInternalFrame[] frames=getMainPanel().getAllInternalFrames();
434 
435     JInternalFrame f=null;
436 
437     for(int i=0; i<frames.length; i++)
438     {
439       String n=frames[i].getName();
440       if(  _name.equals(n)
441    ||("if"+_name).equals(n)
442    ||_name.equals("*")
443    ||_name.equals(frames[i].getTitle()))
444       {
445   f=frames[i];
446   try
447   {
448     if("ACTIVER".equals(_action))
449     {
450       if(f.isIcon()) f.setIcon(false);
451       if(!f.isSelected()) f.setSelected(true);
452     }
453     else if("FERMER".equals(_action))
454     {
455       if(!f.isClosed()) f.setClosed(true);
456     }
457     else if("ICONIFIER"  .equals(_action))
458     {
459       if(!f.isIcon()) f.setIcon(true);
460     }
461     else if("DEICONIFIER".equals(_action))
462     {
463       if(f.isIcon()) f.setIcon(false);
464     }
465     else System.err.println("UNKNOWN SUB-ACTION: "+_action);
466   }
467   catch(PropertyVetoException ex) { }
468       }
469     }
470 
471     if(f==null) System.err.println("UNKNOWN FRAME: "+_name);
472   }
473 
474   private BuGlassPaneHelp glasspane_=null;
475 
476   public void pointerHelp()
477   {
478     BuCommonInterface app=getApp();
479     if(app instanceof BuApplication)
480     {
481       BuApplication appli=(BuApplication)app;
482 
483       if(glasspane_==null)
484       {
485   glasspane_=new BuGlassPaneHelp(appli);
486   glasspane_.setVisible(false);
487       }
488 
489       if(appli.getGlassPane()!=glasspane_)
490   appli.setGlassPane(glasspane_);
491 
492       // System.err.println("SET-GLASSPANE");
493       glasspane_.setVisible(true);
494       appli.invalidate();
495       appli.doLayout();
496       appli.validate();
497       glasspane_.repaint();
498     }
499   }
500 
501   public void contextHelp(String _url)
502   {
503     /*
504     if(_url.startsWith("AIDE_CONTEXTUELLE"))
505       _url=_url.substring(_url.indexOf('(')+1,
506         _url.indexOf(')'));
507     */
508 
509     try
510     {
511       URL    url=new URL(new URL(getInformationsSoftware().man),_url);
512       String ll =Locale.getDefault().getLanguage();
513 
514       _url=url.toString();
515       if(!ll.equals("fr"))
516       {
517   ll="en";
518   int i=_url.lastIndexOf(".html");
519   if(i>=0)
520     _url=_url.substring(0,i)+"-"+ll+_url.substring(i);
521       }
522       System.err.println("URL = "+_url);
523       displayURL(_url);
524     }
525     catch (Exception ex) { }
526   }
527 
528   public void contextHelp(JComponent _c)
529   {
530     if(_c instanceof JInternalFrame)
531       _c=((JInternalFrame)_c).getRootPane();
532 
533     JComponent cp=_c;
534     String param=(String)cp.getClientProperty("HELP_URL");
535 
536     Container pt=cp;
537     while((pt!=null)&&(param==null))
538     {
539       pt=pt.getParent();
540       if(pt instanceof JComponent)
541   param=(String)((JComponent)pt).getClientProperty("HELP_URL");
542     }
543 
544     JComponent focus=_c;
545     if(focus!=null)
546     {
547       String ancre=focus.getName();
548       if(ancre!=null)
549       {
550   int i=0;
551   while(i<ancre.length())
552   {
553     int c=ancre.charAt(i);
554     if((c<'A')||(c>'Z')) i++;
555     else break;
556   }
557   ancre=ancre.substring(i).toLowerCase().replace('_','-');
558   if(!"".equals(ancre)) param+="#"+ancre;
559       }
560 
561       /*
562   else
563   System.err.println("NOT NAMED = "+focus);
564       */
565     }
566 
567     System.err.println("PARAM = "+param);
568     contextHelp(param);
569   }
570 
571   private ActionListener al_=null;
572   private KeyStroke      f1_=null;
573 
574   public void installContextHelp(JComponent _cp)
575   {
576     installContextHelp(_cp,null);
577   }
578 
579   public void installContextHelp(JComponent _cp, String _url)
580   {
581     if(_url!=null) _cp.putClientProperty("HELP_URL",_url);
582 
583     if(al_==null)
584     {
585       al_=new ActionListener()
586       {
587   public void actionPerformed(ActionEvent _evt)
588   {
589     Object source=_evt.getSource();
590     if(source instanceof JComponent)
591     {
592       JComponent cp=(JComponent)source;
593       // System.err.println("SOURCE = "+cp);
594 
595       String param=(String)cp.getClientProperty("HELP_URL");
596 
597       Container pt=cp;
598       while((pt!=null)&&(param==null))
599       {
600         pt=pt.getParent();
601         if(pt instanceof JComponent)
602     param=(String)((JComponent)pt).getClientProperty("HELP_URL");
603       }
604 
605       JComponent focus=null;
606       for(Enumeration e=BuLib.getAllSubComponents(cp).elements();
607     e.hasMoreElements(); )
608       {
609         Object o=e.nextElement();
610         if(  (o instanceof JComponent)
611      &&((JComponent)o).hasFocus())
612         {
613     focus=(JComponent)o;
614     break;
615         }
616       }
617 
618       if(focus!=null)
619       {
620         String ancre=focus.getName();
621         if(ancre!=null)
622         {
623     int i=0;
624     while(i<ancre.length())
625     {
626       int c=ancre.charAt(i);
627       if((c<'A')||(c>'Z')) i++;
628       else break;
629     }
630     ancre=ancre.substring(i).toLowerCase().replace('_','-');
631     if(!"".equals(ancre)) param+="#"+ancre;
632         }
633         else
634     System.err.println("NOT NAMED = "+focus);
635       }
636 
637       System.err.println("PARAM = "+param);
638       param="("+param+")";
639 
640       /*
641         if(cp instanceof JInternalFrame)
642         cp=((JInternalFrame)cp).getRootPane();
643       */
644 
645       ActionEvent evt=new ActionEvent
646         (cp,_evt.getID(),
647          "AIDE_CONTEXTUELLE"+param,_evt.getModifiers());
648       getImplementation().actionPerformed(evt);
649     }
650   }
651       };
652     }
653 
654     if(f1_==null)
655       f1_=KeyStroke.getKeyStroke(KeyEvent.VK_F1,0,false);
656 
657     _cp.unregisterKeyboardAction(f1_);
658     _cp.registerKeyboardAction
659       (al_,f1_,JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
660   }
661 
662   /**
663    * Modification du LookAndFeel.
664    */
665   public void setLookAndFeel(String _lnf)
666   {
667     // System.err.println("LNF="+_lnf);
668 
669     /*
670     if(_lnf.equals(UIManager.getLookAndFeel().getClass().getName()))
671     {
672       String tm=UIManager.getLookAndFeel().getName()+" est déjà installé!";
673 
674       BuDialogMessage dm=new BuDialogMessage
675   (app_,getInformationsSoftware(),tm);
676       dm.activate();
677       return;
678     }
679     */
680 
681     String os=System.getProperty("os.name");
682     if("com.sun.java.swing.plaf.mac.MacLookAndFeel".equals(_lnf))
683       System.getProperties().put("os.name","Mac OS");
684     if("com.sun.java.swing.plaf.windows.WindowsLookAndFeel".equals(_lnf))
685       System.getProperties().put("os.name","Windows");
686 
687     boolean error=false;
688 
689     try
690     {
691       UIManager.setLookAndFeel(_lnf);
692     }
693     catch (Throwable ex)
694     {
695       error=true;
696       // ex.printStackTrace();
697 
698       String tm;
699       int i;
700 
701       tm=_lnf;
702       i=tm.lastIndexOf('.');
703       if(i>=0) tm=tm.substring(i+1);
704       i=tm.lastIndexOf("LookAndFeel");
705       if(i>=0) tm=tm.substring(0,i);
706       tm=BuResource.BU.getString("L'aspect n'a pu être trouvé")+
707   ". ["+tm+"]";
708 
709       BuDialogMessage dm=new BuDialogMessage
710   (app_,getInformationsSoftware(),tm);
711       dm.activate();
712     }
713 
714     System.getProperties().put("os.name",os);
715 
716     if(!error)
717     {
718       try
719       {
720   SwingUtilities.updateComponentTreeUI((Component)app_);
721   getMainPanel().arrangeIcons();
722       }
723       catch (Throwable ex)
724       {
725   // ex.printStackTrace();
726       
727   String tm;
728   int i;
729   
730   tm=_lnf;
731   i=tm.lastIndexOf('.');
732   if(i>=0) tm=tm.substring(i+1);
733   i=tm.lastIndexOf("LookAndFeel");
734   if(i>=0) tm=tm.substring(0,i);
735   tm=BuResource.BU.getString
736     ("L'aspect n'a pu mettre à jour l'arbre des composants")+
737     ". ["+tm+"]";
738 
739   BuDialogMessage dm=new BuDialogMessage
740     (app_,getInformationsSoftware(),tm);
741   dm.activate();
742       }
743     }
744   }
745 
746   public void setMetalTheme(String _arg)
747   {
748     try
749     {
750       int i=Integer.parseInt(_arg);
751       BuMetalCustomTheme[] themes=BuMetalCustomTheme.getList();
752       MetalLookAndFeel.setCurrentTheme(themes[i]);
753       setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
754     }
755     catch (Exception ex)
756     {
757       BuDialogMessage dm=new BuDialogMessage
758   (app_,getInformationsSoftware(),
759    BuResource.BU.getString
760    ("Le thème pour Metal n'a pu être mis en place")+".");
761       dm.activate();
762     }
763   }
764 
765   public void setSlafTheme(String _arg)
766   {
767     try
768     {
769       int i=Integer.parseInt(_arg);
770       BuSlafCustomTheme[] themes=BuSlafCustomTheme.getList();
771 
772       System.err.println("SLAF THEME"+i+" "+themes[i]);
773       Class   c=Class.forName("com.memoire.slaf.SlafLookAndFeel");
774       Method  m=c.getMethod("setCurrentTheme",new Class[] { String.class } );
775       m.invoke(null,new Object[] { themes[i].getKey() } );
776 
777       setLookAndFeel("com.memoire.slaf.SlafLookAndFeel");
778     }
779     catch (Exception ex)
780     {
781       ex.printStackTrace();
782 
783       BuDialogMessage dm=new BuDialogMessage
784   (app_,getInformationsSoftware(),
785    BuResource.BU.getString
786    ("Le thème pour Slaf n'a pu être mis en place")+".");
787       dm.activate();
788     }
789   }
790 
791   public void fullscreen()
792   {
793     if(!(getApp() instanceof JFrame)) return;
794     final JInternalFrame frame=getCurrentInternalFrame();
795     if(frame==null) return;
796 
797     final JComponent     content=(JComponent)frame.getContentPane();
798     final JWindow        win    =new JWindow();
799     final JComponent     cwin   =(JComponent)win.getContentPane();
800     final JFrame         app    =(JFrame)getApp();
801     final Dimension      de     =app.getToolkit().getScreenSize();
802 
803     final BuLabel        label  =new BuLabel();
804     final BuButton       button =new BuButton();
805     final BuPanel        top    =new BuPanel();
806 
807     top.setLayout(new BuBorderLayout());
808 
809     label.setText(app.getTitle()+": "+frame.getTitle());
810     label.setBorder(new EmptyBorder(1,1,1,1));
811     label.setHorizontalAlignment(JLabel.CENTER);
812     top.add(label,BorderLayout.CENTER);
813 
814     button.setBorder(new EmptyBorder(1,1,1,1));
815     button.setRequestFocusEnabled(false);
816     Icon icon=UIManager.getIcon("InternalFrameTitlePane.closeIcon");
817     if(icon==null) icon=UIManager.getIcon("InternalFrame.closeIcon");
818     button.setIcon(icon);
819     button.setIcon(icon);
820     top.add(button,BorderLayout.EAST);
821 
822     frame.setContentPane(new JPanel());
823 
824     cwin.add(content,BuBorderLayout.CENTER);
825     cwin.add(top    ,BuBorderLayout.NORTH);
826     cwin.setBorder(new LineBorder(Color.black,2));
827 
828     win.setSize(de.width,de.height);
829     win.setLocation(0,0);
830     app.setVisible(false);
831     win.doLayout();
832     win.validate();
833     win.setVisible(true);
834     win.setLocation(0,0);
835 
836     button.addActionListener(new ActionListener()
837       {
838         public void actionPerformed(ActionEvent _ae)
839         {
840     win.setVisible(false);
841     cwin.remove(content);
842     frame.setContentPane(content);
843     app.setVisible(true);
844   }
845       }
846     );
847   }
848 
849   public boolean confirmExit()
850   {
851     BuInformationsSoftware il=getInformationsSoftware();
852     BuDialogConfirmation   bd=new BuDialogConfirmation
853       (getApp(),il,BuResource.BU.getString
854        ("Voulez-vous vraiment quitter ce logiciel ?"));
855 
856     int r=bd.activate();
857     return (r==JOptionPane.YES_OPTION);
858   }
859 
860   public void displayURL(String _url)
861   {
862     getApp().displayURL(_url);
863   }
864 
865   public boolean isCloseFrameMode()
866   { return true; }
867 
868   // commands
869 
870   public void about()
871   {
872     BuInformationsSoftware il=getInformationsSoftware();
873     BuDialogMessage        bd=new BuDialogMessage(getApp(),il,il.about());
874     bd.activate();
875   }
876 
877   public void cut()
878   {
879     JInternalFrame frame=getCurrentInternalFrame();
880 
881     if(frame instanceof BuCutCopyPasteInterface)
882       ((BuCutCopyPasteInterface)frame).cut();
883     else
884       System.err.println
885   (frame+" doesn't implement BuCutCopyPasteInterface");
886   }
887 
888   public void copy()
889   {
890     JInternalFrame frame=getCurrentInternalFrame();
891 
892     if(frame instanceof BuCutCopyPasteInterface)
893       ((BuCutCopyPasteInterface)frame).copy();
894     else
895       System.err.println
896   (frame+" doesn't implement BuCutCopyPasteInterface");
897   }
898 
899   public void duplicate()
900   {
901     JInternalFrame frame=getCurrentInternalFrame();
902 
903     if(frame instanceof BuCutCopyPasteInterface)
904       ((BuCutCopyPasteInterface)frame).duplicate();
905     else
906       System.err.println
907   (frame+" doesn't implement BuCutCopyPasteInterface");
908   }
909 
910   public void find()
911   {
912     JInternalFrame frame=getCurrentInternalFrame();
913 
914     if(frame instanceof BuSelectFindReplaceInterface)
915       ((BuSelectFindReplaceInterface)frame).find();
916     else
917       System.err.println
918   (frame+" doesn't implement BuSelectFindReplaceInterface");
919   }
920 
921   public void license()
922   {
923     BuInformationsSoftware il=getInformationsSoftware();
924     BuDialogMessage        bd=new BuDialogMessage(getApp(),il,il.license());
925     bd.activate();
926   }
927 
928   public void paste()
929   {
930     JInternalFrame frame=getCurrentInternalFrame();
931 
932     if(frame instanceof BuCutCopyPasteInterface)
933       ((BuCutCopyPasteInterface)frame).paste();
934     else
935       System.err.println
936   (frame+" doesn't implement BuCutCopyPasteInterface");
937   }
938 
939   public void undo()
940   {
941     JInternalFrame frame=getCurrentInternalFrame();
942 
943     if(frame instanceof BuUndoRedoInterface)
944       ((BuUndoRedoInterface)frame).undo();
945     else
946       System.err.println
947   (frame+" doesn't implement BuUndoRedoInterface");
948   }
949 
950   public void redo()
951   {
952     JInternalFrame frame=getCurrentInternalFrame();
953 
954     if(frame instanceof BuUndoRedoInterface)
955       ((BuUndoRedoInterface)frame).redo();
956     else
957       System.err.println
958   (frame+" doesn't implement BuUndoRedoInterface");
959   }
960 
961   public void replace()
962   {
963     JInternalFrame frame=getCurrentInternalFrame();
964 
965     if(frame instanceof BuSelectFindReplaceInterface)
966       ((BuSelectFindReplaceInterface)frame).replace();
967     else
968       System.err.println
969   (frame+" doesn't implement BuSelectFindReplaceInterface");
970   }
971 
972   public void select()
973   {
974     JInternalFrame frame=getCurrentInternalFrame();
975 
976     if(frame instanceof BuSelectFindReplaceInterface)
977       ((BuSelectFindReplaceInterface)frame).select();
978     else
979       System.err.println
980   (frame+" doesn't implement BuSelectFindReplaceInterface");
981   }
982 
983   public void close()
984   {
985     if(isCloseFrameMode())
986     {
987       JInternalFrame frame=getCurrentInternalFrame();
988 
989       if(!frame.isClosed()&&frame.isClosable())
990       {
991   try { frame.setClosed(true); }
992   catch(PropertyVetoException ex) { }
993       }
994     }
995   }
996 
997   public void exit()
998   {
999     getApp().exit();
1000  }
1001
1002  public void print()
1003  {
1004    getApp().print();
1005  }
1006
1007  public void preview()
1008  {
1009    JInternalFrame frame=getMainPanel().getCurrentInternalFrame();
1010
1011    if(frame instanceof BuPrintable)
1012    {
1013      /*
1014      Image[] images=BuPrinter.preview
1015  (getFrame(),frame.getTitle(),(BuPrintable)frame);
1016      if(images!=null)
1017      {
1018  BuPreviewFrame pf=new BuPreviewFrame(this,images);
1019  addInternalFrame(pf);
1020      }
1021      */
1022      BuPrinter.preview(this,frame.getTitle(),(BuPrintable)frame);
1023    }
1024    else
1025    {
1026      BuInformationsSoftware il=getInformationsSoftware();
1027      BuDialogError          bd=new BuDialogError
1028  (this,il,BuResource.BU.getString
1029   ("La prévisualisation n'est pas disponible pour")+
1030  "\""+frame.getTitle()+"\".");
1031    }
1032  }
1033
1034  // Window
1035
1036  public void windowActivated(WindowEvent _evt)
1037  { }
1038
1039  public void windowClosed(WindowEvent _evt)
1040  { }
1041
1042  public void windowClosing(WindowEvent _evt)
1043  { exit(); }
1044
1045  public void windowDeactivated(WindowEvent _evt)
1046  { }
1047
1048  public void windowDeiconified(WindowEvent _evt)
1049  { }
1050
1051  public void windowIconified(WindowEvent _evt)
1052  { }
1053
1054  public void windowOpened(WindowEvent _evt)
1055  { }
1056
1057  // InternalFrame
1058
1059  public void internalFrameActivated(InternalFrameEvent _evt)
1060  {
1061    ajouterActionsOutils(_evt);
1062    menusOrganisationFenetres();
1063
1064    BuDesktop      desktop=getMainPanel().getDesktop();
1065    JInternalFrame frame  =desktop.getCurrentInternalFrame();
1066    desktop.showFrame(frame);
1067  }
1068
1069  public void internalFrameDeactivated(InternalFrameEvent _evt)
1070  {
1071    // System.err.println("DEACTIVATED "+_evt.getSource());
1072    enleverActionsOutils(_evt);
1073    menusOrganisationFenetres();
1074  }
1075
1076  public void internalFrameClosed(InternalFrameEvent _evt)
1077  {
1078    // System.err.println("CLOSED "+_evt.getSource());
1079    /*
1080    try
1081    {
1082      if(((BuInternalFrame)_evt.getSource()).isSelected()) 
1083      {
1084  enleverActionsOutils(_evt);
1085      }
1086      catch(PropertyVetoException ex) { }
1087    }
1088    */
1089    //enleverActionsOutils(_evt);
1090    //menusOrganisationFenetres();
1091    selectionnerPremiere(_evt);
1092  }
1093
1094  public void internalFrameClosing(InternalFrameEvent _evt)
1095  {
1096    // System.err.println("CLOSING "+_evt.getSource());
1097    // enleverActionsOutils(_evt);
1098  }
1099
1100  public void internalFrameDeiconified(InternalFrameEvent _evt)
1101  {
1102    // System.err.println("DEICONIFIED "+_evt.getSource());
1103    menusOrganisationFenetres();
1104    try
1105    {
1106      Object source=_evt.getSource();
1107      if(source instanceof BuInternalFrame)
1108  ((BuInternalFrame)source).setSelected(true);
1109    }
1110    catch(PropertyVetoException ex) { }
1111  }
1112
1113  public void internalFrameIconified(InternalFrameEvent _evt)
1114  {
1115    // System.err.println("ICONIFIED "+_evt.getSource());
1116    menusOrganisationFenetres();
1117    selectionnerPremiere(_evt);
1118  }
1119
1120  public void internalFrameOpened(InternalFrameEvent _evt)
1121  {
1122    // System.err.println("OPENED "+_evt.getSource());
1123    // ajouterActionsOutils(_evt);
1124    menusOrganisationFenetres();
1125  }
1126
1127  public void componentAdded(ContainerEvent _evt)
1128  {
1129    menusOrganisationFenetres();
1130  }
1131
1132  public void componentRemoved(ContainerEvent _evt)
1133  {
1134    menusOrganisationFenetres();
1135  }
1136
1137  protected void ajouterActionsOutils(InternalFrameEvent _evt)
1138  {
1139    Object source=_evt.getSource();
1140    if(source instanceof BuInternalFrame)
1141    {
1142      BuInternalFrame f =(BuInternalFrame)source;
1143
1144      BuMenuBar       mb=getMainMenuBar();
1145      BuSpecificBar   sb=getSpecificBar();
1146
1147      // System.err.println(""+f+" activated!");
1148
1149      int i;
1150
1151      String[] ea=f.getEnabledActions();
1152      for(i=0;i<ea.length;i++)
1153  setEnabledForAction(ea[i],true);
1154
1155      String[] da=f.getDisabledActions();
1156      for(i=0;i<da.length;i++)
1157  setEnabledForAction(da[i],false);
1158
1159      mb.addMenus(f.getSpecificMenus());
1160      sb.addTools(f.getSpecificTools());
1161
1162      BuMainPanel mp=getMainPanel();
1163      if(mp.getAssistant()!=null)
1164    mp.getAssistant().addEmitters(sb);
1165
1166      f.adjustActions();
1167    }
1168  }
1169
1170  protected void enleverActionsOutils(InternalFrameEvent _evt)
1171  {
1172    Object source=_evt.getSource();
1173    if(source instanceof BuInternalFrame)
1174    {
1175      BuInternalFrame f =(BuInternalFrame)source;
1176      BuMenuBar       mb=getMainMenuBar();
1177      BuSpecificBar   sb=getSpecificBar();
1178
1179      // System.err.println(""+f+" deactivated!");
1180      int i;
1181
1182      String[] ea=f.getEnabledActions();
1183      for(i=0;i<ea.length;i++)
1184  setEnabledForAction(ea[i],false);
1185
1186      String[] da=f.getDisabledActions();
1187      for(i=0;i<da.length;i++)
1188  setEnabledForAction(da[i],true);
1189
1190      mb.removeMenus(f.getSpecificMenus());
1191      sb.removeTools(f.getSpecificTools());
1192    }
1193  }
1194
1195  protected void selectionnerPremiere(InternalFrameEvent _evt)
1196  {
1197    Object source=_evt.getSource();
1198    if(source instanceof BuInternalFrame)
1199    {
1200      BuInternalFrame f=(BuInternalFrame)source;
1201      BuDesktop       d=getMainPanel().getDesktop();
1202
1203      if((f==d.getCurrentInternalFrame())||f.isIcon())
1204      {
1205  try
1206  {
1207    f.setSelected(false);
1208
1209    JInternalFrame[] frames;
1210    boolean          ok;
1211
1212    ok=false;
1213    frames=d.getNormalFrames();
1214    if(frames.length>0)
1215    {
1216      for(int i=0;i<frames.length;i++)
1217        if(frames[i]!=f)
1218        {
1219    try
1220    {
1221      frames[i].setSelected(true); 
1222      // System.err.println("select: "+frames[i]);
1223      ok=true;
1224      break;
1225    }
1226    catch(PropertyVetoException ex) { }
1227        }
1228    }
1229
1230    if(!ok)
1231    {
1232      frames=d.getIconifiedFrames();
1233      for(int i=0;i<frames.length;i++)
1234        if(frames[i]!=f)
1235        {
1236    try
1237    {
1238      frames[i].setSelected(true);
1239      // System.err.println("select: "+frames[i]);
1240      ok=true;
1241      break;
1242    }
1243    catch(PropertyVetoException ex) { }
1244        }
1245    }
1246  }
1247  catch(PropertyVetoException ex) { }
1248      }
1249    }
1250  }
1251
1252  protected void menusOrganisationFenetres()
1253  {
1254    BuDesktop      desktop=getMainPanel().getDesktop();
1255    boolean        appli  =(getApp() instanceof JFrame);
1256    JInternalFrame frame  =desktop.getCurrentInternalFrame();
1257    boolean b;
1258
1259    b=(desktop.getNormalFramesCount()>0);
1260    setEnabledForAction("CASCADE",b);
1261    setEnabledForAction("MOSAIQUE",b);
1262
1263    b=(desktop.getIconifiedFramesCount()>0);
1264    setEnabledForAction("RANGERICONES",b);
1265    
1266    b=(desktop.getPalettesCount()>0);
1267    setEnabledForAction("RANGERPALETTES",b);
1268    
1269    b=(frame!=null);
1270    setEnabledForAction("PLEINECRAN",b&&appli);
1271
1272    if(isCloseFrameMode())
1273    {
1274      b=(frame!=null)&&frame.isClosable();
1275      setEnabledForAction("FERMER",b);
1276    }
1277
1278    // TMP
1279    // desktop.adjustSize();
1280  }
1281}