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 @@
}, {
"type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianSourceIdProcessor",
"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
}
......@@ -104,7 +104,7 @@ public class ActionLoadProject extends AbstractAction {
projectViewModel.setProject(project);
projectViewModel.refreshOutputTable();
logger.info("refreshed output table");
logger.info("refreshed output table - 2");
// select and load first scenario from list
projectViewModel.setSelectedRowIndexInScenarioTable(0);
......
......@@ -135,7 +135,7 @@ public class ClassFinder {
* Scans all classes accessible from the context class loader which belong to the given package
* 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
* @return The classes
......@@ -184,52 +184,6 @@ public class ClassFinder {
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.
*
......
......@@ -109,7 +109,6 @@ class DataProcessingView extends JPanel implements IJsonView {
JPanel togglePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
togglePanel.add(switchJsonViewModeLabel);
add(togglePanel, BorderLayout.SOUTH);
switchMode();
}
......@@ -119,24 +118,27 @@ class DataProcessingView extends JPanel implements IJsonView {
+ "</b> mode</u></font></span></html>");
Preferences.userNodeForPackage(DataProcessingView.class).put("dataProcessingViewMode",
inGuiViewMode ? guiViewMode : jsonViewMode);
viewPanel.removeAll();
if (inGuiViewMode) {
logger.info("switch to gui view");
GuiView guiView = new GuiView();
activeJsonView = guiView;
viewPanel.add(guiView);
} else {
logger.info("switch to expert view");
TextView expertView = buildExpertView();
activeJsonView = expertView;
viewPanel.add(expertView);
}
if (currentScenario != null) {
activeJsonView.setVadereScenario(currentScenario);
activeJsonView.isEditable(isEditable);
}
revalidate();
repaint();
}
......@@ -145,18 +147,16 @@ class DataProcessingView extends JPanel implements IJsonView {
private TextView buildExpertView() {
TextView panel = new TextView("/" + IOUtils.OUTPUT_DIR, "default_directory_outputprocessors", AttributeType.OUTPUTPROCESSOR);
JMenuBar processorsMenuBar = new JMenuBar();
processorsMenu = new JMenu(Messages.getString("Tab.Model.loadTemplateMenu.title"));
processorsMenu.setEnabled(isEditable);
processorsMenuBar.add(processorsMenu);
try {
File[] templateFiles = new File(this.getClass().getResource("/outputTemplates/").getPath()).listFiles();
for (File templateFile : Arrays.stream(templateFiles).filter(File::isFile).collect(Collectors.toList())) {
String templateFileName = templateFile.getName();
String templateJson = org.apache.commons.io.IOUtils.toString(this.getClass().getResourceAsStream("/outputTemplates/" + templateFileName), "UTF-8");
processorsMenu.add(new JMenuItem(new AbstractAction(templateFileName) {
//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.
String fileName = "output_default";
String templateJson = org.apache.commons.io.IOUtils.toString(this.getClass().getResourceAsStream("/outputTemplates/"+fileName+".json"), "UTF-8");
processorsMenu.add(new JMenuItem(new AbstractAction(fileName) {
@Override
public void actionPerformed(ActionEvent e) {
if (JOptionPane.showConfirmDialog(ProjectView.getMainWindow(),
......@@ -171,10 +171,10 @@ class DataProcessingView extends JPanel implements IJsonView {
}
}
}));
}
panel.getPanelTop().add(processorsMenuBar, 0);
} catch (IOException e) {
e.printStackTrace();
logger.error("could not initialize output processor expert view: " + e.getMessage());
}
return panel;
}
......
......@@ -72,7 +72,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
// Edit card...
JPanel editCard = new JPanel();
editCard.setBorder(new EmptyBorder(5, 5, 5, 5));
editCard.setLayout(new BorderLayout(0, 0));
editCard.setBounds(0, 0, 500, 100);
......@@ -141,7 +140,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
}
}
})));
JMenu mnModelNameMenu = new JMenu(Messages.getString("Tab.Model.insertModelNameMenu.title"));
presetMenuBar.add(mnModelNameMenu);
menusInTabs.add(mnModelNameMenu);
......@@ -153,7 +151,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
attributesModelView.insertAtCursor("\"" + className + "\"");
}
})));
logger.info("3");
ClassFinder.getModelNames().stream()
.sorted()
.forEach(className -> mnModelNameMenu.add(new JMenuItem(new AbstractAction(className) {
......@@ -162,16 +159,13 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
attributesModelView.insertAtCursor("\"" + className + "\"");
}
})));
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);
topographyFileView = new TextView("/scenarios", "default_directory_scenarios", AttributeType.TOPOGRAPHY);
tabbedPane.addTab(Messages.getString("Tab.Topography.title"), topographyFileView);
dataProcessingGUIview = new DataProcessingView();
tabbedPane.addTab("Data processing GUI", dataProcessingGUIview);
// online visualization card...
JPanel visualizationCard = new JPanel();
......@@ -183,7 +177,6 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
// Add panels
super.add(editCard, editCardName);
super.add(visualizationCard, visualizationCardName);
}
public void showVisualization() {
......
......@@ -113,7 +113,6 @@ public class TextView extends JPanel implements IJsonView {
this.default_resource = default_resource;
this.attributeType = attributeType;
setLayout(new BorderLayout(0, 0));
logger.info("04");
panelTop = new JPanel();
add(panelTop, BorderLayout.NORTH);
panelTop.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
......
......@@ -45,13 +45,14 @@ public abstract class OutputFile<K extends DataKey<K>> {
}
public void setRelativeFileName(final String fileName) {
File file = new File(this.fileName);
/* File file = new File(this.fileName);
if(file.getParentFile() != null) {
this.fileName = new File(this.fileName).getParentFile().toPath().resolve(fileName).toString();
}
else {
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