From b82536ec35d01fd1195a11733203be7c1c008ad6 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 30 May 2008 00:52:51 +0000 Subject: new package has been documented. --- sources/simulator/2DOCUMENT | 0 sources/simulator/VSLogging.java | 48 +- sources/simulator/VSMain.java | 24 +- sources/simulator/VSMenuItemStates.java | 8 +- sources/simulator/VSSimulator.java | 724 ++++++++++++++----------------- sources/simulator/VSSimulatorCanvas.java | 652 +++++++++++++++------------- sources/simulator/VSSimulatorFrame.java | 247 ++++++----- 7 files changed, 870 insertions(+), 833 deletions(-) delete mode 100644 sources/simulator/2DOCUMENT (limited to 'sources/simulator') diff --git a/sources/simulator/2DOCUMENT b/sources/simulator/2DOCUMENT deleted file mode 100644 index e69de29..0000000 diff --git a/sources/simulator/VSLogging.java b/sources/simulator/VSLogging.java index b89751c..b7ce221 100644 --- a/sources/simulator/VSLogging.java +++ b/sources/simulator/VSLogging.java @@ -10,11 +10,14 @@ import javax.swing.*; import utils.*; -// TODO: Auto-generated Javadoc /** - * The Class VSLogging. + * The Class VSLogging. An object of this class is responsible for the logging + * of text messages into the simulator's logging window. + * + * @author Paul C. Buetow */ public class VSLogging { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** The logging area. */ @@ -23,7 +26,9 @@ public class VSLogging { /** The filter text. */ private String filterText; - /** The pause lines. */ + /** The pause lines. Used for cacheing the logging if the logging is + * deactivated for a while + */ private ArrayList pauseLines; /** The logging lines. */ @@ -32,17 +37,17 @@ public class VSLogging { /** The simulation canvas. */ private VSSimulatorCanvas simulationCanvas; - /** The is filtered. */ + /** The logging messages are filtered. */ private boolean isFiltered; - /** The is paused. */ + /** The logging is paused. */ private boolean isPaused; /** The filter pattern. */ private Pattern filterPattern; /** - * Instantiates a new lang.process.removelogging. + * Instantiates a new VSLogging object. */ public VSLogging() { loggingArea = new JTextArea(0, 0); @@ -57,7 +62,7 @@ public class VSLogging { /** * Sets the simulation canvas. * - * @param simulationCanvas the new simulation canvas + * @param simulationCanvas the simulation canvas */ public void setSimulationCanvas(VSSimulatorCanvas simulationCanvas) { this.simulationCanvas = simulationCanvas; @@ -73,7 +78,7 @@ public class VSLogging { } /** - * Logg. + * Loggs a message using the global time. * * @param message the message */ @@ -85,7 +90,7 @@ public class VSLogging { } /** - * Logg. + * Loggs a message using the specified time. * * @param message the message * @param time the time @@ -103,9 +108,9 @@ public class VSLogging { } /** - * Checks if is paused. + * Sets if the logging is paused. * - * @param isPaused the is paused + * @param isPaused true, if the logging is paused */ public synchronized void isPaused(boolean isPaused) { this.isPaused = isPaused; @@ -119,26 +124,29 @@ public class VSLogging { } /** - * Logg filtered. + * If the logging is filtered, it's using the pattern matching. * - * @param buffer the buffer + * @param buffer the logging buffer to filter */ private void loggFiltered(StringBuffer buffer) { loggingLines.add(buffer); if (!isFiltered) { loggingArea.append(buffer.toString()+"\n"); - loggingArea.setCaretPosition(loggingArea.getDocument().getLength()); + loggingArea.setCaretPosition( + loggingArea.getDocument().getLength()); - } else if (filterPattern != null && filterPattern.matcher(buffer).find()) { + } else if (filterPattern != null && + filterPattern.matcher(buffer).find()) { loggingArea.append(buffer.toString()+"\n"); - loggingArea.setCaretPosition(loggingArea.getDocument().getLength()); + loggingArea.setCaretPosition( + loggingArea.getDocument().getLength()); } } /** - * Checks if is filtered. + * Checks if the logging is filtered. * - * @param isFiltered the is filtered + * @param isFiltered true, if the logging is filtered */ public synchronized void isFiltered(boolean isFiltered) { this.isFiltered = isFiltered; @@ -160,7 +168,7 @@ public class VSLogging { } /** - * Clear. + * Clears the logging. */ public synchronized void clear() { loggingLines.clear(); @@ -169,7 +177,7 @@ public class VSLogging { } /** - * Filter. + * Filters the logging. */ private void filter() { try { diff --git a/sources/simulator/VSMain.java b/sources/simulator/VSMain.java index f8a6df8..b8aa84a 100644 --- a/sources/simulator/VSMain.java +++ b/sources/simulator/VSMain.java @@ -11,15 +11,18 @@ import events.*; import prefs.*; import prefs.editors.*; -// TODO: Auto-generated Javadoc /** - * The Class VSMain. + * The Class VSMain. This class contains the static main method. The simulator + * starts here! + * + * @author Paul C. Buetow */ public class VSMain { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** - * Instantiates a new lang.process.removemain. + * Instantiates a new VSMain object. * * @param prefs the prefs */ @@ -28,24 +31,27 @@ public class VSMain { } /** - * Instantiates a new lang.process.removemain. + * Instantiates a new VSMain object * * @param prefs the prefs - * @param relativeTo the relative to + * @param relativeTo the component to open the window relative to */ public VSMain(VSPrefs prefs, Component relativeTo) { init(prefs, relativeTo); } /** - * Inits the. + * Inits the VSMain object. * * @param prefs the prefs - * @param relativeTo the relative to + * @param relativeTo the component to open the window relative to */ private void init(VSPrefs prefs, Component relativeTo) { - VSSimulatorFrame simulatorFrame = new VSSimulatorFrame(prefs, relativeTo); - new VSEditorFrame(prefs, relativeTo, new VSSimulatorEditor(prefs, simulatorFrame)); + VSSimulatorFrame simulatorFrame = + new VSSimulatorFrame(prefs, relativeTo); + + new VSEditorFrame(prefs, relativeTo, + new VSSimulatorEditor(prefs, simulatorFrame)); } /** diff --git a/sources/simulator/VSMenuItemStates.java b/sources/simulator/VSMenuItemStates.java index ba901de..b751b29 100644 --- a/sources/simulator/VSMenuItemStates.java +++ b/sources/simulator/VSMenuItemStates.java @@ -7,8 +7,11 @@ package simulator; /** * The Class VSMenuItemStates. Used by the VSSimulation to update the * "simulation" bar of the VSSimulationFrame. + * + * @author Paul C. Buetow */ public class VSMenuItemStates { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** The pause state. */ @@ -24,14 +27,15 @@ public class VSMenuItemStates { private volatile boolean start; /** - * Instantiates a new lang.process.removemenu item states. + * Instantiates a new VSMenuItemStates object. * * @param pause the pause state * @param replay the replay state * @param reset the reset state * @param start the start state */ - public VSMenuItemStates(boolean pause, boolean replay, boolean reset, boolean start) { + public VSMenuItemStates(boolean pause, boolean replay, boolean reset, + boolean start) { this.pause = pause; this.replay = replay; this.reset = reset; diff --git a/sources/simulator/VSSimulator.java b/sources/simulator/VSSimulator.java index 3497dd1..be368fd 100644 --- a/sources/simulator/VSSimulator.java +++ b/sources/simulator/VSSimulator.java @@ -19,10 +19,15 @@ import prefs.editors.*; import utils.*; /** - * The Class VSSimulator. + * The Class VSSimulator. An object of this class represents a whole simulation. + * It may be, that several parallel simulations exist. They are independent + * fron each other. + * + * @author Paul C. Buetow */ public class VSSimulator extends JPanel { - private static final long serialVersionUID = 1L; + /** the serial version uid */ + private static final long serialversionuid = 1l; /** The global text fields. */ private ArrayList globalTextFields; @@ -30,7 +35,7 @@ public class VSSimulator extends JPanel { /** The local text fields. */ private ArrayList localTextFields; - /** The create tasks. */ + /** The create tasks array list. */ private ArrayList createTasks; /** The filter active check box. */ @@ -117,12 +122,15 @@ public class VSSimulator extends JPanel { /** The task manager local model. */ private VSTaskManagerTableModel taskManagerLocalModel; - /** The has started. */ + /** The simulation has started. */ private boolean hasStarted = false; /** The last selected process num. */ private int lastSelectedProcessNum; + /** The last expert state. */ + private boolean lastExpertState; + /** The simulation counter. */ private static int simulationCounter; @@ -130,7 +138,222 @@ public class VSSimulator extends JPanel { private static int simulationNum; /** - * Instantiates a new lang.process.removesimulator. + * The Class VSTaskManagerTableModel. An object of this class handles + * the task manager's JTable. + */ + private class VSTaskManagerTableModel extends AbstractTableModel + implements MouseListener { + /** the serial version uid */ + private static final long serialversionuid = 1l; + + /** The Constant LOCAL. */ + public static final boolean LOCAL = true; + + /** The Constant GLOBAL. */ + public static final boolean GLOBAL = false; + + /** The Constant ALL_PROCESSES. */ + public static final boolean ALL_PROCESSES = true; + + /** The Constant ONE_PROCESS. */ + public static final boolean ONE_PROCESS = false; + + /** The all processes. */ + public boolean allProcesses; + + /** The tasks. */ + private VSPriorityQueue tasks; + + /** The column names. */ + private String columnNames[]; + + /** The num columns. */ + private int numColumns; + + /** The table. */ + private JTable table; + + /** + * Instantiates a new VSTaskManagerTableModel object + * + * @param process the process + * @param localTask true, if this table manages the local task. false, + * if this table manages the global tasks. + */ + public VSTaskManagerTableModel(VSProcess process, boolean localTask) { + set(process, localTask, ONE_PROCESS); + columnNames = new String[3]; + columnNames[0]= prefs.getString("lang.time") + " (ms)"; + columnNames[1] = prefs.getString("lang.process.id"); + columnNames[2] = prefs.getString("lang.event"); + numColumns = 3; + } + + /** + * Sets the table. + * + * @param table the table + */ + public void setTable(JTable table) { + this.table = table; + } + + /** + * Sets new values. + * + * @param process the process + * @param localTasks true, if this table manages the local tasks. false + * if this table manages the global tasks. + * @param allProcesses true, if this table shows tasks of all processes. + * false, if this table only shows tasks of the specified process. + */ + public void set(VSProcess process, boolean localTasks, + boolean allProcesses) { + this.allProcesses = allProcesses; + + if (allProcesses) { + this.tasks = localTasks + ? taskManager.getLocalTasks() + : taskManager.getGlobalTasks(); + } else { + this.tasks = localTasks + ? taskManager.getProcessLocalTasks(process) + : taskManager.getProcessGlobalTasks(process); + } + + fireTableDataChanged(); + } + + /* (non-Javadoc) + * @see javax.swing.table.AbstractTableModel#getColumnName(int) + */ + public String getColumnName(int col) { + return columnNames[col]; + } + + /* (non-Javadoc) + * @see javax.swing.table.TableModel#getRowCount() + */ + public int getRowCount() { + return tasks == null ? 0 : tasks.size(); + } + + /* (non-Javadoc) + * @see javax.swing.table.TableModel#getColumnCount() + */ + public int getColumnCount() { + return numColumns; + } + + /* (non-Javadoc) + * @see javax.swing.table.TableModel#getValueAt(int, int) + */ + public Object getValueAt(int row, int col) { + VSTask task = tasks.get(row); + + switch (col) { + case 0: + return task.getTaskTime(); + case 1: + return task.getProcess().getProcessID(); + } + + return task.getEvent().getShortname(); + } + + /* (non-Javadoc) + * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int) + */ + public boolean isCellEditable(int row, int col) { + return false; + } + + /* (non-Javadoc) + * @see javax.swing.table.AbstractTableModel#setValueAt( + * java.lang.Object, int, int) + */ + public void setValueAt(Object value, int row, int col) { + fireTableDataChanged(); + } + + /** + * Adds the task. + * + * @param task the task + */ + public void addTask(VSTask task) { + tasks.add(task); + fireTableDataChanged(); + } + + /** + * Removes the task at a specified row. + * + * @param row the row + */ + private void removeTaskAtRow(int row) { + VSTask task = tasks.get(row); + tasks.remove(task); + taskManager.removeTask(task); + fireTableDataChanged(); + } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseClicked( + * java.awt.event.MouseEvent) + */ + public void mouseClicked(MouseEvent me) { + JTable source = (JTable) me.getSource(); + final int row = source.rowAtPoint(me.getPoint()); + final int col = source.columnAtPoint(me.getPoint()); + + if (SwingUtilities.isRightMouseButton(me)) { + ActionListener actionListener = new ActionListener() { + public void actionPerformed(ActionEvent ae) { + String command = ae.getActionCommand(); + if (command.equals(prefs.getString("lang.remove"))) { + removeTaskAtRow(row); + } + } + }; + + JPopupMenu popup = new JPopupMenu(); + JMenuItem item = new JMenuItem(prefs.getString("lang.remove")); + item.addActionListener(actionListener); + popup.add(item); + + popup.show(me.getComponent(), me.getX(), me.getY()); + } + } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseEntered( + * java.awt.event.MouseEvent) + */ + public void mouseEntered(MouseEvent me) { } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseExited( + * java.awt.event.MouseEvent) + */ + public void mouseExited(MouseEvent me) { } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mousePressed( + * java.awt.event.MouseEvent) + */ + public void mousePressed(MouseEvent me) { } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseReleased( + * java.awt.event.MouseEvent) + */ + public void mouseReleased(MouseEvent me) { } + } + + + /** + * Instantiates a new VSSimulator object. * * @param prefs the prefs * @param simulatorFrame the simulator frame @@ -171,7 +394,7 @@ public class VSSimulator extends JPanel { } /** - * Fill content pane. + * Fills the content pane. */ private void fillContentPane() { loggingArea = logging.getLoggingArea(); @@ -195,7 +418,7 @@ public class VSSimulator extends JPanel { loggingPanel.setPreferredSize(new Dimension(200, 1)); splitPaneH.setOrientation(JSplitPane.HORIZONTAL_SPLIT); - splitPaneH.setLeftComponent(createProcessPane()); + splitPaneH.setLeftComponent(createProcessPanel()); splitPaneH.setRightComponent(canvasPanel); splitPaneH.setContinuousLayout(true); splitPaneH.setOneTouchExpandable(true); @@ -208,25 +431,24 @@ public class VSSimulator extends JPanel { this.add(splitPaneV); } - /** The last expert state. */ - private boolean lastExpertState; - /** * Creates the tools panel. * - * @return the j panel + * @return the panel */ private JPanel createToolsPanel() { JPanel toolsPanel = new JPanel(); boolean expertMode = prefs.getBoolean("sim.mode.expert"); toolsPanel.setLayout(new BoxLayout(toolsPanel, BoxLayout.X_AXIS)); + JCheckBox expertActiveCheckBox = + new JCheckBox(prefs.getString("lang.mode.expert")); - JCheckBox expertActiveCheckBox = new JCheckBox(prefs.getString("lang.mode.expert")); expertActiveCheckBox.setSelected(expertMode); expertActiveCheckBox.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { - AbstractButton abstractButton = (AbstractButton) ce.getSource(); + AbstractButton abstractButton = + (AbstractButton) ce.getSource(); ButtonModel buttonModel = abstractButton.getModel(); boolean newState = buttonModel.isSelected(); if (lastExpertState != newState) { @@ -239,11 +461,13 @@ public class VSSimulator extends JPanel { toolsPanel.add(expertActiveCheckBox); if (expertMode) { - lamportActiveCheckBox = new JCheckBox(prefs.getString("lang.time.lamport")); + lamportActiveCheckBox = new JCheckBox( + prefs.getString("lang.time.lamport")); lamportActiveCheckBox.setSelected(false); lamportActiveCheckBox.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { - AbstractButton abstractButton = (AbstractButton) ce.getSource(); + AbstractButton abstractButton = + (AbstractButton) ce.getSource(); ButtonModel buttonModel = abstractButton.getModel(); simulationCanvas.showLamport(buttonModel.isSelected()); if (buttonModel.isSelected()) @@ -252,11 +476,13 @@ public class VSSimulator extends JPanel { }); toolsPanel.add(lamportActiveCheckBox); - vectorTimeActiveCheckBox = new JCheckBox(prefs.getString("lang.time.vector")); + vectorTimeActiveCheckBox = new JCheckBox( + prefs.getString("lang.time.vector")); vectorTimeActiveCheckBox.setSelected(false); vectorTimeActiveCheckBox.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { - AbstractButton abstractButton = (AbstractButton) ce.getSource(); + AbstractButton abstractButton = + (AbstractButton) ce.getSource(); ButtonModel buttonModel = abstractButton.getModel(); simulationCanvas.showVectorTime(buttonModel.isSelected()); if (buttonModel.isSelected()) @@ -265,11 +491,13 @@ public class VSSimulator extends JPanel { }); toolsPanel.add(vectorTimeActiveCheckBox); - JCheckBox antiAliasing = new JCheckBox(prefs.getString("lang.antialiasing")); + JCheckBox antiAliasing = new JCheckBox( + prefs.getString("lang.antialiasing")); antiAliasing.setSelected(false); antiAliasing.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { - AbstractButton abstractButton = (AbstractButton) ce.getSource(); + AbstractButton abstractButton = + (AbstractButton) ce.getSource(); ButtonModel buttonModel = abstractButton.getModel(); simulationCanvas.isAntiAliased(buttonModel.isSelected()); } @@ -277,11 +505,13 @@ public class VSSimulator extends JPanel { toolsPanel.add(antiAliasing); } - JCheckBox loggingActiveCheckBox = new JCheckBox(prefs.getString("lang.logging.active")); + JCheckBox loggingActiveCheckBox = new JCheckBox( + prefs.getString("lang.logging.active")); loggingActiveCheckBox.setSelected(true); loggingActiveCheckBox.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { - AbstractButton abstractButton = (AbstractButton) ce.getSource(); + AbstractButton abstractButton = + (AbstractButton) ce.getSource(); ButtonModel buttonModel = abstractButton.getModel(); logging.isPaused(!buttonModel.isSelected()); } @@ -289,11 +519,13 @@ public class VSSimulator extends JPanel { toolsPanel.add(loggingActiveCheckBox); if (expertMode) { - filterActiveCheckBox = new JCheckBox(prefs.getString("lang.filter")); + filterActiveCheckBox = new JCheckBox( + prefs.getString("lang.filter")); filterActiveCheckBox.setSelected(false); filterActiveCheckBox.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { - AbstractButton abstractButton = (AbstractButton) ce.getSource(); + AbstractButton abstractButton = + (AbstractButton) ce.getSource(); ButtonModel buttonModel = abstractButton.getModel(); logging.isFiltered(buttonModel.isSelected()); if (buttonModel.isSelected()) @@ -303,26 +535,27 @@ public class VSSimulator extends JPanel { toolsPanel.add(filterActiveCheckBox); filterTextField = new JTextField(); - filterTextField.getDocument().addDocumentListener(new DocumentListener() { + filterTextField.getDocument().addDocumentListener( + new DocumentListener() { public void insertUpdate(DocumentEvent de) { logging.setFilterText(filterTextField.getText()); } - public void removeUpdate(DocumentEvent de) { logging.setFilterText(filterTextField.getText()); } - public void changedUpdate(DocumentEvent de) { logging.setFilterText(filterTextField.getText()); } }); toolsPanel.add(filterTextField); - JButton clearButton = new JButton(prefs.getString("lang.logging.clear")); + JButton clearButton = new JButton( + prefs.getString("lang.logging.clear")); clearButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { - String actionCommand = ae.getActionCommand(); - if (actionCommand.equals(prefs.getString("lang.logging.clear"))) { + String command = ae.getActionCommand(); + if (command.equals( + prefs.getString("lang.logging.clear"))) { logging.clear(); } } @@ -334,11 +567,11 @@ public class VSSimulator extends JPanel { } /** - * Creates the process pane. + * Creates the process panel. * - * @return the j panel + * @return the panel */ - private JPanel createProcessPane() { + private JPanel createProcessPanel() { JPanel editPanel = new JPanel(new GridBagLayout()); boolean expertMode = prefs.getBoolean("sim.mode.expert"); editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.Y_AXIS)); @@ -362,7 +595,8 @@ public class VSSimulator extends JPanel { localPIDComboBox.addItem(prefs.getString("lang.all")); globalPIDComboBox.addItem(prefs.getString("lang.all")); - tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT); + tabbedPane = new JTabbedPane(JTabbedPane.TOP, + JTabbedPane.WRAP_TAB_LAYOUT); localPanel = createTaskLabel(VSTaskManagerTableModel.LOCAL); JPanel globalPanel = createTaskLabel(VSTaskManagerTableModel.GLOBAL); @@ -380,8 +614,10 @@ public class VSSimulator extends JPanel { processesComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { - localTextFields.set(lastSelectedProcessNum, localTextField.getText()); - globalTextFields.set(lastSelectedProcessNum, globalTextField.getText()); + localTextFields.set(lastSelectedProcessNum, + localTextField.getText()); + globalTextFields.set(lastSelectedProcessNum, + globalTextField.getText()); updateTaskManagerTable(); int processNum = getSelectedProcessNum(); @@ -405,8 +641,10 @@ public class VSSimulator extends JPanel { if (processNum != simulationCanvas.getNumProcesses()) { VSProcess process = getSelectedProcess(); - VSProcessEditor processEditor = new VSProcessEditor(prefs, process); - tabbedPane.setComponentAt(1, processEditor.getContentPane()); + VSProcessEditor processEditor = + new VSProcessEditor(prefs, process); + tabbedPane.setComponentAt(1, + processEditor.getContentPane()); } } }); @@ -424,7 +662,7 @@ public class VSSimulator extends JPanel { * * @param text the text * - * @return the j panel + * @return the panel */ private JPanel createLabelPanel(String text) { JPanel panel = new JPanel(); @@ -437,9 +675,10 @@ public class VSSimulator extends JPanel { /** * Creates the task label. * - * @param localTasks the local tasks + * @param localTasks true, if the local task label has to get created. + * false, if the global task label has to get created. * - * @return the j panel + * @return the panel */ private JPanel createTaskLabel(boolean localTasks) { JPanel panel = new JPanel(new GridBagLayout()); @@ -461,347 +700,18 @@ public class VSSimulator extends JPanel { return panel; } - /** - * The Class VSCreateTask. - */ - private class VSCreateTask { - - /** The event classname. */ - private String eventClassname; - - /** The protocol classname. */ - private String protocolClassname; - - /** The shortname. */ - private String shortname; - - /* Those 3 values are for VSProtocolEvent events */ - /** The is protocol activation. */ - private boolean isProtocolActivation; - - /** The is protocol deactivation. */ - private boolean isProtocolDeactivation; - - /** The is client protocol. */ - private boolean isClientProtocol; - - /* Those values are for ProtocolClient onStart events */ - /** The is client request. */ - private boolean isRequest; - - /** - * Instantiates a new lang.process.removecreate task. - * - * @param eventClassname the event classname - */ - public VSCreateTask(String eventClassname) { - this.eventClassname = eventClassname; - } - - /** - * Checks if is protocol activation. - * - * @param isProtocolActivation the is protocol activation - */ - public void isProtocolActivation(boolean isProtocolActivation) { - this.isProtocolActivation = isProtocolActivation; - - if (isProtocolActivation) - isProtocolDeactivation(false); - } - - /** - * Checks if is protocol deactivation. - * - * @param isProtocolDeactivation the is protocol deactivation - */ - public void isProtocolDeactivation(boolean isProtocolDeactivation) { - this.isProtocolDeactivation = isProtocolDeactivation; - - if (isProtocolDeactivation) - isProtocolActivation(false); - } - - /** - * Checks if is client protocol. - * - * @param isClientProtocol the is client protocol - */ - public void isClientProtocol(boolean isClientProtocol) { - this.isClientProtocol = isClientProtocol; - } - - /** - * Checks if is client request. - * - * @param isRequest the is client request - */ - public void isRequest(boolean isRequest) { - this.isRequest = isRequest; - } - - /** - * Sets the protocol classname. - * - * @param protocolClassname the new protocol classname - */ - public void setProtocolClassname(String protocolClassname) { - this.protocolClassname = protocolClassname; - } - - /** - * Sets the shortname. - * - * @param shortname the new shortname - */ - public void setShortname(String shortname) { - this.shortname = shortname; - } - - /** - * Creates the task. - * - * @param process the process - * @param time the time - * @param localTimedTask the local timed task - * - * @return the lang.process.removetask - */ - public VSTask createTask(VSProcess process, long time, boolean localTimedTask) { - VSAbstractEvent event = null; - - if (isRequest) { - event = process.getProtocolObject(eventClassname); - - } else { - event = VSRegisteredEvents.createEventInstanceByClassname(eventClassname, process); - } - - event.init(process); - if (shortname != null) - event.setShortname(shortname); - - if (isProtocolActivation || isProtocolDeactivation) { - VSProtocolEvent protocolEvent = (VSProtocolEvent) event; - protocolEvent.setProtocolClassname(protocolClassname); - protocolEvent.isProtocolActivation(isProtocolActivation); - protocolEvent.isClientProtocol(isClientProtocol); - } - - return new VSTask(time, process, event, localTimedTask); - } - } - - /** - * The Class VSTaskManagerTableModel. - */ - private class VSTaskManagerTableModel extends AbstractTableModel implements MouseListener { - - /** The Constant LOCAL. */ - public static final boolean LOCAL = true; - - /** The Constant GLOBAL. */ - public static final boolean GLOBAL = false; - - /** The Constant ALL_PROCESSES. */ - public static final boolean ALL_PROCESSES = true; - - /** The Constant ONE_PROCESS. */ - public static final boolean ONE_PROCESS = false; - - /** The all processes. */ - public boolean allProcesses; - - /** The tasks. */ - private VSPriorityQueue tasks; - - /** The column names. */ - private String columnNames[]; - - /** The num columns. */ - private int numColumns; - - /** The table. */ - private JTable table; - - /** - * Instantiates a new lang.process.removetask manager table model. - * - * @param process the process - * @param localTask the local task - */ - public VSTaskManagerTableModel(VSProcess process, boolean localTask) { - set(process, localTask, ONE_PROCESS); - columnNames = new String[3]; - columnNames[0]= prefs.getString("lang.time") + " (ms)"; - columnNames[1] = prefs.getString("lang.process.id"); - columnNames[2] = prefs.getString("lang.event"); - numColumns = 3; - } - - /** - * Sets the table. - * - * @param table the new table - */ - public void setTable(JTable table) { - this.table = table; - } - - /** - * Sets the. - * - * @param process the process - * @param localTasks the local tasks - * @param allProcesses the all processes - */ - public void set(VSProcess process, boolean localTasks, boolean allProcesses) { - this.allProcesses = allProcesses; - - if (allProcesses) { - this.tasks = localTasks - ? taskManager.getLocalTasks() - : taskManager.getGlobalTasks(); - } else { - this.tasks = localTasks - ? taskManager.getProcessLocalTasks(process) - : taskManager.getProcessGlobalTasks(process); - } - - fireTableDataChanged(); - } - - /* (non-Javadoc) - * @see javax.swing.table.AbstractTableModel#getColumnName(int) - */ - public String getColumnName(int col) { - return columnNames[col]; - } - - /* (non-Javadoc) - * @see javax.swing.table.TableModel#getRowCount() - */ - public int getRowCount() { - return tasks == null ? 0 : tasks.size(); - } - - /* (non-Javadoc) - * @see javax.swing.table.TableModel#getColumnCount() - */ - public int getColumnCount() { - return numColumns; - } - - /* (non-Javadoc) - * @see javax.swing.table.TableModel#getValueAt(int, int) - */ - public Object getValueAt(int row, int col) { - VSTask task = tasks.get(row); - - switch (col) { - case 0: - return task.getTaskTime(); - case 1: - return task.getProcess().getProcessID(); - } - - return task.getEvent().getShortname(); - } - - /* (non-Javadoc) - * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int) - */ - public boolean isCellEditable(int row, int col) { - return false; - } - - /* (non-Javadoc) - * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, int, int) - */ - public void setValueAt(Object value, int row, int col) { - fireTableDataChanged(); - } - - /** - * Adds the task. - * - * @param task the task - */ - public void addTask(VSTask task) { - tasks.add(task); - fireTableDataChanged(); - } - - /** - * Removes the task at row. - * - * @param row the row - */ - private void removeTaskAtRow(int row) { - VSTask task = tasks.get(row); - tasks.remove(task); - taskManager.removeTask(task); - fireTableDataChanged(); - } - - /* (non-Javadoc) - * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) - */ - public void mouseClicked(MouseEvent me) { - JTable source = (JTable) me.getSource(); - final int row = source.rowAtPoint(me.getPoint()); - final int col = source.columnAtPoint(me.getPoint()); - - if (SwingUtilities.isRightMouseButton(me)) { - ActionListener actionListener = new ActionListener() { - public void actionPerformed(ActionEvent ae) { - String actionCommand = ae.getActionCommand(); - if (actionCommand.equals(prefs.getString("lang.remove"))) { - removeTaskAtRow(row); - } - } - }; - - JPopupMenu popup = new JPopupMenu(); - JMenuItem item = new JMenuItem(prefs.getString("lang.remove")); - item.addActionListener(actionListener); - popup.add(item); - - popup.show(me.getComponent(), me.getX(), me.getY()); - } - } - - /* (non-Javadoc) - * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) - */ - public void mouseEntered(MouseEvent me) { } - - /* (non-Javadoc) - * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) - */ - public void mouseExited(MouseEvent me) { } - - /* (non-Javadoc) - * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) - */ - public void mousePressed(MouseEvent me) { } - - /* (non-Javadoc) - * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) - */ - public void mouseReleased(MouseEvent me) { } - } - /** * Creates the task table. * - * @param localTasks the local tasks + * @param localTasks true, if the local task label has to get created. + * false, if the global task label has to get created. * - * @return the j table + * @return the table */ private JTable createTaskTable(boolean localTasks) { VSProcess process = getSelectedProcess(); - VSTaskManagerTableModel model = new VSTaskManagerTableModel(process, localTasks); + VSTaskManagerTableModel model = + new VSTaskManagerTableModel(process, localTasks); if (localTasks) taskManagerLocalModel = model; @@ -831,9 +741,10 @@ public class VSSimulator extends JPanel { * Inits the add panel. * * @param panel the panel - * @param localTasks the local tasks + * @param localTasks true, if the local task label has to get created. + * false, if the global task label has to get created. * - * @return the j panel + * @return the panel */ private JPanel initAddPanel(JPanel panel, final boolean localTasks) { JPanel addPanel = new JPanel(); @@ -863,7 +774,6 @@ public class VSSimulator extends JPanel { JButton takeoverButton = new JButton(prefs.getString("lang.takeover")); takeoverButton.addActionListener(new ActionListener() { private boolean isRed; - public void actionPerformed(ActionEvent ae) { String textValue = textField.getText(); Long longValue = null; @@ -914,13 +824,16 @@ public class VSSimulator extends JPanel { if (createTask == null) return false; - ArrayList processes = getConcernedProcesses(localTasks); + ArrayList processes = + getConcernedProcesses(localTasks); for (VSProcess process : processes) { - VSTask task = createTask.createTask(process, time, localTasks); + VSTask task = createTask.createTask(process, time, + localTasks); taskManager.addTask(task, VSTaskManager.PROGRAMMED); - if (selectedProcess == null || process.equals(selectedProcess)) { + if (selectedProcess == null || + process.equals(selectedProcess)) { if (localTasks) taskManagerLocalModel.addTask(task); else @@ -937,15 +850,18 @@ public class VSSimulator extends JPanel { boolean createTaskFlag = createTasks == null; if (createTaskFlag) createTasks = new ArrayList(); - Vector eventClassnames = VSRegisteredEvents.getNonProtocolClassnames(); + Vector eventClassnames = + VSRegisteredEvents.getNonProtocolClassnames(); comboBox.setMaximumRowCount(20); - comboBox.addItem("----- " + prefs.getString("lang.events.process") + " -----"); + comboBox.addItem("----- " + prefs.getString("lang.events.process") + + " -----"); if (createTaskFlag) createTasks.add(null); for (String eventClassname : eventClassnames) { - String eventShortname = VSRegisteredEvents.getShortnameByClassname(eventClassname); + String eventShortname = + VSRegisteredEvents.getShortnameByClassname(eventClassname); comboBox.addItem(eventShortname); if (createTaskFlag) createTasks.add(new VSCreateTask(eventClassname)); @@ -963,14 +879,15 @@ public class VSSimulator extends JPanel { eventClassnames = VSRegisteredEvents.getProtocolClassnames(); for (String eventClassname : eventClassnames) { - String eventShortname_ = VSRegisteredEvents.getShortnameByClassname(eventClassname); + String eventShortname_ = + VSRegisteredEvents.getShortnameByClassname(eventClassname); String eventShortname = null; - comboBox.addItem("----- " + eventShortname_ + " " + protocol + " -----"); + comboBox.addItem("----- " + eventShortname_ + " " + + protocol + " -----"); if (createTaskFlag) createTasks.add(null); - if (VSRegisteredEvents.isOnServerStartProtocol(eventClassname)) eventShortname = eventShortname_ + " " + serverRequest; else @@ -987,7 +904,8 @@ public class VSSimulator extends JPanel { eventShortname = eventShortname_ + " " + client + " " + activate; comboBox.addItem(eventShortname); if (createTaskFlag) { - VSCreateTask createTask = new VSCreateTask(protocolEventClassname); + VSCreateTask createTask = + new VSCreateTask(protocolEventClassname); createTask.isProtocolActivation(true); createTask.isClientProtocol(true); createTask.setProtocolClassname(eventClassname); @@ -998,7 +916,8 @@ public class VSSimulator extends JPanel { eventShortname = eventShortname_ + " " + client + " " + deactivate; comboBox.addItem(eventShortname); if (createTaskFlag) { - VSCreateTask createTask = new VSCreateTask(protocolEventClassname); + VSCreateTask createTask = + new VSCreateTask(protocolEventClassname); createTask.isProtocolDeactivation(true); createTask.isClientProtocol(true); createTask.setProtocolClassname(eventClassname); @@ -1009,7 +928,8 @@ public class VSSimulator extends JPanel { eventShortname = eventShortname_ + " " + server + " " + activate; comboBox.addItem(eventShortname); if (createTaskFlag) { - VSCreateTask createTask = new VSCreateTask(protocolEventClassname); + VSCreateTask createTask = + new VSCreateTask(protocolEventClassname); createTask.isProtocolActivation(true); createTask.isClientProtocol(false); createTask.setProtocolClassname(eventClassname); @@ -1020,7 +940,8 @@ public class VSSimulator extends JPanel { eventShortname = eventShortname_ + " " + server + " " + deactivate; comboBox.addItem(eventShortname); if (createTaskFlag) { - VSCreateTask createTask = new VSCreateTask(protocolEventClassname); + VSCreateTask createTask = + new VSCreateTask(protocolEventClassname); createTask.isProtocolDeactivation(true); createTask.isClientProtocol(false); createTask.setProtocolClassname(eventClassname); @@ -1075,7 +996,8 @@ public class VSSimulator extends JPanel { /** * Gets the concerned processes. * - * @param localTasks the local tasks + * @param localTasks true, if this table manages the local tasks. false + * if this table manages the global tasks. * * @return the concerned processes */ @@ -1099,12 +1021,14 @@ public class VSSimulator extends JPanel { public void updateTaskManagerTable() { VSProcess process = getSelectedProcess(); boolean allProcesses = process == null; - taskManagerLocalModel.set(process, VSTaskManagerTableModel.LOCAL, allProcesses); - taskManagerGlobalModel.set(process, VSTaskManagerTableModel.GLOBAL, allProcesses); + taskManagerLocalModel.set(process, + VSTaskManagerTableModel.LOCAL, allProcesses); + taskManagerGlobalModel.set(process, + VSTaskManagerTableModel.GLOBAL, allProcesses); } /** - * Finish. + * The simulation has finished. */ public void finish() { menuItemStates.setStart(false); @@ -1159,7 +1083,7 @@ public class VSSimulator extends JPanel { } /** - * Removes the process at index. + * Removes the process at a specified index. * * @param index the index */ @@ -1180,7 +1104,7 @@ public class VSSimulator extends JPanel { } /** - * Adds the process at index. + * Adds the process at a specified index. * * @param index the index */ @@ -1199,7 +1123,7 @@ public class VSSimulator extends JPanel { } /** - * Fire expert mode changed. + * Fire expert mode changed. Tell, that the expert mode has changed. */ public void fireExpertModeChanged() { boolean expertMode = prefs.getBoolean("sim.mode.expert"); @@ -1209,7 +1133,8 @@ public class VSSimulator extends JPanel { if (expertMode) { tabbedPane.remove(localPanel); - tabbedPane.insertTab(prefs.getString("lang.events"), null, splitPane1, null, 0); + tabbedPane.insertTab(prefs.getString("lang.events"), null, + splitPane1, null, 0); splitPane1.setTopComponent(localPanel); //splitPane1.setDividerLocation((int) (getPaintSize()/2) - 20); @@ -1218,7 +1143,8 @@ public class VSSimulator extends JPanel { } else { tabbedPane.remove(splitPane1); - tabbedPane.insertTab(prefs.getString("lang.events"), null, localPanel, null, 0); + tabbedPane.insertTab(prefs.getString("lang.events"), null, + localPanel, null, 0); /* addPanel */ localAddPanel.remove(2); diff --git a/sources/simulator/VSSimulatorCanvas.java b/sources/simulator/VSSimulatorCanvas.java index 95d7e2c..924c08f 100644 --- a/sources/simulator/VSSimulatorCanvas.java +++ b/sources/simulator/VSSimulatorCanvas.java @@ -18,11 +18,17 @@ import events.internal.*; import prefs.*; import prefs.editors.*; -// TODO: Auto-generated Javadoc /** - * The Class VSSimulatorCanvas. + * The Class VSSimulatorCanvas. An instance of this object represents the + * graphical paint area of a simulation. It contains all graphic calculations. + * Also the simulation thread takes place in this class in a loop! This class + * is probably the most cryptic of the whole simulator source code. This is + * this way in order to gain more performance of the painting area! + * + * @author Paul C. Buetow */ -public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionListener, MouseListener, HierarchyBoundsListener { +public class VSSimulatorCanvas extends Canvas implements Runnable { + /** The serial version uid */ private static final long serialVersionUID = 1L; /** The highlighted process. */ @@ -46,31 +52,31 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi /** The thread sleep. */ private int threadSleep; - /** The until time. */ + /** The until time. Until then goes the simulation? */ private long untilTime; - /** The is paused. */ + /** The simulation is paused. */ private volatile boolean isPaused = true; - /** The is thread stopped. */ - private volatile boolean isThreadStopped = false; + /** The simulation thread is stopped. */ + private volatile boolean hasThreadStopped = false; - /** The is finished. */ + /** The simulation is finished. */ private volatile boolean isFinished = false; - /** The is resetted. */ + /** The simulation is resetted. */ private volatile boolean isResetted = false; - /** The is anti aliased. */ + /** The simulation is anti aliased. */ private volatile boolean isAntiAliased = false; - /** The is anti aliased changed. */ + /** The simulation's anti aliasing has changed. */ private volatile boolean isAntiAliasedChanged = false; - /** The show lamport. */ + /** The simulation shows the lamport time. */ private volatile boolean showLamport = false; - /** The show vector time. */ + /** The simulation shows the vector time. */ private volatile boolean showVectorTime = false; /** The pause time. */ @@ -79,10 +85,10 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi /** The start time. */ private volatile long startTime; - /** The time. */ + /** The global time. */ private volatile long time; - /** The last time. */ + /** The last global time. */ private volatile long lastTime; /** The task manager. */ @@ -103,14 +109,49 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi /** The simulation time. */ private long simulationTime; + /** The x paint size. */ + double xPaintSize; + + /** The paint size. */ + double paintSize; + + /** The y distance. */ + double yDistance; + + /** The global time x position. */ + double globalTimeXPosition; + + /** The xoffset_plus_xpaintsize. */ + int xoffset_plus_xpaintsize; + + /** The xpaintsize_dividedby_untiltime. */ + double xpaintsize_dividedby_untiltime; + + /** The paint processes offset. */ + int paintProcessesOffset; + + /** The paint secondlines seconds. */ + int paintSecondlinesSeconds; + + /** The paint secondlines line. */ + int paintSecondlinesLine[] = new int[4]; + + /** The paint secondlines y string pos1. */ + int paintSecondlinesYStringPos1; + + /** The paint secondlines y string pos2. */ + int paintSecondlinesYStringPos2; + + /** The paint global time y position. */ + int paintGlobalTimeYPosition; + /* GFX buffering */ - /** The strategy. */ + /** The strategy for buffering. */ private BufferStrategy strategy; - /** The g. */ + /** The graphics object to paint at. */ private Graphics2D g; - /* Static constats */ /** The Constant LINE_WIDTH. */ private static final int LINE_WIDTH = 5; @@ -161,9 +202,14 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi private long messageLineCounter; /** - * The Class VSMessageLine. + * The Class VSMessageLine. An object of this class represents a message + * line drawn into the painting area. + * + * @author Paul C. Buetow */ public class VSMessageLine { + /** The serial version uid */ + private static final long serialVersionUID = 1L; /** The receiver process. */ private VSProcess receiverProcess; @@ -189,10 +235,10 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi /** The offset2. */ private int offset2; - /** The is arrived. */ + /** The message has arrived. */ private boolean isArrived; - /** The is lost. */ + /** The message is lost. */ private boolean isLost; /** The x1. */ @@ -226,7 +272,7 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi private VSTask task; /** - * Instantiates a new lang.process.removemessage line. + * Instantiates a new VSMessageLine object. * * @param receiverProcess the receiver process * @param sendTime the send time @@ -284,9 +330,9 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi } /** - * Draw. + * Draws the message line. * - * @param g the g + * @param g the grpahics object to draw at * @param globalTime the global time */ public void draw(final Graphics2D g, final long globalTime) { @@ -320,11 +366,13 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi } /** - * Removes the process at index. + * Called if a process within the simulation has been removed at a + * specified index. * * @param index the index * - * @return true, if successful + * @return true, if the sender or the receiver of the message has been + * removed from the simulation. Else false is returned. */ public boolean removedAProcessAtIndex(int index) { if (index == receiverNum || index == senderNum) @@ -351,11 +399,12 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi } /** - * Equals. + * Checks one line to another if they equal (have the same message line + * id) * - * @param line the line + * @param line the line to compare against * - * @return true, if successful + * @return true, if they equal */ public boolean equals(VSMessageLine line) { return messageLineNum == line.getMessageLineNum(); @@ -372,13 +421,14 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi } /** - * Instantiates a new lang.process.removesimulator canvas. + * Instantiates a new VSSimulatorCanvas object. * * @param prefs the prefs * @param simulation the simulation * @param logging the logging */ - public VSSimulatorCanvas(VSPrefs prefs, VSSimulator simulation, VSLogging logging) { + public VSSimulatorCanvas(VSPrefs prefs, VSSimulator simulation, + VSLogging logging) { this.prefs = prefs; this.simulation = simulation; this.logging = logging; @@ -393,50 +443,167 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi for (int i = 0; i < numProcesses; ++i) processes.add(createProcess(i)); - addMouseListener(this); - addMouseMotionListener(this); - addHierarchyBoundsListener(this); - } + final VSPrefs finalPrefs = prefs; + addMouseListener(new MouseListener() { + public void mouseClicked(MouseEvent me) { + final VSProcess process = getProcessAtYPos(me.getY()); + + if (SwingUtilities.isRightMouseButton(me)) { + ActionListener actionListener = new ActionListener() { + public void actionPerformed(ActionEvent ae) { + String command = ae.getActionCommand(); + if (command.equals( + finalPrefs.getString("lang.process.edit"))) { + editProcess(process); + + } else if (command.equals( + finalPrefs.getString("lang.process.crash"))) { + VSAbstractEvent event = + new VSProcessCrashEvent(); + + taskManager.addTask(new VSTask( + process.getGlobalTime(), + process, event, + VSTask.GLOBAL)); + + } else if (command.equals( + finalPrefs.getString("lang.process.recover"))) { + VSAbstractEvent event = + new VSProcessRecoverEvent(); + + taskManager.addTask(new VSTask( + process.getGlobalTime(), + process, event, + VSTask.GLOBAL)); + + } else if (command.equals( + finalPrefs.getString("lang.process.remove"))) { + removeProcess(process); + + } else if (command.equals( + finalPrefs.getString("lang.process.add.new"))) { + addProcess(); + } + } + }; + + JPopupMenu popup = new JPopupMenu(); + JMenuItem item = new JMenuItem( + finalPrefs.getString("lang.process.edit")); + if (process == null) + item.setEnabled(false); + else + item.addActionListener(actionListener); + popup.add(item); - /** The x paint size. */ - double xPaintSize; + item = new JMenuItem( + finalPrefs.getString("lang.process.crash")); - /** The paint size. */ - double paintSize; + if (process == null || process.isCrashed() || isPaused || + time == 0 || isFinished) + item.setEnabled(false); + else + item.addActionListener(actionListener); + popup.add(item); - /** The y distance. */ - double yDistance; + item = new JMenuItem( + finalPrefs.getString("lang.process.recover")); - /** The global time x position. */ - double globalTimeXPosition; + if (process == null || !process.isCrashed() || isPaused || + time == 0 || isFinished) + item.setEnabled(false); + else + item.addActionListener(actionListener); + popup.add(item); - /** The xoffset_plus_xpaintsize. */ - int xoffset_plus_xpaintsize; + item = new JMenuItem( + finalPrefs.getString("lang.process.remove")); - /** The xpaintsize_dividedby_untiltime. */ - double xpaintsize_dividedby_untiltime; + if (process == null) + item.setEnabled(false); + else + item.addActionListener(actionListener); + popup.add(item); - /** The paint processes offset. */ - int paintProcessesOffset; + popup.addSeparator(); - /** The paint secondlines seconds. */ - int paintSecondlinesSeconds; + item = new JMenuItem( + finalPrefs.getString("lang.process.add.new")); - /** The paint secondlines line. */ - int paintSecondlinesLine[] = new int[4]; + item.addActionListener(actionListener); + popup.add(item); - /** The paint secondlines y string pos1. */ - int paintSecondlinesYStringPos1; - /** The paint secondlines y string pos2. */ - int paintSecondlinesYStringPos2; + popup.show(me.getComponent(), me.getX(), me.getY()); - /** The paint global time y position. */ - int paintGlobalTimeYPosition; + } else { + editProcess(process); + } + } + + public void mouseExited(MouseEvent e) { + if (highlightedProcess != null) { + highlightedProcess.highlightOff(); + highlightedProcess = null; + paint(); + } + } + + public void mouseEntered(MouseEvent e) { } + + public void mousePressed(MouseEvent e) { } + + public void mouseReleased(MouseEvent e) { } + + }); + addMouseMotionListener(new MouseMotionListener() { + public void mouseDragged(MouseEvent e) { } + + public void mouseMoved(MouseEvent e) { + VSProcess p = getProcessAtYPos(e.getY()); + + if (p == null) { + if (highlightedProcess != null) { + highlightedProcess.highlightOff(); + highlightedProcess = null; + } + + if (isPaused) + paint(); + + return; + } + + if (highlightedProcess != null) { + if (highlightedProcess.getProcessID() != p.getProcessID()) { + highlightedProcess.highlightOff(); + highlightedProcess = p; + p.highlightOn(); + } + } else { + highlightedProcess = p; + p.highlightOn(); + } + + if (isPaused) + paint(); + } + + }); + + addHierarchyBoundsListener(new HierarchyBoundsListener() { + public void ancestorMoved(HierarchyEvent e) { } + + public void ancestorResized(HierarchyEvent e) { + recalcOnChange(); + } + }); + } - /* This method contains very ugly code. But this has to be in order to gain performance! */ /** - * Recalc on change. + * This method gets called if the window border of the simulator canvas + * has changed. This method contains very ugly code. But this has to be in + * order to gain performance! */ private void recalcOnChange() { processlineColor = prefs.getColor("col.process.line"); @@ -448,8 +615,10 @@ public class VSSimulatorCanvas extends Canvas implements Runnable, MouseMotionLi backgroundColor = prefs.getColor("col.background"); paintSize = simulation.getPaintSize(); - xPaintSize = simulation.getWidth() - (3 * XOFFSET + simulation.getSplitSize()); - yDistance = (simulation.getPaintSize() - 2 * (YOFFSET + YOUTER_SPACEING))/ numProcesses; + xPaintSize = simulation.getWidth() - + (3 * XOFFSET + simulation.getSplitSize()); + yDistance = (simulation.g