From c1810afebe2f535c798098c2147697fd634f3f18 Mon Sep 17 00:00:00 2001 From: Matt Foulks Date: Wed, 2 Nov 2022 12:55:19 -0400 Subject: [PATCH 1/8] Added ability to zoom to current view by scrolling while holding shift --- .../perf/gcviewer/view/AboutDialog.java | 1 + .../perf/gcviewer/view/GCDocument.java | 3 +- .../perf/gcviewer/view/GCViewerGui.java | 33 ++++++++++++++++++- .../perf/gcviewer/view/ModelChartImpl.java | 25 +++++++++++--- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/AboutDialog.java b/src/main/java/com/tagtraum/perf/gcviewer/view/AboutDialog.java index 9899ab68..f6146276 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/AboutDialog.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/AboutDialog.java @@ -43,6 +43,7 @@ public class AboutDialog extends ScreenCenteredDialog implements ActionListener "Cka3o4Huk", "Frank Dietrich", "Bernd Eckenfels", + "Matt Foulks", "Ryan Gardner", "Martin Geldmacher", "Neil Gentleman", diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/GCDocument.java b/src/main/java/com/tagtraum/perf/gcviewer/view/GCDocument.java index a5897360..87dacec1 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/GCDocument.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/GCDocument.java @@ -4,8 +4,7 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Point; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; +import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/GCViewerGui.java b/src/main/java/com/tagtraum/perf/gcviewer/view/GCViewerGui.java index 0b153e8a..c5331af9 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/GCViewerGui.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/GCViewerGui.java @@ -4,6 +4,8 @@ import javax.swing.*; import java.awt.*; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; import java.beans.PropertyVetoException; import java.util.ArrayList; import java.util.List; @@ -23,12 +25,41 @@ public class GCViewerGui extends JFrame { private GCViewerGuiToolBar toolBar; private GCPreferences preferences; + private static boolean isShiftPressed; + private static boolean isControlPressed; + private static boolean isAltPressed; + + public static boolean isShiftPressed() { + return isShiftPressed; + } + + public static boolean isControlPressed() { + return isControlPressed; + } + + public static boolean isAltPressed() { + return isAltPressed; + } private RecentGCResourcesMenu recentResourceNamesMenu; public GCViewerGui() { super("tagtraum industries incorporated - GCViewer"); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + + KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + manager.addKeyEventDispatcher(new KeyEventDispatcher() { + @Override + public boolean dispatchKeyEvent(KeyEvent e) { + + if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_SHIFT) { isShiftPressed = true; } + else if (e.getID() == KeyEvent.KEY_RELEASED && e.getKeyCode() == KeyEvent.VK_SHIFT) { isShiftPressed = false; } + else if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_CONTROL) { isControlPressed = true; } + else if (e.getID() == KeyEvent.KEY_RELEASED && e.getKeyCode() == KeyEvent.VK_CONTROL) { isControlPressed = false; } + else if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ALT) { isAltPressed = true; } + else if (e.getID() == KeyEvent.KEY_RELEASED && e.getKeyCode() == KeyEvent.VK_ALT) { isAltPressed = false; } + return false; + } + }); } public void addDocument(GCDocument gcDocument) { diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java index 58f86266..e4362118 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java @@ -11,10 +11,7 @@ import javax.swing.event.ChangeListener; import javax.swing.event.SwingPropertyChangeSupport; import java.awt.*; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; +import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.text.DateFormat; @@ -62,6 +59,8 @@ public class ModelChartImpl extends JScrollPane implements ModelChart, ChangeLis private TimeOffsetPanel timeOffsetPanel; private int lastViewPortWidth = 0; + private boolean shiftPressed = false; + public ModelChartImpl() { super(); this.model = new GCModel(); @@ -185,6 +184,24 @@ private void maybePopup(MouseEvent e) { } }); + + addMouseWheelListener(new MouseWheelListener() { + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + if(GCViewerGui.isShiftPressed()) { + double pos = (double)(getHorizontalScrollBar().getValue())/chart.getWidth(); + if(e.getWheelRotation() > 0 && getScaleFactor() < 100) { + setScaleFactor((getScaleFactor()*1.2)); + } + if(e.getWheelRotation() < 0 && getScaleFactor() > 0.01) { + setScaleFactor((getScaleFactor()/1.2)); + } + getHorizontalScrollBar().setValue((int) (pos * chart.getWidth())); + e.consume(); + } + } + }); + } public void addTimeOffsetChangeListener(PropertyChangeListener listener) { From 78b45c1ec8644de83a636c1c0bcd4275c55e479d Mon Sep 17 00:00:00 2001 From: Matt Foulks Date: Wed, 2 Nov 2022 13:08:07 -0400 Subject: [PATCH 2/8] Added Matt Foulks to the list of contributers --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index 568c1727..a6410d74 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,10 @@ Ryan Gardner + + Matt Foulks + https://github.com/mfoulks3200 + Martin Geldmacher https://github.com/geld0r From 6d7a6f044b9a355ff4e518eca7b82c9eaffb1ad1 Mon Sep 17 00:00:00 2001 From: Matt Foulks Date: Thu, 3 Nov 2022 14:13:23 -0400 Subject: [PATCH 3/8] Removed unnessisary modifier tracking --- .../perf/gcviewer/view/GCViewerGui.java | 30 ------------------- .../perf/gcviewer/view/ModelChartImpl.java | 6 ++-- 2 files changed, 3 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/GCViewerGui.java b/src/main/java/com/tagtraum/perf/gcviewer/view/GCViewerGui.java index c5331af9..a4617b1e 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/GCViewerGui.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/GCViewerGui.java @@ -25,41 +25,11 @@ public class GCViewerGui extends JFrame { private GCViewerGuiToolBar toolBar; private GCPreferences preferences; - private static boolean isShiftPressed; - private static boolean isControlPressed; - private static boolean isAltPressed; - - public static boolean isShiftPressed() { - return isShiftPressed; - } - - public static boolean isControlPressed() { - return isControlPressed; - } - - public static boolean isAltPressed() { - return isAltPressed; - } private RecentGCResourcesMenu recentResourceNamesMenu; public GCViewerGui() { super("tagtraum industries incorporated - GCViewer"); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - - KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); - manager.addKeyEventDispatcher(new KeyEventDispatcher() { - @Override - public boolean dispatchKeyEvent(KeyEvent e) { - - if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_SHIFT) { isShiftPressed = true; } - else if (e.getID() == KeyEvent.KEY_RELEASED && e.getKeyCode() == KeyEvent.VK_SHIFT) { isShiftPressed = false; } - else if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_CONTROL) { isControlPressed = true; } - else if (e.getID() == KeyEvent.KEY_RELEASED && e.getKeyCode() == KeyEvent.VK_CONTROL) { isControlPressed = false; } - else if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ALT) { isAltPressed = true; } - else if (e.getID() == KeyEvent.KEY_RELEASED && e.getKeyCode() == KeyEvent.VK_ALT) { isAltPressed = false; } - return false; - } - }); } public void addDocument(GCDocument gcDocument) { diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java index e4362118..04b8aa36 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java @@ -188,15 +188,15 @@ private void maybePopup(MouseEvent e) { addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { - if(GCViewerGui.isShiftPressed()) { - double pos = (double)(getHorizontalScrollBar().getValue())/chart.getWidth(); + if((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) { + double pos = (double)(getHorizontalScrollBar().getValue())/(double)(chart.getWidth()); if(e.getWheelRotation() > 0 && getScaleFactor() < 100) { setScaleFactor((getScaleFactor()*1.2)); } if(e.getWheelRotation() < 0 && getScaleFactor() > 0.01) { setScaleFactor((getScaleFactor()/1.2)); } - getHorizontalScrollBar().setValue((int) (pos * chart.getWidth())); + getHorizontalScrollBar().setValue((int) (pos * (double)(chart.getWidth()))); e.consume(); } } From 78bd2c882aa5d2c1cf892489d8af6cbde7dc6a0c Mon Sep 17 00:00:00 2001 From: Matt Foulks Date: Fri, 4 Nov 2022 12:06:42 -0400 Subject: [PATCH 4/8] Removed unneeded field --- .../java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java index 04b8aa36..bd566afd 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java @@ -59,8 +59,6 @@ public class ModelChartImpl extends JScrollPane implements ModelChart, ChangeLis private TimeOffsetPanel timeOffsetPanel; private int lastViewPortWidth = 0; - private boolean shiftPressed = false; - public ModelChartImpl() { super(); this.model = new GCModel(); From f894f3f9fc11aac8e3a9e3ddd09a77565aec2d8c Mon Sep 17 00:00:00 2001 From: Matt Foulks Date: Fri, 4 Nov 2022 12:09:36 -0400 Subject: [PATCH 5/8] Fixed issue where magic mouse could fire a scrollbar event erroneously --- .../com/tagtraum/perf/gcviewer/view/ModelChartImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java index bd566afd..539ad28a 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java @@ -194,8 +194,10 @@ public void mouseWheelMoved(MouseWheelEvent e) { if(e.getWheelRotation() < 0 && getScaleFactor() > 0.01) { setScaleFactor((getScaleFactor()/1.2)); } - getHorizontalScrollBar().setValue((int) (pos * (double)(chart.getWidth()))); - e.consume(); + if(e.getWheelRotation() != 0) { + getHorizontalScrollBar().setValue((int) (pos * (double) (chart.getWidth()))); + e.consume(); + } } } }); From bb2ad3f2ba5463f6167dc8dc6811081f1f205211 Mon Sep 17 00:00:00 2001 From: Matt Foulks Date: Fri, 4 Nov 2022 12:15:05 -0400 Subject: [PATCH 6/8] Style adjustments --- .../tagtraum/perf/gcviewer/view/ModelChartImpl.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java index 539ad28a..095caa04 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java @@ -186,16 +186,16 @@ private void maybePopup(MouseEvent e) { addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { - if((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) { - double pos = (double)(getHorizontalScrollBar().getValue())/(double)(chart.getWidth()); - if(e.getWheelRotation() > 0 && getScaleFactor() < 100) { + if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) { + double pos = (double)(getHorizontalScrollBar().getValue()) / (double)(chart.getWidth()); + if (e.getWheelRotation() > 0 && getScaleFactor() < 100) { setScaleFactor((getScaleFactor()*1.2)); } - if(e.getWheelRotation() < 0 && getScaleFactor() > 0.01) { + if (e.getWheelRotation() < 0 && getScaleFactor() > 0.01) { setScaleFactor((getScaleFactor()/1.2)); } - if(e.getWheelRotation() != 0) { - getHorizontalScrollBar().setValue((int) (pos * (double) (chart.getWidth()))); + if (e.getWheelRotation() != 0) { + getHorizontalScrollBar().setValue((int)(pos * (double)(chart.getWidth()))); e.consume(); } } From cc0c926581da79018f48bfed722c7cd0ea9495f3 Mon Sep 17 00:00:00 2001 From: Atlas Date: Tue, 20 Dec 2022 17:54:56 -0500 Subject: [PATCH 7/8] Modified the use CTRL and Meta --- .../java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java index 095caa04..72a9d845 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java @@ -186,7 +186,7 @@ private void maybePopup(MouseEvent e) { addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { - if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) { + if ((e.getModifiersEx() & InputEvent.META_DOWN_MASK) != 0||(e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) { double pos = (double)(getHorizontalScrollBar().getValue()) / (double)(chart.getWidth()); if (e.getWheelRotation() > 0 && getScaleFactor() < 100) { setScaleFactor((getScaleFactor()*1.2)); From eca41923e11fdecd055abff7cdf875783c60e91d Mon Sep 17 00:00:00 2001 From: Atlas Date: Mon, 26 Dec 2022 12:14:56 -0500 Subject: [PATCH 8/8] Modified the use CTRL and Meta --- .../java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java index 72a9d845..b7675ad6 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java @@ -186,7 +186,7 @@ private void maybePopup(MouseEvent e) { addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { - if ((e.getModifiersEx() & InputEvent.META_DOWN_MASK) != 0||(e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) { + if (((e.getModifiersEx() & InputEvent.META_DOWN_MASK) != 0 && System.getProperty("os.name").contains("Mac OS X"))||(e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0 && !System.getProperty("os.name").contains("Mac OS X")) { double pos = (double)(getHorizontalScrollBar().getValue()) / (double)(chart.getWidth()); if (e.getWheelRotation() > 0 && getScaleFactor() < 100) { setScaleFactor((getScaleFactor()*1.2));