import javax.swing.border.AbstractBorder;
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+
/**
* This is an attempt to implement Excel style borders for the SuckyViewer
*
Color eastColor = null;
Color southColor = null;
Color westColor = null;
- int northThickness;
- int eastThickness;
- int southThickness;
- int westThickness;
+ int northBorderType;
+ int eastBorderType;
+ int southBorderType;
+ int westBorderType;
boolean northBorder=false;
boolean eastBorder=false;
boolean southBorder=false;
public SVBorder(Color northColor, Color eastColor,
Color southColor, Color westColor,
- int northThickness, int eastThickness,
- int southThickness, int westThickness,
+ int northBorderType, int eastBorderType,
+ int southBorderType, int westBorderType,
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.northBorderType = northBorderType;
+ this.eastBorderType = eastBorderType;
+ this.southBorderType = southBorderType;
+ this.westBorderType = westBorderType;
this.northBorder=northBorder;
this.eastBorder=eastBorder;
this.southBorder=southBorder;
int height) {
Color oldColor = g.getColor();
int i;
-
- if (northBorder) {
- System.out.println("NorthBorder x="+x+",y="+y+"x1="+width+"y1="+y);
+
+ paintNormalBorders(g, x, y, width, height);
+ paintDottedBorders(g, x, y, width, height);
+
+
+ g.setColor(oldColor);
+ }
+
+ private void paintNormalBorders(Graphics g, int x, int y, int width,
+ int height) {
+
+ if (northBorder &&
+ ((northBorderType == HSSFCellStyle.BORDER_THIN) ||
+ (northBorderType == HSSFCellStyle.BORDER_MEDIUM) ||
+ (northBorderType == HSSFCellStyle.BORDER_THICK) ||
+ (northBorderType == HSSFCellStyle.BORDER_HAIR))
+ ) {
+
+ int thickness = getThickness(northBorderType);
+
g.setColor(northColor);
- for (int k=0; k < northThickness; k++) {
+ for (int k=0; k < thickness; k++) {
g.drawLine(x,y+k,width,y+k);
}
}
+ if (eastBorder &&
+ ((eastBorderType == HSSFCellStyle.BORDER_THIN) ||
+ (eastBorderType == HSSFCellStyle.BORDER_MEDIUM) ||
+ (eastBorderType == HSSFCellStyle.BORDER_THICK) ||
+ (eastBorderType == HSSFCellStyle.BORDER_HAIR))
+ ) {
+
+ int thickness = getThickness(eastBorderType);
- if (eastBorder) {
- System.out.println("EastBorder x="+x+",y="+y+"x1="+width+"y1="+y);
g.setColor(eastColor);
- for (int k=0; k < eastThickness; k++) {
+ for (int k=0; k < thickness; k++) {
g.drawLine(width-k,y,width-k,height);
}
}
- if (southBorder) {
- System.out.println("SouthBorder x="+x+",y="+height+"x1="+width+"y1="+height);
+ if (southBorder &&
+ ((southBorderType == HSSFCellStyle.BORDER_THIN) ||
+ (southBorderType == HSSFCellStyle.BORDER_MEDIUM) ||
+ (southBorderType == HSSFCellStyle.BORDER_THICK) ||
+ (southBorderType == HSSFCellStyle.BORDER_HAIR))
+ ) {
+
+ int thickness = getThickness(southBorderType);
+
g.setColor(southColor);
- for (int k=0; k < southThickness; k++) {
+ for (int k=0; k < thickness; k++) {
g.drawLine(x,height - k,width,height - k);
}
}
- if (westBorder) {
- System.out.println("WestBorder x="+x+",y="+y+"x1="+width+"y1="+y);
+ if (westBorder &&
+ ((westBorderType == HSSFCellStyle.BORDER_THIN) ||
+ (westBorderType == HSSFCellStyle.BORDER_MEDIUM) ||
+ (westBorderType == HSSFCellStyle.BORDER_THICK) ||
+ (westBorderType == HSSFCellStyle.BORDER_HAIR))
+ ) {
+
+ int thickness = getThickness(westBorderType);
+
g.setColor(westColor);
- for (int k=0; k < westThickness; k++) {
+ for (int k=0; k < thickness; k++) {
g.drawLine(x+k,y,x+k,height);
}
}
+ }
- g.setColor(oldColor);
+ private void paintDottedBorders(Graphics g, int x, int y, int width,
+ int height) {
+ if (northBorder &&
+ northBorderType == HSSFCellStyle.BORDER_DOTTED) {
+ int thickness = getThickness(northBorderType);
+
+ g.setColor(northColor);
+
+ for (int k=0; k < thickness; k++) {
+ for (int xc = x; xc < width; xc=xc+2) {
+ g.drawLine(xc,y+k,xc,y+k);
+ }
+ }
+ }
+
+ if (eastBorder &&
+ eastBorderType == HSSFCellStyle.BORDER_DOTTED
+ ) {
+
+ int thickness = getThickness(eastBorderType);
+ thickness++; //need for dotted borders to show up east
+
+ g.setColor(eastColor);
+
+ for (int k=0; k < thickness; k++) {
+ for (int yc=y;yc < height; yc=yc+2) {
+ g.drawLine(width-k,yc,width-k,yc);
+ }
+ }
+ }
+
+ if (southBorder &&
+ southBorderType == HSSFCellStyle.BORDER_DOTTED
+ ) {
+
+ int thickness = getThickness(southBorderType);
+ thickness++;
+ g.setColor(southColor);
+ for (int k=0; k < thickness; k++) {
+ for (int xc = x; xc < width; xc=xc+2) {
+ g.drawLine(xc,height-k,xc,height-k);
+ }
+ }
+ }
+
+ if (westBorder &&
+ westBorderType == HSSFCellStyle.BORDER_DOTTED
+ ) {
+
+ int thickness = getThickness(westBorderType);
+// thickness++;
+
+ g.setColor(westColor);
+
+ for (int k=0; k < thickness; k++) {
+ for (int yc=y;yc < height; yc=yc+2) {
+ g.drawLine(x+k,yc,x+k,yc);
+ }
+ }
+ }
+ }
+
+ private int getThickness(int thickness) {
+ int retval=1;
+ switch (thickness) {
+ case HSSFCellStyle.BORDER_THIN:
+ retval=2;
+ break;
+ case HSSFCellStyle.BORDER_MEDIUM:
+ retval=3;
+ break;
+ case HSSFCellStyle.BORDER_THICK:
+ retval=4;
+ break;
+ case HSSFCellStyle.BORDER_HAIR:
+ retval=1;
+ break;
+ default:
+ retval=1;
+ }
+ return retval;
}
}
HSSFCell c = getCell(row,column);
+
if (c != null) {
+
HSSFCellStyle s = c.getCellStyle();
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;
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,fontheight);
setFont(font);
awtcolor = new Color(rgb[0],rgb[1],rgb[2]);
setForeground(awtcolor);
- if (s.getBorderBottom() != HSSFCellStyle.BORDER_NONE ||
+/* 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;
- }
-
+*/
+ int borderTop = s.getBorderTop();
+ int borderRight = s.getBorderRight();
+ int borderBottom = s.getBorderBottom();
+ int borderLeft = s.getBorderLeft();
+
SVBorder border = new SVBorder(Color.black, Color.black,
Color.black, Color.black,
borderTop, borderRight,
s.getBorderLeft() != HSSFCellStyle.BORDER_NONE);
setBorder(border);
isBorderSet=true;
- //need custom border that can have north,east,south,west settings
- }
+
+// }
+ } else {
+ setBackground(Color.white);
}