mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-29 16:01:19 -04:00
more convenient behaviour at zooming in the DataSetDialog
This commit is contained in:
parent
054c3e9764
commit
a947b2139d
@ -13,6 +13,7 @@ import java.awt.*;
|
|||||||
*/
|
*/
|
||||||
public class DataSetComponent extends JComponent {
|
public class DataSetComponent extends JComponent {
|
||||||
private final DataSet dataSet;
|
private final DataSet dataSet;
|
||||||
|
private JScrollPane scrollPane;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new dataSet
|
* Creates a new dataSet
|
||||||
@ -23,7 +24,7 @@ public class DataSetComponent extends JComponent {
|
|||||||
this.dataSet = dataSet;
|
this.dataSet = dataSet;
|
||||||
addMouseWheelListener(e -> {
|
addMouseWheelListener(e -> {
|
||||||
double f = Math.pow(0.9, e.getWheelRotation());
|
double f = Math.pow(0.9, e.getWheelRotation());
|
||||||
scale(f); // ToDo keep relative mouse position
|
scale(f, e.getX());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,12 +47,17 @@ public class DataSetComponent extends JComponent {
|
|||||||
/**
|
/**
|
||||||
* Apply a scaling factor
|
* Apply a scaling factor
|
||||||
*
|
*
|
||||||
* @param f the factor
|
* @param f the factor
|
||||||
|
* @param xPos fixed position
|
||||||
*/
|
*/
|
||||||
public void scale(double f) {
|
public void scale(double f, int xPos) {
|
||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
dataSet.scale(f);
|
dataSet.scale(f);
|
||||||
|
|
||||||
|
int x = (int) (xPos * f) - (xPos - (int) scrollPane.getViewport().getViewRect().getX());
|
||||||
|
if (x < 0) x = 0;
|
||||||
|
scrollPane.getViewport().setViewPosition(new Point(x, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,4 +70,13 @@ public class DataSetComponent extends JComponent {
|
|||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the used scroll pane
|
||||||
|
*
|
||||||
|
* @param scrollPane the scroll pane witch contains this component
|
||||||
|
*/
|
||||||
|
public void setScrollPane(JScrollPane scrollPane) {
|
||||||
|
this.scrollPane = scrollPane;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,7 @@ public class DataSetDialog extends JDialog implements ModelStateObserver {
|
|||||||
dsc = new DataSetComponent(dataSet);
|
dsc = new DataSetComponent(dataSet);
|
||||||
scrollPane = new JScrollPane(dsc);
|
scrollPane = new JScrollPane(dsc);
|
||||||
getContentPane().add(scrollPane);
|
getContentPane().add(scrollPane);
|
||||||
|
dsc.setScrollPane(scrollPane);
|
||||||
|
|
||||||
JToolBar toolBar = new JToolBar();
|
JToolBar toolBar = new JToolBar();
|
||||||
ToolTipAction maximize = new ToolTipAction(Lang.get("menu_maximize"), ICON_EXPAND) {
|
ToolTipAction maximize = new ToolTipAction(Lang.get("menu_maximize"), ICON_EXPAND) {
|
||||||
@ -79,13 +80,15 @@ public class DataSetDialog extends JDialog implements ModelStateObserver {
|
|||||||
ToolTipAction zoomIn = new ToolTipAction(Lang.get("menu_zoomIn"), ICON_ZOOM_IN) {
|
ToolTipAction zoomIn = new ToolTipAction(Lang.get("menu_zoomIn"), ICON_ZOOM_IN) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
dsc.scale(1.25f);
|
Rectangle r = scrollPane.getViewport().getViewRect();
|
||||||
|
dsc.scale(1.25f, r.x + r.width / 2);
|
||||||
}
|
}
|
||||||
}.setAccelerator("control PLUS");
|
}.setAccelerator("control PLUS");
|
||||||
ToolTipAction zoomOut = new ToolTipAction(Lang.get("menu_zoomOut"), ICON_ZOOM_OUT) {
|
ToolTipAction zoomOut = new ToolTipAction(Lang.get("menu_zoomOut"), ICON_ZOOM_OUT) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
dsc.scale(0.8f);
|
Rectangle r = scrollPane.getViewport().getViewRect();
|
||||||
|
dsc.scale(0.8f, r.x + r.width / 2);
|
||||||
}
|
}
|
||||||
}.setAccelerator("control MINUS");
|
}.setAccelerator("control MINUS");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user