From 50d9ef0dda22c91e674f0bcb7a0dec5b0bcf17f0 Mon Sep 17 00:00:00 2001 From: Benedikt Zoennchen Date: Wed, 11 Oct 2017 16:05:19 +0200 Subject: [PATCH] fix problems with the output processor view - expert view --- .../outputTemplates/output_default.json | 14 ------ .../control/ActionLoadProject.java | 2 +- .../gui/projectview/utils/ClassFinder.java | 48 +------------------ .../projectview/view/DataProcessingView.java | 46 +++++++++--------- .../gui/projectview/view/ProjectView.java | 2 +- .../gui/projectview/view/ScenarioPanel.java | 7 --- .../vadere/gui/projectview/view/TextView.java | 1 - .../dataprocessing/outputfile/OutputFile.java | 5 +- 8 files changed, 29 insertions(+), 96 deletions(-) diff --git a/VadereGui/resources/outputTemplates/output_default.json b/VadereGui/resources/outputTemplates/output_default.json index 5e7b3009e..b29724455 100644 --- a/VadereGui/resources/outputTemplates/output_default.json +++ b/VadereGui/resources/outputTemplates/output_default.json @@ -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 } diff --git a/VadereGui/src/org/vadere/gui/projectview/control/ActionLoadProject.java b/VadereGui/src/org/vadere/gui/projectview/control/ActionLoadProject.java index f03e6c99e..39696f233 100644 --- a/VadereGui/src/org/vadere/gui/projectview/control/ActionLoadProject.java +++ b/VadereGui/src/org/vadere/gui/projectview/control/ActionLoadProject.java @@ -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); diff --git a/VadereGui/src/org/vadere/gui/projectview/utils/ClassFinder.java b/VadereGui/src/org/vadere/gui/projectview/utils/ClassFinder.java index 01933d78d..54ef52d51 100644 --- a/VadereGui/src/org/vadere/gui/projectview/utils/ClassFinder.java +++ b/VadereGui/src/org/vadere/gui/projectview/utils/ClassFinder.java @@ -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> getClassesStream(String packageName) throws ClassNotFoundException, IOException { - List> classes = new ArrayList<>(); - - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - String path = packageName.replace('.', '/'); - List resources = new ArrayList<>(); - LinkedList 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. * diff --git a/VadereGui/src/org/vadere/gui/projectview/view/DataProcessingView.java b/VadereGui/src/org/vadere/gui/projectview/view/DataProcessingView.java index efb286de3..6906548af 100644 --- a/VadereGui/src/org/vadere/gui/projectview/view/DataProcessingView.java +++ b/VadereGui/src/org/vadere/gui/projectview/view/DataProcessingView.java @@ -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 { + " mode"); 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,36 +147,34 @@ 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) { - @Override - public void actionPerformed(ActionEvent e) { - if (JOptionPane.showConfirmDialog(ProjectView.getMainWindow(), - Messages.getString("Tab.Model.confirmLoadTemplate.text"), - Messages.getString("Tab.Model.confirmLoadTemplate.title"), - JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { - try { - panel.setText(templateJson); - } catch (Exception e1) { - e1.printStackTrace(); - } - } - } - })); - } + //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(), + Messages.getString("Tab.Model.confirmLoadTemplate.text"), + Messages.getString("Tab.Model.confirmLoadTemplate.title"), + JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { + try { + panel.setText(templateJson); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + } + })); panel.getPanelTop().add(processorsMenuBar, 0); } catch (IOException e) { e.printStackTrace(); + logger.error("could not initialize output processor expert view: " + e.getMessage()); } return panel; } diff --git a/VadereGui/src/org/vadere/gui/projectview/view/ProjectView.java b/VadereGui/src/org/vadere/gui/projectview/view/ProjectView.java index 22d5d2fc0..0c1763a63 100644 --- a/VadereGui/src/org/vadere/gui/projectview/view/ProjectView.java +++ b/VadereGui/src/org/vadere/gui/projectview/view/ProjectView.java @@ -492,7 +492,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing model.setCurrentScenario(bundle.getScenario()); logger.info(String.format("selected scenario '%s'", bundle.getScenario().getName())); - scenarioJPanel.setScenario(bundle.getScenario(), true); + scenarioJPanel.setScenario(bundle.getScenario(), true); outputTableRenderer.setMarkedOutputFiles(bundle.getOutputDirectories()); outputTable.repaint(); // make cell renderer mark associated outputs diff --git a/VadereGui/src/org/vadere/gui/projectview/view/ScenarioPanel.java b/VadereGui/src/org/vadere/gui/projectview/view/ScenarioPanel.java index b173c4534..2261d1f13 100644 --- a/VadereGui/src/org/vadere/gui/projectview/view/ScenarioPanel.java +++ b/VadereGui/src/org/vadere/gui/projectview/view/ScenarioPanel.java @@ -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() { diff --git a/VadereGui/src/org/vadere/gui/projectview/view/TextView.java b/VadereGui/src/org/vadere/gui/projectview/view/TextView.java index 653484b25..93aaf1681 100644 --- a/VadereGui/src/org/vadere/gui/projectview/view/TextView.java +++ b/VadereGui/src/org/vadere/gui/projectview/view/TextView.java @@ -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)); diff --git a/VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/outputfile/OutputFile.java b/VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/outputfile/OutputFile.java index 00cfaca2b..cc52d6928 100644 --- a/VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/outputfile/OutputFile.java +++ b/VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/outputfile/OutputFile.java @@ -45,13 +45,14 @@ public abstract class OutputFile> { } 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; } -- GitLab