Skip to content

Commit 93ba2f8

Browse files
committed
Dev: Properties with text overrun now handle their position gracefully.
2 parents 0e73bdf + 6a8ac39 commit 93ba2f8

8 files changed

Lines changed: 44 additions & 34 deletions

File tree

src/controller/Controller.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,15 +424,15 @@ private void deleteGraphElement(MouseEvent mouseEvent) {
424424
* Defines the Object, or range, of the property, and creates the association between the Subject and Object.
425425
* @param mouseEvent the second click on the canvas when 'Property' is selected.
426426
*/
427-
private void addObjectOfProperty(MouseEvent mouseEvent, Vertex obj) {
428-
obj.setSnapTo(subject.getX(), subject.getY(), mouseEvent.getX(), mouseEvent.getY());
427+
private void addObjectOfProperty(MouseEvent mouseEvent, Vertex object) {
428+
object.setSnapTo(subject.getX(), subject.getY(), mouseEvent.getX(), mouseEvent.getY());
429429

430-
arrow.setEndX(obj.getX());
431-
arrow.setEndY(obj.getY());
430+
arrow.setEndX(object.getX());
431+
arrow.setEndY(object.getY());
432432

433433
StackPane compiledProperty = new StackPane();
434-
compiledProperty.setLayoutX(subject.getX() < obj.getX() ? subject.getX() : obj.getX());
435-
compiledProperty.setLayoutY(subject.getY() < obj.getY() ? subject.getY() : obj.getY());
434+
compiledProperty.setLayoutX(subject.getX() < object.getX() ? subject.getX() : object.getX());
435+
compiledProperty.setLayoutY(subject.getY() < object.getY() ? subject.getY() : object.getY());
436436

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

454+
double textWidth = (new Text(propertyInfo.get(0))).getBoundsInLocal().getWidth();
455+
if (textWidth > arrow.getWidth()) {
456+
double overrunOneSide = (textWidth - arrow.getWidth()) / 2;
457+
compiledProperty.setLayoutX(compiledProperty.getLayoutX() - overrunOneSide);
458+
}
459+
454460
compiledProperty.getChildren().addAll(arrow, propertyName);
455461
drawPane.getChildren().add(compiledProperty);
456462
compiledProperty.toBack();
457463

458-
Edge edge = new Edge(compiledProperty, propertyName, subject, obj);
464+
Edge edge = new Edge(compiledProperty, propertyName, subject, object);
465+
459466
properties.add(edge);
460467
subject.addOutgoingEdge(edge);
461-
obj.addIncomingEdge(edge);
468+
object.addIncomingEdge(edge);
462469

463470
statusLbl.setText("Property " + propertyName.getText() + " created. ");
464471
subject = null;
@@ -521,7 +528,6 @@ private void addElementSubaction(MouseEvent mouseEvent) {
521528
} else isClass = !elementName.getText().matches(globalLiteralRegex + "|" + instanceLiteralRegex);
522529

523530
double textWidth = elementName.getBoundsInLocal().getWidth();
524-
525531
if (isClass){
526532
Ellipse elementType = new Ellipse(x, y, textWidth / 2 > 62.5 ? textWidth / 2 + 10 : 62.5, 37.5);
527533
elementType.setFill(Color.web("f4f4f4"));

src/model/conceptual/Edge.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,21 @@ public class Edge {
1515
private final Vertex object;
1616
private boolean isIri;
1717

18+
private double layoutX;
19+
1820
/**
1921
* A simple constructor for the conceptual property.
2022
* @param name the name of the property.
2123
* @param subject the tail of the property arrow.
2224
* @param object the head of the property arrow.
2325
*/
24-
// TODO: 8/02/2019 if iri add <> keeps adding when save/loading. Need better fix.
2526
public Edge(StackPane container, Label name, Vertex subject, Vertex object){
2627
this.container = container;
2728
this.name = name.getText();
2829
this.subject = subject;
2930
this.object = object;
30-
31-
if (this.name.matches("<?https?:.*>?|<?mailto:.*>?")) {
32-
isIri = true;
33-
this.name = this.name.matches("<https?:.*>|<mailto:.*>") ? this.name : "<" + this.name + ">";
34-
} else isIri = false;
31+
this.layoutX = container.getBoundsInParent().getMinX();
32+
this.isIri = this.name.matches("https?:.*|mailto:.*");
3533
}
3634

3735
public String getName() { return name; }
@@ -60,5 +58,6 @@ public Bounds getBounds() {
6058
}
6159

6260
public boolean isIri(){ return isIri; }
61+
public double getLayoutX() { return layoutX; }
6362
}
6463

src/model/conceptual/Vertex.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public Vertex(EventTarget element) throws OutsideElementException, UndefinedElem
8181
((Text) container.getChildren().get(1)).setText("");
8282
isBlankNode = true;
8383
isIri = false;
84-
} else if (this.name.matches("http:.*|mailto:.*")){
85-
this.name = "<" + this.name + ">";
84+
} else if (this.name.matches("https?:.*|mailto:.*")){
85+
// this.name = "<" + this.name + ">";
8686
isBlankNode = false;
8787
isIri = true;
8888
} else {

src/model/conversion/gat/FromGatConverter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ private void bindClass(String cls) {
156156
* @param prop the .gat String serialization of a Property.
157157
*/
158158
private void bindProperty(String prop) throws PropertyElemMissingException {
159-
String[] propElements = prop.split("=");
160-
String[] propInfo = propElements[0].substring(1).split("\\|");
161-
String propName = propElements[1];
162-
double sx = Double.valueOf(propInfo[0]);
163-
double sy = Double.valueOf(propInfo[1]);
164-
double ex = Double.valueOf(propInfo[2]);
165-
double ey = Double.valueOf(propInfo[3]);
159+
String[] propElements = prop.split("\\\\\\|");
160+
double sx = Double.valueOf(propElements[0].substring(1));
161+
double sy = Double.valueOf(propElements[1]);
162+
double ex = Double.valueOf(propElements[2]);
163+
double ey = Double.valueOf(propElements[3]);
164+
double lx = Double.valueOf(propElements[4]);
165+
String propName = propElements[5];
166166

167167
StackPane compiledProp = new StackPane();
168-
compiledProp.setLayoutX(sx < ex ? sx : ex);
168+
compiledProp.setLayoutX(lx);
169169
compiledProp.setLayoutY(sy < ey ? sy : ey);
170170

171171
Arrow arrow = new Arrow();

src/model/conversion/gat/ToGatConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public String traverseCanvas() {
4343

4444
/**
4545
* Converts properties to the .gat structure.
46-
* Of form: [Asx|sy|ex|ey=name]
46+
* Of form: [Asx\|sy\|ex\|ey\|layX\|name]
4747
* @return the String .gat representation of the properties.
4848
*/
4949
private String traverseProperties() {
@@ -52,8 +52,9 @@ private String traverseProperties() {
5252
for (Edge e : properties) {
5353
result.append("[");
5454
Arrow a = (Arrow) e.getContainer().getChildren().get(0);
55-
String shapeInfo = "A" + a.getStartX() + "|" + a.getStartY() + "|" + a.getEndX() + "|" + a.getEndY();
56-
String shapeName = "=" + e.getName();
55+
String shapeInfo = "A" + a.getStartX() + "\\|" + a.getStartY() + "\\|" + a.getEndX() + "\\|" +
56+
a.getEndY() + "\\|" + e.getLayoutX();
57+
String shapeName = "\\|" + e.getName();
5758
result.append(shapeInfo).append(shapeName);
5859
result.append("]");
5960
}

src/model/conversion/ttl/Converter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private static String convertPredicateObjectList(Vertex subject) {
244244

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

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

323-
if (config.get(1) && object.isBlank()) {
324+
if (asBlankNodeList && object.isBlank()) {
324325
String predicateObjectList = convertPredicateObjectList(object);
325326

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

338339
return objectStr;
339340
}
@@ -346,7 +347,7 @@ private static String convertObject(Vertex object) {
346347
*/
347348
private static String convertSubject(Vertex klass){
348349
String subname = klass.getName();
349-
subname = subname.matches("http:.*|mailto:.*") ? "<" + subname + ">" : subname;
350+
subname = subname.matches("https?:.*|mailto:.*") ? "<" + subname + ">" : subname;
350351
String typeDef;
351352

352353
if (isOntology)

src/model/dataintegration/DataIntegrator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ private String getMetaTriples(String name, Vertex klass) throws PrefixMissingExc
129129
* @throws PrefixMissingException if a given prefix does not have an expanded form.
130130
*/
131131
private String generateLongformURI(Vertex klass, CSVRecord record) throws PrefixMissingException {
132-
if (klass.getElementType() == GLOBAL_LITERAL || klass.isIri())
132+
if (klass.getElementType() == GLOBAL_LITERAL)
133133
return klass.getName();
134+
else if (klass.isIri())
135+
return "<" + klass.getName() + ">";
134136
else if (klass.isBlank())
135137
return klass.getName() + blankNodePermutation;
136138
else if (klass.getElementType() == CLASS) {
@@ -204,7 +206,7 @@ private String getInstanceLevelData(Vertex klass, CSVRecord record) {
204206
*/
205207
private String generateLongformURI(Edge edge) throws PrefixMissingException {
206208
if (edge.isIri()){
207-
return edge.getName();
209+
return "<" + edge.getName() + ">";
208210
} else {
209211
String name = edge.getName();
210212
String[] nameParts = name.split(":");

src/model/graph/Arrow.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ private Arrow(Line line, Line arrow1, Line arrow2) {
7979
public double getStartY() { return line.getStartY(); }
8080
public double getEndX() { return line.getEndX(); }
8181
public double getEndY() { return line.getEndY(); }
82+
public double getWidth() { return Math.abs(line.getEndX() - line.getStartX()); }
8283

8384
private DoubleProperty startXProperty() { return line.startXProperty(); }
8485
private DoubleProperty startYProperty() { return line.startYProperty(); }

0 commit comments

Comments
 (0)