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

Add ability to zoom via scroll wheel #263

Merged
merged 8 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<developer>
<name>Ryan Gardner</name>
</developer>
<developer>
<name>Matt Foulks</name>
<url>https://github.com/mfoulks3200</url>
</developer>
<developer>
<name>Martin Geldmacher</name>
<url>https://github.com/geld0r</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class AboutDialog extends ScreenCenteredDialog implements ActionListener
"Cka3o4Huk",
"Frank Dietrich",
"Bernd Eckenfels",
"Matt Foulks",
"Ryan Gardner",
"Martin Geldmacher",
"Neil Gentleman",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/com/tagtraum/perf/gcviewer/view/GCViewerGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }
mfoulks3200 marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
});
}

public void addDocument(GCDocument gcDocument) {
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/com/tagtraum/perf/gcviewer/view/ModelChartImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,6 +59,8 @@ public class ModelChartImpl extends JScrollPane implements ModelChart, ChangeLis
private TimeOffsetPanel timeOffsetPanel;
private int lastViewPortWidth = 0;

private boolean shiftPressed = false;
mfoulks3200 marked this conversation as resolved.
Show resolved Hide resolved

public ModelChartImpl() {
super();
this.model = new GCModel();
Expand Down Expand Up @@ -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));
}
mfoulks3200 marked this conversation as resolved.
Show resolved Hide resolved
getHorizontalScrollBar().setValue((int) (pos * chart.getWidth()));
e.consume();
}
}
});

}

public void addTimeOffsetChangeListener(PropertyChangeListener listener) {
Expand Down