12.8.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 16279b58 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Fix #57 Wrong scaling of the TopographyWindow

The ScenarioPanel recreates the TopograpyWindow (view) each time a new
selection on the left is triggered. Within the recreation a new thread
recreated the view but was not synchronized to accept a
ChangeViewPortEvent for resizing.

The PostvisualizationWindow had the same issue.
parent ed9c3ccb
......@@ -73,9 +73,13 @@ public interface IDefaultModel<T extends DefaultConfig> extends Iterable<Scenari
*/
void setViewportBound(final Rectangle2D.Double viewportBound);
/**
* resets the scenarioSize to the original scenario size.
*/
void resetTopographySize();
/**
*
* @param viewportBound
*/
void fireChangeViewportEvent(final Rectangle2D.Double viewportBound);
......@@ -89,8 +93,7 @@ public interface IDefaultModel<T extends DefaultConfig> extends Iterable<Scenari
/**
* Sets the window bound.
*
* @param windowBound
*
*/
void setWindowBound(final Rectangle2D.Double windowBound);
......@@ -103,8 +106,7 @@ public interface IDefaultModel<T extends DefaultConfig> extends Iterable<Scenari
/**
* Tells the model that a element has been changed.
*
* @param element
*
*/
void setElementHasChanged(final ScenarioElement element);
......
......@@ -6,11 +6,13 @@ import java.util.function.Function;
import org.vadere.state.scenario.Agent;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
public abstract class SimulationModel<T extends DefaultSimulationConfig> extends DefaultModel {
public final T config;
@SuppressWarnings("unchecked")
public SimulationModel(final T config) {
super(config);
this.config = config;
......@@ -26,6 +28,11 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends
public abstract boolean isFloorFieldAvailable();
@Override
public void resetTopographySize() {
fireChangeViewportEvent(new VRectangle(getTopographyBound()));
}
public T getConfig() {
return config;
}
......
......@@ -7,6 +7,7 @@ import org.vadere.gui.components.control.IViewportChangeListener;
import org.vadere.gui.components.control.JViewportChangeListener;
import org.vadere.gui.components.control.PanelResizeListener;
import org.vadere.gui.components.control.ViewportChangeListener;
import org.vadere.gui.components.model.IDefaultModel;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.utils.Resources;
import org.vadere.gui.components.utils.SwingUtils;
......@@ -29,6 +30,7 @@ import org.vadere.gui.projectview.control.ActionDeselect;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.io.HashGenerator;
import org.vadere.simulator.projects.io.IOOutput;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.io.IOUtils;
import java.awt.*;
......@@ -63,7 +65,7 @@ public class PostvisualizationWindow extends JPanel implements Observer {
this(false, projectPath);
}
public PostvisualizationWindow(final boolean loadTopographyInformationsOnly, final String projectPath) {
private PostvisualizationWindow(final boolean loadTopographyInformationsOnly, final String projectPath) {
// 1. get data from the user screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
......@@ -137,16 +139,13 @@ public class PostvisualizationWindow extends JPanel implements Observer {
final String test = java.text.MessageFormat.format(Messages.getString("PostVis.about.text"), "0.1");
JButton infoButton = new JButton(new ImageIcon(Resources.class.getResource("/icons/info_icon.png")));
infoButton.setBorderPainted(false);
infoButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String text = "<html><font size =\"5\"><b>"+Messages.getString("PostVis.title") + "</font></b><br>" +
"<font size =\"3\"><em>" + MessageFormat.format(Messages.getString("PostVis.version"), HashGenerator.releaseNumber()) + "</em></font><br>" +
"<font size =\"3\">" + MessageFormat.format(Messages.getString("PostVis.license.text"), "<a href=\"https://www.gnu.org/licenses/lgpl-3.0.txt\">LGPL</a>")+".</font></html>";
JOptionPane.showMessageDialog(null, text,
Messages.getString("PostVis.about.title"),
JOptionPane.INFORMATION_MESSAGE);
}
infoButton.addActionListener(e -> {
String text = "<html><font size =\"5\"><b>"+Messages.getString("PostVis.title") + "</font></b><br>" +
"<font size =\"3\"><em>" + MessageFormat.format(Messages.getString("PostVis.version"), HashGenerator.releaseNumber()) + "</em></font><br>" +
"<font size =\"3\">" + MessageFormat.format(Messages.getString("PostVis.license.text"), "<a href=\"https://www.gnu.org/licenses/lgpl-3.0.txt\">LGPL</a>")+".</font></html>";
JOptionPane.showMessageDialog(null, text,
Messages.getString("PostVis.about.title"),
JOptionPane.INFORMATION_MESSAGE);
});
/*
......@@ -178,7 +177,6 @@ public class PostvisualizationWindow extends JPanel implements Observer {
model.notifyObservers();
}
;
}, "View.btnShowPedestrian.tooltip");
addActionToToolbar(toolbar,
......@@ -190,7 +188,7 @@ public class PostvisualizationWindow extends JPanel implements Observer {
model.notifyObservers();
}
;
}, "View.btnShowTrajectories.tooltip");
addActionToToolbar(toolbar,
......@@ -202,7 +200,7 @@ public class PostvisualizationWindow extends JPanel implements Observer {
model.notifyObservers();
}
;
}, "View.btnShowWalkingDirection.tooltip");
addActionToToolbar(toolbar,
......@@ -226,7 +224,7 @@ public class PostvisualizationWindow extends JPanel implements Observer {
model.notifyObservers();
}
;
}, "View.btnShowGrid.tooltip");
addActionToToolbar(
......@@ -239,7 +237,7 @@ public class PostvisualizationWindow extends JPanel implements Observer {
model.notifyObservers();
}
;
}, "View.btnShowDensity.tooltip");
......@@ -312,12 +310,7 @@ public class PostvisualizationWindow extends JPanel implements Observer {
}
miGlobalSettings.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DialogFactory.createSettingsDialog(model).setVisible(true);
}
});
miGlobalSettings.addActionListener(e -> DialogFactory.createSettingsDialog(model).setVisible(true));
mFile.add(miLoadFile);
// mFile.add(miLoadFloorFile);
......@@ -333,7 +326,7 @@ public class PostvisualizationWindow extends JPanel implements Observer {
getActionMap().put("deselect", new ActionDeselect(model, this, null));
}
public JMenuBar getMenu() {
private JMenuBar getMenu() {
return menuBar;
}
......@@ -343,7 +336,7 @@ public class PostvisualizationWindow extends JPanel implements Observer {
model.notifyObservers();
}
public void loadOutputFile(final Scenario scenario) throws IOException {
public void loadOutputFile(final Scenario scenario) {
Player.getInstance(model).stop();
model.init(scenario, model.getOutputPath());
model.notifyObservers();
......@@ -354,6 +347,10 @@ public class PostvisualizationWindow extends JPanel implements Observer {
return SwingUtils.addActionToToolbar(toolbar, action, Messages.getString(toolTipProperty));
}
public IDefaultModel getDefaultModel(){
return this.model;
}
@Override
public void update(java.util.Observable o, Object arg) {
......
......@@ -232,8 +232,10 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
topographyCreatorView = new TopographyWindow(scenario);
tabbedPane.addTab(Messages.getString("Tab.TopographyCreator.title"), topographyCreatorView);
setTopography(scenario.getTopography());
tabbedPane.validate();
tabbedPane.repaint();
tabbedPane.setSelectedIndex(index);
setTopography(scenario.getTopography());
} catch (IOException | IntrospectionException e) {
e.printStackTrace();
......@@ -252,7 +254,11 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
tabbedPane.setSelectedComponent(postVisualizationView);
}
}
tabbedPane.validate();
tabbedPane.repaint();
postVisualizationView.revalidate();
postVisualizationView.repaint(); // force a repaint, otherwise it sometimes only repaints when the mouse moves from the output table to the postvis-view
postVisualizationView.getDefaultModel().resetTopographySize();
}
this.attributesModelView.setVadereScenario(scenario);
......
......@@ -34,7 +34,7 @@ public interface IDrawPanelModel<T extends DefaultConfig> extends IDefaultModel<
/**
* Part of the observer-pattern. Adds an observer that will be notified about the changes of
* this panelModel.
*
*
* @param observer the observer that will be notified about the change of this panelModel.
*/
void addObserver(Observer observer);
......@@ -83,10 +83,6 @@ public interface IDrawPanelModel<T extends DefaultConfig> extends IDefaultModel<
@Override
void hideSelection();
/**
* resets the scenarioSize to the original scenario size.
*/
void resetTopographySize();
/**
* cleans the whole topography, after this call there is no topography element in the topography
......
Markdown is supported
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