diff options
| author | Paul Buetow <paul@buetow.org> | 2008-05-18 15:13:30 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-05-18 15:13:30 +0000 |
| commit | c46ed2242876bfb267ed0b6823c8a3e99ac62dd6 (patch) | |
| tree | 279f9dfd1a9fcc8f91ced6b80ba7e8878ee13b92 /sources/simulator/VSSimulation.java | |
| parent | 34595bc248660a6cd9c51f2b7a18ed33ae31cce4 (diff) | |
TaskManager better.
Diffstat (limited to 'sources/simulator/VSSimulation.java')
| -rw-r--r-- | sources/simulator/VSSimulation.java | 130 |
1 files changed, 107 insertions, 23 deletions
diff --git a/sources/simulator/VSSimulation.java b/sources/simulator/VSSimulation.java index 0b84685..d3547e3 100644 --- a/sources/simulator/VSSimulation.java +++ b/sources/simulator/VSSimulation.java @@ -4,8 +4,9 @@ import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; -import javax.swing.event.*; import javax.swing.border.*; +import javax.swing.event.*; +import javax.swing.table.*; import core.*; import prefs.*; @@ -17,6 +18,7 @@ public class VSSimulation extends VSFrame implements ActionListener { private JCheckBox filterActiveCheckBox; private JCheckBox lamportActiveCheckBox; private JCheckBox vectorTimeActiveCheckBox; + private JComboBox processesComboBox; private JMenuItem pauseItem; private JMenuItem replayItem; private JMenuItem resetItem; @@ -28,6 +30,8 @@ public class VSSimulation extends VSFrame implements ActionListener { private VSPrefs prefs; private VSSimulationPanel simulationPanel; private boolean hasStarted = false; + private VSTaskManagerTableModel taskManagerLocalModel; + private VSTaskManagerTableModel taskManagerGlobalModel; public VSSimulation (VSPrefs prefs, Component relativeTo) { super(prefs.getString("name"), relativeTo); @@ -284,14 +288,14 @@ public class VSSimulation extends VSFrame implements ActionListener { JPanel editPanel = new JPanel(new GridBagLayout()); editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.Y_AXIS)); - JComboBox comboBox = new JComboBox(); + processesComboBox = new JComboBox(); int numProcesses = simulationPanel.getNumProcesses(); String processString = prefs.getString("lang.process"); for (int i = 1; i <= numProcesses; ++i) - comboBox.addItem(processString + " " + i); + processesComboBox.addItem(processString + " " + i); - JPanel localPanel = createTaskLabel(true); - JPanel globalPanel = createTaskLabel(false); + JPanel localPanel = createTaskLabel(VSTaskManagerTableModel.LOCAL); + JPanel globalPanel = createTaskLabel(VSTaskManagerTableModel.GLOBAL); JSplitPane splitPane1 = new JSplitPane(); splitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT); @@ -302,9 +306,15 @@ public class VSSimulation extends VSFrame implements ActionListener { JSplitPane splitPane2 = new JSplitPane(); splitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT); - splitPane2.setTopComponent(comboBox); + splitPane2.setTopComponent(processesComboBox); splitPane2.setBottomComponent(splitPane1); + processesComboBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + updateTaskManagerTable(); + } + }); + return splitPane2; } @@ -333,19 +343,77 @@ public class VSSimulation extends VSFrame implements ActionListener { return panel; } + private class VSTaskManagerTableModel extends AbstractTableModel { + public static final boolean LOCAL = true; + public static final boolean GLOBAL = false; + private VSTaskManager taskManager; + private ArrayList<VSTask> tasks; + private String columnNames[]; + private VSProcess process; + + public VSTaskManagerTableModel(VSProcess process, boolean localTask) { + taskManager = simulationPanel.getTaskManager(); + set(process, localTask); + columnNames = new String[2]; + columnNames[0]= prefs.getString("lang.time") + " (ms)"; + columnNames[1] = prefs.getString("lang.event"); + } + + public void set(VSProcess process, boolean localTasks) { + this.process = process; + this.tasks = localTasks + ? taskManager.getProcessLocalTasks(process) + : taskManager.getProcessGlobalTasks(process); + + fireTableDataChanged(); + } + + public String getColumnName(int col) { + if (col == 0) + return columnNames[0]; + return columnNames[1]; + } + + public int getRowCount() { + return tasks.size(); + } + + public int getColumnCount() { + return 2; + } + + public Object getValueAt(int row, int col) { + VSTask task = tasks.get(row); + + if (col == 0) + return task.getTaskTime(); + + return task.toStringBrief(); + } + + public boolean isCellEditable(int row, int col) { + return false; + } + + public void setValueAt(Object value, int row, int col) { + } + } + private JTable createTaskTable(boolean localTasks) { - String[] columnNames = { prefs.getString("lang.time"), prefs.getString("lang.event") }; - Object[][] data = { - {"foo", "bar" }, - {"foo", "bar" }, - {"foo", "bar" }, - {"foo", "bar" }, - {"foo", "bar" }, - { "baz", "bay" } - }; - - JTable table = new JTable(data, columnNames); - table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + VSProcess process = getSelectedProcess(); + VSTaskManagerTableModel model = new VSTaskManagerTableModel(process, localTasks); + + if (localTasks) + taskManagerLocalModel = model; + else + taskManagerGlobalModel = model; + + JTable table = new JTable(model); + TableColumn col = table.getColumnModel().getColumn(0); + col.setMaxWidth(75); + col.setResizable(false); + col = table.getColumnModel().getColumn(1); + col.sizeWidthToFit(); table.setBackground(Color.WHITE); return table; @@ -361,9 +429,10 @@ public class VSSimulation extends VSFrame implements ActionListener { panel1.add(takeoverButton); JComboBox comboBox = new JComboBox(); + comboBox.setMaximumRowCount(15); comboBox.addItem("-- " + prefs.getString("lang.events.process") + " --"); - comboBox.addItem("Prozessabsturz"); - comboBox.addItem("Prozesswiederbelebung"); + comboBox.addItem(prefs.getString("lang.crash")); + comboBox.addItem(prefs.getString("lang.recover")); comboBox.addItem("-- " + prefs.getString("lang.events.protocol") + " --"); @@ -426,7 +495,7 @@ public class VSSimulation extends VSFrame implements ActionListener { pauseItem.setEnabled(true); resetItem.setEnabled(false); replayItem.setEnabled(true); - runThread(); + registeredProhread(); } else if (source.getText().equals(prefs.getString("lang.pause"))) { startItem.setEnabled(true); @@ -448,11 +517,11 @@ public class VSSimulation extends VSFrame implements ActionListener { resetItem.setEnabled(false); replayItem.setEnabled(true); simulationPanel.reset(); - runThread(); + registeredProhread(); } } - private void runThread() { + private void registeredProhread() { if (hasStarted) { simulationPanel.play(); @@ -463,6 +532,21 @@ public class VSSimulation extends VSFrame implements ActionListener { } } + private VSProcess getSelectedProcess() { + String string = (String) processesComboBox.getSelectedItem(); + int cutLen = prefs.getString("lang.process").length() + 1; + string = string.substring(cutLen); + int processNum = Integer.parseInt(string) - 1; + + return simulationPanel.getProcess(processNum); + } + + public void updateTaskManagerTable() { + VSProcess process = getSelectedProcess(); + taskManagerLocalModel.set(process, VSTaskManagerTableModel.LOCAL); + taskManagerGlobalModel.set(process, VSTaskManagerTableModel.GLOBAL); + } + public void finish() { startItem.setEnabled(false); pauseItem.setEnabled(false); |
