1 2 17 18 19 20 package org.apache.poi.hssf.contrib.view; 21 22 import java.awt.*; 23 import java.awt.event.*; 24 import java.io.*; 25 import javax.swing.*; 26 import javax.swing.table.*; 27 import javax.swing.event.*; 28 29 import org.apache.poi.hssf.usermodel.*; 30 31 37 public class SVRowHeader extends JList { 38 42 private class SVRowHeaderModel extends AbstractListModel { 43 private HSSFSheet sheet; 44 45 public SVRowHeaderModel(HSSFSheet sheet) { 46 this.sheet = sheet; 47 } 48 49 public int getSize() { return sheet.getPhysicalNumberOfRows(); } 50 public Object getElementAt(int index) { 51 return Integer.toString(index+1); 52 } 53 } 54 55 56 private class RowHeaderRenderer extends JLabel implements ListCellRenderer { 57 private HSSFSheet sheet; 58 private int extraHeight; 59 60 RowHeaderRenderer(HSSFSheet sheet, JTable table, int extraHeight) { 61 this.sheet = sheet; 62 this.extraHeight = extraHeight; 63 JTableHeader header = table.getTableHeader(); 64 setOpaque(true); 65 setBorder(UIManager.getBorder("TableHeader.cellBorder")); 66 setHorizontalAlignment(CENTER); 67 setForeground(header.getForeground()); 68 setBackground(header.getBackground()); 69 setFont(header.getFont()); 70 } 71 72 public Component getListCellRendererComponent( JList list, 73 Object value, int index, boolean isSelected, boolean cellHasFocus) { 74 Dimension d = getPreferredSize(); 75 int rowHeight = (int)sheet.getRow(index).getHeightInPoints(); 76 d.height = rowHeight+extraHeight; 77 setPreferredSize(d); 78 setText((value == null) ? "" : value.toString()); 79 return this; 80 } 81 } 82 83 public SVRowHeader(HSSFSheet sheet, JTable table, int extraHeight) { 84 ListModel lm = new SVRowHeaderModel(sheet); 85 this.setModel(lm); 86 87 setFixedCellWidth(50); 88 setCellRenderer(new RowHeaderRenderer(sheet, table, extraHeight)); 89 } 90 } 91 | Popular Tags |