27
27
import com .sun .tools .visualvm .core .ui .DesktopUtils ;
28
28
import com .sun .tools .visualvm .core .ui .components .SectionSeparator ;
29
29
import com .sun .tools .visualvm .profiler .CPUSettingsSupport ;
30
+ import com .sun .tools .visualvm .profiler .JDBCSettingsSupport ;
30
31
import com .sun .tools .visualvm .profiler .MemorySettingsSupport ;
32
+ import com .sun .tools .visualvm .profiler .ProfilerSettingsSupport ;
31
33
import com .sun .tools .visualvm .profiler .ProfilerSupport ;
32
34
import com .sun .tools .visualvm .profiling .presets .PresetSelector ;
35
+ import com .sun .tools .visualvm .profiling .presets .ProfilerPreset ;
33
36
import com .sun .tools .visualvm .profiling .presets .ProfilerPresets ;
34
37
import com .sun .tools .visualvm .uisupport .HorizontalLayout ;
35
38
import com .sun .tools .visualvm .uisupport .SeparatorLine ;
50
53
import java .awt .event .ActionEvent ;
51
54
import java .awt .event .ItemEvent ;
52
55
import java .net .URI ;
56
+ import java .util .ArrayList ;
57
+ import java .util .List ;
53
58
import javax .swing .BorderFactory ;
54
59
import javax .swing .ButtonGroup ;
55
60
import javax .swing .DefaultComboBoxModel ;
94
99
"LBL_Profile=Profile:" ,
95
100
"LBL_CPU=CPU" ,
96
101
"LBL_Memory=Memory" ,
102
+ "LBL_JDBC=JDBC" ,
97
103
"BTN_Clipboard=Copy to clipboard" ,
98
104
"CAP_Clipboard=Copy to Clipboard" ,
99
105
"MSG_Clipboard=Profiler parameter copied to clipboard" ,
@@ -111,14 +117,19 @@ final class StartupConfigurator {
111
117
112
118
private static final String CPU_ICON_PATH = "com/sun/tools/visualvm/profiler/startup/resources/cpu.png" ; // NOI18N
113
119
private static final String MEM_ICON_PATH = "com/sun/tools/visualvm/profiler/startup/resources/memory.png" ; // NOI18N
120
+ private static final String JDBC_ICON_PATH = "com/sun/tools/visualvm/profiler/startup/resources/jdbc.png" ; // NOI18N
114
121
private static final String HELP_ICON_PATH = "com/sun/tools/visualvm/profiler/startup/resources/help.png" ; // NOI18N
115
122
private static final Icon CPU_ICON = ImageUtilities .loadImageIcon (CPU_ICON_PATH , false );
116
123
private static final Icon MEM_ICON = ImageUtilities .loadImageIcon (MEM_ICON_PATH , false );
124
+ private static final Icon JDBC_ICON = ImageUtilities .loadImageIcon (JDBC_ICON_PATH , false );
117
125
private static final Icon HELP_ICON = ImageUtilities .loadImageIcon (HELP_ICON_PATH , false );
118
126
119
127
private CPUSettingsSupport cpuSettings ;
120
128
private MemorySettingsSupport memorySettings ;
121
- private PresetSelector refSelector ;
129
+ private JDBCSettingsSupport jdbcSettings ;
130
+
131
+ private DefaultComboBoxModel selectorModel ;
132
+ private List <PresetSelector > allSelectors ;
122
133
123
134
private JComponent ui ;
124
135
private boolean accepted ;
@@ -131,9 +142,11 @@ final class StartupConfigurator {
131
142
private JPanel panel ;
132
143
private Dimension cpuSize ;
133
144
private Dimension memorySize ;
145
+ private Dimension jdbcSize ;
134
146
135
147
private JRadioButton cpuSelector ;
136
148
private JRadioButton memorySelector ;
149
+ private JRadioButton jdbcSelector ;
137
150
private JComboBox java ;
138
151
private JComboBox arch ;
139
152
private JSpinner port ;
@@ -146,7 +159,8 @@ final class StartupConfigurator {
146
159
cpuSettings = new CPUSettingsSupport () {
147
160
public boolean presetValid () {
148
161
return cpuSettings .settingsValid () &&
149
- memorySettings .settingsValid ();
162
+ memorySettings .settingsValid () &&
163
+ jdbcSettings .settingsValid ();
150
164
}
151
165
public PresetSelector createSelector (Runnable presetSynchronizer ) {
152
166
return StartupConfigurator .this .createSelector (presetSynchronizer );
@@ -155,7 +169,18 @@ public PresetSelector createSelector(Runnable presetSynchronizer) {
155
169
memorySettings = new MemorySettingsSupport () {
156
170
public boolean presetValid () {
157
171
return cpuSettings .settingsValid () &&
158
- memorySettings .settingsValid ();
172
+ memorySettings .settingsValid () &&
173
+ jdbcSettings .settingsValid ();
174
+ }
175
+ public PresetSelector createSelector (Runnable presetSynchronizer ) {
176
+ return StartupConfigurator .this .createSelector (presetSynchronizer );
177
+ }
178
+ };
179
+ jdbcSettings = new JDBCSettingsSupport () {
180
+ public boolean presetValid () {
181
+ return cpuSettings .settingsValid () &&
182
+ memorySettings .settingsValid () &&
183
+ jdbcSettings .settingsValid ();
159
184
}
160
185
public PresetSelector createSelector (Runnable presetSynchronizer ) {
161
186
return StartupConfigurator .this .createSelector (presetSynchronizer );
@@ -165,12 +190,15 @@ public PresetSelector createSelector(Runnable presetSynchronizer) {
165
190
// Warmup, the implementation expects both panels to be created
166
191
cpuSettings .getComponent ();
167
192
memorySettings .getComponent ();
193
+ jdbcSettings .getComponent ();
168
194
}
169
195
170
196
private PresetSelector createSelector (Runnable presetSynchronizer ) {
197
+ if (selectorModel == null ) selectorModel = new DefaultComboBoxModel ();
198
+ if (allSelectors == null ) allSelectors = new ArrayList ();
171
199
PresetSelector selector = ProfilerPresets .getInstance ().createSelector (
172
- refSelector , presetSynchronizer );
173
- if ( refSelector == null ) refSelector = selector ; else refSelector = null ;
200
+ selectorModel , allSelectors , presetSynchronizer );
201
+ allSelectors . add ( selector ) ;
174
202
return selector ;
175
203
}
176
204
@@ -187,16 +215,15 @@ boolean accepted() {
187
215
return accepted ;
188
216
}
189
217
190
- CPUSettingsSupport getCPUSettings () {
191
- return cpuSettings ;
192
- }
193
-
194
- MemorySettingsSupport getMemorySettings () {
195
- return memorySettings ;
218
+ ProfilerSettingsSupport getSettings () {
219
+ if (cpuSelector .isSelected ()) return cpuSettings ;
220
+ else if (memorySelector .isSelected ()) return memorySettings ;
221
+ else if (jdbcSelector .isSelected ()) return jdbcSettings ;
222
+ return null ;
196
223
}
197
224
198
- boolean isCPUProfiling () {
199
- return cpuSelector . isSelected ();
225
+ ProfilerPreset getPreset () {
226
+ return ( ProfilerPreset ) selectorModel . getSelectedItem ();
200
227
}
201
228
202
229
String getJavaPlatform () {
@@ -280,13 +307,17 @@ public Dimension getPreferredSize() {
280
307
JPanel buttonsR = new JPanel (new HorizontalLayout (false ));
281
308
submit = new JButton (Bundle .BTN_Profile (), new ImageIcon (StartupProfilerAction .ICON )) {
282
309
protected void fireActionPerformed (ActionEvent e ) {
283
- boolean isCPU = isCPUProfiling ();
284
- boolean valid = isCPU ? cpuSettings .settingsValid () :
285
- memorySettings .settingsValid ();
286
- if (!valid ) {
287
- String msg = isCPU ? Bundle .MSG_InvalidCPUSettings () :
288
- Bundle .MSG_InvalidMemorySettings ();
289
- Dialogs .show (Dialogs .error (Bundle .CAP_InvalidSettings (), msg ));
310
+ String err = null ;
311
+ if (cpuSelector .isSelected ()) {
312
+ if (!cpuSettings .settingsValid ())
313
+ err = Bundle .MSG_InvalidCPUSettings ();
314
+ } else if (memorySelector .isSelected ()) {
315
+ if (!memorySettings .settingsValid ())
316
+ err = Bundle .MSG_InvalidMemorySettings ();
317
+ }
318
+
319
+ if (err != null ) {
320
+ Dialogs .show (Dialogs .error (Bundle .CAP_InvalidSettings (), err ));
290
321
} else {
291
322
accepted = true ;
292
323
Window w = SwingUtilities .getWindowAncestor (this );
@@ -327,6 +358,8 @@ protected void fireActionPerformed(ActionEvent e) {
327
358
cpuSize = panel .getPreferredSize ();
328
359
memorySize = new Dimension (cpuSize );
329
360
memorySize .height -= cpuSettings .getComponent ().getPreferredSize ().height - memorySettings .getComponent ().getPreferredSize ().height ;
361
+ jdbcSize = new Dimension (cpuSize );
362
+ jdbcSize .height -= cpuSettings .getComponent ().getPreferredSize ().height - jdbcSettings .getComponent ().getPreferredSize ().height ;
330
363
panel .setPreferredSize (cpuSize );
331
364
332
365
separator2 .setVisible (false );
@@ -484,6 +517,11 @@ private JPanel createProfilePanel() {
484
517
((JComponent )memory .getComponent (1 )).setBorder (BorderFactory .createEmptyBorder (3 , 0 , 0 , 0 ));
485
518
memory .setVisible (false );
486
519
520
+ final JComponent jdbc = jdbcSettings .getComponent ();
521
+ ((JComponent )jdbc .getComponent (0 )).setBorder (BorderFactory .createEmptyBorder (-3 , -10 , 0 , -10 ));
522
+ ((JComponent )jdbc .getComponent (1 )).setBorder (BorderFactory .createEmptyBorder (3 , 0 , 0 , 0 ));
523
+ jdbc .setVisible (false );
524
+
487
525
final JPanel profile = new JPanel (new VerticalLayout (false ));
488
526
profile .setBorder (BorderFactory .createEmptyBorder (5 , 13 , 15 , 5 ));
489
527
profile .setOpaque (false );
@@ -500,6 +538,7 @@ protected void fireItemStateChanged(ItemEvent e) {
500
538
if (e .getStateChange () == ItemEvent .SELECTED ) {
501
539
cpu .setVisible (true );
502
540
memory .setVisible (false );
541
+ jdbc .setVisible (false );
503
542
if (panel != null ) {
504
543
panel .setPreferredSize (cpuSize );
505
544
SwingUtilities .getWindowAncestor (profile ).pack ();
@@ -515,6 +554,7 @@ protected void fireItemStateChanged(ItemEvent e) {
515
554
if (e .getStateChange () == ItemEvent .SELECTED ) {
516
555
cpu .setVisible (false );
517
556
memory .setVisible (true );
557
+ jdbc .setVisible (false );
518
558
if (panel != null ) {
519
559
panel .setPreferredSize (memorySize );
520
560
SwingUtilities .getWindowAncestor (profile ).pack ();
@@ -523,10 +563,27 @@ protected void fireItemStateChanged(ItemEvent e) {
523
563
}
524
564
};
525
565
mode .add (memorySelector );
566
+ jdbcSelector = new IconRadioButton (Bundle .LBL_JDBC (), JDBC_ICON , false ) {
567
+ { bg .add (this ); }
568
+ protected void fireItemStateChanged (ItemEvent e ) {
569
+ super .fireItemStateChanged (e );
570
+ if (e .getStateChange () == ItemEvent .SELECTED ) {
571
+ cpu .setVisible (false );
572
+ memory .setVisible (false );
573
+ jdbc .setVisible (true );
574
+ if (panel != null ) {
575
+ panel .setPreferredSize (jdbcSize );
576
+ SwingUtilities .getWindowAncestor (profile ).pack ();
577
+ }
578
+ }
579
+ }
580
+ };
581
+ mode .add (jdbcSelector );
526
582
profile .add (mode );
527
583
528
584
profile .add (cpu );
529
585
profile .add (memory );
586
+ profile .add (jdbc );
530
587
531
588
return profile ;
532
589
}
0 commit comments