View Javadoc

1   /*
2    *  File: DefaultCellStyle.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Common Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/cpl-v10.html
10   */
11  package de.jaret.util.ui.table.renderer;
12  
13  import org.eclipse.swt.graphics.FontData;
14  import org.eclipse.swt.graphics.RGB;
15  
16  import de.jaret.util.misc.PropertyObservableBase;
17  import de.jaret.util.ui.table.model.ITableViewState;
18  import de.jaret.util.ui.table.model.ITableViewState.HAlignment;
19  import de.jaret.util.ui.table.model.ITableViewState.VAlignment;
20  
21  /***
22   * Default implementation of ICellStyle.
23   * 
24   * @author Peter Kliem
25   * @version $Id: DefaultCellStyle.java 347 2007-04-07 15:01:10Z olk $
26   */
27  public class DefaultCellStyle extends PropertyObservableBase implements ICellStyle {
28      /*** the border configuraion. */
29      protected IBorderConfiguration _borderConfiguration;
30      /*** foreground color as RGB (no color ressource here). */
31      protected RGB _foregroundColor;
32      /*** background color as RGB (no color ressource here). */
33      protected RGB _backgroundColor;
34      /*** border color as RGB (no color ressource here). */
35      protected RGB _borderColor;
36      /*** the font data to use (no font ressource here). */
37      protected FontData _font;
38      /*** horizontal alignement. */
39      protected ITableViewState.HAlignment _hAlignment = ITableViewState.HAlignment.LEFT;
40      /*** vertical alignment. */
41      protected ITableViewState.VAlignment _vAlignment = ITableViewState.VAlignment.TOP;
42      /*** should allow multinline.*/
43      protected boolean _multiLine = true;
44  
45      /***
46       * Construct a new default cell style.
47       * 
48       * @param foregroundColor forgeround
49       * @param backgroundColor background
50       * @param borderConfiguration border config
51       * @param font fontdata 
52       */
53      public DefaultCellStyle(RGB foregroundColor, RGB backgroundColor, IBorderConfiguration borderConfiguration,
54              FontData font) {
55          _foregroundColor = foregroundColor;
56          _backgroundColor = backgroundColor;
57          _borderConfiguration = borderConfiguration;
58          _font = font;
59      }
60  
61      /***
62       * {@inheritDoc}
63       */
64      public DefaultCellStyle copy() {
65          DefaultCellStyle cs = new DefaultCellStyle(_foregroundColor, _backgroundColor, _borderConfiguration.copy(),
66                  _font);
67          cs.setHorizontalAlignment(_hAlignment);
68          cs.setVerticalAlignment(_vAlignment);
69          return cs;
70      }
71  
72      /***
73       * @return Returns the backgroundColor.
74       */
75      public RGB getBackgroundColor() {
76          return _backgroundColor;
77      }
78  
79      /***
80       * @param backgroundColor The backgroundColor to set.
81       */
82      public void setBackgroundColor(RGB backgroundColor) {
83          if (isRealModification(_backgroundColor, backgroundColor)) {
84              RGB oldVal = _backgroundColor;
85              _backgroundColor = backgroundColor;
86              firePropertyChange(BACKGROUNDCOLOR, oldVal, backgroundColor);
87          }
88      }
89  
90      /***
91       * @return Returns the borderColor.
92       */
93      public RGB getBorderColor() {
94          return _borderColor;
95      }
96  
97      /***
98       * {@inheritDoc}
99       */
100     public void setBorderColor(RGB borderColor) {
101         if (isRealModification(_borderColor, borderColor)) {
102             RGB oldVal = _borderColor;
103             _borderColor = borderColor;
104             firePropertyChange(BORDERCOLOR, oldVal, borderColor);
105         }
106     }
107 
108     /***
109      * @return Returns the borderConfiguration.
110      */
111     public IBorderConfiguration getBorderConfiguration() {
112         return _borderConfiguration;
113     }
114 
115     /***
116      * {@inheritDoc}
117      */
118     public void setBorderConfiguration(IBorderConfiguration borderConfiguration) {
119         if (isRealModification(_borderConfiguration, borderConfiguration)) {
120             IBorderConfiguration oldVal = _borderConfiguration;
121             _borderConfiguration = borderConfiguration;
122             firePropertyChange(BORDERCONFIGURATION, oldVal, borderConfiguration);
123         }
124     }
125 
126     /***
127      * @return Returns the font.
128      */
129     public FontData getFont() {
130         return _font;
131     }
132 
133     /***
134      * @param font The font to set.
135      */
136     public void setFont(FontData font) {
137         if (isRealModification(_font, font)) {
138             FontData oldVal = _font;
139             _font = font;
140             firePropertyChange(FONT, oldVal, font);
141         }
142     }
143 
144     /***
145      * @return Returns the foregroundColor.
146      */
147     public RGB getForegroundColor() {
148         return _foregroundColor;
149     }
150 
151     /***
152      * @param foregroundColor The foregroundColor to set.
153      */
154     public void setForegroundColor(RGB foregroundColor) {
155         if (isRealModification(_foregroundColor, foregroundColor)) {
156             RGB oldVal = _foregroundColor;
157             _foregroundColor = foregroundColor;
158             firePropertyChange(FOREGROUNDCOLOR, oldVal, foregroundColor);
159         }
160     }
161 
162     /***
163      * {@inheritDoc}
164      */
165     public HAlignment getHorizontalAlignment() {
166         return _hAlignment;
167     }
168 
169     /***
170      * {@inheritDoc}
171      */
172     public void setHorizontalAlignment(HAlignment alignment) {
173         if (!_hAlignment.equals(alignment)) {
174             HAlignment oldVal = _hAlignment;
175             _hAlignment = alignment;
176             firePropertyChange(HORIZONTAL_ALIGNMENT, oldVal, alignment);
177         }
178     }
179 
180     /***
181      * {@inheritDoc}
182      */
183     public VAlignment getVerticalAlignment() {
184         return _vAlignment;
185     }
186 
187     /***
188      * {@inheritDoc}
189      */
190     public void setVerticalAlignment(VAlignment alignment) {
191         if (!_vAlignment.equals(alignment)) {
192             VAlignment oldVal = _vAlignment;
193             _vAlignment = alignment;
194             firePropertyChange(VERTICAL_ALIGNMENT, oldVal, alignment);
195         }
196     }
197 
198     /***
199      * @return Returns the multiLine.
200      */
201     public boolean getMultiLine() {
202         return _multiLine;
203     }
204 
205     /***
206      * @param multiLine The multiLine to set.
207      */
208     public void setMultiLine(boolean multiLine) {
209         _multiLine = multiLine;
210     }
211 
212 }