View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: DiagramSettings.java
13   * Created: 2007-00-00
14   * Author: awos
15   * $Id: DiagramSettings.java 2817 2009-05-05 13:17:57Z tmilos $
16   */
17  
18  package pl.edu.agh.cast.model.visual.backward;
19  
20  import java.beans.PropertyChangeListener;
21  
22  import pl.edu.agh.cast.data.model.property.PropertyChangeProviderHelper;
23  
24  import com.thoughtworks.xstream.annotations.XStreamAlias;
25  import com.thoughtworks.xstream.annotations.XStreamOmitField;
26  
27  /**
28   * Schema diagram settings.
29   *
30   * @author AGH CAST Team
31   */
32  @XStreamAlias("diagramSettings")
33  public class DiagramSettings implements IDiagramSettings {
34  
35  	private static final long serialVersionUID = 5036382806995356626L;
36  
37  	/**
38  	 * Name of the <em>Show diagram legend changed</em> event.
39  	 */
40  	public static final String LEGEND_SHOWN = "DiagramSettings.LegendShown"; //$NON-NLS-1$
41  
42  	/**
43  	 * Name of the <em>Diagram display name changed</em> event.
44  	 */
45  	public static final String DISPLAY_NAME = "DiagramSettings.DisplayName"; //$NON-NLS-1$
46  
47  	@XStreamAlias("defaultLayoutManager")
48  	private String defaultLayoutManager;
49  
50  	@XStreamAlias("showLegend")
51  	private boolean showLegend = true;
52  
53  	@XStreamAlias("displayName")
54  	private String displayName = ""; //$NON-NLS-1$
55  
56  	@XStreamAlias("needsLayout")
57  	private boolean needsInitialLayout = true;
58  
59  	@XStreamAlias("editorId")
60  	private String editorId;
61  
62  	/**
63  	 * Property change support.
64  	 */
65  	@XStreamOmitField
66  	private transient PropertyChangeProviderHelper pcpHelper;
67  
68  	protected Object readResolve() {
69  		pcpHelper = new PropertyChangeProviderHelper(this);
70  		return this;
71  	}
72  
73  	public boolean isShowLegend() {
74  		return showLegend;
75  	}
76  
77  	/**
78  	 * {@inheritDoc}
79  	 *
80  	 * @see pl.edu.agh.cast.model.visual.backward.IDiagramSettings#setShowLegend(boolean)
81  	 */
82  	public void setShowLegend(boolean showLegend) {
83  		boolean oldValue = this.showLegend;
84  		this.showLegend = showLegend;
85  		firePropertyChange(LEGEND_SHOWN, oldValue, showLegend);
86  	}
87  
88  	/**
89  	 * {@inheritDoc}
90  	 *
91  	 * @see pl.edu.agh.cast.model.visual.backward.IDiagramSettings#getDisplayName()
92  	 */
93  	public String getDisplayName() {
94  		return displayName;
95  	}
96  
97  	/**
98  	 * {@inheritDoc}
99  	 *
100 	 * @see pl.edu.agh.cast.model.visual.backward.IDiagramSettings#setDisplayName(java.lang.String)
101 	 */
102 	public void setDisplayName(String displayName) {
103 		String oldValue = this.displayName;
104 		this.displayName = displayName;
105 		firePropertyChange(DISPLAY_NAME, oldValue, displayName);
106 	}
107 
108 	/**
109 	 * {@inheritDoc}
110 	 *
111 	 * @see pl.edu.agh.cast.model.visual.backward.IDiagramSettings#needsInitialLayout()
112 	 */
113 	public boolean needsInitialLayout() {
114 		return needsInitialLayout;
115 	}
116 
117 	/**
118 	 * {@inheritDoc}
119 	 *
120 	 * @see pl.edu.agh.cast.model.visual.backward.IDiagramSettings#setNeedsInitialLayout(boolean)
121 	 */
122 	public void setNeedsInitialLayout(boolean in) {
123 		needsInitialLayout = in;
124 	}
125 
126 	/**
127 	 * {@inheritDoc}
128 	 *
129 	 * @see pl.edu.agh.cast.model.visual.backward.IDiagramSettings#setDefaultLayoutManagerClass(java.lang.String)
130 	 */
131 	public void setDefaultLayoutManagerClass(String layoutManagerClass) {
132 		defaultLayoutManager = layoutManagerClass;
133 	}
134 
135 	/**
136 	 * {@inheritDoc}
137 	 *
138 	 * @see pl.edu.agh.cast.model.visual.backward.IDiagramSettings#getDefaultLayoutManagerClass()
139 	 */
140 	public String getDefaultLayoutManagerClass() {
141 		return defaultLayoutManager;
142 	}
143 
144 	/**
145 	 * {@inheritDoc}
146 	 *
147 	 * @see pl.edu.agh.cast.model.visual.backward.IDiagramSettings#getEditorId()
148 	 */
149 	public String getEditorId() {
150 		return editorId;
151 	}
152 
153 	/**
154 	 * {@inheritDoc}
155 	 *
156 	 * @see pl.edu.agh.cast.model.visual.backward.IDiagramSettings#setEditorId(java.lang.String)
157 	 */
158 	public void setEditorId(String id) {
159 		editorId = id;
160 	}
161 
162 	// BEGIN Property change support
163 
164 	/**
165 	 * {@inheritDoc}
166 	 *
167 	 * @see pl.edu.agh.cast.data.model.property.IPropertyChangeProvider#addPropertyChangeListener(java.beans.PropertyChangeListener)
168 	 */
169 	public void addPropertyChangeListener(PropertyChangeListener l) {
170 		if (pcpHelper == null) {
171 			pcpHelper = new PropertyChangeProviderHelper(this);
172 		}
173 		pcpHelper.addPropertyChangeListener(l);
174 	}
175 
176 	/**
177 	 * {@inheritDoc}
178 	 *
179 	 * @see pl.edu.agh.cast.data.model.property.IPropertyChangeProvider
180 	 *      #removePropertyChangeListener(java.beans.PropertyChangeListener)
181 	 */
182 	public void removePropertyChangeListener(PropertyChangeListener l) {
183 		pcpHelper.removePropertyChangeListener(l);
184 	}
185 
186 	/**
187 	 * Notifies about property change.
188 	 *
189 	 * @param property
190 	 *            name of the property
191 	 * @param oldValue
192 	 *            old value of the property
193 	 * @param newValue
194 	 *            new value of the property
195 	 */
196 	protected void firePropertyChange(String property, Object oldValue, Object newValue) {
197 		pcpHelper.firePropertyChange(property, oldValue, newValue);
198 	}
199 
200 	// END Property change support
201 
202 }