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:
parent
3aafd04e68
commit
0f999b3891
@ -8,6 +8,8 @@ import java.awt.Component;
|
|||||||
|
|
||||||
import javax.swing.border.AbstractBorder;
|
import javax.swing.border.AbstractBorder;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an attempt to implement Excel style borders for the SuckyViewer
|
* 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 eastColor = null;
|
||||||
Color southColor = null;
|
Color southColor = null;
|
||||||
Color westColor = null;
|
Color westColor = null;
|
||||||
int northThickness;
|
int northBorderType;
|
||||||
int eastThickness;
|
int eastBorderType;
|
||||||
int southThickness;
|
int southBorderType;
|
||||||
int westThickness;
|
int westBorderType;
|
||||||
boolean northBorder=false;
|
boolean northBorder=false;
|
||||||
boolean eastBorder=false;
|
boolean eastBorder=false;
|
||||||
boolean southBorder=false;
|
boolean southBorder=false;
|
||||||
@ -28,18 +30,18 @@ public class SVBorder extends AbstractBorder {
|
|||||||
|
|
||||||
public SVBorder(Color northColor, Color eastColor,
|
public SVBorder(Color northColor, Color eastColor,
|
||||||
Color southColor, Color westColor,
|
Color southColor, Color westColor,
|
||||||
int northThickness, int eastThickness,
|
int northBorderType, int eastBorderType,
|
||||||
int southThickness, int westThickness,
|
int southBorderType, int westBorderType,
|
||||||
boolean northBorder, boolean eastBorder,
|
boolean northBorder, boolean eastBorder,
|
||||||
boolean southBorder, boolean westBorder) {
|
boolean southBorder, boolean westBorder) {
|
||||||
this.northColor = northColor;
|
this.northColor = northColor;
|
||||||
this.eastColor = eastColor;
|
this.eastColor = eastColor;
|
||||||
this.southColor = southColor;
|
this.southColor = southColor;
|
||||||
this.westColor = westColor;
|
this.westColor = westColor;
|
||||||
this.northThickness = northThickness;
|
this.northBorderType = northBorderType;
|
||||||
this.eastThickness = eastThickness;
|
this.eastBorderType = eastBorderType;
|
||||||
this.southThickness = southThickness;
|
this.southBorderType = southBorderType;
|
||||||
this.westThickness = westThickness;
|
this.westBorderType = westBorderType;
|
||||||
this.northBorder=northBorder;
|
this.northBorder=northBorder;
|
||||||
this.eastBorder=eastBorder;
|
this.eastBorder=eastBorder;
|
||||||
this.southBorder=southBorder;
|
this.southBorder=southBorder;
|
||||||
@ -51,44 +53,162 @@ public class SVBorder extends AbstractBorder {
|
|||||||
Color oldColor = g.getColor();
|
Color oldColor = g.getColor();
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (northBorder) {
|
paintNormalBorders(g, x, y, width, height);
|
||||||
System.out.println("NorthBorder x="+x+",y="+y+"x1="+width+"y1="+y);
|
paintDottedBorders(g, x, y, width, height);
|
||||||
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);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -131,13 +131,14 @@ public class SVTableCellRenderer extends JLabel
|
|||||||
}
|
}
|
||||||
|
|
||||||
HSSFCell c = getCell(row,column);
|
HSSFCell c = getCell(row,column);
|
||||||
|
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
|
|
||||||
HSSFCellStyle s = c.getCellStyle();
|
HSSFCellStyle s = c.getCellStyle();
|
||||||
HSSFFont f = wb.getFontAt(s.getFontIndex());
|
HSSFFont f = wb.getFontAt(s.getFontIndex());
|
||||||
boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
|
boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
|
||||||
boolean isitalics = f.getItalic();
|
boolean isitalics = f.getItalic();
|
||||||
// System.out.println("bold="+isbold);
|
|
||||||
// System.out.println("italics="+isitalics);
|
|
||||||
int fontstyle = 0;
|
int fontstyle = 0;
|
||||||
|
|
||||||
if (isbold) fontstyle = Font.BOLD;
|
if (isbold) fontstyle = Font.BOLD;
|
||||||
@ -146,8 +147,6 @@ public class SVTableCellRenderer extends JLabel
|
|||||||
int fontheight = f.getFontHeightInPoints();
|
int fontheight = f.getFontHeightInPoints();
|
||||||
if (fontheight == 9) fontheight = 10; //fix for stupid ol Windows
|
if (fontheight == 9) fontheight = 10; //fix for stupid ol Windows
|
||||||
|
|
||||||
// System.out.println("fontsizeinpnts="+f.getFontHeightInPoints());
|
|
||||||
|
|
||||||
Font font = new Font(f.getFontName(),fontstyle,fontheight);
|
Font font = new Font(f.getFontName(),fontstyle,fontheight);
|
||||||
setFont(font);
|
setFont(font);
|
||||||
|
|
||||||
@ -169,30 +168,15 @@ public class SVTableCellRenderer extends JLabel
|
|||||||
awtcolor = new Color(rgb[0],rgb[1],rgb[2]);
|
awtcolor = new Color(rgb[0],rgb[1],rgb[2]);
|
||||||
setForeground(awtcolor);
|
setForeground(awtcolor);
|
||||||
|
|
||||||
if (s.getBorderBottom() != HSSFCellStyle.BORDER_NONE ||
|
/* if (s.getBorderBottom() != HSSFCellStyle.BORDER_NONE ||
|
||||||
s.getBorderTop() != HSSFCellStyle.BORDER_NONE ||
|
s.getBorderTop() != HSSFCellStyle.BORDER_NONE ||
|
||||||
s.getBorderLeft() != HSSFCellStyle.BORDER_NONE ||
|
s.getBorderLeft() != HSSFCellStyle.BORDER_NONE ||
|
||||||
s.getBorderRight() != HSSFCellStyle.BORDER_NONE) {
|
s.getBorderRight() != HSSFCellStyle.BORDER_NONE) {
|
||||||
int borderTop = 0;
|
*/
|
||||||
int borderRight = 0;
|
int borderTop = s.getBorderTop();
|
||||||
int borderBottom = 0;
|
int borderRight = s.getBorderRight();
|
||||||
int borderLeft = 0;
|
int borderBottom = s.getBorderBottom();
|
||||||
|
int borderLeft = s.getBorderLeft();
|
||||||
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,
|
SVBorder border = new SVBorder(Color.black, Color.black,
|
||||||
Color.black, Color.black,
|
Color.black, Color.black,
|
||||||
@ -204,8 +188,10 @@ public class SVTableCellRenderer extends JLabel
|
|||||||
s.getBorderLeft() != HSSFCellStyle.BORDER_NONE);
|
s.getBorderLeft() != HSSFCellStyle.BORDER_NONE);
|
||||||
setBorder(border);
|
setBorder(border);
|
||||||
isBorderSet=true;
|
isBorderSet=true;
|
||||||
//need custom border that can have north,east,south,west settings
|
|
||||||
}
|
// }
|
||||||
|
} else {
|
||||||
|
setBackground(Color.white);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user