acoliver    2002/06/22 19:54:08

  Modified:    src/contrib/src/org/apache/poi/hssf/contrib/view
                        SVTableCellRenderer.java
  Added:       src/contrib/src/org/apache/poi/hssf/contrib/view
                        SVBorder.java
  Log:
  added minimal border support to sucky viewer (currently just ON or OFF)
  
  Revision  Changes    Path
  1.3       +51 -3     
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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SVTableCellRenderer.java  22 Jun 2002 20:54:14 -0000      1.2
  +++ SVTableCellRenderer.java  23 Jun 2002 02:54:08 -0000      1.3
  @@ -123,6 +123,8 @@
       public Component getTableCellRendererComponent(JTable table, Object value,
                             boolean isSelected, boolean hasFocus, int row, int 
column) {
   
  +     boolean isBorderSet = false;
  +
        if (isSelected) {
           super.setForeground(table.getSelectionForeground());
           super.setBackground(table.getSelectionBackground());
  @@ -134,13 +136,19 @@
             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;
             if (isitalics) fontstyle = fontstyle | Font.ITALIC;
   
  +          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,f.getFontHeightInPoints());
  +          Font font = new Font(f.getFontName(),fontstyle,fontheight);
             setFont(font);
             
   
  @@ -160,16 +168,56 @@
             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) {
  +              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;
  +              }
  +
  +              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;
  +           //need custom border that can have north,east,south,west settings
  +          }
           }
   
   
        if (hasFocus) {
  -         setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
  +            if (!isBorderSet) {
  +             setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
  +            }
            if (table.isCellEditable(row, column)) {
                super.setForeground( UIManager.getColor("Table.focusCellForeground") );
                super.setBackground( UIManager.getColor("Table.focusCellBackground") );
            }
  -     } else {
  +     } else if (!isBorderSet) {
            setBorder(noFocusBorder);
        }
   
  
  
  
  1.1                  
jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SVBorder.java
  
  Index: SVBorder.java
  ===================================================================
  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;
  
  /**
   * 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 northThickness;
     int eastThickness;
     int southThickness;
     int westThickness;
     boolean northBorder=false;
     boolean eastBorder=false;
     boolean southBorder=false;
     boolean westBorder=false;
  
     public SVBorder(Color northColor, Color eastColor, 
                     Color southColor, Color westColor,
                     int northThickness, int eastThickness,
                     int southThickness, int westThickness, 
                     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.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;
   
        if (northBorder) {
          System.out.println("NorthBorder x="+x+",y="+y+"x1="+width+"y1="+y);
                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);    
     }
  
  
  }
  
  
  

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

Reply via email to