Skip to content

Commit

Permalink
Dev: Added Placeholder Classes, updated instructions, added more shor…
Browse files Browse the repository at this point in the history
…tcuts, bugfixes
  • Loading branch information
CodeGat committed Feb 25, 2019
2 parents 8d9978d + 3b4c071 commit a4f6506
Show file tree
Hide file tree
Showing 21 changed files with 618 additions and 418 deletions.
57 changes: 30 additions & 27 deletions src/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import javafx.scene.image.ImageView;
import javafx.stage.Modality;
import javafx.stage.Stage;
import model.conceptual.Class;
import model.conceptual.Edge;
import model.conceptual.Literal;
import model.conceptual.Vertex;
import model.conceptual.Vertex.OutsideElementException;
import model.conceptual.Vertex.UndefinedElementTypeException;
Expand Down Expand Up @@ -162,12 +164,12 @@ public final class Controller implements Initializable {
* @param title the title of the new window.
* @param data the parameters passed to the Controller.
* @param <C> a Controller that can pass data to and recieve data from this method (extending
* AbstractDataSharingController).
* DataSharingController).
* @param <T> the type of data passed to and from the Controller.
* @return the data after it has been modified by the Controller.
*/
@FXML @SuppressWarnings("unchecked")
private <C extends AbstractDataSharingController<T>, T> ArrayList<T> showWindow(String fxml, String title, ArrayList<T> data){
private <C extends DataSharingController<T>, T> ArrayList<T> showWindow(String fxml, String title, ArrayList<T> data){
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml));
Parent parent = loader.load();
Expand Down Expand Up @@ -250,8 +252,12 @@ private <C extends AbstractDataSharingController<T>, T> ArrayList<T> showWindow(
properties.clear();

try (BufferedReader reader = new BufferedReader(new FileReader(loadFile))){
String graph = reader.readLine(); // TODO: 24/02/2019 may need to read more than one line in case of multiline rdfs:comment?
if (graph == null || graph.length() == 0){
StringBuilder graphLines = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) graphLines.append(line).append("\n");

String graph = graphLines.toString();
if (graph.length() == 0){
setWarnStatus("Graph Read failed: nothing in graph file.");
LOGGER.warning("Nothing in graph file.");
return;
Expand Down Expand Up @@ -616,14 +622,17 @@ private void addElementSubaction(MouseEvent mouseEvent) {

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

double textWidth = elementName.getBoundsInLocal().getWidth();
if (isClass){
Ellipse elementType = new Ellipse(x, y, textWidth / 2 > 62.5 ? textWidth / 2 + 10 : 62.5, 37.5);
boolean isPlaceholder = classInfo.size() >= 4 && Boolean.valueOf(classInfo.get(4));

elementType.setFill(JFX_DEFAULT_COLOUR);
elementType.setStroke(Color.BLACK);
if (isPlaceholder) elementType.getStrokeDashArray().addAll(10d, 10d);
compiledElement.getChildren().addAll(elementType, elementName);
} else {
Rectangle elementType = new Rectangle(textWidth > 125 ? textWidth + 15 : 125, 75);
Expand All @@ -641,13 +650,22 @@ private void addElementSubaction(MouseEvent mouseEvent) {
if (isOntology && isClass) {
String rdfslabel = classInfo.get(2);
String rdfscomment = classInfo.get(3);
classes.add(new Vertex(compiledElement, rdfslabel, rdfscomment));
classes.add(new Class(compiledElement, rdfslabel, rdfscomment));
} else if (isOntology){
String dataType = classInfo.get(1);
classes.add(new Vertex(compiledElement, dataType));
} else classes.add(new Vertex(compiledElement));
} catch (OutsideElementException | UndefinedElementTypeException e) {
e.printStackTrace();
classes.add(new Literal(compiledElement, dataType));
} else if (isClass) {
classes.add(new Class(compiledElement));
} else {
classes.add(new Literal(compiledElement));
}
} catch (UndefinedElementTypeException e) {
setErrorStatus("Adding the element failed: The name does not match Turtle syntax. Recreate the" +
" graph. ");
LOGGER.log(Level.SEVERE, "Adding element failed: ", e);
} catch (OutsideElementException e) {
setErrorStatus("Somehow, you went outside the bounds of the canvas...");
LOGGER.log(Level.SEVERE, "Adding the element failed: ", e);
}
}

Expand Down Expand Up @@ -739,20 +757,7 @@ private File showLoadFileDialog(String title, ExtensionFilter extFilter){
* Creates an instructional alert.
*/
private void showInstructionsAlert() {
Alert instrAlert = new Alert(Alert.AlertType.INFORMATION);
instrAlert.setTitle("Instructions on using Drawing Turtles");
instrAlert.setHeaderText(null);
instrAlert.setContentText(
"How to use Drawing Turtles:\nClick once on the button corresponding to the graph element you want to" +
" add to the canvas, then click somewhere on the canvas. Add a name (even in .ttl syntax!) an" +
"d the item will be created in that position. \nIn regards to the Property button, you must c" +
"lick on a valid (already existing) element in the graph as the subject, and then another as " +
"the object. If you click on something that is not a Class or Literal, you will need toclick " +
"the subject-object pair again.\nFeel free to add elements near the edge of the graph, it aut" +
"omatically resizes! "
);

instrAlert.showAndWait();
showWindow("/view/instructions.fxml", "Instructions for Drawing Turtles", null);
}

/**
Expand Down Expand Up @@ -809,9 +814,7 @@ private void showOptionsDialog() {
return;
}

LOGGER.info("AFTER Correlation:" +
"\nCorrelated: " + dataIntegrator.getCorrelations().toString() +
"\nUncorrelated (assumed constant): " + dataIntegrator.uncorrelatedClassesToString());
LOGGER.info("AFTER Correlation:" + "\nCorrelated: " + dataIntegrator.getCorrelations().toString());

try {
instanceData = dataIntegrator.generate();
Expand Down
6 changes: 3 additions & 3 deletions src/controller/CorrelateDialogController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* The controller for view.correlateDialog.fxml.
*/
public class CorrelateDialogController extends AbstractDataSharingController<DataIntegrator> implements Initializable {
public class CorrelateDialogController extends DataSharingController<DataIntegrator> implements Initializable {
@FXML Button addManualCorrBtn, addHeaderBtn, commitBtn, cancelBtn;
@FXML ListView<String> csvHeaderList;
@FXML ListView<String> csvTtlCorrelationList;
Expand Down Expand Up @@ -114,7 +114,7 @@ public class CorrelateDialogController extends AbstractDataSharingController<Dat
/**
* Close the Window and mark the modified DataIntegrator for commital.
*/
@FXML void commitCorrelationBtn() {
@FXML void commitCorrelationAction() {
dataIntegrator.setCorrelations(correlations);
dataIntegrator.setUncorrelated(new Pair<>(uncorrelatedCsvHeaders, uncorrelatedTtlClasses));
Stage stage = (Stage) commitBtn.getScene().getWindow();
Expand All @@ -124,7 +124,7 @@ public class CorrelateDialogController extends AbstractDataSharingController<Dat
/**
* Close the Window.
*/
@FXML void cancelCorrelationBtn() {
@FXML void cancelCorrelationAction() {
Stage stage = (Stage) cancelBtn.getScene().getWindow();
stage.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* An abstract Controller that faciliitates the passing of data to and from the Controller class.
* @param <T> the type of data passed between the two controllers.
*/
abstract class AbstractDataSharingController<T> {
abstract class DataSharingController<T> {

/**
* The method that passes data from the Caller to the Callee.
Expand Down
18 changes: 18 additions & 0 deletions src/controller/InstructionsController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package controller;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.stage.Stage;

import java.util.ArrayList;

public class InstructionsController extends DataSharingController<String> {
@FXML Button closeBtn;



@FXML void closeAction() { ((Stage) closeBtn.getScene().getWindow()).close(); }

@Override public void setData(ArrayList<String> data) {}
@Override public ArrayList<String> getData() { return null; }
}
2 changes: 1 addition & 1 deletion src/controller/NewClassDialogController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* The controller for view.newClassDialog.fxml.
*/
public class NewClassDialogController extends AbstractDataSharingController<String> implements Initializable {
public class NewClassDialogController extends DataSharingController<String> implements Initializable {
private final BooleanProperty isClasslike = new SimpleBooleanProperty(false);
private final BooleanProperty isLiterallike = new SimpleBooleanProperty(false);

Expand Down
15 changes: 13 additions & 2 deletions src/controller/OntologyClassDialogController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
Expand All @@ -17,10 +18,11 @@
/**
* The controller for ontologyClassDialog.fxml.
*/
public class OntologyClassDialogController extends AbstractDataSharingController<String> implements Initializable {
public class OntologyClassDialogController extends DataSharingController<String> implements Initializable {
@FXML Button cmtBtn, cancelBtn;
@FXML TextField typeTfd, nameTfd, labelTfd;
@FXML TextArea commentTxa;
@FXML CheckBox placeholderClassCbx;

private final BooleanProperty isClasslike = new SimpleBooleanProperty(false);
private final BooleanProperty isLiterallike = new SimpleBooleanProperty(false);
Expand All @@ -34,6 +36,8 @@ public class OntologyClassDialogController extends AbstractDataSharingController
*/
@Override
public void initialize(URL location, ResourceBundle resources) {
placeholderClassCbx.setSelected(false);

nameTfd.textProperty().addListener(((observable, oldValue, newValue) -> {
final String stringLitRegex = "\".+\"";
final String otherLitRegex = "\".+\"\\^\\^.*";
Expand Down Expand Up @@ -74,9 +78,11 @@ else if (newValue.matches(otherLitRegex)) {
if (observable.getValue().booleanValue()){
labelTfd.setDisable(false);
commentTxa.setDisable(false);
placeholderClassCbx.setDisable(false);
} else {
labelTfd.setDisable(true);
commentTxa.setDisable(true);
placeholderClassCbx.setDisable(true);
labelTfd.setText("");
commentTxa.setText("");
}
Expand All @@ -95,7 +101,12 @@ else if (newValue.matches(otherLitRegex)) {
* Add the created class and it's associated metadata for commital, and close the Window.
*/
@FXML void addNewClassAction() {
commit_data.addAll(Arrays.asList(nameTfd.getText(), typeTfd.getText(), labelTfd.getText(), commentTxa.getText()));
commit_data.addAll(Arrays.asList(
nameTfd.getText(),
typeTfd.getText(),
labelTfd.getText(),
commentTxa.getText(),
Boolean.toString(placeholderClassCbx.isSelected())));
Stage stage = (Stage) cmtBtn.getScene().getWindow();
stage.close();
}
Expand Down
2 changes: 1 addition & 1 deletion src/controller/OptionsMenuController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Controller for view.optionsmenu.fxml.
*/
public class OptionsMenuController extends AbstractDataSharingController<Boolean> {
public class OptionsMenuController extends DataSharingController<Boolean> {
@FXML Button cancelBtn, commitBtn;
@FXML CheckBox collectionsCbx, blankCbx, ontologyCbx;

Expand Down
21 changes: 15 additions & 6 deletions src/controller/PrefixMenuController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
Expand All @@ -31,11 +30,11 @@
/**
* Controller for view.prefixmenu.fxml.
*/
public class PrefixMenuController extends AbstractDataSharingController<Map<String, String>> implements Initializable {
public class PrefixMenuController extends DataSharingController<Map<String, String>> implements Initializable {

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

@FXML AnchorPane root;
@FXML BorderPane root;
@FXML ToolBar toolBar;
@FXML Button addPrefixBtn, remPrefixBtn, clrPrefixBtn, savPrefixBtn, lodPrefixBtn, cmtPrefixBtn, canPrefixBtn;
@FXML ListView<String> prefixList;
Expand Down Expand Up @@ -63,6 +62,16 @@ public class PrefixMenuController extends AbstractDataSharingController<Map<Stri
});
}

@FXML void keyPressedAction(KeyEvent keyEvent) {
KeyCode keyCode = keyEvent.getCode();

if (keyCode == KeyCode.ENTER) commitPrefixAction();
else if (keyCode == KeyCode.S) savePrefixAction();
else if (keyCode == KeyCode.L) loadPrefixAction();
else if (keyCode == KeyCode.A) addPrefixAction();
else if (keyCode == KeyCode.C) cancelPrefixAction();
}

/**
* On clicking the 'Add Prefix' button, adds prefixes to the arraylist of existing prefixes unless malformed.
*/
Expand Down
Loading

0 comments on commit a4f6506

Please sign in to comment.