30
30
import javax .swing .JTextArea ;
31
31
import javax .swing .SwingConstants ;
32
32
import javax .swing .SwingUtilities ;
33
+ import javax .swing .event .ChangeListener ;
33
34
import javax .swing .event .SwingPropertyChangeSupport ;
34
35
35
36
import com .tagtraum .perf .gcviewer .log .TextAreaLogHandler ;
36
37
37
-
38
38
/**
39
39
*
40
40
* @author <a href="mailto:[email protected] ">Hendrik Schreiber</a>
41
41
* <p>Date: May 5, 2005<br/>
42
42
* Time: 2:14:36 PM</p>
43
43
*
44
44
*/
45
- public class ChartPanelView {
45
+ public class ChartPanelView extends JPanel {
46
46
47
+ public static final String EVENT_MINIMIZED = "minimized" ;
48
+
49
+ private static final long serialVersionUID = -4259423581681643286L ;
47
50
private static final ResourceBundle localStrings = ResourceBundle .getBundle ("com.tagtraum.perf.gcviewer.localStrings" );
48
51
private static final DataReaderFactory factory = new DataReaderFactory ();
49
52
50
53
private GCPreferences preferences ;
51
-
52
54
private ModelChartImpl modelChart ;
53
55
private ModelPanel modelPanel ;
54
56
private GCModel model ;
55
57
private ViewBar viewBar ;
56
- private boolean viewBarVisible ;
57
58
private boolean minimized ;
58
59
private SwingPropertyChangeSupport propertyChangeSupport ;
59
60
private GCDocument gcDocument ;
@@ -70,12 +71,59 @@ public ChartPanelView(GCDocument gcDocument, URL url) throws IOException {
70
71
this .viewBar = new ViewBar (this );
71
72
this .propertyChangeSupport = new SwingPropertyChangeSupport (this );
72
73
this .textAreaLogHandler = new TextAreaLogHandler ();
74
+
75
+ addComponents ();
76
+
73
77
final GCModel model = loadModel (url );
74
78
setModel (model );
75
79
// TODO delete
76
80
model .printDetailedInformation ();
77
81
}
78
82
83
+ private void addComponents () {
84
+ GridBagLayout layout = new GridBagLayout ();
85
+ setLayout (layout );
86
+
87
+ int row = 0 ;
88
+ GridBagConstraints constraints = new GridBagConstraints ();
89
+ constraints .fill = GridBagConstraints .HORIZONTAL ;
90
+ constraints .anchor = GridBagConstraints .NORTH ;
91
+
92
+ // show viewbar if needed (GCDocument knows, when this is necessary
93
+ // -> more than one chartPanel is displayed in the same document)
94
+ constraints .gridy = row ;
95
+ //if (isViewBarVisible()) {
96
+ viewBar .setVisible (false );
97
+ constraints .gridwidth = 2 ;
98
+ constraints .weightx = 2 ;
99
+ add (getViewBar (), constraints );
100
+ row ++;
101
+ //}
102
+
103
+ // show modelchart if not minimised
104
+ constraints .fill = GridBagConstraints .BOTH ;
105
+ constraints .gridy = row ;
106
+ constraints .gridwidth = 1 ;
107
+ constraints .gridheight = 1 ;
108
+ constraints .gridx = 0 ;
109
+ constraints .weightx = 2 ;
110
+ constraints .weighty = 2 ;
111
+ modelChart .setPreferredSize (new Dimension (800 , 1024 ));
112
+ modelChart .setVisible (!isMinimized ());
113
+ add (modelChart , constraints );
114
+
115
+ // show modelPanel if not minimised
116
+ constraints .gridy = row ;
117
+ constraints .gridheight = 1 ;
118
+ constraints .gridx = 1 ;
119
+ constraints .weightx = 0 ;
120
+ constraints .weighty = 0 ;
121
+ constraints .fill = GridBagConstraints .HORIZONTAL ;
122
+ constraints .anchor = GridBagConstraints .SOUTH ;
123
+ add (modelPanel , constraints );
124
+ modelPanel .setVisible (preferences .isShowDataPanel ());
125
+ }
126
+
79
127
/**
80
128
* @return true, if the files has been reloaded
81
129
* @throws IOException
@@ -124,13 +172,33 @@ public void run() {
124
172
}
125
173
126
174
public void invalidate () {
175
+ super .invalidate ();
176
+
127
177
modelChart .invalidate ();
128
178
modelPanel .invalidate ();
129
179
}
130
180
131
181
public void addPropertyChangeListener (PropertyChangeListener propertyChangeListener ) {
132
182
propertyChangeSupport .addPropertyChangeListener (propertyChangeListener );
133
183
}
184
+
185
+ public void addChartScrollBarChangeListener (ChangeListener changeListener ) {
186
+ modelChart .getViewport ().addChangeListener (changeListener );
187
+ }
188
+
189
+ public void removeChartScrollBarChangeListeners () {
190
+ for (ChangeListener listener : modelChart .getViewport ().getChangeListeners ()) {
191
+ if (listener instanceof ChartPanelView ) {
192
+ modelChart .getViewport ().removeChangeListener (listener );
193
+ }
194
+ }
195
+ }
196
+
197
+ public void setScrollBarVisible (boolean scrollBarVisible ) {
198
+ modelChart .setHorizontalScrollBarPolicy (scrollBarVisible
199
+ ? JScrollPane .HORIZONTAL_SCROLLBAR_AS_NEEDED
200
+ : JScrollPane .HORIZONTAL_SCROLLBAR_NEVER );
201
+ }
134
202
135
203
public ViewBar getViewBar () {
136
204
return viewBar ;
@@ -141,11 +209,11 @@ public JTextArea getParseLog() {
141
209
}
142
210
143
211
public boolean isViewBarVisible () {
144
- return viewBarVisible ;
212
+ return viewBar . isVisible () ;
145
213
}
146
214
147
215
public void setViewBarVisible (boolean viewBarVisible ) {
148
- this .viewBarVisible = viewBarVisible ;
216
+ this .viewBar . setVisible ( viewBarVisible ) ;
149
217
}
150
218
151
219
public boolean isMinimized () {
@@ -156,7 +224,11 @@ public void setMinimized(boolean minimized) {
156
224
boolean oldValue = this .minimized ;
157
225
if (minimized != this .minimized ) {
158
226
this .minimized = minimized ;
159
- propertyChangeSupport .firePropertyChange ("minimized" , oldValue , minimized );
227
+
228
+ modelChart .setVisible (!minimized );
229
+ modelPanel .setVisible (preferences .isShowDataPanel () && !minimized );
230
+
231
+ propertyChangeSupport .firePropertyChange (EVENT_MINIMIZED , oldValue , minimized );
160
232
}
161
233
}
162
234
@@ -175,6 +247,7 @@ public GCModel getModel() {
175
247
public void setModel (GCModel model ) {
176
248
this .model = model ;
177
249
this .modelPanel .setModel (model );
250
+ this .modelPanel .setVisible (preferences .isShowDataPanel ());
178
251
this .modelChart .setModel (model , preferences );
179
252
this .viewBar .setTitle (model .getURL ().toString ());
180
253
}
@@ -184,6 +257,7 @@ public void close() {
184
257
}
185
258
186
259
private static class ViewBar extends JPanel {
260
+ private static final long serialVersionUID = -5219100256784644319L ;
187
261
private JLabel title = new JLabel ();
188
262
private ViewBarButton closeButton = new ViewBarButton ("images/close.png" , "images/close_selected.png" );
189
263
private MinMaxButton minimizeButton = new MinMaxButton ();
@@ -237,6 +311,8 @@ protected void paintComponent(Graphics graphics) {
237
311
}
238
312
239
313
private static class ViewBarButton extends JButton {
314
+ private static final long serialVersionUID = 587920510707520092L ;
315
+
240
316
public ViewBarButton (String image1 , String image2 ) {
241
317
final ImageIcon imageIcon1 = new ImageIcon (Toolkit .getDefaultToolkit ().getImage (getClass ().getResource (image1 )));
242
318
final ImageIcon imageIcon2 = new ImageIcon (Toolkit .getDefaultToolkit ().getImage (getClass ().getResource (image2 )));
@@ -254,7 +330,9 @@ public void setIcons(final ImageIcon imageIcon1, final ImageIcon imageIcon2) {
254
330
}
255
331
256
332
}
333
+
257
334
private static class MinMaxButton extends JButton {
335
+ private static final long serialVersionUID = -6518226257396629789L ;
258
336
private final ImageIcon min1 = new ImageIcon (Toolkit .getDefaultToolkit ().getImage (getClass ().getResource ("images/minimize.png" )));
259
337
private final ImageIcon min2 = new ImageIcon (Toolkit .getDefaultToolkit ().getImage (getClass ().getResource ("images/minimize_selected.png" )));
260
338
private final ImageIcon max1 = new ImageIcon (Toolkit .getDefaultToolkit ().getImage (getClass ().getResource ("images/maximize.png" )));
0 commit comments