mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 06:49:36 -04:00
simplified PLUS key stroke handling
This commit is contained in:
parent
e4a43c0cea
commit
3997b6c15f
@ -84,6 +84,7 @@ import java.util.List;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
|
||||
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
||||
import static de.neemann.gui.ToolTipAction.getCTRLMask;
|
||||
import static javax.swing.JOptionPane.showInputDialog;
|
||||
|
||||
/**
|
||||
@ -352,21 +353,16 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
circuitComponent.scaleCircuit(1 / 0.9);
|
||||
}
|
||||
}.setAcceleratorCTRLplus("PLUS");
|
||||
// enable [+] which is SHIFT+[=] on english keyboard layout
|
||||
circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, KeyEvent.CTRL_DOWN_MASK, false), zoomIn);
|
||||
circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_DOWN_MASK, false), zoomIn);
|
||||
circuitComponent.getActionMap().put(zoomIn, zoomIn);
|
||||
}.setAcceleratorCTRLplus("PLUS").enableAcceleratorIn(circuitComponent);
|
||||
circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, getCTRLMask()), zoomIn);
|
||||
|
||||
ToolTipAction zoomOut = new ToolTipAction(Lang.get("menu_zoomOut"), ICON_ZOOM_OUT) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
circuitComponent.scaleCircuit(0.9);
|
||||
}
|
||||
}.setAcceleratorCTRLplus("MINUS");
|
||||
// enable [+] which is SHIFT+[=] on english keyboard layout
|
||||
circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, KeyEvent.CTRL_DOWN_MASK, false), zoomOut);
|
||||
circuitComponent.getActionMap().put(zoomOut, zoomOut);
|
||||
}.setAcceleratorCTRLplus("MINUS").enableAcceleratorIn(circuitComponent);
|
||||
circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, getCTRLMask()), zoomOut);
|
||||
|
||||
ToolTipAction viewHelp = new ToolTipAction(Lang.get("menu_viewHelp"), ICON_HELP) {
|
||||
@Override
|
||||
|
@ -317,12 +317,10 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib
|
||||
}.setAcceleratorCTRLplus('D').enableAcceleratorIn(this);
|
||||
|
||||
ToolTipAction plus = new PlusMinusAction(1).setAccelerator("PLUS").enableAcceleratorIn(this);
|
||||
// enable [+] which is SHIFT+[=] on english keyboard layout
|
||||
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, 0, false), plus);
|
||||
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0, false), plus);
|
||||
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0), plus);
|
||||
|
||||
ToolTipAction minus = new PlusMinusAction(-1).setAccelerator("MINUS").enableAcceleratorIn(this);
|
||||
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0, false), minus);
|
||||
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0), minus);
|
||||
|
||||
new ToolTipAction(Lang.get("menu_programDiode")) {
|
||||
@Override
|
||||
|
@ -5,6 +5,8 @@
|
||||
*/
|
||||
package de.neemann.gui;
|
||||
|
||||
import de.neemann.digital.lang.Lang;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.InputEvent;
|
||||
@ -85,7 +87,7 @@ public abstract class ToolTipAction extends AbstractAction {
|
||||
* @return this for call chaining
|
||||
*/
|
||||
public ToolTipAction setAcceleratorCTRLplus(char key) {
|
||||
return setAccelerator(KeyStroke.getKeyStroke(key, getAccMask()));
|
||||
return setAccelerator(KeyStroke.getKeyStroke(key, getCTRLMask()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,10 +98,13 @@ public abstract class ToolTipAction extends AbstractAction {
|
||||
*/
|
||||
public ToolTipAction setAcceleratorCTRLplus(String key) {
|
||||
int keyCode = KeyStroke.getKeyStroke(key).getKeyCode();
|
||||
return setAccelerator(KeyStroke.getKeyStroke(keyCode, getAccMask()));
|
||||
return setAccelerator(KeyStroke.getKeyStroke(keyCode, getCTRLMask()));
|
||||
}
|
||||
|
||||
private int getAccMask() {
|
||||
/**
|
||||
* @return the system specific CTRL mask.
|
||||
*/
|
||||
public static int getCTRLMask() {
|
||||
int mask = InputEvent.CTRL_DOWN_MASK;
|
||||
if (Screen.isMac())
|
||||
mask = InputEvent.META_DOWN_MASK;
|
||||
@ -123,6 +128,8 @@ public abstract class ToolTipAction extends AbstractAction {
|
||||
* @return this for call chaining
|
||||
*/
|
||||
public ToolTipAction setAccelerator(KeyStroke accelerator) {
|
||||
if (accelerator.getKeyCode() == KeyEvent.VK_PLUS && Lang.currentLanguage().getName().equals("en"))
|
||||
accelerator = KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, accelerator.getModifiers());
|
||||
this.accelerator = accelerator;
|
||||
return this;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user