summaryrefslogtreecommitdiffstats
path: root/src/contrib
diff options
context:
space:
mode:
authorAndrew C. Oliver <acoliver@apache.org>2002-06-23 02:54:08 +0000
committerAndrew C. Oliver <acoliver@apache.org>2002-06-23 02:54:08 +0000
commit9a4e7149ff53ff4f931a96f4610a452fbc35d407 (patch)
tree5ff6648327b37c842e1f6a241d052f0e77ab5495 /src/contrib
parent6d66d9e26a96eb50821c1020be3394bd9a9f2276 (diff)
downloadpoi-9a4e7149ff53ff4f931a96f4610a452fbc35d407.tar.gz
poi-9a4e7149ff53ff4f931a96f4610a452fbc35d407.zip
added minimal border support to sucky viewer (currently just ON or OFF)
PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352716 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/contrib')
-rw-r--r--src/contrib/src/org/apache/poi/hssf/contrib/view/SVBorder.java94
-rw-r--r--src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellRenderer.java54
2 files changed, 145 insertions, 3 deletions
diff --git a/src/contrib/src/org/apache/poi/hssf/contrib/view/SVBorder.java b/src/contrib/src/org/apache/poi/hssf/contrib/view/SVBorder.java
new file mode 100644
index 0000000000..5522c72f5e
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/hssf/contrib/view/SVBorder.java
@@ -0,0 +1,94 @@
+package org.apache.poi.hssf.contrib.view;
+
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Rectangle;
+import java.awt.Color;
+import java.awt.Component;
+
+import javax.swing.border.AbstractBorder;
+
+/**
+ * This is an attempt to implement Excel style borders for the SuckyViewer
+ *
+ */
+public class SVBorder extends AbstractBorder {
+ Color northColor = null;
+ Color eastColor = null;
+ Color southColor = null;
+ Color westColor = null;
+ int northThickness;
+ int eastThickness;
+ int southThickness;
+ int westThickness;
+ boolean northBorder=false;
+ boolean eastBorder=false;
+ boolean southBorder=false;
+ boolean westBorder=false;
+
+ public SVBorder(Color northColor, Color eastColor,
+ Color southColor, Color westColor,
+ int northThickness, int eastThickness,
+ int southThickness, int westThickness,
+ boolean northBorder, boolean eastBorder,
+ boolean southBorder, boolean westBorder) {
+ this.northColor = northColor;
+ this.eastColor = eastColor;
+ this.southColor = southColor;
+ this.westColor = westColor;
+ this.northThickness = northThickness;
+ this.eastThickness = eastThickness;
+ this.southThickness = southThickness;
+ this.westThickness = westThickness;
+ this.northBorder=northBorder;
+ this.eastBorder=eastBorder;
+ this.southBorder=southBorder;
+ this.westBorder=westBorder;
+ }
+
+ public void paintBorder(Component c, Graphics g, int x, int y, int width,
+ int height) {
+ Color oldColor = g.getColor();
+ int i;
+
+ if (northBorder) {
+ System.out.println("NorthBorder x="+x+",y="+y+"x1="+width+"y1="+y);
+ g.setColor(northColor);
+
+ for (int k=0; k < northThickness; k++) {
+ g.drawLine(x,y+k,width,y+k);
+ }
+ }
+
+
+ if (eastBorder) {
+ System.out.println("EastBorder x="+x+",y="+y+"x1="+width+"y1="+y);
+ g.setColor(eastColor);
+
+ for (int k=0; k < eastThickness; k++) {
+ g.drawLine(width-k,y,width-k,height);
+ }
+ }
+
+ if (southBorder) {
+ System.out.println("SouthBorder x="+x+",y="+height+"x1="+width+"y1="+height);
+ g.setColor(southColor);
+ for (int k=0; k < southThickness; k++) {
+ g.drawLine(x,height - k,width,height - k);
+ }
+ }
+
+ if (westBorder) {
+ System.out.println("WestBorder x="+x+",y="+y+"x1="+width+"y1="+y);
+ g.setColor(westColor);
+
+ for (int k=0; k < westThickness; k++) {
+ g.drawLine(x+k,y,x+k,height);
+ }
+ }
+
+ g.setColor(oldColor);
+ }
+
+
+}
diff --git a/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellRenderer.java b/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellRenderer.java
index 0c45069305..20a25010e9 100644
--- a/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellRenderer.java
+++ b/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellRenderer.java
@@ -123,6 +123,8 @@ public class SVTableCellRenderer extends JLabel
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
+ boolean isBorderSet = false;
+
if (isSelected) {
super.setForeground(table.getSelectionForeground());
super.setBackground(table.getSelectionBackground());
@@ -134,13 +136,19 @@ public class SVTableCellRenderer extends JLabel
HSSFFont f = wb.getFontAt(s.getFontIndex());
boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
boolean isitalics = f.getItalic();
+// System.out.println("bold="+isbold);
+// System.out.println("italics="+isitalics);
int fontstyle = 0;
if (isbold) fontstyle = Font.BOLD;
if (isitalics) fontstyle = fontstyle | Font.ITALIC;
+ int fontheight = f.getFontHeightInPoints();
+ if (fontheight == 9) fontheight = 10; //fix for stupid ol Windows
+
+// System.out.println("fontsizeinpnts="+f.getFontHeightInPoints());
- Font font = new Font(f.getFontName(),fontstyle,f.getFontHeightInPoints());
+ Font font = new Font(f.getFontName(),fontstyle,fontheight);
setFont(font);
@@ -160,16 +168,56 @@ public class SVTableCellRenderer extends JLabel
rgb = clr.getTriplet();
awtcolor = new Color(rgb[0],rgb[1],rgb[2]);
setForeground(awtcolor);
+
+ if (s.getBorderBottom() != HSSFCellStyle.BORDER_NONE ||
+ s.getBorderTop() != HSSFCellStyle.BORDER_NONE ||
+ s.getBorderLeft() != HSSFCellStyle.BORDER_NONE ||
+ s.getBorderRight() != HSSFCellStyle.BORDER_NONE) {
+ int borderTop = 0;
+ int borderRight = 0;
+ int borderBottom = 0;
+ int borderLeft = 0;
+
+ if(s.getBorderBottom() != HSSFCellStyle.BORDER_NONE) {
+ borderBottom = 2;
+ }
+
+ if(s.getBorderRight() != HSSFCellStyle.BORDER_NONE) {
+ borderRight = 2;
+ }
+
+ if(s.getBorderTop() != HSSFCellStyle.BORDER_NONE) {
+ borderTop = 2;
+ }
+
+ if(s.getBorderLeft() != HSSFCellStyle.BORDER_NONE) {
+ borderLeft = 2;
+ }
+
+ SVBorder border = new SVBorder(Color.black, Color.black,
+ Color.black, Color.black,
+ borderTop, borderRight,
+ borderBottom, borderLeft,
+ s.getBorderTop() != HSSFCellStyle.BORDER_NONE,
+ s.getBorderRight() != HSSFCellStyle.BORDER_NONE,
+ s.getBorderBottom() != HSSFCellStyle.BORDER_NONE,
+ s.getBorderLeft() != HSSFCellStyle.BORDER_NONE);
+ setBorder(border);
+ isBorderSet=true;
+ //need custom border that can have north,east,south,west settings
+ }
}
if (hasFocus) {
- setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
+ if (!isBorderSet) {
+ setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
+ }
if (table.isCellEditable(row, column)) {
super.setForeground( UIManager.getColor("Table.focusCellForeground") );
super.setBackground( UIManager.getColor("Table.focusCellBackground") );
}
- } else {
+ } else if (!isBorderSet) {
setBorder(noFocusBorder);
}