/
GPopupMenu.java
158 lines (128 loc) · 4.33 KB
/
GPopupMenu.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Class GPopupMenu is a group of radio buttons/menu actions displayed as a popup menu when a
* right click is performed on the GUI. It extends JPopupMenu.
* @author Dan
*/
public class GPopupMenu extends JPopupMenu{
/**
* Declaration of the instance of the popup
*/
private JPopupMenu popup;
/**
* Declaration of the instance of the GUI
*/
private final GUI gui;
/**
* Declaration of the objectIndex for referencing objects
*/
private int objectIndex;
/**
* Declaration of the menu action for removing an object
*/
private JMenuAction removeObject;
/**
* Method to initiate the popup and add the necessary menu items and radio
* buttons to it including:
* <ul>
* <li> Remove Pane menu action
* <li> Add Object menu action
* <li> Remove Object menu action
* <li> Map Dragging radio button
* <li> Selection Rectangle radio button </ul>
*
* @param gui The GUI instance which will listen for the popup creation.
*/
public GPopupMenu(GUI gui) {
// Save the instance of the gui
this.gui = gui;
// Declaration of the general menuItem
JMenuItem menuItem;
// Declaration of the general JMenuRadioButton
JRadioButtonMenuItem rb, rb2;
// Declaration of the general JCheckBoxMenuItem
JCheckBoxMenuItem cb;
// Instantiation of the PopupMenu
popup = new JPopupMenu();
// Create some menu items for the popupmenu
menuItem = new JMenuActionSetPaneTitle(gui);
this.add(menuItem);
menuItem = new JMenuActionRemovePane(gui);
this.add(menuItem);
removeObject = new JMenuActionRemoveGDrawableObject(gui);
this.add(removeObject);
// New separator between actions and the radio buttons
this.add( new JSeparator() );
//copy
menuItem = new JMenuActionCopy(gui);
this.add(menuItem);
//paste
menuItem = new JMenuActionPaste(gui);
this.add(menuItem);
// New separator between actions and the radio buttons
this.add( new JSeparator() );
// New button group for the radio buttons
ButtonGroup group = new ButtonGroup();
// Create the radio buttons
rb = new JMenuRadioButtonDragOn(gui);
group.add(rb);
this.add(rb);
rb2 = new JMenuRadioButtonSelectionOn(gui);
group.add(rb2);
this.add(rb2);
rb = new JMenuRadioButtonCalculateDistance(gui);
group.add(rb);
this.add(rb);
rb = new JMenuRadioButtonAddPoints(gui);
group.add(rb);
this.add(rb);
rb = new JMenuRadioButtonAddLines(gui);
group.add(rb);
this.add(rb);
rb = new JMenuRadioButtonAddText(gui);
group.add(rb);
this.add(rb);
rb = new JMenuRadioButtonAddImages(gui);
group.add(rb);
this.add(rb);
// New separator between actions and the radio buttons
this.add( new JSeparator() );
/*
cb = new JMenuCheckBoxSmartClick(gui);
this.add(cb);
*/
// New separator between actions and the radio buttons
this.add( new JSeparator() );
//paste
menuItem = new JMenuActionShowProperties(gui);
this.add(menuItem);
// Define the radio button to be selected by default
this.setSelected(rb2);
}
/**
* Method to check and update the removeObject menu actions state when necessary
*
* @param invoker The component in whose space the popup menu is to appear.
* @param x The x coordinate in invoker's coordinate space at which the popup menu
* is to be displayed.
* @param y The y coordinate in invoker's coordinate space at which the popup menu
* is to be displayed.
*/
public void show(Component invoker, int x, int y){
update();
super.show(invoker,x,y);
}
/**
* Method to set the boolean value of whether the menu action removeObject
* is enabled or not depending if the right click occured on an object.
*/
public void update(){
if(gui.getGMap().getGDraw().getSelected().getSize() == 0){
removeObject.setEnabled(false);
}else{
removeObject.setEnabled(true);
}
}
}