Component scaling support
[debian/openrocket] / src / net / sf / openrocket / gui / configdialog / FreeformFinSetConfig.java
index 87be5fb40592fd06546250371e255c7596b410f5..06c877c7fa94810f31866d711b5bdce19777d78c 100644 (file)
@@ -28,6 +28,7 @@ import net.sf.openrocket.gui.scalefigure.FinPointFigure;
 import net.sf.openrocket.gui.scalefigure.ScaleScrollPane;
 import net.sf.openrocket.gui.scalefigure.ScaleSelector;
 import net.sf.openrocket.l10n.Translator;
+import net.sf.openrocket.logging.LogHelper;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.rocketcomponent.FinSet;
 import net.sf.openrocket.rocketcomponent.FreeformFinSet;
@@ -38,24 +39,26 @@ import net.sf.openrocket.unit.UnitGroup;
 import net.sf.openrocket.util.Coordinate;
 
 public class FreeformFinSetConfig extends FinSetConfig {
-
+       
+       private static final LogHelper log = Application.getLogger();
+       private static final Translator trans = Application.getTranslator();
+       
        private final FreeformFinSet finset;
        private JTable table = null;
        private FinPointTableModel tableModel = null;
        
        private FinPointFigure figure = null;
-       private static final Translator trans = Application.getTranslator();
-
+       
        
        public FreeformFinSetConfig(RocketComponent component) {
                super(component);
-               this.finset = (FreeformFinSet)component;
-
+               this.finset = (FreeformFinSet) component;
+               
                //// General and General properties
-               tabbedPane.insertTab(trans.get("FreeformFinSetCfg.tab.General"), null, generalPane(), 
+               tabbedPane.insertTab(trans.get("FreeformFinSetCfg.tab.General"), null, generalPane(),
                                trans.get("FreeformFinSetCfg.tab.ttip.General"), 0);
                //// Shape and Fin shape
-               tabbedPane.insertTab(trans.get("FreeformFinSetCfg.tab.Shape"), null, shapePane(), 
+               tabbedPane.insertTab(trans.get("FreeformFinSetCfg.tab.Shape"), null, shapePane(),
                                trans.get("FreeformFinSetCfg.tab.ttip.Finshape"), 1);
                tabbedPane.setSelectedIndex(0);
                
@@ -63,43 +66,43 @@ public class FreeformFinSetConfig extends FinSetConfig {
        }
        
        
-       
-       private JPanel generalPane() {
 
+       private JPanel generalPane() {
+               
                DoubleModel m;
                JSpinner spin;
                JComboBox combo;
                
                JPanel mainPanel = new JPanel(new MigLayout("fill"));
                
-               JPanel panel = new JPanel(new MigLayout("fill, gap rel unrel","[][65lp::][30lp::]",""));
-               
-               
+               JPanel panel = new JPanel(new MigLayout("fill, gap rel unrel", "[][65lp::][30lp::]", ""));
                
+
+
                ////  Number of fins:
                panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Numberoffins")));
                
-               IntegerModel im = new IntegerModel(component,"FinCount",1,8);
+               IntegerModel im = new IntegerModel(component, "FinCount", 1, 8);
                
                spin = new JSpinner(im.getSpinnerModel());
                spin.setEditor(new SpinnerEditor(spin));
-               panel.add(spin,"growx, wrap");
-               
+               panel.add(spin, "growx, wrap");
                
+
                ////  Base rotation
                panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Finrotation")));
                
-               m = new DoubleModel(component, "BaseRotation", UnitGroup.UNITS_ANGLE,-Math.PI,Math.PI);
+               m = new DoubleModel(component, "BaseRotation", UnitGroup.UNITS_ANGLE, -Math.PI, Math.PI);
                
                spin = new JSpinner(m.getSpinnerModel());
                spin.setEditor(new SpinnerEditor(spin));
-               panel.add(spin,"growx");
-               
-               panel.add(new UnitSelector(m),"growx");
-               panel.add(new BasicSlider(m.getSliderModel(-Math.PI,Math.PI)),"w 100lp, wrap");
+               panel.add(spin, "growx");
                
+               panel.add(new UnitSelector(m), "growx");
+               panel.add(new BasicSlider(m.getSliderModel(-Math.PI, Math.PI)), "w 100lp, wrap");
                
 
+
                ////  Fin cant
                JLabel label = new JLabel(trans.get("FreeformFinSetCfg.lbl.Fincant"));
                //// The angle that the fins are canted with respect to the rocket body.
@@ -107,135 +110,135 @@ public class FreeformFinSetConfig extends FinSetConfig {
                panel.add(label);
                
                m = new DoubleModel(component, "CantAngle", UnitGroup.UNITS_ANGLE,
-                               -FinSet.MAX_CANT,FinSet.MAX_CANT);
+                               -FinSet.MAX_CANT, FinSet.MAX_CANT);
                
                spin = new JSpinner(m.getSpinnerModel());
                spin.setEditor(new SpinnerEditor(spin));
-               panel.add(spin,"growx");
+               panel.add(spin, "growx");
                
-               panel.add(new UnitSelector(m),"growx");
-               panel.add(new BasicSlider(m.getSliderModel(-FinSet.MAX_CANT,FinSet.MAX_CANT)),
+               panel.add(new UnitSelector(m), "growx");
+               panel.add(new BasicSlider(m.getSliderModel(-FinSet.MAX_CANT, FinSet.MAX_CANT)),
                                "w 100lp, wrap 40lp");
                
-               
-               
+
+
                ////  Position
                //// Position relative to:
-               panel.add(new JLabel("FreeformFinSetCfg.lbl.Posrelativeto"));
-
+               panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Posrelativeto")));
+               
                combo = new JComboBox(
                                new EnumModel<RocketComponent.Position>(component, "RelativePosition",
                                                new RocketComponent.Position[] {
-                                               RocketComponent.Position.TOP,
-                                               RocketComponent.Position.MIDDLE,
-                                               RocketComponent.Position.BOTTOM,
-                                               RocketComponent.Position.ABSOLUTE
+                                                               RocketComponent.Position.TOP,
+                                                               RocketComponent.Position.MIDDLE,
+                                                               RocketComponent.Position.BOTTOM,
+                                                               RocketComponent.Position.ABSOLUTE
                                }));
-               panel.add(combo,"spanx 3, growx, wrap");
-                               //// plus
-               panel.add(new JLabel("FreeformFinSetCfg.lbl.plus"),"right");
-
-               m = new DoubleModel(component,"PositionValue",UnitGroup.UNITS_LENGTH);
+               panel.add(combo, "spanx 3, growx, wrap");
+               //// plus
+               panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.plus")), "right");
+               
+               m = new DoubleModel(component, "PositionValue", UnitGroup.UNITS_LENGTH);
                spin = new JSpinner(m.getSpinnerModel());
                spin.setEditor(new SpinnerEditor(spin));
-               panel.add(spin,"growx");
+               panel.add(spin, "growx");
                
-               panel.add(new UnitSelector(m),"growx");
+               panel.add(new UnitSelector(m), "growx");
                panel.add(new BasicSlider(m.getSliderModel(
                                new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE),
                                new DoubleModel(component.getParent(), "Length"))),
                                "w 100lp, wrap");
-
-               
-               
                
 
+
+
+
                mainPanel.add(panel, "aligny 20%");
                mainPanel.add(new JSeparator(SwingConstants.VERTICAL), "growy, height 150lp");
                
+
+               panel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::]", ""));
                
-               panel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]",""));
-               
-               
-               
-               
+
+
+
                ////  Cross section
                //// Fin cross section:
-               panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.FincrossSection")),"span, split");
+               panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.FincrossSection")), "span, split");
                combo = new JComboBox(
-                               new EnumModel<FinSet.CrossSection>(component,"CrossSection"));
-               panel.add(combo,"growx, wrap unrel");
+                               new EnumModel<FinSet.CrossSection>(component, "CrossSection"));
+               panel.add(combo, "growx, wrap unrel");
                
 
                ////  Thickness:
                panel.add(new JLabel(trans.get("FreeformFinSetCfg.lbl.Thickness")));
                
-               m = new DoubleModel(component,"Thickness",UnitGroup.UNITS_LENGTH,0);
+               m = new DoubleModel(component, "Thickness", UnitGroup.UNITS_LENGTH, 0);
                
                spin = new JSpinner(m.getSpinnerModel());
                spin.setEditor(new SpinnerEditor(spin));
-               panel.add(spin,"growx");
+               panel.add(spin, "growx");
                
-               panel.add(new UnitSelector(m),"growx");
-               panel.add(new BasicSlider(m.getSliderModel(0,0.01)),"w 100lp, wrap 30lp");
+               panel.add(new UnitSelector(m), "growx");
+               panel.add(new BasicSlider(m.getSliderModel(0, 0.01)), "w 100lp, wrap 30lp");
                
 
                //// Material
                materialPanel(panel, Material.Type.BULK);
                
-               
-               
+
+
                mainPanel.add(panel, "aligny 20%");
                
                return mainPanel;
        }
        
        
-       
+
        private JPanel shapePane() {
                JPanel panel = new JPanel(new MigLayout("fill"));
                
-               
+
                // Create the figure
                figure = new FinPointFigure(finset);
                ScaleScrollPane figurePane = new FinPointScrollPane();
                figurePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                figurePane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
-
+               
                // Create the table
                tableModel = new FinPointTableModel();
                table = new JTable(tableModel);
                table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-               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());
+                                       setPreferredWidth(Columns.values()[i].getWidth());
                }
                JScrollPane tablePane = new JScrollPane(table);
                
+
+               //              panel.add(new JLabel("Coordinates:"), "aligny bottom, alignx 50%");
+               //              panel.add(new JLabel("    View:"), "wrap, aligny bottom");
                
-//             panel.add(new JLabel("Coordinates:"), "aligny bottom, alignx 50%");
-//             panel.add(new JLabel("    View:"), "wrap, aligny bottom");
-               
-               
-               panel.add(tablePane,"growy, width 100lp:100lp:, height 100lp:250lp:");
-               panel.add(figurePane,"gap unrel, spanx, growx, growy 1000, height 100lp:250lp:, wrap");
-               
-               panel.add(new StyledLabel("Double-click", -2), "alignx 50%");
+
+               panel.add(tablePane, "growy, width 100lp:100lp:, height 100lp:250lp:");
+               panel.add(figurePane, "gap unrel, spanx, growx, growy 1000, height 100lp:250lp:, wrap");
                
-               panel.add(new ScaleSelector(figurePane),"spany 2");
-               panel.add(new StyledLabel("Click+drag: Add and move points   " +
-                               "Ctrl+click: Remove point", -2), "spany 2, right, wrap");
+               panel.add(new StyledLabel(trans.get("lbl.doubleClick1"), -2), "alignx 50%");
                
+               panel.add(new ScaleSelector(figurePane), "spany 2");
+               panel.add(new StyledLabel(trans.get("FreeformFinSetConfig.lbl.clickDrag") + "   " +
+                               trans.get("FreeformFinSetConfig.lbl.ctrlClick"), -2), "spany 2, right, wrap");
                
-               panel.add(new StyledLabel("to edit", -2), "alignx 50%");
+
+               panel.add(new StyledLabel(trans.get("FreeformFinSetConfig.lbl.doubleClick2"), -2), "alignx 50%");
                
                return panel;
        }
        
        
