/* * * Copyright (c) 2006 by Know-Center, Graz, Austria * * * This software is the confidential and proprietary information of Know-Center, * Graz, Austria. You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with Know-Center. * * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, * OR NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. * * $Id: Style.java,v 1.3 2006/08/25 17:08:19 wprinz Exp $ */ package at.knowcenter.wag.egov.egiz.table; import java.awt.Color; import java.io.Serializable; /** * This class implements an abstract style definiton used in tables or table entrys. Predefined * values exists for valign and halign. Color definitions uses the native awt color declarations. *
* The predefined keys are used in the setting definition file to style tables and table entries. *
* It provides an static method to inherit style informations from a given style object. * {@link at.knowcenter.wag.egov.egiz.table.Style#doInherit} * * * @author wlackner * @see java.awt.Color */ public class Style implements Serializable { /** * SVUID. */ private static final long serialVersionUID = 5855722896712428387L; /** * valign statement key top */ public final static String TOP = "top"; /** * valign statement key middle */ public final static String MIDDLE = "middle"; /** * valign statement key bottom */ public final static String BOTTOM = "bottom"; /** * halign statement key left */ public final static String LEFT = "left"; /** * halign statement key center */ public final static String CENTER = "center"; /** * halign statement key right */ public final static String RIGHT = "right"; /** * bgcolor key */ public final static String BGCOLOR = "bgcolor"; /** * halign key */ public final static String HALIGN = "halign"; /** * valign key */ public final static String VALIGN = "valign"; /** * padding key, default padding = 1 */ public final static String PADDING = "padding"; /** * border key, default border = 1;
* The border value is one value for all border lines of an entry or table!
* No separte definitions for top, right, bottom or left are possible. */ public final static String BORDER = "border"; /** * Font key */ public final static String FONT = "font"; /** * The value font key. */ public final static String VALUEFONT = "valuefont"; /** * Font name HELVETICA */ public final static String HELVETICA = "HELVETICA"; /** * Font name TIMES_ROMAN */ public final static String TIMES_ROMAN = "TIMES_ROMAN"; /** * Font name COURIER */ public final static String COURIER = "COURIER"; /** * Font type NORMAL */ public final static String NORMAL = "NORMAL"; /** * Font type BOLD */ public final static String BOLD = "BOLD"; /** * Font type ITALIC */ public final static String ITALIC = "ITALIC"; /** * Font type BOLDITALIC */ public final static String BOLDITALIC = "BOLDITALIC"; /** * Font type UNDERLINE */ public final static String UNDERLINE = "UNDERLINE"; /** * Font type STRIKETHRU */ public final static String STRIKETHRU = "STRIKETHRU"; /** * all paddings initialized with the default padding value (1) */ private static final float DEFAULT_PADDING = 1; /** * all borders initialized with the default border value (1) */ private static final float DEFAULT_BORDER = 1; /** * The background color definition. */ private Color bgColor_ = null; /** * The current padding value -> initialized with the default padding value */ private float padding_ = DEFAULT_PADDING; /** * The current halign value -> initialized with left */ private String hAlign_ = LEFT; /** * The current valign value -> initialized with top */ private String vAlign_ = TOP; /** * The current border value -> initialized with the default border value */ private float border_ = DEFAULT_BORDER; /** * The font string of the style definition */ private String font_ = null; /** * The font string of the value font. */ private String valuefont_ = null; /** * The empty constructor. */ public Style() { } /** * Set a style attribute. The style attribute must be one of the public definitions * * @param id the style attribute to set * @param value the style value to set for the given attribute */ public void setStyle(String id, String value) { if (BGCOLOR.equals(id)) { String[] col_strg = value.split(" "); if (col_strg.length == 3) { int r = Integer.parseInt(col_strg[0]); int g = Integer.parseInt(col_strg[1]); int b = Integer.parseInt(col_strg[2]); if (r < 256 && g < 256 && b < 256 && r >= 0 && g >= 0 && b >= 0) { bgColor_ = new Color(r, g, b); } } } if (HALIGN.equals(id)) { if (LEFT.equals(value) || CENTER.equals(value) || RIGHT.equals(value)) { hAlign_ = value; } } if (VALIGN.equals(id)) { if (TOP.equals(value) || MIDDLE.equals(value) || BOTTOM.equals(value)) { vAlign_ = value; } } if (PADDING.equals(id)) { padding_ = Float.parseFloat(value); } if (BORDER.equals(id)) { border_ = Float.parseFloat(value); } if (FONT.equals(id)) { font_ = value; } if (VALUEFONT.equals(id)) { valuefont_ = value; } } /** * @return Returns the bgColor. */ public Color getBgColor() { return bgColor_; } /** * @param bgColor The bgColor to set. */ public void setBgColor(Color bgColor) { bgColor_ = bgColor; } /** * @return Returns the hAlign. */ public String getHAlign() { return hAlign_; } /** * @param align The hAlign to set. */ public void setHAlign(String align) { hAlign_ = align; } /** * @return Returns the padding. */ public float getPadding() { return padding_; } /** * @param padding The padding to set. */ public void setPadding(float padding) { padding_ = padding; } /** * @return Returns the vAlign. */ public String getVAlign() { return vAlign_; } /** * @param align The vAlign to set. */ public void setVAlign(String align) { vAlign_ = align; } /** * @return Returns the border. */ public float getBorder() { return border_; } /** * @param border The border to set. */ public void setBorder(float border) { border_ = border; } /** * @return Returns the font. */ public String getFont() { return font_; } /** * @param font The font to set. */ public void setFont(String font) { font_ = font; } /** * Returns the value font. * @return Returns the value font. */ public String getValueFont() { return valuefont_; } /** * Sets the value font. * @param valuefont The value font to be set. */ public void setValueFont(String valuefont) { this.valuefont_ = valuefont; } /** * The toString method, used for tests or debugging. */ public String toString() { return "bgcolor:" + getBgColor() + " halign:" + getHAlign() + " valign:" + getVAlign() + " padding:" + getPadding() + " border:" + getBorder() + " font:" + getFont() + " valuefont:" + getValueFont(); } /** * This method inherits all style attributes (values) from a given style object. A new style * object is created if the base style object is null. If a value is not defined in the * baseStyle object it would be inhert from the inheritStyle object. * * @param baseStyle the base style object that should be enhanced * @param inhertStyle the style values that could inherit from * @return an inherit style object */ public static Style doInherit(Style baseStyle, Style inhertStyle) { if (baseStyle == null) { baseStyle = new Style(); } if (inhertStyle != null) { if (baseStyle.getBgColor() == null) baseStyle.setBgColor(inhertStyle.getBgColor()); if (baseStyle.getBorder() == DEFAULT_BORDER) baseStyle.setBorder(inhertStyle.getBorder()); if (baseStyle.getHAlign() == null) baseStyle.setHAlign(inhertStyle.getHAlign()); if (baseStyle.getVAlign() == null) baseStyle.setVAlign(inhertStyle.getVAlign()); if (baseStyle.getPadding() == DEFAULT_PADDING) baseStyle.setPadding(inhertStyle.getPadding()); if (baseStyle.getFont() == null) baseStyle.setFont(inhertStyle.getFont()); if (baseStyle.getValueFont() == null) baseStyle.setValueFont(inhertStyle.getValueFont()); } return baseStyle; } }