? view/SViewerPanel.java Index: view/SVBorder.java =================================================================== RCS file: /home/cvspublic/jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SVBorder.java,v retrieving revision 1.6 diff -r1.6 SVBorder.java 1,507c1,517 < 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; < < import org.apache.poi.hssf.usermodel.HSSFCellStyle; < < /** < * 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 northBorderType; < int eastBorderType; < int southBorderType; < int westBorderType; < boolean northBorder=false; < boolean eastBorder=false; < boolean southBorder=false; < boolean westBorder=false; < < public SVBorder(Color northColor, Color eastColor, < Color southColor, Color westColor, < 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.northBorderType = northBorderType; < this.eastBorderType = eastBorderType; < this.southBorderType = southBorderType; < this.westBorderType = westBorderType; < 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; < < // System.err.println("northBorder="+northBorderType); < paintNormalBorders(g, x, y, width, height); < paintDottedBorders(g, x, y, width, height); < paintDashedBorders(g, x, y, width, height); < paintDoubleBorders(g, x, y, width, height); < paintDashDotDotBorders(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) < ) < ) { < < 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) < ) < ) { < < 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) < ) < ) { < < 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) < ) < ) { < < 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 void paintDashedBorders(Graphics g, int x, int y, int width, < int height) { < if (northBorder && < ((northBorderType == HSSFCellStyle.BORDER_DASHED) || < (northBorderType == HSSFCellStyle.BORDER_HAIR)) < ) { < int thickness = getThickness(northBorderType); < < int dashlength = 1; < < if (northBorderType == HSSFCellStyle.BORDER_DASHED) < dashlength = 2; < < g.setColor(northColor); < < for (int k=0; k < thickness; k++) { < for (int xc = x; xc < width; xc=xc+5) { < g.drawLine(xc,y+k,xc+dashlength,y+k); < } < } < } < < if (eastBorder && < ((eastBorderType == HSSFCellStyle.BORDER_DASHED) || < (eastBorderType == HSSFCellStyle.BORDER_HAIR)) < ) { < < int thickness = getThickness(eastBorderType); < thickness++; //need for dotted borders to show up east < < < int dashlength = 1; < < if (eastBorderType == HSSFCellStyle.BORDER_DASHED) < dashlength = 2; < < g.setColor(eastColor); < < for (int k=0; k < thickness; k++) { < for (int yc=y;yc < height; yc=yc+5) { < g.drawLine(width-k,yc,width-k,yc+dashlength); < } < } < } < < if (southBorder && < ((southBorderType == HSSFCellStyle.BORDER_DASHED) || < (southBorderType == HSSFCellStyle.BORDER_HAIR)) < ) { < < int thickness = getThickness(southBorderType); < thickness++; < < int dashlength = 1; < < if (southBorderType == HSSFCellStyle.BORDER_DASHED) < dashlength = 2; < < g.setColor(southColor); < for (int k=0; k < thickness; k++) { < for (int xc = x; xc < width; xc=xc+5) { < g.drawLine(xc,height-k,xc+dashlength,height-k); < } < } < } < < if (westBorder && < ((westBorderType == HSSFCellStyle.BORDER_DASHED) || < (westBorderType == HSSFCellStyle.BORDER_HAIR)) < ) { < < int thickness = getThickness(westBorderType); < // thickness++; < < int dashlength = 1; < < if (westBorderType == HSSFCellStyle.BORDER_DASHED) < dashlength = 2; < < g.setColor(westColor); < < for (int k=0; k < thickness; k++) { < for (int yc=y;yc < height; yc=yc+5) { < g.drawLine(x+k,yc,x+k,yc+dashlength); < } < } < } < } < < < private void paintDoubleBorders(Graphics g, int x, int y, int width, < int height) { < if (northBorder && < northBorderType == HSSFCellStyle.BORDER_DOUBLE) { < < g.setColor(northColor); < < int leftx=x; < int rightx=width; < < // if there are borders on the west or east then < // the second line shouldn't cross them < if (westBorder) < leftx = x+3; < < if (eastBorder) < rightx = width-3; < < g.drawLine(x,y,width,y); < g.drawLine(leftx,y+2,rightx,y+2); < } < < if (eastBorder && < eastBorderType == HSSFCellStyle.BORDER_DOUBLE < ) { < < int thickness = getThickness(eastBorderType); < thickness++; //need for dotted borders to show up east < < g.setColor(eastColor); < < int topy=y; < int bottomy=height; < < if (northBorder) < topy=y+3; < < if (southBorder) < bottomy=height-3; < < g.drawLine(width-1,y,width-1,height); < g.drawLine(width-3,topy,width-3,bottomy); < } < < if (southBorder && < southBorderType == HSSFCellStyle.BORDER_DOUBLE < ) { < < g.setColor(southColor); < < int leftx=y; < int rightx=width; < < if (westBorder) < leftx=x+3; < < if (eastBorder) < rightx=width-3; < < < g.drawLine(x,height - 1,width,height - 1); < g.drawLine(leftx,height - 3,rightx,height - 3); < } < < if (westBorder && < westBorderType == HSSFCellStyle.BORDER_DOUBLE < ) { < < int thickness = getThickness(westBorderType); < // thickness++; < < g.setColor(westColor); < < int topy=y; < int bottomy=height-3; < < if (northBorder) < topy=y+2; < < if (southBorder) < bottomy=height-3; < < g.drawLine(x,y,x,height); < g.drawLine(x+2,topy,x+2,bottomy); < } < } < < < private void paintDashDotDotBorders(Graphics g, int x, int y, int width, < int height) { < if (northBorder && < ((northBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || < (northBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) < ) { < int thickness = getThickness(northBorderType); < < g.setColor(northColor); < for (int l=x; l < width;) { < l=l+drawDashDotDot(g, l, y, thickness, true, true); < } < < } < < if (eastBorder && < ((eastBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || < (eastBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) < ) { < < int thickness = getThickness(eastBorderType); < < g.setColor(eastColor); < < for (int l=y;l < height;) { < //System.err.println("drawing east"); < l=l+drawDashDotDot(g,width-1,l,thickness,false,false); < } < } < < if (southBorder && < ((southBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || < (southBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) < ) { < < int thickness = getThickness(southBorderType); < < g.setColor(southColor); < < for (int l=x; l < width;) { < //System.err.println("drawing south"); < l=l+drawDashDotDot(g, l, height-1, thickness, true, false); < } < } < < if (westBorder && < ((westBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || < (westBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) < ) { < < int thickness = getThickness(westBorderType); < < g.setColor(westColor); < < for (int l=y;l < height;) { < //System.err.println("drawing west"); < l=l+drawDashDotDot(g,x,l,thickness,false,true); < } < < } < } < < /** < * Draws one dash dot dot horizontally or vertically with thickness drawn < * incrementally to either the right or left. < * < * @param g graphics object for drawing with < * @param x the x origin of the line < * @param y the y origin of the line < * @param thickness the thickness of the line < * @param horizontal or vertical (true for horizontal) < * @param right/bottom or left/top thickness (true for right or top), < * if true then the x or y origin will be incremented to provide < * thickness, if false, they'll be decremented. For vertical < * borders, x is incremented or decremented, for horizontal its y. < * Just set to true for north and west, and false for east and < * south. < * @returns length - returns the length of the line. < */ < private int drawDashDotDot(Graphics g,int x, int y, int thickness, < boolean horizontal, < boolean rightBottom) { < < for (int t=0; t < thickness; t++) { < if (!rightBottom) { < t = 0 - t; //add negative thickness so we go the other way < //then we'll decrement instead of increment. < } < if (horizontal) { < g.drawLine(x,y+t,x+5,y+t); < g.drawLine(x+8,y+t,x+10,y+t); < g.drawLine(x+13,y+t,x+15,y+t); < } else { < g.drawLine(x+t,y,x+t,y+5); < g.drawLine(x+t,y+8,x+t,y+10); < g.drawLine(x+t,y+13,x+t,y+15); < } < } < return 18; < } < < 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_DASHED: < retval=1; < break; < case HSSFCellStyle.BORDER_DASH_DOT_DOT: < retval=1; < break; < case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT: < retval=3; < break; < case HSSFCellStyle.BORDER_HAIR: < retval=1; < break; < default: < retval=1; < } < return retval; < } < < < } --- > package org.apache.poi.hssf.contrib.view; > > import java.awt.*; > > import javax.swing.border.AbstractBorder; > > import org.apache.poi.hssf.usermodel.HSSFCellStyle; > > /** > * This is an attempt to implement Excel style borders for the SuckyViewer > * > */ > public class SVBorder extends AbstractBorder { > private Color northColor = null; > private Color eastColor = null; > private Color southColor = null; > private Color westColor = null; > private int northBorderType = HSSFCellStyle.BORDER_NONE; > private int eastBorderType =HSSFCellStyle.BORDER_NONE; > private int southBorderType = HSSFCellStyle.BORDER_NONE; > private int westBorderType = HSSFCellStyle.BORDER_NONE; > private boolean northBorder=false; > private boolean eastBorder=false; > private boolean southBorder=false; > private boolean westBorder=false; > private boolean selected = false; > > public void setBorder(Color northColor, Color eastColor, > Color southColor, Color westColor, > int northBorderType, int eastBorderType, > int southBorderType, int westBorderType, > boolean selected) { > this.eastColor = eastColor; > this.southColor = southColor; > this.westColor = westColor; > this.northBorderType = northBorderType; > this.eastBorderType = eastBorderType; > this.southBorderType = southBorderType; > this.westBorderType = westBorderType; > this.northBorder=northBorderType != HSSFCellStyle.BORDER_NONE; > this.eastBorder=eastBorderType != HSSFCellStyle.BORDER_NONE; > this.southBorder=southBorderType != HSSFCellStyle.BORDER_NONE; > this.westBorder=westBorderType != HSSFCellStyle.BORDER_NONE; > this.selected = selected; > } > > public void paintBorder(Component c, Graphics g, int x, int y, int width, > int height) { > Color oldColor = g.getColor(); > > > paintSelectedBorder(g, x, y, width, height); > paintNormalBorders(g, x, y, width, height); > paintDottedBorders(g, x, y, width, height); > paintDashedBorders(g, x, y, width, height); > paintDoubleBorders(g, x, y, width, height); > paintDashDotDotBorders(g, x, y, width, height); > > > g.setColor(oldColor); > } > > private void paintSelectedBorder(Graphics g, int x, int y, int width, > int height) { > if (selected) { > //Need to setup thickness of 2 > g.setColor(Color.black); > //paint the border > g.drawRect(x,y,width-1,height-1); > > //paint the filled rectangle at the bottom left hand position > g.fillRect(x+width-5, y+height-5, 5, 5); > } > } > > > 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) > ) > ) { > > 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) > ) > ) { > > 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) > ) > ) { > > 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) > ) > ) { > > 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 void paintDashedBorders(Graphics g, int x, int y, int width, > int height) { > if (northBorder && > ((northBorderType == HSSFCellStyle.BORDER_DASHED) || > (northBorderType == HSSFCellStyle.BORDER_HAIR)) > ) { > int thickness = getThickness(northBorderType); > > int dashlength = 1; > > if (northBorderType == HSSFCellStyle.BORDER_DASHED) > dashlength = 2; > > g.setColor(northColor); > > for (int k=0; k < thickness; k++) { > for (int xc = x; xc < width; xc=xc+5) { > g.drawLine(xc,y+k,xc+dashlength,y+k); > } > } > } > > if (eastBorder && > ((eastBorderType == HSSFCellStyle.BORDER_DASHED) || > (eastBorderType == HSSFCellStyle.BORDER_HAIR)) > ) { > > int thickness = getThickness(eastBorderType); > thickness++; //need for dotted borders to show up east > > > int dashlength = 1; > > if (eastBorderType == HSSFCellStyle.BORDER_DASHED) > dashlength = 2; > > g.setColor(eastColor); > > for (int k=0; k < thickness; k++) { > for (int yc=y;yc < height; yc=yc+5) { > g.drawLine(width-k,yc,width-k,yc+dashlength); > } > } > } > > if (southBorder && > ((southBorderType == HSSFCellStyle.BORDER_DASHED) || > (southBorderType == HSSFCellStyle.BORDER_HAIR)) > ) { > > int thickness = getThickness(southBorderType); > thickness++; > > int dashlength = 1; > > if (southBorderType == HSSFCellStyle.BORDER_DASHED) > dashlength = 2; > > g.setColor(southColor); > for (int k=0; k < thickness; k++) { > for (int xc = x; xc < width; xc=xc+5) { > g.drawLine(xc,height-k,xc+dashlength,height-k); > } > } > } > > if (westBorder && > ((westBorderType == HSSFCellStyle.BORDER_DASHED) || > (westBorderType == HSSFCellStyle.BORDER_HAIR)) > ) { > > int thickness = getThickness(westBorderType); > // thickness++; > > int dashlength = 1; > > if (westBorderType == HSSFCellStyle.BORDER_DASHED) > dashlength = 2; > > g.setColor(westColor); > > for (int k=0; k < thickness; k++) { > for (int yc=y;yc < height; yc=yc+5) { > g.drawLine(x+k,yc,x+k,yc+dashlength); > } > } > } > } > > > private void paintDoubleBorders(Graphics g, int x, int y, int width, > int height) { > if (northBorder && > northBorderType == HSSFCellStyle.BORDER_DOUBLE) { > > g.setColor(northColor); > > int leftx=x; > int rightx=width; > > // if there are borders on the west or east then > // the second line shouldn't cross them > if (westBorder) > leftx = x+3; > > if (eastBorder) > rightx = width-3; > > g.drawLine(x,y,width,y); > g.drawLine(leftx,y+2,rightx,y+2); > } > > if (eastBorder && > eastBorderType == HSSFCellStyle.BORDER_DOUBLE > ) { > > int thickness = getThickness(eastBorderType); > thickness++; //need for dotted borders to show up east > > g.setColor(eastColor); > > int topy=y; > int bottomy=height; > > if (northBorder) > topy=y+3; > > if (southBorder) > bottomy=height-3; > > g.drawLine(width-1,y,width-1,height); > g.drawLine(width-3,topy,width-3,bottomy); > } > > if (southBorder && > southBorderType == HSSFCellStyle.BORDER_DOUBLE > ) { > > g.setColor(southColor); > > int leftx=y; > int rightx=width; > > if (westBorder) > leftx=x+3; > > if (eastBorder) > rightx=width-3; > > > g.drawLine(x,height - 1,width,height - 1); > g.drawLine(leftx,height - 3,rightx,height - 3); > } > > if (westBorder && > westBorderType == HSSFCellStyle.BORDER_DOUBLE > ) { > > int thickness = getThickness(westBorderType); > // thickness++; > > g.setColor(westColor); > > int topy=y; > int bottomy=height-3; > > if (northBorder) > topy=y+2; > > if (southBorder) > bottomy=height-3; > > g.drawLine(x,y,x,height); > g.drawLine(x+2,topy,x+2,bottomy); > } > } > > > private void paintDashDotDotBorders(Graphics g, int x, int y, int width, > int height) { > if (northBorder && > ((northBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || > (northBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) > ) { > int thickness = getThickness(northBorderType); > > g.setColor(northColor); > for (int l=x; l < width;) { > l=l+drawDashDotDot(g, l, y, thickness, true, true); > } > > } > > if (eastBorder && > ((eastBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || > (eastBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) > ) { > > int thickness = getThickness(eastBorderType); > > g.setColor(eastColor); > > for (int l=y;l < height;) { > //System.err.println("drawing east"); > l=l+drawDashDotDot(g,width-1,l,thickness,false,false); > } > } > > if (southBorder && > ((southBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || > (southBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) > ) { > > int thickness = getThickness(southBorderType); > > g.setColor(southColor); > > for (int l=x; l < width;) { > //System.err.println("drawing south"); > l=l+drawDashDotDot(g, l, height-1, thickness, true, false); > } > } > > if (westBorder && > ((westBorderType == HSSFCellStyle.BORDER_DASH_DOT_DOT) || > (westBorderType == HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT)) > ) { > > int thickness = getThickness(westBorderType); > > g.setColor(westColor); > > for (int l=y;l < height;) { > //System.err.println("drawing west"); > l=l+drawDashDotDot(g,x,l,thickness,false,true); > } > > } > } > > /** > * Draws one dash dot dot horizontally or vertically with thickness drawn > * incrementally to either the right or left. > * > * @param g graphics object for drawing with > * @param x the x origin of the line > * @param y the y origin of the line > * @param thickness the thickness of the line > * @param horizontal or vertical (true for horizontal) > * @param right/bottom or left/top thickness (true for right or top), > * if true then the x or y origin will be incremented to provide > * thickness, if false, they'll be decremented. For vertical > * borders, x is incremented or decremented, for horizontal its y. > * Just set to true for north and west, and false for east and > * south. > * @returns length - returns the length of the line. > */ > private int drawDashDotDot(Graphics g,int x, int y, int thickness, > boolean horizontal, > boolean rightBottom) { > > for (int t=0; t < thickness; t++) { > if (!rightBottom) { > t = 0 - t; //add negative thickness so we go the other way > //then we'll decrement instead of increment. > } > if (horizontal) { > g.drawLine(x,y+t,x+5,y+t); > g.drawLine(x+8,y+t,x+10,y+t); > g.drawLine(x+13,y+t,x+15,y+t); > } else { > g.drawLine(x+t,y,x+t,y+5); > g.drawLine(x+t,y+8,x+t,y+10); > g.drawLine(x+t,y+13,x+t,y+15); > } > } > return 18; > } > > 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_DASHED: > retval=1; > break; > case HSSFCellStyle.BORDER_DASH_DOT_DOT: > retval=1; > break; > case HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT: > retval=3; > break; > case HSSFCellStyle.BORDER_HAIR: > retval=1; > break; > default: > retval=1; > } > return retval; > } > > > } Index: view/SVTableCellRenderer.java =================================================================== RCS file: /home/cvspublic/jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellRenderer.java,v retrieving revision 1.6 diff -r1.6 SVTableCellRenderer.java 69a70 > import java.text.*; 71,76c72 < import org.apache.poi.hssf.usermodel.HSSFWorkbook; < import org.apache.poi.hssf.usermodel.HSSFSheet; < import org.apache.poi.hssf.usermodel.HSSFRow; < import org.apache.poi.hssf.usermodel.HSSFCell; < import org.apache.poi.hssf.usermodel.HSSFCellStyle; < import org.apache.poi.hssf.usermodel.HSSFFont; --- > import org.apache.poi.hssf.usermodel.*; 78c74 < import org.apache.poi.hssf.util.HSSFColor.WHITE; --- > 89a86,88 > private static final Color black = getAWTColor(new HSSFColor.BLACK()); > private static final Color white = getAWTColor(new HSSFColor.WHITE()); > 90a90,92 > protected SVBorder cellBorder = new SVBorder(); > > 93a96,154 > /* private class CellFormatter { > private Format[] textFormatters; > private Color[] negativeColour; > > public CellFormatter() { > textFormatters = new Format[0x31]; > negativeColour = new Color[0x31]; > for (int i=0;i negativeColour = Color.BLACK; > > textFormatter[0x01] = new DecimalFormat("0"); > textFormatter[0x02] = new DecimalFormat("0.00"); > textFormatter[0x03] = new DecimalFormat("#,##0"); > textFormatter[0x04] = new DecimalFormat("#,##0.00"); > textFormatter[0x05] = new DecimalFormat("($#,##0_);($#,##0)"); > textFormatter[0x06] = new DecimalFormat("($#,##0_);[Red]($#,##0)"); > textFormatter[0x07] = new DecimalFormat("($#,##0.00);($#,##0.00)"); > textFormatter[0x08] = new DecimalFormat("($#,##0.00_);[Red]($#,##0.00)"); > textFormatter[0x09] = new DecimalFormat("0%"); > textFormatter[0x0A] = new DecimalFormat("0.00%"); > textFormatter[0x0B] = new DecimalFormat("0.00E+00"); > textFormatter[0x0C] = new SimpleDateFormat("# ?/?"); > textFormatter[0x0D] = new SimpleDateFormat("# ??/??"); > textFormatter[0x0E] = new SimpleDateFormat("m/d/yy"); > textFormatter[0x0F] = new SimpleDateFormat("d-mmm-yy"); > textFormatter[0x10] = new SimpleDateFormat("d-mmm"); > textFormatter[0x11] = new SimpleDateFormat("mmm-yy"); > textFormatter[0x12] = new SimpleDateFormat("h:mm AM/PM"); > textFormatter[0x13] = new SimpleDateFormat("h:mm:ss AM/PM"); > textFormatter[0x14] = new SimpleDateFormat("h:mm"); > textFormatter[0x15] = new SimpleDateFormat("h:mm:ss"); > textFormatter[0x16] = new SimpleDateFormat("m/d/yy h:mm"); > // 0x17 - 0x24 reserved for international and undocumented 0x25, "(#,##0_);(#,##0)" > //start at 0x26 > textFormatter[0x26] = new DecimalFormat("(#,##0_);[Red](#,##0)"); > textFormatter[0x27] = new DecimalFormat("(#,##0.00_);(#,##0.00)"); > textFormatter[00x28] = new DecimalFormat("(#,##0.00_);[Red](#,##0.00)"); > textFormatter[0x29] = new DecimalFormat("_(*#,##0_);_(*(#,##0);_(* \"-\"_);_(@_)"); > textFormatter[0x2A] = new DecimalFormat("_($*#,##0_);_($*(#,##0);_($* \"-\"_);_(@_)"); > textFormatter[0x2B] = new DecimalFormat("_(*#,##0.00_);_(*(#,##0.00);_(*\"-\"??_);_(@_)"); > textFormatter[0x2C] = new DecimalFormat("_($*#,##0.00_);_($*(#,##0.00);_($*\"-\"??_);_(@_)"); > textFormatter[0x2D] = new SimpleDateFormat("mm:ss"); > textFormatter[0x2E] = new SimpleDateFormat("[h]:mm:ss"); > textFormatter[0x2F] = new SimpleDateFormat("mm:ss.0"); > textFormatter[0x30] = new DecimalFormat("##0.0E+0"); > } > > public String format(short index, Object value) { > > } > > public String format(short index, double value) { > > } > } > > private static final CellFormatter cellFormatter = new CellFormatter(); > */ > 105,109d165 < if (isSelected) { < setForeground(table.getSelectionForeground()); < setBackground(table.getSelectionBackground()); < } < 115d170 < 131,132c186 < < HSSFColor clr = null; --- > 134,152c188,224 < clr = (HSSFColor)colors.get(new Integer(s.getFillForegroundColor())); < } < if (clr == null) clr = new HSSFColor.WHITE(); < < short[] rgb = clr.getTriplet(); < Color awtcolor = new Color(rgb[0],rgb[1],rgb[2]); < < setBackground(awtcolor); < < clr = (HSSFColor)colors.get(new Integer(f.getColor())); < if (clr == null) clr = new HSSFColor.BLACK(); < 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) { --- > setBackground(getAWTColor(s.getFillForegroundColor(), white)); > } else setBackground(white); > > setForeground(getAWTColor(f.getColor(), black)); > > cellBorder.setBorder(getAWTColor(s.getTopBorderColor(), black), > getAWTColor(s.getRightBorderColor(), black), > getAWTColor(s.getBottomBorderColor(), black), > getAWTColor(s.getLeftBorderColor(), black), > s.getBorderTop(), s.getBorderRight(), > s.getBorderBottom(), s.getBorderLeft(), > hasFocus); > setBorder(cellBorder); > isBorderSet=true; > > //Set the value that is rendered for the cell > switch (c.getCellType()) { > case HSSFCell.CELL_TYPE_BLANK: > setValue(""); > break; > case HSSFCell.CELL_TYPE_BOOLEAN: > if (c.getBooleanCellValue()) { > setValue("true"); > } else { > setValue("false"); > } > break; > case HSSFCell.CELL_TYPE_FORMULA: > case HSSFCell.CELL_TYPE_NUMERIC: > setValue(Double.toString(c.getNumericCellValue())); > /* short format = s.getDataFormat(); > if (format == 40) { > String formatStr = HSSFDataFormat.getFormat(format); > System.out.println("Format Str="+formatStr); > java.text.DecimalFormat frm = new java.text.DecimalFormat(formatStr); > System.out.println("Formatted value = "+frm.format(c.getNumericCellValue())); > } 154,217c226,255 < int borderTop = s.getBorderTop(); < int borderRight = s.getBorderRight(); < int borderBottom = s.getBorderBottom(); < int borderLeft = s.getBorderLeft(); < < //OUCH! This could causing rendering performance problems. < //Need to somehow create once and store < 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; < < //Set the value that is rendered for the cell < switch (c.getCellType()) { < case HSSFCell.CELL_TYPE_BLANK: < setValue(""); < break; < case HSSFCell.CELL_TYPE_BOOLEAN: < if (c.getBooleanCellValue()) { < setValue("true"); < } else { < setValue("false"); < } < break; < case HSSFCell.CELL_TYPE_FORMULA: < case HSSFCell.CELL_TYPE_NUMERIC: < setValue(""+c.getNumericCellValue()); < break; < case HSSFCell.CELL_TYPE_STRING: < setValue(c.getStringCellValue()); < break; < default: < setValue("?"); < } < //Set the text alignment of the cell < switch (s.getAlignment()) { < case HSSFCellStyle.ALIGN_GENERAL: < case HSSFCellStyle.ALIGN_LEFT: < case HSSFCellStyle.ALIGN_JUSTIFY: < case HSSFCellStyle.ALIGN_FILL: < setHorizontalAlignment(SwingConstants.LEFT); < break; < case HSSFCellStyle.ALIGN_CENTER: < case HSSFCellStyle.ALIGN_CENTER_SELECTION: < setHorizontalAlignment(SwingConstants.CENTER); < break; < case HSSFCellStyle.ALIGN_RIGHT: < setHorizontalAlignment(SwingConstants.RIGHT); < break; < default: < setHorizontalAlignment(SwingConstants.LEFT); < break; < } < // } < } else { < setValue(""); < setBackground(Color.white); < } --- > break; > case HSSFCell.CELL_TYPE_STRING: > setValue(c.getStringCellValue()); > break; > default: > setValue("?"); > } > //Set the text alignment of the cell > switch (s.getAlignment()) { > case HSSFCellStyle.ALIGN_GENERAL: > case HSSFCellStyle.ALIGN_LEFT: > case HSSFCellStyle.ALIGN_JUSTIFY: > case HSSFCellStyle.ALIGN_FILL: > setHorizontalAlignment(SwingConstants.LEFT); > break; > case HSSFCellStyle.ALIGN_CENTER: > case HSSFCellStyle.ALIGN_CENTER_SELECTION: > setHorizontalAlignment(SwingConstants.CENTER); > break; > case HSSFCellStyle.ALIGN_RIGHT: > setHorizontalAlignment(SwingConstants.RIGHT); > break; > default: > setHorizontalAlignment(SwingConstants.LEFT); > break; > } > } else { > setValue(""); > setBackground(white); > } 222c260,269 < setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") ); --- > cellBorder.setBorder(black, > black, > black, > black, > HSSFCellStyle.BORDER_NONE, > HSSFCellStyle.BORDER_NONE, > HSSFCellStyle.BORDER_NONE, > HSSFCellStyle.BORDER_NONE, > isSelected); > setBorder(cellBorder); 226a274 > System.out.println("PING!"); 237d284 < 241d287 < 265a312,327 > > /** This method retrieves the AWT Color representation from the colour hash table > * > */ > private final Color getAWTColor(int index, Color deflt) { > HSSFColor clr = (HSSFColor)colors.get(new Integer(index)); > if (clr == null) return deflt; > return getAWTColor(clr); > } > > private static final Color getAWTColor(HSSFColor clr) { > short[] rgb = clr.getTriplet(); > return new Color(rgb[0],rgb[1],rgb[2]); > } > >