|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
@@ -107,53 +107,49 @@ ProfilerPreset presetToCreate() {
|
107 | 107 | }
|
108 | 108 |
|
109 | 109 | void optionsSubmitted(final ProfilerPreset selected) {
|
110 |
| - SwingUtilities.invokeLater(new Runnable() { |
111 |
| - public void run() { |
112 |
| - Map<DefaultComboBoxModel, Boolean> models = new HashMap(); |
113 |
| - Iterator<WeakReference<PresetSelector>> selectorsI = |
114 |
| - selectors.iterator(); |
115 |
| - |
116 |
| - while (selectorsI.hasNext()) { |
117 |
| - WeakReference<PresetSelector> selectorR = selectorsI.next(); |
118 |
| - PresetSelector selector = selectorR.get(); |
119 |
| - if (selector == null) { |
120 |
| - selectorsI.remove(); |
121 |
| - } else if (SwingUtilities.getRoot(selector) == null) { |
122 |
| - selectorsI.remove(); |
123 |
| - } else { |
124 |
| - DefaultComboBoxModel model = selector.getModel(); |
125 |
| - boolean savingCustom = selector.checkSavingCustom(); |
126 |
| - if (!Boolean.TRUE.equals(models.get(model))) |
127 |
| - models.put(model, savingCustom); |
128 |
| - } |
129 |
| - } |
130 |
| - |
131 |
| - for (DefaultComboBoxModel model : models.keySet()) { |
132 |
| - ProfilerPreset selectedPreset = (ProfilerPreset)model.getSelectedItem(); |
133 |
| - ProfilerPreset defaultPreset = (ProfilerPreset)model.getElementAt(0); |
134 |
| - ProfilerPreset customPreset = model.getSize() < 2 ? null : |
135 |
| - (ProfilerPreset)model.getElementAt(1); |
136 |
| - if (customPreset != null && !PresetSelector.isCustomPreset(customPreset)) |
137 |
| - customPreset = null; |
138 |
| - |
139 |
| - boolean savingCustom = models.get(model); |
140 |
| - |
| 110 | + Map<DefaultComboBoxModel, Boolean> models = new HashMap(); |
| 111 | + Iterator<WeakReference<PresetSelector>> selectorsI = |
| 112 | + selectors.iterator(); |
| 113 | + |
| 114 | + while (selectorsI.hasNext()) { |
| 115 | + WeakReference<PresetSelector> selectorR = selectorsI.next(); |
| 116 | + PresetSelector selector = selectorR.get(); |
| 117 | + if (selector == null) { |
| 118 | + selectorsI.remove(); |
| 119 | + } else if (SwingUtilities.getRoot(selector) == null) { |
| 120 | + selectorsI.remove(); |
| 121 | + } else { |
| 122 | + DefaultComboBoxModel model = selector.getModel(); |
| 123 | + boolean savingCustom = selector.checkSavingCustom(); |
| 124 | + if (!Boolean.TRUE.equals(models.get(model))) |
| 125 | + models.put(model, savingCustom); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + for (DefaultComboBoxModel model : models.keySet()) { |
| 130 | + ProfilerPreset selectedPreset = (ProfilerPreset)model.getSelectedItem(); |
| 131 | + ProfilerPreset defaultPreset = (ProfilerPreset)model.getElementAt(0); |
| 132 | + ProfilerPreset customPreset = model.getSize() < 2 ? null : |
| 133 | + (ProfilerPreset)model.getElementAt(1); |
| 134 | + if (customPreset != null && !PresetSelector.isCustomPreset(customPreset)) |
| 135 | + customPreset = null; |
| 136 | + |
| 137 | + boolean savingCustom = models.get(model); |
| 138 | + |
141 | 139 | // internalChange = true;
|
142 | 140 |
|
143 |
| - model.removeAllElements(); |
144 |
| - model.addElement(defaultPreset); |
145 |
| - if (!savingCustom && customPreset != null) model.addElement(customPreset); |
146 |
| - for (ProfilerPreset preset : presets) model.addElement(preset); |
147 |
| - |
148 |
| - ProfilerPreset toSelect = savingCustom && selected != null ? selected : |
149 |
| - selectedPreset; |
150 |
| - if (model.getIndexOf(toSelect) >= 0) model.setSelectedItem(toSelect); |
151 |
| - else model.setSelectedItem(model.getElementAt(0)); |
| 141 | + model.removeAllElements(); |
| 142 | + model.addElement(defaultPreset); |
| 143 | + if (!savingCustom && customPreset != null) model.addElement(customPreset); |
| 144 | + for (ProfilerPreset preset : presets) model.addElement(preset); |
| 145 | + |
| 146 | + ProfilerPreset toSelect = savingCustom && selected != null ? selected : |
| 147 | + selectedPreset; |
| 148 | + if (model.getIndexOf(toSelect) >= 0) model.setSelectedItem(toSelect); |
| 149 | + else model.setSelectedItem(model.getElementAt(0)); |
152 | 150 |
|
153 | 151 | // internalChange = false;
|
154 |
| - } |
155 |
| - } |
156 |
| - }); |
| 152 | + } |
157 | 153 | }
|
158 | 154 |
|
159 | 155 | public PresetSelector createSelector(DefaultComboBoxModel selectorsModel,
|
@@ -233,16 +229,12 @@ public void run() {
|
233 | 229 | }
|
234 | 230 |
|
235 | 231 | void savePresets(final PresetsModel toSave) {
|
236 |
| - SwingUtilities.invokeLater(new Runnable() { |
237 |
| - public void run() { |
238 |
| - presets.clear(); |
239 |
| - Enumeration en = toSave.elements(); |
240 |
| - while (en.hasMoreElements()) |
241 |
| - presets.add((ProfilerPreset)en.nextElement()); |
242 |
| - VisualVM.getInstance().runTask(new Runnable() { |
243 |
| - public void run() { doSavePresets(toSave); } |
244 |
| - }); |
245 |
| - } |
| 232 | + presets.clear(); |
| 233 | + Enumeration en = toSave.elements(); |
| 234 | + while (en.hasMoreElements()) |
| 235 | + presets.add((ProfilerPreset)en.nextElement()); |
| 236 | + VisualVM.getInstance().runTask(new Runnable() { |
| 237 | + public void run() { doSavePresets(toSave); } |
246 | 238 | });
|
247 | 239 | }
|
248 | 240 |
|
|
0 commit comments