this should have committed before... dunno why it iddn't
PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352759 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
148afcc96f
commit
d01b6e7db0
@ -87,50 +87,29 @@ import org.apache.poi.hssf.util.HSSFColor.WHITE;
|
|||||||
public class SVTableCellRenderer extends JLabel
|
public class SVTableCellRenderer extends JLabel
|
||||||
implements TableCellRenderer, Serializable
|
implements TableCellRenderer, Serializable
|
||||||
{
|
{
|
||||||
|
|
||||||
protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
|
protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
|
||||||
|
|
||||||
private Color unselFG;
|
|
||||||
private Color unselBG;
|
|
||||||
private HSSFWorkbook wb = null;
|
private HSSFWorkbook wb = null;
|
||||||
private HSSFSheet st = null;
|
|
||||||
private Hashtable colors = HSSFColor.getIndexHash();
|
private Hashtable colors = HSSFColor.getIndexHash();
|
||||||
|
|
||||||
public SVTableCellRenderer(HSSFWorkbook wb, HSSFSheet st) {
|
public SVTableCellRenderer(HSSFWorkbook wb) {
|
||||||
super();
|
super();
|
||||||
setOpaque(true);
|
setOpaque(true);
|
||||||
setBorder(noFocusBorder);
|
setBorder(noFocusBorder);
|
||||||
this.wb = wb;
|
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,
|
public Component getTableCellRendererComponent(JTable table, Object value,
|
||||||
boolean isSelected, boolean hasFocus, int row, int column) {
|
boolean isSelected, boolean hasFocus, int row, int column) {
|
||||||
|
|
||||||
boolean isBorderSet = false;
|
boolean isBorderSet = false;
|
||||||
|
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
super.setForeground(table.getSelectionForeground());
|
setForeground(table.getSelectionForeground());
|
||||||
super.setBackground(table.getSelectionBackground());
|
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) {
|
if (c != null) {
|
||||||
|
|
||||||
@ -139,7 +118,7 @@ public class SVTableCellRenderer extends JLabel
|
|||||||
boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
|
boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
|
||||||
boolean isitalics = f.getItalic();
|
boolean isitalics = f.getItalic();
|
||||||
|
|
||||||
int fontstyle = 0;
|
int fontstyle = Font.PLAIN;
|
||||||
|
|
||||||
if (isbold) fontstyle = Font.BOLD;
|
if (isbold) fontstyle = Font.BOLD;
|
||||||
if (isitalics) fontstyle = fontstyle | Font.ITALIC;
|
if (isitalics) fontstyle = fontstyle | Font.ITALIC;
|
||||||
@ -150,7 +129,6 @@ public class SVTableCellRenderer extends JLabel
|
|||||||
Font font = new Font(f.getFontName(),fontstyle,fontheight);
|
Font font = new Font(f.getFontName(),fontstyle,fontheight);
|
||||||
setFont(font);
|
setFont(font);
|
||||||
|
|
||||||
|
|
||||||
HSSFColor clr = null;
|
HSSFColor clr = null;
|
||||||
if (s.getFillPattern() == HSSFCellStyle.SOLID_FOREGROUND) {
|
if (s.getFillPattern() == HSSFCellStyle.SOLID_FOREGROUND) {
|
||||||
clr = (HSSFColor)colors.get(new Integer(s.getFillForegroundColor()));
|
clr = (HSSFColor)colors.get(new Integer(s.getFillForegroundColor()));
|
||||||
@ -178,6 +156,8 @@ public class SVTableCellRenderer extends JLabel
|
|||||||
int borderBottom = s.getBorderBottom();
|
int borderBottom = s.getBorderBottom();
|
||||||
int borderLeft = s.getBorderLeft();
|
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,
|
SVBorder border = new SVBorder(Color.black, Color.black,
|
||||||
Color.black, Color.black,
|
Color.black, Color.black,
|
||||||
borderTop, borderRight,
|
borderTop, borderRight,
|
||||||
@ -189,25 +169,7 @@ public class SVTableCellRenderer extends JLabel
|
|||||||
setBorder(border);
|
setBorder(border);
|
||||||
isBorderSet=true;
|
isBorderSet=true;
|
||||||
|
|
||||||
// }
|
//Set the value that is rendered for the cell
|
||||||
} 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) {
|
|
||||||
switch (c.getCellType()) {
|
switch (c.getCellType()) {
|
||||||
case HSSFCell.CELL_TYPE_BLANK:
|
case HSSFCell.CELL_TYPE_BLANK:
|
||||||
setValue("");
|
setValue("");
|
||||||
@ -229,11 +191,44 @@ public class SVTableCellRenderer extends JLabel
|
|||||||
default:
|
default:
|
||||||
setValue("?");
|
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 {
|
} else {
|
||||||
setValue("");
|
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 ----
|
// ---- begin optimization to avoid painting background ----
|
||||||
Color back = getBackground();
|
Color back = getBackground();
|
||||||
boolean colorMatch = (back != null) && ( back.equals(table.getBackground()) ) && table.isOpaque();
|
boolean colorMatch = (back != null) && ( back.equals(table.getBackground()) ) && table.isOpaque();
|
||||||
@ -261,7 +256,6 @@ public class SVTableCellRenderer extends JLabel
|
|||||||
|
|
||||||
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) { }
|
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) { }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the string to either the value or "" if the value is null.
|
* Sets the string to either the value or "" if the value is null.
|
||||||
*
|
*
|
||||||
@ -269,16 +263,4 @@ public class SVTableCellRenderer extends JLabel
|
|||||||
protected void setValue(Object value) {
|
protected void setValue(Object value) {
|
||||||
setText((value == null) ? "" : value.toString());
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -78,13 +78,11 @@ import org.apache.poi.hssf.usermodel.HSSFCell;
|
|||||||
*
|
*
|
||||||
* @author Andrew C. Oliver
|
* @author Andrew C. Oliver
|
||||||
*/
|
*/
|
||||||
public class SViewer extends Applet {
|
public class SViewer extends JApplet {
|
||||||
|
private SViewerPanel panel;
|
||||||
boolean isStandalone = false;
|
boolean isStandalone = false;
|
||||||
String filename = null;
|
String filename = null;
|
||||||
BorderLayout borderLayout = new BorderLayout();
|
|
||||||
JScrollPane mainScrollPane = new JScrollPane();
|
|
||||||
JTable mainTable = new JTable();
|
|
||||||
URLConnection uc = null;
|
|
||||||
/**Get a parameter value*/
|
/**Get a parameter value*/
|
||||||
public String getParameter(String key, String def) {
|
public String getParameter(String key, String def) {
|
||||||
return isStandalone ? System.getProperty(key, def) :
|
return isStandalone ? System.getProperty(key, def) :
|
||||||
@ -94,6 +92,7 @@ public class SViewer extends Applet {
|
|||||||
/**Construct the applet*/
|
/**Construct the applet*/
|
||||||
public SViewer() {
|
public SViewer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Initialize the applet*/
|
/**Initialize the applet*/
|
||||||
public void init() {
|
public void init() {
|
||||||
try {
|
try {
|
||||||
@ -103,6 +102,7 @@ public class SViewer extends Applet {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Component initialization*/
|
/**Component initialization*/
|
||||||
private void jbInit() throws Exception {
|
private void jbInit() throws Exception {
|
||||||
InputStream i = null;
|
InputStream i = null;
|
||||||
@ -121,16 +121,9 @@ public class SViewer extends Applet {
|
|||||||
} else {
|
} else {
|
||||||
wb = constructWorkbook(filename);
|
wb = constructWorkbook(filename);
|
||||||
}
|
}
|
||||||
|
panel = new SViewerPanel(wb);
|
||||||
HSSFSheet st = wb.getSheetAt(0);
|
getContentPane().setLayout(new BorderLayout());
|
||||||
SVTableModel tm = constructTableModel(wb,st);
|
getContentPane().add(panel, BorderLayout.CENTER);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private HSSFWorkbook constructWorkbook(String filename) {
|
private HSSFWorkbook constructWorkbook(String filename) {
|
||||||
@ -159,18 +152,6 @@ public class SViewer extends Applet {
|
|||||||
return wb;
|
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*/
|
/**Start the applet*/
|
||||||
public void start() {
|
public void start() {
|
||||||
}
|
}
|
||||||
@ -197,9 +178,7 @@ public class SViewer extends Applet {
|
|||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
URL url = new URL(urlstring);
|
URL url = new URL(urlstring);
|
||||||
uc = url.openConnection();
|
is = url.openStream();
|
||||||
uc.connect();
|
|
||||||
is = uc.getInputStream();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user