/
GPropertiesDialog.java
232 lines (197 loc) · 5.62 KB
/
GPropertiesDialog.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.awt.image.*;
import javax.imageio.*;
import java.beans.*; //Property change stuff
import javax.swing.table.*;
import com.sun.image.codec.jpeg.*;
import java.net.*;
import javax.imageio.ImageIO;
import java.awt.geom.*;
/** A PropertiesDialog controls the visual appearance of GDrawablePanels.
*/
public class GPropertiesDialog extends JDialog implements MouseListener, ActionListener, ItemListener{
//properties
private JTabbedPane pane;
private JPanel tabbedPanePanel;
private JButton apply;
private JButton close;
//container of objects
ObjectContainer objects;
//store stuff
private GUI gui;
/**
* The GPropertiesDialog class constructor.
*
*@param gui the GUI class
*/
public GPropertiesDialog(GUI gui){
//superclass constructor
super(gui, "Properties", false);
objects = new ObjectContainer();
//gui
this.gui = gui;
//set the fixed size
setSize(260,350);
setResizable(false);
setLayout(null);
//set up panels for stuff
pane = new JTabbedPane();
//add the tabbed panel
tabbedPanePanel = new JPanel();
tabbedPanePanel.add(pane);
tabbedPanePanel.setLayout(null);
this.getContentPane().add(tabbedPanePanel);
tabbedPanePanel.setBounds(0,0,this.getWidth(),280);
pane.setBounds(0,0,tabbedPanePanel.getWidth(),tabbedPanePanel.getHeight());
//set up buttons
apply = new JButton("Apply");
apply.setBounds(150,290,80,26);
this.getContentPane().add(apply);
close = new JButton("Close");
close.setBounds(50,290,80,26);
this.getContentPane().add(close);
addPanel(new GPropertiesPanelCustomObject(gui.getGMap()), "Object");
//add listeners
addMouseListener(this);
apply.addItemListener(this);
apply.addActionListener(this);
close.addItemListener(this);
close.addActionListener(this);
}
/**
* Get the tabbed pane associated with this properties dialog.
*@return The pane.
*/
public JTabbedPane getPane(){
return pane;
}
/**
* Get the panel that holds the tabbed pane associated with this properties dialog.
*@return The pane.
*/
public JPanel getTabbedPanePanel(){
return tabbedPanePanel;
}
/**
* Get this dialog's close button.
*@return The pane.
*/
public JButton getClose(){
return close;
}
/**
* Get this dialogs apply button.
*@return The pane.
*/
public JButton getApply(){
return apply;
}
private void apply(){
int size = getPanelsSize();
for(int i=0;i<size;i++){
getPanel(i).apply();
}
//System.out.println("apply from dialog");
gui.getTopPane().draw();
}
private void close(){
this.setVisible(false);
}
/**
* Method for adding a new Panel
* @param object The new Panel
*/
public void addPanel(GPropertiesPanel object, String title){
pane.add(object,title);
objects.add(object);
}
/**
* Method for removing a Panel by index reference
* @param index The index of the object to remove
*/
public void removePanel(int index){
pane.remove((GPropertiesPanel)objects.get(index));
objects.remove(index);
}
/**
* Method for removing a Panel by object reference
* @param object The object to remove
*/
public void removePanel(GPropertiesPanel object){
pane.remove(object);
objects.remove(object);
}
/** Method for removing all current Panels */
public void removeAllPanels(){
pane.removeAll();
objects.removeAll();
}
/**
* Method for getting a Panel by index reference
* @param index The index of the object
* @return The object with the given index
*/
public GPropertiesPanel getPanel(int index){
return (GPropertiesPanel)objects.get(index);
}
/**
* Method gets the size of this container.
* @return The size.
*/
public int getPanelsSize(){
return objects.getSize();
}
/**
* Method for getting the index of a given Panel
* @param object The object to get the index of
* @return The index of the given object
*/
public int getIndex(GPropertiesPanel object){
return objects.getIndex(object);
}
/**
*
*@param e It is the type of action event the user pursues.
*/
public void actionPerformed(ActionEvent e){
if(e.getSource() == apply) apply();
else if(e.getSource() == close) close();
}
/**
* A method for a mouse event when the mouse is released.
*
*/
public void mouseReleased(MouseEvent e){}
/**
* A method for a mouse event when the mouse is pressed.
*
*/
public void mousePressed(MouseEvent e){}
/**
* A method for a mouse event when the mouse is exited.
*
*/
public void mouseExited(MouseEvent e){}
/**
*
* A method for a mouse event when the mouse is entered.
*/
public void mouseEntered(MouseEvent e){}
/**
*
*A method for a mouse event when the mouse is clicked.
*/
public void mouseClicked(MouseEvent e){}
/**
*
*A method for an event when any item state is changed.
*@param evt It is the event that is detected to show that an item is changed.
*/
public void itemStateChanged(ItemEvent evt) {
}
}