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

Quick Search    Search Deep

Source code: org/fudaa/ebli/test/TestCalques.java


1   /*
2    * @file         TestCalques.java
3    * @creation     1998-08-27
4    * @modification $Date: 2001/09/11 15:29:21 $
5    * @license      GNU General Public License 2
6    * @copyright    (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne
7    * @mail         devel@fudaa.org
8    */
9   
10  package org.fudaa.ebli.test;
11  
12  import javax.swing.*;
13  import javax.swing.border.*;
14  import javax.swing.event.*;
15  import javax.swing.tree.*;
16  import java.awt.*;
17  import java.awt.event.*;
18  
19  import com.memoire.bu.*;
20  import org.fudaa.ebli.calque.*;
21  import org.fudaa.ebli.calque.dessin.*;
22  import org.fudaa.ebli.geometrie.*;
23  import org.fudaa.ebli.palette.*;
24  import org.fudaa.ebli.repere.*;
25  import org.fudaa.ebli.ressource.*;
26  import org.fudaa.ebli.trace.*;
27  
28  /**
29   * Un test des classes Calques.
30   *
31   * @version      $Revision: 1.8 $ $Date: 2001/09/11 15:29:21 $ by $Author: deniger $
32   * @author       Guillaume Desnoix 
33   */
34  public class TestCalques
35  {
36    public static void main(String[] args)
37    {
38  
39      /*
40      try
41      {
42        UIManager.setLookAndFeel
43    ("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
44      }
45      catch (Exception ex) { System.err.println(""+ex); }
46      */
47  
48      JLabel ss=new JLabel();
49      ss.setFont(new Font("SansSerif",Font.PLAIN,10));
50      ss.setPreferredSize(new Dimension(200,20));
51      ss.setSize(new Dimension(100,20));
52  
53      BCalque[] c=new BCalque[8];
54  
55      {
56        BCalque[] cu=new BCalque[2];
57  
58        {
59    BuInformationsDocument id=new BuInformationsDocument();
60    id.name        ="Essai";
61    id.organization="CETMEF";
62    id.author      ="Guillaume Desnoix";
63    id.contact     ="g.desnoix@stcpmvn.equipement.gouv.fr";
64    id.date        ="02/09/1998";
65    id.logo        =EbliResource.EBLI.getIcon("minlogo.gif");
66  
67    BCalqueCartouche calque=new BCalqueCartouche();
68    calque.setName("Cartouche");
69    calque.setInformations(id);
70    calque.setForeground(Color.black);
71    calque.setBackground(new Color(255,255,224));
72    calque.setFont(new Font("SansSerif",Font.PLAIN,10));
73    calque.setAttenue(false);
74    cu[0]=calque;
75        }
76  
77        {
78    GrBoite b=new GrBoite();
79    b.ajuste(new GrPoint(  0.,  0.,0.));
80    b.ajuste(new GrPoint(400.,400.,0.));
81  
82    BCalqueGrille calque=new BCalqueGrille();
83    calque.setName("Grille");
84    calque.setBoite(b);
85    calque.setForeground(Color.lightGray);
86    calque.setFont(new Font("SansSerif",Font.PLAIN,8));
87    calque.setAttenue(false);
88    cu[1]=calque;
89        }
90  
91        BGroupeCalque gcu=new BGroupeCalque();
92        gcu.setName("Informations");
93        gcu.add(cu[0]);
94        gcu.add(cu[1]);
95        c[0]=gcu;
96      }
97  
98      {
99        BCalque[] ci=new BCalque[2];
100 
101       {
102   BCalqueImage calque=new BCalqueImage();
103   calque.setName("Abeille");
104   calque.setNW(new GrPoint(-100.,-100.,0.));
105   calque.setNE(new GrPoint( 100.,-100.,0.));
106   calque.setSE(new GrPoint( 100., 100.,0.));
107   calque.setSW(new GrPoint(-100., 100.,0.));
108   calque.setImage((new ImageIcon("abeille1.gif")).getImage());
109 //  calque.setCouleur(new Color(255,255,192));
110   calque.setForeground(new Color(255,255,192));
111   ci[0]=calque;
112       }
113         
114       {
115   BCalqueImage calque=new BCalqueImage();
116   calque.setName("Linux");
117   calque.setNW(new GrPoint(   0., 200.,0.));
118   calque.setNE(new GrPoint( 100., 300.,0.));
119   calque.setSE(new GrPoint( 200., 200.,0.));
120   calque.setSW(new GrPoint( 100., 100.,0.));
121   calque.setImage((new ImageIcon("linuxpow.gif")).getImage());
122   ci[1]=calque;
123       }
124 
125       BGroupeCalque gci=new BGroupeCalque();
126       gci.setName("Fonds de carte");
127       gci.add(ci[0]);
128       gci.add(ci[1]);
129 
130       c[1]=gci;
131     }
132 
133     {
134       BCalqueTexte calque=new BCalqueTexte();
135       calque.setName("Etiquettes");
136       for(int i=0;i<300;i+=30)
137   calque.ajoute(new GrPoint(Math.cos(i/10.)*50.,i*1.,0.),"Etiquette "+i);
138       calque.setForeground(Color.black);
139       calque.setBackground(Color.yellow);
140       calque.setFont(new Font("SansSerif",Font.PLAIN,10));
141       calque.setEtiquettePleine(true);
142       c[2]=calque;
143     }
144 
145     {
146       BCalquePolyligne calque=new BCalquePolyligne();
147       calque.setName("Sinus");
148       GrPolyligne pl=new GrPolyligne();
149       for(int i=0;i<300;i++)
150   pl.sommets.ajoute(new GrPoint(Math.cos(i/10.)*50.,i*1.,0.));
151       calque.ajoute(pl);
152       calque.setForeground(Color.blue);
153       c[3]=calque;
154     }
155 
156     {
157       DeLigneBrisee l=new DeLigneBrisee();
158       l.ajoute(new GrPoint(  0.,  0.,0.));
159       l.ajoute(new GrPoint(150.,150.,0.));
160       l.ajoute(new GrPoint(150.,250.,0.));
161       l.ajoute(new GrPoint(250.,250.,0.));
162       l.setTypeTrait(TraceLigne.POINTILLE);
163 //      l.setCouleurContour(Color.blue);
164       l.setForeground(Color.blue);
165 
166       BCalqueDessin calque=new BCalqueDessin();
167       calque.setName("Dessin");
168       calque.ajoute(l);
169       c[4]=calque;
170     }
171     
172     {
173       BCalqueSuiviSourisInteraction calque=new BCalqueSuiviSourisInteraction();
174       calque.setName("Souris");
175       calque.addCoordonneesListener(new SuiviSouris(ss));
176       c[5]=calque;
177     }
178 
179     {
180       BCalqueDessin calque=new BCalqueDessin();
181       calque.setName("Dessin");
182       c[6]=calque;
183     }
184 
185     {
186       BCalqueDessinInteraction calque=new BCalqueDessinInteraction((BCalqueDessin)c[6]);
187       calque.setName("Dessin (interaction)");
188       c[7]=calque;
189     }
190 
191     BGroupeCalque gc=new BGroupeCalque();
192     gc.setName("Plan-masse");
193     for(int i=c.length-1;i>=0;i--)
194       gc.add(c[i]);
195 
196     BVueCalque vc=new BVueCalque();
197     vc.setCalque(gc);
198     vc.setBackground(Color.white);
199 
200     BTransformationGlissiere e=new BTransformationGlissiere();
201     e.setTypeTransfo(RepereEvent.ZOOM);
202     e.addRepereEventListener(vc);
203 
204     BTransformationGlissiere tx=new BTransformationGlissiere();
205     tx.setTypeTransfo(RepereEvent.TRANS_X);
206     tx.addRepereEventListener(vc);
207 
208     BTransformationGlissiere ty=new BTransformationGlissiere();
209     ty.setTypeTransfo(RepereEvent.TRANS_Y);
210     ty.addRepereEventListener(vc);
211 
212     BTransformationGlissiere rz=new BTransformationGlissiere();
213     rz.setTypeTransfo(RepereEvent.ROT_Z);
214     rz.addRepereEventListener(vc);
215 
216     BTransformationBouton bt=new BTransformationBouton(RepereEvent.ROT_Z);
217     bt.addRepereEventListener(vc);
218 
219     BArbreCalque ac=new BArbreCalque();
220     ac.setCalque(gc);
221 
222     JScrollPane spac=new JScrollPane(ac);
223     Dimension dspac=ac.getPreferredSize();
224     Dimension de=e.getPreferredSize();
225     dspac.width+=20;
226     dspac.height=de.height;
227     spac.setPreferredSize(dspac);
228     spac.setRequestFocusEnabled(false);
229 
230     BSelecteurReduitCouleur srcfg=new BSelecteurReduitCouleur();
231     srcfg.addPropertyChangeListener(ac);
232     srcfg.setPropertyName("foreground");
233 
234     BuPopupButton pbfg=new BuPopupButton(srcfg);
235     pbfg.setText("Tracé");
236 
237     BSelecteurReduitCouleur srcbg=new BSelecteurReduitCouleur();
238     srcbg.addPropertyChangeListener(ac);
239     srcbg.setPropertyName("background");
240 
241     BuPopupButton pbbg=new BuPopupButton(srcbg);
242     pbbg.setText("Remplissage");
243 
244     // BControleurCalque cc=new BControleurCalque((BCalqueAffichage)c[4]);
245     // SelectionCalque s=new SelectionCalque(cc);
246     // ac.addTreeSelectionListener(s);
247 
248     JComponent[] ctrls=new JComponent[]
249       { spac,e,tx,ty,rz,bt,ss,pbfg,pbbg };
250 
251     JPanel panel=new JPanel(new FlowLayout(FlowLayout.LEFT));
252     for(int i=0;i<ctrls.length;i++)
253       panel.add(ctrls[i]);
254     
255     JComponent[] beans=new JComponent[]
256       { vc,panel };
257 
258     TestFrame f=new TestFrame(beans);
259     vc   .setPreferredSize(new Dimension(500,500));
260     panel.setPreferredSize(new Dimension(500,500));
261     f.setVisible(true);
262   }
263 }
264 
265 /*
266 class SelectionCalque
267       implements TreeSelectionListener
268 {
269   BControleurCalque controleur_;
270 
271   public SelectionCalque(BControleurCalque _controleur)
272   {
273     controleur_=_controleur;
274   }
275 
276   public void valueChanged(TreeSelectionEvent _evt)
277   {
278     Object o=_evt.getPath().getLastPathComponent();
279     if(o instanceof BCalqueAffichage)
280       controleur_.setCalque((BCalqueAffichage)o);
281   }
282 }
283 */
284 
285 class SuiviSouris
286       implements CoordonneesListener
287 {
288   JLabel label_;
289 
290   public SuiviSouris(JLabel _label)
291   {
292     label_=_label;
293   }
294 
295   public void coordonneesModifiees(CoordonneesEvent _evt)
296   {
297     double [] c=_evt.valeur();
298     boolean[] d=_evt.defini();
299     boolean[] m=_evt.modifie();
300 
301     String r="";
302     for(int i=0;i<c.length;i++)
303     {
304       if(i==0) r+=" X:"         +(int)c[i];
305       if(i==1) r+=" Y:"         +(int)c[i];
306       if(i==2) r+=" Z:"         +(int)c[i];
307       if(i>=3) r+=" V"+(i-3)+":"+(int)c[i];
308     }
309     label_.setText(r);
310   }
311 }