[fixes #425] FinPointFigure ScrollBars now adjust with zoom in/out

This commit is contained in:
Daniel_M_Williams 2018-07-07 15:26:49 -04:00
parent c3918ad2d4
commit 80c0fa8568

View File

@ -265,23 +265,23 @@ public class ScaleScrollPane extends JScrollPane
public Ruler(int orientation) { public Ruler(int orientation) {
this.orientation = orientation; this.orientation = orientation;
updateSize();
rulerUnit.addChangeListener(new ChangeListener() { rulerUnit.addChangeListener(new ChangeListener() {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
updateSize();
Ruler.this.repaint(); Ruler.this.repaint();
} }
}); });
} }
private void updateSize() {
public void updateSize() {
Dimension d = component.getPreferredSize();
if (orientation == HORIZONTAL) { if (orientation == HORIZONTAL) {
setPreferredSize(new Dimension(d.width + 10, RULER_SIZE)); Ruler.this.setMinimumSize(new Dimension(component.getWidth() + 10, RULER_SIZE));
Ruler.this.setPreferredSize(new Dimension(component.getWidth() + 10, RULER_SIZE));
} else { } else {
setPreferredSize(new Dimension(RULER_SIZE, d.height + 10)); Ruler.this.setMinimumSize(new Dimension(RULER_SIZE, component.getHeight() + 10));
Ruler.this.setPreferredSize(new Dimension(RULER_SIZE, component.getHeight() + 10));
} }
revalidate(); revalidate();
repaint(); repaint();
@ -314,7 +314,12 @@ public class ScaleScrollPane extends JScrollPane
super.paintComponent(g); super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g; Graphics2D g2 = (Graphics2D) g;
Rectangle area = g2.getClipBounds(); updateSize();
// this function doesn't reliably update all the time, so we'll draw everything for the entire canvas,
// and let the JVM drawing algorithms figure out what should be drawn.
//
Rectangle area = ScaleScrollPane.this.getViewport().getViewRect();
// Fill area with background color // Fill area with background color
g2.setColor(getBackground()); g2.setColor(getBackground());
@ -329,14 +334,13 @@ public class ScaleScrollPane extends JScrollPane
endpx = area.y + area.height; endpx = area.y + area.height;
} }
final double start = fromPx(startpx);
final double end = fromPx(endpx);
final double minor = MINOR_TICKS / figure.getAbsoluteScale();
final double major = MAJOR_TICKS / figure.getAbsoluteScale();
Unit unit = rulerUnit.getCurrentUnit(); Unit unit = rulerUnit.getCurrentUnit();
double start, end, minor, major;
start = fromPx(startpx);
end = fromPx(endpx);
minor = MINOR_TICKS / figure.getAbsoluteScale();
major = MAJOR_TICKS / figure.getAbsoluteScale();
Tick[] ticks = null; Tick[] ticks = null;
if( VERTICAL == orientation ){ if( VERTICAL == orientation ){
// the parameters are *intended* to be backwards: because 'getTicks(...)' can only // the parameters are *intended* to be backwards: because 'getTicks(...)' can only