[refactor] Changed Dimension to Point display Figures
This commit is contained in:
parent
6e2ab642e5
commit
f0269b5d91
@ -4,6 +4,7 @@ import java.awt.Color;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.Point;
|
||||||
import java.util.EventListener;
|
import java.util.EventListener;
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -40,7 +41,7 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
|
|
||||||
protected static final Dimension borderThickness_px = new Dimension(DEFAULT_BORDER_PIXELS_WIDTH, DEFAULT_BORDER_PIXELS_HEIGHT);
|
protected static final Dimension borderThickness_px = new Dimension(DEFAULT_BORDER_PIXELS_WIDTH, DEFAULT_BORDER_PIXELS_HEIGHT);
|
||||||
// pixel offset from the the subject's origin to the canvas's upper-left-corner.
|
// pixel offset from the the subject's origin to the canvas's upper-left-corner.
|
||||||
protected Dimension originLocation_px = new Dimension(0,0);
|
protected Point originLocation_px = new Point(0,0);
|
||||||
|
|
||||||
// size of the visible region
|
// size of the visible region
|
||||||
protected Dimension visibleBounds_px = new Dimension(0,0);
|
protected Dimension visibleBounds_px = new Dimension(0,0);
|
||||||
@ -81,7 +82,7 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dimension getSubjectOrigin() {
|
public Point getSubjectOrigin() {
|
||||||
return originLocation_px;
|
return originLocation_px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +163,7 @@ public abstract class AbstractScaleFigure extends JPanel {
|
|||||||
// Calculate and store the transformation used
|
// Calculate and store the transformation used
|
||||||
// (inverse is used in detecting clicks on objects)
|
// (inverse is used in detecting clicks on objects)
|
||||||
projection = new AffineTransform();
|
projection = new AffineTransform();
|
||||||
projection.translate(this.originLocation_px.width, originLocation_px.height);
|
projection.translate(this.originLocation_px.x, originLocation_px.y);
|
||||||
// Mirror position Y-axis upwards
|
// Mirror position Y-axis upwards
|
||||||
projection.scale(scale, -scale);
|
projection.scale(scale, -scale);
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@ package net.sf.openrocket.gui.scalefigure;
|
|||||||
|
|
||||||
import java.awt.BasicStroke;
|
import java.awt.BasicStroke;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.geom.Line2D;
|
import java.awt.geom.Line2D;
|
||||||
@ -347,12 +347,12 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dimension getSubjectOrigin() {
|
public Point getSubjectOrigin() {
|
||||||
if (modID != finset.getRocket().getAerodynamicModID()) {
|
if (modID != finset.getRocket().getAerodynamicModID()) {
|
||||||
modID = finset.getRocket().getAerodynamicModID();
|
modID = finset.getRocket().getAerodynamicModID();
|
||||||
updateTransform();
|
updateTransform();
|
||||||
}
|
}
|
||||||
return new Dimension(originLocation_px.width, originLocation_px.height);
|
return new Point(originLocation_px.x, originLocation_px.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -383,12 +383,12 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
final int finFrontPx = (int)(subjectBounds_m.getX()*scale);
|
final int finFrontPx = (int)(subjectBounds_m.getX()*scale);
|
||||||
final int subjectHeight = (int)(subjectBounds_m.getHeight()*scale);
|
final int subjectHeight = (int)(subjectBounds_m.getHeight()*scale);
|
||||||
|
|
||||||
originLocation_px.width = borderThickness_px.width - finFrontPx;
|
originLocation_px.x = borderThickness_px.width - finFrontPx;
|
||||||
|
|
||||||
if( visibleBounds_px.height > (subjectHeight+ 2*borderThickness_px.height)) {
|
if( visibleBounds_px.height > (subjectHeight+ 2*borderThickness_px.height)) {
|
||||||
originLocation_px.height = getHeight() - mountHeight - borderThickness_px.height;
|
originLocation_px.y = getHeight() - mountHeight - borderThickness_px.height;
|
||||||
}else {
|
}else {
|
||||||
originLocation_px.height = borderThickness_px.height + finHeight;
|
originLocation_px.y = borderThickness_px.height + finHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,7 @@
|
|||||||
package net.sf.openrocket.gui.scalefigure;
|
package net.sf.openrocket.gui.scalefigure;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.BasicStroke;
|
import java.awt.*;
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Rectangle;
|
|
||||||
import java.awt.RenderingHints;
|
|
||||||
import java.awt.Shape;
|
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.geom.Ellipse2D;
|
import java.awt.geom.Ellipse2D;
|
||||||
import java.awt.geom.NoninvertibleTransformException;
|
import java.awt.geom.NoninvertibleTransformException;
|
||||||
@ -361,7 +354,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
* Gets the shapes required to draw the component.
|
* Gets the shapes required to draw the component.
|
||||||
*
|
*
|
||||||
* @param component
|
* @param component
|
||||||
* @param params
|
*
|
||||||
* @return the <code>ArrayList</code> containing all the shapes to draw.
|
* @return the <code>ArrayList</code> containing all the shapes to draw.
|
||||||
*/
|
*/
|
||||||
private static ArrayList<RocketComponentShape> addThisShape(
|
private static ArrayList<RocketComponentShape> addThisShape(
|
||||||
@ -425,6 +418,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
final double maxR = Math.max(Math.hypot(newBounds.min.y, newBounds.min.z),
|
final double maxR = Math.max(Math.hypot(newBounds.min.y, newBounds.min.z),
|
||||||
Math.hypot(newBounds.max.y, newBounds.max.z));
|
Math.hypot(newBounds.max.y, newBounds.max.z));
|
||||||
|
|
||||||
|
|
||||||
switch (currentViewType) {
|
switch (currentViewType) {
|
||||||
case SideView:
|
case SideView:
|
||||||
subjectBounds_m = new Rectangle2D.Double(newBounds.min.x, -maxR, newBounds.span().x, 2 * maxR);
|
subjectBounds_m = new Rectangle2D.Double(newBounds.min.x, -maxR, newBounds.span().x, 2 * maxR);
|
||||||
@ -451,12 +445,11 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
final int newOriginX = borderThickness_px.width + Math.max(getWidth(), subjectWidth + 2*borderThickness_px.width)/ 2;
|
final int newOriginX = borderThickness_px.width + Math.max(getWidth(), subjectWidth + 2*borderThickness_px.width)/ 2;
|
||||||
final int newOriginY = borderThickness_px.height + getHeight() / 2;
|
final int newOriginY = borderThickness_px.height + getHeight() / 2;
|
||||||
|
|
||||||
originLocation_px = new Dimension(newOriginX, newOriginY);
|
originLocation_px = new Point(newOriginX, newOriginY);
|
||||||
}else if (currentViewType == RocketPanel.VIEW_TYPE.SideView){
|
}else if (currentViewType == RocketPanel.VIEW_TYPE.SideView){
|
||||||
final int newOriginX = borderThickness_px.width - subjectFront;
|
final int newOriginX = borderThickness_px.width - subjectFront;
|
||||||
final int newOriginY = Math.max(getHeight(), subjectHeight + 2*borderThickness_px.height )/ 2;
|
final int newOriginY = Math.max(getHeight(), subjectHeight + 2*borderThickness_px.height )/ 2;
|
||||||
|
originLocation_px = new Point(newOriginX, newOriginY);
|
||||||
originLocation_px = new Dimension(newOriginX, newOriginY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import java.awt.Dimension;
|
|||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
@ -34,7 +35,7 @@ import net.sf.openrocket.util.StateChangeListener;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A scroll pane that holds a {@link ScaleFigure} and includes rulers that show
|
* A scroll pane that holds a {@link AbstractScaleFigure} and includes rulers that show
|
||||||
* natural units. The figure can be moved by dragging on the figure.
|
* natural units. The figure can be moved by dragging on the figure.
|
||||||
* <p>
|
* <p>
|
||||||
* This class implements both <code>MouseListener</code> and
|
* This class implements both <code>MouseListener</code> and
|
||||||
@ -68,7 +69,6 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
* Create a scale scroll pane.
|
* Create a scale scroll pane.
|
||||||
*
|
*
|
||||||
* @param component the component to contain (must implement ScaleFigure)
|
* @param component the component to contain (must implement ScaleFigure)
|
||||||
* @param allowFit whether automatic fitting of the figure is allowed
|
|
||||||
*/
|
*/
|
||||||
public ScaleScrollPane(final JComponent component) {
|
public ScaleScrollPane(final JComponent component) {
|
||||||
super(component);
|
super(component);
|
||||||
@ -151,8 +151,8 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
|
|
||||||
Dimension view = viewport.getExtentSize();
|
Dimension view = viewport.getExtentSize();
|
||||||
figure.scaleTo(view);
|
figure.scaleTo(view);
|
||||||
this.firePropertyChange( USER_SCALE_PROPERTY, 1.0, figure.getUserScale());
|
|
||||||
|
|
||||||
|
this.firePropertyChange( USER_SCALE_PROPERTY, 1.0, figure.getUserScale());
|
||||||
revalidate();
|
revalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -286,23 +286,23 @@ public class ScaleScrollPane extends JScrollPane
|
|||||||
}
|
}
|
||||||
|
|
||||||
private double fromPx(final int px) {
|
private double fromPx(final int px) {
|
||||||
Dimension origin = figure.getSubjectOrigin();
|
final Point origin = figure.getSubjectOrigin();
|
||||||
double realValue = Double.NaN;
|
double realValue = Double.NaN;
|
||||||
if (orientation == HORIZONTAL) {
|
if (orientation == HORIZONTAL) {
|
||||||
realValue = px - origin.width;
|
realValue = px - origin.x;
|
||||||
} else {
|
} else {
|
||||||
realValue = origin.height - px;
|
realValue = origin.y - px;
|
||||||
}
|
}
|
||||||
return realValue / figure.getAbsoluteScale();
|
return realValue / figure.getAbsoluteScale();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int toPx(final double value) {
|
private int toPx(final double value) {
|
||||||
final Dimension origin = figure.getSubjectOrigin();
|
final Point origin = figure.getSubjectOrigin();
|
||||||
final int px = (int) (value * figure.getAbsoluteScale() + 0.5);
|
final int px = (int) (value * figure.getAbsoluteScale() + 0.5);
|
||||||
if (orientation == HORIZONTAL) {
|
if (orientation == HORIZONTAL) {
|
||||||
return (px + origin.width);
|
return (px + origin.x);
|
||||||
} else {
|
} else {
|
||||||
return (origin.height - px);
|
return (origin.y - px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user