acoliver    2002/07/05 11:22:05

  Modified:    src/contrib/src/org/apache/poi/hssf/contrib/view
                        SVTableCellRenderer.java SViewer.java
  Log:
  this should have committed before... dunno why it iddn't
  
  Revision  Changes    Path
  1.6       +43 -61    
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SVTableCellRenderer.java  4 Jul 2002 04:47:21 -0000       1.5
  +++ SVTableCellRenderer.java  5 Jul 2002 18:22:05 -0000       1.6
  @@ -87,50 +87,29 @@
   public class SVTableCellRenderer extends JLabel
       implements TableCellRenderer, Serializable
   {
  -
       protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
  -
  -    private Color unselFG;
  -    private Color unselBG;
       private HSSFWorkbook wb = null;
  -    private HSSFSheet    st = null;
       private Hashtable colors = HSSFColor.getIndexHash();
   
  -    public SVTableCellRenderer(HSSFWorkbook wb, HSSFSheet st) {
  +    public SVTableCellRenderer(HSSFWorkbook wb) {
        super();
        setOpaque(true);
           setBorder(noFocusBorder);
           this.wb = wb;
  -        this.st = st;
  -    }
  -
  -    public void setForeground(Color c) {
  -        super.setForeground(c);
  -        unselFG = c;
  -    }
  -
  -    public void setBackground(Color c) {
  -        super.setBackground(c);
  -        unselBG = c;
  -    }
  -
  -    public void updateUI() {
  -        super.updateUI();
  -     setForeground(null);
  -     setBackground(null);
       }
   
       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());
  +        setForeground(table.getSelectionForeground());
  +        setBackground(table.getSelectionBackground());
        }
   
  -        HSSFCell c = getCell(row,column);
  +        //If the JTables default cell renderer has been setup correctly the
  +        //value will be the HSSFCell that we are trying to render
  +        HSSFCell c = (HSSFCell)value;
   
           if (c != null) {
   
  @@ -139,7 +118,7 @@
             boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
             boolean isitalics = f.getItalic();
   
  -          int fontstyle = 0;
  +          int fontstyle = Font.PLAIN;
   
             if (isbold) fontstyle = Font.BOLD;
             if (isitalics) fontstyle = fontstyle | Font.ITALIC;
  @@ -150,7 +129,6 @@
             Font font = new Font(f.getFontName(),fontstyle,fontheight);
             setFont(font);
             
  -
             HSSFColor clr = null;
             if (s.getFillPattern() == HSSFCellStyle.SOLID_FOREGROUND) {
               clr = (HSSFColor)colors.get(new Integer(s.getFillForegroundColor()));
  @@ -178,6 +156,8 @@
                 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,
  @@ -189,25 +169,7 @@
                 setBorder(border);
                 isBorderSet=true;
   
  -//          }
  -        } else {
  -          setBackground(Color.white);
  -        }
  -
  -
  -     if (hasFocus) {
  -            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 if (!isBorderSet) {
  -         setBorder(noFocusBorder);
  -     }
  -
  -        if (c != null) {
  +              //Set the value that is rendered for the cell
             switch (c.getCellType()) {
               case HSSFCell.CELL_TYPE_BLANK:
                 setValue("");
  @@ -229,11 +191,44 @@
               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);
          }
   
   
  +     if (hasFocus) {
  +            if (!isBorderSet) {
  +             setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
  +            }
  +         if (table.isCellEditable(row, column)) {
  +             setForeground( UIManager.getColor("Table.focusCellForeground") );
  +             setBackground( UIManager.getColor("Table.focusCellBackground") );
  +         }
  +     } else if (!isBorderSet) {
  +         setBorder(noFocusBorder);
  +     }
  +
        // ---- begin optimization to avoid painting background ----
        Color back = getBackground();
        boolean colorMatch = (back != null) && ( back.equals(table.getBackground()) ) 
&& table.isOpaque();
  @@ -261,24 +256,11 @@
   
       public void firePropertyChange(String propertyName, boolean oldValue, boolean 
newValue) { }
   
  -
       /**
        * Sets the string to either the value or "" if the value is null.
        *
        */
       protected void setValue(Object value) {
        setText((value == null) ? "" : value.toString());
  -    }
  -
  -    /**
  -     * Get a cell at a given row  (warning: slow)
  -     *
  -     */
  -    private HSSFCell getCell(int row, int col) {
  -      HSSFRow r = st.getRow(row);
  -      HSSFCell c = null;
  -      if ( r != null)
  -       c = r.getCell((short)col);
  -      return c;
       }
   }
  
  
  
  1.4       +9 -30     
jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SViewer.java
  
  Index: SViewer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SViewer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SViewer.java      23 Jun 2002 19:16:04 -0000      1.3
  +++ SViewer.java      5 Jul 2002 18:22:05 -0000       1.4
  @@ -78,13 +78,11 @@
    *
    * @author Andrew C. Oliver
    */
  -public class SViewer extends Applet {
  +public class SViewer extends JApplet {
  +  private SViewerPanel panel;
     boolean isStandalone = false;
     String filename = null;
  -  BorderLayout borderLayout = new BorderLayout();
  -  JScrollPane mainScrollPane = new JScrollPane();
  -  JTable mainTable = new JTable();
  -  URLConnection uc = null;
  +
     /**Get a parameter value*/
     public String getParameter(String key, String def) {
       return isStandalone ? System.getProperty(key, def) :
  @@ -94,6 +92,7 @@
     /**Construct the applet*/
     public SViewer() {
     }
  +
     /**Initialize the applet*/
     public void init() {
       try {
  @@ -103,6 +102,7 @@
         e.printStackTrace();
       }
     }
  +
     /**Component initialization*/
     private void jbInit() throws Exception {
       InputStream i = null;
  @@ -121,16 +121,9 @@
       } else {
         wb = constructWorkbook(filename);
       }
  -
  -    HSSFSheet    st = wb.getSheetAt(0);
  -    SVTableModel tm = constructTableModel(wb,st);
  -    mainTable.setModel(tm);
  -    SVTableCellRenderer rnd = new SVTableCellRenderer(wb, st);
  -    mainTable.setDefaultRenderer(HSSFCell.class,rnd);
  -
  -    this.setLayout(borderLayout);
  -    this.add(mainScrollPane, BorderLayout.CENTER);
  -    mainScrollPane.getViewport().add(mainTable, null);
  +    panel = new SViewerPanel(wb);
  +    getContentPane().setLayout(new BorderLayout());
  +    getContentPane().add(panel, BorderLayout.CENTER);
     }
   
     private HSSFWorkbook constructWorkbook(String filename) {
  @@ -159,18 +152,6 @@
       return wb;
     }
   
  -
  -  private SVTableModel constructTableModel(HSSFWorkbook wb, HSSFSheet st) {
  -    SVTableModel retval = null;
  -
  -    try {
  -      retval = new SVTableModel(st);
  -    } catch (Exception e) {
  -      e.printStackTrace();
  -    }
  -    return retval;
  -  }
  -
     /**Start the applet*/
     public void start() {
     }
  @@ -197,9 +178,7 @@
     InputStream is = null;
     try {
       URL url = new URL(urlstring);
  -    uc = url.openConnection();
  -    uc.connect();
  -    is = uc.getInputStream();
  +    is = url.openStream();
     } catch (Exception e) {
       e.printStackTrace();
     }
  
  
  

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

Reply via email to