Commit 6f32aad9 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Merge branch 'issue_280_gui_nullpointer' into 'master'

fix #280 nullpointer in gui while simulation setup

Closes #280

See merge request !93
parents 801b7818 417627d4
Pipeline #186183 failed with stages
in 92 minutes and 19 seconds
...@@ -9,7 +9,6 @@ import org.vadere.gui.components.view.ISelectScenarioElementListener; ...@@ -9,7 +9,6 @@ import org.vadere.gui.components.view.ISelectScenarioElementListener;
import org.vadere.state.scenario.ScenarioElement; import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.types.ScenarioElementType; import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VPolygon;
import org.vadere.util.geometry.shapes.VShape; import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.logging.Logger; import org.vadere.util.logging.Logger;
import org.vadere.util.voronoi.VoronoiDiagram; import org.vadere.util.voronoi.VoronoiDiagram;
......
package org.vadere.gui.onlinevisualization; package org.vadere.gui.onlinevisualization;
import javax.swing.JPanel;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel; import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel;
...@@ -93,6 +91,15 @@ public class OnlineVisualization implements PassiveCallback { ...@@ -93,6 +91,15 @@ public class OnlineVisualization implements PassiveCallback {
@Override @Override
public void preLoop(double simTimeInSec) { public void preLoop(double simTimeInSec) {
// [issue 280] ensure OnlineVisualisation model is completely setup before
// OnlineVisualisation renderer is initialized in window.preLoop()
// push pop DrawData once at the beginning. This will completely initialize the model
// (i.e. set Topography to correct value. Before this call it is null....)
pushDrawData(simTimeInSec);
model.popDrawData();
// [issue 280] activate mouse listeners to allow zoom action in OnlineVisualisation
window.addListener();
onlineVisualisationPanel.setVisible(this.enableVisualization); onlineVisualisationPanel.setVisible(this.enableVisualization);
window.preLoop(); window.preLoop();
} }
...@@ -101,6 +108,9 @@ public class OnlineVisualization implements PassiveCallback { ...@@ -101,6 +108,9 @@ public class OnlineVisualization implements PassiveCallback {
public void postLoop(double simTimeInSec) { public void postLoop(double simTimeInSec) {
onlineVisualisationPanel.setVisible(false); onlineVisualisationPanel.setVisible(false);
model.reset(); model.reset();
// [issue 280] deactivate mouse listeners because model is not valid anymore
window.removeListeners();
} }
@Override @Override
...@@ -142,7 +152,17 @@ public class OnlineVisualization implements PassiveCallback { ...@@ -142,7 +152,17 @@ public class OnlineVisualization implements PassiveCallback {
} }
public JPanel getVisualizationPanel() { // [issue 280] show OnlineVisualization Window and remove mouse Listeners. This is necessary to ensure
// that no null pointer exception is thrown in the awt thread due to not completely
// initialized OnlineVisualisation model. A better fix would be to only initialize the
// OnlineVisualisation AFTER the model is loaded completely but this would need more changes
// in the gui setup.
public void showVisualization(){
window.setVisible(true);
window.removeListeners();
}
public OnlineVisualisationWindow getVisualizationPanel() {
return onlineVisualisationPanel; return onlineVisualisationPanel;
} }
......
package org.vadere.gui.onlinevisualization.view; package org.vadere.gui.onlinevisualization.view;
import java.util.*;
import org.vadere.gui.components.control.IMode; import org.vadere.gui.components.control.IMode;
import org.vadere.gui.components.control.RectangleSelectionMode;
import org.vadere.gui.components.utils.Resources; import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.components.view.ScaleablePanel; import org.vadere.gui.components.view.ScaleablePanel;
import org.vadere.gui.onlinevisualization.control.OnlineVisSelectionMode; import org.vadere.gui.onlinevisualization.control.OnlineVisSelectionMode;
import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel; import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
/** /**
* Main panel of the visualization window, used to display the simulation * Main panel of the visualization window, used to display the simulation
...@@ -31,7 +33,8 @@ public class MainPanel extends ScaleablePanel implements Observer { ...@@ -31,7 +33,8 @@ public class MainPanel extends ScaleablePanel implements Observer {
private final OnlineVisualizationModel model; private final OnlineVisualizationModel model;
private List<IRendererChangeListener> rendererChangeListeners; private List<IRendererChangeListener> rendererChangeListeners;
private static Resources resources = Resources.getInstance("global"); private static Resources resources = Resources.getInstance("global");
private IMode selectionMode = null; private IMode selectionMode;
/** Creates a new main panel. */ /** Creates a new main panel. */
public MainPanel(final OnlineVisualizationModel model) { public MainPanel(final OnlineVisualizationModel model) {
...@@ -39,12 +42,31 @@ public class MainPanel extends ScaleablePanel implements Observer { ...@@ -39,12 +42,31 @@ public class MainPanel extends ScaleablePanel implements Observer {
this.model = model; this.model = model;
this.rendererChangeListeners = new ArrayList<>(); this.rendererChangeListeners = new ArrayList<>();
RectangleSelectionMode selectionMode = new OnlineVisSelectionMode(model); this.selectionMode = new OnlineVisSelectionMode(model);
addMouseListener(selectionMode); addMouseListener(selectionMode);
addMouseMotionListener(selectionMode); addMouseMotionListener(selectionMode);
addMouseWheelListener(selectionMode); addMouseWheelListener(selectionMode);
} }
// [issue 280] remove listener if model is not valid.
public void addListener(){
if (selectionMode == null)
selectionMode = new OnlineVisSelectionMode(model);
addMouseListener(selectionMode);
addMouseMotionListener(selectionMode);
addMouseWheelListener(selectionMode);
}
// [issue 280] add listener if model is valid.
public void removeListeners(){
if (selectionMode != null){
removeMouseListener(this.selectionMode);
removeMouseMotionListener(this.selectionMode);
removeMouseWheelListener(this.selectionMode);
}
}
public void addRendererChangeListener(final IRendererChangeListener listener) { public void addRendererChangeListener(final IRendererChangeListener listener) {
rendererChangeListeners.add(listener); rendererChangeListeners.add(listener);
} }
......
...@@ -40,12 +40,20 @@ public class OnlineVisualisationWindow extends JPanel implements Observer { ...@@ -40,12 +40,20 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
private static final long serialVersionUID = 3522170593760789565L; private static final long serialVersionUID = 3522170593760789565L;
private static final Resources resources = Resources.getInstance("global"); private static final Resources resources = Resources.getInstance("global");
private static final Configuration CONFIG = VadereConfig.getConfig(); private ScenarioElementView jsonPanel; private static final Configuration CONFIG = VadereConfig.getConfig();
private JToolBar toolbar;
private SimulationInfoPanel infoPanel; private JToolBar toolbar; // top
private SimulationInfoPanel infoPanel; // footer
private JScrollPane scenarioScrollPane; // left
private ScenarioElementView jsonPanel; // right
private JSplitPane splitPaneForTopographyAndJsonPane; // container left/right
private MainPanel mainPanel;
private OnlineVisualizationModel model;
public OnlineVisualisationWindow(final MainPanel mainPanel, final OnlineVisualizationModel model) { public OnlineVisualisationWindow(final MainPanel mainPanel, final OnlineVisualizationModel model) {
this.mainPanel = mainPanel;
this.model = model;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int windowHeight = screenSize.height - 250; int windowHeight = screenSize.height - 250;
...@@ -53,15 +61,15 @@ public class OnlineVisualisationWindow extends JPanel implements Observer { ...@@ -53,15 +61,15 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
FormLayout spiltLayout = new FormLayout("2dlu, default:grow(0.75), 2dlu, default:grow(0.25), 2dlu", // col FormLayout spiltLayout = new FormLayout("2dlu, default:grow(0.75), 2dlu, default:grow(0.25), 2dlu", // col
"2dlu, default, 2dlu, fill:default:grow, 2dlu, default, 2dlu"); // rows "2dlu, default, 2dlu, fill:default:grow, 2dlu, default, 2dlu"); // rows
JScrollPane scrollPane = new ScenarioScrollPane(mainPanel, model); scenarioScrollPane = new ScenarioScrollPane(mainPanel, model);
model.addScaleChangeListener(mainPanel); model.addScaleChangeListener(mainPanel);
mainPanel.addComponentListener(new PanelResizeListener(model)); mainPanel.addComponentListener(new PanelResizeListener(model));
mainPanel.setScrollPane(scrollPane); mainPanel.setScrollPane(scenarioScrollPane);
scrollPane.getViewport() scenarioScrollPane.getViewport()
.addChangeListener(new JViewportChangeListener(model, scrollPane.getVerticalScrollBar())); .addChangeListener(new JViewportChangeListener(model, scenarioScrollPane.getVerticalScrollBar()));
model.addScrollPane(scrollPane); model.addScrollPane(scenarioScrollPane);
IViewportChangeListener viewportChangeListener = new ViewportChangeListener(model, scrollPane); IViewportChangeListener viewportChangeListener = new ViewportChangeListener(model, scenarioScrollPane);
model.addViewportChangeListener(viewportChangeListener); model.addViewportChangeListener(viewportChangeListener);
jsonPanel = new ScenarioElementView(model); jsonPanel = new ScenarioElementView(model);
...@@ -256,13 +264,13 @@ public class OnlineVisualisationWindow extends JPanel implements Observer { ...@@ -256,13 +264,13 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
SwingUtils.addActionToToolbar(toolbar, openSettingsDialog, SwingUtils.addActionToToolbar(toolbar, openSettingsDialog,
Messages.getString("ProjectView.btnSettings.tooltip")); Messages.getString("ProjectView.btnSettings.tooltip"));
JSplitPane splitPaneForTopographyAndJsonPane = new JSplitPane(); splitPaneForTopographyAndJsonPane = new JSplitPane();
splitPaneForTopographyAndJsonPane.setResizeWeight(0.8); splitPaneForTopographyAndJsonPane.setResizeWeight(0.8);
splitPaneForTopographyAndJsonPane.resetToPreferredSizes(); splitPaneForTopographyAndJsonPane.resetToPreferredSizes();
splitPaneForTopographyAndJsonPane.setLeftComponent(scrollPane); splitPaneForTopographyAndJsonPane.setLeftComponent(scenarioScrollPane);
splitPaneForTopographyAndJsonPane.setRightComponent(jsonPanel); splitPaneForTopographyAndJsonPane.setRightComponent(jsonPanel);
scrollPane.setPreferredSize(new Dimension(1, windowHeight)); scenarioScrollPane.setPreferredSize(new Dimension(1, windowHeight));
add(toolbar, cc.xyw(2, 2, 3)); add(toolbar, cc.xyw(2, 2, 3));
add(splitPaneForTopographyAndJsonPane, cc.xywh(2, 4, 4, 1)); add(splitPaneForTopographyAndJsonPane, cc.xywh(2, 4, 4, 1));
......
...@@ -219,7 +219,9 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro ...@@ -219,7 +219,9 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
public void showVisualization() { public void showVisualization() {
CardLayout cl = (CardLayout) this.getLayout(); CardLayout cl = (CardLayout) this.getLayout();
cl.show(this, visualizationCardName); cl.show(this, visualizationCardName);
onlineVisualization.getMainPanel().setVisible(true); // [issue 280] set visibility and remove mouse listeners during setup. Will be added
// after setup of simulation run is complete.
onlineVisualization.showVisualization();
} }
public void showEditScenario() { public void showEditScenario() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment