Cleanup, more borders supported

PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352750 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew C. Oliver 2002-07-04 04:47:21 +00:00
parent 3aafd04e68
commit 0f999b3891
2 changed files with 178 additions and 72 deletions

View File

@ -8,6 +8,8 @@ import java.awt.Component;
import javax.swing.border.AbstractBorder;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
/**
* This is an attempt to implement Excel style borders for the SuckyViewer
*
@ -17,10 +19,10 @@ public class SVBorder extends AbstractBorder {
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;
@ -28,18 +30,18 @@ public class SVBorder extends AbstractBorder {
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;
@ -51,44 +53,162 @@ public class SVBorder extends AbstractBorder {
Color oldColor = g.getColor();
int i;
if (northBorder) {
System.out.println("NorthBorder x="+x+",y="+y+"x1="+width+"y1="+y);
g.setColor(northColor);
paintNormalBorders(g, x, y, width, height);
paintDottedBorders(g, x, y, width, height);
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);
}
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 < 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);
g.setColor(eastColor);
for (int k=0; k < thickness; k++) {
g.drawLine(width-k,y,width-k,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 < thickness; k++) {
g.drawLine(x,height - k,width,height - k);
}
}
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 < thickness; k++) {
g.drawLine(x+k,y,x+k,height);
}
}
}
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;
}
}

View File

@ -131,13 +131,14 @@ public class SVTableCellRenderer extends JLabel
}
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;
@ -146,8 +147,6 @@ public class SVTableCellRenderer extends JLabel
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);
@ -169,30 +168,15 @@ public class SVTableCellRenderer extends JLabel
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,
@ -204,8 +188,10 @@ public class SVTableCellRenderer extends JLabel
s.getBorderLeft() != HSSFCellStyle.BORDER_NONE);
setBorder(border);
isBorderSet=true;
//need custom border that can have north,east,south,west settings
}
// }
} else {
setBackground(Color.white);
}