diff options
| author | Paul Buetow <paul@buetow.org> | 2008-06-13 22:57:15 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-06-13 22:57:15 +0000 |
| commit | 053ecc68889e3b4ed1afd23ec12d6ff0aea593d4 (patch) | |
| tree | d62eadeb7c06712a7c4d8fad33bd35d09bfe79b2 | |
| parent | 12b26d3285b05ad3d7387280bd7e9ec016f818d8 (diff) | |
compiles again
| -rw-r--r-- | sources/core/VSTask.java | 25 | ||||
| -rw-r--r-- | sources/events/VSAbstractEvent.java | 14 | ||||
| -rw-r--r-- | sources/events/VSCopyableEvent.java (renamed from sources/events/VSNotCopyableEvent.java) | 8 | ||||
| -rw-r--r-- | sources/events/implementations/VSProcessCrashEvent.java | 11 | ||||
| -rw-r--r-- | sources/events/implementations/VSProcessRecoverEvent.java | 11 | ||||
| -rw-r--r-- | sources/events/internal/VSMessageReceiveEvent.java | 3 | ||||
| -rw-r--r-- | sources/events/internal/VSProtocolEvent.java | 20 | ||||
| -rw-r--r-- | sources/events/internal/VSProtocolScheduleEvent.java | 2 | ||||
| -rw-r--r-- | sources/exceptions/VSEventNotCopyableException.java | 36 | ||||
| -rw-r--r-- | sources/exceptions/VSParseIntegerVectorException.java | 2 | ||||
| -rw-r--r-- | sources/simulator/VSSimulator.java | 80 | ||||
| -rw-r--r-- | sources/simulator/VSSimulatorCanvas.java | 17 |
12 files changed, 182 insertions, 47 deletions
diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java index dbac3e9..bbc9cec 100644 --- a/sources/core/VSTask.java +++ b/sources/core/VSTask.java @@ -28,6 +28,7 @@ import java.io.*; import events.*; import events.implementations.*; import events.internal.*; +import exceptions.*; import prefs.VSPrefs; import protocols.VSAbstractProtocol; import serialize.*; @@ -101,9 +102,20 @@ public class VSTask implements Comparable, VSSerializable { * @param task the task to copy */ public VSTask(VSTask task) { + VSAbstractEvent event = task.getEvent(); + + try { + VSAbstractEvent copy = event.getCopy(); + // Use the copy of the event object + event = copy; + } catch (VSEventNotCopyableException e) { + // Use the original event object + System.out.println(e); + } + init(task.getTaskTime(), task.getProcess(), - task.getEvent(), + event, !task.isGlobalTimed()); } @@ -296,6 +308,17 @@ public class VSTask implements Comparable, VSSerializable { } /** + * Sets the process. + * + * @param process the process + */ + public void setProcess(VSProcess process) { + this.process = process; + // TODO:: use the process' specific event object + //this.event = null; + } + + /** * Gets the event. * * @return the event diff --git a/sources/events/VSAbstractEvent.java b/sources/events/VSAbstractEvent.java index 834b691..263f21f 100644 --- a/sources/events/VSAbstractEvent.java +++ b/sources/events/VSAbstractEvent.java @@ -55,17 +55,21 @@ abstract public class VSAbstractEvent extends VSPrefs { private String eventClassname; /** - * Creates a copy of the event. + * Creates a copy of the event. * * @return The copy */ final public VSAbstractEvent getCopy() throws VSEventNotCopyableException { - VSAbstractEvent copy = null + if (!(this instanceof VSCopyableEvent)) + throw new VSEventNotCopyableException(eventShortname); - if (this instanceof VSCopyableEvent) - throw new VSEventNotCopyableException(eventShortname); + VSAbstractEvent copy = + VSRegisteredEvents.createEventInstanceByClassname( + eventClassname, process); - return copy; + ((VSCopyableEvent) this).initCopy(copy); + + return copy; } /** diff --git a/sources/events/VSNotCopyableEvent.java b/sources/events/VSCopyableEvent.java index 49dde93..0ad6b24 100644 --- a/sources/events/VSNotCopyableEvent.java +++ b/sources/events/VSCopyableEvent.java @@ -26,9 +26,15 @@ package events; /** * The interface VSCopyableEvent, all events which implement this class - * are nor copyable. + * are copyable. * * @author Paul C. Buetow */ public interface VSCopyableEvent { + /** + * Fills a copy of this event with its values + * + * @param copy The copy + */ + public void initCopy(VSAbstractEvent copy); } diff --git a/sources/events/implementations/VSProcessCrashEvent.java b/sources/events/implementations/VSProcessCrashEvent.java index c281500..e5c99f5 100644 --- a/sources/events/implementations/VSProcessCrashEvent.java +++ b/sources/events/implementations/VSProcessCrashEvent.java @@ -23,18 +23,25 @@ package events.implementations; -import events.VSAbstractEvent; +import events.*; /** * The class VSProcessCrashEvent. This event makes a process to crash. * * @author Paul C. Buetow */ -public class VSProcessCrashEvent extends VSAbstractEvent { +public class VSProcessCrashEvent extends VSAbstractEvent + implements VSCopyableEvent { /** The serial version uid */ private static final long serialVersionUID = 1L; /* (non-Javadoc) + * @see events.VSCopyableEvent#initCopy(events.VSAbstractEvent) + */ + public void initCopy(VSAbstractEvent copy) { + } + + /* (non-Javadoc) * @see events.VSAbstractEvent#onInit() */ public void onInit() { diff --git a/sources/events/implementations/VSProcessRecoverEvent.java b/sources/events/implementations/VSProcessRecoverEvent.java index 43479cf..600fcf7 100644 --- a/sources/events/implementations/VSProcessRecoverEvent.java +++ b/sources/events/implementations/VSProcessRecoverEvent.java @@ -23,7 +23,7 @@ package events.implementations; -import events.VSAbstractEvent; +import events.*; /** * The class VSProcessRecoverEvent. This event makes a process to recover if @@ -31,11 +31,18 @@ import events.VSAbstractEvent; * * @author Paul C. Buetow */ -public class VSProcessRecoverEvent extends VSAbstractEvent { +public class VSProcessRecoverEvent extends VSAbstractEvent + implements VSCopyableEvent { /** The serial version uid */ private static final long serialVersionUID = 1L; /* (non-Javadoc) + * @see events.VSCopyableEvent#initCopy(events.VSAbstractEvent) + */ + public void initCopy(VSAbstractEvent copy) { + } + + /* (non-Javadoc) * @see events.VSAbstractEvent#onInit() */ public void onInit() { diff --git a/sources/events/internal/VSMessageReceiveEvent.java b/sources/events/internal/VSMessageReceiveEvent.java index 7755b60..825e500 100644 --- a/sources/events/internal/VSMessageReceiveEvent.java +++ b/sources/events/internal/VSMessageReceiveEvent.java @@ -26,7 +26,6 @@ package events.internal; import java.io.*; import core.VSMessage; -import events.VSCopyableEvent; import protocols.VSAbstractProtocol; import serialize.VSNotSerializable; @@ -37,7 +36,7 @@ import serialize.VSNotSerializable; * @author Paul C. Buetow */ public class VSMessageReceiveEvent extends VSAbstractInternalEvent - implements VSNotSerializable, VSCopyableEvent { + implements VSNotSerializable { /** The serioal version uid */ private static final long serialVersionUID = 1L; diff --git a/sources/events/internal/VSProtocolEvent.java b/sources/events/internal/VSProtocolEvent.java index d0a12cc..1ccb700 100644 --- a/sources/events/internal/VSProtocolEvent.java +++ b/sources/events/internal/VSProtocolEvent.java @@ -38,7 +38,8 @@ import serialize.VSSerialize; * * @author Paul C. Buetow */ -public class VSProtocolEvent extends VSAbstractInternalEvent { +public class VSProtocolEvent extends VSAbstractInternalEvent + implements VSCopyableEvent { /** The serial version uid */ private static final long serialVersionUID = 1L; @@ -51,16 +52,15 @@ public class VSProtocolEvent extends VSAbstractInternalEvent { /** The event is a protocol activation if true. Else it is a deactivation */ private boolean isProtocolActivation; - /** - * Fills a copy of this event with its values - * - * @param copy The copy + /* (non-Javadoc) + * @see events.VSCopyableEvent#initCopy(events.VSAbstractEvent) */ - public void initCopy(VSProtocolEvent copy) { - copy.isClientProtocol(isClientProtocol); - copy.isProtocolActivation(isProtocolActivation); - copy.setProtocolClassname(protocolClassname); - } + public void initCopy(VSAbstractEvent copy) { + VSProtocolEvent protocolEventCopy = (VSProtocolEvent) copy; + protocolEventCopy.isClientProtocol(isClientProtocol); + protocolEventCopy.isProtocolActivation(isProtocolActivation); + protocolEventCopy.setProtocolClassname(protocolClassname); + } /* (non-Javadoc) * @see events.VSAbstractEvent#onInit() diff --git a/sources/events/internal/VSProtocolScheduleEvent.java b/sources/events/internal/VSProtocolScheduleEvent.java index 0ee7d05..bab0a63 100644 --- a/sources/events/internal/VSProtocolScheduleEvent.java +++ b/sources/events/internal/VSProtocolScheduleEvent.java @@ -37,7 +37,7 @@ import serialize.*; * @author Paul C. Buetow */ public class VSProtocolScheduleEvent extends VSAbstractInternalEvent - implements VSNotSerializable, VSCopyableEvent { + implements VSNotSerializable { /** The serial version uid */ private static final long serialVersionUID = 1L; diff --git a/sources/exceptions/VSEventNotCopyableException.java b/sources/exceptions/VSEventNotCopyableException.java new file mode 100644 index 0000000..9437090 --- /dev/null +++ b/sources/exceptions/VSEventNotCopyableException.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2008 Paul C. Buetow, vs@dev.buetow.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * All icons of the icons/ folder are under a Creative Commons + * Attribution-Noncommercial-Share Alike License a CC-by-nc-sa. + * + * The icon's homepage is http://code.google.com/p/ultimate-gnome/ + */ + +package exceptions; + +/** + * The Interface VSEventNotCopyableException, this exception is thrown if + * the someone tried to copy a not copyable event! + * + * @author Paul C. Buetow + */ +public class VSEventNotCopyableException extends Exception { + public VSEventNotCopyableException(String descr) { + super(descr); + } +} diff --git a/sources/exceptions/VSParseIntegerVectorException.java b/sources/exceptions/VSParseIntegerVectorException.java index da49737..3aabe87 100644 --- a/sources/exceptions/VSParseIntegerVectorException.java +++ b/sources/exceptions/VSParseIntegerVectorException.java @@ -24,7 +24,7 @@ package exceptions; /** - * The Interface VSParseIntegerVectorException. This exception is thrown if + * The Interface VSParseIntegerVectorException, this exception is thrown if * the VSAbstractEditor is not able to parse the vector fields input of the * user. * diff --git a/sources/simulator/VSSimulator.java b/sources/simulator/VSSimulator.java index 21b2de5..ece71b0 100644 --- a/sources/simulator/VSSimulator.java +++ b/sources/simulator/VSSimulator.java @@ -289,6 +289,9 @@ public class VSSimulator extends JPanel implements VSSerializable { * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int) */ public boolean isCellEditable(int row, int col) { + if (col == 2) + return false; + return true; } @@ -314,24 +317,34 @@ public class VSSimulator extends JPanel implements VSSerializable { * Removes the task at a specified row. * * @param row the row - * @return The removed task + * @return The removed task */ public VSTask removeTaskAtRow(int row) { VSTask task = tasks.get(row); tasks.remove(task); taskManager.removeTask(task); fireTableDataChanged(); - return task; + return task; + } + + /** + * Gets the task at a specified row. + * + * @param row the row + * @return The task + */ + public VSTask getTaskAtRow(int row) { + return tasks.get(row); } /** * Gets the index of a specific task * * @param task The task - * @return The index of the task + * @return The index of the task */ public int getIndexOf(VSTask task) { - return tasks.indexOf(task); + return tasks.indexOf(task); } /** @@ -456,38 +469,61 @@ public class VSSimulator extends JPanel implements VSSerializable { valField.setBackground(Color.WHITE); valField.setBorder(null); valField.addActionListener(new ActionListener() { - private boolean isRed = false; - public void actionPerformed(ActionEvent ae) { + private boolean isRed = false; + public void actionPerformed(ActionEvent ae) { try { Long val = Long.valueOf(valField.getText()); - VSTask task = model.removeTaskAtRow(row); - task.setTaskTime(val.longValue()); - taskManager.addTask(task, VSTaskManager.PROGRAMMED); - model.addTask(task); - if (isRed) { - valField.setBackground(Color.WHITE); - isRed = false; - } - int index = model.getIndexOf(task); - ListSelectionModel selectionModel = - table.getSelectionModel(); - selectionModel.setSelectionInterval(index, index); - fireEditingStopped(); + VSTask task = model.removeTaskAtRow(row); + task.setTaskTime(val.longValue()); + taskManager.addTask(task, VSTaskManager.PROGRAMMED); + model.addTask(task); + if (isRed) { + valField.setBackground(Color.WHITE); + isRed = false; + } + int index = model.getIndexOf(task); + ListSelectionModel selectionModel = + table.getSelectionModel(); + selectionModel.setSelectionInterval(index, index); + fireEditingStopped(); } catch (NumberFormatException exc) { valField.setBackground(Color.RED); - isRed = true; + isRed = true; } } }); return valField; case 1: - break; + Integer current[] = { (Integer) model.getValueAt(row, col) }; + final JComboBox comboBox = new JComboBox(current); + + Integer pids[] = simulatorCanvas.getProcessIDs(); + for (Integer pid : pids) + comboBox.addItem(pid); + + comboBox.setSelectedIndex(0); + comboBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + System.out.println("DFSDF "); + int index = comboBox.getSelectedIndex() - 1; + if (index >= 0) { + VSTask task = model.getTaskAtRow(row); + VSProcess process = + simulatorCanvas.getProcess(index); + task.setProcess(process); + } + + fireEditingStopped(); + } + }); + + return comboBox; case 2: break; } - return new JTextField(); + return null; } /* (non-Javadoc) diff --git a/sources/simulator/VSSimulatorCanvas.java b/sources/simulator/VSSimulatorCanvas.java index c28be85..7309d75 100644 --- a/sources/simulator/VSSimulatorCanvas.java +++ b/sources/simulator/VSSimulatorCanvas.java @@ -1454,6 +1454,23 @@ public class VSSimulatorCanvas extends Canvas } /** + * Gets the processes IDs. + * + * @return the processes IDs + */ + public Integer[] getProcessIDs() { + Integer pids[] = null; + + synchronized (processes) { + pids = new Integer[numProcesses]; + for (int i = 0; i < numProcesses; ++i) + pids[i] = new Integer(processes.get(i).getProcessID()); + } + + return pids; + } + + /** * Gets the processes. * * @return the processes |
