[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.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.io.BufferedWriter;
|
||||
@ -71,6 +72,8 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
||||
private JTable table = null;
|
||||
private FinPointTableModel tableModel = null;
|
||||
|
||||
private int dragIndex = -1;
|
||||
|
||||
private FinPointFigure figure = null;
|
||||
|
||||
|
||||
@ -214,6 +217,14 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
||||
for (int i = 0; i < Columns.values().length; i++) {
|
||||
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);
|
||||
|
||||
JButton scaleButton = new JButton(trans.get("FreeformFinSetConfig.lbl.scaleFin"));
|
||||
@ -341,7 +352,6 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
||||
document.stopUndo();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -351,8 +361,21 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
||||
|
||||
if (tableModel != null) {
|
||||
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( 0 <= this.dragIndex ) {
|
||||
figure.setSelectedIndex(dragIndex);
|
||||
}else{
|
||||
figure.resetSelectedIndex();
|
||||
}
|
||||
figure.updateFigure();
|
||||
}
|
||||
|
||||
@ -360,13 +383,11 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 int dragIndex = -1;
|
||||
|
||||
|
||||
private FinPointScrollPane( final FinPointFigure _figure) {
|
||||
super( _figure);
|
||||
@ -381,30 +402,30 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
||||
return;
|
||||
}
|
||||
|
||||
final int pointIndex = getPoint(event);
|
||||
|
||||
if ( pointIndex >= 0) {
|
||||
dragIndex = pointIndex;
|
||||
final int pressIndex = getPoint(event);
|
||||
if ( pressIndex >= 0) {
|
||||
dragIndex = pressIndex;
|
||||
updateFields();
|
||||
return;
|
||||
}
|
||||
|
||||
final int segmentIndex = getSegment(event);
|
||||
System.err.println(String.format(".... finpoint//segmentIndex: %d", segmentIndex));
|
||||
if (segmentIndex >= 0) {
|
||||
Point2D.Double point = getCoordinates(event);
|
||||
finset.addPoint(segmentIndex );
|
||||
|
||||
try {
|
||||
finset.setPoint(dragIndex, point.x, point.y);
|
||||
dragIndex = segmentIndex;
|
||||
updateFields();
|
||||
return;
|
||||
} catch (IllegalFinPointException ignore) {
|
||||
// no-op
|
||||
} catch (ArrayIndexOutOfBoundsException ex) {
|
||||
log.error("bad index while editing fin points!!", ex);
|
||||
}
|
||||
dragIndex = segmentIndex;
|
||||
|
||||
updateFields();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -415,7 +436,7 @@ public class FreeformFinSetConfig extends FinSetConfig {
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent event) {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.NoninvertibleTransformException;
|
||||
import java.awt.geom.Path2D;
|
||||
@ -43,6 +42,7 @@ public class FinPointFigure extends AbstractScaleFigure {
|
||||
|
||||
// the size of the boxes around each fin point vertex
|
||||
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 MAJOR_TICKS = 0.1;
|
||||
@ -56,7 +56,7 @@ public class FinPointFigure extends AbstractScaleFigure {
|
||||
protected final List<StateChangeListener> listeners = new LinkedList<StateChangeListener>();
|
||||
|
||||
private Rectangle2D.Double[] finPointHandles = null;
|
||||
|
||||
private int selectedIndex = -1;
|
||||
|
||||
public FinPointFigure(FreeformFinSet finset) {
|
||||
this.finset = finset;
|
||||
@ -229,19 +229,30 @@ public class FinPointFigure extends AbstractScaleFigure {
|
||||
|
||||
// Fin point boxes
|
||||
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 );
|
||||
g2.setStroke(new BasicStroke( boxEdgeWidth_m, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
||||
g2.setColor(new Color(150, 0, 0));
|
||||
final double boxHalfWidth = boxWidth/2;
|
||||
|
||||
finPointHandles = new Rectangle2D.Double[ drawPoints.length];
|
||||
for (int i = 0; i < drawPoints.length; i++) {
|
||||
Coordinate c = drawPoints[i];
|
||||
finPointHandles[i] = new Rectangle2D.Double(c.x - boxHalfWidth, c.y - boxHalfWidth, boxWidth, boxWidth);
|
||||
g2.draw(finPointHandles[i]);
|
||||
for (int currentIndex = 0; currentIndex < drawPoints.length; currentIndex++) {
|
||||
Coordinate c = drawPoints[currentIndex];
|
||||
|
||||
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)
|
||||
return null;
|
||||
|
||||
@ -261,9 +272,11 @@ public class FinPointFigure extends AbstractScaleFigure {
|
||||
return -1;
|
||||
|
||||
for (int i = 0; i < finPointHandles.length; i++) {
|
||||
if (finPointHandles[i].contains(p))
|
||||
if (finPointHandles[i].contains(p)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public void resetSelectedIndex() {
|
||||
this.selectedIndex = -1;
|
||||
}
|
||||
|
||||
public void setSelectedIndex(final int newIndex) {
|
||||
this.selectedIndex = newIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user