[feature][Resolves #426] implemented FinPoint SelectedIndex Indicators
- figure and table update each other
This commit is contained in:
parent
bea26fc511
commit
4a91ecd63a
@ -3,6 +3,7 @@ package net.sf.openrocket.gui.configdialog;
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
@ -71,6 +72,8 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
|||||||
private JTable table = null;
|
private JTable table = null;
|
||||||
private FinPointTableModel tableModel = null;
|
private FinPointTableModel tableModel = null;
|
||||||
|
|
||||||
|
private int dragIndex = -1;
|
||||||
|
|
||||||
private FinPointFigure figure = null;
|
private FinPointFigure figure = null;
|
||||||
|
|
||||||
|
|
||||||
@ -214,6 +217,14 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
|||||||
for (int i = 0; i < Columns.values().length; i++) {
|
for (int i = 0; i < Columns.values().length; i++) {
|
||||||
table.getColumnModel().getColumn(i).setPreferredWidth(Columns.values()[i].getWidth());
|
table.getColumnModel().getColumn(i).setPreferredWidth(Columns.values()[i].getWidth());
|
||||||
}
|
}
|
||||||
|
table.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent ev) {
|
||||||
|
figure.setSelectedIndex(table.getSelectedRow());
|
||||||
|
figure.updateFigure();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
JScrollPane tablePane = new JScrollPane(table);
|
JScrollPane tablePane = new JScrollPane(table);
|
||||||
|
|
||||||
JButton scaleButton = new JButton(trans.get("FreeformFinSetConfig.lbl.scaleFin"));
|
JButton scaleButton = new JButton(trans.get("FreeformFinSetConfig.lbl.scaleFin"));
|
||||||
@ -341,7 +352,6 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
|||||||
document.stopUndo();
|
document.stopUndo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -351,8 +361,21 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
|||||||
|
|
||||||
if (tableModel != null) {
|
if (tableModel != null) {
|
||||||
tableModel.fireTableDataChanged();
|
tableModel.fireTableDataChanged();
|
||||||
|
|
||||||
|
// make sure to do this *after* the table data is updated.
|
||||||
|
if( 0 <= this.dragIndex ) {
|
||||||
|
table.setRowSelectionInterval(dragIndex, dragIndex);
|
||||||
|
}else {
|
||||||
|
table.clearSelection();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (figure != null) {
|
if (figure != null) {
|
||||||
|
if( 0 <= this.dragIndex ) {
|
||||||
|
figure.setSelectedIndex(dragIndex);
|
||||||
|
}else{
|
||||||
|
figure.resetSelectedIndex();
|
||||||
|
}
|
||||||
figure.updateFigure();
|
figure.updateFigure();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,13 +383,11 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private class FinPointScrollPane extends ScaleScrollPane {
|
private class FinPointScrollPane extends ScaleScrollPane {
|
||||||
|
|
||||||
private static final int ANY_MASK = (MouseEvent.ALT_DOWN_MASK | MouseEvent.ALT_GRAPH_DOWN_MASK | MouseEvent.META_DOWN_MASK | MouseEvent.CTRL_DOWN_MASK | MouseEvent.SHIFT_DOWN_MASK);
|
private static final int ANY_MASK = (MouseEvent.ALT_DOWN_MASK | MouseEvent.ALT_GRAPH_DOWN_MASK | MouseEvent.META_DOWN_MASK | MouseEvent.CTRL_DOWN_MASK | MouseEvent.SHIFT_DOWN_MASK);
|
||||||
|
|
||||||
private int dragIndex = -1;
|
|
||||||
|
|
||||||
private FinPointScrollPane( final FinPointFigure _figure) {
|
private FinPointScrollPane( final FinPointFigure _figure) {
|
||||||
super( _figure);
|
super( _figure);
|
||||||
@ -381,30 +402,30 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int pointIndex = getPoint(event);
|
final int pressIndex = getPoint(event);
|
||||||
|
if ( pressIndex >= 0) {
|
||||||
if ( pointIndex >= 0) {
|
dragIndex = pressIndex;
|
||||||
dragIndex = pointIndex;
|
updateFields();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int segmentIndex = getSegment(event);
|
final int segmentIndex = getSegment(event);
|
||||||
System.err.println(String.format(".... finpoint//segmentIndex: %d", segmentIndex));
|
|
||||||
if (segmentIndex >= 0) {
|
if (segmentIndex >= 0) {
|
||||||
Point2D.Double point = getCoordinates(event);
|
Point2D.Double point = getCoordinates(event);
|
||||||
finset.addPoint(segmentIndex );
|
finset.addPoint(segmentIndex );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
finset.setPoint(dragIndex, point.x, point.y);
|
finset.setPoint(dragIndex, point.x, point.y);
|
||||||
|
dragIndex = segmentIndex;
|
||||||
|
updateFields();
|
||||||
|
return;
|
||||||
} catch (IllegalFinPointException ignore) {
|
} catch (IllegalFinPointException ignore) {
|
||||||
// no-op
|
// no-op
|
||||||
} catch (ArrayIndexOutOfBoundsException ex) {
|
} catch (ArrayIndexOutOfBoundsException ex) {
|
||||||
log.error("bad index while editing fin points!!", ex);
|
log.error("bad index while editing fin points!!", ex);
|
||||||
}
|
}
|
||||||
dragIndex = segmentIndex;
|
|
||||||
|
|
||||||
updateFields();
|
updateFields();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +436,7 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
|||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent event) {
|
public void mouseDragged(MouseEvent event) {
|
||||||
int mods = event.getModifiersEx();
|
int mods = event.getModifiersEx();
|
||||||
if (dragIndex < 0 || (mods & (ANY_MASK | MouseEvent.BUTTON1_DOWN_MASK)) != MouseEvent.BUTTON1_DOWN_MASK) {
|
if (dragIndex <= 0 || (mods & (ANY_MASK | MouseEvent.BUTTON1_DOWN_MASK)) != MouseEvent.BUTTON1_DOWN_MASK) {
|
||||||
super.mouseDragged(event);
|
super.mouseDragged(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import java.awt.Graphics;
|
|||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.geom.AffineTransform;
|
|
||||||
import java.awt.geom.Line2D;
|
import java.awt.geom.Line2D;
|
||||||
import java.awt.geom.NoninvertibleTransformException;
|
import java.awt.geom.NoninvertibleTransformException;
|
||||||
import java.awt.geom.Path2D;
|
import java.awt.geom.Path2D;
|
||||||
@ -43,6 +42,7 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
|
|
||||||
// the size of the boxes around each fin point vertex
|
// the size of the boxes around each fin point vertex
|
||||||
private static final float BOX_WIDTH_PIXELS = 12;
|
private static final float BOX_WIDTH_PIXELS = 12;
|
||||||
|
private static final float SELECTED_BOX_WIDTH_PIXELS = 16;
|
||||||
|
|
||||||
private static final double MINOR_TICKS = 0.05;
|
private static final double MINOR_TICKS = 0.05;
|
||||||
private static final double MAJOR_TICKS = 0.1;
|
private static final double MAJOR_TICKS = 0.1;
|
||||||
@ -56,7 +56,7 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
protected final List<StateChangeListener> listeners = new LinkedList<StateChangeListener>();
|
protected final List<StateChangeListener> listeners = new LinkedList<StateChangeListener>();
|
||||||
|
|
||||||
private Rectangle2D.Double[] finPointHandles = null;
|
private Rectangle2D.Double[] finPointHandles = null;
|
||||||
|
private int selectedIndex = -1;
|
||||||
|
|
||||||
public FinPointFigure(FreeformFinSet finset) {
|
public FinPointFigure(FreeformFinSet finset) {
|
||||||
this.finset = finset;
|
this.finset = finset;
|
||||||
@ -229,19 +229,30 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
|
|
||||||
// Fin point boxes
|
// Fin point boxes
|
||||||
final float boxWidth = (float) (BOX_WIDTH_PIXELS / scale );
|
final float boxWidth = (float) (BOX_WIDTH_PIXELS / scale );
|
||||||
|
final float boxHalfWidth = boxWidth/2;
|
||||||
|
final float selBoxWidth = (float) (SELECTED_BOX_WIDTH_PIXELS / scale );
|
||||||
|
final float selBoxHalfWidth = boxWidth/2;
|
||||||
|
|
||||||
final float boxEdgeWidth_m = (float) ( LINE_WIDTH_PIXELS / scale );
|
final float boxEdgeWidth_m = (float) ( LINE_WIDTH_PIXELS / scale );
|
||||||
g2.setStroke(new BasicStroke( boxEdgeWidth_m, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
g2.setStroke(new BasicStroke( boxEdgeWidth_m, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
||||||
g2.setColor(new Color(150, 0, 0));
|
g2.setColor(new Color(150, 0, 0));
|
||||||
final double boxHalfWidth = boxWidth/2;
|
|
||||||
finPointHandles = new Rectangle2D.Double[ drawPoints.length];
|
finPointHandles = new Rectangle2D.Double[ drawPoints.length];
|
||||||
for (int i = 0; i < drawPoints.length; i++) {
|
for (int currentIndex = 0; currentIndex < drawPoints.length; currentIndex++) {
|
||||||
Coordinate c = drawPoints[i];
|
Coordinate c = drawPoints[currentIndex];
|
||||||
finPointHandles[i] = new Rectangle2D.Double(c.x - boxHalfWidth, c.y - boxHalfWidth, boxWidth, boxWidth);
|
|
||||||
g2.draw(finPointHandles[i]);
|
if( currentIndex == selectedIndex ) {
|
||||||
|
finPointHandles[currentIndex] = new Rectangle2D.Double(c.x - selBoxHalfWidth, c.y - selBoxHalfWidth, selBoxWidth, selBoxWidth);
|
||||||
|
} else {
|
||||||
|
// normal boxes
|
||||||
|
finPointHandles[currentIndex] = new Rectangle2D.Double(c.x - boxHalfWidth, c.y - boxHalfWidth, boxWidth, boxWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
g2.draw(finPointHandles[currentIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point2D.Double getPoint( final int x, final int y){
|
private Point2D.Double getPoint( final int x, final int y){
|
||||||
if (finPointHandles == null)
|
if (finPointHandles == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -261,9 +272,11 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (int i = 0; i < finPointHandles.length; i++) {
|
for (int i = 0; i < finPointHandles.length; i++) {
|
||||||
if (finPointHandles[i].contains(p))
|
if (finPointHandles[i].contains(p)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,5 +367,12 @@ public class FinPointFigure extends AbstractScaleFigure {
|
|||||||
System.err.println(String.format("________ Origin Location (px): w=%d, h=%d: ", originLocation_px.width, originLocation_px.height));
|
System.err.println(String.format("________ Origin Location (px): w=%d, h=%d: ", originLocation_px.width, originLocation_px.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetSelectedIndex() {
|
||||||
|
this.selectedIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedIndex(final int newIndex) {
|
||||||
|
this.selectedIndex = newIndex;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user