Skip to content

Commit

Permalink
prmr#422 Update classes' to reflect new StringViewer constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
yannsartori committed Mar 12, 2021
1 parent 7a8c3d6 commit 193b5ca
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 75 deletions.
6 changes: 2 additions & 4 deletions src/ca/mcgill/cs/jetuml/viewers/edges/AbstractEdgeViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*******************************************************************************/
package ca.mcgill.cs.jetuml.viewers.edges;

import static java.util.EnumSet.noneOf;

import ca.mcgill.cs.jetuml.diagram.Edge;
import ca.mcgill.cs.jetuml.geom.Dimension;
import ca.mcgill.cs.jetuml.geom.Direction;
Expand All @@ -30,6 +28,7 @@
import ca.mcgill.cs.jetuml.geom.Rectangle;
import ca.mcgill.cs.jetuml.viewers.nodes.NodeViewerRegistry;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.ToolGraphics;
import javafx.geometry.Bounds;
import javafx.scene.canvas.GraphicsContext;
Expand All @@ -46,8 +45,7 @@ public abstract class AbstractEdgeViewer implements EdgeViewer
protected static final int MAX_DISTANCE = 3;
protected static final int BUTTON_SIZE = 25;
protected static final int OFFSET = 3;
private static final StringViewer SIZE_TESTER = StringViewer.get(StringViewer.VerticalAlign.TOP, StringViewer.HorizontalAlign.LEFT,
noneOf(StringViewer.TextDecorations.class));
private static final StringViewer SIZE_TESTER = StringViewer.get(Alignment.TOP_LEFT);

private static final int DEGREES_180 = 180;

Expand Down
10 changes: 4 additions & 6 deletions src/ca/mcgill/cs/jetuml/viewers/edges/CallEdgeViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*******************************************************************************/
package ca.mcgill.cs.jetuml.viewers.edges;

import static java.util.EnumSet.of;

import java.util.ArrayList;

