1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014 |
- package ui.view;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Cursor;
- import java.awt.Dimension;
- import java.awt.Image;
- import java.awt.Point;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.FocusEvent;
- import java.awt.event.FocusListener;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- import java.beans.PropertyVetoException;
- import java.beans.VetoableChangeListener;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Timer;
- import java.util.TimerTask;
- import javax.swing.AbstractAction;
- import javax.swing.ActionMap;
- import javax.swing.BoxLayout;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.ImageIcon;
- import javax.swing.InputMap;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JComponent;
- import javax.swing.JDialog;
- import javax.swing.JEditorPane;
- import javax.swing.JFileChooser;
- import javax.swing.JFrame;
- 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.JPopupMenu;
- import javax.swing.JScrollPane;
- import javax.swing.JSlider;
- import javax.swing.JSplitPane;
- import javax.swing.JTabbedPane;
- import javax.swing.JTable;
- import javax.swing.JTextField;
- import javax.swing.JToolBar;
- import javax.swing.JTree;
- import javax.swing.KeyStroke;
- import javax.swing.SwingUtilities;
- import javax.swing.border.LineBorder;
- import javax.swing.event.ChangeEvent;
- import javax.swing.event.ChangeListener;
- import javax.swing.filechooser.FileNameExtensionFilter;
- import javax.swing.table.DefaultTableModel;
- import javax.swing.table.TableCellEditor;
- import javax.swing.table.TableCellRenderer;
- import javax.swing.tree.DefaultMutableTreeNode;
- import javax.swing.tree.DefaultTreeModel;
- import javax.swing.tree.TreeCellRenderer;
- import classes.AbstractCpsObject;
- import classes.Category;
- import classes.CpsEdge;
- import classes.CpsUpperNode;
- import classes.HolonElement;
- import classes.HolonObject;
- import classes.HolonSwitch;
- import classes.HolonTransformer;
- import classes.IdCounter;
- import classes.IdCounterElem;
- import interfaces.CategoryListener;
- import ui.controller.Control;
- import ui.controller.UpdateController;
- import ui.model.Model;
- /**
- * Graphical User Interface.
- *
- * @author Gruppe14
- *
- * @param <E>
- * Generic
- */
- public class GUI<E> implements CategoryListener {
- // for doubleclick
- private boolean click = false;
- private JFrame frmCyberPhysical;
- private final SimulationMenu simMenu;
- private final JMenuBar menuBar = new JMenuBar();
- private final JMenu mnNewMenu = new JMenu("File");
- private final JMenu mnNewMenuEdit = new JMenu("Edit");
- private final JMenu mnNewMenuOptions = new JMenu("Options");
- private final JMenu mnNewMenuView = new JMenu("View");
- private final JMenu mnHelp = new JMenu("Help");
- private final JMenuItem mntmOpen = new JMenuItem("Open");
- private final JMenuItem mntmNew = new JMenuItem("New");
- private final JMenuItem mntmSave = new JMenuItem("Save");
- private final JMenuItem aboutUs = new JMenuItem("About Us");
- private final JMenuItem canvasSize = new JMenuItem("View Size");
- private final JSplitPane splitPane = new JSplitPane();
- private final JSplitPane splitPane1 = new JSplitPane();
- private final JSplitPane splitPaneCanvasConsole = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
- private final JScrollPane canvasSP = new JScrollPane();
- private final JScrollPane scrollPane1 = new JScrollPane();
- private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
- private final JPanel panelTapped_SimMenu = new JPanel();
- private JPopupMenu popmenuEdit = new JPopupMenu();
- private JMenuItem editItem = new JMenuItem("Edit Object");
- private String catOfObjToBeEdited;
- private final JScrollPane statTab = new JScrollPane();
- private splitPane statSplitPane;
- private JScrollPane statScrollPane;
- private UpperNodeCanvas unc;;
- private final JLabel maxGraph = new JLabel("100%");
- private final JLabel medGraph = new JLabel("50%");
- private final JLabel minGraph = new JLabel("0%");
- private final JLabel elementGraph = new JLabel("None ");
- private final ArrayList<HolonElement> selectedElements = new ArrayList<HolonElement>();
- private String holonEleNamesDisplayed = "None ";
- private HashMap<Integer, ArrayList<HolonElement>> eleToDelete = new HashMap<Integer, ArrayList<HolonElement>>();
- private final JTree tree = new JTree();
- /******************************************
- ************* Right Container*************
- ******************************************
- * Right Container: here comes the information about the HolonObject, such
- * as HolonElements Information, Properties and Consumption/Production
- * graph.
- **/
- private final JSplitPane splitHolonElPro = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
- private final JSplitPane splitGraphHolonEl = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
- // In this section are all the Holonelements that correspond to the clicked
- // HolonObject with consumption/production, name and amount.
- // Table for HolonElements --> all cells are editable
- private JTable tableHolonElement = new JTable();
- // Model for single or multi selection
- private PropertyTable tableModelHolonElementMulti = new PropertyTable();
- private PropertyTable tableModelHolonElementSingle = new PropertyTable();
- private final JPanel scrollElements = new JPanel();
- private JScrollPane tableHolonElementScrollPane = new JScrollPane();
- // In this section are all the properties that correspond to the clicked
- // HolonObject, such as connections, name, Type, etc.
- // Table for Properties --> Cell with (0,1) is editable by CpsObjt and
- // Cell(3,1) is editable by Edges
- private JTable tableProperties = new JTable() {
- private static final long serialVersionUID = 1L;
- @Override
- public TableCellRenderer getCellRenderer(int row, int column) {
- if (getValueAt(row, column) instanceof Boolean) {
- return super.getDefaultRenderer(Boolean.class);
- } else {
- return super.getCellRenderer(row, column);
- }
- }
- @Override
- public TableCellEditor getCellEditor(int row, int column) {
- if (getValueAt(row, column) instanceof Boolean) {
- return super.getDefaultEditor(Boolean.class);
- } else {
- return super.getCellEditor(row, column);
- }
- }
- };
- private JPanel graphLabel = new JPanel();
- private DefaulTable tableModelProperties;
- private final JScrollPane scrollProperties = new JScrollPane();
- // In this section is the graph for the selected HolonElement of the clicked
- // HolonObject
- private JTable tableGraph = new JTable();
- private DefaultTableModel tableModelGraph = new DefaultTableModel();
- private final JScrollPane scrollGraph = new JScrollPane();
- private Model model;
- private final Control controller;
- // Pop up Windows
- private AddObjectPopUp addObjectPopUP;
- private AboutUsPopUp aboutUsPopUp;
- private AddElementPopUp addElementPopUp;
- private final JPanel panel = new JPanel();
- private final JPanel panelHolonEl = new JPanel();
- private final JComboBox comboBox = new JComboBox();
- // private final JComboBox comboBoxGraph = new JComboBox();
- // Buttons
- private final JButton btnAdd = new JButton("+");
- private final JButton btnDel = new JButton("-");
- private final JButton btnAddHolEL = new JButton("+");
- private final JButton btnDelHolEL = new JButton("-");
- private final JButton resetGraphBtn = new JButton("Reset");
- private final JToolBar toolBar = new JToolBar();
- private final JToolBar toolBarHolonEl = new JToolBar();
- private final JToolBar toolBarGraph = new JToolBar();
- // private final Languages languages = new Languages();
- // Languages
- private final JMenuItem englishBtn = new JMenuItem("EN");
- private final JMenuItem spanishBtn = new JMenuItem("ES");
- private final JMenuItem germanBtn = new JMenuItem("DE");
- private final JMenuItem czechBtn = new JMenuItem("CZ");
- private final JMenuItem chineseBtn = new JMenuItem("ZH");
- // variables
- private boolean dragging = false;
- private String actualObjectClicked;
- private Image img = null;
- private AbstractCpsObject tempCps = null;
- private int yValueElements = 0;
- private Console console = new Console();
- private MyCanvas canvas;
- private UnitGraph unitGraph;
- private final JSplitPane splitPane3 = new JSplitPane();
- private final JSlider sizeSlider = new JSlider();
- private final JLabel lblImageSize = new JLabel(Languages.getLanguage()[94]);
- // Time Stuff
- private TimePanel timePanel;
- // Coord for all Cells with text
- private int yThis;
- private int xThis;
- // Coord for all Cells with boolean values (checkbox)
- private int yBTis;
- private int xBThis;
- // Coord for the Edit-Modus in the PropertieTable
- private int yProThis;
- private int xProThis;
- private AbstractCpsObject temp = null;
- private final JMenuItem mntmUndo = new JMenuItem("Undo");
- private final JMenuItem mntmRedo = new JMenuItem("Redo");
- private final JMenuItem mntmEditEdges = new JMenuItem("Edit Edges");
- private final JMenuItem mntmFindReplace = new JMenuItem("Find/ Replace");
- private final JMenuItem mntmEditShowedInformation = new JMenuItem("Edit showed Information");
- private final JMenuItem mntmResetCategory = new JMenuItem("Reset Categories");
- private final JMenu mnLanguage = new JMenu("Language");
- private String[] columnNamesMulti = { "Object", "Nr.", "Device", "Energy", "Quantity", "Activated" };
- private String[] columnNamesSingle = { "Nr.", "Device", "Energy", "Quantity", "Activated" };
- private String[] colNames = { "Field", "Information" };
- private String[] comboBoxCat = { "Category", "Object", "Switch" };
- private String warningText = "Warning";
- private String saveBeforeNew = "Do you want to save your current data?";
- private String eraseCategory = "Do you really want to delete the Category ";
- private String selectObjBeforeErase = "Please select a Category or an Object in order to delete something.";
- UpdateController updCon;
- /**
- * Create the application.
- *
- * @param control
- * the Controller
- */
- public GUI(Control control) {
- this.controller = control;
- this.model = control.getModel();
- statSplitPane = new splitPane();
- model.addGraphListener(statSplitPane);
- statScrollPane = new JScrollPane(statSplitPane);
- this.canvas = new MyCanvas(model, control);
- this.unitGraph = new UnitGraph(model, control);
- control.initListener(this);
- controller.setCanvas(canvas);
- model.setConsole(console);
- simMenu = new SimulationMenu(model, control);
- initialize();
- updateCategories(model.getCategories());
- updCon = new UpdateController(model, controller);
- }
- /**
- * Initialize the contents of the frame.
- */
- @SuppressWarnings({ "serial", "unchecked" })
- private void initialize() {
- frmCyberPhysical = new JFrame();
- frmCyberPhysical.setTitle("Cyber Physical Systems Model");
- frmCyberPhysical.setBounds(100, 100, 1000, 800);
- frmCyberPhysical.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- frmCyberPhysical.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent windowEvent) {
- if (JOptionPane.showConfirmDialog(frmCyberPhysical, Languages.getLanguage()[88],
- "Cyber Physical Systems Model", JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
- controller.deleteDirectory(new File(System.getProperty("user.home") + "/HolonGUI/Autosave"));
- System.exit(0);
- }
- }
- });
- JPanel contentPane = (JPanel) frmCyberPhysical.getContentPane();
- int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
- InputMap inputMap = contentPane.getInputMap(condition);
- ActionMap actionMap = contentPane.getActionMap();
- String cntrlZDown = "controlZ";
- inputMap.put(KeyStroke.getKeyStroke("control Z"), cntrlZDown);
- actionMap.put(cntrlZDown, new AbstractAction() {
- private static final long serialVersionUID = 1L;
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- controller.loadFile(controller.getUndoSave());
- canvas.repaint();
- ArrayList<HolonElement> tempList = new ArrayList<>();
- for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
- if (cps instanceof HolonObject) {
- for (HolonElement h : ((HolonObject) cps).getElements()) {
- tempList.add(h);
- unitGraph.repaintWithNewElement(tempList);
- unitGraph.fillArrayofValue();
- tempList.remove(0);
- }
- } else if (cps instanceof HolonSwitch) {
- unitGraph.repaintWithNewSwitch((HolonSwitch) cps);
- unitGraph.fillArrayofBooleans();
- }
- }
- unitGraph.empty();
- } catch (IOException eex) {
- // TODO Auto-generated catch block
- eex.printStackTrace();
- }
- }
- });
- String cntrlYDown = "controlY";
- inputMap.put(KeyStroke.getKeyStroke("control Y"), cntrlYDown);
- actionMap.put(cntrlYDown, new AbstractAction() {
- private static final long serialVersionUID = 1L;
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- controller.loadFile(controller.getRedoSave());
- canvas.repaint();
- ArrayList<HolonElement> tempList = new ArrayList<>();
- for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
- if (cps instanceof HolonObject) {
- for (HolonElement h : ((HolonObject) cps).getElements()) {
- tempList.add(h);
- unitGraph.repaintWithNewElement(tempList);
- unitGraph.fillArrayofValue();
- tempList.remove(0);
- }
- } else if (cps instanceof HolonSwitch) {
- unitGraph.repaintWithNewSwitch((HolonSwitch) cps);
- unitGraph.fillArrayofBooleans();
- }
- }
- unitGraph.empty();
- } catch (IOException ex) {
- // TODO Auto-generated catch block
- ex.printStackTrace();
- }
- }
- });
- String cntrlADown = "controlA";
- inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
- actionMap.put(cntrlADown, new AbstractAction() {
- private static final long serialVersionUID = 1L;
- @Override
- public void actionPerformed(ActionEvent e) {
- model.getSelectedCpsObjects().clear();
- for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
- controller.addSelectedObject(cps);
- }
- canvas.repaint();
- }
- });
- String delDown = "delete";
- inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false), delDown);
- actionMap.put(delDown, new AbstractAction() {
- private static final long serialVersionUID = 1L;
- @Override
- public void actionPerformed(ActionEvent e) {
- for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
- controller.delCanvasObject(cps);
- }
- model.getSelectedCpsObjects().clear();
- canvas.repaint();
- unitGraph.empty();
- }
- });
- String cntrlFDown = "controlF";
- inputMap.put(KeyStroke.getKeyStroke("control F"), cntrlFDown);
- actionMap.put(cntrlFDown, new AbstractAction() {
- private static final long serialVersionUID = 1L;
- @Override
- public void actionPerformed(ActionEvent e) {
- SearchPopUp dialog = new SearchPopUp(controller, canvas);
- dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
- dialog.setVisible(true);
- }
- });
- String cntrlCDown = "controlC";
- inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
- actionMap.put(cntrlCDown, new AbstractAction() {
- private static final long serialVersionUID = 1L;
- @Override
- public void actionPerformed(ActionEvent e) {
- if (!model.getSelectedCpsObjects().isEmpty()) {
- controller.copyObjects();
- if (!model.getClipboradObjects().isEmpty()) {
- canvas.itemPaste.setEnabled(true);
- }
- }
- }
- });
- String cntrlVDown = "controlV";
- inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
- actionMap.put(cntrlVDown, new AbstractAction() {
- private static final long serialVersionUID = 1L;
- @Override
- public void actionPerformed(ActionEvent e) {
- controller.pasteObjects(canvas.getMousePosition());
- canvas.repaint();
- }
- });
- String cntrlXDown = "controlX";
- inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
- actionMap.put(cntrlXDown, new AbstractAction() {
- private static final long serialVersionUID = 1L;
- @Override
- public void actionPerformed(ActionEvent e) {
- if (!model.getSelectedCpsObjects().isEmpty()) {
- controller.cutObjects();
- if (!model.getClipboradObjects().isEmpty()) {
- canvas.itemPaste.setEnabled(true);
- }
- canvas.repaint();
- }
- }
- });
- frmCyberPhysical.setJMenuBar(menuBar);
- frmCyberPhysical.setIconImage(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
- .getScaledInstance(30, 30, Image.SCALE_SMOOTH));
- menuBar.add(mnNewMenu);
- mnNewMenu.add(mntmNew);
- mnNewMenu.add(mntmOpen);
- mnNewMenu.add(mntmSave);
- menuBar.add(mnNewMenuEdit);
- mnNewMenuEdit.add(mntmUndo);
- mnNewMenuEdit.add(mntmRedo);
- mnLanguage.add(englishBtn);
- englishBtn.setIcon(new ImageIcon(new ImageIcon("res/Button_Images/FlagEN.png").getImage().getScaledInstance(20,
- 20, java.awt.Image.SCALE_SMOOTH)));
- mnLanguage.add(spanishBtn);
- spanishBtn.setIcon(new ImageIcon(new ImageIcon("res/Button_Images/FlagES.png").getImage().getScaledInstance(20,
- 20, java.awt.Image.SCALE_SMOOTH)));
- mnLanguage.add(germanBtn);
- germanBtn.setIcon(new ImageIcon(new ImageIcon("res/Button_Images/FlagDE.png").getImage().getScaledInstance(20,
- 20, java.awt.Image.SCALE_SMOOTH)));
- // mnLanguage.add(czechBtn);
- // czechBtn.setIcon(new ImageIcon(new
- // ImageIcon("res/Button_Images/FlagCZ.png").getImage().getScaledInstance(20,
- // 20, java.awt.Image.SCALE_SMOOTH)));
- mnLanguage.add(chineseBtn);
- chineseBtn.setIcon(new ImageIcon(new ImageIcon("res/Button_Images/FlagZH.png").getImage().getScaledInstance(20,
- 20, java.awt.Image.SCALE_SMOOTH)));
- mntmFindReplace.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- SearchPopUp dialog = new SearchPopUp(controller, canvas);
- dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
- dialog.setVisible(true);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- });
- mnNewMenuEdit.add(mntmFindReplace);
- mntmEditShowedInformation.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- ShowedInformationPopUp dialog = new ShowedInformationPopUp(canvas);
- dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
- dialog.setVisible(true);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- });
- mnNewMenuEdit.add(mntmEditShowedInformation);
- menuBar.add(mnNewMenuOptions);
- mntmEditEdges.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- EditEdgesPopUp edgePopUp = new EditEdgesPopUp();
- edgePopUp.setCanvas(canvas);
- edgePopUp.setController(controller);
- edgePopUp.setVisible(true);
- }
- });
- mnNewMenuOptions.add(mntmEditEdges);
- mnNewMenuOptions.add(mntmResetCategory);
- mntmResetCategory.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- ArrayList<Category> cat = model.getCategories();
- while (!cat.isEmpty()) {
- controller.deleteCategory(cat.get(0).getName());
- ;
- }
- controller.resetCategorys();
- tree.repaint();
- }
- });
- menuBar.add(mnNewMenuView);
- mnNewMenuView.add(canvasSize);
- canvasSize.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- JPanel myPanel = new JPanel();
- JTextField field1 = new JTextField("" + canvas.getWidth() + "");
- JTextField field2 = new JTextField("" + canvas.getHeight() + "");
- myPanel.add(field1);
- myPanel.add(field2);
- JOptionPane.showMessageDialog(null, myPanel);
- controller.setCanvasX(Integer.parseInt(field1.getText()));
- controller.setCanvasY(Integer.parseInt(field2.getText()));
- for (int i = 2; i < tabbedPane.getTabCount(); i++) {
- tabbedPane.getComponentAt(i)
- .setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
- tabbedPane.getComponentAt(i).repaint();
- }
- canvas.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
- canvas.repaint();
- }
- });
- mnNewMenuView.add(splitPane3);
- sizeSlider.setMinimum(15);
- sizeSlider.setMaximum(115);
- sizeSlider.addChangeListener(new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent e) {
- controller.setScale(sizeSlider.getValue());
- tree.setRowHeight(50);
- canvas.repaint();
- }
- });
- splitPane3.setRightComponent(sizeSlider);
- splitPane3.setLeftComponent(lblImageSize);
- menuBar.add(mnHelp);
- mnHelp.add(aboutUs);
- mnNewMenuOptions.add(mnLanguage);
- canvas.setBackground(Color.WHITE);
- canvas.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
- /********************
- * RIGHT CONTAINER (INFORMATION)
- **********************/
- // Set up of the HolonElements section
- // Two different Models: Multi for multi-selection mode and Single for
- // single-selection mode (CPS-Object)
- tableModelHolonElementMulti.setColumnIdentifiers(columnNamesMulti);
- tableModelHolonElementSingle.setColumnIdentifiers(columnNamesSingle);
- tableHolonElement.setBorder(null);
- tableHolonElement.setFillsViewportHeight(true);
- tableHolonElement.setCellSelectionEnabled(true);
- tableHolonElement.setColumnSelectionAllowed(true);
- tableHolonElementScrollPane.setViewportView(tableHolonElement);
- scrollElements.setLayout(new BorderLayout(0, 0));
- scrollElements.add(panelHolonEl, BorderLayout.NORTH);
- scrollElements.add(tableHolonElementScrollPane);
- panelHolonEl.setLayout(new BoxLayout(panelHolonEl, BoxLayout.X_AXIS));
- toolBarHolonEl.add(btnAddHolEL);
- toolBarHolonEl.add(btnDelHolEL);
- toolBarHolonEl.setFloatable(false);
- panelHolonEl.add(toolBarHolonEl);
- // Set up of the Properties section
- tableModelProperties = new DefaulTable(1000, colNames.length);
- tableModelProperties.setColumnIdentifiers(colNames);
- tableProperties.setModel(tableModelProperties);
- tableProperties.setFillsViewportHeight(true);
- tableProperties.setCellSelectionEnabled(true);
- tableProperties.setColumnSelectionAllowed(true);
- scrollProperties.setViewportView(tableProperties);
- // Set up of the Graph section
- tableGraph.setModel(tableModelGraph);
- tableGraph.setFillsViewportHeight(true);
- tableGraph.setCellSelectionEnabled(true);
- tableGraph.setColumnSelectionAllowed(true);
- scrollGraph.setViewportView(unitGraph);
- graphLabel.setLayout(new BorderLayout(0, 10));
- graphLabel.add(maxGraph, BorderLayout.NORTH);
- graphLabel.add(medGraph, BorderLayout.CENTER);
- graphLabel.add(minGraph, BorderLayout.SOUTH);
- toolBarGraph.add(elementGraph);
- toolBarGraph.add(resetGraphBtn);
- toolBarGraph.setFloatable(false);
- scrollGraph.setRowHeaderView(graphLabel);
- scrollGraph.setColumnHeaderView(toolBarGraph);
- /***********************
- * HolonElement Table Actions
- **********************/
- /*
- * Add HolonElement to given HolonObject
- */
- btnAddHolEL.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- if (model.getSelectedCpsObjects().size() == 1) {
- AbstractCpsObject tempCpsObject = getActualCps();
- if (tempCpsObject != null && tempCpsObject.getClass() == HolonObject.class
- && tempCpsObject.getID() != 0) {
- addElementPopUp = new AddElementPopUp();
- addElementPopUp.setActualCps(getActualCps());
- addElementPopUp.setVisible(true);
- HolonElement ele = addElementPopUp.getElement();
- if (ele != null) {
- controller.addElementCanvasObject(tempCpsObject.getID(), ele.getEleName(), ele.getAmount(),
- ele.getEnergy());
- }
- updCon.refreshTableHolonElement(tableModelHolonElementMulti, tableModelHolonElementSingle);
- updCon.refreshTableProperties(tableModelProperties);
- controller.calculateStateForTimeStep(model.getCurIteration());
- }
- }
- }
- });
- /*
- * Delete the chosen HolonElement of the selected HolonObject,
- * Multi-Selection for CpsObjects as well as for HolonElements possible
- */
- btnDelHolEL.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- // For Single Selection of CpsObject
- if (model.getSelectedCpsObjects().size() == 1) {
- if (getActualCps().getClass() == HolonObject.class) {
- HolonObject obj = (HolonObject) getActualCps();
- for (HolonElement e : selectedElements) {
- controller.deleteElementCanvas(obj.getID(), e.getId());
- updCon.refreshTableHolonElement(tableModelHolonElementMulti, tableModelHolonElementSingle);
- updCon.refreshTableProperties(tableModelProperties);
- controller.calculateStateForTimeStep(model.getCurIteration());
- // Names displayed in graph are not updated
- }
- eleToDelete.clear();
- selectedElements.clear();
- }
- // For MultiSelection of CpsObject
- } else if (model.getSelectedCpsObjects().size() > 1) {
- for (Integer i : eleToDelete.keySet()) {
- for (HolonElement e : eleToDelete.get(i)) {
- controller.deleteElementCanvas(i, e.getId());
- }
- }
- updCon.refreshTableHolonElement(tableModelHolonElementMulti, tableModelHolonElementSingle);
- updCon.refreshTableProperties(tableModelProperties);
- eleToDelete.clear();
- selectedElements.clear();
- }
- elementGraph.setText("None ");
- holonEleNamesDisplayed = "None ";
- }
- });
- /*
- * Communication between HolonElement Table and displayed Graph and
- * Properties, as well as selection of differet HolonElements
- */
- tableHolonElement.addMouseListener(new MouseAdapter() {
- public void mousePressed(MouseEvent e) {
- HolonObject obj = (HolonObject) getActualCps();
- yValueElements = e.getY();
- HolonElement ele = null;
- // Search for current clicked HolonElement
- if (model.getSelectedCpsObjects().size() == 1) {
- ele = getActualHolonElement(obj, yValueElements, 0);
- } else {
- ele = getActualHolonElement(null, yValueElements, 0);
- }
- // Multi-Selection of HolonElements through control button +
- // mouse click
- if (e.isControlDown() && ele != null) {
- if (!selectedElements.contains(ele)) {
- selectedElements.add(ele);
- if (!holonEleNamesDisplayed.equals("None ")) {
- holonEleNamesDisplayed = holonEleNamesDisplayed + "; " + ele.getEleName() + " ";
- } else {
- holonEleNamesDisplayed = ele.getEleName() + " ";
- }
- unitGraph.repaintWithNewElement(selectedElements);
- }
- getActualHolonElement(null, yValueElements, 2);
- } // if no control-button pressed but a HolonElement choose
- else if (ele != null) {
- selectedElements.clear();
- selectedElements.add(ele);
- getActualHolonElement(null, yValueElements, 1);
- holonEleNamesDisplayed = ele.getEleName() + " ";
- unitGraph.repaintWithNewElement(selectedElements);
- } // If any empty space is clicked
- else {
- elementGraph.setText(Languages.getLanguage()[25]);
- unitGraph.empty();
- }
- // if any HolonElement is double-clicked --> Edit-Mode started
- // for selected HolonElement
- if (e.getClickCount() == 2) {
- yThis = e.getY();
- xThis = e.getX();
- }
- // for single click and empty slot
- if (e.getClickCount() == 1 && ele == null) {
- selectedElements.clear();
- holonEleNamesDisplayed = Languages.getLanguage()[25];
- }
- elementGraph.setText(holonEleNamesDisplayed);
- yBTis = e.getY();
- xBThis = e.getX();
- }
- });
- /*
- * Triggered every time a change is made
- */
- tableHolonElement.addPropertyChangeListener(new PropertyChangeListener() {
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- try {
- int yMouse = yThis;
- int yBMouse = yBTis;
- int selectedValueY = (int) Math.floor(yMouse / 16);
- int selectedValueBY = (int) Math.floor(yBMouse / 16);
- // for multi-selection mode
- if (model.getSelectedCpsObjects().size() > 1) {
- int selectedValueX = (int) Math.floor(xThis / (tableHolonElement.getWidth() / 6));
- int selectedValueBX = (int) Math.floor(xBThis / (tableHolonElement.getWidth() / 6));
- if (updCon.getHolonObj(yMouse, tableModelHolonElementMulti) != null) {
- // For last column (boolean with a checkbox)
- if (selectedValueBX == 5) {
- HolonElement eleBTemp = getActualHolonElement(null, yBMouse, 0);
- String newBStuff = tableModelHolonElementMulti
- .getValueAt(selectedValueBY, selectedValueBX).toString();
- Boolean bTemp = Boolean.parseBoolean(newBStuff);
- eleBTemp.setActive(bTemp);
- } else {
- // Update of HolonElement
- HolonElement eleTemp = getActualHolonElement(null, yMouse, 0);
- String newStuff = tableModelHolonElementMulti.getValueAt(selectedValueY, selectedValueX)
- .toString();
- // Name update
- if (selectedValueX == 2) {
- eleTemp.setEleName(newStuff);
- }
- // Energy Update
- else if (selectedValueX == 3) {
- Float ftemp = Float.parseFloat(newStuff);
- eleTemp.setEnergy(ftemp);
- }
- // Amount of Elements update
- else if (selectedValueX == 4) {
- Integer iTemp = Integer.parseInt(newStuff);
- eleTemp.setAmount(iTemp);
- }
- }
- }
- } // For single-selection mode
- else if (model.getSelectedCpsObjects().size() == 1) {
- int selectedValueX = (int) Math.floor(xThis / (tableHolonElement.getWidth() / 5));
- int selectedValueBX = (int) Math.floor(xBThis / (tableHolonElement.getWidth() / 5));
- if (getActualCps() != null && getActualCps().getClass() == HolonObject.class) {
- // For last column (boolean with a checkbox)
- if (selectedValueBX == 4) {
- HolonElement eleBTemp = getActualHolonElement((HolonObject) getActualCps(), yBMouse, 0);
- String newBStuff = tableModelHolonElementSingle
- .getValueAt(selectedValueBY, selectedValueBX).toString();
- Boolean bTemp = Boolean.parseBoolean(newBStuff);
- eleBTemp.setActive(bTemp);
- } else {
- // Update of HolonElement
- HolonElement eleTemp = getActualHolonElement((HolonObject) getActualCps(), yMouse, 0);
- String newStuff = tableModelHolonElementSingle
- .getValueAt(selectedValueY, selectedValueX).toString();
- // Name update
- if (selectedValueX == 1) {
- eleTemp.setEleName(newStuff);
- } // Energy Update
- else if (selectedValueX == 2) {
- Float ftemp = Float.parseFloat(newStuff);
- eleTemp.setEnergy(ftemp);
- } // Amount of Elements update
- else if (selectedValueX == 3) {
- Integer iTemp = Integer.parseInt(newStuff);
- eleTemp.setAmount(iTemp);
- }
- }
- }
- }
- updCon.refreshTableProperties(tableModelProperties);
- tableModelHolonElementSingle.fireTableDataChanged();
- controller.calculateStateForTimeStep(model.getCurIteration());
- unitGraph.repaint();
- } catch (Exception e) {
- }
- }
- });
- /***********************
- * HolonElement Properties Actions
- **********************/
- /*
- * Update of the mouse coord for Edit-Mode
- */
- tableProperties.addMouseListener(new MouseAdapter() {
- public void mousePressed(MouseEvent e) {
- if (e.getClickCount() == 2) {
- yProThis = e.getY();
- xProThis = e.getX();
- }
- }
- });
- /*
- * Update any change in the Property table
- */
- tableProperties.addPropertyChangeListener(new PropertyChangeListener() {
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- try {
- Object temp;
- Object btemp;
- Point mousePos = tableProperties.getMousePosition();
- int selValueY = (int) Math.floor(yProThis / 16);
- int selValueX = (int) Math.floor(xProThis / (tableProperties.getWidth() / 2));
- if (getActualCps() != null) {
- temp = tableModelProperties.getValueAt(selValueY, selValueX);
- if (getActualCps() instanceof HolonSwitch) {
- btemp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
- mousePos.x / (tableProperties.getWidth() / 2));
- if (mousePos.y / tableProperties.getRowHeight() == 0) {
- getActualCps().setName(btemp.toString());
- } else if (mousePos.y / tableProperties.getRowHeight() == 2) {
- Boolean bbTemp = Boolean.parseBoolean(btemp.toString());
- ((HolonSwitch) getActualCps()).setManualMode(bbTemp);
- if (bbTemp) {
- tableModelProperties.setCellEditable(3, 1, true);
- } else {
- tableModelProperties.setCellEditable(3, 1, false);
- }
- } else if (mousePos.y / tableProperties.getRowHeight() == 3) {
- if (((HolonSwitch) getActualCps()).getManualMode()) {
- tableModelProperties.setCellEditable(3, 1, true);
- Boolean bTemp = Boolean.parseBoolean(temp.toString());
- ((HolonSwitch) getActualCps()).setManualState(bTemp);
- }
- }
- } // else if (getActualCps() instanceof
- // AbstractCpsObject) {
- getActualCps().setName(temp.toString());
- // }
- } else {
- temp = tableModelProperties.getValueAt(selValueY, selValueX);
- btemp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
- mousePos.x / (tableProperties.getWidth() / 2));
- if (selValueY == 2) {
- Float ftemp;
- if (Float.parseFloat(temp.toString()) >= 0.0) {
- ftemp = Float.parseFloat(temp.toString());
- } else {
- ftemp = model.getSelectedEdge().getCapacity();
- }
- model.getSelectedEdge().setCapacity(ftemp);
- } else if (mousePos.y / tableProperties.getRowHeight() == 3) {
- Boolean bbTemp = Boolean.parseBoolean(btemp.toString());
- model.getSelectedEdge().setState(bbTemp);
- }
- }
- canvas.repaint();
- } catch (Exception e) {
- }
- }
- });
- /***********************
- * HolonElement Graph Actions
- **********************/
- /*
- * Reset the graph of the selected HolonElement
- */
- resetGraphBtn.setBorder(new LineBorder(Color.BLACK));
- resetGraphBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- unitGraph.reset();
- }
- });
- /*****************************
- * RIGHT CONTAINER DONE
- *****************************/
- frmCyberPhysical.getContentPane().setLayout(new BorderLayout(0, 0));
- TreeCellRenderer customRenderer = new TreeCellRenderer() {
- @Override
- public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
- boolean leaf, int row, boolean hasFocus) {
- JLabel label = new JLabel();
- Image imgR = null;
- if (leaf) {
- for (Category cat : model.getCategories()) {
- for (AbstractCpsObject cps : cat.getObjects()) {
- if (value.toString().compareTo(cps.getObjName()) == 0) {
- File checkPath = new File(cps.getImage());
- if (checkPath.exists()) {
- imgR = new ImageIcon(cps.getImage()).getImage().getScaledInstance(50, 50,
- java.awt.Image.SCALE_SMOOTH);
- } else {
- imgR = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
- .getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH);
- }
- if (imgR != null) {
- label.setIcon(new ImageIcon(imgR));
- }
- label.setText(cps.getName());
- }
- }
- }
- }
- tree.setRowHeight(50);
- if (hasFocus) {
- label.setForeground(new Color(0, 0, 255));
- label.setOpaque(true);
- }
- if (label.getText().length() == 0) {
- label.setText(value.toString());
- if (value.toString().compareTo("Categories") != 0) {
- label.setIcon(new ImageIcon(this.getClass().getResource("/Images/folder.png")));
- }
- }
- return label;
- }
- };
- tree.setCellRenderer(customRenderer);
- tree.addMouseListener(new MouseAdapter() {
- public void mouseReleased(MouseEvent e) {
- try {
- if (dragging) {
- if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
- .getComponent(0) instanceof UpperNodeCanvas) {
- UpperNodeCanvas unc = ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getSelectedComponent())
- .getViewport().getComponent(0));
- int x = (int) unc.getMousePosition().getX();
- int y = (int) unc.getMousePosition().getY();
- AbstractCpsObject h = null;
- if (tempCps instanceof HolonObject) {
- h = new HolonObject(tempCps);
- }
- if (tempCps instanceof HolonSwitch) {
- h = new HolonSwitch(tempCps);
- }
- if (tempCps instanceof HolonTransformer) {
- h = new HolonTransformer(tempCps);
- }
- h.setPosition(x, y);
- controller.addObjUpperNode(h, unc.upperNode);
- unc.invalidate();
- unc.repaint();
- } else {
- int x = (int) canvas.getMousePosition().getX();
- int y = (int) canvas.getMousePosition().getY();
- AbstractCpsObject h = null;
- if (tempCps instanceof HolonObject) {
- h = new HolonObject(tempCps);
- }
- if (tempCps instanceof HolonSwitch) {
- h = new HolonSwitch(tempCps);
- }
- if (tempCps instanceof HolonTransformer) {
- h = new HolonTransformer(tempCps);
- }
- h.setPosition(x, y);
- controller.addObjectCanvas(h);
- canvas.invalidate();
- canvas.repaint();
- }
- dragging = false;
- }
- } catch (Exception eex) {
- }
- frmCyberPhysical.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
- }
- });
- popmenuEdit.add(editItem);
- editItem.setEnabled(false);
- editItem.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- }
- });
- tree.addMouseListener(new MouseAdapter() {
- public void mousePressed(MouseEvent e) {
- try {
- actualObjectClicked = tree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent().toString();
- // if an Object was selected, the porperties are shown in
- // the table
- DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree
- .getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
- if (selectedNode.getLevel() == 2) {
- controller.searchCategoryObject(selectedNode.getParent().toString(), selectedNode.toString());
- updCon.deleteRows(tableModelHolonElementSingle);
- updCon.deleteRows(tableModelHolonElementMulti);
- // if (selected instanceof HolonObject && selected !=
- // null) {
- // selected = (HolonObject) selected;
- // fillElementTable(((HolonObject)
- // selected).getElements());
- // }
- }
- if (SwingUtilities.isRightMouseButton(e)) {
- for (Category cat : model.getCategories()) {
- for (AbstractCpsObject cps : cat.getObjects()) {
- if (actualObjectClicked.compareTo(cps.getObjName()) == 0
- && !(cps instanceof HolonSwitch)) {
- editItem.setEnabled(true);
- popmenuEdit.show(e.getComponent(), e.getX(), e.getY());
- catOfObjToBeEdited = selectedNode.getParent().toString();
- tempCps = cps;
- }
- }
- }
- } else {
- for (Category cat : model.getCategories()) {
- for (AbstractCpsObject cps : cat.getObjects()) {
- if (actualObjectClicked.compareTo(cps.getObjName()) == 0) {
- File checkPath = new File(cps.getImage());
- if (checkPath.exists()) {
- img = new ImageIcon(cps.getImage()).getImage().getScaledInstance(50, 50,
- java.awt.Image.SCALE_SMOOTH);
- } else {
- img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
- .getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH);
- }
- tempCps = cps;
- dragging = true;
- Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0, 0),
- "Image");
- frmCyberPhysical.setCursor(cursor);
- }
- }
- }
- }
- } catch (Exception eex) {
- }
- }
- });
- editItem.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- // Remove the selected Object object
- addObjectPopUP = new AddObjectPopUp(true, tempCps, catOfObjToBeEdited);
- addObjectPopUP.setCategory(catOfObjToBeEdited);
- addObjectPopUP.setController(controller);
- addObjectPopUP.setVisible(true);
- }
- });
- scrollPane1.setViewportView(tree);
- scrollPane1.setColumnHeaderView(panel);
- panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
- toolBar.setFloatable(false);
- panel.add(toolBar);
- toolBar.add(comboBox);
- comboBox.setModel(new DefaultComboBoxModel(comboBoxCat));
- // Add Buttonnew DefaultComboBoxModel(comboBoxCat)
- btnAdd.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- Object nodeInfo = tree.getLastSelectedPathComponent();
- String selectedOption = comboBox.getSelectedItem().toString();
- DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
- try {
- switch (selectedOption) {
- case "Category":
- String catName = JOptionPane.showInputDialog(Languages.getLanguage()[56]);
- if (catName.length() != 0) {
- controller.addCategory(catName);
- }
- break;
- case "Object":
- if (selectedNode == null) {
- JOptionPane.showMessageDialog(new JFrame(),
- Languages.getLanguage()[57] + selectedOption + ".");
- }
- if (selectedNode.getLevel() == 1) {
- AbstractCpsObject tmp = new HolonObject("");
- addObjectPopUP = new AddObjectPopUp(false, tmp, null);
- addObjectPopUP.setVisible(true);
- addObjectPopUP.setController(controller);
- addObjectPopUP.setCategory(selectedNode.toString());
- }
- break;
- default:
- addObjectAction(selectedOption, selectedNode);
- break;
- }
- } catch (Exception e) {
- // TODO: handle exception
- }
- tree.repaint();
- }
- });
- /**
- * Pop up - About Us with some important information about the
- * developers, source and programming stuff
- */
- aboutUs.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- aboutUsPopUp = new AboutUsPopUp();
- aboutUsPopUp.setVisible(true);
- }
- });
- /**
- * Update of every interaction between the user and the canvas (only on
- * the canvas). Basically the update of all the information concerning
- * the clicked HolonObject. For multi-selection, the propertyTable would
- * be disabled
- */
- canvas.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- selectedElements.clear();
- holonEleNamesDisplayed = Languages.getLanguage()[25];
- // If any empty space is clicked
- if (temp == null || temp.getID() != model.getSelectedObjectID()) {
- unitGraph.empty();
- elementGraph.setText(Languages.getLanguage()[25]);
- }
- temp = getActualCps();
- // Erase old data in the PropertyTable
- if (tableModelProperties.getRowCount() > 0) {
- for (int i = tableModelProperties.getRowCount() - 1; i > -1; i--) {
- tableModelProperties.removeRow(i);
- }
- }
- if (e.isControlDown() && temp != null) {
- if (model.getSelectedCpsObjects().contains(temp)) {
- controller.deleteSelectedObject(temp);
- } else {
- controller.addSelectedObject(temp);
- }
- }
- // Write new data in the PropertyTable
- if (temp != null) {
- // Name of the CpsObject
- Object[] tempName = { Languages.getLanguage()[72], temp.getName() };
- tableModelProperties.addRow(tempName);
- // Id of the CpsObject
- Object[] tempId = { "ID", temp.getID() };
- tableModelProperties.addRow(tempId);
- // For HolonObjects the Total Energy (production or
- // consumption) is calculated
- if (temp instanceof HolonObject) {
- updCon.refreshTableHolonElement(tableModelHolonElementMulti, tableModelHolonElementSingle);
- Object[] tempEnergy = { Languages.getLanguage()[73], ((HolonObject) temp).getCurrentEnergy() };
- tableModelProperties.addRow(tempEnergy);
- tableModelProperties.setCellEditable(0, 1, true);
- tableModelProperties.setCellEditable(2, 1, false);
- tableModelProperties.setCellEditable(3, 1, false);
- } // For HolonSwitches is showed the actual status (active
- // or inactive)
- else if (temp instanceof HolonSwitch) {
- updCon.deleteRows(tableModelHolonElementSingle);
- updCon.deleteRows(tableModelHolonElementMulti);
- Object[] tempMode = { Languages.getLanguage()[74], ((HolonSwitch) temp).getManualMode() };
- tableModelProperties.addRow(tempMode);
- if (((HolonSwitch) temp).getManualMode()) {
- Object[] tempActive = { Languages.getLanguage()[75],
- ((HolonSwitch) temp).getActiveManual() };
- tableModelProperties.addRow(tempActive);
- tableModelProperties.setCellEditable(3, 1, true);
- } else {
- Object[] tempActive = { Languages.getLanguage()[75],
- ((HolonSwitch) temp).getActiveAt()[model.getCurIteration()] };
- tableModelProperties.addRow(tempActive);
- tableModelProperties.setCellEditable(3, 1, false);
- }
- unitGraph.repaintWithNewSwitch((HolonSwitch) temp);
- elementGraph.setText(temp.getName());
- tableModelProperties.setCellEditable(0, 1, true);
- tableModelProperties.setCellEditable(2, 1, true);
- } else {
- updCon.deleteRows(tableModelHolonElementSingle);
- updCon.deleteRows(tableModelHolonElementMulti);
- }
- // For Objects the only editable cell is the name
- ArrayList<CpsEdge> tempArray = temp.getConnections();
- // If the clicked object has connections
- if (!tempArray.isEmpty()) {
- boolean first = true;
- for (CpsEdge temp2 : tempArray) {
- if (first) {
- first = false;
- if (temp.getID() != temp2.getA().getID()) {
- Object[] tempConnection = { temp.getName() + Languages.getLanguage()[76],
- temp2.getA().getName() + Languages.getLanguage()[77]
- + temp2.getA().getID() };
- tableModelProperties.addRow(tempConnection);
- } else {
- Object[] tempConnection = { temp.getName() + Languages.getLanguage()[76],
- temp2.getB().getName() + Languages.getLanguage()[77]
- + temp2.getB().getID() };
- tableModelProperties.addRow(tempConnection);
- }
- } else {
- if (temp.getID() != temp2.getA().getID()) {
- Object[] tempConnection = { "", temp2.getA().getName() + Languages.getLanguage()[77]
- + temp2.getA().getID() };
- tableModelProperties.addRow(tempConnection);
- } else {
- Object[] tempConnection = { "", temp2.getB().getName() + Languages.getLanguage()[77]
- + temp2.getB().getID() };
- tableModelProperties.addRow(tempConnection);
- }
- }
- }
- }
- } // If the clicked Object is an edge
- else if (model.getSelectedEdge() != null) {
- // Name displayed
- Object[] tempName = { Languages.getLanguage()[72],
- Languages.getLanguage()[78] + model.getSelectedEdge().getA().getName()
- + Languages.getLanguage()[79] + model.getSelectedEdge().getB().getName() };
- tableModelProperties.addRow(tempName);
- // Current Flow displayed
- Object[] tempFlow = { Languages.getLanguage()[80], model.getSelectedEdge().getFlow() };
- tableModelProperties.addRow(tempFlow);
- // Max Capacity displayed
- Object[] tempCapacity = { Languages.getLanguage()[81], model.getSelectedEdge().getCapacity() };
- tableModelProperties.addRow(tempCapacity);
- // Status displayed
- Object[] tempStatus = { Languages.getLanguage()[82], model.getSelectedEdge().getState() };
- tableModelProperties.addRow(tempStatus);
- // For edges, the only possible editable cell is the max
- // flow
- tableModelProperties.setCellEditable(0, 1, false);
- tableModelProperties.setCellEditable(2, 1, true);
- tableModelProperties.setCellEditable(3, 1, true);
- } else if (getActualCps() == null) {
- updCon.deleteRows(tableModelHolonElementSingle);
- updCon.deleteRows(tableModelHolonElementMulti);
- } // Update of the HolonElementTable (Single- or
- // Multi-Selection)
- if (model.getSelectedCpsObjects().size() > 1) {
- tableHolonElement.setModel(tableModelHolonElementMulti);
- } else if (model.getSelectedCpsObjects().size() == 1) {
- tableHolonElement.setModel(tableModelHolonElementSingle);
- }
- // New Tab with NodeOfNode
- if (doubleClick() && temp instanceof CpsUpperNode) {
- openNewUpperNodeTab();
- }
- }
- @Override
- public void mouseReleased(MouseEvent e) {
- updCon.refreshTableHolonElement(tableModelHolonElementMulti, tableModelHolonElementSingle);
- updCon.refreshTableProperties(tableModelProperties);
- if (model.getSelectedCpsObjects().size() > 1) {
- tableHolonElement.setModel(tableModelHolonElementMulti);
- } else if (model.getSelectedCpsObjects().size() == 1) {
- tableHolonElement.setModel(tableModelHolonElementSingle);
- }
- }
- });
- toolBar.add(btnAdd);
- // Del Button
- btnDel.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- Object nodeInfo = tree.getLastSelectedPathComponent();
- if (nodeInfo != null) {
- DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
- String nodeName = selectedNode.getUserObject().toString();
- int depthOfNode = selectedNode.getLevel();
- switch (depthOfNode) {
- case 1:
- int dialogResult = JOptionPane.showConfirmDialog(null, eraseCategory + nodeName + "?",
- warningText, JOptionPane.YES_NO_OPTION);
- if (dialogResult == JOptionPane.YES_OPTION) {
- controller.deleteCategory(nodeName);
- }
- break;
- case 2:
- DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
- controller.delObjectCategory(parent.getUserObject().toString(), nodeName);
- break;
- default:
- JOptionPane.showMessageDialog(new JFrame(), selectObjBeforeErase);
- }
- } else {
- JOptionPane.showMessageDialog(new JFrame(), selectObjBeforeErase);
- }
- tree.repaint();
- }
- });
- toolBar.add(btnDel);
- frmCyberPhysical.getContentPane().add(splitPane);
- mntmNew.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- if (model.getObjectsOnCanvas().size() != 0) {
- int newWarning = JOptionPane.YES_NO_OPTION;
- int dialogForNewWarning = JOptionPane.showConfirmDialog(null, saveBeforeNew, warningText,
- newWarning);
- if (dialogForNewWarning == JOptionPane.YES_OPTION) {
- mntmSave.doClick();
- }
- }
- model.getEdgesOnCanvas().removeAll(model.getEdgesOnCanvas());
- model.getObjectsOnCanvas().removeAll(model.getObjectsOnCanvas());
- controller.setSelectedObjectID(0);
- controller.setSelecteEdge(null);
- controller.setCurIteration(0);
- unitGraph.empty();
- elementGraph.setText(Languages.getLanguage()[25]);
- canvas.tempCps = null;
- canvas.repaint();
- IdCounter.resetCounter();
- IdCounterElem.resetCounter();
- }
- });
- mntmOpen.addActionListener(new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- menuFileExitActionPerformed(evt);
- }
- private void menuFileExitActionPerformed(java.awt.event.ActionEvent evt) {
- JFileChooser fileChooser = new JFileChooser();
- JFrame test = new JFrame();
- FileNameExtensionFilter jsonFilter = new FileNameExtensionFilter("*.json", "json");
- fileChooser.setFileFilter(jsonFilter);
- if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
- File file = fileChooser.getSelectedFile();
- try {
- controller.loadFile(file.getAbsolutePath());
- canvas.repaint();
- ArrayList<HolonElement> tempList = new ArrayList<>();
- for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
- if (cps instanceof HolonObject) {
- for (HolonElement h : ((HolonObject) cps).getElements()) {
- tempList.add(h);
- unitGraph.repaintWithNewElement(tempList);
- unitGraph.fillArrayofValue();
- tempList.remove(0);
- }
- } else if (cps instanceof HolonSwitch) {
- unitGraph.repaintWithNewSwitch((HolonSwitch) cps);
- unitGraph.fillArrayofBooleans();
- }
- }
- unitGraph.empty();
- tree.repaint();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- });
- mntmSave.addActionListener(new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- menuSaveActionPerformed(evt);
- }
- private void menuSaveActionPerformed(java.awt.event.ActionEvent evt) {
- JFileChooser fileChooser = new JFileChooser();
- JFrame test = new JFrame();
- FileNameExtensionFilter jsonFilter = new FileNameExtensionFilter("*.json", "json");
- fileChooser.setFileFilter(jsonFilter);
- if (fileChooser.showSaveDialog(test) == JFileChooser.APPROVE_OPTION) {
- String file = fileChooser.getSelectedFile().getPath();
- if (!file.endsWith(".json"))
- file += ".json";
- try {
- controller.saveFile(new File(file).getAbsolutePath());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- });
- englishBtn.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Languages.setLanguage(0);
- refreshLanguages();
- updCon.refreshTableProperties(tableModelProperties);
- }
- });
- spanishBtn.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Languages.setLanguage(1);
- refreshLanguages();
- updCon.refreshTableProperties(tableModelProperties);
- }
- });
- germanBtn.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Languages.setLanguage(2);
- refreshLanguages();
- updCon.refreshTableProperties(tableModelProperties);
- }
- });
- czechBtn.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Languages.setLanguage(3);
- refreshLanguages();
- updCon.refreshTableProperties(tableModelProperties);
- }
- });
- chineseBtn.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Languages.setLanguage(4);
- refreshLanguages();
- updCon.refreshTableProperties(tableModelProperties);
- ;
- }
- });
- mntmUndo.addActionListener(new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- menuUndoActionPerformed(evt);
- }
- private void menuUndoActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- controller.loadFile(controller.getUndoSave());
- canvas.repaint();
- ArrayList<HolonElement> tempList = new ArrayList<>();
- for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
- if (cps instanceof HolonObject) {
- for (HolonElement h : ((HolonObject) cps).getElements()) {
- tempList.add(h);
- unitGraph.repaintWithNewElement(tempList);
- unitGraph.fillArrayofValue();
- tempList.remove(0);
- }
- } else if (cps instanceof HolonSwitch) {
- unitGraph.repaintWithNewSwitch((HolonSwitch) cps);
- unitGraph.fillArrayofBooleans();
- }
- }
- unitGraph.empty();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- mntmRedo.addActionListener(new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- menuRedoActionPerformed(evt);
- }
- private void menuRedoActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- controller.loadFile(controller.getRedoSave());
- canvas.repaint();
- ArrayList<HolonElement> tempList = new ArrayList<>();
- for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
- if (cps instanceof HolonObject) {
- for (HolonElement h : ((HolonObject) cps).getElements()) {
- tempList.add(h);
- unitGraph.repaintWithNewElement(tempList);
- unitGraph.fillArrayofValue();
- tempList.remove(0);
- }
- } else if (cps instanceof HolonSwitch) {
- unitGraph.repaintWithNewSwitch((HolonSwitch) cps);
- unitGraph.fillArrayofBooleans();
- }
- }
- unitGraph.empty();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- timePanel = new TimePanel(model, controller);
- timePanel.setBorder(null);
- ((JSlider) (timePanel.getComponent(1))).addChangeListener(new ChangeListener() {
- @Override
- public void stateChanged(ChangeEvent e) {
- int i = model.getCurIteration();
- controller.calculateStateForTimeStep(i);
- unitGraph.repaint();
- }
- });
- splitPane.setRightComponent(splitPane1);
- splitPane.setDividerLocation(200);
- splitPane1.setDividerLocation(500);
- splitPaneCanvasConsole.setDividerLocation(500);
- splitPane.setLeftComponent(scrollPane1);
- splitPaneCanvasConsole.setLeftComponent(panelTapped_SimMenu);
- tabbedPane.addTab("View", canvasSP);
- tabbedPane.addTab("Statistics", statScrollPane);
- splitPaneCanvasConsole.setRightComponent(console);
- splitPane1.setLeftComponent(splitPaneCanvasConsole);
- splitPane1.setRightComponent(splitHolonElPro);
- splitPane1.setResizeWeight(0.9);
- splitHolonElPro.setDividerLocation(400);
- splitHolonElPro.setTopComponent(splitGraphHolonEl);
- splitHolonElPro.setBottomComponent(scrollProperties);
- splitGraphHolonEl.setDividerLocation(150);
- splitGraphHolonEl.setTopComponent(scrollGraph);
- splitGraphHolonEl.setBottomComponent(scrollElements);
- canvasSP.setViewportView(canvas);
- panelTapped_SimMenu.setLayout(new BorderLayout());
- panelTapped_SimMenu.add(simMenu, BorderLayout.NORTH);
- panelTapped_SimMenu.add(tabbedPane);
- simMenu.setBackground(new Color(240, 240, 240));
- panelTapped_SimMenu.setBorder(null);
- tabbedPane.setBorder(null);
- scrollProperties.setBorder(null);
- scrollGraph.setBorder(null);
- scrollElements.setBorder(null);
- splitPane.setBorder(null);
- splitPane1.setBorder(null);
- splitPaneCanvasConsole.setBorder(null);
- splitHolonElPro.setBorder(null);
- splitGraphHolonEl.setBorder(null);
- panelHolonEl.setBorder(null);
- canvasSP.setBorder(null);
- tableHolonElementScrollPane.setBorder(null);
- frmCyberPhysical.getContentPane().add(timePanel, BorderLayout.SOUTH);
- String autoPath = System.getProperty("user.home") + "/HolonGUI/Autosave/";
- File dest = new File(autoPath);
- if (dest.listFiles().length > 1) {
- int dialogButton = JOptionPane.YES_NO_OPTION;
- int dialogResult = JOptionPane.showConfirmDialog(null, "Old autosave file was found, should it be loaded?",
- warningText, dialogButton);
- if (dialogResult == JOptionPane.YES_OPTION) {
- model.setAutoSaveNr(dest.listFiles().length - 1);
- mntmRedo.doClick();
- } else {
- controller.deleteDirectory(dest);
- dest.mkdirs();
- try {
- controller.autoSave();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
- }
- /**
- * adds a specific object type to selected Category also handles input
- * windows and illegal inputs.
- *
- * @param objType
- * type of the Object
- * @param selectedNode
- * The selected Node
- */
- public void addObjectAction(String objType, DefaultMutableTreeNode selectedNode) {
- if (selectedNode == null) {
- JOptionPane.showMessageDialog(new JFrame(),
- "Please select a Category first before adding " + objType + ".");
- }
- // if selected node is a directory for Categories
- else {
- if (selectedNode.getLevel() == 1) {
- String objname = JOptionPane.showInputDialog("Please enter a Name for the " + objType);
- Category cat = controller.searchCategory(selectedNode.getUserObject().toString());
- if (objname.length() != 0) {
- switch (objType) {
- case "Switch":
- controller.addSwitch(cat, objname);
- break;
- }
- }
- } else {
- JOptionPane.showMessageDialog(new JFrame(),
- "Objects can not be added to Objects. Please select a Category.");
- }
- }
- }
- /**
- * reloads the Categories from Model.
- *
- * @param categories
- * the current categories
- */
- public void updateCategories(final ArrayList<Category> categories) {
- tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Categories") {
- private static final long serialVersionUID = 1L;
- {
- DefaultMutableTreeNode node1;
- for (Category c : categories) {
- node1 = new DefaultMutableTreeNode(c.getName());
- // kann eventuell umgeändert werden
- for (AbstractCpsObject obj : c.getObjects()) {
- node1.add(new DefaultMutableTreeNode(obj.getObjName()));
- }
- add(node1);
- }
- }
- }));
- }
- /**
- * When changes are made to the Categories.
- *
- * @param categories
- * the Categories
- */
- public void onChange(ArrayList<Category> categories) {
- DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
- updateCategories(categories);
- model.reload();
- }
- /**
- * Get the Frame.
- *
- * @return the Frame
- */
- public JFrame getFrmCyberPhysical() {
- return frmCyberPhysical;
- }
- /**
- * Getter for selected CpsObject.
- *
- * @return selected CpsObject
- */
- private AbstractCpsObject getActualCps() {
- int tempID = model.getSelectedObjectID();
- AbstractCpsObject tempCps = controller.searchByID(tempID);
- return tempCps;
- }
- /**
- * Search for actual selected HolonElement.
- *
- * @param obj
- * selected HolonObject, if obj==null means multi-selection
- * active
- * @param yValue
- * Y-Coord in the HolonElementsTable
- * @param toMultiHash
- * 0 means no MultiSelection, 1 means MultiSelection without
- * Control, 2 means MultiSelection with Control
- * @return the selected HolonElement
- */
- private HolonElement getActualHolonElement(HolonObject obj, int yValue, int toMultiHash) {
- final int yTemp = (int) Math.floor(yValue / 16);
- int rowsTotal = 0;
- // Filter for search --> single and multi selection
- if (obj == null) {
- rowsTotal = tableModelHolonElementMulti.getRowCount();
- } else {
- rowsTotal = tableModelHolonElementSingle.getRowCount();
- }
- // search for the clicked HolonObject and HolonElement --> in the
- // HolonElementTable
- HolonObject obtTemp = null;
- HolonElement toReturnEle = null;
- int id = 0;
- if (rowsTotal != 0 && rowsTotal > yTemp) {
- // Multi-Selection search
- if (obj == null) {
- String tempStringObj = tableModelHolonElementMulti.getValueAt(yTemp, 0).toString();
- int idTempObj = Integer.parseInt(tempStringObj.split(", ")[1]);
- obtTemp = (HolonObject) controller.searchByID(idTempObj);
- id = Integer.parseInt(tableModelHolonElementMulti.getValueAt(yTemp, 1).toString());
- ArrayList<HolonElement> eleTemp = new ArrayList<HolonElement>();
- if (eleToDelete.containsKey(idTempObj) && toMultiHash == 2) {
- eleTemp = eleToDelete.get(idTempObj);
- if (!eleTemp.contains(obtTemp.searchElementById(id))) {
- eleTemp.add(obtTemp.searchElementById(id));
- eleToDelete.replace(idTempObj, eleTemp);
- }
- } else if (toMultiHash == 2) {
- eleTemp.add(obtTemp.searchElementById(id));
- eleToDelete.put(idTempObj, eleTemp);
- } else if (toMultiHash == 1) {
- eleToDelete = new HashMap<Integer, ArrayList<HolonElement>>();
- eleTemp.add(obtTemp.searchElementById(id));
- eleToDelete.put(idTempObj, eleTemp);
- } else if (toMultiHash == 0) {
- toReturnEle = obtTemp.searchElementById(id);
- }
- } // Single-Selection search
- else {
- eleToDelete = new HashMap<Integer, ArrayList<HolonElement>>();
- id = Integer.parseInt(tableModelHolonElementSingle.getValueAt(yTemp, 0).toString());
- toReturnEle = obj.searchElementById(id);
- }
- model.setSelectedHolonElement(toReturnEle);
- return toReturnEle;
- } // If no HolonObject selected
- else {
- eleToDelete = new HashMap<Integer, ArrayList<HolonElement>>();
- model.setSelectedHolonElement(null);
- return null;
- }
- }
- /**
- * Adds a Popup.
- *
- * @param component
- * Component
- * @param popup
- * PopupMenu
- */
- private static void addPopup(Component component, final JPopupMenu popup) {
- component.addMouseListener(new MouseAdapter() {
- public void mousePressed(MouseEvent e) {
- if (e.isPopupTrigger()) {
- showMenu(e);
- }
- }
- public void mouseReleased(MouseEvent e) {
- if (e.isPopupTrigger()) {
- showMenu(e);
- }
- }
- private void showMenu(MouseEvent e) {
- popup.show(e.getComponent(), e.getX(), e.getY());
- }
- });
- }
- private void refreshLanguages() {
- String[] tempArray = Languages.getLanguage();
- // ToolBar
- mnNewMenu.setText(tempArray[0]);
- mntmNew.setText(tempArray[1]);
- mntmOpen.setText(tempArray[2]);
- mntmSave.setText(tempArray[3]);
- mnNewMenuEdit.setText(tempArray[4]);
- mntmUndo.setText(tempArray[5]);
- mntmRedo.setText(tempArray[6]);
- mntmFindReplace.setText(tempArray[7]);
- mntmEditShowedInformation.setText(tempArray[8]);
- mnNewMenuOptions.setText(tempArray[9]);
- mntmResetCategory.setText(tempArray[10]);
- mnNewMenuView.setText(tempArray[11]);
- canvasSize.setText(tempArray[12]);
- mnHelp.setText(tempArray[13]);
- aboutUs.setText(tempArray[14]);
- mntmEditEdges.setText(tempArray[15]);
- mnLanguage.setText(tempArray[16]);
- // Tables
- for (int i = 0; i < columnNamesMulti.length; i++) {
- columnNamesMulti[i] = tempArray[i + 17];
- }
- tableModelHolonElementMulti.setColumnIdentifiers(columnNamesMulti);
- for (int i = 0; i < columnNamesSingle.length; i++) {
- columnNamesSingle[i] = tempArray[i + 18];
- }
- tableModelHolonElementSingle.setColumnIdentifiers(columnNamesSingle);
- colNames[0] = tempArray[23];
- colNames[1] = tempArray[24];
- tableModelProperties.setColumnIdentifiers(colNames);
- // Graph
- elementGraph.setText(tempArray[25]);
- holonEleNamesDisplayed = tempArray[25];
- resetGraphBtn.setText(tempArray[26]);
- // Warning PopUps
- warningText = tempArray[27];
- saveBeforeNew = tempArray[28];
- eraseCategory = tempArray[29];
- selectObjBeforeErase = tempArray[30];
- // SimMenu
- simMenu.simButton.setText(Languages.getLanguage()[83]);
- simMenu.simSpeedLabel.setText(Languages.getLanguage()[84]);
- simMenu.algoFolderButton.setText(Languages.getLanguage()[85]);
- // TimePanel
- timePanel.playBtn.setToolTipText(Languages.getLanguage()[89]);
- timePanel.timeResetBtn.setToolTipText(Languages.getLanguage()[90]);
- timePanel.timeForwardBtn.setToolTipText(Languages.getLanguage()[91]);
- timePanel.timeBackwardBtn.setToolTipText(Languages.getLanguage()[92]);
- timePanel.timeSlider.setToolTipText(Languages.getLanguage()[93]);
- // Image Size Slider
- lblImageSize.setText(Languages.getLanguage()[94]);
- }
- /**
- * Checks if a double click was made.
- *
- * @return
- *
- * @return true if doublecklick, false if not
- */
- private boolean doubleClick() {
- if (click) {
- click = false;
- return true;
- } else {
- click = true;
- Timer t = new Timer("doubleclickTimer", false);
- t.schedule(new TimerTask() {
- @Override
- public void run() {
- click = false;
- }
- }, 350);
- }
- return false;
- }
- /*
- * Open a new Tab with an UpperNodeCanvas
- */
- private void openNewUpperNodeTab() {
- if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport().getComponent(0) instanceof MyCanvas) {
- unc = new UpperNodeCanvas(model, controller, (CpsUpperNode) temp, "");
- } else {
- unc = new UpperNodeCanvas(model, controller, (CpsUpperNode) temp,
- ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
- .getComponent(0)).path + " -> ");
- }
- // check if tab already open for clicked NodeOfNode
- boolean dupl = false;
- for (int i = 2; i < tabbedPane.getTabCount() && dupl == false; i++) {
- if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport().getComponent(0)).upperNode
- .getID() == temp.getID()) {
- dupl = true;
- tabbedPane.setSelectedComponent(tabbedPane.getComponentAt(i));
- }
- }
- if (!dupl) {
- unc.setBorder(null);
- unc.setBackground(Color.WHITE);
- unc.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
- unc.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- temp = unc.tempCps;
- if (doubleClick() && temp instanceof CpsUpperNode) {
- openNewUpperNodeTab();
- }
- }
- });
- JScrollPane sp = new JScrollPane(unc);
- sp.setBorder(null);
- tabbedPane.add(temp.getName(), sp);
- tabbedPane.setSelectedComponent(sp);
- tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1, new ButtonTabComponent(tabbedPane));
- temp = null;
- }
- }
- }
|