diff options
| -rw-r--r-- | sources/core/VSProcess.java | 4 | ||||
| -rw-r--r-- | sources/prefs/VSDefaultPrefs.java | 36 | ||||
| -rw-r--r-- | sources/simulator/VSSimulation.java | 19 | ||||
| -rw-r--r-- | sources/simulator/VSSimulationCanvas.java | 224 | ||||
| -rw-r--r-- | sources/simulator/VSSimulatorFrame.java | 51 |
5 files changed, 188 insertions, 146 deletions
diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java index 63c27d5..e5e8c9d 100644 --- a/sources/core/VSProcess.java +++ b/sources/core/VSProcess.java @@ -104,8 +104,6 @@ public class VSProcess extends VSPrefs { currentColor = getColor("col.process.default"); /* Make additional process settings editable through GUI */ - initInteger("process.id", processID, - prefs.getString("lang.process.id"), 1, processID + 10); setLongIfUnset("process.localtime", localTime, prefs.getString("lang.process.time.local")); crashedColor = getColor("col.process.crashed"); @@ -144,7 +142,6 @@ public class VSProcess extends VSPrefs { */ public synchronized void updateFromVSPrefs() { setClockVariance(getFloat("process.clock.variance")); - setProcessID(getInteger("process.id")); setLocalTime(getLong("process.localtime")); crashedColor = getColor("col.process.crashed"); //simulationCanvas.repaint(); @@ -156,7 +153,6 @@ public class VSProcess extends VSPrefs { */ public synchronized void updatePrefs() { setFloat("process.clock.variance", getClockVariance()); - setInteger("process.id", getProcessID()); setLong("process.localtime", getTime()); } diff --git a/sources/prefs/VSDefaultPrefs.java b/sources/prefs/VSDefaultPrefs.java index 262f9b0..25e3ef9 100644 --- a/sources/prefs/VSDefaultPrefs.java +++ b/sources/prefs/VSDefaultPrefs.java @@ -39,7 +39,6 @@ public class VSDefaultPrefs extends VSPrefs { } public void fillDefaultStrings() { - initString("lang.mode.expert", "Expertenmodus"); initString("lang.about", "About"); initString("lang.about.info!", "Dieses Programm wurde von Paul Bütow im Rahmen der Diplomarbeit \"Objektorientierte Entwicklung eines GUI-basierten Tools für die ereignisbasierte Simulation verteilter Systeme\" bei Prof. Dr.-Ing. Oßmann erstellt. Dieses Programm stellt noch keinesfalls eine fertige Version dar, da es sich noch in Entwicklung befindet und die Diplomarbeit erst mitte August abgeschlossen sein wird! Bei Fehlern bitte eine kurze Mail mitsamt Fehlerbeschreibung an paul@buetow.org schicken! Dieser Simulator wird später außerdem unter einer open source Linzenz (wahrscheinlich der GNU General Public License) freigegeben!"); initString("lang.activate", "aktivieren"); @@ -53,7 +52,6 @@ public class VSDefaultPrefs extends VSPrefs { initString("lang.close", "Schliessen"); initString("lang.colorchooser", "Farbauswahl"); initString("lang.colorchooser2", "Bitte Farbe auswählen"); - initString("lang.crash", "Abstürzen"); initString("lang.crashed", "Abgestürzt"); initString("lang.deactivate", "deaktivieren"); initString("lang.deactivated", "deaktiviert"); @@ -61,36 +59,41 @@ public class VSDefaultPrefs extends VSPrefs { initString("lang.edit", "Editieren"); initString("lang.editor", "Editor"); initString("lang.event", "Ereignis"); + initString("lang.events", "Ereignisse"); initString("lang.events.process", "Prozessereignisse"); initString("lang.events.protocol", "Protokollereignisse"); initString("lang.file", "Datei"); initString("lang.filter", "Filter"); - initString("lang.timed.global", "Globale Ereignisse"); - initString("lang.timed.local", "Lokale Ereignisse"); initString("lang.logging.active", "Logging"); initString("lang.logging.clear", "Loggs löschen"); initString("lang.message", "Nachricht"); initString("lang.message.recv", "Nachricht erhalten"); initString("lang.message.sent", "Nachricht versendet"); + initString("lang.mode.expert", "Expertenmodus"); + initString("lang.name", "VS-Simulator v0.2-devel"); initString("lang.ok", "OK"); initString("lang.open", "Öffnen"); initString("lang.pause", "Pausieren"); - initString("lang.variables", "Variablen"); - initString("lang.protocols", "Protokolle"); - initString("lang.variable", "Variable"); - initString("lang.value", "Wert"); - initString("lang.variables.global", "Globale Variablen"); initString("lang.prefs", "Einstellungen"); + initString("lang.prefs.color", "Farbeinstellungen"); + initString("lang.prefs.diverse", "Diverse Einstellungen"); initString("lang.prefs.ext", "Erweiterte Einstellungen"); initString("lang.prefs.info!", "Prozessvariablen können für jeden Prozess einzelnd eingestellt werden. Die hier gezeigen Prozessvariablen sind lediglich die globalen Defaultwerte, die für neue Prozesse verwendet werden!"); + initString("lang.prefs.message", "Nachrichteneinstellungen"); initString("lang.prefs.more", "Mehr Einstellungen"); initString("lang.prefs.process", "Prozesseinstellungen"); + initString("lang.prefs.process", "Prozessstandardeinstellungen"); initString("lang.prefs.process.ext", "Erweiterte Prozesseinstellungen"); initString("lang.prefs.process.info!", "Änderungen werden erst nach Betätigen des \"Übernehmen\" Knopfes übernommen!"); initString("lang.prefs.protocols", "Protokolleinstellungen"); + initString("lang.prefs.simulation", "Simulationseinstellungen"); initString("lang.process", "Prozess"); + initString("lang.process.crash", "Prozess abstürzen"); + initString("lang.process.remove", "Prozess entfernen"); + initString("lang.process.edit", "Prozess editieren"); initString("lang.process.id", "PID"); initString("lang.process.new", "Neuer Prozess"); + initString("lang.process.recover", "Prozess wiederbeleben"); initString("lang.process.time.local", "Lokale Zeit"); initString("lang.processes.all", "Alle Prozesse"); initString("lang.protocol", "Protokoll"); @@ -99,8 +102,8 @@ public class VSDefaultPrefs extends VSPrefs { initString("lang.protocol.server", "Serverseite"); initString("lang.protocol.tasks.activation", "Client-/Serverprotokoll Aktivierung"); initString("lang.protocol.tasks.client", "Client Task-Manager (Clientanfragen)"); + initString("lang.protocols", "Protokolle"); initString("lang.quit", "Beenden"); - initString("lang.recover", "Wiederbeleben"); initString("lang.recovered", "Wiederbelebt"); initString("lang.remove", "Entfernen"); initString("lang.replay", "Wiederholen"); @@ -121,7 +124,6 @@ public class VSDefaultPrefs extends VSPrefs { initString("lang.stop", "Stoppen"); initString("lang.takeover", "Übernehmen"); initString("lang.task", "Aufgabe"); - initString("lang.events", "Ereignisse"); initString("lang.task.manager", "Ereigniseditor"); initString("lang.tasks.fullfilled", "Abgelaufene Aufgaben"); initString("lang.tasks.global", "Globale Aufgaben"); @@ -129,15 +131,15 @@ public class VSDefaultPrefs extends VSPrefs { initString("lang.time", "Zeit"); initString("lang.time.lamport", "Lamportzeit"); initString("lang.time.vector", "Vektorzeit"); + initString("lang.timed.global", "Globale Ereignisse"); + initString("lang.timed.local", "Lokale Ereignisse"); initString("lang.type", "Typ"); + initString("lang.value", "Wert"); + initString("lang.variable", "Variable"); + initString("lang.variables", "Variablen"); + initString("lang.variables.global", "Globale Variablen"); initString("lang.window.close", "Fenster schliessen"); initString("lang.window.new", "Neues Fenster"); - initString("lang.name", "VS-Simulator v0.2-devel"); - initString("lang.prefs.simulation", "Simulationseinstellungen"); - initString("lang.prefs.process", "Prozessstandardeinstellungen"); - initString("lang.prefs.message", "Nachrichteneinstellungen"); - initString("lang.prefs.diverse", "Diverse Einstellungen"); - initString("lang.prefs.color", "Farbeinstellungen"); } public void fillDefaultIntegers() { diff --git a/sources/simulator/VSSimulation.java b/sources/simulator/VSSimulation.java index cc0ba16..17400cb 100644 --- a/sources/simulator/VSSimulation.java +++ b/sources/simulator/VSSimulation.java @@ -822,15 +822,7 @@ public class VSSimulation extends JPanel { } private int getSelectedProcessNum() { - try { - String string = (String) processesComboBox.getSelectedItem(); - int cutLen = prefs.getString("lang.process").length() + 1; - string = string.substring(cutLen); - return Integer.parseInt(string) - 1; - } catch (NumberFormatException e) { - } - - return simulationCanvas.getNumProcesses(); + return processesComboBox.getSelectedIndex(); } private VSProcess getSelectedProcess() { @@ -879,7 +871,7 @@ public class VSSimulation extends JPanel { return simulationCanvas; } - public VSFrame getSimulatorFrame() { + public VSSimulatorFrame getSimulatorFrame() { return simulatorFrame; } @@ -888,6 +880,13 @@ public class VSSimulation extends JPanel { simulationCanvas.updateFromPrefs(); } + public void removeProcessAtIndex(int index) { + globalPIDComboBox.removeItemAt(index); + localPIDComboBox.removeItemAt(index); + processesComboBox.removeItemAt(index); + simulatorFrame.updateEditMenu(); + } + public void fireExpertModeChanged() { boolean expertMode = prefs.getBoolean("sim.mode.expert"); diff --git a/sources/simulator/VSSimulationCanvas.java b/sources/simulator/VSSimulationCanvas.java index f9fbbe8..8444785 100644 --- a/sources/simulator/VSSimulationCanvas.java +++ b/sources/simulator/VSSimulationCanvas.java @@ -21,7 +21,7 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL private VSSimulation simulation; private VSPrefs prefs; private VSLogging logging; - private int numProcesses; + private volatile int numProcesses; private int secondsSpaceing; private int threadSleep; private long untilTime; @@ -39,7 +39,7 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL private volatile long lastTime; private VSTaskManager taskManager; private LinkedList<VSMessageLine> messageLines; - private LinkedList<VSProcess> processes; + private Vector<VSProcess> processes; private double clockSpeed; private double clockOffset; private long simulationTime; @@ -108,11 +108,11 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL this.x = getTimeXPosition(sendTime); this.y = getProcessYPosition(senderNum) + offset1; - recalcOnWindowChanged(); + recalcOnChange(); paint(); } - public void recalcOnWindowChanged() { + public void recalcOnChange() { x1 = getTimeXPosition(sendTime); y1 = getProcessYPosition(senderNum) + offset1; x2 = getTimeXPosition(recvTime); @@ -162,14 +162,14 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL this.logging = logging; this.taskManager = new VSTaskManager(prefs); this.messageLines = new LinkedList<VSMessageLine>(); - this.processes = new LinkedList<VSProcess>(); + this.processes = new Vector<VSProcess>(); numProcesses = prefs.getInteger("sim.process.num"); updateFromPrefs(); VSProcess.resetProcessCounter(); for (int i = 0; i < numProcesses; ++i) - createProcess(i); + addProcess(); addMouseListener(this); addMouseMotionListener(this); @@ -192,7 +192,7 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL int paintGlobalTimeYPosition; /* This method contains very ugly code. But this has to be in order to gain performance! */ - private void recalcOnWindowChanged() { + private void recalcOnChange() { processlineColor = prefs.getColor("col.process.line"); processSecondlineColor = prefs.getColor("col.process.secondline"); processSeplineColor = prefs.getColor("col.process.sepline"); @@ -206,7 +206,7 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL xpaintsize_dividedby_untiltime = xPaintSize / (double) untilTime; for (VSMessageLine messageLine : messageLines) - messageLine.recalcOnWindowChanged(); + messageLine.recalcOnChange(); /* paintProcesses optimization, precalc things */ { @@ -242,7 +242,7 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL } } - public VSProcess createProcess(int i) { + public VSProcess addProcess() { VSProcess process = new VSProcess(prefs, this, logging); processes.add(process); logging.logg(prefs.getString("lang.process.new") + "; " + process); @@ -272,8 +272,10 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL for (long l = 0; l < offset; ++l) taskManager.runTasks(l, offset, lastSimulationTime); - for (VSProcess process : processes) - process.syncTime(simulationTime); + synchronized (processes) { + for (VSProcess process : processes) + process.syncTime(simulationTime); + } } public void paint() { @@ -323,52 +325,54 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL final int xPoints[] = { XOFFSET, xoffset_plus_xpaintsize, xoffset_plus_xpaintsize, XOFFSET, XOFFSET }; final int yPoints[] = { yOffset, yOffset, yOffset + LINE_WIDTH, yOffset + LINE_WIDTH, yOffset }; - for (VSProcess process : processes) { - final long localTime = process.getTime(); + synchronized (processes) { + for (VSProcess process : processes) { + final long localTime = process.getTime(); - g.setColor(process.getColor()); - g.fillPolygon(xPoints, yPoints, 5); + g.setColor(process.getColor()); + g.fillPolygon(xPoints, yPoints, 5); - if (process.hasCrashed()) { - g.setColor(process.getCrashedColor()); - final Long crashHistory[] = process.getCrashHistoryArray(); - final int length = crashHistory.length; + if (process.hasCrashed()) { + g.setColor(process.getCrashedColor()); + final Long crashHistory[] = process.getCrashHistoryArray(); + final int length = crashHistory.length; - for (int i = 0; i < length; i += 2) { - final int crashStartPos = (int) getTimeXPosition(crashHistory[i].longValue()); - int crashEndPos; + for (int i = 0; i < length; i += 2) { + final int crashStartPos = (int) getTimeXPosition(crashHistory[i].longValue()); + int crashEndPos; - if (i == length - 1) - crashEndPos = xoffset_plus_xpaintsize; - else - crashEndPos = (int) getTimeXPosition(crashHistory[i+1].longValue()); + if (i == length - 1) + crashEndPos = xoffset_plus_xpaintsize; + else + crashEndPos = (int) getTimeXPosition(crashHistory[i+1].longValue()); - final int xPointsCrashed[] = { crashStartPos, crashEndPos, - crashEndPos, crashStartPos, crashStartPos - }; - g.fillPolygon(xPointsCrashed, yPoints, 5); + final int xPointsCrashed[] = { crashStartPos, crashEndPos, + crashEndPos, crashStartPos, crashStartPos + }; + g.fillPolygon(xPointsCrashed, yPoints, 5); + } } - } - g.setColor(process.getColor()); - g.drawString("P" + process.getProcessID() + ":", XOFFSET - 30, yPoints[0] + LINE_WIDTH); + g.setColor(process.getColor()); + g.drawString("P" + process.getProcessID() + ":", XOFFSET - 30, yPoints[0] + LINE_WIDTH); - final long tmp = localTime > untilTime ? untilTime : localTime; - final int xPos = 1 + (int) getTimeXPosition(tmp); - final int yStart = yPoints[0] - 14; - final int yEnd = yPoints[0]; + final long tmp = localTime > untilTime ? untilTime : localTime; + final int xPos = 1 + (int) getTimeXPosition(tmp); + final int yStart = yPoints[0] - 14; + final int yEnd = yPoints[0]; - g.setColor(processlineColor); - g.drawLine(xPos, yStart, xPos, yEnd); - g.drawString(localTime+"ms", xPos + 2, yStart + TEXT_SPACEING); + g.setColor(processlineColor); + g.drawLine(xPos, yStart, xPos, yEnd); + g.drawString(localTime+"ms", xPos + 2, yStart + TEXT_SPACEING); - if (showLamport) - paintTime(g, process.getLamportTimeArray(), process, yStart, 25); - else if (showVectorTime) - paintTime(g, process.getVectorTimeArray(), process, yStart, 20 * numProcesses); + if (showLamport) + paintTime(g, process.getLamportTimeArray(), process, yStart, 25); + else if (showVectorTime) + paintTime(g, process.getVectorTimeArray(), process, yStart, 20 * numProcesses); - for (int i = 0; i < 5; ++i) - yPoints[i] += paintProcessesOffset; + for (int i = 0; i < 5; ++i) + yPoints[i] += paintProcessesOffset; + } } } @@ -548,8 +552,10 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL logging.logg(prefs.getString("lang.simulation.started")); final long currentTime = System.currentTimeMillis(); - for (VSProcess p : processes) - p.play(); + synchronized (processes) { + for (VSProcess p : processes) + p.play(); + } if (isResetted) isResetted = false; @@ -571,8 +577,10 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL } public void finish() { - for (VSProcess p : processes) - p.finish(); + synchronized (processes) { + for (VSProcess p : processes) + p.finish(); + } simulation.finish(); isFinished = true; @@ -583,8 +591,10 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL public void pause() { isPaused = true; - for (VSProcess p : processes) - p.pause(); + synchronized (processes) { + for (VSProcess p : processes) + p.pause(); + } pauseTime = System.currentTimeMillis(); @@ -605,14 +615,18 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL clockOffset = 0; simulationTime = 0; - for (VSProcess process : processes) - process.reset(); + synchronized (processes) { + for (VSProcess process : processes) + process.reset(); + } /* Reset the task manager AFTER the processes, for the programmed tasks */ taskManager.reset(); - for (VSProcess process : processes) - process.createRandomCrashTask(); + synchronized (processes) { + for (VSProcess process : processes) + process.createRandomCrashTask(); + } synchronized (messageLines) { messageLines.clear(); @@ -657,32 +671,34 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL long deliverTime, outageTime, durationTime; boolean recvOwn = prefs.getBoolean("sim.message.own.recv"); - for (VSProcess receiverProcess : processes) { - if (receiverProcess.equals(sendingProcess)) { - if (recvOwn) { - deliverTime = sendingProcess.getGlobalTime(); - messageReceiveEvent = new MessageReceiveEvent(message); - task = new VSTask(deliverTime, receiverProcess, messageReceiveEvent, VSTask.GLOBAL); - taskManager.addTask(task); - } + synchronized (processes) { + for (VSProcess receiverProcess : processes) { + if (receiverProcess.equals(sendingProcess)) { + if (recvOwn) { + deliverTime = sendingProcess.getGlobalTime(); + messageReceiveEvent = new MessageReceiveEvent(message); + task = new VSTask(deliverTime, receiverProcess, messageReceiveEvent, VSTask.GLOBAL); + taskManager.addTask(task); + } - } else { - durationTime = sendingProcess.getDurationTime(); - deliverTime = sendingProcess.getGlobalTime() + durationTime; - outageTime = sendingProcess.getARandomMessageOutageTime(durationTime); - - /* Only add a 'receiving message' task if the message will not get lost! */ - if (outageTime == -1) { - messageReceiveEvent = new MessageReceiveEvent(message); - task = new VSTask(deliverTime, receiverProcess, messageReceiveEvent, VSTask.GLOBAL); - taskManager.addTask(task); - } + } else { + durationTime = sendingProcess.getDurationTime(); + deliverTime = sendingProcess.getGlobalTime() + durationTime; + outageTime = sendingProcess.getARandomMessageOutageTime(durationTime); + + /* Only add a 'receiving message' task if the message will not get lost! */ + if (outageTime == -1) { + messageReceiveEvent = new MessageReceiveEvent(message); + task = new VSTask(deliverTime, receiverProcess, messageReceiveEvent, VSTask.GLOBAL); + taskManager.addTask(task); + } - synchronized (messageLines) { - messageLines.add( - new VSMessageLine(receiverProcess, sendingProcess.getGlobalTime(), - deliverTime, outageTime, sendingProcess.getProcessID(), - receiverProcess.getProcessID())); + synchronized (messageLines) { + messageLines.add( + new VSMessageLine(receiverProcess, sendingProcess.getGlobalTime(), + deliverTime, outageTime, sendingProcess.getProcessID(), + receiverProcess.getProcessID())); + } } } } @@ -698,42 +714,51 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { String actionCommand = ae.getActionCommand(); - if (actionCommand.equals(prefs.getString("lang.edit"))) { + if (actionCommand.equals(prefs.getString("lang.process.edit"))) { editProcess(process); - } else if (actionCommand.equals(prefs.getString("lang.crash"))) { + } else if (actionCommand.equals(prefs.getString("lang.process.crash"))) { VSEvent event = new ProcessCrashEvent(); - event.init(process); + //event.init(process); taskManager.addTask(new VSTask(process.getGlobalTime(), process, event, VSTask.GLOBAL)); - } else if (actionCommand.equals(prefs.getString("lang.recover"))) { + } else if (actionCommand.equals(prefs.getString("lang.process.recover"))) { VSEvent event = new ProcessRecoverEvent(); - event.init(process); + //event.init(process); taskManager.addTask(new VSTask(process.getGlobalTime(), process, event, VSTask.GLOBAL)); + + } else if (actionCommand.equals(prefs.getString("lang.process.remove"))) { + removeProcess(process); } } }; JPopupMenu popup = new JPopupMenu(); - JMenuItem item = new JMenuItem(prefs.getString("lang.edit")); + JMenuItem item = new JMenuItem(prefs.getString("lang.process.edit")); item.addActionListener(actionListener); popup.add(item); - item = new JMenuItem(prefs.getString("lang.crash")); + item = new JMenuItem(prefs.getString("lang.process.crash")); if (process.isCrashed() || isPaused || time == 0 || isFinished) item.setEnabled(false); else item.addActionListener(actionListener); popup.add(item); - item = new JMenuItem(prefs.getString("lang.recover")); + item = new JMenuItem(prefs.getString("lang.process.recover")); if (!process.isCrashed() || isPaused || time == 0 || isFinished) item.setEnabled(false); else item.addActionListener(actionListener); popup.add(item); + item = new JMenuItem(prefs.getString("lang.process.remove")); + item.addActionListener(actionListener); + popup.add(item); + + popup.addSeparator(); + popup.show(me.getComponent(), me.getX(), me.getY()); } else { @@ -806,14 +831,16 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL public void ancestorMoved(HierarchyEvent e) { } public void ancestorResized(HierarchyEvent e) { - recalcOnWindowChanged(); + recalcOnChange(); } public ArrayList<VSProcess> getProcessesArray() { ArrayList<VSProcess> arr = new ArrayList<VSProcess>(); - for (VSProcess process : processes) - arr.add(process); + synchronized (processes) { + for (VSProcess process : processes) + arr.add(process); + } return arr; } @@ -830,6 +857,19 @@ public class VSSimulationCanvas extends Canvas implements Runnable, MouseMotionL if (threadSleep == 0) threadSleep = 1; - recalcOnWindowChanged(); + recalcOnChange(); + } + + public void removeProcess(VSProcess process) { + if (numProcesses == 1) { + simulation.getSimulatorFrame().removeSimulation(simulation); + + } else { + int index = processes.indexOf(process); + processes.remove(index); + numProcesses = processes.size(); + recalcOnChange(); + simulation.removeProcessAtIndex(index); + } } } diff --git a/sources/simulator/VSSimulatorFrame.java b/sources/simulator/VSSimulatorFrame.java index 8ca7d94..c4abdb3 100644 --- a/sources/simulator/VSSimulatorFrame.java +++ b/sources/simulator/VSSimulatorFrame.java @@ -182,16 +182,10 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener { pane.add(toolBar, BorderLayout.PAGE_START); pane.add(tabbedPane, BorderLayout.CENTER); - /* - speedSlider = new JSlider(JSlider.HORIZONTAL, - 0, 200, (int) (100 * prefs.getFloat("sim.clock.speed"))); - toolBar.add(speedSlider); - */ - return pane; } - private void updateEditMenu() { + public void updateEditMenu() { menuEdit.removeAll(); JMenuItem globalPrefsItem = new JMenuItem(prefs.getString("lang.prefs")); @@ -210,13 +204,16 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener { return; final String processString = prefs.getString("lang.process"); - final int numProcesses = currentSimulation.getSimulationCanvas().getNumProcesses(); - - for (int i = 0; i < numProcesses; ++i) { - JMenuItem processItem = new JMenuItem(processString + " " + (i+1)); - processItem.setAccelerator(KeyStroke.getKeyStroke(0x31+i, + final ArrayList<VSProcess> arr = currentSimulation.getSimulationCanvas().getProcessesArray(); + final int numProcesses = arr.size(); + + int processNum = 0; + for (VSProcess process : arr) { + int processID = process.getProcessID(); + JMenuItem processItem = new JMenuItem(processString + " " + processID); + processItem.setAccelerator(KeyStroke.getKeyStroke(0x31+processID, ActionEvent.ALT_MASK)); - final int finalProcessNum = i; + final int finalProcessNum = processNum++; processItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { currentSimulation.getSimulationCanvas().editProcess(finalProcessNum); @@ -242,8 +239,10 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener { } public void dispose() { - for (VSSimulation simulation : simulations) - simulation.getSimulationCanvas().stopThread(); + synchronized (simulations) { + for (VSSimulation simulation : simulations) + simulation.getSimulationCanvas().stopThread(); + } super.dispose(); } @@ -257,10 +256,7 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener { sourceText = ((ImageIcon) ((JButton) source).getIcon()).getDescription(); if (sourceText.equals(prefs.getString("lang.simulation.close"))) { - if (simulations.size() == 1) - dispose(); - else - removeCurrentSimulation(); + removeCurrentSimulation(); } else if (sourceText.equals(prefs.getString("lang.simulation.new"))) { VSPrefs newPrefs = VSDefaultPrefs.init(); @@ -334,11 +330,19 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener { } } + public void removeSimulation(VSSimulation simulationToRemove) { + if (simulations.size() == 1) { + dispose(); + + } else { + simulations.remove(simulationToRemove); + tabbedPane.remove(simulationToRemove); + simulationToRemove.getSimulationCanvas().stopThread(); + } + } + private void removeCurrentSimulation() { - VSSimulation simulationToRemove = currentSimulation; - simulations.remove(simulationToRemove); - tabbedPane.remove(simulationToRemove); - simulationToRemove.getSimulationCanvas().stopThread(); + removeSimulation(currentSimulation); } public VSSimulation getCurrentSimulation() { @@ -354,4 +358,5 @@ public class VSSimulatorFrame extends VSFrame implements ActionListener { return new ImageIcon(imageURL, descr); } + } |
