Skip to content

Commit

Permalink
Fix history list
Browse files Browse the repository at this point in the history
Tidy transition labels
  • Loading branch information
micycle1 committed Jul 5, 2019
1 parent aec8863 commit 7ddcec5
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 75 deletions.
30 changes: 22 additions & 8 deletions src/javafx/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,7 @@ public void initialize(URL location, ResourceBundle resources) {
redo.setDisable(true);
machine_DFA.setDisable(true);

history.setDisable(true); // todo

open.setAccelerator(KeyCombination.keyCombination("SHORTCUT+O"));
save.setAccelerator(KeyCombination.keyCombination("SHORTCUT+S"));
undo.setAccelerator(KeyCombination.keyCombination("SHORTCUT+Z"));
redo.setAccelerator(KeyCombination.keyCombination("SHORTCUT+Y"));
close.setAccelerator(KeyCombination.keyCombination("Esc"));
deleteSelection.setAccelerator(KeyCombination.keyCombination("Del"));
selectAllStates.setAccelerator(KeyCombination.keyCombination("SHORTCUT+A"));

colourPicker_state.setValue(PFLAP.stateColour);
colourPicker_stateSelected.setValue(PFLAP.stateSelectedColour);
Expand Down Expand Up @@ -143,6 +135,23 @@ private void open() {
File f = fileChooser.showOpenDialog(stage);
if (f != null) {
HistoryHandler.loadHistory(f.getAbsolutePath());
machineMenu.getItems().forEach(m -> m.setDisable(false));
switch (PFLAP.mode) {
case DFA :
machine_DFA.setDisable(true);
break;
case DPA :
machine_DPA.setDisable(true);
break;
case MEALY :
machine_mealy.setDisable(true);
break;
case MOORE :
machine_moore.setDisable(true);
break;
default :
break;
}
}
}

Expand Down Expand Up @@ -210,6 +219,11 @@ private void invertSelection() {
/*
* View Menu
*/

@FXML
private void fullscreen() {
stage.setFullScreen(!stage.isFullScreen());
}

@FXML
private void resetZoom() {
Expand Down
41 changes: 34 additions & 7 deletions src/javafx/PFLAP.fxml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.CheckMenuItem?>
<?import javafx.scene.control.ColorPicker?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SeparatorMenuItem?>
<?import javafx.scene.input.KeyCodeCombination?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
Expand All @@ -15,33 +17,58 @@
<menus>
<Menu fx:id="fileMenu" mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="open" mnemonicParsing="false" onAction="#open" text="Open…" />
<MenuItem fx:id="save" mnemonicParsing="false" onAction="#save" text="Save..." />
<MenuItem fx:id="open" mnemonicParsing="false" onAction="#open" text="Open…">
<accelerator>
<KeyCodeCombination alt="UP" code="O" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></MenuItem>
<MenuItem fx:id="save" mnemonicParsing="false" onAction="#save" text="Save...">
<accelerator>
<KeyCodeCombination alt="UP" code="S" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></MenuItem>
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="close" mnemonicParsing="false" onAction="#close" text="Close" />
</items>
</Menu>
<Menu fx:id="editMenu" mnemonicParsing="false" text="Edit">
<items>
<MenuItem fx:id="undo" mnemonicParsing="false" onAction="#undo" text="Undo">
</MenuItem>
<MenuItem fx:id="redo" mnemonicParsing="false" onAction="#redo" text="Redo" />
<accelerator>
<KeyCodeCombination alt="UP" code="Z" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></MenuItem>
<MenuItem fx:id="redo" mnemonicParsing="false" onAction="#redo" text="Redo">
<accelerator>
<KeyCodeCombination alt="UP" code="Y" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></MenuItem>
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="reset" mnemonicParsing="false" onAction="#reset" text="Reset PFLAP" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="deleteSelection" mnemonicParsing="false" onAction="#deleteSelection" text="Delete Selected States" />
<MenuItem fx:id="selectAllStates" mnemonicParsing="false" onAction="#selectAllStates" text="Select All States" />
<MenuItem fx:id="deleteSelection" mnemonicParsing="false" onAction="#deleteSelection" text="Delete Selected States">
<accelerator>
<KeyCodeCombination alt="UP" code="DELETE" control="UP" meta="UP" shift="UP" shortcut="ANY" />
</accelerator></MenuItem>
<MenuItem fx:id="selectAllStates" mnemonicParsing="false" onAction="#selectAllStates" text="Select All States">
<accelerator>
<KeyCodeCombination alt="UP" code="A" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></MenuItem>
<MenuItem fx:id="deleteAllStates" mnemonicParsing="false" onAction="#deleteAllStates" text="Delete All States" />
<MenuItem fx:id="invertSelection" mnemonicParsing="false" onAction="#invertSelection" text="Invert Selection" />
</items>
</Menu>
<Menu fx:id="viewMenu" mnemonicParsing="false" text="View">
<items>
<CheckMenuItem fx:id="fullscreen" mnemonicParsing="false" onAction="#fullscreen" text="Fullscreen">
<accelerator>
<KeyCodeCombination alt="UP" code="F11" control="UP" meta="UP" shift="UP" shortcut="ANY" />
</accelerator>
</CheckMenuItem>
<MenuItem fx:id="resetZoom" mnemonicParsing="false" onAction="#resetZoom" text="Reset Zoom" />
<MenuItem fx:id="resetColors" mnemonicParsing="false" onAction="#resetColors" text="Reset Colours" />
<MenuItem fx:id="saveAsImage" mnemonicParsing="false" onAction="#saveAsImage" text="Save Stage as Image..." />
<MenuItem fx:id="machineInformation" mnemonicParsing="false" onAction="#machineInformation" text="Machine Information..." />
<MenuItem fx:id="history" mnemonicParsing="false" onAction="#history" text="History" />
<CheckMenuItem fx:id="history" mnemonicParsing="false" onAction="#history" text="History">
<accelerator>
<KeyCodeCombination alt="UP" code="H" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></CheckMenuItem>
<Menu fx:id="colourMenu" mnemonicParsing="false" text="Redefine Colours">
<items>
<MenuItem fx:id="colour_state" mnemonicParsing="false" text="State Colour...">
Expand Down
33 changes: 12 additions & 21 deletions src/main/HistoryList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,33 @@

import static main.Functions.colorToRGB;

import commands.Command;
import controlP5.CallbackEvent;
import controlP5.CallbackListener;
import controlP5.ControlP5;
import controlP5.ListBox;
import main.PFLAP.PApplet;

/**
* Manages the controlP5 representation of the user's action history.
* @author micycle1
* @deprecated
*/
public final class HistoryList {

// private static final ControlP5 cP5;
// private static final DropdownList history;

private PApplet p;
private ControlP5 cp5;
private ListBox history;

public HistoryList(PApplet p) {
cp5 = new ControlP5(p);
cp5.hide();
public HistoryList() {
// @formatter:off
history = cp5.addListBox("HistoryList")
.setWidth(160)
history = PFLAP.cp5.addListBox("History")
.setWidth(240)
.setColorBackground(colorToRGB(50, 50, 50))
.setColorForeground(colorToRGB(50, 50, 50))
.setBarHeight(30)
.setItemHeight(20)
.setHeight(200)
.hide()
.addCallback(new CallbackListener() {
@Override
public void controlEvent(CallbackEvent theEvent) {
if (theEvent.getAction() == 100) { // clicked
if (theEvent.getAction() == 100 && PFLAP.allowGUIInterraction) { // clicked
HistoryHandler.movetoIndex((int) history.getValue() - 1);
}
}
Expand All @@ -51,19 +43,18 @@ public void controlEvent(CallbackEvent theEvent) {
protected void update() {
history.clear();
history.open();
// history.addItem("{Init}", null);
// for (Command c : HistoryHandler.export()) {
// history.addItem(c.description(), c);
// }
history.addItem("asds", null);
history.addItem("{Init}", null);
for (Command c : HistoryHandler.export()) {
history.addItem(c.description(), c);
}
}

protected boolean isMouseOver() {
return cp5.isMouseOver();
return history.isMouseOver();
}

public void toggleVisible() {
cp5.setVisible(!cp5.isVisible());
history.setVisible(!history.isVisible());
history.open();
}

Expand Down
33 changes: 4 additions & 29 deletions src/main/PFLAP.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@

/**
* @author micycle1
* @version 1.3
* history list broken
* fix lambda/space functionality
* self-arrows broken w/ big size states
* @version 1.5
*/
public final class PFLAP {

Expand Down Expand Up @@ -90,7 +87,7 @@ public final static class PApplet extends processing.core.PApplet {
private static PFont comfortaaRegular, comfortaaBold;
private static State mouseOverState, arrowTailState, arrowHeadState, dragState;
private static SelectionBox selectionBox;
private static boolean fullScreen = false, newState = false, drawingArrow = false, reset = false;
private static boolean newState = false, drawingArrow = false, reset = false;
private static PVector mouseClickXY, mouseReleasedXY, mouseCoords, zoomPanOffsetp;
private static ZoomPan zoomPan;
private static ArrayList<Command> multiMoveCache;
Expand Down Expand Up @@ -174,7 +171,7 @@ public void setup() {
cp5.setFont(PFLAP.cp5Font);
mode = modes.DFA;
view = new View(this);
historyList = new HistoryList(this);
historyList = new HistoryList();

zoomPanScalep = zoomPan.getZoomScale();
zoomPanOffsetp = zoomPan.getPanOffset();
Expand Down Expand Up @@ -282,6 +279,7 @@ public static void reset() {
default :
break;
}
historyList.update();
reset = false;
}

Expand Down Expand Up @@ -312,8 +310,6 @@ public void keyPressed(KeyEvent e) {
case RIGHT :
Step.stepForward();
break;
case CONTROL :
allowGUIInterraction = false;
default :
break;
}
Expand All @@ -323,31 +319,10 @@ public void keyPressed(KeyEvent e) {

@Override
public void keyReleased(KeyEvent key) {
if (keysDown.contains(CONTROL)) {
switch (key.getKey()) {
case 'H' :
historyList.toggleVisible();
break;
default :
break;
}
}
switch (key.getKeyCode()) {
case 127 : // 127 == delete key
deleteSelection();
break;
case 122 : // F11
if (fullScreen) {
surface.setSize(Consts.WIDTH, Consts.HEIGHT);
surface.setLocation(displayWidth / 2 - width / 2, displayHeight / 2 - height / 2);
} else {
surface.setSize(displayWidth, displayHeight);
surface.setLocation(0, 0);
}
fullScreen = !fullScreen;
break;
case CONTROL :
allowGUIInterraction = true;
default :
break;
}
Expand Down
5 changes: 5 additions & 0 deletions src/p5/AbstractArrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ protected final void drawTransitionLabel(PVector pos) {
p.fill(0);
p.text(transitionInfo, pos.x, pos.y);
}

protected final void drawTransitionLabel(float xPos, float yPos) {
p.fill(0);
p.text(transitionInfo, xPos, yPos);
}

protected final void drawArrowTip(PVector translate, float angle) {
p.noFill();
Expand Down
6 changes: 3 additions & 3 deletions src/p5/BezierArrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BezierArrow extends AbstractArrow {

private float textSize, arrowTipAngle, theta2;
private PVector bezierCPoint, bezierApex, arrowTip, midPoint;

public BezierArrow(State head, State tail, ArrayList<LogicalTransition> t) {
super(head, tail, t);
}
Expand All @@ -36,7 +36,7 @@ public void update() {
arrowTipAngle = angleBetween(head.getPosition(), bezierApex);
arrowTip = new PVector(head.getPosition().x + (head.getRadius() + 3) * -0.5f * cos(arrowTipAngle),
head.getPosition().y + (head.getRadius() + 3) * -0.5f * sin(arrowTipAngle));
// transitionSymbolEntry.setPosition(bezierApex.x - transitionSymbolEntry.getWidth() / 2, bezierApex.y + 10);
// transitionSymbolEntry.setPosition(bezierApex.x - transitionSymbolEntry.getWidth() / 2, bezierApex.y + 10);
stateOptions.setPosition(bezierApex.x, bezierApex.y + 10);
}

Expand All @@ -48,7 +48,7 @@ public void draw() {
drawArrowTip(arrowTip, arrowTipAngle);
p.textAlign(PConstants.CENTER, PConstants.TOP);
p.textSize(textSize);
drawTransitionLabel(bezierApex);
drawTransitionLabel(bezierApex.x, bezierApex.y - textSize / 2);
}

@Override
Expand Down
15 changes: 9 additions & 6 deletions src/p5/SelfArrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.ArrayList;

import model.LogicalTransition;
import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PVector;

Expand All @@ -30,12 +31,16 @@ public SelfArrow(State s, ArrayList<LogicalTransition> t) {
@Override
public void update() {
textSize = 24;
int offset = PApplet.max(head.getRadius() - main.Consts.stateRadius, 0);
offset = 0;
selfBezierCP1 = new PVector(
head.getPosition().x + (selfTransitionLength + offset) * sin(selfTransitionAngle),
head.getPosition().y + (selfTransitionLength + offset) * cos(selfTransitionAngle));

selfBezierCP1 = new PVector(head.getPosition().x + selfTransitionLength * sin(selfTransitionAngle),
head.getPosition().y + selfTransitionLength * cos(selfTransitionAngle));
selfBezierCP2 = new PVector(
head.getPosition().x + selfTransitionLength * sin(selfTransitionAngle + radians(45)),
head.getPosition().y + selfTransitionLength * cos(selfTransitionAngle + radians(45)));
head.getPosition().x + (selfTransitionLength + offset) * sin(selfTransitionAngle + radians(45)),
head.getPosition().y + (selfTransitionLength + offset) * cos(selfTransitionAngle + radians(45)));

selfBezierTranslate = new PVector(head.getPosition().x + head.getRadius() / 2 * sin(selfTransitionAngle),
head.getPosition().y + head.getRadius() / 2 * cos(selfTransitionAngle));
selfBezierAngle = angleBetween(head.getPosition(), selfBezierCP1) - 0.3f;
Expand All @@ -44,8 +49,6 @@ public void update() {
+ 15 * sin(selfTransitionAngle),
p.bezierPoint(head.getPosition().y, selfBezierCP1.y, selfBezierCP2.y, head.getPosition().y, 0.5f)
+ 15 * cos(selfTransitionAngle));
// transitionSymbolEntry.setPosition(selfBezierTextLoc.x - transitionSymbolEntry.getWidth() / 2,
// selfBezierTextLoc.y + 10);
stateOptions.setPosition(selfBezierTextLoc.x, selfBezierTextLoc.y + 10);
}

Expand Down
2 changes: 2 additions & 0 deletions src/p5/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void controlEvent(CallbackEvent input) {
rename.setFocus(false).hide();
rename.clear();
renameState = null;
PFLAP.allowGUIInterraction = true;
}
}
});
Expand Down Expand Up @@ -130,6 +131,7 @@ public void controlEvent(ControlEvent optionSelected) {
break;
case 3 : // Relabel
renameState = State.this;
PFLAP.allowGUIInterraction = false;
rename.setPosition(position.x - rename.getWidth() / 2, position.y + 30);
rename.setFocus(true);
rename.show();
Expand Down
2 changes: 1 addition & 1 deletion src/transitionView/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

/**
* Renders the view of the abstract transitions etc.
* handle initial & accepting state here , not in state class
* handle initial & accepting state here, not in state class
* @author micycle1
*/
public final class View {
Expand Down

0 comments on commit 7ddcec5

Please sign in to comment.