01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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: * Creates a new font for a specific cell style
44: */
45: public static Font makeFont(HSSFFont font) {
46: boolean isbold = font.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
47: boolean isitalics = font.getItalic();
48: int fontstyle = Font.PLAIN;
49: if (isbold) {
50: fontstyle = Font.BOLD;
51: }
52: if (isitalics) {
53: fontstyle = fontstyle | Font.ITALIC;
54: }
55:
56: int fontheight = font.getFontHeightInPoints();
57: if (fontheight == 9) {
58: //fix for stupid ol Windows
59: fontheight = 10;
60: }
61:
62: return new Font(font.getFontName(), fontstyle, fontheight);
63: }
64:
65: /**
66: * This method retrieves the AWT Color representation from the colour hash table
67: *
68: * @param index Description of the Parameter
69: * @param deflt Description of the Parameter
70: * @return The aWTColor value
71: */
72: public final static Color getAWTColor(int index, Color deflt) {
73: HSSFColor clr = (HSSFColor) colors.get(new Integer(index));
74: if (clr == null) {
75: return deflt;
76: }
77: return getAWTColor(clr);
78: }
79:
80: /**
81: * Gets the aWTColor attribute of the SVTableUtils class
82: *
83: * @param clr Description of the Parameter
84: * @return The aWTColor value
85: */
86: public final static Color getAWTColor(HSSFColor clr) {
87: short[] rgb = clr.getTriplet();
88: return new Color(rgb[0], rgb[1], rgb[2]);
89: }
90:
91: }
|