Skip to content

Commit bd26549

Browse files
authored
Merge pull request #334 from ProgrammingLife2017/cssAndFormat
Updated onClick and formatting
2 parents 90e118d + 1560046 commit bd26549

13 files changed

+383
-116
lines changed

.idea/misc.xml

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/programminglife/ProgrammingLife.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
public final class ProgrammingLife extends Application {
2929

3030
private static Stage primaryStage;
31+
private static boolean showCSS = false;
32+
private static AnchorPane root;
3133

3234
/**
3335
* Main method for the application.
@@ -41,7 +43,8 @@ public static void main(String[] args) {
4143
@Override
4244
public void start(Stage stage) throws IOException {
4345
FXMLLoader loader = new FXMLLoader(getClass().getResource("/Basic_Gui.fxml"));
44-
AnchorPane root = loader.load();
46+
root = loader.load();
47+
root.getStylesheets().add("/LightTheme.css");
4548
primaryStage = stage;
4649
primaryStage.setTitle("Programming Life");
4750
primaryStage.setScene(new Scene(root));
@@ -106,6 +109,22 @@ private void arguments(GuiController guiCtrl) throws IOException {
106109
});
107110
};
108111

112+
/**
113+
* Toggles which styleSheets is used for the program.
114+
*/
115+
public static void toggleCSS() {
116+
showCSS = !showCSS;
117+
Platform.runLater(() -> {
118+
if (showCSS) {
119+
root.getStylesheets().remove("/LightTheme.css");
120+
root.getStylesheets().add("/DarkTheme.css");
121+
} else {
122+
root.getStylesheets().remove("/DarkTheme.css");
123+
root.getStylesheets().add("/LightTheme.css");
124+
}
125+
});
126+
}
127+
109128
/**
110129
* Returns the Stage if called upon.
111130
*

src/main/java/programminglife/gui/controller/GraphController.java

+83-32
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class GraphController {
2626
private final ResizableCanvas canvas;
2727
private final int archFactor = 5;
2828

29-
private DrawableSegment clicked1;
30-
private DrawableSegment clicked2;
29+
private DrawableSegment clicked;
30+
private DrawableSegment clickedShift;
31+
private DrawableSNP clickedSNP;
32+
private DrawableSNP clickedSNPShift;
3133

3234
private int centerNodeInt;
3335
private boolean drawSNP = false;
34-
private DrawableSegment highlightSegmentShift;
35-
private DrawableSegment highlightSegment;
3636

3737
private HighlightController highlightController;
3838

@@ -235,7 +235,6 @@ private void drawSNP(GraphicsContext gc, DrawableSNP drawableSNP) {
235235

236236
int size = drawableSNP.getMutations().size();
237237
int seqNumber = 0;
238-
239238
gc.strokeRoundRect(locX, locY, width, height, archFactor, archFactor);
240239

241240
for (DrawableSegment drawableSegment : drawableSNP.getMutations()) {
@@ -347,17 +346,29 @@ public void zoom(double scale) {
347346
private void draw(GraphicsContext gc) {
348347
gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
349348

350-
if (clicked1 != null) {
351-
highlightNode(clicked1, Color.DARKTURQUOISE);
352-
clicked1.setStrokeWidth(5.0 * subGraph.getZoomLevel());
349+
if (clicked != null) {
350+
highlightNode(clicked, Color.DARKTURQUOISE);
351+
clicked.setStrokeWidth(5.0 * subGraph.getZoomLevel());
353352
}
354-
if (clicked2 != null) {
355-
highlightNode(clicked2, Color.PURPLE);
356-
clicked2.setStrokeWidth(5.0 * subGraph.getZoomLevel());
353+
if (clickedSNP != null) {
354+
highlightNode(clickedSNP, Color.DARKTURQUOISE);
355+
clickedSNP.setStrokeWidth(5.0 * subGraph.getZoomLevel());
357356
}
358-
if (clicked1 == clicked2 && clicked1 != null && clicked2 != null) {
359-
highlightNode(clicked1, Color.DARKCYAN);
360-
clicked1.setStrokeWidth(5.0 * subGraph.getZoomLevel());
357+
if (clickedShift != null) {
358+
highlightNode(clickedShift, Color.PURPLE);
359+
clickedShift.setStrokeWidth(5.0 * subGraph.getZoomLevel());
360+
}
361+
if (clickedSNPShift != null) {
362+
highlightNode(clickedSNPShift, Color.PURPLE);
363+
clickedSNPShift.setStrokeWidth(5.0 * subGraph.getZoomLevel());
364+
}
365+
if (clicked == clickedShift && clicked != null && clickedShift != null) {
366+
highlightNode(clicked, Color.DARKCYAN);
367+
clicked.setStrokeWidth(5.0 * subGraph.getZoomLevel());
368+
}
369+
if (clickedSNP == clickedSNPShift && clickedSNP != null && clickedSNPShift != null) {
370+
highlightNode(clickedSNP, Color.DARKCYAN);
371+
clickedSNP.setStrokeWidth(5.0 * subGraph.getZoomLevel());
361372
}
362373

363374
boolean didLoad = subGraph.checkDynamicLoad(0, canvas.getWidth());
@@ -434,8 +445,17 @@ public void highlightByGenome(int genomeID, Color color) {
434445
*/
435446
void setSNP() {
436447
drawSNP = !drawSNP;
437-
clicked1 = null;
438-
clicked2 = null;
448+
resetClicked();
449+
}
450+
451+
/**
452+
* Resets which nodes are clicked on.
453+
*/
454+
void resetClicked() {
455+
clicked = null;
456+
clickedShift = null;
457+
clickedSNP = null;
458+
clickedSNPShift = null;
439459
}
440460

441461
/**
@@ -450,28 +470,47 @@ public Drawable onClick(double x, double y) {
450470
}
451471

452472
/**
453-
* Method to hightlight the node clicked on.
473+
* Method to highlight the node clicked on.
454474
*
455475
* @param segment is the {@link DrawableSegment} clicked on.
476+
* @param snp is the {@link DrawableSNP} clicked on.
456477
* @param shiftPressed boolean true if shift was pressed during the click.
457478
*/
458-
public void highlightClicked(DrawableSegment segment, boolean shiftPressed) {
479+
public void highlightClicked(DrawableSegment segment, DrawableSNP snp, boolean shiftPressed) {
459480
if (shiftPressed) {
460-
if (highlightSegmentShift != null) {
461-
this.highlightSegmentShift.colorize(subGraph);
481+
if (clicked != null) {
482+
this.clicked.colorize(subGraph);
483+
}
484+
if (clickedSNP != null) {
485+
this.clickedSNP.colorize(subGraph);
486+
}
487+
this.clicked = segment;
488+
this.clickedSNP = snp;
489+
if (segment != null) {
490+
highlightNode(segment, Color.DARKTURQUOISE);
491+
segment.setStrokeWidth(5.0 * subGraph.getZoomLevel()); //Correct thickness when zoomed
492+
}
493+
if (snp != null) {
494+
highlightNode(snp, Color.DARKTURQUOISE);
495+
snp.setStrokeWidth(5.0 * subGraph.getZoomLevel()); //Correct thickness when zoomed
462496
}
463-
this.highlightSegmentShift = segment;
464-
this.clicked1 = segment;
465-
highlightNode(segment, Color.DARKTURQUOISE);
466-
segment.setStrokeWidth(5.0 * subGraph.getZoomLevel()); //Correct thickness when zoomed
467497
} else {
468-
if (highlightSegment != null) {
469-
this.highlightSegment.colorize(subGraph);
498+
if (clickedShift != null) {
499+
this.clickedShift.colorize(subGraph);
500+
}
501+
if (clickedSNPShift != null) {
502+
this.clickedSNPShift.colorize(subGraph);
503+
}
504+
this.clickedShift = segment;
505+
this.clickedSNPShift = snp;
506+
if (segment != null) {
507+
highlightNode(segment, Color.PURPLE);
508+
segment.setStrokeWidth(5.0 * subGraph.getZoomLevel()); //Correct thickness when zoomed
509+
}
510+
if (snp != null) {
511+
highlightNode(snp, Color.PURPLE);
512+
snp.setStrokeWidth(5.0 * subGraph.getZoomLevel()); //Correct thickness when zoomed
470513
}
471-
this.highlightSegment = segment;
472-
this.clicked2 = segment;
473-
highlightNode(segment, Color.PURPLE);
474-
segment.setStrokeWidth(5.0 * subGraph.getZoomLevel()); //Correct thickness when zoomed
475514
}
476515
draw(canvas.getGraphicsContext2D());
477516
}
@@ -498,11 +537,23 @@ public Collection<Integer> getGenomesEdge(DrawableEdge edge) {
498537
return null;
499538
}
500539

501-
public Collection<DrawableNode> getParentSegments(DrawableSegment node) {
540+
/**
541+
* Method to return the segments in a given edge.
542+
*
543+
* @param node the Drawable segment the check which parent segments it contains.
544+
* @return Collection<Integer> of the parents segments in the node.
545+
*/
546+
Collection<DrawableNode> getParentSegments(DrawableSegment node) {
502547
return subGraph.getParentSegments(node);
503548
}
504549

505-
public Collection<DrawableNode> getChildSegments(DrawableSegment node) {
550+
/**
551+
* Method to return the segments in a given edge.
552+
*
553+
* @param node the Drawable segment the check which child segments it contains.
554+
* @return Collection<Integer> of the child segments in the node.
555+
*/
556+
Collection<DrawableNode> getChildSegments(DrawableSegment node) {
506557
return subGraph.getChildSegments(node);
507558
}
508559

src/main/java/programminglife/gui/controller/GuiController.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ public class GuiController implements Observer {
5858
@FXML private MenuItem btnInstructions;
5959
@FXML private Menu menuRecentGFA;
6060

61+
@FXML private RadioMenuItem btnDark;
6162
@FXML private RadioMenuItem btnSNP;
6263
@FXML private RadioMenuItem btnConsole;
6364
@FXML private RadioMenuItem btnMiniMap;
6465

6566
@FXML private Button btnZoomReset;
66-
@FXML private Button btnTranslateReset;
6767
@FXML private Button btnDraw;
6868
@FXML private Button btnDrawRandom;
6969
@FXML private Button btnBookmark;
@@ -92,7 +92,6 @@ public class GuiController implements Observer {
9292
private File recentFileGFA = new File("RecentGFA.txt");
9393
private Thread parseThread;
9494

95-
private final ExtensionFilter extFilterGFF = new ExtensionFilter("GFF files (*.gff)", "*.GFF");
9695
private final ExtensionFilter extFilterGFA = new ExtensionFilter("GFA files (*.gfa)", "*.GFA");
9796

9897
private static final double MAX_SCALE = 10.0d;
@@ -130,6 +129,7 @@ private void initialize() {
130129
public GraphParser openFile(File file) {
131130
if (file != null) {
132131
if (this.graphController != null && this.graphController.getGraph() != null) {
132+
this.graphController.resetClicked();
133133
this.graphController.getGraph().close();
134134
this.canvas.getGraphicsContext2D().clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
135135
}
@@ -255,6 +255,9 @@ private void initMenuBar() {
255255
Platform.runLater(this::draw);
256256
});
257257
btnSNP.setAccelerator(new KeyCodeCombination(KeyCode.G, KeyCodeCombination.CONTROL_DOWN));
258+
259+
btnDark.setOnAction(event -> ProgrammingLife.toggleCSS());
260+
btnDark.setAccelerator(new KeyCodeCombination(KeyCode.Z, KeyCodeCombination.CONTROL_DOWN));
258261
}
259262

260263

@@ -302,9 +305,10 @@ private void disableGraphUIElements(boolean isDisabled) {
302305
private void initLeftControlpanelScreenModifiers() {
303306
disableGraphUIElements(true);
304307

305-
btnTranslateReset.setOnAction(event -> this.draw());
306-
307-
btnZoomReset.setOnAction(event -> this.draw());
308+
btnZoomReset.setOnAction(event -> {
309+
graphController.resetClicked();
310+
this.draw();
311+
});
308312
}
309313

310314
/**
@@ -438,14 +442,15 @@ private void mouseClick(double x, double y, boolean shiftPressed) {
438442
} else {
439443
showInfoSNP(snp, 10);
440444
}
445+
graphController.highlightClicked(null, snp, shiftPressed);
441446
} else if (clickedOn instanceof DrawableSegment) {
442447
DrawableSegment segment = (DrawableSegment) clickedOn;
443448
if (shiftPressed) {
444449
showInfoNode(segment, 240);
445450
} else {
446451
showInfoNode(segment, 10);
447452
}
448-
graphController.highlightClicked(segment, shiftPressed);
453+
graphController.highlightClicked(segment, null, shiftPressed);
449454
} else if (clickedOn instanceof DrawableEdge) {
450455
DrawableEdge edge = (DrawableEdge) clickedOn;
451456
if (shiftPressed) {
@@ -690,7 +695,7 @@ private void showInfoNode(DrawableSegment node, int x) {
690695
}
691696

692697
String genomesString = graphController.getGraph().getGenomeNames(node.getGenomes()).toString();
693-
String sequenceString = node.getSequence().replaceAll("(.{24})", "$1" + System.getProperty("line.separator"));
698+
String sequenceString = node.getSequence().replaceAll("(.{23})", "$1" + System.getProperty("line.separator"));
694699
TextField inEdges = getTextField("Incoming Edges: ", x, 190, Integer.toString(node.getParents().size()));
695700
TextField outEdges = getTextField("Outgoing Edges: ", x, 230, Integer.toString(node.getChildren().size()));
696701
TextField seqLength = getTextField("Sequence Length: ", x, 270, Integer.toString(node.getSequence().length()));
@@ -749,9 +754,6 @@ private TextField getTextField(String id, int x, int y, String text) {
749754
textField.setLayoutX(x);
750755
textField.setLayoutY(y);
751756
textField.setEditable(false);
752-
textField.setStyle("-fx-text-box-border: transparent;-fx-background-color: none; -fx-background-insets: 0;"
753-
+ " -fx-padding: 1 3 1 3; -fx-focus-color: transparent; "
754-
+ "-fx-faint-focus-color: transparent; -fx-font-family: monospace;");
755757
textField.setPrefSize(220, 20);
756758

757759
return textField;
@@ -774,9 +776,6 @@ private TextArea getTextArea(String id, int x, int y, String text, int height) {
774776
textArea.setLayoutX(x);
775777
textArea.setLayoutY(y);
776778
textArea.setEditable(false);
777-
textArea.setStyle("-fx-text-box-border: transparent;-fx-background-color: none; -fx-background-insets: 0;"
778-
+ " -fx-padding: 1 3 1 3; -fx-focus-color: transparent; "
779-
+ "-fx-faint-focus-color: transparent; -fx-font-family: monospace;");
780779
textArea.setPrefSize(225, height);
781780

782781
return textArea;

src/main/java/programminglife/gui/controller/RecentFileController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private void initRecent() {
102102
} catch (FileAlreadyExistsException e) {
103103
//This will always happen if a user has used the program before.
104104
//Therefore it is unnecessary to handle further.
105-
Console.println("Recent file couldn't be found. New one created.");
105+
Console.println("Recent file has been found and will be used.");
106106
} catch (IOException e) {
107107
Alerts.error("Recent.txt can't be opened");
108108
return;

src/main/java/programminglife/model/drawing/DrawableSNP.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public Collection<Integer> getGenomes() {
133133
*/
134134
@Override
135135
protected void setDrawDimensions(double zoomLevel) {
136-
this.setSize(new XYCoordinate(NODE_HEIGHT * zoomLevel, NODE_HEIGHT));
136+
this.setSize(new XYCoordinate(NODE_HEIGHT * zoomLevel, NODE_HEIGHT * zoomLevel));
137137
}
138138

139139
/**

src/main/java/programminglife/model/drawing/DrawableSegment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void setDrawDimensions(double zoomLevel) {
112112
width = 10 + Math.pow(segmentLength, 1.0 / 2);
113113
height = NODE_HEIGHT;
114114

115-
this.setSize(width, height * zoomLevel);
115+
this.setSize(width * zoomLevel, height * zoomLevel);
116116
}
117117

118118
@Override

src/main/java/programminglife/model/drawing/Layer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void setDrawLocations(double y, double zoomLevel) {
168168
*/
169169
public void setSize(double scale) {
170170
for (DrawableNode node : nodes) {
171-
node.setWidth(node.getWidth() * scale);
171+
node.setDrawDimensions(scale);
172172
}
173173
}
174174

src/main/java/programminglife/model/drawing/SubGraph.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private static void findNodes(SubGraph subGraph, Collection<DrawableNode> startN
188188

189189
DrawableNode previous;
190190
if (excludedNodes.containsKey(current.node.getIdentifier())) {
191-
if (startNodes.contains(current.node) && !foundNodes.containsKey(current.node.getIdentifier())) {
191+
if (startNodes.contains(current.node)) {
192192
previous = null; // to signify it did not exist in subGraph.nodes yet.
193193
} else {
194194
continue; // This is an excluded node, just continue with next

0 commit comments

Comments
 (0)