-       
-       
-       
+
+
+
        @Override
        public void updateFields() {
                super.updateFields();
@@ -249,20 +252,20 @@ public class FreeformFinSetConfig extends FinSetConfig {
        }
        
        
-       
-       
+
+
        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 | 
+               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;
                
                public FinPointScrollPane() {
-                       super(figure, false);   // Disallow fitting as it's buggy
+                       super(figure, false); // Disallow fitting as it's buggy
                }
-
+               
                @Override
                public void mousePressed(MouseEvent event) {
                        int mods = event.getModifiersEx();
@@ -284,7 +287,8 @@ public class FreeformFinSetConfig extends FinSetConfig {
                                finset.addPoint(index);
                                try {
                                        finset.setPoint(index, point.x, point.y);
-                               } catch (IllegalFinPointException ignore) { }
+                               } catch (IllegalFinPointException ignore) {
+                               }
                                dragIndex = index;
                                
                                return;
@@ -293,13 +297,13 @@ public class FreeformFinSetConfig extends FinSetConfig {
                        super.mousePressed(event);
                        return;
                }
-
+               
                
                @Override
                public void mouseDragged(MouseEvent event) {
                        int mods = event.getModifiersEx();
                        if (dragIndex < 0 ||
-                                       (mods & (ANY_MASK | MouseEvent.BUTTON1_DOWN_MASK)) != 
+                                       (mods & (ANY_MASK | MouseEvent.BUTTON1_DOWN_MASK)) !=
                                                MouseEvent.BUTTON1_DOWN_MASK) {
                                super.mouseDragged(event);
                                return;
@@ -309,7 +313,8 @@ public class FreeformFinSetConfig extends FinSetConfig {
                        try {
                                finset.setPoint(dragIndex, point.x, point.y);
                        } catch (IllegalFinPointException ignore) {
-                               System.out.println("IAE:"+ignore);
+                               log.debug("Ignoring IllegalFinPointException while dragging, dragIndex=" + dragIndex +
+                                               " x=" + point.x + " y=" + point.y);
                        }
                }
                
@@ -334,7 +339,7 @@ public class FreeformFinSetConfig extends FinSetConfig {
                                super.mouseClicked(event);
                                return;
                        }
-
+                       
                        try {
                                finset.removePoint(index);
                        } catch (IllegalFinPointException ignore) {
@@ -369,54 +374,58 @@ public class FreeformFinSetConfig extends FinSetConfig {
                        return figure.convertPoint(x, y);
                }
                
-               
+
        }
        
        
 
-       
-       
+
+
        private enum Columns {
-//             NUMBER {
-//                     @Override
-//                     public String toString() {
-//                             return "#";
-//                     }
-//                     @Override
-//                     public String getValue(FreeformFinSet finset, int row) {
-//                             return "" + (row+1) + ".";
-//                     }
-//                     @Override
-//                     public int getWidth() {
-//                             return 10;
-//                     }
-//             }, 
+               //              NUMBER {
+               //                      @Override
+               //                      public String toString() {
+               //                              return "#";
+               //                      }
+               //                      @Override
+               //                      public String getValue(FreeformFinSet finset, int row) {
+               //                              return "" + (row+1) + ".";
+               //                      }
+               //                      @Override
+               //                      public int getWidth() {
+               //                              return 10;
+               //                      }
+               //              }, 
                X {
                        @Override
                        public String toString() {
                                return "X / " + UnitGroup.UNITS_LENGTH.getDefaultUnit().toString();
                        }
+                       
                        @Override
                        public String getValue(FreeformFinSet finset, int row) {
                                return UnitGroup.UNITS_LENGTH.getDefaultUnit()
-                                       .toString(finset.getFinPoints()[row].x);
+                                               .toString(finset.getFinPoints()[row].x);
                        }
-               }, 
+               },
                Y {
                        @Override
                        public String toString() {
                                return "Y / " + UnitGroup.UNITS_LENGTH.getDefaultUnit().toString();
                        }
+                       
                        @Override
                        public String getValue(FreeformFinSet finset, int row) {
                                return UnitGroup.UNITS_LENGTH.getDefaultUnit()
-                                       .toString(finset.getFinPoints()[row].y);
+                                               .toString(finset.getFinPoints()[row].y);
                        }
                };
                
                public abstract String getValue(FreeformFinSet finset, int row);
+               
                @Override
                public abstract String toString();
+               
                public int getWidth() {
                        return 20;
                }
@@ -428,12 +437,12 @@ public class FreeformFinSetConfig extends FinSetConfig {
                public int getColumnCount() {
                        return Columns.values().length;
                }
-
+               
                @Override
                public int getRowCount() {
                        return finset.getPointCount();
                }
-
+               
                @Override
                public Object getValueAt(int rowIndex, int columnIndex) {
                        return Columns.values()[columnIndex].getValue(finset, rowIndex);
@@ -446,7 +455,7 @@ public class FreeformFinSetConfig extends FinSetConfig {
                
                @Override
                public boolean isCellEditable(int rowIndex, int columnIndex) {
-                       if (rowIndex == 0 || rowIndex == getRowCount()-1) {
+                       if (rowIndex == 0 || rowIndex == getRowCount() - 1) {
                                return (columnIndex == Columns.X.ordinal());
                        }
                        
@@ -460,11 +469,11 @@ public class FreeformFinSetConfig extends FinSetConfig {
                        
                        if (rowIndex < 0 || rowIndex >= finset.getFinPoints().length ||
                                        columnIndex < 0 || columnIndex >= Columns.values().length) {
-                               throw new IllegalArgumentException("Index out of bounds, row="+rowIndex+
-                                               " column="+columnIndex+" fin point count="+finset.getFinPoints().length);
+                               throw new IllegalArgumentException("Index out of bounds, row=" + rowIndex +
+                                               " column=" + columnIndex + " fin point count=" + finset.getFinPoints().length);
                        }
                        
-                       String str = (String)o;
+                       String str = (String) o;
                        try {
                                
                                double value = UnitGroup.UNITS_LENGTH.fromString(str);
@@ -475,7 +484,7 @@ public class FreeformFinSetConfig extends FinSetConfig {
                                        c = c.setY(value);
                                
                                finset.setPoint(rowIndex, c.x, c.y);
-                       
+                               
                        } catch (NumberFormatException ignore) {
                        } catch (IllegalFinPointException ignore) {
                        }