/*
* 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 simulator;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import core.*;
import events.*;
import events.internal.*;
import exceptions.*;
import prefs.*;
import prefs.editors.*;
import serialize.*;
import utils.*;
/**
* The class VSSimulator, an object of this class represents a whole simulator.
* It may be, that several parallel simulators exist. They are independent
* fron each other.
*
* @author Paul C. Buetow
*/
public class VSSimulator extends JPanel implements VSSerializable {
/** the serial version uid */
private static final long serialversionuid = 1l;
/** The global text fields. */
private ArrayList<String> globalTextFields;
/** The local text fields. */
private ArrayList<String> localTextFields;
/** The create tasks array list. */
private ArrayList<VSCreateTask> createTasks;
/** The filter active check box. */
private JCheckBox filterActiveCheckBox;
/** The lamport active check box. */
private JCheckBox lamportActiveCheckBox;
/** The vector time active check box. */
private JCheckBox vectorTimeActiveCheckBox;
/** The global pid combo box. */
private JComboBox globalPIDComboBox;
/** The local pid combo box. */
private JComboBox localPIDComboBox;
/** The processes combo box. */
private JComboBox processesComboBox;
/** The global add panel. */
private JPanel globalAddPanel;
/** The local add panel. */
private JPanel localAddPanel;
/** The local panel. */
private JPanel localPanel;
/** The logging panel. */
private JPanel loggingPanel;
/** The tools panel. */
private JPanel toolsPanel;
/** The split pane1. */
private JSplitPane splitPane1;
/** The split pane h. */
private JSplitPane splitPaneH;
/** The split pane v. */
private JSplitPane splitPaneV;
/** The tabbed pane. */
private JTabbedPane tabbedPane;
/** The logging area. */
private JTextArea loggingArea;
/** The filter text field. */
private JTextField filterTextField;
/** The global text field. */
private JTextField globalTextField;
/** The local text field. */
private JTextField localTextField;
/** The thread. */
private Thread thread;
/** The logging. */
private VSLogging logging;
/** The menu item states. */
private VSMenuItemStates menuItemStates;
/** The prefs. */
private VSPrefs prefs;
/** The simulator canvas. */
private VSSimulatorCanvas simulatorCanvas;
/** The simulator frame. */
private VSSimulatorFrame simulatorFrame;
/** The task manager. */
private VSTaskManager taskManager;
/** The task manager global model. */
private VSTaskManagerTableModel taskManagerGlobalModel;
/** The task manager local model. */
private VSTaskManagerTableModel taskManagerLocalModel;
/** The task manager global editor. */
private VSTaskManagerCellEditor taskManagerGlobalEditor;
/** The task manager local editor. */
private VSTaskManagerCellEditor taskManagerLocalEditor;
/** The simulator has started. */
private boolean hasStarted = false;
/** The last selected process num. */
private int lastSelectedProcessNum;
/** The last expert state. */
private boolean lastExpertState;
/** The simulator counter. */
private static int simulatorCounter;
/** The simulator num. */
private static int simulatorNum;
/**
* The class VSTaskManagerTableModel, an object of this class handles
* the task manager's JTable.
*/
@SuppressWarnings("unchecked")
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 ArrayList<VSTask> tasks;
/** The column names. */
private String columnNames[];
/** The num columns. */
private int numColumns;
/** The table. */
private JTable table;
/** The editor. */
private VSTaskManagerCellEditor editor;
/**
* 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(VSInternalProcess process, boolean localTask) {
tasks = new ArrayList<VSTask>();
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 the editor.
*
* @param editor the editor
*/
public void setEditor(VSTaskManagerCellEditor editor) {
this.editor = editor;
}
/**
* 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(VSInternalProcess 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);
}
Collections.sort(tasks);
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() {
|