KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   Copyright (C) 2002 Renaud Pawlak
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   USA. */

18
19 package org.objectweb.jac.ide.diagrams;
20
21 import CH.ifa.draw.framework.DrawingEditor;
22 import CH.ifa.draw.framework.Figure;
23 import CH.ifa.draw.figures.TextTool;
24 import CH.ifa.draw.standard.TextHolder;
25 import java.awt.event.MouseEvent JavaDoc;
26
27 class AttachedTextTool extends TextTool {
28
29    private boolean fConnected = false;
30    
31    public AttachedTextTool(DrawingEditor editor, Figure prototype) {
32       super(editor, prototype);
33    }
34
35     /**
36      * If the pressed figure is a TextHolder it can be edited otherwise
37      * a new text figure is created.
38      */

39    public void mouseDown(MouseEvent JavaDoc e, int x, int y) {
40       super.mouseDown(e, x, y);
41       
42       Figure pressedFigure = drawing().findFigureInside(x, y);
43       TextHolder textHolder = getTypingTarget();
44       if (!fConnected && pressedFigure != null &&
45           textHolder != null && pressedFigure != textHolder
46           && (pressedFigure instanceof LinkFigure) ) {
47          
48          /*
49          ((AttachedTextFigure)getCreatedFigure())
50          .setSubstance((RelationLink)((LinkFigure)pressedFigure).getSubstance());*/

51          textHolder.connect(pressedFigure);
52          // ((ConnectedTextTool.UndoActivity)getUndoActivity()).setConnectedFigure(pressedFigure);
53
fConnected = true;
54       }
55    }
56    
57    /**
58     * If the pressed figure is a TextHolder it can be edited otherwise
59     * a new text figure is created.
60     */

61    public void activate() {
62       super.activate();
63       fConnected = false;
64    }
65    
66    /**
67     * Factory method for undo activity
68     */

69    /*
70    protected Undoable createUndoActivity() {
71       return new ConnectedTextTool.UndoActivity(view(), getTypingTarget().getText());
72    }
73    
74    public static class UndoActivity extends TextTool.UndoActivity {
75       private Figure myConnectedFigure;
76       
77       public UndoActivity(DrawingView newDrawingView, String newOriginalText) {
78          super(newDrawingView, newOriginalText);
79       }
80       
81       /*
82        * Undo the activity
83        * @return true if the activity could be undone, false otherwise
84        * /
85       public boolean undo() {
86          if (!super.undo()) {
87             return false;
88          }
89          
90          FigureEnumeration fe = getAffectedFigures();
91          while (fe.hasMoreElements()) {
92             Figure currentFigure = fe.nextFigure();
93             if (currentFigure instanceof TextHolder) {
94                TextHolder currentTextHolder = (TextHolder)currentFigure;
95                // the text figure didn't exist before
96                if (!isValidText(getOriginalText())) {
97                   currentTextHolder.disconnect(getConnectedFigure());
98                }
99                // the text figure did exist but was remove
100                else if (!isValidText(getBackupText())) {
101                   currentTextHolder.connect(getConnectedFigure());
102                }
103             }
104          }
105          
106          return true;
107       }
108       
109       /*
110        * Redo the activity
111        * @return true if the activity could be redone, false otherwise
112        * /
113       public boolean redo() {
114          if (!super.redo()) {
115             return false;
116          }
117          
118          FigureEnumeration fe = getAffectedFigures();
119          while (fe.hasMoreElements()) {
120             Figure currentFigure = fe.nextFigure();
121             if (currentFigure instanceof TextHolder) {
122                TextHolder currentTextHolder = (TextHolder)currentFigure;
123                // the text figure did exist but was remove
124                if (!isValidText(getBackupText())) {
125                   currentTextHolder.disconnect(getConnectedFigure());
126                }
127                // the text figure didn't exist before
128                else if (!isValidText(getOriginalText())) {
129                   currentTextHolder.connect(getConnectedFigure());
130                }
131             }
132          }
133          
134          return true;
135       }
136       
137       public void setConnectedFigure(Figure newConnectedFigure) {
138          myConnectedFigure = newConnectedFigure;
139       }
140       
141       public Figure getConnectedFigure() {
142          return myConnectedFigure;
143       }
144    }
145    */

146 }
147
Popular Tags