KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > ide > diagrams > DiagramView


1 /*
2   Copyright (C) 2002-2003 Renaud Pawlak <renaud@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 */

18
19 package org.objectweb.jac.ide.diagrams;
20
21 import CH.ifa.draw.framework.Drawing;
22 import CH.ifa.draw.framework.DrawingEditor;
23 import CH.ifa.draw.framework.DrawingView;
24 import CH.ifa.draw.framework.Figure;
25 import CH.ifa.draw.framework.FigureEnumeration;
26 import CH.ifa.draw.framework.Tool;
27 import CH.ifa.draw.framework.ViewChangeListener;
28 import CH.ifa.draw.standard.ChangeAttributeCommand;
29 import CH.ifa.draw.standard.ChopBoxConnector;
30 import CH.ifa.draw.standard.StandardDrawing;
31 import CH.ifa.draw.util.ColorMap;
32 import CH.ifa.draw.util.CommandChoice;
33 import CH.ifa.draw.util.Filler;
34 import CH.ifa.draw.util.PaletteButton;
35 import CH.ifa.draw.util.PaletteListener;
36 import CH.ifa.draw.util.StandardVersionControlStrategy;
37 import CH.ifa.draw.util.VersionControlStrategy;
38 import CH.ifa.draw.util.VersionManagement;
39 import CH.ifa.draw.util.VersionRequester;
40 import java.awt.BorderLayout JavaDoc;
41 import java.awt.Component JavaDoc;
42 import java.awt.Point JavaDoc;
43 import java.awt.datatransfer.Transferable JavaDoc;
44 import java.awt.dnd.DnDConstants JavaDoc;
45 import java.awt.dnd.DropTarget JavaDoc;
46 import java.awt.dnd.DropTargetDragEvent JavaDoc;
47 import java.awt.dnd.DropTargetDropEvent JavaDoc;
48 import java.awt.dnd.DropTargetEvent JavaDoc;
49 import java.awt.dnd.DropTargetListener JavaDoc;
50 import java.awt.event.ActionEvent JavaDoc;
51 import java.awt.event.ActionListener JavaDoc;
52 import java.awt.event.KeyAdapter JavaDoc;
53 import java.awt.event.KeyEvent JavaDoc;
54 import java.awt.event.MouseAdapter JavaDoc;
55 import java.awt.event.MouseEvent JavaDoc;
56 import java.util.Iterator JavaDoc;
57 import java.util.List JavaDoc;
58 import java.util.Vector JavaDoc;
59 import javax.swing.JComboBox JavaDoc;
60 import javax.swing.JLabel JavaDoc;
61 import javax.swing.JPanel JavaDoc;
62 import javax.swing.JScrollPane JavaDoc;
63 import org.objectweb.jac.aspects.gui.CollectionUpdate;
64 import org.objectweb.jac.aspects.gui.DisplayContext;
65 import org.objectweb.jac.aspects.gui.EventHandler;
66 import org.objectweb.jac.aspects.gui.GuiAC;
67 import org.objectweb.jac.aspects.gui.Transfer;
68 import org.objectweb.jac.aspects.gui.Utils;
69 import org.objectweb.jac.aspects.gui.ViewFactory;
70 import org.objectweb.jac.aspects.gui.swing.AbstractView;
71 import org.objectweb.jac.aspects.gui.swing.SwingEvents;
72 import org.objectweb.jac.core.rtti.ClassRepository;
73 import org.objectweb.jac.core.rtti.CollectionItem;
74 import org.objectweb.jac.ide.Aspect;
75 import org.objectweb.jac.ide.Class;
76 import org.objectweb.jac.ide.Diagram;
77 import org.objectweb.jac.ide.InheritanceLink;
78 import org.objectweb.jac.ide.Link;
79 import org.objectweb.jac.ide.ModelElement;
80 import org.objectweb.jac.ide.Package;
81 import org.objectweb.jac.ide.RelationLink;
82 import org.objectweb.jac.ide.RelationRole;
83 import org.objectweb.jac.ide.TypedElement;
84 import org.objectweb.jac.util.Log;
85 import org.objectweb.jac.util.Strings;
86
87 public class DiagramView extends AbstractView
88     implements DrawingEditor, PaletteListener, VersionRequester,
89               CollectionUpdate, DropTargetListener JavaDoc
90 {
91     static public boolean init = false;
92
93     protected Diagram diagram;
94
95     public DiagramView(ViewFactory factory, DisplayContext context,
96                        Object JavaDoc diagram) {
97         super(factory,context);
98         new DropTarget JavaDoc(this, // component
99
DnDConstants.ACTION_COPY_OR_MOVE, // actions
100
this); // DropTargetListener
101
this.diagram = (Diagram)diagram;
102         init();
103         Utils.registerCollection(diagram,"figures",this);
104     }
105
106     public void close(boolean validate) {
107         Log.trace("diagram","CLOSING DIAGRAM "+this);
108         super.close(validate);
109         FigureEnumeration figures = fDrawing.figures();
110         while (figures.hasMoreElements()) {
111             Figure f = figures.nextFigure();
112             if (f instanceof ModelElementFigure)
113                 ((ModelElementFigure)f).close();
114         }
115         Utils.unregisterCollection(diagram,"figures",this);
116     }
117
118     public Object JavaDoc getSubstance() {
119         return diagram;
120     }
121
122     public final Diagram getDiagram() {
123         return diagram;
124     }
125
126     /**
127      * Add a figure for a class at a given location
128      * @param cl the class to add a figure for
129      * @param location where to put the class figure
130      */

131     public void addClass(Class JavaDoc cl, Point JavaDoc location) {
132         Diagram diagram = (Diagram)getSubstance();
133         if (diagram.contains(cl))
134             return;
135         ClassFigure cf = null;
136         org.objectweb.jac.ide.ClassFigure figure = new org.objectweb.jac.ide.ClassFigure(cl);
137         Log.trace("diagram","diagram = "+diagram);
138         diagram.addFigure(figure);
139         Log.trace("diagram","creating new figure "+figure+","+
140                   diagram.getContainer());
141         cf = new ClassFigure(figure,diagram.getContainer(),
142                              view());
143         (view().add(cf)).displayBox(location,location);
144     }
145
146     /**
147      * Import all relations and inheritance links between a class with
148      * other classes on the diagram
149      * @param cl the class to import relations for
150      */

151     public void importRelations(Class JavaDoc cl) {
152         Iterator JavaDoc it = diagram.getMissingRelations(cl).iterator();
153         while (it.hasNext()) {
154             Link relation = (Link)it.next();
155             try {
156                 if (relation instanceof RelationLink)
157                     importRelation((RelationLink)relation);
158                 else if (relation instanceof InheritanceLink)
159                     importInheritance((InheritanceLink)relation);
160             } catch (Exception JavaDoc e) {
161                  Log.warning(e.getMessage());
162             }
163         }
164     }
165
166     /**
167      * Import a relation in the diagram.
168      * @param relation the relation to import
169      * @throws Exception if both classes of the relation are not on the diagram
170      */

171     public void importRelation(RelationLink relation) throws Exception JavaDoc {
172         ClassFigure endFig = findClass((Class JavaDoc)relation.getEnd());
173         if (endFig==null) {
174             throw new Exception JavaDoc("Cannot import relation "+GuiAC.toString(relation)+
175                                 " since "+GuiAC.toString(relation.getEnd())+
176                                 " is not on the diagram");
177         }
178         ClassFigure startFig = findClass((Class JavaDoc)relation.getStart());
179         if (startFig==null) {
180             throw new Exception JavaDoc("Cannot import relation "+GuiAC.toString(relation)+
181                                 " since "+GuiAC.toString(relation.getStart())+
182                                 " is not on the diagram");
183         }
184
185         org.objectweb.jac.ide.LinkFigure linkFig = new org.objectweb.jac.ide.LinkFigure(relation);
186         diagram.addFigure(linkFig);
187       
188         RelationLinkFigure relf = new RelationLinkFigure();
189         relf.setLinkFigure(linkFig);
190
191         relf.startPoint(startFig.center());
192         relf.endPoint(endFig.center());
193         relf.connectStart(startFig.connectorAt(startFig.center()));
194         relf.connectEnd(endFig.connectorAt(endFig.center()));
195
196         relf.updateConnection();
197       
198         view().add(relf);
199         if (relation.getName()!=null && !relation.getName().equals(""))
200             view().add(relf.createName());
201         if (relation.getEndRole()!=null && !relation.getEndRole().equals(""))
202             view().add(relf.createEndRole());
203         if (relation.getStartRole()!=null && !relation.getStartRole().equals(""))
204             view().add(relf.createStartRole());
205         String JavaDoc startCardinality = relation.startRole().getCardinality();
206         if (startCardinality!=null && !startCardinality.equals(""))
207             view().add(relf.createStartCardinality());
208         String JavaDoc endCardinality = relation.endRole().getCardinality();
209         if (endCardinality!=null && !endCardinality.equals(""))
210             view().add(relf.createEndCardinality());
211       
212         Utils.registerObject(relation,relf);
213     }
214
215     /**
216      * Import an inheritance link in the diagram. An exception
217      * @param inheritance the inheritance link to import
218      */

219     public void importInheritance(InheritanceLink inheritance) throws Exception JavaDoc {
220         ClassFigure endFig = findClass((Class JavaDoc)inheritance.getEnd());
221         ClassFigure startFig = findClass((Class JavaDoc)inheritance.getStart());
222       
223         org.objectweb.jac.ide.LinkFigure linkFig = new org.objectweb.jac.ide.LinkFigure(inheritance);
224         diagram.addFigure(linkFig);
225       
226         InheritanceLinkFigure relf = new InheritanceLinkFigure();
227         relf.setLinkFigure(linkFig);
228
229         relf.startPoint(startFig.center());
230         relf.endPoint(endFig.center());
231         relf.connectStart(startFig.connectorAt(startFig.center()));
232         relf.connectEnd(endFig.connectorAt(endFig.center()));
233
234         relf.updateConnection();
235       
236         view().add(relf);
237       
238         Utils.registerObject(inheritance,relf);
239     }
240
241     /**
242      * Create a RelationLink between two classes.
243      *
244      * @param source start class of the link
245      * @param target end class of the link
246      * @param linkFigure the figure that represents the relation
247      * @param isAggregation wether the relation is an aggregation
248      */

249     public void createRelation(Class JavaDoc source, Class JavaDoc target,
250                                RelationLinkFigure linkFigure,
251                                boolean isAggregation) {
252         Log.trace("figures","creating a new relation link between "+
253                   source+" and "+target);
254
255         RelationLink rel = new RelationLink(source,target);
256         rel.setAggregation(isAggregation);
257         Log.trace("diagram","1. end="+rel.getEnd()+"===> substance="+target);
258         org.objectweb.jac.ide.LinkFigure linkFig = new org.objectweb.jac.ide.LinkFigure(rel);
259         linkFigure.setLinkFigure(linkFig);
260         view().add(linkFigure.createName());
261         view().add(linkFigure.createEndRole());
262         view().add(linkFigure.createStartRole());
263         view().add(linkFigure.createStartCardinality());
264         view().add(linkFigure.createEndCardinality());
265       
266         Log.trace("diagram","2. end="+rel.getEnd());
267
268         if (source==target) {
269             Point JavaDoc c = linkFigure.endFigure().center();
270             linkFig.addPoint(1,new Point JavaDoc(c.x+100,c.y));
271             linkFig.addPoint(1,new Point JavaDoc(c.x+100,c.y+100));
272             linkFig.addPoint(1,new Point JavaDoc(c.x,c.y+100));
273         }
274       
275         diagram.addFigure(linkFig);
276
277         Utils.registerObject(rel,linkFigure);
278         Log.trace("diagram","3. end="+rel.getEnd());
279     }
280
281     // drop listener interface
282
public void drop(DropTargetDropEvent JavaDoc e) {
283         try {
284             Transferable JavaDoc tr = e.getTransferable();
285             List JavaDoc transfered = Transfer.getTransferedWrappees(tr);
286             Object JavaDoc o = transfered.get(0);
287             Point JavaDoc location = e.getLocation();
288             Point JavaDoc offset = scrollPane.getViewport().getViewPosition();
289             location.translate((int)offset.getX(),(int)offset.getY());
290             Log.trace("gui.dnd","drop event: "+o);
291             if (o==null)
292                 return;
293             if (o instanceof Class JavaDoc) {
294                 addClass((Class JavaDoc)o,location);
295             } else if (o instanceof RelationRole) {
296                 importRelation((RelationLink)((RelationRole)o).getLink());
297             }
298
299         } catch(Exception JavaDoc ex) {
300             ex.printStackTrace();
301         }
302     }
303     public void dragEnter(DropTargetDragEvent JavaDoc e) { }
304     public void dragExit(DropTargetEvent JavaDoc e) { }
305     public void dragOver(DropTargetDragEvent JavaDoc e) { }
306     public void dropActionChanged(DropTargetDragEvent JavaDoc e) { }
307     // end of drop listener interface
308

309     public void figureSelectionChanged(DrawingView view) {
310         if (view.selection().size() > 0) {
311             Figure f = (Figure)view.selection().get(0);
312
313             Log.trace("figures","figure "+f+" selected");
314
315             if (f instanceof Selectable) {
316                 ((Selectable)f).onSelect(getContext());
317             }
318
319             if (f instanceof ClassFigure) {
320                 CollectionItem coll = ClassRepository.get().getClass(Package JavaDoc.class)
321                     .getCollection("classes");
322                 EventHandler.get().onSelection(
323                     getContext(),coll,((ClassFigure)f).getSubstance(),null,null);
324
325             } else if (f instanceof InstanceFigure) {
326                 CollectionItem coll = ClassRepository.get().getClass(Package JavaDoc.class)
327                     .getCollection("instances");
328                 EventHandler.get().onSelection(
329                     getContext(),coll,((InstanceFigure)f).getSubstance(),null,null);
330
331             } else if (f instanceof GenericObjectFigure) {
332
333                 Log.trace("figures","generic object");
334                 EventHandler.get().onSelection(
335                     getContext(),
336                     ((GenericObjectFigure)f).getCollection(),
337                     ((GenericObjectFigure)f).getSubstance(),null,null);
338
339             } else if (f instanceof RelationLinkFigure ||
340                        f instanceof AttachedTextFigure) {
341             
342                 RelationLink rel = (RelationLink)
343                     ((ModelElementFigure)f).getSubstance();
344                 Class JavaDoc cl = (Class JavaDoc)rel.getStart();
345                 CollectionItem coll = ClassRepository.get().getClass(Package JavaDoc.class)
346                     .getCollection("classes");
347                 EventHandler.get().onSelection(getContext(),coll,cl,null,null);
348                 coll = ClassRepository.get().getClass(Class JavaDoc.class)
349                     .getCollection("relationRoles");
350                 EventHandler.get().onSelection(getContext(),coll,
351                                                rel.getStartRole(),null,null);
352                 //((RelationLinkFigure)f).selectAll(view);
353

354             } else if (f instanceof PointcutLinkFigure) {
355             
356                 org.objectweb.jac.ide.PointcutLink rel = (org.objectweb.jac.ide.PointcutLink)
357                     ((PointcutLinkFigure)f).getSubstance();
358                 org.objectweb.jac.ide.Aspect aspect = (org.objectweb.jac.ide.Aspect)rel.getStart();
359                 CollectionItem coll = ClassRepository.get().getClass(Package JavaDoc.class)
360                     .getCollection("aspects");
361                 EventHandler.get().onSelection(getContext(),coll,aspect,null,null);
362                 coll = ClassRepository.get().getClass(Aspect.class)
363                     .getCollection("pointcutLinks");
364                 EventHandler.get().onSelection(getContext(),coll,rel,null,null);
365                 //((PointcutLinkFigure)f).selectAll(view);
366
}
367         }
368         // update(getGraphics());
369
}
370
371     private transient Drawing fDrawing;
372     private transient Tool fTool;
373    
374     private transient DrawingView fView;
375     private transient ToolButton fSelectedToolButton;
376    
377     static String JavaDoc fgUntitled = "untitled";
378    
379     ToolPalette classPalette;
380     ToolPalette aspectPalette;
381     ToolPalette instancePalette;
382     ToolPalette groupPalette;
383     ToolPalette currentPalette;
384
385     /**
386      * Find the figure of a given class in the default drawing.
387      * @param cl the Class to search for
388      * @return a ModelElementFigure that matches cl, or null if none is found.
389      */

390     public ClassFigure findClass(Class JavaDoc cl) {
391         return (ClassFigure)findFigure(view().drawing(),cl);
392     }
393
394     /**
395      * Find the figure of a given model element
396      * @param drawing the Drawing to search the figure into
397      * @param cl the Class to search for
398      * @return a ModelElementFigure that matches cl, or null if none is found.
399      */

400     public ClassFigure findClass(Drawing drawing, Class JavaDoc cl) {
401         return (ClassFigure)findFigure(drawing,cl);
402     }
403
404     /**
405      * Find the figure of a given model element.
406      * @param drawing the Drawing to search the figure into
407      * @param element the ModelElement to search for
408      * @return a ModelElementFigure that matches element, or null if none is found.
409      */

410     public ModelElementFigure findFigure(Drawing drawing, ModelElement element) {
411         FigureEnumeration figs = drawing.figures();
412         while(figs.hasMoreElements()) {
413             Figure fig = figs.nextFigure();
414             if( (fig instanceof ModelElementFigure) &&
415                 ((ModelElementFigure)fig).getSubstance() == element) {
416                 return (ModelElementFigure)fig;
417             }
418         }
419         return null;
420     }
421
422     /**
423      * Find the figure of a given TypedElement
424      */

425     public Figure findElement(TypedElement te) {
426         FigureEnumeration figs = view().drawing().figures();
427         while(figs.hasMoreElements()) {
428             Figure fig = figs.nextFigure();
429             if( (fig instanceof ModelElementFigure) &&
430                 ((ModelElementFigure)fig).getSubstance() == te) {
431                 return fig;
432             }
433         }
434         return null;
435     }
436
437     /**
438      * Find the figure of a given ModelElement
439      */

440     public Figure findElement(ModelElement element) {
441         FigureEnumeration figs = view().drawing().figures();
442         while(figs.hasMoreElements()) {
443             Figure fig = figs.nextFigure();
444             if( (fig instanceof ModelElementFigure) &&
445                 ((ModelElementFigure)fig).getSubstance() == element) {
446                 return fig;
447             }
448         }
449         return null;
450     }
451    
452     JScrollPane JavaDoc scrollPane;
453     /**
454      * Initializes the applet and creates its contents.
455      */

456     public void init() {
457         //DiagramView.display = display;
458
//diagramViews.add(this);
459

460         getVersionControlStrategy().assertCompatibleVersion();
461         
462         setLayout(new BorderLayout JavaDoc());
463
464         fView = createDrawingView();
465
466         try {
467             buildClassBar();
468         } catch (Exception JavaDoc e) {
469             e.printStackTrace();
470         }
471
472         scrollPane = new JScrollPane JavaDoc((Component JavaDoc)view());
473         add("Center", scrollPane);
474         JPanel JavaDoc buttonPalette = createButtonPanel();
475         createButtons(buttonPalette);
476         add("North", buttonPalette);
477         setToolBar(buildClassBar());
478
479         initDrawing();
480         // JFC should have its own internal double buffering...
481
//setBufferedDisplayUpdate();
482
//setupAttributes();
483
load();
484         //((JComponent)drawing()).setMinimumSize(new Dimension(2000,2000));
485
}
486
487     public void addViewChangeListener(ViewChangeListener vsl) {
488     }
489
490     public void removeViewChangeListener(ViewChangeListener vsl) {
491     }
492
493
494     /**
495      * Creates the color choice for the given attribute.
496      */

497     protected JComboBox JavaDoc createColorChoice(String JavaDoc attribute) {
498         CommandChoice choice = new CommandChoice();
499         for (int i = 0; i < ColorMap.size(); i++)
500             choice.addItem(
501                 new ChangeAttributeCommand(
502                     ColorMap.name(i),
503                     attribute,
504                     ColorMap.color(i),
505                     this
506                 )
507                     );
508         return choice;
509     }
510
511     /**
512      * Creates the buttons panel.
513      */

514     protected JPanel JavaDoc createButtonPanel() {
515         JPanel JavaDoc panel = new JPanel JavaDoc();
516         panel.setLayout(new PaletteLayout(2, new Point JavaDoc(2,2), false));
517         return panel;
518     }
519
520     /**
521      * Sets the tool bar containing tool buttons.
522      */

523     void setToolBar(ToolPalette newPalette) {
524         if (currentPalette != null) {
525             remove(currentPalette);
526         }
527         add(BorderLayout.WEST, newPalette);
528         currentPalette = newPalette;
529         validate();
530     }
531
532     ToolPalette buildClassBar() {
533         Log.trace("diagram","BUILDING CLASS BAR");
534         classPalette = new ToolPalette();
535
536         classPalette.setDefaultToolButton(
537             classPalette.addToolButton(this, "icon_selection", "Selection Tool",
538                                        createSelectionTool()));
539
540         classPalette.addToolButton(this, "icon_text", "Text Tool",
541                                    new TextTool(this, new TextFigure()));
542         classPalette.addToolButton(this, "icon_class", "Create a new class",
543                                    new NewClassFigureCreationTool(this,getContext()));
544         classPalette.addToolButton(this, "icon_import_class", "Add an existing class",
545                                    new ClassFigureCreationTool(this,getContext()));
546         try {
547             classPalette.addToolButton(this, "icon_see_relation", "Show existing relation",
548                                        new RelationLinkShowTool(this,getContext()));
549         } catch (ClassNotFoundException JavaDoc e) {
550             e.printStackTrace();
551         }
552         classPalette.addToolButton(this, "icon_relation", "New relation link",
553                                    new RelationLinkCreationTool(this));
554         classPalette.addToolButton(this, "icon_add_point", "Add a point",
555                                    new ConnectionTool(this, new RelationLinkFigure()));
556         classPalette.addToolButton(this, "icon_inheritance", "Inheritance link",
557                                    new InheritanceLinkCreationTool(this));
558         classPalette.addToolButton(this, "icon_field", "Create new attribute",
559                                    new FieldCreationTool(this,getContext()));
560         classPalette.addToolButton(this, "icon_method", "Create new method",
561                                    new MethodCreationTool(this,getContext()));
562         return classPalette;
563     }
564
565     ToolPalette buildAspectBar() {
566         Log.trace("diagram","BUILDING ASPECT BAR");
567       
568         aspectPalette = new ToolPalette();
569       
570         aspectPalette.setDefaultToolButton(
571             aspectPalette.addToolButton(this, "icon_selection", "Selection Tool",
572                                         createSelectionTool()));
573       
574         aspectPalette.addToolButton(this, "icon_text", "Text Tool",
575                                     new TextTool(this, new TextFigure()));
576         aspectPalette.addToolButton(this, "icon_aspect", "Create a new aspect",
577                                     new NewAspectFigureCreationTool(this,getContext()));
578         aspectPalette.addToolButton(this, "icon_import_aspect", "Add an existing aspect",
579                                     new AspectFigureCreationTool(this,getContext()));
580         aspectPalette.addToolButton(this, "icon_pointcut", "New pointcut link",
581                                     new PointcutLinkCreationTool(this, new PointcutLinkFigure()));
582         aspectPalette.addToolButton(this, "icon_see_pointcut", "Show existing pointcut",
583                                     new PointcutLinkShowTool(this,getContext()));
584         aspectPalette.addToolButton(this, "icon_add_point", "Add a point",
585                                     new ConnectionTool(this, new RelationLinkFigure()));
586         aspectPalette.addToolButton(this, "icon_field", "Create new attribute",
587                                     new FieldCreationTool(this,getContext()));
588         aspectPalette.addToolButton(this, "icon_method", "Create new configuration method",
589                                     new MethodCreationTool(this,getContext()));
590         aspectPalette.addToolButton(this, "icon_aspect_method","Create new aspect method",
591                                     new MethodCreationTool(this,getContext()));
592         return aspectPalette;
593     }
594
595     ToolPalette buildInstanceBar() {
596         Log.trace("diagram","BUILDING INSTANCE BAR");
597          
598         instancePalette = new ToolPalette();
599       
600         instancePalette.setDefaultToolButton(
601             instancePalette.addToolButton(this, "icon_selection", "Selection Tool",
602                                           createSelectionTool()));
603         instancePalette.addToolButton(this, "icon_text", "Text Tool",
604                                       new TextTool(this, new TextFigure()));
605         instancePalette.addToolButton(this, "icon_instance", "Create a new instance",
606                                       new NewInstanceFigureCreationTool(this,getContext()));
607         instancePalette.addToolButton(this, "icon_import_instance", "Add an existing instance",
608                                       new InstanceFigureCreationTool(this,getContext()));
609         return instancePalette;
610     }
611
612     ToolPalette buildGroupBar() {
613         Log.trace("diagram","BUILDING GROUP BAR");
614          
615         groupPalette = new ToolPalette();
616
617         groupPalette.setDefaultToolButton(
618             groupPalette.addToolButton(this,"icon_selection", "Selection Tool",
619                                        createSelectionTool()));
620         groupPalette.addToolButton(this,"icon_text", "Text Tool",
621                                    new TextTool(this, new TextFigure()));
622         groupPalette.addToolButton(this, "icon_group", "Create a new group",
623                                    new NewInstanceFigureCreationTool(this,getContext()));
624         groupPalette.addToolButton(this, "icon_import_group", "Add an existing group",
625                                    new GroupFigureShowTool(this,getContext()));
626         return groupPalette;
627     }
628
629     /**
630      * Creates the buttons shown in the buttons panel. Override to
631      * add additional buttons.
632      * @param panel the buttons panel.
633      */

634     protected void createButtons(JPanel JavaDoc panel) {
635         panel.add(new Filler(24,20));
636         JLabel JavaDoc title = new JLabel JavaDoc(GuiAC.toString(diagram)+" diagram ");
637         panel.add(title);
638
639         panel.add(new Filler(6,20));
640
641         JComboBox JavaDoc combo = new JComboBox JavaDoc(new Object JavaDoc[] {
642             "class mode",
643             "aspect mode",
644             "instance mode",
645             "group mode"}
646         );
647
648         combo.addActionListener(
649             new ActionListener JavaDoc() {
650                     public void actionPerformed(ActionEvent JavaDoc event) {
651                         JComboBox JavaDoc cb = (JComboBox JavaDoc)event.getSource();
652                         String JavaDoc command = (String JavaDoc)cb.getSelectedItem();
653                         if (command.equals("class mode")) {
654                             setToolBar(buildClassBar());
655                         } else if (command.equals("aspect mode")) {
656                             setToolBar(buildAspectBar());
657                         } else if (command.equals("instance mode")) {
658                             setToolBar(buildInstanceBar());
659                         } else