View Javadoc

1   /*
2   
3   nextobjects Copyright (C) 2001-2005 Emmanuel Florent
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by the
7   Free Software Foundation; either version 2 of the License, or (at your
8   option) any later version.
9   
10  This program is distributed in the hope that it will
11  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  PURPOSE. See the GNU General Public License for more details.
14  
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc., 59
17  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  
19  */
20  
21  package org.devaki.nextobjects.workspace.models.styles;
22  
23  import java.awt.Color;
24  
25  import java.awt.datatransfer.DataFlavor;
26  import java.awt.datatransfer.Transferable;
27  import java.awt.datatransfer.UnsupportedFlavorException;
28  import java.io.Serializable;
29  import org.devaki.nextobjects.constants.CstGraphics;
30  import org.devaki.nextobjects.workspace.models.graphics.AssociationView;
31  import org.devaki.nextobjects.workspace.models.graphics.EntityView;
32  import org.devaki.nextobjects.workspace.models.graphics.ObjectView;
33  
34  
35  /***
36   * This class defines the style of all class-like objects
37   */
38  public class ClassStyle implements Transferable, Serializable
39  {
40   // Colors
41   protected Color backgroundColor;
42   protected Color borderColor;
43  
44   // Formatting
45   protected boolean textAdjusted;
46  
47   // ObjectView that use this style
48   protected ObjectView myObjectView;
49  
50   // Clipboard
51   public static DataFlavor fieldFlavor
52     = new DataFlavor(ClassStyle.class, "ClassStyle");
53   private DataFlavor[] supportedFlavors = { fieldFlavor };
54  
55  
56   /***
57    * Construct a new 'ClassStyle' object with default properties
58    * @param pObjectView the context object view
59    */
60   public ClassStyle(ObjectView pObjectView)
61   {
62    this.myObjectView = pObjectView;
63    if (pObjectView instanceof EntityView)
64    {
65     this.backgroundColor = CstGraphics.DEFAULT_ENTITY_BACKGROUND_COLOR;
66     this.borderColor = CstGraphics.DEFAULT_ENTITY_BORDER_COLOR;
67    }
68    else if (pObjectView instanceof AssociationView)
69    {
70     this.backgroundColor = CstGraphics.DEFAULT_ASSOCIATION_BACKGROUND_COLOR;
71     this.borderColor = CstGraphics.DEFAULT_ASSOCIATION_BORDER_COLOR;
72    }
73    else
74    {
75     this.backgroundColor = CstGraphics.DEFAULT_TABLE_BACKGROUND_COLOR;
76     this.borderColor = CstGraphics.DEFAULT_TABLE_BORDER_COLOR;
77    }
78    this.textAdjusted = true;
79   }
80  
81  
82   /***
83    * Construct a new 'ClassStyle' object
84    * @param pObjectView the context object
85    * @param pBackgroundColor the background color
86    * @param pBorderColor the border color
87    * @param pTextAdjusted the format
88    */
89   public ClassStyle(ObjectView pObjectView, Color pBackgroundColor,
90              Color pBorderColor, boolean pTextAdjusted)
91   {
92    this.myObjectView = pObjectView;
93    this.backgroundColor = pBackgroundColor;
94    this.borderColor = pBorderColor;
95    this.textAdjusted = pTextAdjusted;
96   }
97  
98  
99   /***
100   * Construct a new 'ClassStyle' object from an other
101   * @param pClassStyle the context class style
102   */
103  public ClassStyle(ClassStyle pClassStyle)
104  {
105   this.myObjectView = pClassStyle.getMyObjectView();
106   this.backgroundColor = pClassStyle.getBackgroundColor();
107   this.borderColor = pClassStyle.getBorderColor();
108   this.textAdjusted = pClassStyle.isTextAdjusted();
109  }
110 
111 
112  /***
113   * Return the object view to which the style is applied
114   * @return the object view
115   */
116  public ObjectView getMyObjectView()
117  {
118   return this.myObjectView;
119  }
120 
121 
122  /***
123   * Define the object view to which the style is applied
124   * @param pObjectView the object view
125   */
126  public void setMyObjectView(ObjectView pObjectView)
127  {
128   this.myObjectView = pObjectView;
129  }
130 
131 
132  /***
133   * Get the background color
134   * @return the background color
135   */
136  public Color getBackgroundColor()
137  {
138   return this.backgroundColor;
139  }
140 
141 
142  /***
143   * Set the background color
144   * @param pBackgroundColor the background color
145   */
146  public void setBackgroundColor(Color pBackgroundColor)
147  {
148   this.backgroundColor = pBackgroundColor;
149  }
150 
151 
152  /***
153   * Get the border color
154   * @return the border color
155   */
156  public Color getBorderColor()
157  {
158   return this.borderColor;
159  }
160 
161 
162  /***
163   * Set the border color
164   * @param pBorderColor the border color
165   */
166  public void setBorderColor(Color pBorderColor)
167  {
168   this.borderColor = pBorderColor;
169  }
170 
171 
172  /***
173   * Return wether or not the draw is adjusted to its content
174   * @return textAdjusted a boolean
175   */
176  public boolean isTextAdjusted()
177  {
178   return this.textAdjusted;
179  }
180 
181 
182  /***
183   * Set wether or not the draw is adjusted to its content
184   * @param pTextAdjusted a boolean
185   */
186  public void setTextAdjusted(boolean pTextAdjusted)
187  {
188   this.textAdjusted = pTextAdjusted;
189  }
190 
191 
192  ///////////////////////
193  // CLIPBOARD METHODS //
194  ///////////////////////
195 
196   /***
197   * Return the flavors
198   * @return a table of DataFlavor
199   */
200  public synchronized DataFlavor[] getTransferDataFlavors()
201  {
202   return this.supportedFlavors;
203  }
204 
205 
206  /***
207   * Is the data supported by this class?
208   * @param parFlavor
209   * @return a boolean
210   */
211  public boolean isDataFlavorSupported(DataFlavor parFlavor)
212  {
213   return (parFlavor.equals(fieldFlavor));
214  }
215 
216 
217  /***
218   * Return the object to be used by the clipboard
219   * @param parFlavor
220   * @return an Object
221   * @throws UnsupportedFlavorException
222   */
223  public synchronized Object getTransferData(DataFlavor parFlavor)
224    throws UnsupportedFlavorException
225  {
226   if (parFlavor.equals(fieldFlavor))
227   {
228    return (this);
229   }
230   else
231   {
232    throw new UnsupportedFlavorException(fieldFlavor);
233   }
234  }
235 
236 
237  /***
238   * Need to be defined
239   * @param parClipboard
240   * @param parTransferable
241   */
242  /*public void lostOwnership (Clipboard parClipboard, Transferable parTransferable)
243  {
244  }*/
245 }