import ca.mcgill.cs.jetuml.diagram.Edge;
Expand All @@ -40,6 +38,8 @@
import ca.mcgill.cs.jetuml.views.ArrowHeadView;
import ca.mcgill.cs.jetuml.views.LineStyle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.StringViewer.TextDecoration;
import ca.mcgill.cs.jetuml.views.ToolGraphics;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
Expand All @@ -55,10 +55,8 @@
*/
public final class CallEdgeViewer extends AbstractEdgeViewer
{
private static final StringViewer CENTERED_STRING_VIEWER = StringViewer.get(StringViewer.VerticalAlign.CENTER,
StringViewer.HorizontalAlign.CENTER, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer LEFT_JUSTIFIED_STRING_VIEWER = StringViewer.get(StringViewer.VerticalAlign.TOP,
StringViewer.HorizontalAlign.LEFT, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer CENTERED_STRING_VIEWER = StringViewer.get(Alignment.CENTER_CENTER, TextDecoration.PADDED);
private static final StringViewer LEFT_JUSTIFIED_STRING_VIEWER = StringViewer.get(Alignment.TOP_LEFT, TextDecoration.PADDED);

private static final int SHIFT = -10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*******************************************************************************/
package ca.mcgill.cs.jetuml.viewers.edges;

import static java.util.EnumSet.of;

import java.util.function.Function;

import ca.mcgill.cs.jetuml.diagram.Edge;
Expand All @@ -31,15 +29,16 @@
import ca.mcgill.cs.jetuml.views.ArrowHead;
import ca.mcgill.cs.jetuml.views.LineStyle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.StringViewer.TextDecoration;
import javafx.scene.canvas.GraphicsContext;

/**
* Can draw a straight edge with a label than can be obtained dynamically.
*/
public class LabeledStraightEdgeViewer extends StraightEdgeViewer
{
private static final StringViewer STRING_VIEWER = StringViewer.get(StringViewer.VerticalAlign.CENTER,
StringViewer.HorizontalAlign.CENTER, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer STRING_VIEWER = StringViewer.get(Alignment.CENTER_CENTER, TextDecoration.PADDED);
private static final int SHIFT = -10;

private final Function<Edge, String> aLabelExtractor;
Expand Down
18 changes: 7 additions & 11 deletions src/ca/mcgill/cs/jetuml/viewers/edges/SegmentedEdgeViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*******************************************************************************/
package ca.mcgill.cs.jetuml.viewers.edges;

import static java.util.EnumSet.of;

import java.util.function.Function;

import ca.mcgill.cs.jetuml.diagram.Edge;
Expand All @@ -33,6 +31,7 @@
import ca.mcgill.cs.jetuml.views.ArrowHead;
import ca.mcgill.cs.jetuml.views.LineStyle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.ToolGraphics;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
Expand All @@ -48,12 +47,9 @@
*/
public class SegmentedEdgeViewer extends AbstractEdgeViewer
{
private static final StringViewer CENTERED_TOP_STRING_VIEWER = StringViewer.get(StringViewer.VerticalAlign.TOP,
StringViewer.HorizontalAlign.CENTER, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer CENTERED_BOTTOM_STRING_VIEWER = StringViewer.get(StringViewer.VerticalAlign.BOTTOM,
StringViewer.HorizontalAlign.CENTER, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer LEFT_JUSTIFIED_STRING_VIEWER = StringViewer.get(StringViewer.VerticalAlign.TOP,
StringViewer.HorizontalAlign.LEFT, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer TOP_CENTERED_STRING_VIEWER = StringViewer.get(Alignment.TOP_CENTER);
private static final StringViewer BOTTOM_CENTERED_STRING_VIEWER = StringViewer.get(Alignment.BOTTOM_CENTER);
private static final StringViewer LEFT_JUSTIFIED_STRING_VIEWER = StringViewer.get(Alignment.TOP_LEFT);

private Function<Edge, LineStyle> aLineStyleExtractor;
private Function<Edge, ArrowHead> aArrowStartExtractor;
Expand Down Expand Up @@ -103,13 +99,13 @@ private static void drawString(GraphicsContext pGraphics, Point2D pEndPoint1, Po
Rectangle bounds = getStringBounds(pEndPoint1, pEndPoint2, pArrowHead, pString, pCenter);
if(pCenter)
{
if ( pEndPoint2.getY() > pEndPoint1.getY() )
if ( pEndPoint2.getY() >= pEndPoint1.getY() )
{
CENTERED_TOP_STRING_VIEWER.draw(pString, pGraphics, bounds);
TOP_CENTERED_STRING_VIEWER.draw(pString, pGraphics, bounds);
}
else
{
CENTERED_BOTTOM_STRING_VIEWER.draw(pString, pGraphics, bounds);
BOTTOM_CENTERED_STRING_VIEWER.draw(pString, pGraphics, bounds);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import static ca.mcgill.cs.jetuml.views.StringViewer.FONT;

import static java.util.EnumSet.noneOf;

import ca.mcgill.cs.jetuml.diagram.Edge;
import ca.mcgill.cs.jetuml.diagram.edges.StateTransitionEdge;
import ca.mcgill.cs.jetuml.geom.Conversions;
Expand All @@ -37,6 +35,7 @@
import ca.mcgill.cs.jetuml.views.LineStyle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.ToolGraphics;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.canvas.Canvas;
Expand Down Expand Up @@ -66,8 +65,7 @@ public final class StateTransitionEdgeViewer extends AbstractEdgeViewer
private static final double HEIGHT_RATIO = 3.5;
private static final int MAX_LENGTH_FOR_NORMAL_FONT = 15;
private static final int MIN_FONT_SIZE = 9;
private static final StringViewer STRING_VIEWER = StringViewer.get(StringViewer.VerticalAlign.BOTTOM, StringViewer.HorizontalAlign.CENTER,
noneOf(StringViewer.TextDecorations.class));
private static final StringViewer STRING_VIEWER = StringViewer.get(Alignment.CENTER_CENTER);

// The amount of vertical difference in connection points to tolerate
// before centering the edge label on one side instead of in the center.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
*******************************************************************************/
package ca.mcgill.cs.jetuml.viewers.edges;

import static java.util.EnumSet.of;

import ca.mcgill.cs.jetuml.diagram.Edge;
import ca.mcgill.cs.jetuml.diagram.edges.UseCaseDependencyEdge;
import ca.mcgill.cs.jetuml.geom.Rectangle;
import ca.mcgill.cs.jetuml.views.ArrowHead;
import ca.mcgill.cs.jetuml.views.LineStyle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.StringViewer.TextDecoration;
import javafx.scene.canvas.Canvas;

/**
Expand All @@ -50,8 +50,8 @@ public Canvas createIcon(Edge pEdge)
Canvas canvas = super.createIcon(pEdge);
final float scale = 0.75f;
canvas.getGraphicsContext2D().scale(scale, scale);
StringViewer.get(StringViewer.VerticalAlign.CENTER, StringViewer.HorizontalAlign.CENTER, of(StringViewer.TextDecorations.PADDED))
.draw(getIconTag(pEdge), canvas.getGraphicsContext2D(), new Rectangle(1, BUTTON_SIZE, 1, 1));
StringViewer.get(Alignment.CENTER_CENTER, TextDecoration.PADDED).draw(getIconTag(pEdge),
canvas.getGraphicsContext2D(), new Rectangle(1, BUTTON_SIZE, 1, 1));
return canvas;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package ca.mcgill.cs.jetuml.viewers.nodes;

import static ca.mcgill.cs.jetuml.geom.GeomUtils.max;
import static java.util.EnumSet.of;

import ca.mcgill.cs.jetuml.diagram.Node;
import ca.mcgill.cs.jetuml.diagram.nodes.AbstractPackageNode;
Expand All @@ -30,6 +29,8 @@
import ca.mcgill.cs.jetuml.geom.Point;
import ca.mcgill.cs.jetuml.geom.Rectangle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.StringViewer.TextDecoration;
import ca.mcgill.cs.jetuml.views.ViewUtils;
import javafx.scene.canvas.GraphicsContext;

Expand All @@ -44,8 +45,7 @@ public abstract class AbstractPackageNodeViewer extends AbstractNodeViewer
protected static final int DEFAULT_BOTTOM_HEIGHT = 60;
protected static final int DEFAULT_TOP_WIDTH = 60;
protected static final int NAME_GAP = 3;
private static final StringViewer NAME_VIEWER = StringViewer.get(StringViewer.VerticalAlign.TOP,
StringViewer.HorizontalAlign.LEFT, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer NAME_VIEWER = StringViewer.get(Alignment.TOP_LEFT, TextDecoration.PADDED);

@Override
public void draw(Node pNode, GraphicsContext pGraphics)
Expand Down
7 changes: 3 additions & 4 deletions src/ca/mcgill/cs/jetuml/viewers/nodes/ActorNodeViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
*******************************************************************************/
package ca.mcgill.cs.jetuml.viewers.nodes;

import static java.util.EnumSet.of;

import ca.mcgill.cs.jetuml.diagram.Node;
import ca.mcgill.cs.jetuml.diagram.nodes.ActorNode;
import ca.mcgill.cs.jetuml.geom.Dimension;
import ca.mcgill.cs.jetuml.geom.Rectangle;
import ca.mcgill.cs.jetuml.views.LineStyle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.StringViewer.TextDecoration;
import ca.mcgill.cs.jetuml.views.ToolGraphics;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.shape.LineTo;
Expand All @@ -40,8 +40,7 @@
*/
public final class ActorNodeViewer extends AbstractNodeViewer
{
private static final StringViewer NAME_VIEWER = StringViewer.get(StringViewer.VerticalAlign.CENTER,
StringViewer.HorizontalAlign.CENTER, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer NAME_VIEWER = StringViewer.get(Alignment.CENTER_CENTER, TextDecoration.PADDED);

private static final int PADDING = 4;
private static final int HEAD_SIZE = 16;
Expand Down
13 changes: 5 additions & 8 deletions src/ca/mcgill/cs/jetuml/viewers/nodes/FieldNodeViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*******************************************************************************/
package ca.mcgill.cs.jetuml.viewers.nodes;

import static java.util.EnumSet.of;

import ca.mcgill.cs.jetuml.diagram.Node;
import ca.mcgill.cs.jetuml.diagram.nodes.FieldNode;
import ca.mcgill.cs.jetuml.diagram.nodes.ObjectNode;
Expand All @@ -30,6 +28,8 @@
import ca.mcgill.cs.jetuml.geom.Point;
import ca.mcgill.cs.jetuml.geom.Rectangle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.StringViewer.TextDecoration;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
Expand All @@ -44,12 +44,9 @@ public final class FieldNodeViewer extends AbstractNodeViewer
private static final int DEFAULT_WIDTH = 60;
private static final int DEFAULT_HEIGHT = 20;
private static final int XGAP = 5;
private static final StringViewer VALUE_VIEWER = StringViewer.get(StringViewer.VerticalAlign.TOP,
StringViewer.HorizontalAlign.LEFT, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer NAME_VIEWER = StringViewer.get(StringViewer.VerticalAlign.TOP,
StringViewer.HorizontalAlign.LEFT, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer EQUALS_VIEWER = StringViewer.get(StringViewer.VerticalAlign.TOP,
StringViewer.HorizontalAlign.LEFT, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer VALUE_VIEWER = StringViewer.get(Alignment.TOP_LEFT, TextDecoration.PADDED);
private static final StringViewer NAME_VIEWER = StringViewer.get(Alignment.TOP_LEFT, TextDecoration.PADDED);
private static final StringViewer EQUALS_VIEWER = StringViewer.get(Alignment.TOP_LEFT, TextDecoration.PADDED);
private static final int MID_OFFSET = EQUALS_VIEWER.getDimension(EQUALS).width() / 2;
private static final ObjectNodeViewer OBJECT_NODE_VIEWER = new ObjectNodeViewer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package ca.mcgill.cs.jetuml.viewers.nodes;

import static ca.mcgill.cs.jetuml.geom.GeomUtils.max;
import static java.util.EnumSet.of;

import java.util.List;
import java.util.Optional;
Expand All @@ -36,6 +35,8 @@
import ca.mcgill.cs.jetuml.geom.Rectangle;
import ca.mcgill.cs.jetuml.views.LineStyle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.StringViewer.TextDecoration;
import ca.mcgill.cs.jetuml.views.ViewUtils;
import javafx.scene.canvas.GraphicsContext;

Expand All @@ -50,8 +51,7 @@ public final class ImplicitParameterNodeViewer extends AbstractNodeViewer
private static final int TAIL_HEIGHT = 20; // Piece of the life line below the last call node
private static final int TOP_HEIGHT = 60;
private static final int Y_GAP_SMALL = 20;
private static final StringViewer NAME_VIEWER = StringViewer.get(StringViewer.VerticalAlign.CENTER,
StringViewer.HorizontalAlign.CENTER, of(StringViewer.TextDecorations.UNDERLINED, StringViewer.TextDecorations.PADDED));
private static final StringViewer NAME_VIEWER = StringViewer.get(Alignment.CENTER_CENTER, TextDecoration.PADDED, TextDecoration.UNDERLINED);
private static final CallNodeViewer CALL_NODE_VIEWER = new CallNodeViewer();

@Override
Expand Down
7 changes: 3 additions & 4 deletions src/ca/mcgill/cs/jetuml/viewers/nodes/NoteNodeViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
*******************************************************************************/
package ca.mcgill.cs.jetuml.viewers.nodes;

import static java.util.EnumSet.of;

import ca.mcgill.cs.jetuml.diagram.Node;
import ca.mcgill.cs.jetuml.diagram.nodes.NoteNode;
import ca.mcgill.cs.jetuml.geom.Dimension;
import ca.mcgill.cs.jetuml.geom.Rectangle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.StringViewer.TextDecoration;
import ca.mcgill.cs.jetuml.views.ToolGraphics;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
Expand All @@ -43,8 +43,7 @@ public final class NoteNodeViewer extends AbstractNodeViewer
private static final int DEFAULT_HEIGHT = 40;
private static final int FOLD_LENGTH = 8;
private static final Color NOTE_COLOR = Color.color(0.9f, 0.9f, 0.6f); // Pale yellow
private static final StringViewer NOTE_VIEWER = StringViewer.get(StringViewer.VerticalAlign.TOP,
StringViewer.HorizontalAlign.LEFT, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer NOTE_VIEWER = StringViewer.get(Alignment.TOP_LEFT, TextDecoration.PADDED);

@Override
public void draw(Node pNode, GraphicsContext pGraphics)
Expand Down
8 changes: 4 additions & 4 deletions src/ca/mcgill/cs/jetuml/viewers/nodes/ObjectNodeViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*******************************************************************************/
package ca.mcgill.cs.jetuml.viewers.nodes;

import static java.util.EnumSet.allOf;

import ca.mcgill.cs.jetuml.diagram.Node;
import ca.mcgill.cs.jetuml.diagram.nodes.FieldNode;
import ca.mcgill.cs.jetuml.diagram.nodes.ObjectNode;
Expand All @@ -30,6 +28,8 @@
import ca.mcgill.cs.jetuml.views.Grid;
import ca.mcgill.cs.jetuml.views.LineStyle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.StringViewer.TextDecoration;
import ca.mcgill.cs.jetuml.views.ViewUtils;
import javafx.scene.canvas.GraphicsContext;

Expand All @@ -43,8 +43,8 @@ public final class ObjectNodeViewer extends AbstractNodeViewer
private static final int TEXT_HORIZONTAL_MARGIN = 5;
private static final int XGAP = 5;
private static final int YGAP = 5;
private static final StringViewer NAME_VIEWER = StringViewer.get(StringViewer.VerticalAlign.CENTER,
StringViewer.HorizontalAlign.CENTER, allOf(StringViewer.TextDecorations.class));
private static final StringViewer NAME_VIEWER = StringViewer.get(Alignment.CENTER_CENTER,
TextDecoration.BOLD, TextDecoration.UNDERLINED, TextDecoration.PADDED);
private static final FieldNodeViewer FIELD_NODE_VIEWER = new FieldNodeViewer();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
package ca.mcgill.cs.jetuml.viewers.nodes;

import static ca.mcgill.cs.jetuml.geom.GeomUtils.max;
import static java.util.EnumSet.of;

import ca.mcgill.cs.jetuml.diagram.Node;
import ca.mcgill.cs.jetuml.diagram.nodes.AbstractPackageNode;
import ca.mcgill.cs.jetuml.diagram.nodes.PackageDescriptionNode;
import ca.mcgill.cs.jetuml.geom.Dimension;
import ca.mcgill.cs.jetuml.geom.Rectangle;
import ca.mcgill.cs.jetuml.views.StringViewer;
import ca.mcgill.cs.jetuml.views.StringViewer.Alignment;
import ca.mcgill.cs.jetuml.views.StringViewer.TextDecoration;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;

Expand All @@ -37,8 +38,7 @@
*/
public final class PackageDescriptionNodeViewer extends AbstractPackageNodeViewer
{
private static final StringViewer CONTENTS_VIEWER = StringViewer.get(StringViewer.VerticalAlign.CENTER,
StringViewer.HorizontalAlign.CENTER, of(StringViewer.TextDecorations.PADDED));
private static final StringViewer CONTENTS_VIEWER = StringViewer.get(Alignment.CENTER_CENTER, TextDecoration.PADDED);

@Override
public void draw(Node pNode, GraphicsContext pGraphics)
Expand Down
Loading

0 comments on commit 193b5ca

Please sign in to comment.