-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented diagnostic trace listeners on the state machine. Created …
…a simple simulation of a coin operated tunrstile to demonstrate the state machine in use.
- Loading branch information
1 parent
1a8e591
commit 46025fc
Showing
15 changed files
with
755 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
src/FalseStartException.java → ...co/tigranetworks/FalseStartException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package uk.co.tigranetworks; | ||
|
||
/** | ||
* Created by Tim on 20/02/14. | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/StateTransitionAction.java → .../tigranetworks/StateTransitionAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package uk.co.tigranetworks; | ||
|
||
public interface StateTransitionAction | ||
{ | ||
public void action(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package uk.co.tigranetworks; | ||
|
||
import java.util.EventListener; | ||
|
||
/** | ||
* Created by Tim on 21/02/14. | ||
*/ | ||
public interface TraceListener extends EventListener | ||
{ | ||
public void trace(String traceOutput); | ||
} |
3 changes: 2 additions & 1 deletion
3
src/TransitionRule.java → ...c/uk/co/tigranetworks/TransitionRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package uk.co.tigranetworks; | ||
|
||
import java.util.EventListener; | ||
|
||
public interface TransitionRule extends EventListener | ||
{ | ||
public boolean transitionIsAllowed(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
TurnstileSample/src/com/codeproject/javaConsole/BlockCaret.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.codeproject.javaConsole; | ||
|
||
import javax.swing.text.BadLocationException; | ||
import javax.swing.text.DefaultCaret; | ||
import javax.swing.text.JTextComponent; | ||
import java.awt.*; | ||
|
||
/** | ||
* @author David MacDermot | ||
* @brief Custom block caret for the Java Console. | ||
* @par Comments: | ||
* Adapted from http://www.java2s.com/Code/Java/Swing-JFC/Acustomcaretclass.htm | ||
* @date 02-07-2012 | ||
* @bug | ||
*/ | ||
public class BlockCaret extends DefaultCaret | ||
{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* @brief Class Constructor | ||
*/ | ||
public BlockCaret() | ||
{ | ||
setBlinkRate(500); // half a second | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see javax.swing.text.DefaultCaret#damage(java.awt.Rectangle) | ||
*/ | ||
protected synchronized void damage(Rectangle r) | ||
{ | ||
if (r == null) | ||
return; | ||
|
||
// give values to x,y,width,height (inherited from java.awt.Rectangle) | ||
x = r.x; | ||
y = r.y; | ||
height = r.height; | ||
// A value for width was probably set by paint(), which we leave alone. | ||
// But the first call to damage() precedes the first call to paint(), so | ||
// in this case we must be prepared to set a valid width, or else | ||
// paint() | ||
// will receive a bogus clip area and caret will not get drawn properly. | ||
if (width <= 0) | ||
width = getComponent().getWidth(); | ||
|
||
repaint(); //Calls getComponent().repaint(x, y, width, height) to erase | ||
repaint(); // previous location of caret. Sometimes one call isn't enough. | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see javax.swing.text.DefaultCaret#paint(java.awt.Graphics) | ||
*/ | ||
public void paint(Graphics g) | ||
{ | ||
JTextComponent comp = getComponent(); | ||
|
||
if (comp == null) | ||
return; | ||
|
||
int dot = getDot(); | ||
Rectangle r = null; | ||
char dotChar; | ||
try | ||
{ | ||
r = comp.modelToView(dot); | ||
if (r == null) | ||
return; | ||
dotChar = comp.getText(dot, 1).charAt(0); | ||
} | ||
catch (BadLocationException e) | ||
{ | ||
return; | ||
} | ||
|
||
if (Character.isWhitespace(dotChar)) dotChar = '_'; | ||
|
||
if ((x != r.x) || (y != r.y)) | ||
{ | ||
// paint() has been called directly, without a previous call to | ||
// damage(), so do some cleanup. (This happens, for example, when | ||
// the text component is resized.) | ||
damage(r); | ||
return; | ||
} | ||
|
||
g.setColor(comp.getCaretColor()); | ||
g.setXORMode(comp.getBackground()); // do this to draw in XOR mode | ||
|
||
width = g.getFontMetrics().charWidth(dotChar); | ||
if (isVisible()) | ||
g.fillRect(r.x, r.y, width, r.height); | ||
} | ||
} |
Oops, something went wrong.