Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 21339af58b1b7c787b0fd269c5d1d5431e20fee9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*******************************************************************************
 * Copyright (c) 2004, 2005 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/

package org.eclipse.jst.jsf.facesconfig.ui.pageflow.figure;

import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.MidpointLocator;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jst.jsf.facesconfig.ui.EditorPlugin;
import org.eclipse.jst.jsf.facesconfig.ui.pageflow.editpart.PageflowElementEditPart;
import org.eclipse.jst.jsf.facesconfig.ui.preference.GEMPreferences;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;

/**
 * 
 * The figure for pflink, used by pflink edit part, which is a polyline with a
 * label control on it, and with tooltip support.
 * 
 * @author Xiao-guang Zhang
 */
public class PFLinkFigure extends PolylineConnection {
	/** the label attached to the connection */
	private ConnectionLabel textLabel = null;

	private ConnectionLabel iconLabel = null;

	/** The label's background color */
	private Color labelBgColor;

	/** The label's foreground color */
	private Color labelFgColor;

	/** the label's font */
	private Font labelFont;

	/** The label's visiblity */
	private boolean bLabelVisible = false;

	/** The connection's line width */
	private int lineWidth = 0;

	/** the polygon decoration for connection line */
	private PolygonDecoration arrow;

	/**
	 * 
	 */
	public PFLinkFigure() {
		arrow = new PolygonDecoration();
		arrow.setTemplate(PolygonDecoration.TRIANGLE_TIP);
		arrow.setScale(10, getLineWidth() * 2);
		setTargetDecoration(arrow);
		setForegroundColor(getForegroundColor());
	}

	/**
	 * set the connection's label string
	 * 
	 * @param strLabel
	 */
	public void setLabel(String strLabel) {
		if (null != strLabel) {
			if (textLabel == null) {
				textLabel = new ConnectionLabel();
				textLabel.setFont(getLabelFont());
				textLabel.setBackgroundColor(getLabelBackgroundColor());
				textLabel.setForegroundColor(getLabelForegroundColor());
				setLineWidth(getLineWidth());
				setLabelVisible(getLabelVisible());
				setForegroundColor(getForegroundColor());
				add(textLabel, new MidpointLocator(this, 1));
			}
			// textLabel.setVisible(true);
			textLabel.setText(strLabel);
		}
	}

	public void clearIcon() {
		setImage(null);
	}

	public void clearOutcome() {
		setLabel("");
	}

	/**
	 * set the connection's label string
	 * 
	 * @param strLabel
	 */
	public void setImage(Image image) {
		if (textLabel == null) {
			textLabel = new ConnectionLabel();
			textLabel.setFont(getLabelFont());
			textLabel.setBackgroundColor(getLabelBackgroundColor());
			textLabel.setForegroundColor(getLabelForegroundColor());
			setLineWidth(getLineWidth());
			setLabelVisible(getLabelVisible());
			setForegroundColor(getForegroundColor());
			add(textLabel, new MidpointLocator(this, 0));
		}
		textLabel.setIcon(image);
	}

	public void setActionImage() {
		ImageDescriptor imageDescriptor = PageflowElementEditPart.IMG_ACTION;
		Image image = EditorPlugin.getDefault().getImageRegistry().get(
				imageDescriptor.toString());
		if (null == image) {
			EditorPlugin.getDefault().getImageRegistry().put(
					imageDescriptor.toString(), imageDescriptor);
			image = EditorPlugin.getDefault().getImageRegistry().get(
					imageDescriptor.toString());
		}
		setImage(image);
	}

