added minimal border support to sucky viewer (currently just ON or OFF)
PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352716 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
63cfe59acc
commit
d23edd5bd1
@ -0,0 +1,94 @@
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -123,6 +123,8 @@ public class SVTableCellRenderer extends JLabel
|
||||
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 @@ public class SVTableCellRenderer extends JLabel
|
||||
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
|
||||
|
||||
Font font = new Font(f.getFontName(),fontstyle,f.getFontHeightInPoints());
|
||||
// System.out.println("fontsizeinpnts="+f.getFontHeightInPoints());
|
||||
|
||||
Font font = new Font(f.getFontName(),fontstyle,fontheight);
|
||||
setFont(font);
|
||||
|
||||
|
||||
@ -160,16 +168,56 @@ public class SVTableCellRenderer extends JLabel
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user