import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Ellipse2D;
-import java.util.Arrays;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.event.ChangeListener;
import net.miginfocom.swing.MigLayout;
+import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.gui.Resettable;
import net.sf.openrocket.gui.SpinnerEditor;
import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.components.BasicSlider;
import net.sf.openrocket.gui.components.UnitSelector;
+import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.ClusterConfiguration;
import net.sf.openrocket.rocketcomponent.Clusterable;
import net.sf.openrocket.rocketcomponent.InnerTube;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.RocketComponent;
+import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
+import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Coordinate;
public class InnerTubeConfig extends ThicknessRingComponentConfig {
-
-
- public InnerTubeConfig(RocketComponent c) {
- super(c);
+ private static final Translator trans = Application.getTranslator();
+
+
+ public InnerTubeConfig(OpenRocketDocument d, RocketComponent c) {
+ super(d, c);
JPanel tab;
- tab = positionTab();
- tabbedPane.insertTab("Radial position", null, tab, "Radial position", 1);
+ tab = new MotorConfig((MotorMount) c);
+ //// Motor and Motor mount configuration
+ tabbedPane.insertTab(trans.get("InnerTubeCfg.tab.Motor"), null, tab,
+ trans.get("InnerTubeCfg.tab.ttip.Motor"), 1);
- tab = new MotorConfig((MotorMount)c);
- tabbedPane.insertTab("Motor", null, tab, "Motor mount configuration", 2);
-
tab = clusterTab();
- tabbedPane.insertTab("Cluster", null, tab, "Cluster configuration", 3);
+ //// Cluster and Cluster configuration
+ tabbedPane.insertTab(trans.get("InnerTubeCfg.tab.Cluster"), null, tab,
+ trans.get("InnerTubeCfg.tab.ttip.Cluster"), 2);
+
+ tab = positionTab();
+ //// Radial position
+ tabbedPane.insertTab(trans.get("InnerTubeCfg.tab.Radialpos"), null, tab,
+ trans.get("InnerTubeCfg.tab.ttip.Radialpos"), 3);
tabbedPane.setSelectedIndex(0);
}
JPanel subPanel = new JPanel(new MigLayout());
// Cluster type selection
- subPanel.add(new JLabel("Select cluster configuration:"),"spanx, wrap");
- subPanel.add(new ClusterSelectionPanel((InnerTube)component),"spanx, wrap");
-// JPanel clusterSelection = new ClusterSelectionPanel((InnerTube)component);
-// clusterSelection.setBackground(Color.blue);
-// subPanel.add(clusterSelection);
+ //// Select cluster configuration:
+ subPanel.add(new JLabel(trans.get("InnerTubeCfg.lbl.Selectclustercfg")), "spanx, wrap");
+ subPanel.add(new ClusterSelectionPanel((InnerTube) component), "spanx, wrap");
+ // JPanel clusterSelection = new ClusterSelectionPanel((InnerTube)component);
+ // clusterSelection.setBackground(Color.blue);
+ // subPanel.add(clusterSelection);
panel.add(subPanel);
-
- subPanel = new JPanel(new MigLayout("gap rel unrel","[][65lp::][30lp::]"));
+ subPanel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::]"));
+
// Tube separation scale
- JLabel l = new JLabel("Tube separation:");
- l.setToolTipText("The separation of the tubes, 1.0 = touching each other");
+ //// Tube separation:
+ JLabel l = new JLabel(trans.get("InnerTubeCfg.lbl.TubeSep"));
+ //// The separation of the tubes, 1.0 = touching each other
+ l.setToolTipText(trans.get("InnerTubeCfg.lbl.ttip.TubeSep"));
subPanel.add(l);
- DoubleModel dm = new DoubleModel(component,"ClusterScale",1,UnitGroup.UNITS_NONE,0);
-
+ DoubleModel dm = new DoubleModel(component, "ClusterScale", 1, UnitGroup.UNITS_NONE, 0);
+
JSpinner spin = new JSpinner(dm.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
- spin.setToolTipText("The separation of the tubes, 1.0 = touching each other");
- subPanel.add(spin,"growx");
+ //// The separation of the tubes, 1.0 = touching each other
+ spin.setToolTipText(trans.get("InnerTubeCfg.lbl.ttip.TubeSep"));
+ subPanel.add(spin, "growx");
BasicSlider bs = new BasicSlider(dm.getSliderModel(0, 1, 4));
- bs.setToolTipText("The separation of the tubes, 1.0 = touching each other");
- subPanel.add(bs,"skip,w 100lp, wrap");
-
- // Rotation
- l = new JLabel("Rotation:");
- l.setToolTipText("Rotation angle of the cluster configuration");
+ //// The separation of the tubes, 1.0 = touching each other
+ bs.setToolTipText(trans.get("InnerTubeCfg.lbl.ttip.TubeSep"));
+ subPanel.add(bs, "skip,w 100lp, wrap");
+
+ // Rotation:
+ l = new JLabel(trans.get("InnerTubeCfg.lbl.Rotation"));
+ //// Rotation angle of the cluster configuration
+ l.setToolTipText(trans.get("InnerTubeCfg.lbl.ttip.Rotation"));
subPanel.add(l);
- dm = new DoubleModel(component,"ClusterRotation",1,UnitGroup.UNITS_ANGLE,
- -Math.PI,Math.PI);
-
+ dm = new DoubleModel(component, "ClusterRotation", 1, UnitGroup.UNITS_ANGLE,
+ -Math.PI, Math.PI);
+
spin = new JSpinner(dm.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
- spin.setToolTipText("Rotation angle of the cluster configuration");
- subPanel.add(spin,"growx");
+ //// Rotation angle of the cluster configuration
+ spin.setToolTipText(trans.get("InnerTubeCfg.lbl.ttip.Rotation"));
+ subPanel.add(spin, "growx");
- subPanel.add(new UnitSelector(dm),"growx");
+ subPanel.add(new UnitSelector(dm), "growx");
bs = new BasicSlider(dm.getSliderModel(-Math.PI, 0, Math.PI));
- bs.setToolTipText("Rotation angle of the cluster configuration");
- subPanel.add(bs,"w 100lp, wrap para");
-
-
+ //// Rotation angle of the cluster configuration
+ bs.setToolTipText(trans.get("InnerTubeCfg.lbl.ttip.Rotation"));
+ subPanel.add(bs, "w 100lp, wrap para");
+
+
// Split button
- JButton split = new JButton("Split cluster");
- split.setToolTipText("<html>Split the cluster into separate components.<br>" +
- "This also duplicates all components attached to this inner tube.");
+ //// Split cluster
+ JButton split = new JButton(trans.get("InnerTubeCfg.but.Splitcluster"));
+ //// <html>Split the cluster into separate components.<br>
+ //// This also duplicates all components attached to this inner tube.
+ split.setToolTipText(trans.get("InnerTubeCfg.lbl.longA1") +
+ trans.get("InnerTubeCfg.lbl.longA2"));
split.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
RocketComponent parent = component.getParent();
int index = parent.getChildPosition(component);
if (index < 0) {
- throw new IllegalStateException("component="+component+
- " parent="+parent+" parent.children=" +
- Arrays.toString(parent.getChildren()));
+ throw new BugException("Inconsistent state: component=" + component +
+ " parent=" + parent + " parent.children=" + parent.getChildren());
}
-
- InnerTube tube = (InnerTube)component;
+
+ InnerTube tube = (InnerTube) component;
if (tube.getClusterCount() <= 1)
return;
-
- ComponentConfigDialog.addUndoPosition("Split cluster");
-
+
+ document.addUndoPosition("Split cluster");
+
Coordinate[] coords = { Coordinate.NUL };
coords = component.shiftCoordinates(coords);
parent.removeChild(index);
- for (int i=0; i<coords.length; i++) {
- InnerTube copy = (InnerTube)component.copy();
+ for (int i = 0; i < coords.length; i++) {
+ InnerTube copy = (InnerTube) component.copy();
copy.setClusterConfiguration(ClusterConfiguration.SINGLE);
copy.setClusterRotation(0.0);
copy.setClusterScale(1.0);
copy.setRadialShift(coords[i].y, coords[i].z);
- copy.setName(copy.getName() + " #" + (i+1));
+ copy.setName(copy.getName() + " #" + (i + 1));
- parent.addChild(copy, index+i);
+ parent.addChild(copy, index + i);
}
}
});
});
subPanel.add(split, "spanx, split 2, gapright para, sizegroup buttons, right");
-
+
// Reset button
- JButton reset = new JButton("Reset settings");
- reset.setToolTipText("Reset the separation and rotation to the default values");
+ ///// Reset settings
+ JButton reset = new JButton(trans.get("InnerTubeCfg.but.Resetsettings"));
+ //// Reset the separation and rotation to the default values
+ reset.setToolTipText(trans.get("InnerTubeCfg.but.ttip.Resetsettings"));
reset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
- ((InnerTube)component).setClusterScale(1.0);
- ((InnerTube)component).setClusterRotation(0.0);
+ ((InnerTube) component).setClusterScale(1.0);
+ ((InnerTube) component).setClusterRotation(0.0);
}
});
- subPanel.add(reset,"sizegroup buttons, right");
-
- panel.add(subPanel,"grow");
+ subPanel.add(reset, "sizegroup buttons, right");
+ panel.add(subPanel, "grow");
+
return panel;
}
}
public ClusterSelectionPanel(Clusterable component) {
super(new MigLayout("gap 0 0",
- "["+BUTTON_SIZE+"!]["+BUTTON_SIZE+"!]["+BUTTON_SIZE+"!]["+BUTTON_SIZE+"!]",
- "["+BUTTON_SIZE+"!]["+BUTTON_SIZE+"!]["+BUTTON_SIZE+"!]"));
+ "[" + BUTTON_SIZE + "!][" + BUTTON_SIZE + "!][" + BUTTON_SIZE + "!][" + BUTTON_SIZE + "!]",
+ "[" + BUTTON_SIZE + "!][" + BUTTON_SIZE + "!][" + BUTTON_SIZE + "!]"));
- for (int i=0; i<ClusterConfiguration.CONFIGURATIONS.length; i++) {
+ for (int i = 0; i < ClusterConfiguration.CONFIGURATIONS.length; i++) {
ClusterConfiguration config = ClusterConfiguration.CONFIGURATIONS[i];
- JComponent button = new ClusterButton(component,config);
- if (i%4 == 3)
- add(button,"wrap");
+ JComponent button = new ClusterButton(component, config);
+ if (i % 4 == 3)
+ add(button, "wrap");
else
add(button);
}
-
+
}
private class ClusterButton extends JPanel implements ChangeListener, MouseListener,
- Resettable {
+ Resettable {
private Clusterable component;
private ClusterConfiguration config;
public ClusterButton(Clusterable c, ClusterConfiguration config) {
component = c;
this.config = config;
- setMinimumSize(new Dimension(BUTTON_SIZE,BUTTON_SIZE));
- setPreferredSize(new Dimension(BUTTON_SIZE,BUTTON_SIZE));
- setMaximumSize(new Dimension(BUTTON_SIZE,BUTTON_SIZE));
+ setMinimumSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
+ setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
+ setMaximumSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
-// setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
+ // setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
component.addChangeListener(this);
addMouseListener(this);
}
-
+
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
- Graphics2D g2 = (Graphics2D)g;
+ Graphics2D g2 = (Graphics2D) g;
Rectangle area = g2.getClipBounds();
if (component.getClusterConfiguration() == config)
g2.fillRect(area.x, area.y, area.width, area.height);
- g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
+ g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_NORMALIZE);
- g2.setRenderingHint(RenderingHints.KEY_RENDERING,
+ g2.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
List<Double> points = config.getPoints();
Ellipse2D.Float circle = new Ellipse2D.Float();
- for (int i=0; i < points.size()/2; i++) {
- double x = points.get(i*2);
- double y = points.get(i*2+1);
+ for (int i = 0; i < points.size() / 2; i++) {
+ double x = points.get(i * 2);
+ double y = points.get(i * 2 + 1);
- double px = BUTTON_SIZE/2 + x*MOTOR_DIAMETER;
- double py = BUTTON_SIZE/2 - y*MOTOR_DIAMETER;
- circle.setFrameFromCenter(px,py,px+MOTOR_DIAMETER/2,py+MOTOR_DIAMETER/2);
+ double px = BUTTON_SIZE / 2 + x * MOTOR_DIAMETER;
+ double py = BUTTON_SIZE / 2 - y * MOTOR_DIAMETER;
+ circle.setFrameFromCenter(px, py, px + MOTOR_DIAMETER / 2, py + MOTOR_DIAMETER / 2);
g2.setColor(MOTOR_FILL_COLOR);
g2.fill(circle);
g2.draw(circle);
}
}
-
-
+
+
+ @Override
public void stateChanged(ChangeEvent e) {
repaint();
}
-
-
+
+
+ @Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
component.setClusterConfiguration(config);
}
}
- public void mouseEntered(MouseEvent e) { }
- public void mouseExited(MouseEvent e) { }
- public void mousePressed(MouseEvent e) { }
- public void mouseReleased(MouseEvent e) { }
-
-
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ }
+
+
+ @Override
public void resetModel() {
component.removeChangeListener(this);
removeMouseListener(this);