aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/sl/draw/DrawTableShape.java
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-10-29 01:05:27 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-10-29 01:05:27 +0000
commiteb1e1a28e8fe4815851b283789a2552bbac9afcb (patch)
tree40273b56cb9179d7341c57f19eac18a13995e02a /src/java/org/apache/poi/sl/draw/DrawTableShape.java
parent8f0093e4648f0e9598d26847984eee060535f951 (diff)
downloadpoi-eb1e1a28e8fe4815851b283789a2552bbac9afcb.tar.gz
poi-eb1e1a28e8fe4815851b283789a2552bbac9afcb.zip
Common sl unification - copy first paragraph / textrun properties on XSLFTextShape.setText()
Common sl unification - converted ApacheconEU08 example to common sl - added missing functionality Common sl unification - return null instead of default values for missing borders X/HSLFTable Common sl unification - use points in HSLFTable.setColumnWidth() Fix appending text to empty HSLFTextParagraph git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711171 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/sl/draw/DrawTableShape.java')
-rw-r--r--src/java/org/apache/poi/sl/draw/DrawTableShape.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/sl/draw/DrawTableShape.java b/src/java/org/apache/poi/sl/draw/DrawTableShape.java
index b252ddfda9..ec44d17d6b 100644
--- a/src/java/org/apache/poi/sl/draw/DrawTableShape.java
+++ b/src/java/org/apache/poi/sl/draw/DrawTableShape.java
@@ -17,9 +17,15 @@
package org.apache.poi.sl.draw;
+import java.awt.Color;
import java.awt.Graphics2D;
import org.apache.poi.sl.usermodel.GroupShape;
+import org.apache.poi.sl.usermodel.StrokeStyle;
+import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound;
+import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
+import org.apache.poi.sl.usermodel.TableCell;
+import org.apache.poi.sl.usermodel.TableCell.BorderEdge;
import org.apache.poi.sl.usermodel.TableShape;
public class DrawTableShape extends DrawShape {
@@ -57,5 +63,111 @@ public class DrawTableShape extends DrawShape {
}
}
+ @Override
+ protected TableShape<?,?> getShape() {
+ return (TableShape<?,?>)shape;
+ }
+
+ /**
+ * Format the table and apply the specified Line to all cell boundaries,
+ * both outside and inside.
+ * An empty args parameter removes the affected border.
+ *
+ * @param args a varargs array possible containing {@link Double} (width),
+ * {@link StrokeStyle.LineCompound}, {@link Color}, {@link StrokeStyle.LineDash}
+ */
+ public void setAllBorders(Object... args) {
+ TableShape<?,?> table = getShape();
+ final int rows = table.getNumberOfRows();
+ final int cols = table.getNumberOfColumns();
+
+ BorderEdge edges[] = { BorderEdge.top, BorderEdge.left, null, null };
+ for (int row = 0; row < rows; row++) {
+ for (int col = 0; col < cols; col++) {
+ edges[2] = (col == cols - 1) ? BorderEdge.right : null;
+ edges[3] = (row == rows - 1) ? BorderEdge.bottom : null;
+ setEdges(table.getCell(row, col), edges, args);
+ }
+ }
+ }
+
+ /**
+ * Format the outside border using the specified Line object
+ * An empty args parameter removes the affected border.
+ *
+ * @param args a varargs array possible containing {@link Double} (width),
+ * {@link StrokeStyle.LineCompound}, {@link Color}, {@link StrokeStyle.LineDash}
+ */
+ public void setOutsideBorders(Object... args){
+ if (args.length == 0) return;
+
+ TableShape<?,?> table = getShape();
+ final int rows = table.getNumberOfRows();
+ final int cols = table.getNumberOfColumns();
+
+ BorderEdge edges[] = new BorderEdge[4];
+ for (int row = 0; row < rows; row++) {
+ for (int col = 0; col < cols; col++) {
+ edges[0] = (col == 0) ? BorderEdge.left : null;
+ edges[1] = (col == cols - 1) ? BorderEdge.right : null;
+ edges[2] = (row == 0) ? BorderEdge.top : null;
+ edges[3] = (row == rows - 1) ? BorderEdge.bottom : null;
+ setEdges(table.getCell(row, col), edges, args);
+ }
+ }
+ }
+
+ /**
+ * Format the inside border using the specified Line object
+ * An empty args parameter removes the affected border.
+ *
+ * @param args a varargs array possible containing {@link Double} (width),
+ * {@link StrokeStyle.LineCompound}, {@link Color}, {@link StrokeStyle.LineDash}
+ */
+ public void setInsideBorders(Object... args) {
+ if (args.length == 0) return;
+
+ TableShape<?,?> table = getShape();
+ final int rows = table.getNumberOfRows();
+ final int cols = table.getNumberOfColumns();
+
+ BorderEdge edges[] = new BorderEdge[2];
+ for (int row = 0; row < rows; row++) {
+ for (int col = 0; col < cols; col++) {
+ edges[0] = (col > 0 && col < cols - 1) ? BorderEdge.right : null;
+ edges[1] = (row > 0 && row < rows - 1) ? BorderEdge.bottom : null;
+ setEdges(table.getCell(row, col), edges, args);
+ }
+ }
+ }
+
+ /**
+ * Apply the border attributes (args) to the given cell and edges
+ *
+ * @param cell the cell
+ * @param edges the border edges
+ * @param args the border attributes
+ */
+ private static void setEdges(TableCell<?,?> cell, BorderEdge edges[], Object... args) {
+ for (BorderEdge be : edges) {
+ if (be != null) {
+ if (args.length == 0) {
+ cell.removeBorder(be);
+ } else {
+ for (Object o : args) {
+ if (o instanceof Double) {
+ cell.setBorderWidth(be, (Double)o);
+ } else if (o instanceof Color) {
+ cell.setBorderColor(be, (Color)o);
+ } else if (o instanceof LineDash) {
+ cell.setBorderDash(be, (LineDash)o);
+ } else if (o instanceof LineCompound) {
+ cell.setBorderCompound(be, (LineCompound)o);
+ }
+ }
+ }
+ }
+ }
+ }
}