bug fixes
authorplaa <plaa@180e2498-e6e9-4542-8430-84ac67f01cd8>
Mon, 19 Jul 2010 11:28:15 +0000 (11:28 +0000)
committerplaa <plaa@180e2498-e6e9-4542-8430-84ac67f01cd8>
Mon, 19 Jul 2010 11:28:15 +0000 (11:28 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@58 180e2498-e6e9-4542-8430-84ac67f01cd8

ChangeLog
src/net/sf/openrocket/gui/main/ComponentAddButtons.java
src/net/sf/openrocket/gui/main/SimulationRunDialog.java
src/net/sf/openrocket/util/Prefs.java
test/net/sf/openrocket/logging/LoggingTest.java

index 4404b9ca9e27beb455bc61b75b062521aebf21f2..58bb84c166d18d65704ce1f75137326ba9940ccb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-07-19  Sampo Niskanen
+
+       * Small bug fixes
+
+2010-07-18  Sampo Niskanen
+
+       * Major refactoring of simulation code
+
 2010-03-21  Sampo Niskanen
 
        * Released version 1.1.0
index 1a311d328012bc866198b5a0c33d671ac8e83259..1f22c2e9ad2605a0b506522d6affaee61e6b7e4a 100644 (file)
@@ -62,11 +62,11 @@ import net.sf.openrocket.util.Reflection;
  */
 
 public class ComponentAddButtons extends JPanel implements Scrollable {
-
+       
        private static final int ROWS = 3;
        private static final int MAXCOLS = 6;
        private static final String BUTTONPARAM = "grow, sizegroup buttons";
-
+       
        private static final int GAP = 5;
        private static final int EXTRASPACE = 0;
        
@@ -80,15 +80,15 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
        private final int width, height;
        
        
-       public ComponentAddButtons(OpenRocketDocument document, TreeSelectionModel model, 
+       public ComponentAddButtons(OpenRocketDocument document, TreeSelectionModel model,
                        JViewport viewport) {
                
                super();
                String constaint = "[min!]";
-               for (int i=1; i<MAXCOLS; i++)
+               for (int i = 1; i < MAXCOLS; i++)
                        constaint = constaint + GAP + "[min!]";
                
-               layout = new MigLayout("fill",constaint);
+               layout = new MigLayout("fill", constaint);
                setLayout(layout);
                this.document = document;
                this.selectionModel = model;
@@ -99,48 +99,46 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                
                ////////////////////////////////////////////
                
-               
-               addButtonRow("Body components and fin sets",row,
-                               new BodyComponentButton(NoseCone.class,"Nose cone"),
-                               new BodyComponentButton(BodyTube.class,"Body tube"),
-                               new BodyComponentButton(Transition.class,"Transition"),
-                               new FinButton(TrapezoidFinSet.class,"Trapezoidal"),  // TODO: MEDIUM: freer fin placing
-                               new FinButton(EllipticalFinSet.class,"Elliptical"),
-                               new FinButton(FreeformFinSet.class,"Freeform"),
-                               new FinButton(LaunchLug.class,"Launch lug")
-               );
+
+               addButtonRow("Body components and fin sets", row,
+                               new BodyComponentButton(NoseCone.class, "Nose cone"),
+                               new BodyComponentButton(BodyTube.class, "Body tube"),
+                               new BodyComponentButton(Transition.class, "Transition"),
+                               new FinButton(TrapezoidFinSet.class, "Trapezoidal"), // TODO: MEDIUM: freer fin placing
+                               new FinButton(EllipticalFinSet.class, "Elliptical"),
+                               new FinButton(FreeformFinSet.class, "Freeform"),
+                               new FinButton(LaunchLug.class, "Launch lug"));
                
                row++;
                
-               
+
                /////////////////////////////////////////////
                
-               addButtonRow("Inner component",row,
+               addButtonRow("Inner component", row,
                                new ComponentButton(InnerTube.class, "Inner tube"),
                                new ComponentButton(TubeCoupler.class, "Coupler"),
                                new ComponentButton(CenteringRing.class, "Centering\nring"),
                                new ComponentButton(Bulkhead.class, "Bulkhead"),
                                new ComponentButton(EngineBlock.class, "Engine\nblock"));
-
+               
                row++;
                
                ////////////////////////////////////////////
                
-               addButtonRow("Mass objects",row,
+               addButtonRow("Mass objects", row,
                                new ComponentButton(Parachute.class, "Parachute"),
                                new ComponentButton(Streamer.class, "Streamer"),
                                new ComponentButton(ShockCord.class, "Shock cord"),
-//                             new ComponentButton("Motor clip"),
-//                             new ComponentButton("Payload"),
-                               new ComponentButton(MassComponent.class,"Mass\ncomponent")
-               );
-               
+                               //                              new ComponentButton("Motor clip"),
+                               //                              new ComponentButton("Payload"),
+                               new ComponentButton(MassComponent.class, "Mass\ncomponent"));
                
+
                // Get maximum button size
-               int w=0, h=0;
+               int w = 0, h = 0;
                
-               for (row=0; row < buttons.length; row++) {
-                       for (int col=0; col < buttons[row].length; col++) {
+               for (row = 0; row < buttons.length; row++) {
+                       for (int col = 0; col < buttons[row].length; col++) {
                                Dimension d = buttons[row][col].getPreferredSize();
                                if (d.width > w)
                                        w = d.width;
@@ -150,12 +148,12 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                }
                
                // Set all buttons to maximum size
-               System.out.println("Setting w="+w+" h="+h);
-               width=w;
-               height=h;
-               Dimension d = new Dimension(width,height);
-               for (row=0; row < buttons.length; row++) {
-                       for (int col=0; col < buttons[row].length; col++) {
+               System.out.println("Setting w=" + w + " h=" + h);
+               width = w;
+               height = h;
+               Dimension d = new Dimension(width, height);
+               for (row = 0; row < buttons.length; row++) {
+                       for (int col = 0; col < buttons[row].length; col++) {
                                buttons[row][col].setMinimumSize(d);
                                buttons[row][col].setPreferredSize(d);
                                buttons[row][col].getComponent(0).validate();
@@ -166,6 +164,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                if (viewport != null) {
                        viewport.addChangeListener(new ChangeListener() {
                                private int oldWidth = -1;
+                               
                                public void stateChanged(ChangeEvent e) {
                                        Dimension d = ComponentAddButtons.this.viewport.getExtentSize();
                                        if (d.width != oldWidth) {
@@ -176,7 +175,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                        });
                }
                
-               add(new JPanel(),"grow");
+               add(new JPanel(), "grow");
        }
        
        
@@ -186,50 +185,50 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
         * @param row    Row number
         * @param b      List of ComponentButtons to place on the row
         */
-       private void addButtonRow(String label, int row, ComponentButton ... b) {
-               if (row>0)
-                       add(new JLabel(label),"span, gaptop unrel, wrap");
-               else 
-                       add(new JLabel(label),"span, gaptop 0, wrap");
+       private void addButtonRow(String label, int row, ComponentButton... b) {
+               if (row > 0)
+                       add(new JLabel(label), "span, gaptop unrel, wrap");
+               else
+                       add(new JLabel(label), "span, gaptop 0, wrap");
                
-               int col=0;
+               int col = 0;
                buttons[row] = new ComponentButton[b.length];
-
-               for (int i=0; i<b.length; i++) {
+               
+               for (int i = 0; i < b.length; i++) {
                        buttons[row][col] = b[i];
-                       if (i < b.length-1)
-                               add(b[i],BUTTONPARAM);
+                       if (i < b.length - 1)
+                               add(b[i], BUTTONPARAM);
                        else
-                               add(b[i],BUTTONPARAM+", wrap");
+                               add(b[i], BUTTONPARAM + ", wrap");
                        col++;
                }
        }
        
-
+       
        /**
         * Flows the buttons in all rows of the panel.  If a button would come too close
         * to the right edge of the viewport, "newline" is added to its constraints flowing 
         * it to the next line.
         */
        private void flowButtons() {
-               if (viewport==null)
+               if (viewport == null)
                        return;
                
                int w;
                
                Dimension d = viewport.getExtentSize();
-
-               for (int row=0; row < buttons.length; row++) {
-                       w=0;
-                       for (int col=0; col < buttons[row].length; col++) {
-                               w += GAP+width;
-                               String param = BUTTONPARAM+",width "+width+"!,height "+height+"!";
-
-                               if (w+EXTRASPACE > d.width) {
+               
+               for (int row = 0; row < buttons.length; row++) {
+                       w = 0;
+                       for (int col = 0; col < buttons[row].length; col++) {
+                               w += GAP + width;
+                               String param = BUTTONPARAM + ",width " + width + "!,height " + height + "!";
+                               
+                               if (w + EXTRASPACE > d.width) {
                                        param = param + ",newline";
-                                       w = GAP+width;
+                                       w = GAP + width;
                                }
-                               if (col == buttons[row].length-1)
+                               if (col == buttons[row].length - 1)
                                        param = param + ",wrap";
                                layout.setComponentConstraints(buttons[row][col], param);
                        }
@@ -238,7 +237,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
        }
        
        
-       
+
        /**
         * Class for a component button.
         */
@@ -248,7 +247,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                
                /** Only label, no icon. */
                public ComponentButton(String text) {
-                       this(text,null,null);
+                       this(text, null, null);
                }
                
                /**
@@ -257,48 +256,48 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                 */
                public ComponentButton(String text, Icon enabled, Icon disabled) {
                        super();
-                       setLayout(new MigLayout("fill, flowy, insets 0, gap 0","",""));
+                       setLayout(new MigLayout("fill, flowy, insets 0, gap 0", "", ""));
                        
-                       add(new JLabel(),"push, sizegroup spacing");
+                       add(new JLabel(), "push, sizegroup spacing");
                        
                        // Add Icon
                        if (enabled != null) {
                                JLabel label = new JLabel(enabled);
                                if (disabled != null)
                                        label.setDisabledIcon(disabled);
-                               add(label,"growx");
+                               add(label, "growx");
                        }
-                               
+                       
                        // Add labels
                        String[] l = text.split("\n");
-                       for (int i=0; i<l.length; i++) {
-                               add(new StyledLabel(l[i],SwingConstants.CENTER,-3.0f),"growx");
+                       for (int i = 0; i < l.length; i++) {
+                               add(new StyledLabel(l[i], SwingConstants.CENTER, -3.0f), "growx");
                        }
                        
-                       add(new JLabel(),"push, sizegroup spacing");
+                       add(new JLabel(), "push, sizegroup spacing");
                        
-                       valueChanged(null);  // Update enabled status
+                       valueChanged(null); // Update enabled status
                        selectionModel.addTreeSelectionListener(this);
                }
-
+               
                
                /**
                 * Main constructor that should be used.  The generated component type is specified
                 * and the text.  The icons are fetched based on the component type.
                 */
                public ComponentButton(Class<? extends RocketComponent> c, String text) {
-                       this(text,ComponentIcons.getLargeIcon(c),ComponentIcons.getLargeDisabledIcon(c));
+                       this(text, ComponentIcons.getLargeIcon(c), ComponentIcons.getLargeDisabledIcon(c));
                        
-                       if (c==null)
+                       if (c == null)
                                return;
                        
-                       componentClass = c; 
-
+                       componentClass = c;
+                       
                        try {
                                constructor = c.getConstructor();
                        } catch (NoSuchMethodException e) {
-                               throw new IllegalArgumentException("Unable to get default "+
-                                               "constructor for class "+c,e);
+                               throw new IllegalArgumentException("Unable to get default " +
+                                               "constructor for class " + c, e);
                        }
                }
                
@@ -308,9 +307,9 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                 * c is null if there is no selection.  The default is to use c.isCompatible(class).
                 */
                public boolean isAddable(RocketComponent c) {
-                       if (c==null)
+                       if (c == null)
                                return false;
-                       if (componentClass==null)
+                       if (componentClass == null)
                                return false;
                        return c.isCompatible(componentClass);
                }
@@ -345,22 +344,22 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                public void setEnabled(boolean enabled) {
                        super.setEnabled(enabled);
                        Component[] c = getComponents();
-                       for (int i=0; i<c.length; i++)
+                       for (int i = 0; i < c.length; i++)
                                c[i].setEnabled(enabled);
                }
                
-
+               
                /**
                 * Update the enabled status of the button.
                 */
                private void updateEnabled() {
-                       RocketComponent c=null;
+                       RocketComponent c = null;
                        TreePath p = selectionModel.getSelectionPath();
-                       if (p!=null)
-                               c = (RocketComponent)p.getLastPathComponent();
+                       if (p != null)
+                               c = (RocketComponent) p.getLastPathComponent();
                        setEnabled(isAddable(c));
                }
-
+               
                
                @Override
                protected void fireActionPerformed(ActionEvent event) {
@@ -369,18 +368,18 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                        Integer position = null;
                        
                        TreePath p = selectionModel.getSelectionPath();
-                       if (p!= null)
-                               c = (RocketComponent)p.getLastPathComponent();
-
+                       if (p != null)
+                               c = (RocketComponent) p.getLastPathComponent();
+                       
                        Pair<RocketComponent, Integer> pos = getAdditionPosition(c);
-                       if (pos==null) {
+                       if (pos == null) {
                                // Cancel addition
                                return;
                        }
                        c = pos.getU();
                        position = pos.getV();
-
                        
+
                        if (c == null) {
                                // Should not occur
                                ExceptionHandler.handleErrorCondition("ERROR:  Could not place new component.");
@@ -395,13 +394,13 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                        
                        RocketComponent component;
                        try {
-                               component = (RocketComponent)constructor.newInstance();
+                               component = (RocketComponent) constructor.newInstance();
                        } catch (InstantiationException e) {
-                               throw new BugException("Could not construct new instance of class "+
-                                               constructor,e);
+                               throw new BugException("Could not construct new instance of class " +
+                                               constructor, e);
                        } catch (IllegalAccessException e) {
-                               throw new BugException("Could not construct new instance of class "+
-                                               constructor,e);
+                               throw new BugException("Could not construct new instance of class " +
+                                               constructor, e);
                        } catch (InvocationTargetException e) {
                                throw Reflection.handleWrappedException(e);
                        }
@@ -409,7 +408,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                        // Next undo position is set by opening the configuration dialog
                        document.addUndoPosition("Add " + component.getComponentName());
                        
-                       
+
                        if (position == null)
                                c.addChild(component);
                        else
@@ -419,14 +418,13 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                        selectionModel.setSelectionPath(ComponentTreeModel.makeTreePath(component));
                        
                        JFrame parent = null;
-                       for (Component comp = ComponentAddButtons.this; comp != null; 
-                                comp = comp.getParent()) {
+                       for (Component comp = ComponentAddButtons.this; comp != null; comp = comp.getParent()) {
                                if (comp instanceof JFrame) {
                                        parent = (JFrame) comp;
                                        break;
                                }
                        }
-                               
+                       
                        ComponentConfigDialog.showDialog(parent, document, component);
                }
        }
@@ -439,15 +437,15 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                public BodyComponentButton(Class<? extends RocketComponent> c, String text) {
                        super(c, text);
                }
-
+               
                public BodyComponentButton(String text, Icon enabled, Icon disabled) {
                        super(text, enabled, disabled);
                }
-
+               
                public BodyComponentButton(String text) {
                        super(text);
                }
-
+               
                @Override
                public boolean isAddable(RocketComponent c) {
                        if (super.isAddable(c))
@@ -462,28 +460,31 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                
                @Override
                public Pair<RocketComponent, Integer> getAdditionPosition(RocketComponent c) {
-                       if (super.isAddable(c))     // Handled automatically
+                       if (super.isAddable(c)) // Handled automatically
                                return super.getAdditionPosition(c);
                        
-                       
+
                        if (c == null || c instanceof Rocket) {
                                // Add as last body component of the last stage
                                Rocket rocket = document.getRocket();
-                               return new Pair<RocketComponent,Integer>(rocket.getChild(rocket.getStageCount()-1),
+                               return new Pair<RocketComponent, Integer>(rocket.getChild(rocket.getStageCount() - 1),
                                                null);
                        }
                        
                        if (!(c instanceof BodyComponent))
                                return null;
                        RocketComponent parent = c.getParent();
-                       assert(parent != null);
+                       if (parent == null) {
+                               throw new BugException("Component " + c.getComponentName() + " is the root component, " +
+                                               "componentClass=" + componentClass);
+                       }
                        
                        // Check whether to insert between or at the end.
                        // 0 = ask, 1 = in between, 2 = at the end
                        int pos = Prefs.getChoise(Prefs.BODY_COMPONENT_INSERT_POSITION_KEY, 2, 0);
-                       if (pos==0) {
-                               if (parent.getChildPosition(c) == parent.getChildCount()-1)
-                                       pos = 2;  // Selected component is the last component
+                       if (pos == 0) {
+                               if (parent.getChildPosition(c) == parent.getChildCount() - 1)
+                                       pos = 2; // Selected component is the last component
                                else
                                        pos = askPosition();
                        }
@@ -494,12 +495,12 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                                return null;
                        case 1:
                                // Insert after current position
-                               return new Pair<RocketComponent,Integer>(parent, parent.getChildPosition(c)+1);
+                               return new Pair<RocketComponent, Integer>(parent, parent.getChildPosition(c) + 1);
                        case 2:
                                // Insert at the end of the parent
-                               return new Pair<RocketComponent,Integer>(parent, null);
+                               return new Pair<RocketComponent, Integer>(parent, null);
                        default:
-                               ExceptionHandler.handleErrorCondition("ERROR:  Bad position type: "+pos);
+                               ExceptionHandler.handleErrorCondition("ERROR:  Bad position type: " + pos);
                                return null;
                        }
                }
@@ -509,22 +510,22 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                        
                        JPanel panel = new JPanel(new MigLayout());
                        JCheckBox check = new JCheckBox("Do not ask me again");
-                       panel.add(check,"wrap");
+                       panel.add(check, "wrap");
                        panel.add(new StyledLabel("You can change the default operation in the " +
-                                       "preferences.",-2));
+                                       "preferences.", -2));
                        
-                       int sel = JOptionPane.showOptionDialog(null,  // parent component 
+                       int sel = JOptionPane.showOptionDialog(null, // parent component 
                                        new Object[] {
-                                       "Insert the component after the current component or as the last " +
-                                       "component?",
-                                       panel },
-                                       "Select component position",   // title
-                                       JOptionPane.DEFAULT_OPTION,    // default selections
-                                       JOptionPane.QUESTION_MESSAGE,  // dialog type
-                                       null,         // icon
-                                       options,      // options
-                                       options[0]);  // initial value
-
+                                                       "Insert the component after the current component or as the last " +
+                                                                       "component?",
+                                                       panel },
+                                       "Select component position", // title
+                                       JOptionPane.DEFAULT_OPTION, // default selections
+                                       JOptionPane.QUESTION_MESSAGE, // dialog type
+                                       null, // icon
+                                       options, // options
+                                       options[0]); // initial value
+                       
                        switch (sel) {
                        case JOptionPane.CLOSED_OPTION:
                        case 2:
@@ -539,7 +540,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                                sel = 2;
                                break;
                        default:
-                               ExceptionHandler.handleErrorCondition("ERROR:  JOptionPane returned "+sel);
+                               ExceptionHandler.handleErrorCondition("ERROR:  JOptionPane returned " + sel);
                                return 0;
                        }
                        
@@ -552,7 +553,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                
        }
        
-
+       
 
        /**
         * Class for fin sets, that attach only to BodyTubes.
@@ -561,33 +562,33 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                public FinButton(Class<? extends RocketComponent> c, String text) {
                        super(c, text);
                }
-
+               
                public FinButton(String text, Icon enabled, Icon disabled) {
                        super(text, enabled, disabled);
                }
-
+               
                public FinButton(String text) {
                        super(text);
                }
-
+               
                @Override
                public boolean isAddable(RocketComponent c) {
-                       if (c==null)
+                       if (c == null)
                                return false;
                        return (c.getClass().equals(BodyTube.class));
                }
        }
-
-
        
-       /////////  Scrolling functionality
+       
 
+       /////////  Scrolling functionality
+       
        @Override
        public Dimension getPreferredScrollableViewportSize() {
                return getPreferredSize();
        }
-
-
+       
+       
        @Override
        public int getScrollableBlockIncrement(Rectangle visibleRect,
                        int orientation, int direction) {
@@ -595,20 +596,20 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
                        return visibleRect.height * 8 / 10;
                return 10;
        }
-
-
+       
+       
        @Override
        public boolean getScrollableTracksViewportHeight() {
                return false;
        }
-
-
+       
+       
        @Override
        public boolean getScrollableTracksViewportWidth() {
                return true;
        }
-
-
+       
+       
        @Override
        public int getScrollableUnitIncrement(Rectangle visibleRect,
                        int orientation, int direction) {
@@ -616,4 +617,3 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
        }
        
 }
-
index 50b3f2c5b101b21a25ca1f8d9d3202118edddf3f..c37ceef22d6b8ba9c05182a1e35b5a858ad515bf 100644 (file)
@@ -25,6 +25,7 @@ import javax.swing.JProgressBar;
 import net.miginfocom.swing.MigLayout;
 import net.sf.openrocket.document.Simulation;
 import net.sf.openrocket.gui.dialogs.DetailDialog;
+import net.sf.openrocket.logging.LogHelper;
 import net.sf.openrocket.rocketcomponent.Configuration;
 import net.sf.openrocket.rocketcomponent.MotorMount;
 import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent;
@@ -35,6 +36,7 @@ import net.sf.openrocket.simulation.exception.SimulationException;
 import net.sf.openrocket.simulation.exception.SimulationLaunchException;
 import net.sf.openrocket.simulation.listeners.AbstractSimulationListener;
 import net.sf.openrocket.simulation.listeners.SimulationListener;
+import net.sf.openrocket.startup.Application;
 import net.sf.openrocket.unit.Unit;
 import net.sf.openrocket.unit.UnitGroup;
 import net.sf.openrocket.util.GUIUtil;
@@ -43,6 +45,8 @@ import net.sf.openrocket.util.Prefs;
 
 
 public class SimulationRunDialog extends JDialog {
+       private static final LogHelper log = Application.getLogger();
+       
        /** Update the dialog status every this many ms */
        private static final long UPDATE_MS = 200;
        
@@ -174,7 +178,6 @@ public class SimulationRunDialog extends JDialog {
 
 
        private void updateProgress() {
-               System.out.println("updateProgress() called");
                int index;
                for (index = 0; index < simulations.length; index++) {
                        if (!simulationDone[index])
@@ -183,7 +186,7 @@ public class SimulationRunDialog extends JDialog {
                
                if (index >= simulations.length) {
                        // Everything is done, close the dialog
-                       System.out.println("Everything done.");
+                       log.debug("Everything done.");
                        this.dispose();
                        return;
                }
@@ -195,15 +198,15 @@ public class SimulationRunDialog extends JDialog {
                }
                progress /= simulationWorkers.length;
                progressBar.setValue(progress);
-               System.out.println("Progressbar value " + progress);
+               log.debug("Progressbar value " + progress);
                
                // Update the simulation fields
                simLabel.setText("Running " + simulations[index].getName());
                if (simulationStatuses[index] == null) {
+                       log.debug("No simulation status data available, setting empty labels");
                        timeLabel.setText("");
                        altLabel.setText("");
                        velLabel.setText("");
-                       System.out.println("Empty labels, how sad.");
                        return;
                }
                
@@ -217,7 +220,6 @@ public class SimulationRunDialog extends JDialog {
                u = UnitGroup.UNITS_VELOCITY.getDefaultUnit();
                velLabel.setText(u.toStringUnit(simulationStatuses[index].getRocketVelocity().z) + " (max. " +
                                u.toStringUnit(simulationMaxVelocity[index]) + ")");
-               System.out.println("Set interesting labels.");
        }
        
        
@@ -299,7 +301,7 @@ public class SimulationRunDialog extends JDialog {
                        
                        // 1. time = 0 ... burnoutTimeEstimate
                        if (simulationStage == -2 && status.getSimulationTime() < burnoutTimeEstimate) {
-                               System.out.println("Method 1:  t=" + status.getSimulationTime() + "  est=" + burnoutTimeEstimate);
+                               log.debug("Method 1:  t=" + status.getSimulationTime() + "  est=" + burnoutTimeEstimate);
                                setSimulationProgress(MathUtil.map(status.getSimulationTime(), 0, burnoutTimeEstimate,
                                                0.0, BURNOUT_PROGRESS));
                                updateProgress();
@@ -309,13 +311,12 @@ public class SimulationRunDialog extends JDialog {
                        if (simulationStage == -2) {
                                simulationStage++;
                                burnoutVelocity = MathUtil.max(status.getRocketVelocity().z, 0.1);
-                               System.out.println("CHANGING to Method 2, vel=" + burnoutVelocity);
+                               log.debug("CHANGING to Method 2, vel=" + burnoutVelocity);
                        }
                        
                        // 2. z-velocity from burnout velocity to zero
                        if (simulationStage == -1 && status.getRocketVelocity().z >= 0) {
-                               System.out.println("Method 2:  vel=" + status.getRocketVelocity().z + " burnout=" +
-                                               burnoutVelocity);
+                               log.debug("Method 2:  vel=" + status.getRocketVelocity().z + " burnout=" + burnoutVelocity);
                                setSimulationProgress(MathUtil.map(status.getRocketVelocity().z, burnoutVelocity, 0,
                                                BURNOUT_PROGRESS, APOGEE_PROGRESS));
                                updateProgress();
@@ -325,11 +326,12 @@ public class SimulationRunDialog extends JDialog {
                        if (simulationStage == -1 && status.getRocketVelocity().z < 0) {
                                simulationStage++;
                                apogeeAltitude = MathUtil.max(status.getRocketPosition().z, 1);
+                               log.debug("CHANGING to Method 3, apogee=" + apogeeAltitude);
                        }
                        
                        // 3. z-position from apogee to zero
                        // TODO: MEDIUM: several stages
-                       System.out.println("Method 3:  alt=" + status.getRocketPosition().z + "  apogee=" + apogeeAltitude);
+                       log.debug("Method 3:  alt=" + status.getRocketPosition().z + "  apogee=" + apogeeAltitude);
                        setSimulationProgress(MathUtil.map(status.getRocketPosition().z,
                                        apogeeAltitude, 0, APOGEE_PROGRESS, 1.0));
                        updateProgress();
@@ -341,7 +343,7 @@ public class SimulationRunDialog extends JDialog {
                @Override
                protected void simulationDone() {
                        simulationDone[index] = true;
-                       System.out.println("DONE, setting progress");
+                       log.debug("Simulation done");
                        setSimulationProgress(1.0);
                        updateProgress();
                }
@@ -425,10 +427,9 @@ public class SimulationRunDialog extends JDialog {
                
 
                private void setSimulationProgress(double p) {
-                       progress = Math.max(progress, (int) (100 * p + 0.5));
-                       progress = MathUtil.clamp(progress, 0, 100);
-                       System.out.println("Setting progress to " + progress + " (real " +
-                                       ((int) (100 * p + 0.5)) + ")");
+                       int exact = Math.max(progress, (int) (100 * p + 0.5));
+                       progress = MathUtil.clamp(exact, 0, 100);
+                       log.debug("Setting progress to " + progress + " (real " + exact + ")");
                        super.setProgress(progress);
                }
                
@@ -448,7 +449,7 @@ public class SimulationRunDialog extends JDialog {
                                case APOGEE:
                                        simulationStage = 0;
                                        apogeeAltitude = status.getRocketPosition().z;
-                                       System.out.println("APOGEE, setting progress");
+                                       log.debug("APOGEE, setting progress");
                                        setSimulationProgress(APOGEE_PROGRESS);
                                        publish(status);
                                        break;
@@ -458,7 +459,7 @@ public class SimulationRunDialog extends JDialog {
                                        break;
                                
                                case SIMULATION_END:
-                                       System.out.println("END, setting progress");
+                                       log.debug("END, setting progress");
                                        setSimulationProgress(1.0);
                                        break;
                                }
index 91b61ea2cbc5a46e0f370837fad1692c5f458263..c8ed58b9273e64e06434b5dd59d51ccdfd278212 100644 (file)
@@ -479,9 +479,7 @@ public class Prefs {
        ////  Background flight data computation
        
        public static boolean computeFlightInBackground() {
-               // TODO: CRITICAL: Revert 
-               return false;
-               //              return PREFNODE.getBoolean("backgroundFlight", true);
+               return PREFNODE.getBoolean("backgroundFlight", true);
        }
        
        public static Simulation getBackgroundSimulation(Rocket rocket) {
index 1260fa5abad097ea4e958f5d0d66ec2cae82c629..39e4777db1e1759c2dcab83d6042181c44451488 100644 (file)
@@ -7,7 +7,7 @@ import java.util.List;
 import org.junit.Test;
 
 public class LoggingTest {
-
+       
        @Test
        public void testLoggers() {
                // Ensure a sane stack trace
@@ -31,7 +31,7 @@ public class LoggingTest {
                List<LogLine> logs = log4.getLogs();
                assertEquals(4, logs.size());
                assertTrue(logs.get(0).toString(), logs.get(0).toString().matches(
-                               " *[0-9]+ +[0-9]+\\.[0-9]+ +DEBUG \\(LoggingTest.java:[0-9]+\\) two"));
+                               " *[0-9]+ +[0-9]+\\.[0-9]+ +DEBUG \\(-\\) two"));
                assertTrue(logs.get(1).toString(), logs.get(1).toString().matches(
                                " *[0-9]+ +[0-9]+\\.[0-9]+ +INFO  \\(LoggingTest.java:[0-9]+\\) three"));
                assertTrue(logs.get(2).toString(), logs.get(2).toString().matches(