001: /*
002: * Javu WingS - Lightweight Java Component Set
003: * Copyright (c) 2005-2007 Krzysztof A. Sadlocha
004: * e-mail: ksadlocha@programics.com
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: package com.javujavu.javux.wings;
022:
023: import java.awt.Color;
024: import java.awt.Insets;
025:
026: /**
027: * A collection of attributes, typically used to represent component styles<br>
028: * <br>
029: * <b>This is one of the core WingS classes required by all the components</b><br>
030: * <br>
031: * <b>This class is thread safe.</b>
032: **/
033: public class Style {
034:
035: /**
036: * component state associated with this style
037: */
038: public int state;
039:
040: /**
041: * background color
042: */
043: public Color background;
044: /**
045: * background image
046: */
047: public WingImage image;
048: /**
049: * foreground color
050: */
051: public Color foreground;
052: /**
053: * border color
054: */
055: public Color border;
056: /**
057: * icon image
058: */
059: public WingImage icon;
060: /**
061: * margin
062: */
063: public Insets margin = new Insets(0, 0, 0, 0);
064: /**
065: * multipurpose gap value
066: */
067: public int gap;
068: /**
069: * font
070: */
071: public WingFont font;
072: /**
073: * focus indicator frame color
074: */
075: public Color focus;
076:
077: /**
078: * copies values from style st
079: * @param st source
080: */
081: public void copyFrom(Style st) {
082: this .state = st.state;
083:
084: this .background = st.background;
085: this .image = st.image;
086: this .foreground = st.foreground;
087: this .border = st.border;
088: this .icon = st.icon;
089: this .margin = st.margin;
090: this .gap = st.gap;
091: this .font = st.font;
092: this .focus = st.focus;
093: }
094:
095: /**
096: * Returns font
097: * @param def default value
098: * @return font or def if font is null
099: */
100: public WingFont getFont(WingFont def) {
101: WingFont f = font;
102: return (f != null) ? f : def;
103: }
104:
105: /**
106: * Returns foreground color
107: * @param def default value
108: * @return foreground or def if foreground is null
109: */
110: public Color getForeground(Color def) {
111: Color c = foreground;
112: return (c != null) ? c : def;
113: }
114:
115: /**
116: * Returns background color
117: * @param def default value
118: * @return background or def if background is null
119: */
120: public Color getBackground(Color def) {
121: Color c = background;
122: return (c != null) ? c : def;
123: }
124:
125: /**
126: * Merges values from this and filter style
127: * if the state of filter covers this state
128: * @param filter style to merge with
129: * @return result of merge operation
130: */
131: public Style merge(Style filter) {
132: if (filter == null || ((filter.state ^ -1) & this .state) != 0)
133: return this ;
134: Style s2 = new Style();
135: s2.copyFrom(this );
136: if (filter.background != null)
137: s2.background = filter.background;
138: if (filter.image != null)
139: s2.image = filter.image;
140: if (filter.foreground != null)
141: s2.foreground = filter.foreground;
142: if (filter.border != null)
143: s2.border = filter.border;
144: if (filter.focus != null)
145: s2.focus = filter.focus;
146: if (filter.icon != null)
147: s2.icon = filter.icon;
148: if (filter.font != null)
149: s2.font = filter.font;
150: if (filter.margin.left != 0 || filter.margin.right != 0
151: || filter.margin.top != 0 || filter.margin.bottom != 0)
152: s2.margin = filter.margin;
153: if (filter.gap != 0)
154: s2.gap = filter.gap;
155: return s2;
156: }
157:
158: }
|