	public Image getImage() {
		if (textLabel != null) {
			return textLabel.getIcon();
		} else {
			return null;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.sybase.stf.gem.diagram.editor.figures.IBaseFigure#setToolTipText()
	 */
	public void setToolTipText(String text) {
		Label toolTip = null;

		if (text != null && text.length() > 0) {
			toolTip = new Label(text);
			toolTip.setBorder(new MarginBorder(3));
		}

		super.setToolTip(toolTip);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.sybase.stf.gem.diagram.editor.figures.IBaseFigure#getToolTipText()
	 */
	public String getToolTipText() {
		if (getToolTip() != null) {
			return ((Label) getToolTip()).getText();
		}
		return null;
	}

	/**
	 * set the font including label's
	 * 
	 */
	public void setFont(Font f) {
		if (textLabel != null) {
			textLabel.setFont(f);
		}
		super.setFont(f);
	}

	/**
	 * get the label's font from preference
	 * 
	 */
	private Font getLabelFont() {
		if (labelFont == null) {
			IPreferenceStore store = EditorPlugin.getDefault()
					.getPreferenceStore();
			labelFont = new Font(null, PreferenceConverter.getFontData(store,
					GEMPreferences.LINE_LABEL_FONT));
		}
		return labelFont;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.draw2d.Shape#setLineWidth(int)
	 */
	public void setLineWidth(int w) {
		if (textLabel != null) {
			textLabel.setBorderWidth(w);
		}
		arrow.setScale(10, getLineWidth() * 2);
		super.setLineWidth(w);
	}

	/**
	 * get the connection line width from preference.
	 */
	public int getLineWidth() {
		IPreferenceStore store = EditorPlugin.getDefault().getPreferenceStore();
		lineWidth = store.getInt(GEMPreferences.LINE_WIDTH);
		return lineWidth;
	}

	/**
	 * set label's visibility
	 * 
	 * @param flag -
	 *            visible or not.
	 */
	public void setLabelVisible(boolean flag) {
		if (textLabel != null) {
			textLabel.setVisible(flag);
		}
	}

	/**
	 * get the label's visiblity from preference
	 * 
	 */
	private boolean getLabelVisible() {
		IPreferenceStore store = EditorPlugin.getDefault().getPreferenceStore();
		bLabelVisible = store.getBoolean(GEMPreferences.SHOW_LINE_LABELS);
		return bLabelVisible;
	}

	/**
	 * set the label's foreground color
	 * 
	 * @param c
	 */
	public void setLabelForegroundColor(Color c) {
		labelFgColor = c;
		if (textLabel != null) {
			textLabel.setForegroundColor(c);
		}
	}

	/**
	 * get the label's foreground color from preference
	 * 
	 */
	private Color getLabelForegroundColor() {
		if (labelFgColor == null) {
			IPreferenceStore store = EditorPlugin.getDefault()
					.getPreferenceStore();
			labelFgColor = GEMPreferences.getColor(store,
					GEMPreferences.LINE_LABEL_FONT_COLOR);
		}
		return labelFgColor;
	}

	/**
	 * set the label's background color
	 * 
	 * @param c
	 */
	public void setLabelBackgroundColor(Color c) {
		labelBgColor = c;
		if (textLabel != null) {
			textLabel.setBackgroundColor(c);
		}
	}

	/**
	 * get the label's background color from preference
	 * 
	 */
	private Color getLabelBackgroundColor() {
		if (labelBgColor == null) {
			IPreferenceStore store = EditorPlugin.getDefault()
					.getPreferenceStore();
			labelBgColor = GEMPreferences.getColor(store,
					GEMPreferences.LINE_LABEL_COLOR);
		}
		return labelBgColor;
	}

	/**
	 * get the foreground color from preference
	 * 
	 */
	public Color getForegroundColor() {
		IPreferenceStore store = EditorPlugin.getDefault().getPreferenceStore();
		fgColor = GEMPreferences.getColor(store, GEMPreferences.LINE_COLOR);
		return fgColor;
	}

	/**
	 * set the figure's foreground, which will also update the label's border's
	 * color.
	 */
	public void setForegroundColor(Color c) {
		if (textLabel != null) {
			textLabel.setBorderColor(c);
		}
		super.setForegroundColor(c);
	}
}

Back to the top