Add needed bounds variable and utilize setter annonations
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Jordan Atwood <jordan.atwood423@gmail.com>
|
* Copyright (c) 2018, Jordan Atwood <jordan.atwood423@gmail.com>
|
||||||
|
* Copyright (c) 2019, TheStonedTurtle <https://github.com/TheStonedTurtle>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -29,9 +30,14 @@ import java.awt.Dimension;
|
|||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
public class TableComponent implements LayoutableRenderableEntity
|
public class TableComponent implements LayoutableRenderableEntity
|
||||||
{
|
{
|
||||||
public enum TableAlignment
|
public enum TableAlignment
|
||||||
@@ -41,16 +47,29 @@ public class TableComponent implements LayoutableRenderableEntity
|
|||||||
RIGHT
|
RIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Rectangle bounds = new Rectangle();
|
||||||
|
|
||||||
|
@Setter(AccessLevel.NONE)
|
||||||
private ArrayList<String[]> cells = new ArrayList<>();
|
private ArrayList<String[]> cells = new ArrayList<>();
|
||||||
private TableAlignment[] columnAlignments;
|
@Nonnull
|
||||||
private Color[] columnColors;
|
private TableAlignment[] columnAlignments = new TableAlignment[0];
|
||||||
|
@Nonnull
|
||||||
|
private Color[] columnColors = new Color[0];
|
||||||
|
@Setter(AccessLevel.NONE)
|
||||||
private int numCols;
|
private int numCols;
|
||||||
|
@Setter(AccessLevel.NONE)
|
||||||
private int numRows;
|
private int numRows;
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
private TableAlignment defaultAlignment = TableAlignment.LEFT;
|
private TableAlignment defaultAlignment = TableAlignment.LEFT;
|
||||||
|
@Nonnull
|
||||||
private Color defaultColor = Color.WHITE;
|
private Color defaultColor = Color.WHITE;
|
||||||
|
@Nonnull
|
||||||
private Dimension gutter = new Dimension(3, 0);
|
private Dimension gutter = new Dimension(3, 0);
|
||||||
|
@Nonnull
|
||||||
private Point preferredLocation = new Point();
|
private Point preferredLocation = new Point();
|
||||||
|
@Nonnull
|
||||||
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,44 +107,10 @@ public class TableComponent implements LayoutableRenderableEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
graphics.translate(-preferredLocation.x, -preferredLocation.y);
|
graphics.translate(-preferredLocation.x, -preferredLocation.y);
|
||||||
return new Dimension(preferredSize.width, height);
|
final Dimension dimension = new Dimension(preferredSize.width, height);
|
||||||
}
|
bounds.setLocation(preferredLocation);
|
||||||
|
bounds.setSize(dimension);
|
||||||
public void setDefaultColor(@Nonnull final Color color)
|
return dimension;
|
||||||
{
|
|
||||||
this.defaultColor = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDefaultAlignment(@Nonnull final TableAlignment alignment)
|
|
||||||
{
|
|
||||||
this.defaultAlignment = alignment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGutter(@Nonnull final Dimension gutter)
|
|
||||||
{
|
|
||||||
this.gutter = gutter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPreferredLocation(@Nonnull final Point location)
|
|
||||||
{
|
|
||||||
this.preferredLocation = location;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPreferredSize(@Nonnull final Dimension size)
|
|
||||||
{
|
|
||||||
this.preferredSize = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColumnColors(@Nonnull Color... colors)
|
|
||||||
{
|
|
||||||
columnColors = colors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColumnAlignments(@Nonnull TableAlignment... alignments)
|
|
||||||
{
|
|
||||||
columnAlignments = alignments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColumnColor(final int col, final Color color)
|
public void setColumnColor(final int col, final Color color)
|
||||||
@@ -157,8 +142,7 @@ public class TableComponent implements LayoutableRenderableEntity
|
|||||||
|
|
||||||
private Color getColumnColor(final int column)
|
private Color getColumnColor(final int column)
|
||||||
{
|
{
|
||||||
if (columnColors == null
|
if (columnColors.length <= column
|
||||||
|| columnColors.length <= column
|
|
||||||
|| columnColors[column] == null)
|
|| columnColors[column] == null)
|
||||||
{
|
{
|
||||||
return defaultColor;
|
return defaultColor;
|
||||||
@@ -168,8 +152,7 @@ public class TableComponent implements LayoutableRenderableEntity
|
|||||||
|
|
||||||
private TableAlignment getColumnAlignment(final int column)
|
private TableAlignment getColumnAlignment(final int column)
|
||||||
{
|
{
|
||||||
if (columnAlignments == null
|
if (columnAlignments.length <= column
|
||||||
|| columnAlignments.length <= column
|
|
||||||
|| columnAlignments[column] == null)
|
|| columnAlignments[column] == null)
|
||||||
{
|
{
|
||||||
return defaultAlignment;
|
return defaultAlignment;
|
||||||
|
|||||||
Reference in New Issue
Block a user