Skip to content

Commit

Permalink
Add ability to zoom via scroll wheel (#263)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Foulks <[email protected]>
  • Loading branch information
mfoulks3200 and mfoulksATL authored Mar 1, 2023
1 parent eb2676f commit 561d379
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
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
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 @@ -27,7 +29,6 @@ public class GCViewerGui extends JFrame {

public GCViewerGui() {
super("tagtraum industries incorporated - GCViewer");

setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
}

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 @@ -185,6 +182,26 @@ private void maybePopup(MouseEvent e) {
}
});


addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
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));
}
if (e.getWheelRotation() < 0 && getScaleFactor() > 0.01) {
setScaleFactor((getScaleFactor()/1.2));
}
if (e.getWheelRotation() != 0) {
getHorizontalScrollBar().setValue((int)(pos * (double)(chart.getWidth())));
e.consume();
}
}
}
});

}

public void addTimeOffsetChangeListener(PropertyChangeListener listener) {
Expand Down

0 comments on commit 561d379

Please sign in to comment.