Skip to content

Commit 5a21ceb

Browse files
committed
GH-54 Fixed Filter / Find shortcuts in affected views (Ctrl+G / Ctrl+F)
1 parent d1e97a8 commit 5a21ceb

File tree

6 files changed

+212
-3
lines changed

6 files changed

+212
-3
lines changed

visualvm/applicationviews/src/com/sun/tools/visualvm/application/views/threads/ApplicationThreadsView.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@
5050
import java.beans.PropertyChangeListener;
5151
import javax.swing.AbstractAction;
5252
import javax.swing.Action;
53+
import javax.swing.ActionMap;
5354
import javax.swing.BorderFactory;
5455
import javax.swing.ImageIcon;
56+
import javax.swing.InputMap;
5557
import javax.swing.JButton;
5658
import javax.swing.JComponent;
5759
import javax.swing.JLabel;
@@ -60,7 +62,9 @@
6062
import org.netbeans.lib.profiler.ui.components.ProfilerToolbar;
6163
import org.netbeans.lib.profiler.ui.swing.ActionPopupButton;
6264
import org.netbeans.lib.profiler.ui.swing.GrayLabel;
65+
import org.netbeans.lib.profiler.ui.swing.SearchUtils;
6366
import org.netbeans.lib.profiler.ui.threads.ThreadsPanel;
67+
import org.netbeans.modules.profiler.api.ActionsSupport;
6468
import org.netbeans.modules.profiler.api.ProfilerDialogs;
6569
import org.openide.util.ImageUtilities;
6670
import org.openide.util.NbBundle;
@@ -347,6 +351,27 @@ protected void filterSelected(ThreadsPanel.Filter filter) {
347351
};
348352
threadsPanel.threadsMonitoringEnabled();
349353

354+
InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
355+
ActionMap actionMap = getActionMap();
356+
357+
final String filterKey = org.netbeans.lib.profiler.ui.swing.FilterUtils.FILTER_ACTION_KEY;
358+
Action filterAction = new AbstractAction() {
359+
public void actionPerformed(ActionEvent e) {
360+
Action action = threadsPanel.getActionMap().get(filterKey);
361+
if (action != null && action.isEnabled()) action.actionPerformed(e);
362+
}
363+
};
364+
ActionsSupport.registerAction(filterKey, filterAction, actionMap, inputMap);
365+
366+
final String findKey = SearchUtils.FIND_ACTION_KEY;
367+
Action findAction = new AbstractAction() {
368+
public void actionPerformed(ActionEvent e) {
369+
Action action = threadsPanel.getActionMap().get(findKey);
370+
if (action != null && action.isEnabled()) action.actionPerformed(e);
371+
}
372+
};
373+
ActionsSupport.registerAction(findKey, findAction, actionMap, inputMap);
374+
350375
// -----------------------------------------------------------------
351376
// --- copy-pasted timeline toolbar from org.netbeans.modules.profiler.v2.features.ThreadsFeatureUI
352377

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.sun.tools.visualvm.modules.appui.actions;
26+
27+
import java.awt.event.InputEvent;
28+
import java.awt.event.KeyEvent;
29+
import javax.swing.Action;
30+
import javax.swing.ActionMap;
31+
import javax.swing.InputMap;
32+
import javax.swing.KeyStroke;
33+
import org.netbeans.lib.profiler.ui.swing.FilterUtils;
34+
import org.netbeans.lib.profiler.ui.swing.SearchUtils;
35+
import org.netbeans.modules.profiler.spi.ActionsSupportProvider;
36+
import org.openide.util.lookup.ServiceProvider;
37+
38+
/**
39+
* Definition of VisualVM shortcuts for UI actions.
40+
*
41+
* @author Jiri Sedlacek
42+
*/
43+
@ServiceProvider(service=ActionsSupportProvider.class, position=10)
44+
public final class VisualVMActionsSupportProvider extends ActionsSupportProvider {
45+
46+
public KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
47+
KeyStroke ks = null;
48+
49+
if (FilterUtils.FILTER_ACTION_KEY.equals(actionKey)) {
50+
ks = KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK);
51+
} else if (SearchUtils.FIND_ACTION_KEY.equals(actionKey)) {
52+
ks = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK);
53+
} else if (SearchUtils.FIND_NEXT_ACTION_KEY.equals(actionKey)) {
54+
ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0);
55+
} else if (SearchUtils.FIND_PREV_ACTION_KEY.equals(actionKey)) {
56+
ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_MASK);
57+
} else if (SearchUtils.FIND_SEL_ACTION_KEY.equals(actionKey)) {
58+
ks = KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.CTRL_MASK);
59+
}
60+
61+
if (ks != null) {
62+
actionMap.put(actionKey, action);
63+
inputMap.put(ks, actionKey);
64+
}
65+
66+
return ks;
67+
}
68+
69+
}

