Commit 7e04cf21 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

group image creation buttons in online- and postvis

parent c8667eba
Pipeline #58386 passed with stage
in 48 seconds
......@@ -217,6 +217,7 @@ PostVis.chbShowObstacles.text=Show Obstacles
PostVis.chbShowTargets.text=Show Targets
PostVis.chbShowSources.text=Show Sources
PostVis.chbShowStairs.text=Show Stairs
PostVis.btnSnapshot.tooltip=Snapshot
PostVis.btnPNGSnapshot.tooltip=PNG Snapshot
PostVis.btnSVGSnapshot.tooltip=SVG Snapshot
PostVis.menuFile.title=File
......
......@@ -217,6 +217,7 @@ PostVis.chbShowObstacles.text=Hindernisse anzeigen
PostVis.chbShowTargets.text=Ziele anzeigen
PostVis.chbShowSources.text=Quellen anzeigen
PostVis.chbShowStairs.text=Treppen anzeigen
PostVis.btnSnapshot.tooltip=Snapshot
PostVis.btnPNGSnapshot.tooltip=PNG-Snapshot
PostVis.btnSVGSnapshot.tooltip=SVG-Snapshot
PostVis.menuFile.title=Datei
......
package org.vadere.gui.onlinevisualization.control;
import org.vadere.gui.postvisualization.control.ActionVisualization;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.List;
import javax.swing.*;
public class ActionOnlineVisMenu extends AbstractAction {
private final List<Action> actions;
private JPopupMenu menu;
private Component parent;
public ActionOnlineVisMenu(final String name, Icon icon, final List<Action> actions) {
super(name, icon);
this.actions = actions;
}
public void setParent(Component parent) {
this.parent = parent;
}
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (menu == null) {
menu = new JPopupMenu();
for (Action action : actions) {
menu.add(action);
}
}
menu.show(parent, 0, parent.getHeight());
}
});
}
}
......@@ -3,8 +3,6 @@ package org.vadere.gui.onlinevisualization.view;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import javax.swing.*;
import org.vadere.gui.components.control.IViewportChangeListener;
import org.vadere.gui.components.control.JViewportChangeListener;
import org.vadere.gui.components.control.PanelResizeListener;
......@@ -17,14 +15,18 @@ import org.vadere.gui.components.view.ScenarioScrollPane;
import org.vadere.gui.components.view.SimulationInfoPanel;
import org.vadere.gui.onlinevisualization.control.ActionGeneratePNG;
import org.vadere.gui.onlinevisualization.control.ActionGenerateSVG;
import org.vadere.gui.onlinevisualization.control.ActionOnlineVisMenu;
import org.vadere.gui.onlinevisualization.control.ActionShowPotentialField;
import org.vadere.gui.onlinevisualization.model.OnlineVisualizationModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import javax.swing.*;
public class OnlineVisualisationWindow extends JPanel implements Observer {
private static final long serialVersionUID = 3522170593760789565L;
......@@ -185,8 +187,17 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
toolbar.addSeparator();
SwingUtils.addActionToToolbar(toolbar, generatePNG, Messages.getString("PostVis.btnPNGSnapshot.tooltip"));
SwingUtils.addActionToToolbar(toolbar, generateSVG, Messages.getString("PostVis.btnSVGSnapshot.tooltip"));
ArrayList<Action> imgOptions = new ArrayList<>();
imgOptions.add(generatePNG);
imgOptions.add(generateSVG);
ActionOnlineVisMenu imgDialog = new ActionOnlineVisMenu(
"camera_menu",
resources.getIcon("camera.png", iconWidth, iconHeight), imgOptions);
JButton imgMenuBtn =
SwingUtils.addActionToToolbar(toolbar, imgDialog, "PostVis.btnSnapshot.tooltip");
imgDialog.setParent(imgMenuBtn);
SwingUtils.addActionToToolbar(toolbar, showPotentialField, Messages.getString("OnlineVis.btnShowPotentialfield.tooltip"));
add(toolbar, cc.xyw(2, 2, 3));
......@@ -194,6 +205,9 @@ public class OnlineVisualisationWindow extends JPanel implements Observer {
scrollPane.setPreferredSize(new Dimension(1, windowHeight));
add(jsonPanel, cc.xy(4, 4));
add(infoPanel, cc.xyw(2, 6, 3));
repaint();
revalidate();
}
@Override
......
package org.vadere.gui.postvisualization.control;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.List;
import javax.swing.*;
public class ActionVisualizationMenu extends ActionVisualization {
private final List<Action> actions;
private JPopupMenu menu;
private Component parent;
private final ActionVisualization action;
public ActionVisualizationMenu(String name, Icon icon, PostvisualizationModel model,
final ActionVisualization action,
final List<Action> actions) {
super(name, icon, model);
this.action = action;
this.actions = actions;
}
public ActionVisualizationMenu(String name, PostvisualizationModel model,
final ActionVisualization action,
final List<Action> actions) {
super(name, model);
this.action = action;
this.actions = actions;
}
public void setParent(Component parent) {
this.parent = parent;
}
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (menu == null) {
menu = new JPopupMenu();
for (Action action : actions) {
menu.add(action);
}
}
menu.show(parent, 0, parent.getHeight());
}
});
// action.actionPerformed(e);
}
}
......@@ -24,21 +24,21 @@ import org.vadere.gui.postvisualization.control.ActionShowPotentialField;
import org.vadere.gui.postvisualization.control.ActionStop;
import org.vadere.gui.postvisualization.control.ActionSwapSelectionMode;
import org.vadere.gui.postvisualization.control.ActionVisualization;
import org.vadere.gui.postvisualization.control.ActionVisualizationMenu;
import org.vadere.gui.postvisualization.control.Player;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
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.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Observer;
import java.util.prefs.Preferences;
......@@ -260,16 +260,22 @@ public class PostvisualizationWindow extends JPanel implements Observer {
recordAction.setButton(recordButton);
toolbar.addSeparator(new Dimension(5, 50));
addActionToToolbar(
toolbar,
new ActionGeneratePNG("png_snapshot", resources.getIcon("camera_png.png", iconWidth, iconHeight),
renderer),
"PostVis.btnPNGSnapshot.tooltip");
addActionToToolbar(
toolbar,
new ActionGenerateSVG("svg_snapshot", resources.getIcon("camera_svg.png", iconWidth, iconHeight),
renderer),
"PostVis.btnSVGSnapshot.tooltip");
ArrayList<Action> imgOptions = new ArrayList<>();
ActionVisualization pngImg = new ActionGeneratePNG(Messages.getString("PostVis.btnPNGSnapshot.tooltip"), resources.getIcon("camera_png.png", iconWidth, iconHeight),
renderer);
ActionVisualization svgImg = new ActionGenerateSVG(Messages.getString("PostVis.btnSVGSnapshot.tooltip"), resources.getIcon("camera_svg.png", iconWidth, iconHeight),
renderer);
// add new ImageGenerator Action ...
imgOptions.add(pngImg);
imgOptions.add(svgImg);
// add Action to List ....
ActionVisualizationMenu imgDialog = new ActionVisualizationMenu(
"camera_menu",
resources.getIcon("camera.png", iconWidth, iconHeight),
model, null, imgOptions);
addActionMenuToToolbar(toolbar, imgDialog, Messages.getString("PostVis.btnSnapshot.tooltip"));
toolbar.addSeparator(new Dimension(5, 50));
......@@ -335,6 +341,8 @@ public class PostvisualizationWindow extends JPanel implements Observer {
// deselect selected element on esc
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "deselect");
getActionMap().put("deselect", new ActionDeselect(model, this, null));
repaint();
revalidate();
}
private JMenuBar getMenu() {
......@@ -359,6 +367,13 @@ public class PostvisualizationWindow extends JPanel implements Observer {
return SwingUtils.addActionToToolbar(toolbar, action, Messages.getString(toolTipProperty));
}
private static JButton addActionMenuToToolbar(final JToolBar toolbar, final ActionVisualizationMenu menuAction,
final String toolTipProperty) {
JButton btn = SwingUtils.addActionToToolbar(toolbar, menuAction, Messages.getString(toolTipProperty));
menuAction.setParent(btn);
return btn;
}
public IDefaultModel getDefaultModel(){
return this.model;
}
......
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