1
2
3
4
5
6
7 package com.vikash.firsttool.UI;
8 import com.vikash.firsttool.Diagram.*;
9 import java.net.URL;
10 import java.awt.event.*;
11 import java.awt.*;
12
13 import javax.swing.*;
14 import javax.swing.Action;
15 import com.vikash.firsttool.ToolMain;
16
17 /***
18 *
19 * @author studajb
20 */
21
22 public class ToolBar extends JToolBar {
23
24
25 ToolInternalFrame internalframe;
26 EditorPanel panel;
27 ToolGraph graph;
28 MainFrame frame;
29 MainEditor editor;
30 private Action undoaction, redoaction,zoomaction,zoominaction,zoomoutaction,
31 cutaction,copyaction,pasteaction,deleteaction,deleteviewaction,saveaction,saveasaction,openaction,newaction,
32 assetdiagaction,swotdiagaction,unwanteddiagaction,riskdiagaction,threatdiagaction,treatmentdiagaction,
33 treateffectdiagaction;
34
35 public ToolBar(final MainFrame frame) {
36
37
38 this.frame=frame;
39 setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
40 setFloatable(false);
41 setMargin(new Insets(0,0,0,0));
42
43
44
45
46 URL New=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/New.gif");
47 newaction = new AbstractAction("",new ImageIcon(New)){
48 public void actionPerformed(ActionEvent e)
49 {
50 ToolMain.newProject(true);
51 }
52 };
53 newaction.putValue(Action.SHORT_DESCRIPTION,"New Project");
54
55
56
57 URL open=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/open.gif");
58 openaction = new AbstractAction("",new ImageIcon(open)){
59 public void actionPerformed(ActionEvent e)
60 {
61 ToolMain.newProject(true);
62 editor=frame.getEditor();;
63 editor.openfile();
64
65 }
66 };
67 openaction.putValue(Action.SHORT_DESCRIPTION,"Open Project");
68
69
70
71 URL save=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/save.gif");
72 saveaction = new AbstractAction("",new ImageIcon(save)){
73 public void actionPerformed(ActionEvent e)
74 {
75 editor=frame.getEditor();;
76 editor.savefile();
77
78 }
79 };
80 saveaction.putValue(Action.SHORT_DESCRIPTION,"Save");
81
82
83
84 URL saveas=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/saveas.gif");
85 saveasaction = new AbstractAction("",new ImageIcon(saveas)){
86 public void actionPerformed(ActionEvent e)
87 {
88 editor=frame.getEditor();
89 editor.saveasfile();
90
91 }
92 };
93 saveasaction.putValue(Action.SHORT_DESCRIPTION,"SaveAs");
94
95
96
97
98
99 copyaction=CopyAction.getinstance(frame,false);
100 createButton(copyaction);
101
102
103 cutaction=CutAction.getinstance(frame,false);
104 createButton(cutaction);
105
106
107 pasteaction=PasteAction.getinstance(frame,false);
108 createButton(pasteaction);
109
110
111 deleteaction=DeleteAction.getinstance(frame,false);
112 createButton(deleteaction);
113 deleteviewaction=DeleteViewAction.getinstance(frame,false);
114 createButton(deleteviewaction);
115 addSeparator();
116
117
118
119 undoaction = UndoAction.getinstance(frame,false);
120 createButton(undoaction);
121
122
123 redoaction = RedoAction.getinstance(frame,false);
124 createButton(redoaction);
125
126 addSeparator();
127
128
129
130
131 URL zoom=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/zoom.gif");
132 zoomaction = new AbstractAction("",new ImageIcon(zoom)){
133 public void actionPerformed(ActionEvent e)
134 {
135 getCurrentGraph();
136 graph.setScale(1.0);
137 }
138 };
139 zoomaction.putValue(Action.SHORT_DESCRIPTION,"Normal Size");
140 createButton(zoomaction);
141
142
143
144 URL zoomin=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/zoomin.gif");
145 zoominaction = new AbstractAction("",new ImageIcon(zoomin)){
146 public void actionPerformed(ActionEvent e)
147 {
148 getCurrentGraph();
149 graph.setScale(1.5*graph.getScale());
150 }
151 };
152 zoominaction.putValue(Action.SHORT_DESCRIPTION,"Zoom In");
153 createButton(zoominaction);
154
155
156
157 URL zoomout=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/zoomout.gif");
158 zoomoutaction = new AbstractAction("",new ImageIcon(zoomout)){
159 public void actionPerformed(ActionEvent e)
160 {
161 getCurrentGraph();
162 graph.setScale(graph.getScale()/1.5);
163 }
164 };
165 zoomoutaction.putValue(Action.SHORT_DESCRIPTION,"Zoom Out");
166 createButton(zoomoutaction);
167
168 addSeparator();
169
170 FindAction find=new FindAction(frame);
171 createButton(find);
172 addSeparator();
173
174 ColorFillAction colorfill= new ColorFillAction(frame);
175 createButton(colorfill);
176
177 LineColorAction linecolor=new LineColorAction(frame);
178 createButton(linecolor);
179
180 BorderColorAction bordercolor=new BorderColorAction(frame);
181 createButton(bordercolor);
182 addSeparator();
183
184 TextFontAction fonttype=new TextFontAction(frame);
185 add(fonttype);
186 TextFontSizeAction fontsize=new TextFontSizeAction(frame);
187 add(fontsize);
188 TextFontStyleAction fontstyle=new TextFontStyleAction(frame);
189 add(fontstyle);
190 addSeparator();
191
192
193
194
195 try{
196 swotdiagaction = new AddDiagramAction(frame,SWOTDiagram.class,"EnterpriseThreat");
197
198
199 assetdiagaction = new AddDiagramAction(frame,AssetDiagram.class,"Asset");
200
201
202
203 unwanteddiagaction = new AddDiagramAction(frame,UnwantedIncidentDiagram.class,"UnwantedIncident");
204 createButton(unwanteddiagaction);
205
206 riskdiagaction = new AddDiagramAction(frame,RiskDiagram.class,"Risk");
207
208
209 treatmentdiagaction = new AddDiagramAction(frame,TreatmentDiagram.class,"Treatment");
210 createButton(treatmentdiagaction);
211
212 treateffectdiagaction = new AddDiagramAction(frame,TreatmentEffectDiagram.class,"TreatmentEffect");
213
214 }catch(Exception excp){
215 excp.printStackTrace();
216 }
217
218
219 }
220 private void createButton(Action action){
221 JButton button=new JButton(action);
222 button.setPreferredSize(new Dimension(30,30));
223 button.setMaximumSize(new Dimension(30,30));
224 add(button);
225 }
226
227
228 public Action getUndoAction() {
229 return undoaction;
230 }
231
232 public Action getRedoAction() {
233 return redoaction;
234 }
235 public Action getcopyaction(){
236 return copyaction;
237 }
238 public Action getcutaction()
239 {
240 return cutaction;
241 }
242 public Action getdeleteaction()
243 {
244 return deleteaction;
245 }
246 public ToolGraph getCurrentGraph(){
247 internalframe=(ToolInternalFrame)frame.getDesktopPane().getSelectedFrame();
248 if(internalframe==null) return null;
249 graph=internalframe.getGraph();
250 return graph;
251 }
252 }