KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > contrib > view > SVTableUtils


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18 package org.apache.poi.hssf.contrib.view;
19
20 import java.util.*;
21 import java.awt.*;
22 import javax.swing.border.*;
23
24 import org.apache.poi.hssf.usermodel.*;
25 import org.apache.poi.hssf.util.*;
26
27 /**
28  * SVTableCell Editor and Renderer helper functions.
29  *
30  * @author Jason Height
31  * @since 16 July 2002
32  */

33 public class SVTableUtils {
34   private final static Hashtable colors = HSSFColor.getIndexHash();
35   /** Description of the Field */
36   public final static Color black = getAWTColor(new HSSFColor.BLACK());
37   /** Description of the Field */
38   public final static Color white = getAWTColor(new HSSFColor.WHITE());
39   /** Description of the Field */
40   public static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
41
42
43   /**
44    * Creates a new font for a specific cell style
45    */

46   public static Font makeFont(HSSFFont font) {
47     boolean isbold = font.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
48     boolean isitalics = font.getItalic();
49     int fontstyle = Font.PLAIN;
50     if (isbold) {
51       fontstyle = Font.BOLD;
52     }
53     if (isitalics) {
54       fontstyle = fontstyle | Font.ITALIC;
55     }
56
57     int fontheight = font.getFontHeightInPoints();
58     if (fontheight == 9) {
59       //fix for stupid ol Windows
60
fontheight = 10;
61     }
62
63     return new Font(font.getFontName(), fontstyle, fontheight);
64   }
65
66
67   /**
68    * This method retrieves the AWT Color representation from the colour hash table
69    *
70    * @param index Description of the Parameter
71    * @param deflt Description of the Parameter
72    * @return The aWTColor value
73    */

74   public final static Color getAWTColor(int index, Color deflt) {
75     HSSFColor clr = (HSSFColor) colors.get(new Integer JavaDoc(index));
76     if (clr == null) {
77       return deflt;
78     }
79     return getAWTColor(clr);
80   }
81
82
83   /**
84    * Gets the aWTColor attribute of the SVTableUtils class
85    *
86    * @param clr Description of the Parameter
87    * @return The aWTColor value
88    */

89   public final static Color getAWTColor(HSSFColor clr) {
90     short[] rgb = clr.getTriplet();
91     return new Color(rgb[0], rgb[1], rgb[2]);
92   }
93
94 }
95
Popular Tags