Commit 279a9cb2 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

replace ClassFinder use with generated Factories and deprecate CassFinder

parent 73c491b3
Pipeline #54759 failed with stage
in 26 seconds
......@@ -25,6 +25,7 @@ import java.util.jar.JarFile;
import java.util.stream.Collector;
import java.util.stream.Collectors;
@Deprecated
public class ClassFinder {
private static Logger log = LogManager.getLogger(ClassFinder.class);
......
package org.vadere.gui.projectview.view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.prefs.Preferences;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import info.clearthought.layout.TableLayout;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
......@@ -57,8 +12,6 @@ import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rsyntaxtextarea.Theme;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.view.JComboCheckBox;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.gui.projectview.utils.ClassFinder;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
import org.vadere.simulator.projects.dataprocessing.outputfile.OutputFile;
......@@ -70,10 +23,27 @@ import org.vadere.simulator.projects.dataprocessing.store.OutputFileStore;
import org.vadere.state.util.StateJsonConverter;
import org.vadere.util.io.IOUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.prefs.Preferences;
import java.util.stream.Collectors;
import info.clearthought.layout.TableLayout;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
class DataProcessingView extends JPanel implements IJsonView {
......@@ -293,7 +263,12 @@ class DataProcessingView extends JPanel implements IJsonView {
"Choose data processor", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
String processorClass = processorLableToClass.get(processorOptions.getSelectedItem());
// System.out.println("Selected Processor is: " + processorClass);
DataProcessor newDataProcessor = factory.getInstanceOf(processorClass);
DataProcessor newDataProcessor = null;
try {
newDataProcessor = factory.getInstanceOf(processorClass);
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
newDataProcessor.setId(currentScenario.getDataProcessingJsonManager().getMaxProcessorsId() + 1);
currentScenario.getDataProcessingJsonManager().addInstantiatedProcessor(newDataProcessor);
updateDataProcessorsTable();
......
......@@ -7,20 +7,21 @@ import org.vadere.gui.onlinevisualization.OnlineVisualization;
import org.vadere.gui.postvisualization.view.PostvisualizationWindow;
import org.vadere.gui.projectview.control.IProjectChangeListener;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.gui.projectview.utils.ClassFinder;
import org.vadere.gui.topographycreator.view.TopographyWindow;
import org.vadere.simulator.models.ModelHelper;
import org.vadere.simulator.projects.ProjectFinishedListener;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.VadereProject;
import org.vadere.state.attributes.ModelAttributeFactory;
import org.vadere.state.scenario.Topography;
import org.vadere.state.util.StateJsonConverter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
......@@ -128,8 +129,8 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
JMenu mnAttributesMenu = new JMenu(Messages.getString("Tab.Model.addAttributesMenu.title"));
presetMenuBar.add(mnAttributesMenu);
menusInTabs.add(mnAttributesMenu);
ClassFinder.getAttributesNames().stream()
.sorted().forEach(
ModelAttributeFactory attributeFactory = ModelAttributeFactory.instance();
attributeFactory.sortedAttributeStream().forEach(
attributesClassName -> mnAttributesMenu.add(new JMenuItem(new AbstractAction(attributesClassName) {
@Override
public void actionPerformed(ActionEvent e) {
......@@ -148,9 +149,10 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
JMenu submenuMainModels = new JMenu(Messages.getString("Tab.Model.insertModelNameSubMenu.title"));
mnModelNameMenu.add(submenuMainModels);
ClassFinder.getMainModelNames().stream()
.sorted()
ModelHelper.instance().getSortedMainModel()
// ClassFinder.getMainModelNames().stream()
// .sorted()
.forEach(className -> submenuMainModels.add(new JMenuItem(new AbstractAction(className) {
@Override
public void actionPerformed(ActionEvent e) {
......@@ -159,22 +161,23 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
}
)));
Map<String, List<String>> groupedPackages = ClassFinder.groupPackages(ClassFinder.getModelNames());
for (Map.Entry<String, List<String>> entry : groupedPackages.entrySet()) {
// Map<String, List<String>> groupedPackages = ClassFinder.groupPackages(ClassFinder.getModelNames());
// Map<String, List<String>> groupedPackages = ModelHelper.instance().getModelsSortedByPackage();
ModelHelper.instance().getModelsSortedByPackageStream().forEach( entry -> {
JMenu currentSubMenu = new JMenu(entry.getKey());
for (String className : entry.getValue()) {
currentSubMenu.add(new JMenuItem(new AbstractAction(className) {
@Override
public void actionPerformed(ActionEvent e) {
attributesModelView.insertAtCursor("\"" + className + "\"");
}
}));
}));
}
mnModelNameMenu.add(currentSubMenu);
}
});
attributesModelView.getPanelTop().add(presetMenuBar, 0); // the 0 puts it at the leftmost position instead of the rightmost
tabbedPane.addTab(Messages.getString("Tab.Model.title"), attributesModelView);
......
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