]> source.dussan.org Git - poi.git/commitdiff
Cleanup, more borders supported
authorAndrew C. Oliver <acoliver@apache.org>
Thu, 4 Jul 2002 04:47:21 +0000 (04:47 +0000)
committerAndrew C. Oliver <acoliver@apache.org>
Thu, 4 Jul 2002 04:47:21 +0000 (04:47 +0000)
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

src/contrib/src/org/apache/poi/hssf/contrib/view/SVBorder.java
src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellRenderer.java

index 5522c72f5e226c92a6f78ecbedb3395d5000ec22..124f937a1b46cd0b83347affaad1e7b6a8d1c51e 100644 (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;
@@ -50,44 +52,162 @@ public class SVBorder extends AbstractBorder {
                            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; 
    }
 
 
index 0a09d742da18933c68c765ddd6ac287e1509705b..478548441c41a25711aadc06f80f8b538a527808 100644 (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,31 +168,16 @@ 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,
                                            borderTop, borderRight,
@@ -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);
         }