acoliver    2002/07/03 21:47:21

  Modified:    src/contrib/src/org/apache/poi/hssf/contrib/view
                        SVBorder.java SVTableCellRenderer.java
  Log:
  Cleanup, more borders supported
  
  Revision  Changes    Path
  1.2       +144 -24   
jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SVBorder.java
  
  Index: SVBorder.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SVBorder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SVBorder.java     23 Jun 2002 02:54:08 -0000      1.1
  +++ SVBorder.java     4 Jul 2002 04:47:21 -0000       1.2
  @@ -8,6 +8,8 @@
   
   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 @@
      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 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 @@
                              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; 
      }
   
   
  
  
  
  1.5       +14 -28    
jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellRenderer.java
  
  Index: SVTableCellRenderer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableCellRenderer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SVTableCellRenderer.java  23 Jun 2002 14:12:36 -0000      1.4
  +++ SVTableCellRenderer.java  4 Jul 2002 04:47:21 -0000       1.5
  @@ -131,13 +131,14 @@
        }
   
           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 @@
             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 @@
             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 @@
                                              s.getBorderLeft() != 
HSSFCellStyle.BORDER_NONE);
                 setBorder(border);
                 isBorderSet=true;
  -           //need custom border that can have north,east,south,west settings
  -          }
  +
  +//          }
  +        } else {
  +          setBackground(Color.white);
           }
   
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to