-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartState.java
More file actions
executable file
·112 lines (101 loc) · 3.38 KB
/
StartState.java
File metadata and controls
executable file
·112 lines (101 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
/**
* Written by Daniel Barter, Alby Himelick, and Grace Whitmore.
* For CS204 - Software Design
* 4 June 2012
*
* StartState inherits from state and executes the same functionality
* as State except that it draws differently, and is always the first
* state to be put into and stored by an NFA.
*
* StartState contains:
* - all the same things State contains.
*/
public class StartState extends State
{
/**
* Constructor for StartState. Same as constructor for state
* except it assumes it is not selected.
*
* int xPos: the x position of the center of the state.
* int yPos: the y position of the center of the state.
* boolean acceptState: whether or not this is an accept state.
*/
public StartState(int xPos, int yPos, boolean acceptState)
{
super(xPos, yPos, acceptState);
selected = false;
}
/**
* Draws the start state and part of the arrow leading into it.
*
* Graphics g: graphics handler that draws in the workspace
*/
public void draw(Graphics g)
{
Graphics2D g2D = (Graphics2D) g;
g2D.setStroke(new BasicStroke(5));
g2D.setColor(new Color(181, 27, 224));
g2D.drawOval(xPos - RADIUS + 4, yPos - RADIUS + 4, 2*RADIUS - 8, 2*RADIUS - 8);
if (transitionSelected)
{
g2D.setColor(new Color(204, 0, 0));
}
else if (acceptState)
{
if (selected)
{
g2D.setColor(new Color(30, 144, 255));
}
else
{
g2D.setColor(Color.blue);
}
}
else
{
if (selected)
{
g2D.setColor(Color.gray);
}
else
{
g2D.setColor(Color.black);
}
}
g2D.drawOval(xPos - RADIUS, yPos - RADIUS, 2*RADIUS, 2*RADIUS);
g2D.setColor(Color.black);
g2D.setStroke(new BasicStroke(3));
g2D.drawLine(xPos - RADIUS - 50, yPos, xPos - RADIUS, yPos);
g2D.setColor(Color.gray);
g2D.setColor(Color.black);
drawArrowhead(g2D, xPos - RADIUS, yPos);
}
/**
* Draws the arrow head pointing into the start state.
*
* Graphics2D g2D: graphics handler that draws in the workspace
* int arrowheadx: the x position the arrow points to
* int arrowheady: the y position the arrow points to
*/
public void drawArrowhead(Graphics2D g2D, int arrowheadx, int arrowheady)
{
double theta = Math.PI/2;
int point1x = (int) (arrowheadx - Transition.ARROW_LENGTH * Math.sin(theta - Transition.ARROW_ANGLE));
int point1y = (int) (arrowheady - Transition.ARROW_LENGTH * Math.cos(theta - Transition.ARROW_ANGLE));
int point2x = (int) (arrowheadx - Transition.ARROW_LENGTH * Math.sin(theta + Transition.ARROW_ANGLE));
int point2y = (int) (arrowheady - Transition.ARROW_LENGTH * Math.cos(theta + Transition.ARROW_ANGLE));
int[] xpoints = new int[3];
xpoints[0] = arrowheadx;
xpoints[1] = point1x;
xpoints[2] = point2x;
int[] ypoints = new int[3];
ypoints[0] = arrowheady;
ypoints[1] = point1y;
ypoints[2] = point2y;
g2D.fillPolygon(xpoints, ypoints, 3);
}
}