Skip to content

Commit

Permalink
Dev: Properties with text overrun now handle their position gracefully.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeGat committed Feb 9, 2019
2 parents 0e73bdf + 6a8ac39 commit 93ba2f8
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 34 deletions.
24 changes: 15 additions & 9 deletions src/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,15 @@ private void deleteGraphElement(MouseEvent mouseEvent) {
* Defines the Object, or range, of the property, and creates the association between the Subject and Object.
* @param mouseEvent the second click on the canvas when 'Property' is selected.
*/
private void addObjectOfProperty(MouseEvent mouseEvent, Vertex obj) {
obj.setSnapTo(subject.getX(), subject.getY(), mouseEvent.getX(), mouseEvent.getY());
private void addObjectOfProperty(MouseEvent mouseEvent, Vertex object) {
object.setSnapTo(subject.getX(), subject.getY(), mouseEvent.getX(), mouseEvent.getY());

arrow.setEndX(obj.getX());
arrow.setEndY(obj.getY());
arrow.setEndX(object.getX());
arrow.setEndY(object.getY());

StackPane compiledProperty = new StackPane();
compiledProperty.setLayoutX(subject.getX() < obj.getX() ? subject.getX() : obj.getX());
compiledProperty.setLayoutY(subject.getY() < obj.getY() ? subject.getY() : obj.getY());
compiledProperty.setLayoutX(subject.getX() < object.getX() ? subject.getX() : object.getX());
compiledProperty.setLayoutY(subject.getY() < object.getY() ? subject.getY() : object.getY());

ArrayList<String> propertyInfo = showNameElementDialog();
if (propertyInfo == null || propertyInfo.size() == 0){
Expand All @@ -451,14 +451,21 @@ private void addObjectOfProperty(MouseEvent mouseEvent, Vertex obj) {
Insets.EMPTY
)));

double textWidth = (new Text(propertyInfo.get(0))).getBoundsInLocal().getWidth();
if (textWidth > arrow.getWidth()) {
double overrunOneSide = (textWidth - arrow.getWidth()) / 2;
compiledProperty.setLayoutX(compiledProperty.getLayoutX() - overrunOneSide);
}

compiledProperty.getChildren().addAll(arrow, propertyName);
drawPane.getChildren().add(compiledProperty);
compiledProperty.toBack();

Edge edge = new Edge(compiledProperty, propertyName, subject, obj);
Edge edge = new Edge(compiledProperty, propertyName, subject, object);

properties.add(edge);
subject.addOutgoingEdge(edge);
obj.addIncomingEdge(edge);
object.addIncomingEdge(edge);

statusLbl.setText("Property " + propertyName.getText() + " created. ");
subject = null;
Expand Down Expand Up @@ -521,7 +528,6 @@ private void addElementSubaction(MouseEvent mouseEvent) {
} 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);
elementType.setFill(Color.web("f4f4f4"));
Expand Down
11 changes: 5 additions & 6 deletions src/model/conceptual/Edge.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@ public class Edge {
private final Vertex object;
private boolean isIri;

private double layoutX;

/**
* A simple constructor for the conceptual property.
* @param name the name of the property.
* @param subject the tail of the property arrow.
* @param object the head of the property arrow.
*/
// TODO: 8/02/2019 if iri add <> keeps adding when save/loading. Need better fix.
public Edge(StackPane container, Label name, Vertex subject, Vertex object){
this.container = container;
this.name = name.getText();
this.subject = subject;
this.object = object;

if (this.name.matches("<?https?:.*>?|<?mailto:.*>?")) {
isIri = true;
this.name = this.name.matches("<https?:.*>|<mailto:.*>") ? this.name : "<" + this.name + ">";
} else isIri = false;
this.layoutX = container.getBoundsInParent().getMinX();
this.isIri = this.name.matches("https?:.*|mailto:.*");
}

public String getName() { return name; }
Expand Down Expand Up @@ -60,5 +58,6 @@ public Bounds getBounds() {
}

public boolean isIri(){ return isIri; }
public double getLayoutX() { return layoutX; }
}

4 changes: 2 additions & 2 deletions src/model/conceptual/Vertex.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public Vertex(EventTarget element) throws OutsideElementException, UndefinedElem
((Text) container.getChildren().get(1)).setText("");
isBlankNode = true;
isIri = false;
} else if (this.name.matches("http:.*|mailto:.*")){
this.name = "<" + this.name + ">";
} else if (this.name.matches("https?:.*|mailto:.*")){
// this.name = "<" + this.name + ">";
isBlankNode = false;
isIri = true;
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/model/conversion/gat/FromGatConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ private void bindClass(String cls) {
* @param prop the .gat String serialization of a Property.
*/
private void bindProperty(String prop) throws PropertyElemMissingException {
String[] propElements = prop.split("=");
String[] propInfo = propElements[0].substring(1).split("\\|");
String propName = propElements[1];
double sx = Double.valueOf(propInfo[0]);
double sy = Double.valueOf(propInfo[1]);
double ex = Double.valueOf(propInfo[2]);
double ey = Double.valueOf(propInfo[3]);
String[] propElements = prop.split("\\\\\\|");
double sx = Double.valueOf(propElements[0].substring(1));
double sy = Double.valueOf(propElements[1]);
double ex = Double.valueOf(propElements[2]);
double ey = Double.valueOf(propElements[3]);
double lx = Double.valueOf(propElements[4]);
String propName = propElements[5];

StackPane compiledProp = new StackPane();
compiledProp.setLayoutX(sx < ex ? sx : ex);
compiledProp.setLayoutX(lx);
compiledProp.setLayoutY(sy < ey ? sy : ey);

Arrow arrow = new Arrow();
Expand Down
7 changes: 4 additions & 3 deletions src/model/conversion/gat/ToGatConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String traverseCanvas() {

/**
* Converts properties to the .gat structure.
* Of form: [Asx|sy|ex|ey=name]
* Of form: [Asx\|sy\|ex\|ey\|layX\|name]
* @return the String .gat representation of the properties.
*/
private String traverseProperties() {
Expand All @@ -52,8 +52,9 @@ private String traverseProperties() {
for (Edge e : properties) {
result.append("[");
Arrow a = (Arrow) e.getContainer().getChildren().get(0);
String shapeInfo = "A" + a.getStartX() + "|" + a.getStartY() + "|" + a.getEndX() + "|" + a.getEndY();
String shapeName = "=" + e.getName();
String shapeInfo = "A" + a.getStartX() + "\\|" + a.getStartY() + "\\|" + a.getEndX() + "\\|" +
a.getEndY() + "\\|" + e.getLayoutX();
String shapeName = "\\|" + e.getName();
result.append(shapeInfo).append(shapeName);
result.append("]");
}
Expand Down
9 changes: 5 additions & 4 deletions src/model/conversion/ttl/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private static String convertPredicateObjectList(Vertex subject) {

for (Map.Entry<String, ArrayList<Vertex>> e : commonObjects.entrySet()){
String predicateObjectListStr = "";
String propName = e.getKey();
String propName = e.getKey().matches("https?:.*") ? "<" + e.getKey() + ">" : e.getKey();
String objectListStr;
ArrayList<Vertex> objectList = e.getValue();

Expand Down Expand Up @@ -319,8 +319,9 @@ private static String convertObjectList(ArrayList<Vertex> objectList) {
*/
private static String convertObject(Vertex object) {
String objectStr = object.getName();
boolean asBlankNodeList = config.get(1);

if (config.get(1) && object.isBlank()) {
if (asBlankNodeList && object.isBlank()) {
String predicateObjectList = convertPredicateObjectList(object);

if (predicateObjectList.contains(";") || predicateObjectList.contains(",")) {
Expand All @@ -333,7 +334,7 @@ private static String convertObject(Vertex object) {
String dataType = object.getDataType();
objectStr = "\"" + objectStr + "\"" +
(dataType != null && dataType.length() != 0 ? "^^" + object.getDataType() : "");
} else objectStr = objectStr.matches("http:.*|mailto:.*") ? "<"+objectStr+">" : objectStr;
} else objectStr = objectStr.matches("https?:.*|mailto:.*") ? "<"+objectStr+">" : objectStr;

return objectStr;
}
Expand All @@ -346,7 +347,7 @@ private static String convertObject(Vertex object) {
*/
private static String convertSubject(Vertex klass){
String subname = klass.getName();
subname = subname.matches("http:.*|mailto:.*") ? "<" + subname + ">" : subname;
subname = subname.matches("https?:.*|mailto:.*") ? "<" + subname + ">" : subname;
String typeDef;

if (isOntology)
Expand Down
6 changes: 4 additions & 2 deletions src/model/dataintegration/DataIntegrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ private String getMetaTriples(String name, Vertex klass) throws PrefixMissingExc
* @throws PrefixMissingException if a given prefix does not have an expanded form.
*/
private String generateLongformURI(Vertex klass, CSVRecord record) throws PrefixMissingException {
if (klass.getElementType() == GLOBAL_LITERAL || klass.isIri())
if (klass.getElementType() == GLOBAL_LITERAL)
return klass.getName();
else if (klass.isIri())
return "<" + klass.getName() + ">";
else if (klass.isBlank())
return klass.getName() + blankNodePermutation;
else if (klass.getElementType() == CLASS) {
Expand Down Expand Up @@ -204,7 +206,7 @@ private String getInstanceLevelData(Vertex klass, CSVRecord record) {
*/
private String generateLongformURI(Edge edge) throws PrefixMissingException {
if (edge.isIri()){
return edge.getName();
return "<" + edge.getName() + ">";
} else {
String name = edge.getName();
String[] nameParts = name.split(":");
Expand Down
1 change: 1 addition & 0 deletions src/model/graph/Arrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private Arrow(Line line, Line arrow1, Line arrow2) {
public double getStartY() { return line.getStartY(); }
public double getEndX() { return line.getEndX(); }
public double getEndY() { return line.getEndY(); }
public double getWidth() { return Math.abs(line.getEndX() - line.getStartX()); }

private DoubleProperty startXProperty() { return line.startXProperty(); }
private DoubleProperty startYProperty() { return line.startYProperty(); }
Expand Down

0 comments on commit 93ba2f8

Please sign in to comment.