? view/SVFractionalFormat.java ? view/SVTableCellEditor.java ? view/SVTableUtils.java ? view/SVRowHeader.java 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.7 diff -w -r1.7 SVTableCellRenderer.java 86,88d85 < private static final Color black = getAWTColor(new HSSFColor.BLACK()); < private static final Color white = getAWTColor(new HSSFColor.WHITE()); < 94d90 < private Hashtable colors = HSSFColor.getIndexHash(); 117,118c113,114 < //?? textFormatter[0x0C] = new DecimalFormat("# ?/?"); < //?? textFormatter[0x0D] = new DecimalFormat("# ??/??"); --- > textFormatter[0x0C] = new SVFractionalFormat("# ?/?"); > textFormatter[0x0D] = new SVFractionalFormat("# ??/??"); 163c159,162 < else throw new RuntimeException("Sorry. I cant handle a non decimal formatter for a decimal value :"+Integer.toHexString(index)); --- > if (textFormatter[index] instanceof SVFractionalFormat) { > return ((SVFractionalFormat)textFormatter[index]).format(value); > } > throw new RuntimeException("Sorry. I cant handle a non decimal formatter for a decimal value :"+Integer.toHexString(index)); 191,203c190 < boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL; < boolean isitalics = f.getItalic(); < < int fontstyle = Font.PLAIN; < < 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 < < Font font = new Font(f.getFontName(),fontstyle,fontheight); < setFont(font); --- > setFont(SVTableUtils.makeFont(f)); 206,207c193,194 < setBackground(getAWTColor(s.getFillForegroundColor(), white)); < } else setBackground(white); --- > setBackground(SVTableUtils.getAWTColor(s.getFillForegroundColor(), SVTableUtils.white)); > } else setBackground(SVTableUtils.white); 209c196 < setForeground(getAWTColor(f.getColor(), black)); --- > setForeground(SVTableUtils.getAWTColor(f.getColor(), SVTableUtils.black)); 211,214c198,201 < cellBorder.setBorder(getAWTColor(s.getTopBorderColor(), black), < getAWTColor(s.getRightBorderColor(), black), < getAWTColor(s.getBottomBorderColor(), black), < getAWTColor(s.getLeftBorderColor(), black), --- > cellBorder.setBorder(SVTableUtils.getAWTColor(s.getTopBorderColor(), SVTableUtils.black), > SVTableUtils.getAWTColor(s.getRightBorderColor(), SVTableUtils.black), > SVTableUtils.getAWTColor(s.getBottomBorderColor(), SVTableUtils.black), > SVTableUtils.getAWTColor(s.getLeftBorderColor(), SVTableUtils.black), 233d219 < case HSSFCell.CELL_TYPE_FORMULA: 244a231 > case HSSFCell.CELL_TYPE_FORMULA: 269c256 < setBackground(white); --- > setBackground(SVTableUtils.white); 275,278c262,267 < cellBorder.setBorder(black, < black, < black, < black, --- > //This is the border to paint when there is no border > //and the cell has focus > cellBorder.setBorder(SVTableUtils.black, > SVTableUtils.black, > SVTableUtils.black, > SVTableUtils.black, 326,341d314 < < /** 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]); < } < < Index: view/SVTableModel.java =================================================================== RCS file: /home/cvspublic/jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SVTableModel.java,v retrieving revision 1.3 diff -w -r1.3 SVTableModel.java 111a112,121 > public boolean isCellEditable(int rowIndex, int columnIndex) { > return true; > } > > public void setValueAt(Object aValue, int rowIndex, int columnIndex) { > if (aValue != null) > System.out.println("SVTableModel.setValueAt. value type = "+aValue.getClass().getName()); > else System.out.println("SVTableModel.setValueAt. value type = null"); > } > Index: view/SViewer.java =================================================================== RCS file: /home/cvspublic/jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SViewer.java,v retrieving revision 1.4 diff -w -r1.4 SViewer.java 61,62c61 < import java.net.URL; < import java.net.URLConnection; --- > import java.net.*; 64,65c63 < import java.io.InputStream; < import java.io.FileInputStream; --- > import java.io.*; 102a101 > System.exit(1); 124c123 < panel = new SViewerPanel(wb); --- > panel = new SViewerPanel(wb, false); 129c128 < private HSSFWorkbook constructWorkbook(String filename) { --- > private HSSFWorkbook constructWorkbook(String filename) throws FileNotFoundException, IOException { 131,132d129 < < try { 136,138d132 < } catch (Exception e) { < e.printStackTrace(); < } 142c136 < private HSSFWorkbook constructWorkbook(InputStream in) { --- > private HSSFWorkbook constructWorkbook(InputStream in) throws IOException { 145d138 < try { 148,151d140 < < } catch (Exception e) { < e.printStackTrace(); < } 177,179c166 < private InputStream getXLSFromURL(String urlstring) { < InputStream is = null; < try { --- > private InputStream getXLSFromURL(String urlstring) throws MalformedURLException, IOException { 181,183c168,172 < is = url.openStream(); < } catch (Exception e) { < e.printStackTrace(); --- > URLConnection uc = url.openConnection(); > String field = uc.getHeaderField(0); > for (int i=0;field != null; i++) { > System.out.println(field); > field = uc.getHeaderField(i); 184a174 > BufferedInputStream is = new BufferedInputStream(uc.getInputStream()); Index: view/SViewerPanel.java =================================================================== RCS file: /home/cvspublic/jakarta-poi/src/contrib/src/org/apache/poi/hssf/contrib/view/SViewerPanel.java,v retrieving revision 1.1 diff -w -r1.1 SViewerPanel.java 62a63,64 > import javax.swing.table.*; > import javax.swing.event.*; 64,66c66 < import org.apache.poi.hssf.usermodel.HSSFWorkbook; < import org.apache.poi.hssf.usermodel.HSSFSheet; < import org.apache.poi.hssf.usermodel.HSSFCell; --- > import org.apache.poi.hssf.usermodel.*; 75a76,87 > /** This field is the magic number to convert from a Character width to a > * java pixel width. > * > * When the "normal" font size in a workbook changes, this effects all > * of the heights and widths. Unfortunately there is no way to retrieve this > * information, hence the MAGIC number. > * > * This number may only work for the normal style font size of Arial size 10. > * > */ > private static final int magicCharFactor = 7; > /** Reference to the woorkbook that is being displayed*/ 77c89,100 < private JTable sheets[]; --- > /** Reference to the tabs component*/ > private JTabbedPane sheetPane; > /** Reference to the cell renderer that is used to render all cells*/ > private SVTableCellRenderer cellRenderer; > /** Reference to the cell editor that is used to edit all cells. > * Only constructed if editing is allowed > */ > private SVTableCellEditor cellEditor; > /** Flag indicating if editing is allowed. Otherwise the viewer is in > * view only mode. > */ > private boolean allowEdits; 80c103 < public SViewerPanel(HSSFWorkbook wb) { --- > public SViewerPanel(HSSFWorkbook wb, boolean allowEdits) { 81a105,113 > this.allowEdits = allowEdits; > > initialiseGui(); > } > > private void initialiseGui() { > cellRenderer = new SVTableCellRenderer(this.wb); > if (allowEdits) > cellEditor = new SVTableCellEditor(this.wb); 84c116,119 < JTabbedPane sheetPane = new JTabbedPane(JTabbedPane.BOTTOM); --- > sheetPane = new JTabbedPane(JTabbedPane.BOTTOM); > > if (allowEdits) > sheetPane.addMouseListener(createTabListener()); 86,87d120 < sheets = new JTable[sheetCount]; < SVTableCellRenderer rnd = new SVTableCellRenderer(wb); 90,93d122 < //Construct the view of the sheet < SVTableModel tm = new SVTableModel(wb.getSheetAt(i)); < sheets[i] = new JTable(tm); < sheets[i].setDefaultRenderer(HSSFCell.class, rnd); 95c124 < sheetPane.addTab(sheetName, new JScrollPane(sheets[i])); --- > sheetPane.addTab(sheetName, makeSheetView(wb.getSheetAt(i))); 100a130,171 > protected JComponent makeSheetView(HSSFSheet sheet) { > JTable sheetView = new JTable(new SVTableModel(sheet)); > sheetView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); > sheetView.setDefaultRenderer(HSSFCell.class, cellRenderer); > if (allowEdits) > sheetView.setDefaultEditor(HSSFCell.class, cellEditor); > JTableHeader header = sheetView.getTableHeader(); > //Dont allow column reordering > header.setReorderingAllowed(false); > //Only allow column resizing if editing is allowed > header.setResizingAllowed(allowEdits); > > //Set the columns the correct size > TableColumnModel columns = sheetView.getColumnModel(); > for (int i=0; i< columns.getColumnCount(); i++) { > TableColumn column = columns.getColumn(i); > short width = sheet.getColumnWidth((short)i); > //256 is because the width is in 256ths of a character > column.setPreferredWidth(width/256*magicCharFactor); > } > > //Set the rows to the correct size > int rows = sheet.getPhysicalNumberOfRows(); > Insets insets = cellRenderer.getInsets(); > //Need to include the insets in the calculation of the row height to use. > int extraHeight = insets.bottom+insets.top; > for (int i=0; i< rows; i++) { > HSSFRow row = sheet.getRow(i); > if (row == null) { > sheetView.setRowHeight(i, (int)sheet.getDefaultRowHeightInPoints()+extraHeight); > } else { > sheetView.setRowHeight(i, (int)row.getHeightInPoints()+extraHeight); > } > } > > //Add the row header to the sheet > SVRowHeader rowHeader = new SVRowHeader(sheet, sheetView, extraHeight); > JScrollPane scroll = new JScrollPane( sheetView ); > scroll.setRowHeaderView(rowHeader); > return scroll; > } > 101a173 > //JMH I am only overriding this to get a picture of the time taken to paint 107a180,296 > protected MouseListener createTabListener() { > return new TabListener(); > } > > /** This class defines the default MouseListener that listens to > * mouse events in the tabbed pane > * > * The default is to popup a menu when the event occurs over a tab > */ > private class TabListener implements MouseListener { > public JPopupMenu popup; > public TabListener() { > popup = new JPopupMenu("Sheet"); > popup.add(createInsertSheetAction()); > popup.add(createDeleteSheetAction()); > popup.add(createRenameSheetAction()); > } > > protected Action createInsertSheetAction() { > return new InsertSheetAction(); > } > > protected Action createDeleteSheetAction() { > return new DeleteSheetAction(); > } > > protected Action createRenameSheetAction() { > return new RenameSheetAction(); > } > > > /** This method will display the popup if the mouseevent is a popup event > * and the event occurred over a tab > */ > protected void checkPopup(MouseEvent e) { > if (e.isPopupTrigger()) { > int tab = sheetPane.getUI().tabForCoordinate(sheetPane, e.getX(), e.getY()); > if (tab != -1) { > popup.show(sheetPane, e.getX(), e.getY()); > } > } > } > > public void mouseClicked(MouseEvent e) { > checkPopup(e); > } > > public void mousePressed(MouseEvent e) { > checkPopup(e); > } > > public void mouseReleased(MouseEvent e) { > checkPopup(e); > } > > public void mouseEntered(MouseEvent e) {} > public void mouseExited(MouseEvent e) {} > } > > /** This class defines the action that is performed when the sheet is renamed*/ > private class RenameSheetAction extends AbstractAction { > public RenameSheetAction() { > super("Rename"); > } > > public void actionPerformed(ActionEvent e) { > int tabIndex = sheetPane.getSelectedIndex(); > if (tabIndex != -1) { > String newSheetName = (String)JOptionPane.showInputDialog(sheetPane, "Enter a new Sheetname", "Rename Sheet", JOptionPane.QUESTION_MESSAGE); > if (newSheetName != null) { > wb.setSheetName(tabIndex, newSheetName); > sheetPane.setTitleAt(tabIndex, newSheetName); > } > } > } > } > > /** This class defines the action that is performed when a sheet is inserted*/ > private class InsertSheetAction extends AbstractAction { > public InsertSheetAction() { > super("Insert"); > } > > public void actionPerformed(ActionEvent e) { > //Create a new sheet then search for the sheet and make sure that the > //sheetPane shows it. > HSSFSheet newSheet = wb.createSheet(); > for (int i=0; i HSSFSheet sheet = wb.getSheetAt(i); > if (newSheet == sheet) { > sheetPane.insertTab(wb.getSheetName(i), null, makeSheetView(sheet), null, i); > } > } > } > } > > /** This class defines the action that is performed when the sheet is deleted*/ > private class DeleteSheetAction extends AbstractAction { > public DeleteSheetAction() { > super("Delete"); > } > > public void actionPerformed(ActionEvent e) { > int tabIndex = sheetPane.getSelectedIndex(); > if (tabIndex != -1) { > if (JOptionPane.showConfirmDialog(sheetPane, "Are you sure that you want to delete the selected sheet", "Delete Sheet?", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { > wb.removeSheetAt(tabIndex); > sheetPane.remove(tabIndex); > } > } > } > } > > public boolean isEditable() { > return allowEdits; > } > 115c304 < SViewerPanel p = new SViewerPanel(wb); --- > SViewerPanel p = new SViewerPanel(wb, true); 131c320 < frame.setSize(400,320); --- > frame.setSize(800,640);