/*
* 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.awt.image.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import core.*;
import core.time.*;
import events.*;
import events.implementations.*;
import events.internal.*;
import prefs.*;
import prefs.editors.*;
import serialize.*;
import utils.*;
/**
* The class VSSimulatorCanvas. An instance of this object represents the
* graphical paint area of a simulator. It contains all graphic calculations.
* Also the simulator 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, VSSerializable {
/** The serial version uid */
private static final long serialVersionUID = 1L;
/** The highlighted process. */
private VSProcess highlightedProcess;
/** The simulator. */
private VSSimulator simulator;
/** The prefs. */
private VSPrefs prefs;
/** The logging. */
private VSLogging logging;
/** The num processes. */
private volatile int numProcesses;
/** The seconds spaceing. */
private int secondsSpaceing;
/** The thread sleep. */
private int threadSleep;
/** The until time. Until then goes the simulator? */
private long untilTime;
/** The simulator is paused. */
private volatile boolean isPaused = true;
/** The simulator thread is stopped. */
private volatile boolean hasThreadStopped = false;
/** The simulator is finished. */
private volatile boolean isFinished = false;
/** The simulator is resetted. */
private volatile boolean isResetted = false;
/** The simulator is anti aliased. */
private volatile boolean isAntiAliased = false;
/** The simulator's anti aliasing has changed. */
private volatile boolean isAntiAliasedChanged = false;
/** The simulator shows the lamport time. */
private volatile boolean showLamport = false;
/** The simulator shows the vector time. */
private volatile boolean showVectorTime = false;
/** The pause time. */
private volatile long pauseTime;
/** The start time. */
private volatile long startTime;
/** The global time. */
private volatile long time;
/** The last global time. */
private volatile long lastTime;
/** The task manager. */
private VSTaskManager taskManager;
/** The message lines. */
private LinkedList<VSMessageLine> messageLines;
/** The message lines to remove. */
private LinkedList<VSMessageLine> messageLinesToRemove;
/** The processes. */
private ArrayList<VSProcess> processes;
/** The clock speed. */
private double clockSpeed;
/** The clock offset. */
private double clockOffset;
/** The simulator time. */
private long simulatorTime;
/** 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 for buffering. */
private BufferStrategy strategy;
/** The graphics object to paint at. */
private Graphics2D g;
/** The Constant LINE_WIDTH. */
private static final int LINE_WIDTH = 5;
/** The Constant SEPLINE_WIDTH. */
private static final int SEPLINE_WIDTH = 2;
/** The Constant XOFFSET. */
private static final int XOFFSET = 50;
/** The Constant YOFFSET. */
private static final int YOFFSET = 30;
/** The Constant YOUTER_SPACEING. */
private static final int YOUTER_SPACEING = 15;
/** The C
|