From 80c0fa85680712e970d60d226d179c69564088bf Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sat, 7 Jul 2018 15:26:49 -0400 Subject: [PATCH] [fixes #425] FinPointFigure ScrollBars now adjust with zoom in/out --- .../gui/scalefigure/ScaleScrollPane.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/ScaleScrollPane.java b/swing/src/net/sf/openrocket/gui/scalefigure/ScaleScrollPane.java index bc973938d..7856083e6 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/ScaleScrollPane.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/ScaleScrollPane.java @@ -265,23 +265,23 @@ public class ScaleScrollPane extends JScrollPane public Ruler(int orientation) { this.orientation = orientation; - updateSize(); rulerUnit.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { + updateSize(); Ruler.this.repaint(); } }); } - - public void updateSize() { - Dimension d = component.getPreferredSize(); + private void updateSize() { 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 { - 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(); repaint(); @@ -314,8 +314,13 @@ public class ScaleScrollPane extends JScrollPane super.paintComponent(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 g2.setColor(getBackground()); g2.fillRect(area.x, area.y, area.width, area.height + 100); @@ -329,14 +334,13 @@ public class ScaleScrollPane extends JScrollPane endpx = area.y + area.height; } - Unit unit = rulerUnit.getCurrentUnit(); - double start, end, minor, major; - start = fromPx(startpx); - end = fromPx(endpx); + final double start = fromPx(startpx); + final double end = fromPx(endpx); - minor = MINOR_TICKS / figure.getAbsoluteScale(); - major = MAJOR_TICKS / figure.getAbsoluteScale(); + final double minor = MINOR_TICKS / figure.getAbsoluteScale(); + final double major = MAJOR_TICKS / figure.getAbsoluteScale(); + Unit unit = rulerUnit.getCurrentUnit(); Tick[] ticks = null; if( VERTICAL == orientation ){ // the parameters are *intended* to be backwards: because 'getTicks(...)' can only