Skip to content

Commit

Permalink
Repolaced width/height vars with a Dimension obj.
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkryst committed Sep 28, 2017
1 parent 92198b6 commit 02e70f6
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/com/valkryst/VTerminal/component/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import lombok.Setter;
import lombok.ToString;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
Expand All @@ -28,10 +29,8 @@ public class Component {
/** The x/y-axis (column/row) coordinates of the top-left character. */
@Getter private final Point position;

/** The width, in characters. */
@Getter private int width;
/** The height, in characters. */
@Getter private int height;
/** The width/height, in characters. */
@Getter final Dimension dimensions;

/** Whether or not the component is currently the target of the user's input. */
@Getter protected boolean isFocused = false;
Expand Down Expand Up @@ -63,16 +62,15 @@ public class Component {
public Component(final @NonNull ComponentBuilder builder) {
this.id = builder.getId();
position = new Point(builder.getColumnIndex(), builder.getRowIndex());
this.width = builder.getWidth();
this.height = builder.getHeight();
dimensions = new Dimension(builder.getWidth(), builder.getHeight());

boundingBox.setLocation(position);
boundingBox.setSize(width, height);
boundingBox.setSize(dimensions.width, dimensions.height);

strings = new AsciiString[height];
strings = new AsciiString[dimensions.height];

for (int row = 0 ; row < height ; row++) {
strings[row] = new AsciiString(width);
for (int row = 0 ; row < dimensions.height ; row++) {
strings[row] = new AsciiString(dimensions.width);
}

this.radio = builder.getRadio();
Expand Down Expand Up @@ -328,6 +326,14 @@ public AsciiCharacter getCharacterAt(final Point position) {
throw new IllegalArgumentException("The position (" + position.x + " columnIndex, " + position.y + " rowIndex) is invalid.");
}

public int getWidth() {
return dimensions.width;
}

public int getHeight() {
return dimensions.height;
}

/**
* Sets a new position.
*
Expand Down Expand Up @@ -365,8 +371,8 @@ public void setWidth(final int width) {
throw new IllegalArgumentException("The width cannot be < columnIndex,");
}

this.width = width;
boundingBox.setSize(width, height);
dimensions.setSize(width, dimensions.height);
boundingBox.setSize(dimensions);
}

/**
Expand All @@ -387,7 +393,7 @@ public void setHeight(final int height) {
throw new IllegalArgumentException("The height cannot be < rowIndex,");
}

this.height = height;
boundingBox.setSize(width, height);
dimensions.setSize(dimensions.width, height);
boundingBox.setSize(dimensions);
}
}

0 comments on commit 02e70f6

Please sign in to comment.