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

Commit 50d9ef0d authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

fix problems with the output processor view - expert view

parent 81dd0f86
...@@ -173,20 +173,6 @@ ...@@ -173,20 +173,6 @@
}, { }, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianSourceIdProcessor", "type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianSourceIdProcessor",
"id": 19 "id": 19
}, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.FloorFieldGridProcessor",
"id": 20,
"attributesType": "org.vadere.state.attributes.processor.AttributesFloorFieldProcessor",
"attributes": {
"targetId": 1
}
}, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.FloorFieldProcessor",
"id": 21,
"attributesType": "org.vadere.state.attributes.processor.AttributesFloorFieldProcessor",
"attributes": {
"targetId": 1
}
} ], } ],
"isTimestamped": true "isTimestamped": true
} }
...@@ -104,7 +104,7 @@ public class ActionLoadProject extends AbstractAction { ...@@ -104,7 +104,7 @@ public class ActionLoadProject extends AbstractAction {
projectViewModel.setProject(project); projectViewModel.setProject(project);
projectViewModel.refreshOutputTable(); projectViewModel.refreshOutputTable();
logger.info("refreshed output table"); logger.info("refreshed output table - 2");
// select and load first scenario from list // select and load first scenario from list
projectViewModel.setSelectedRowIndexInScenarioTable(0); projectViewModel.setSelectedRowIndexInScenarioTable(0);
......
...@@ -135,7 +135,7 @@ public class ClassFinder { ...@@ -135,7 +135,7 @@ public class ClassFinder {
* Scans all classes accessible from the context class loader which belong to the given package * Scans all classes accessible from the context class loader which belong to the given package
* and subpackages. * and subpackages.
* *
* Deprecated since this method does not work inside a jar file! * Deprecated since this method is slow if we have to access jar file, which is the case if we execute the project via vadere.jar!
* *
* @param packageName The base package * @param packageName The base package
* @return The classes * @return The classes
...@@ -184,52 +184,6 @@ public class ClassFinder { ...@@ -184,52 +184,6 @@ public class ClassFinder {
return classes; return classes;
} }
/**
* Scans all classes accessible from the context class loader which belong to the given package
* and subpackages. Works inside a jar file.
*
*
* @param packageName The base package
* @return The classes
* @throws ClassNotFoundException
* @throws IOException
*/
private static List<Class<?>> getClassesStream(String packageName) throws ClassNotFoundException, IOException {
List<Class<?>> classes = new ArrayList<>();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
String path = packageName.replace('.', '/');
List<String> resources = new ArrayList<>();
LinkedList<String> dirs = new LinkedList<>();
dirs.add(path);
log.info(ClassFinder.class.forName(AttributesBHM.class.getName()));
while(!dirs.isEmpty()) {
String currentDir = dirs.removeFirst();
String currentPackage = currentDir.replace('/', '.');
InputStream in = ClassFinder.class.getResourceAsStream("/" + currentDir);
BufferedReader rdr = new BufferedReader(new InputStreamReader(in));
String line; // line is either a .class file or a directory containing .class files or other directories
while ((line = rdr.readLine()) != null) {
// line is a filenamew
if(line.endsWith(".class")) {
classes.add(ClassFinder.class.forName(currentPackage + '.' + line.substring(0, line.length() - 6)));
}
else {
dirs.add(currentDir+'/'+line);
}
}
rdr.close();
}
return classes;
}
/** /**
* Recursive method used to find all classes in a given directory and subdirs. * Recursive method used to find all classes in a given directory and subdirs.
* *
......
...@@ -109,7 +109,6 @@ class DataProcessingView extends JPanel implements IJsonView { ...@@ -109,7 +109,6 @@ class DataProcessingView extends JPanel implements IJsonView {
JPanel togglePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JPanel togglePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
togglePanel.add(switchJsonViewModeLabel); togglePanel.add(switchJsonViewModeLabel);
add(togglePanel, BorderLayout.SOUTH); add(togglePanel, BorderLayout.SOUTH);
switchMode(); switchMode();
} }
...@@ -119,24 +118,27 @@ class DataProcessingView extends JPanel implements IJsonView { ...@@ -119,24 +118,27 @@ class DataProcessingView extends JPanel implements IJsonView {
+ "</b> mode</u></font></span></html>"); + "</b> mode</u></font></span></html>");
Preferences.userNodeForPackage(DataProcessingView.class).put("dataProcessingViewMode", Preferences.userNodeForPackage(DataProcessingView.class).put("dataProcessingViewMode",
inGuiViewMode ? guiViewMode : jsonViewMode); inGuiViewMode ? guiViewMode : jsonViewMode);
viewPanel.removeAll(); viewPanel.removeAll();
if (inGuiViewMode) { if (inGuiViewMode) {
logger.info("switch to gui view");
GuiView guiView = new GuiView(); GuiView guiView = new GuiView();
activeJsonView = guiView; activeJsonView = guiView;
viewPanel.add(guiView); viewPanel.add(guiView);
} else { } else {
logger.info("switch to expert view");
TextView expertView = buildExpertView(); TextView expertView = buildExpertView();
activeJsonView = expertView; activeJsonView = expertView;
viewPanel.add(expertView); viewPanel.add(expertView);
} }
if (currentScenario != null) { if (currentScenario != null) {
activeJsonView.setVadereScenario(currentScenario); activeJsonView.setVadereScenario(currentScenario);
activeJsonView.isEditable(isEditable); activeJsonView.isEditable(isEditable);
} }
revalidate(); revalidate();
repaint(); repaint();
} }
...@@ -145,36 +147,34 @@ class DataProcessingView extends JPanel implements IJsonView { ...@@ -145,36 +147,34 @@ class DataProcessingView extends JPanel implements IJsonView {
private TextView buildExpertView() { private TextView buildExpertView() {
TextView panel = new TextView("/" + IOUtils.OUTPUT_DIR, "default_directory_outputprocessors", AttributeType.OUTPUTPROCESSOR); TextView panel = new TextView("/" + IOUtils.OUTPUT_DIR, "default_directory_outputprocessors", AttributeType.OUTPUTPROCESSOR);
JMenuBar processorsMenuBar = new JMenuBar(); JMenuBar processorsMenuBar = new JMenuBar();
processorsMenu = new JMenu(Messages.getString("Tab.Model.loadTemplateMenu.title")); processorsMenu = new JMenu(Messages.getString("Tab.Model.loadTemplateMenu.title"));
processorsMenu.setEnabled(isEditable); processorsMenu.setEnabled(isEditable);
processorsMenuBar.add(processorsMenu); processorsMenuBar.add(processorsMenu);
try { try {
File[] templateFiles = new File(this.getClass().getResource("/outputTemplates/").getPath()).listFiles(); //TODO [bug, jar]: the file name is hard coded and it is not possible to add more presets! This is because listFile() does not work inside a jar.
for (File templateFile : Arrays.stream(templateFiles).filter(File::isFile).collect(Collectors.toList())) { String fileName = "output_default";
String templateFileName = templateFile.getName(); String templateJson = org.apache.commons.io.IOUtils.toString(this.getClass().getResourceAsStream("/outputTemplates/"+fileName+".json"), "UTF-8");
String templateJson = org.apache.commons.io.IOUtils.toString(this.getClass().getResourceAsStream("/outputTemplates/" + templateFileName), "UTF-8"); processorsMenu.add(new JMenuItem(new AbstractAction(fileName) {
processorsMenu.add(new JMenuItem(new AbstractAction(templateFileName) { @Override
@Override public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(ProjectView.getMainWindow(),
if (JOptionPane.showConfirmDialog(ProjectView.getMainWindow(), Messages.getString("Tab.Model.confirmLoadTemplate.text"),
Messages.getString("Tab.Model.confirmLoadTemplate.text"), Messages.getString("Tab.Model.confirmLoadTemplate.title"),
Messages.getString("Tab.Model.confirmLoadTemplate.title"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { try {
try { panel.setText(templateJson);
panel.setText(templateJson); } catch (Exception e1) {
} catch (Exception e1) { e1.printStackTrace();
e1.printStackTrace(); }
} }
} }
} }));
}));
}
panel.getPanelTop().add(processorsMenuBar, 0); panel.getPanelTop().add(processorsMenuBar, 0);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
logger.error("could not initialize output processor expert view: " + e.getMessage());
} }
return panel; return panel;
} }
......
...@@ -492,7 +492,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing ...@@ -492,7 +492,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
model.setCurrentScenario(bundle.getScenario()); model.setCurrentScenario(bundle.getScenario());
logger.info(String.format("selected scenario '%s'", bundle.getScenario().getName())); logger.info(String.format("selected scenario '%s'", bundle.getScenario().getName()));
scenarioJPanel.setScenario(bundle.getScenario(), true); scenarioJPanel.setScenario(bundle.getScenario(), true);
outputTableRenderer.setMarkedOutputFiles(bundle.getOutputDirectories()); outputTableRenderer.setMarkedOutputFiles(bundle.getOutputDirectories());
outputTable.repaint(); // make cell renderer mark associated outputs outputTable.repaint(); // make cell renderer mark associated outputs
......
...@@ -72,7 +72,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro ...@@ -72,7 +72,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
// Edit card... // Edit card...
JPanel editCard = new JPanel(); JPanel editCard = new JPanel();
editCard.setBorder(new EmptyBorder(5, 5, 5, 5)); editCard.setBorder(new EmptyBorder(5, 5, 5, 5));
editCard.setLayout(new BorderLayout(0, 0)); editCard.setLayout(new BorderLayout(0, 0));
editCard.setBounds(0, 0, 500, 100); editCard.setBounds(0, 0, 500, 100);
...@@ -141,7 +140,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro ...@@ -141,7 +140,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
} }
} }
}))); })));
JMenu mnModelNameMenu = new JMenu(Messages.getString("Tab.Model.insertModelNameMenu.title")); JMenu mnModelNameMenu = new JMenu(Messages.getString("Tab.Model.insertModelNameMenu.title"));
presetMenuBar.add(mnModelNameMenu); presetMenuBar.add(mnModelNameMenu);
menusInTabs.add(mnModelNameMenu); menusInTabs.add(mnModelNameMenu);
...@@ -153,7 +151,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro ...@@ -153,7 +151,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
attributesModelView.insertAtCursor("\"" + className + "\""); attributesModelView.insertAtCursor("\"" + className + "\"");
} }
}))); })));
logger.info("3");
ClassFinder.getModelNames().stream() ClassFinder.getModelNames().stream()
.sorted() .sorted()
.forEach(className -> mnModelNameMenu.add(new JMenuItem(new AbstractAction(className) { .forEach(className -> mnModelNameMenu.add(new JMenuItem(new AbstractAction(className) {
...@@ -162,16 +159,13 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro ...@@ -162,16 +159,13 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
attributesModelView.insertAtCursor("\"" + className + "\""); attributesModelView.insertAtCursor("\"" + className + "\"");
} }
}))); })));
attributesModelView.getPanelTop().add(presetMenuBar, 0); // the 0 puts it at the leftest position instead of the rightest attributesModelView.getPanelTop().add(presetMenuBar, 0); // the 0 puts it at the leftest position instead of the rightest
tabbedPane.addTab(Messages.getString("Tab.Model.title"), attributesModelView); tabbedPane.addTab(Messages.getString("Tab.Model.title"), attributesModelView);
topographyFileView = new TextView("/scenarios", "default_directory_scenarios", AttributeType.TOPOGRAPHY); topographyFileView = new TextView("/scenarios", "default_directory_scenarios", AttributeType.TOPOGRAPHY);
tabbedPane.addTab(Messages.getString("Tab.Topography.title"), topographyFileView); tabbedPane.addTab(Messages.getString("Tab.Topography.title"), topographyFileView);
dataProcessingGUIview = new DataProcessingView(); dataProcessingGUIview = new DataProcessingView();
tabbedPane.addTab("Data processing GUI", dataProcessingGUIview); tabbedPane.addTab("Data processing GUI", dataProcessingGUIview);
// online visualization card... // online visualization card...
JPanel visualizationCard = new JPanel(); JPanel visualizationCard = new JPanel();
...@@ -183,7 +177,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro ...@@ -183,7 +177,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
// Add panels // Add panels
super.add(editCard, editCardName); super.add(editCard, editCardName);
super.add(visualizationCard, visualizationCardName); super.add(visualizationCard, visualizationCardName);
} }
public void showVisualization() { public void showVisualization() {
......
...@@ -113,7 +113,6 @@ public class TextView extends JPanel implements IJsonView { ...@@ -113,7 +113,6 @@ public class TextView extends JPanel implements IJsonView {
this.default_resource = default_resource; this.default_resource = default_resource;
this.attributeType = attributeType; this.attributeType = attributeType;
setLayout(new BorderLayout(0, 0)); setLayout(new BorderLayout(0, 0));
logger.info("04");
panelTop = new JPanel(); panelTop = new JPanel();
add(panelTop, BorderLayout.NORTH); add(panelTop, BorderLayout.NORTH);
panelTop.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); panelTop.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
......
...@@ -45,13 +45,14 @@ public abstract class OutputFile<K extends DataKey<K>> { ...@@ -45,13 +45,14 @@ public abstract class OutputFile<K extends DataKey<K>> {
} }
public void setRelativeFileName(final String fileName) { public void setRelativeFileName(final String fileName) {
File file = new File(this.fileName); /* File file = new File(this.fileName);
if(file.getParentFile() != null) { if(file.getParentFile() != null) {
this.fileName = new File(this.fileName).getParentFile().toPath().resolve(fileName).toString(); this.fileName = new File(this.fileName).getParentFile().toPath().resolve(fileName).toString();
} }
else { else {
this.fileName = fileName; this.fileName = fileName;
} }*/
this.fileName = fileName;
} }
......
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