View Javadoc

1   /*
2    * TreatmentIconPane.java
3    *
4    * Created on 25. april 2005, 15:08
5    */
6   
7   package com.vikash.firsttool.Diagram.DiagramBars;
8   import com.vikash.firsttool.Diagram.*;
9   import com.vikash.firsttool.UI.*;
10  import java.net.URL;
11  import java.awt.event.*;
12  import java.awt.*;
13  import javax.swing.*;
14  import javax.swing.Action;
15  import javax.swing.JToolBar;
16  /***
17   *
18   * @author  studajb
19   */
20  
21  public class TreatmentBar extends JToolBar{
22      
23      EditorPanel panel;
24       ButtonGroup group;
25       JMenu humanthreatmenu,systemthreatmenu,malicioussoftwaremenu;
26      /*** Creates a new instance of ThreatIconpane */
27      public TreatmentBar(final EditorPanel panel) {
28          this.panel=panel;
29          group=new ButtonGroup();
30           CreateIcon("Select","Select","Select");
31          CreateIcon("Treatment","vertex","Treatment");
32          CreateIcon("UnwantedIncident","vertex","UnwantedIncident");
33          CreateIcon("ThreatScenario","vertex","ThreatScenario");
34          CreateIcon("Asset","vertex","Asset");
35          CreateIcon("Include","dependency","<html><p align=\"center\">"+"Include"+"<br>"+"UnwantedIncident ----> ThreatScenario"+"</p></html>");
36          CreateIcon("Uniassociation","uniassociation","<html><p align=\"center\">"+"UniAssociation"+"<br>"+"UnwantedIncident ----> Asset"+"ThreatScenario ----> Asset"+"</p></html>");
37          CreateIcon("Avoid","dependency","<html><p align=\"center\">"+"Avoid"+"<br>"+"Treatment ----> UnwantedIncident"+"</p></html>");
38          CreateIcon("ReduceConsequence","dependency","<html><p align=\"center\">"+"ReduceConsequence"+"<br>"+"Treatment ----> UnwantedIncident"+"</p></html>");
39          CreateIcon("ReduceLikelihood","dependency","<html><p align=\"center\">"+"ReduceLikelihood"+"<br>"+"Treatment ----> UnwantedIncident"+"</p></html>");
40          CreateIcon("Transfer","dependency","<html><p align=\"center\">"+"Transfer"+"<br>"+"Treatment ----> UnwantedIncident"+"</p></html>");
41          //CreateIcon("TreatmentEvaluation","dependency","<html><p align=\"center\">"+"UniAssociation"+"<br>"+"UnwantedIncident ----> Asset"+"</p></html>");
42          
43          humanthreatmenu=new JMenu("Human Threats");
44         URL humanthreat=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/HumanThreat.gif");
45         humanthreatmenu.setIcon(new ImageIcon(humanthreat));
46          JMenuItem attackeritem=humanthreatmenu.add(CreateMenuItem("Attacker","vertex"));
47          JMenuItem intruderitem=humanthreatmenu.add(CreateMenuItem("Intruder","vertex"));
48          JMenuItem eavesdropperitem=humanthreatmenu.add(CreateMenuItem("Eavesdropper","vertex"));
49          JMenuItem maninthemiddleitem=humanthreatmenu.add(CreateMenuItem("Man-in-the-Middle","vertex"));
50          JMenuItem insideritem=humanthreatmenu.add(CreateMenuItem("Insider","vertex"));
51              
52         systemthreatmenu=new JMenu("System Threats");
53         URL systemthreat=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/SystemThreat.gif");
54         systemthreatmenu.setIcon(new ImageIcon(systemthreat));
55         JMenuItem hardwarefailureitem=systemthreatmenu.add(CreateMenuItem("HardwareFailure","vertex"));
56         JMenuItem softwarefailureitem=systemthreatmenu.add(CreateMenuItem("SoftwareFailure","vertex"));
57         
58         
59        malicioussoftwaremenu=new JMenu("Malicious Software");
60        URL malsoftware=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/MaliciousSoftware.gif");
61         malicioussoftwaremenu.setIcon(new ImageIcon(malsoftware));
62        JMenuItem virusitem=malicioussoftwaremenu.add(CreateMenuItem("Virus","vertex"));
63        JMenuItem wormitem=malicioussoftwaremenu.add(CreateMenuItem("Worm","vertex"));
64        JMenuItem zoombieitem=malicioussoftwaremenu.add(CreateMenuItem("Zoombie","vertex"));
65        JMenuItem horseitem=malicioussoftwaremenu.add(CreateMenuItem("TrojanHorse","vertex"));
66        JMenuItem bombitem=malicioussoftwaremenu.add(CreateMenuItem("LogicalBomb","vertex"));
67        JMenuItem trapdooritem=malicioussoftwaremenu.add(CreateMenuItem("TrapDoor","vertex"));
68       
69        
70        final JPopupMenu PopupMenu=new JPopupMenu();
71        PopupMenu.add(humanthreatmenu);
72        PopupMenu.add(systemthreatmenu);
73        PopupMenu.add(malicioussoftwaremenu);
74        
75        
76        final JButton ThreatsButton=new JButton();
77        URL threatbutton=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/ThreatAgent" +
78        ".gif");
79        ThreatsButton.setIcon(new ImageIcon(threatbutton));
80        ThreatsButton.setPreferredSize(new Dimension(30, 30));
81        ThreatsButton.setMinimumSize(new Dimension(30, 30));
82        ThreatsButton.setToolTipText("Threat Agents");
83        ThreatsButton.addMouseListener(new MouseAdapter(){
84            public void mousePressed(MouseEvent event){
85                PopupMenu.show(ThreatsButton,0,ThreatsButton.getHeight()-ThreatsButton.getMargin().bottom);
86            }
87        });
88        
89        
90        ThreatsButton.setPreferredSize(new Dimension(30, 30));
91        ThreatsButton.setMinimumSize(new Dimension(30, 30));
92       
93          add(ThreatsButton);
94        
95      }
96      private void CreateIcon(String name,String type,String tooltip){
97      
98      URL iconurl=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/"+name+".gif");
99      Action iconaction= new DrawAction(tooltip,new ImageIcon(iconurl),name,panel,type);
100     JToggleButton button = new JToggleButton(iconaction);
101     button.setPreferredSize(new Dimension(30,30));
102     button.setMaximumSize(new Dimension(30,30));
103     group.add(button);
104     add(button);
105     }
106     private DrawAction CreateMenuItem(String name,String type){
107     String icon=name;    
108     URL iconurl=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/"+icon+".gif");
109     DrawAction iconaction= new DrawAction(icon,new ImageIcon(iconurl),icon,panel,type);
110     return iconaction;
111     
112     }
113 }