Don't revalidate/repaint component in Ruler.updateSize()
Analysis from Justin Hanney indicates that the CPU is constantly processing paint events in the ScaleScrollPane.Ruler. Change the updateSize method to not revalidate and repaint since the paintComponent method also invokes the updateSize to ensure it is drawing components of the right size. This change also refactors the ChangeListener implementation to have the RulerClass implement the method instead of using an anonymous class for event handling when ruler units change. Additionally, this change adds a revalidate call to the scrollPane to fix an issue where the ruler is not repainted when switching views from 3D to 2D. Fixes #615 Signed-off-by: Billy Olsen <billy.olsen@gmail.com>
This commit is contained in:
parent
faf770450c
commit
adf3101315
@ -260,6 +260,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
|||||||
figureHolder.add(scrollPane, BorderLayout.CENTER);
|
figureHolder.add(scrollPane, BorderLayout.CENTER);
|
||||||
rotationSlider.setEnabled(true);
|
rotationSlider.setEnabled(true);
|
||||||
scaleSelector.setEnabled(true);
|
scaleSelector.setEnabled(true);
|
||||||
|
scrollPane.revalidate();
|
||||||
revalidate();
|
revalidate();
|
||||||
figureHolder.revalidate();
|
figureHolder.revalidate();
|
||||||
figure.repaint();
|
figure.repaint();
|
||||||
|
@ -258,7 +258,7 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
//////////////// The view port rulers ////////////////
|
//////////////// The view port rulers ////////////////
|
||||||
|
|
||||||
|
|
||||||
private class Ruler extends JComponent {
|
private class Ruler extends JComponent implements ChangeListener {
|
||||||
public static final int HORIZONTAL = 0;
|
public static final int HORIZONTAL = 0;
|
||||||
public static final int VERTICAL = 1;
|
public static final int VERTICAL = 1;
|
||||||
|
|
||||||
@ -266,26 +266,23 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
|
|
||||||
public Ruler(int orientation) {
|
public Ruler(int orientation) {
|
||||||
this.orientation = orientation;
|
this.orientation = orientation;
|
||||||
|
rulerUnit.addChangeListener(this);
|
||||||
rulerUnit.addChangeListener(new ChangeListener() {
|
}
|
||||||
@Override
|
|
||||||
public void stateChanged(ChangeEvent e) {
|
@Override
|
||||||
updateSize();
|
public void stateChanged(ChangeEvent e) {
|
||||||
Ruler.this.repaint();
|
updateSize();
|
||||||
}
|
repaint();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSize() {
|
private void updateSize() {
|
||||||
if (orientation == HORIZONTAL) {
|
if (orientation == HORIZONTAL) {
|
||||||
Ruler.this.setMinimumSize(new Dimension(component.getWidth() + 10, RULER_SIZE));
|
setMinimumSize(new Dimension(component.getWidth() + 10, RULER_SIZE));
|
||||||
Ruler.this.setPreferredSize(new Dimension(component.getWidth() + 10, RULER_SIZE));
|
setPreferredSize(new Dimension(component.getWidth() + 10, RULER_SIZE));
|
||||||
} else {
|
} else {
|
||||||
Ruler.this.setMinimumSize(new Dimension(RULER_SIZE, component.getHeight() + 10));
|
setMinimumSize(new Dimension(RULER_SIZE, component.getHeight() + 10));
|
||||||
Ruler.this.setPreferredSize(new Dimension(RULER_SIZE, component.getHeight() + 10));
|
setPreferredSize(new Dimension(RULER_SIZE, component.getHeight() + 10));
|
||||||
}
|
}
|
||||||
revalidate();
|
|
||||||
repaint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private double fromPx(final int px) {
|
private double fromPx(final int px) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user