visualvm/profiler/src/com/sun/tools/visualvm/profiler/CPULivePanel.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
import java.awt.BorderLayout;
3030
import java.awt.event.ActionEvent;
3131
import java.awt.event.ItemEvent;
32+
import javax.swing.AbstractAction;
33+
import javax.swing.Action;
34+
import javax.swing.ActionMap;
3235
import javax.swing.Icon;
36+
import javax.swing.InputMap;
3337
import javax.swing.JButton;
38+
import javax.swing.JComponent;
3439
import javax.swing.JLabel;
3540
import javax.swing.JToggleButton;
3641
import javax.swing.SwingUtilities;
@@ -41,8 +46,10 @@
4146
import org.netbeans.lib.profiler.ui.cpu.LiveCPUViewUpdater;
4247
import org.netbeans.lib.profiler.ui.swing.GrayLabel;
4348
import org.netbeans.lib.profiler.ui.swing.MultiButtonGroup;
49+
import org.netbeans.lib.profiler.ui.swing.SearchUtils;
4450
import org.netbeans.modules.profiler.actions.ResetResultsAction;
4551
import org.netbeans.modules.profiler.actions.TakeSnapshotAction;
52+
import org.netbeans.modules.profiler.api.ActionsSupport;
4653
import org.netbeans.modules.profiler.api.GoToSource;
4754
import org.netbeans.modules.profiler.api.icons.GeneralIcons;
4855
import org.netbeans.modules.profiler.api.icons.Icons;
@@ -210,6 +217,27 @@ protected void foundInReverseCalls() {
210217
updater = new LiveCPUViewUpdater(cpuView, Profiler.getDefault().getTargetAppRunner().getProfilerClient());
211218
resetter = ProfilingResultsSupport.ResultsResetter.registerView(this);
212219

220+
InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
221+
ActionMap actionMap = getActionMap();
222+
223+
final String filterKey = org.netbeans.lib.profiler.ui.swing.FilterUtils.FILTER_ACTION_KEY;
224+
Action filterAction = new AbstractAction() {
225+
public void actionPerformed(ActionEvent e) {
226+
Action action = cpuView.getActionMap().get(filterKey);
227+
if (action != null && action.isEnabled()) action.actionPerformed(e);
228+
}
229+
};
230+
ActionsSupport.registerAction(filterKey, filterAction, actionMap, inputMap);
231+
232+
final String findKey = SearchUtils.FIND_ACTION_KEY;
233+
Action findAction = new AbstractAction() {
234+
public void actionPerformed(ActionEvent e) {
235+
Action action = cpuView.getActionMap().get(findKey);
236+
if (action != null && action.isEnabled()) action.actionPerformed(e);
237+
}
238+
};
239+
ActionsSupport.registerAction(findKey, findAction, actionMap, inputMap);
240+
213241

214242
// --- Toolbar ---------------------------------------------------------
215243

visualvm/profiler/src/com/sun/tools/visualvm/profiler/MemoryLivePanel.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
import java.awt.BorderLayout;
3030
import java.awt.event.ActionEvent;
3131
import java.awt.event.ItemEvent;
32+
import javax.swing.AbstractAction;
33+
import javax.swing.Action;
34+
import javax.swing.ActionMap;
3235
import javax.swing.Icon;
36+
import javax.swing.InputMap;
3337
import javax.swing.JButton;
38+
import javax.swing.JComponent;
3439
import javax.swing.JLabel;
3540
import javax.swing.JToggleButton;
3641
import javax.swing.SwingUtilities;
@@ -40,8 +45,10 @@
4045
import org.netbeans.lib.profiler.ui.memory.LiveMemoryView;
4146
import org.netbeans.lib.profiler.ui.memory.LiveMemoryViewUpdater;
4247
import org.netbeans.lib.profiler.ui.swing.GrayLabel;
48+
import org.netbeans.lib.profiler.ui.swing.SearchUtils;
4349
import org.netbeans.modules.profiler.actions.ResetResultsAction;
4450
import org.netbeans.modules.profiler.actions.TakeSnapshotAction;
51+
import org.netbeans.modules.profiler.api.ActionsSupport;
4552
import org.netbeans.modules.profiler.api.GoToSource;
4653
import org.netbeans.modules.profiler.api.icons.GeneralIcons;
4754
import org.netbeans.modules.profiler.api.icons.Icons;
@@ -186,6 +193,28 @@ protected void popupHidden() {
186193
updater = new LiveMemoryViewUpdater(memoryView, Profiler.getDefault().getTargetAppRunner().getProfilerClient());
187194
resetter = ProfilingResultsSupport.ResultsResetter.registerView(this);
188195

196+
InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
197+
ActionMap actionMap = getActionMap();
198+
199+
final String filterKey = org.netbeans.lib.profiler.ui.swing.FilterUtils.FILTER_ACTION_KEY;
200+
Action filterAction = new AbstractAction() {
201+
public void actionPerformed(ActionEvent e) {
202+
Action action = memoryView.getActionMap().get(filterKey);
203+
if (action != null && action.isEnabled()) action.actionPerformed(e);
204+
}
205+
};
206+
ActionsSupport.registerAction(filterKey, filterAction, actionMap, inputMap);
207+
208+
final String findKey = SearchUtils.FIND_ACTION_KEY;
209+
Action findAction = new AbstractAction() {
210+
public void actionPerformed(ActionEvent e) {
211+
Action action = memoryView.getActionMap().get(findKey);
212+
if (action != null && action.isEnabled()) action.actionPerformed(e);
213+
}
214+
};
215+
ActionsSupport.registerAction(findKey, findAction, actionMap, inputMap);
216+
217+
189218
// --- Toolbar ---------------------------------------------------------
190219

191220
lrLabel = new GrayLabel(Bundle.ObjectsFeatureUI_liveResults());

visualvm/sampler/src/com/sun/tools/visualvm/sampler/cpu/CPUView.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@
3535
import java.awt.event.HierarchyEvent;
3636
import java.awt.event.HierarchyListener;
3737
import java.awt.event.ItemEvent;
38+
import javax.swing.AbstractAction;
3839
import javax.swing.AbstractButton;
40+
import javax.swing.Action;
41+
import javax.swing.ActionMap;
3942
import javax.swing.Icon;
43+
import javax.swing.InputMap;
4044
import javax.swing.JButton;
45+
import javax.swing.JComponent;
4146
import javax.swing.JLabel;
4247
import javax.swing.JPanel;
4348
import javax.swing.JToggleButton;
@@ -48,7 +53,9 @@
4853
import org.netbeans.lib.profiler.ui.cpu.LiveCPUView;
4954
import org.netbeans.lib.profiler.ui.swing.GrayLabel;
5055
import org.netbeans.lib.profiler.ui.swing.MultiButtonGroup;
56+
import org.netbeans.lib.profiler.ui.swing.SearchUtils;
5157
import org.netbeans.modules.profiler.actions.TakeSnapshotAction;
58+
import org.netbeans.modules.profiler.api.ActionsSupport;
5259
import org.netbeans.modules.profiler.api.GoToSource;
5360
import org.netbeans.modules.profiler.api.icons.GeneralIcons;
5461
import org.netbeans.modules.profiler.api.icons.Icons;
@@ -79,7 +86,7 @@
7986
"MethodsFeatureUI_showDeltas=Show delta values"
8087
})
8188
final class CPUView extends JPanel {
82-
89+
8390
private final AbstractSamplerSupport.Refresher refresher;
8491
private boolean forceRefresh = false;
8592

@@ -229,6 +236,28 @@ protected void foundInReverseCalls() {
229236
};
230237
cpuView.putClientProperty(ProfilerResultsAction.PROP_APPLICATION, application);
231238

239+
InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
240+
ActionMap actionMap = getActionMap();
241+
242+
final String filterKey = org.netbeans.lib.profiler.ui.swing.FilterUtils.FILTER_ACTION_KEY;
243+
Action filterAction = new AbstractAction() {
244+
public void actionPerformed(ActionEvent e) {
245+
Action action = cpuView.getActionMap().get(filterKey);
246+
if (action != null && action.isEnabled()) action.actionPerformed(e);
247+
}
248+
};
249+
ActionsSupport.registerAction(filterKey, filterAction, actionMap, inputMap);
250+
251+
final String findKey = SearchUtils.FIND_ACTION_KEY;
252+
Action findAction = new AbstractAction() {
253+
public void actionPerformed(ActionEvent e) {
254+
Action action = cpuView.getActionMap().get(findKey);
255+
if (action != null && action.isEnabled()) action.actionPerformed(e);
256+
}
257+
};
258+
ActionsSupport.registerAction(findKey, findAction, actionMap, inputMap);
259+
260+
232261
// --- Toolbar ---------------------------------------------------------
233262

234263
lrLabel = new GrayLabel(Bundle.MethodsFeatureUI_liveResults());
@@ -382,5 +411,5 @@ public Dimension getPreferredSize() {
382411
add(cpuView, BorderLayout.CENTER);
383412

384413
}
385-
414+
386415
}

