Skip to content

Commit a4f6506

Browse files
committed
Dev: Added Placeholder Classes, updated instructions, added more shortcuts, bugfixes
2 parents 8d9978d + 3b4c071 commit a4f6506

21 files changed

+618
-418
lines changed

src/controller/Controller.java

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import javafx.scene.image.ImageView;
1212
import javafx.stage.Modality;
1313
import javafx.stage.Stage;
14+
import model.conceptual.Class;
1415
import model.conceptual.Edge;
16+
import model.conceptual.Literal;
1517
import model.conceptual.Vertex;
1618
import model.conceptual.Vertex.OutsideElementException;
1719
import model.conceptual.Vertex.UndefinedElementTypeException;
@@ -162,12 +164,12 @@ public final class Controller implements Initializable {
162164
* @param title the title of the new window.
163165
* @param data the parameters passed to the Controller.
164166
* @param <C> a Controller that can pass data to and recieve data from this method (extending
165-
* AbstractDataSharingController).
167+
* DataSharingController).
166168
* @param <T> the type of data passed to and from the Controller.
167169
* @return the data after it has been modified by the Controller.
168170
*/
169171
@FXML @SuppressWarnings("unchecked")
170-
private <C extends AbstractDataSharingController<T>, T> ArrayList<T> showWindow(String fxml, String title, ArrayList<T> data){
172+
private <C extends DataSharingController<T>, T> ArrayList<T> showWindow(String fxml, String title, ArrayList<T> data){
171173
try {
172174
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml));
173175
Parent parent = loader.load();
@@ -250,8 +252,12 @@ private <C extends AbstractDataSharingController<T>, T> ArrayList<T> showWindow(
250252
properties.clear();
251253

252254
try (BufferedReader reader = new BufferedReader(new FileReader(loadFile))){
253-
String graph = reader.readLine(); // TODO: 24/02/2019 may need to read more than one line in case of multiline rdfs:comment?
254-
if (graph == null || graph.length() == 0){
255+
StringBuilder graphLines = new StringBuilder();
256+
String line;
257+
while ((line = reader.readLine()) != null) graphLines.append(line).append("\n");
258+
259+
String graph = graphLines.toString();
260+
if (graph.length() == 0){
255261
setWarnStatus("Graph Read failed: nothing in graph file.");
256262
LOGGER.warning("Nothing in graph file.");
257263
return;
@@ -616,14 +622,17 @@ private void addElementSubaction(MouseEvent mouseEvent) {
616622

617623
if (elementName.getText().equals("")){
618624
isClass = true;
619-
elementName = new Text("_:" + Vertex.getNextBlankNodeName());
625+
elementName = new Text("_:" + Class.getNextBlankNodeName());
620626
} else isClass = !elementName.getText().matches(globalLiteralRegex + "|" + instanceLiteralRegex);
621627

622628
double textWidth = elementName.getBoundsInLocal().getWidth();
623629
if (isClass){
624630
Ellipse elementType = new Ellipse(x, y, textWidth / 2 > 62.5 ? textWidth / 2 + 10 : 62.5, 37.5);
631+
boolean isPlaceholder = classInfo.size() >= 4 && Boolean.valueOf(classInfo.get(4));
632+
625633
elementType.setFill(JFX_DEFAULT_COLOUR);
626634
elementType.setStroke(Color.BLACK);
635+
if (isPlaceholder) elementType.getStrokeDashArray().addAll(10d, 10d);
627636
compiledElement.getChildren().addAll(elementType, elementName);
628637
} else {
629638
Rectangle elementType = new Rectangle(textWidth > 125 ? textWidth + 15 : 125, 75);
@@ -641,13 +650,22 @@ private void addElementSubaction(MouseEvent mouseEvent) {
641650
if (isOntology && isClass) {
642651
String rdfslabel = classInfo.get(2);
643652
String rdfscomment = classInfo.get(3);
644-
classes.add(new Vertex(compiledElement, rdfslabel, rdfscomment));
653+
classes.add(new Class(compiledElement, rdfslabel, rdfscomment));
645654
} else if (isOntology){
646655
String dataType = classInfo.get(1);
647-
classes.add(new Vertex(compiledElement, dataType));
648-
} else classes.add(new Vertex(compiledElement));
649-
} catch (OutsideElementException | UndefinedElementTypeException e) {
650-
e.printStackTrace();
656+
classes.add(new Literal(compiledElement, dataType));
657+
} else if (isClass) {
658+
classes.add(new Class(compiledElement));
659+
} else {
660+
classes.add(new Literal(compiledElement));
661+
}
662+
} catch (UndefinedElementTypeException e) {
663+
setErrorStatus("Adding the element failed: The name does not match Turtle syntax. Recreate the" +
664+
" graph. ");
665+
LOGGER.log(Level.SEVERE, "Adding element failed: ", e);
666+
} catch (OutsideElementException e) {
667+
setErrorStatus("Somehow, you went outside the bounds of the canvas...");
668+
LOGGER.log(Level.SEVERE, "Adding the element failed: ", e);
651669
}
652670
}
653671

@@ -739,20 +757,7 @@ private File showLoadFileDialog(String title, ExtensionFilter extFilter){
739757
* Creates an instructional alert.
740758
*/
741759
private void showInstructionsAlert() {
742-
Alert instrAlert = new Alert(Alert.AlertType.INFORMATION);
743-
instrAlert.setTitle("Instructions on using Drawing Turtles");
744-
instrAlert.setHeaderText(null);
745-
instrAlert.setContentText(
746-
"How to use Drawing Turtles:\nClick once on the button corresponding to the graph element you want to" +
747-
" add to the canvas, then click somewhere on the canvas. Add a name (even in .ttl syntax!) an" +
748-
"d the item will be created in that position. \nIn regards to the Property button, you must c" +
749-
"lick on a valid (already existing) element in the graph as the subject, and then another as " +
750-
"the object. If you click on something that is not a Class or Literal, you will need toclick " +
751-
"the subject-object pair again.\nFeel free to add elements near the edge of the graph, it aut" +
752-
"omatically resizes! "
753-
);
754-
755-
instrAlert.showAndWait();
760+
showWindow("/view/instructions.fxml", "Instructions for Drawing Turtles", null);
756761
}
757762

758763
/**
@@ -809,9 +814,7 @@ private void showOptionsDialog() {
809814
return;
810815
}
811816

812-
LOGGER.info("AFTER Correlation:" +
813-
"\nCorrelated: " + dataIntegrator.getCorrelations().toString() +
814-
"\nUncorrelated (assumed constant): " + dataIntegrator.uncorrelatedClassesToString());
817+
LOGGER.info("AFTER Correlation:" + "\nCorrelated: " + dataIntegrator.getCorrelations().toString());
815818

816819
try {
817820
instanceData = dataIntegrator.generate();

src/controller/CorrelateDialogController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* The controller for view.correlateDialog.fxml.
2424
*/
25-
public class CorrelateDialogController extends AbstractDataSharingController<DataIntegrator> implements Initializable {
25+
public class CorrelateDialogController extends DataSharingController<DataIntegrator> implements Initializable {
2626
@FXML Button addManualCorrBtn, addHeaderBtn, commitBtn, cancelBtn;
2727
@FXML ListView<String> csvHeaderList;
2828
@FXML ListView<String> csvTtlCorrelationList;
@@ -114,7 +114,7 @@ public class CorrelateDialogController extends AbstractDataSharingController<Dat
114114
/**
115115
* Close the Window and mark the modified DataIntegrator for commital.
116116
*/
117-
@FXML void commitCorrelationBtn() {
117+
@FXML void commitCorrelationAction() {
118118
dataIntegrator.setCorrelations(correlations);
119119
dataIntegrator.setUncorrelated(new Pair<>(uncorrelatedCsvHeaders, uncorrelatedTtlClasses));
120120
Stage stage = (Stage) commitBtn.getScene().getWindow();
@@ -124,7 +124,7 @@ public class CorrelateDialogController extends AbstractDataSharingController<Dat
124124
/**
125125
* Close the Window.
126126
*/
127-
@FXML void cancelCorrelationBtn() {
127+
@FXML void cancelCorrelationAction() {
128128
Stage stage = (Stage) cancelBtn.getScene().getWindow();
129129
stage.close();
130130
}

src/controller/AbstractDataSharingController.java renamed to src/controller/DataSharingController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* An abstract Controller that faciliitates the passing of data to and from the Controller class.
77
* @param <T> the type of data passed between the two controllers.
88
*/
9-
abstract class AbstractDataSharingController<T> {
9+
abstract class DataSharingController<T> {
1010

1111
/**
1212
* The method that passes data from the Caller to the Callee.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package controller;
2+
3+
import javafx.fxml.FXML;
4+
import javafx.scene.control.Button;
5+
import javafx.stage.Stage;
6+
7+
import java.util.ArrayList;
8+
9+
public class InstructionsController extends DataSharingController<String> {
10+
@FXML Button closeBtn;
11+
12+
13+
14+
@FXML void closeAction() { ((Stage) closeBtn.getScene().getWindow()).close(); }
15+
16+
@Override public void setData(ArrayList<String> data) {}
17+
@Override public ArrayList<String> getData() { return null; }
18+
}

src/controller/NewClassDialogController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* The controller for view.newClassDialog.fxml.
2020
*/
21-
public class NewClassDialogController extends AbstractDataSharingController<String> implements Initializable {
21+
public class NewClassDialogController extends DataSharingController<String> implements Initializable {
2222
private final BooleanProperty isClasslike = new SimpleBooleanProperty(false);
2323
private final BooleanProperty isLiterallike = new SimpleBooleanProperty(false);
2424

src/controller/OntologyClassDialogController.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javafx.fxml.FXML;
66
import javafx.fxml.Initializable;
77
import javafx.scene.control.Button;
8+
import javafx.scene.control.CheckBox;
89
import javafx.scene.control.TextArea;
910
import javafx.scene.control.TextField;
1011
import javafx.stage.Stage;
@@ -17,10 +18,11 @@
1718
/**
1819
* The controller for ontologyClassDialog.fxml.
1920
*/
20-
public class OntologyClassDialogController extends AbstractDataSharingController<String> implements Initializable {
21+
public class OntologyClassDialogController extends DataSharingController<String> implements Initializable {
2122
@FXML Button cmtBtn, cancelBtn;
2223
@FXML TextField typeTfd, nameTfd, labelTfd;
2324
@FXML TextArea commentTxa;
25+
@FXML CheckBox placeholderClassCbx;
2426

2527
private final BooleanProperty isClasslike = new SimpleBooleanProperty(false);
2628
private final BooleanProperty isLiterallike = new SimpleBooleanProperty(false);
@@ -34,6 +36,8 @@ public class OntologyClassDialogController extends AbstractDataSharingController
3436
*/
3537
@Override
3638
public void initialize(URL location, ResourceBundle resources) {
39+
placeholderClassCbx.setSelected(false);
40+
3741
nameTfd.textProperty().addListener(((observable, oldValue, newValue) -> {
3842
final String stringLitRegex = "\".+\"";
3943
final String otherLitRegex = "\".+\"\\^\\^.*";
@@ -74,9 +78,11 @@ else if (newValue.matches(otherLitRegex)) {
7478
if (observable.getValue().booleanValue()){
7579
labelTfd.setDisable(false);
7680
commentTxa.setDisable(false);
81+
placeholderClassCbx.setDisable(false);
7782
} else {
7883
labelTfd.setDisable(true);
7984
commentTxa.setDisable(true);
85+
placeholderClassCbx.setDisable(true);
8086
labelTfd.setText("");
8187
commentTxa.setText("");
8288
}
@@ -95,7 +101,12 @@ else if (newValue.matches(otherLitRegex)) {
95101
* Add the created class and it's associated metadata for commital, and close the Window.
96102
*/
97103
@FXML void addNewClassAction() {
98-
commit_data.addAll(Arrays.asList(nameTfd.getText(), typeTfd.getText(), labelTfd.getText(), commentTxa.getText()));
104+
commit_data.addAll(Arrays.asList(
105+
nameTfd.getText(),
106+
typeTfd.getText(),
107+
labelTfd.getText(),
108+
commentTxa.getText(),
109+
Boolean.toString(placeholderClassCbx.isSelected())));
99110
Stage stage = (Stage) cmtBtn.getScene().getWindow();
100111
stage.close();
101112
}

src/controller/OptionsMenuController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Controller for view.optionsmenu.fxml.
1212
*/
13-
public class OptionsMenuController extends AbstractDataSharingController<Boolean> {
13+
public class OptionsMenuController extends DataSharingController<Boolean> {
1414
@FXML Button cancelBtn, commitBtn;
1515
@FXML CheckBox collectionsCbx, blankCbx, ontologyCbx;
1616

src/controller/PrefixMenuController.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
import javafx.fxml.Initializable;
88
import javafx.geometry.Insets;
99
import javafx.scene.control.*;
10-
import javafx.scene.layout.AnchorPane;
11-
import javafx.scene.layout.Background;
12-
import javafx.scene.layout.BackgroundFill;
13-
import javafx.scene.layout.CornerRadii;
10+
import javafx.scene.input.KeyCode;
11+
import javafx.scene.input.KeyEvent;
12+
import javafx.scene.layout.*;
1413
import javafx.scene.paint.Color;
1514
import javafx.stage.FileChooser;
1615
import javafx.stage.Stage;
@@ -31,11 +30,11 @@
3130
/**
3231
* Controller for view.prefixmenu.fxml.
3332
*/
34-
public class PrefixMenuController extends AbstractDataSharingController<Map<String, String>> implements Initializable {
33+
public class PrefixMenuController extends DataSharingController<Map<String, String>> implements Initializable {
3534

3635
private static final Logger LOGGER = Logger.getLogger(PrefixMenuController.class.getName());
3736

38-
@FXML AnchorPane root;
37+
@FXML BorderPane root;
3938
@FXML ToolBar toolBar;
4039
@FXML Button addPrefixBtn, remPrefixBtn, clrPrefixBtn, savPrefixBtn, lodPrefixBtn, cmtPrefixBtn, canPrefixBtn;
4140
@FXML ListView<String> prefixList;
@@ -63,6 +62,16 @@ public class PrefixMenuController extends AbstractDataSharingController<Map<Stri
6362
});
6463
}
6564

65+
@FXML void keyPressedAction(KeyEvent keyEvent) {
66+
KeyCode keyCode = keyEvent.getCode();
67+
68+
if (keyCode == KeyCode.ENTER) commitPrefixAction();
69+
else if (keyCode == KeyCode.S) savePrefixAction();
70+
else if (keyCode == KeyCode.L) loadPrefixAction();
71+
else if (keyCode == KeyCode.A) addPrefixAction();
72+
else if (keyCode == KeyCode.C) cancelPrefixAction();
73+
}
74+
6675
/**
6776
* On clicking the 'Add Prefix' button, adds prefixes to the arraylist of existing prefixes unless malformed.
6877
*/

0 commit comments

Comments
 (0)