Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On the fly look and feel updates, change zoom hotkey to ctrl+alt+wheel #566

Merged
merged 3 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,15 @@ protected NamePanel getNamePanel() {
* @return a JLabel which subclasses can add to their GUI
*/
protected Component createTitleLabel() {
JLabel titleLabel = new JLabel(getStaticLabel());
Font curFont = titleLabel.getFont();
titleLabel.setFont(curFont.deriveFont((float) curFont.getSize() + 4));
return titleLabel;
return new JLabel(getStaticLabel()) {
@Override
public void updateUI() {
super.updateUI();
// Setting the font in updateUI reduces UI jumps when look and feel changes
Font curFont = getFont();
setFont(curFont.deriveFont((float) curFont.getSize() + 4));
}
};
}

/**
Expand Down
38 changes: 19 additions & 19 deletions src/core/src/main/java/org/apache/jmeter/gui/GuiPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.jmeter.gui;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.beans.Introspector;
import java.util.ArrayList;
Expand All @@ -36,6 +37,8 @@
import org.apache.jmeter.engine.util.ValueReplacer;
import org.apache.jmeter.exceptions.IllegalUserActionException;
import org.apache.jmeter.gui.UndoHistory.HistoryListener;
import org.apache.jmeter.gui.action.ActionNames;
import org.apache.jmeter.gui.action.ActionRouter;
import org.apache.jmeter.gui.action.TreeNodeNamingPolicy;
import org.apache.jmeter.gui.action.impl.DefaultTreeNodeNamingPolicy;
import org.apache.jmeter.gui.logging.GuiLogEventBus;
Expand Down Expand Up @@ -648,27 +651,24 @@ public void localeChanged(LocaleChangeEvent event) {
// will flush it away):
updateCurrentNode();

// Forget about all GUIs we've created so far: we'll need to re-created
// them all!
guis = new HashMap<>();
nodesToGui = new HashMap<>();
testBeanGUIs = new HashMap<>();

// BeanInfo objects also contain locale-sensitive data -- flush them
// away:
Introspector.flushCaches();

// Now put the current GUI in place. [This code was copied from the
// EditCommand action -- we can't just trigger the action because that
// would populate the current node with the contents of the new GUI --
// which is empty.]
MainFrame mf = getMainFrame(); // Fetch once
if (mf == null) { // Probably caused by unit testing on headless system
log.warn("Mainframe is null");
} else {
mf.setMainPanel((javax.swing.JComponent) getCurrentGui());
mf.setEditMenu(getTreeListener().getCurrentNode().createPopupMenu());
}
invalidateCachedUi();
}

public void invalidateCachedUi() {
// Save current edits from the GUI to tree model just in case
updateCurrentNode();

// Invalidate UIs
guis.clear();
nodesToGui.clear();
testBeanGUIs.clear();

// Call "start edit for the current tree node" action to show the UI
ActionRouter.getInstance().actionPerformed(
new ActionEvent(this, 3334, ActionNames.EDIT)
);
}

private String testPlanFile;
Expand Down
7 changes: 4 additions & 3 deletions src/core/src/main/java/org/apache/jmeter/gui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ public MainFrame(TreeModel treeModel, JMeterTreeListener treeListener) {
initTopLevelDndHandler();
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

int ctrlShiftMask = (IS_MAC ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK) |
InputEvent.SHIFT_DOWN_MASK;
int ctrlAltMask = (IS_MAC ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK) |
InputEvent.ALT_DOWN_MASK;

addMouseWheelListener(e -> {
if (e.getWheelRotation() == 0) {
Expand All @@ -243,7 +243,8 @@ public MainFrame(TreeModel treeModel, JMeterTreeListener treeListener) {
// See https://github.com/JetBrains/intellij-community/blob/21c99af7c78fc82aefc4d05646389f4991b08b38/bin/idea.properties#L133-L156
return;
}
if ((e.getModifiersEx() & ctrlShiftMask) == ctrlShiftMask) {
// Shift down means "horizontal scrolling" on macOS, and we need only vertical one
if ((e.getModifiersEx() & (ctrlAltMask | InputEvent.SHIFT_DOWN_MASK)) == ctrlAltMask) {
final float scale = 1.1f;
int rotation = e.getWheelRotation();
if (rotation > 0) { // DOWN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Set;
import java.util.prefs.Preferences;

import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

Expand Down Expand Up @@ -212,6 +211,7 @@ public static void activateLookAndFeel(String command) {
} else {
UIManager.setLookAndFeel(className);
UIManager.put("Button.defaultButtonFollowsFocus", false);
LafManager.updateLaf();
}
PREFS.put(USER_PREFS_KEY, item.command);
} catch (UnsupportedLookAndFeelException
Expand All @@ -230,14 +230,7 @@ public static void activateLookAndFeel(String command) {
public void doAction(ActionEvent ev) {
try {
activateLookAndFeel(ev.getActionCommand());
JMeterUtils.refreshUI();
int chosenOption = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(), JMeterUtils
.getResString("laf_quit_after_change"), // $NON-NLS-1$
JMeterUtils.getResString("exit"), // $NON-NLS-1$
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (chosenOption == JOptionPane.YES_OPTION) {
ActionRouter.getInstance().doActionNow(new ActionEvent(ev.getSource(), ev.getID(), ActionNames.RESTART));
}
GuiPackage.getInstance().invalidateCachedUi();
} catch (IllegalArgumentException e) {
JMeterUtils.reportErrorToUser(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.weisj.darklaf.ui.button.DarkButtonUI;

/**
* The JMeter main toolbar class
*
Expand Down Expand Up @@ -126,7 +128,18 @@ private static JButton makeButtonItemRes(IconToolbarBean iconBean) throws Except
if (imageURL == null) {
throw new Exception("No icon for: " + iconBean.getActionName());
}
JButton button = new JButton(new ImageIcon(imageURL));
JButton button = new JButton(new ImageIcon(imageURL)) {
@Override
public void updateUI() {
super.updateUI();
// Certain LaFs might alter button configuration, so we revert it to the way we want
// For instance, https://github.com/weisJ/darklaf/issues/84
setFocusable(false);
setRolloverEnabled(true);
putClientProperty(DarkButtonUI.KEY_VARIANT, DarkButtonUI.VARIANT_SHADOW);
putClientProperty(DarkButtonUI.KEY_THIN, true);
}
};
button.setToolTipText(JMeterUtils.getResString(iconBean.getI18nKey()));
final URL imageURLPressed = JMeterUtils.class.getClassLoader().getResource(iconBean.getIconPathPressed());
button.setPressedIcon(new ImageIcon(imageURLPressed));
Expand Down
14 changes: 2 additions & 12 deletions src/core/src/main/java/org/apache/jmeter/util/JMeterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
package org.apache.jmeter.util;

import java.awt.Component;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.Frame;
import java.awt.HeadlessException;
import java.awt.Window;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -73,6 +70,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.weisj.darklaf.LafManager;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.security.AnyTypePermission;
import com.thoughtworks.xstream.security.NoTypePermission;
Expand Down Expand Up @@ -1267,15 +1265,7 @@ public static void applyScaleOnFonts(final float scale) {
* Refresh UI after LAF change or resizing
*/
public static final void refreshUI() {
for (Window w : Window.getWindows()) {
SwingUtilities.updateComponentTreeUI(w);
if (w.isDisplayable() &&
(w instanceof Frame ? !((Frame)w).isResizable() :
w instanceof Dialog ? !((Dialog)w).isResizable() :
true)) {
w.pack();
}
}
LafManager.updateLaf();
}

/**
Expand Down
6 changes: 6 additions & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ are gray. It is purely a UI change, and the behavior is not altered.

<p>Tree context menu is shown even in case the node selection is changed. Previously
the popup did disappear and it was required to select a node first and only then launch popup.</p>

<p>Update look and feel without restart</p>

<p>Use <keycombo><keysym>CTRL</keysym><keysym>ALT</keysym><keysym>wheel</keysym></keycombo> for zooming
fonts. Previous shortcut was <keycombo><keysym>CTRL</keysym><keysym>SHIFT</keysym><keysym>wheel</keysym></keycombo>,
however, it conflicted with horizontal scrolling.</p>
<!--
<ch_title>Functions</ch_title>
-->
Expand Down