visualvm/sampler/src/com/sun/tools/visualvm/sampler/memory/MemoryView.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@
4848
import java.util.HashMap;
4949
import java.util.List;
5050
import java.util.Map;
51+
import javax.swing.AbstractAction;
5152
import javax.swing.AbstractButton;
53+
import javax.swing.Action;
54+
import javax.swing.ActionMap;
5255
import javax.swing.Icon;
5356
import javax.swing.ImageIcon;
57+
import javax.swing.InputMap;
5458
import javax.swing.JButton;
5559
import javax.swing.JComponent;
5660
import javax.swing.JLabel;
@@ -59,6 +63,7 @@
5963
import javax.swing.JPopupMenu;
6064
import javax.swing.JToggleButton;
6165
import javax.swing.SortOrder;
66+
import javax.swing.SwingUtilities;
6267
import javax.swing.UIManager;
6368
import javax.swing.table.AbstractTableModel;
6469
import org.netbeans.lib.profiler.ui.Formatters;
@@ -72,6 +77,7 @@
7277
import org.netbeans.lib.profiler.ui.swing.renderer.JavaNameRenderer;
7378
import org.netbeans.lib.profiler.ui.swing.renderer.NumberPercentRenderer;
7479
import org.netbeans.lib.profiler.utils.Wildcards;
80+
import org.netbeans.modules.profiler.api.ActionsSupport;
7581
import org.netbeans.modules.profiler.api.icons.GeneralIcons;
7682
import org.netbeans.modules.profiler.api.icons.Icons;
7783
import org.netbeans.modules.profiler.api.icons.LanguageIcons;
@@ -342,6 +348,29 @@ protected void popupHidden() {
342348

343349
ProfilerTableContainer tableContainer = new ProfilerTableContainer(table, false, null);
344350

351+
InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
352+
ActionMap actionMap = getActionMap();
353+
354+
final String filterKey = org.netbeans.lib.profiler.ui.swing.FilterUtils.FILTER_ACTION_KEY;
355+
Action filterAction = new AbstractAction() {
356+
public void actionPerformed(ActionEvent e) {
357+
MemoryView.this.activateFilter();
358+
}
359+
};
360+
ActionsSupport.registerAction(filterKey, filterAction, actionMap, inputMap);
361+
362+
final String findKey = SearchUtils.FIND_ACTION_KEY;
363+
Action findAction = new AbstractAction() {
364+
public void actionPerformed(ActionEvent e) {
365+
MemoryView.this.activateSearch();
366+
}
367+
};
368+
ActionsSupport.registerAction(findKey, findAction, actionMap, inputMap);
369+
370+
SwingUtilities.invokeLater(new Runnable() {
371+
public void run() { SearchUtils.enableSearchActions(table); }
372+
});
373+
345374

346375
// --- Toolbar ---------------------------------------------------------
347376

@@ -679,5 +708,5 @@ void add(ClassInfo cInfo) {
679708
public long getBytes() { return bytes; }
680709

681710
}
682-
711+
683712
}

0 commit comments

Comments
 (0)