blob: e89f95cbcb25e6a444e3ef4db85499c80d0f1e37 [file] [log] [blame]
itrimble38bf0b92006-10-30 18:59:16 +00001/*******************************************************************************
2 * Copyright (c) 2006 Sybase, Inc. and others.
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Sybase, Inc. - initial API and implementation
11 *******************************************************************************/
12package org.eclipse.jst.pagedesigner.ui.dialogs;
13
14import org.eclipse.jface.preference.PreferencePage;
cbateman6d3359f2006-11-28 20:23:25 +000015import org.eclipse.jst.jsf.common.ui.internal.dialogfield.ColorButtonDialogField;
16import org.eclipse.jst.jsf.common.ui.internal.dialogfield.DialogField;
17import org.eclipse.jst.jsf.common.ui.internal.dialogfield.IDialogFieldApplyListener;
itrimble38bf0b92006-10-30 18:59:16 +000018import org.eclipse.swt.SWT;
19import org.eclipse.swt.events.ModifyEvent;
20import org.eclipse.swt.events.ModifyListener;
21import org.eclipse.swt.layout.GridData;
22import org.eclipse.swt.layout.GridLayout;
23import org.eclipse.swt.widgets.Composite;
24import org.eclipse.swt.widgets.Control;
25import org.eclipse.swt.widgets.Label;
26import org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext;
27import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
28
29/**
30 * @author mengbo
31 * @version 1.5
32 */
33public class BackgroundPreferencePage extends PreferencePage {
34 private CSSPropertyContext _style;
35
36 private StyleCombo _backgroundImageCombo, _backgroundRepeatCombo,
37 _backgroundAttachmentCombo, _horizontalNumberCombo,
38 _horizontalUnitCombo, _verticalNumberCombo, _verticalUnitCombo;
39
40 private ColorButtonDialogField _backgroundColorField;
41
cbatemanf3b843f2007-10-23 19:21:36 +000042 /**
43 * @param element
44 * @param style
45 */
itrimble38bf0b92006-10-30 18:59:16 +000046 public BackgroundPreferencePage(IDOMElement element,
47 CSSPropertyContext style) {
48 super();
49 _style = style;
50
51 setTitle(DialogsMessages.getString("BackgroundPreferencePage.Title")); //$NON-NLS-1$
52 }
53
54 /**
55 * @see org.eclipse.jface.preference.
56 * PreferencePage#createContents(Composite)
57 */
58 protected Control createContents(Composite parent) {
59 GridLayout layout;
60 GridData data;
61
62 Composite top = new Composite(parent, SWT.NONE);
63 layout = new GridLayout(3, false);
64 data = new GridData(GridData.FILL_BOTH);
65 top.setLayout(layout);
66 top.setLayoutData(data);
67
cbateman6d3359f2006-11-28 20:23:25 +000068 _backgroundColorField = new ColorButtonDialogField(SWT.BORDER, new ColorUtil());
itrimble38bf0b92006-10-30 18:59:16 +000069 _backgroundColorField.setLabelText(DialogsMessages
gkesslercfc53082008-11-18 22:25:04 +000070 .getString("BackgroundBoxPreferencePage.BackgroundColor")); //$NON-NLS-1$
itrimble38bf0b92006-10-30 18:59:16 +000071 data = new GridData(GridData.HORIZONTAL_ALIGN_END);
72 _backgroundColorField.getLabelControl(null, top).setLayoutData(data);
73
74 data = new GridData(GridData.FILL_HORIZONTAL);
75 _backgroundColorField.getComboControl(null, top).setLayoutData(data);
76
77 data = new GridData();
78 _backgroundColorField.getChangeControl(null, top).setLayoutData(data);
79 _backgroundColorField
80 .setDialogFieldApplyListener(new IDialogFieldApplyListener() {
81 public void dialogFieldApplied(DialogField field) {
82 String color = _backgroundColorField.getText();
83
84 _style.setBackgroundColor(color);
85 }
86 });
87
88 Label backgroundImageLabel = new Label(top, SWT.NONE);
89 backgroundImageLabel.setText(DialogsMessages
90 .getString("BackgroundBoxPreferencePage.BackgroundImage")); //$NON-NLS-1$
91 data = new GridData(GridData.HORIZONTAL_ALIGN_END);
92 backgroundImageLabel.setLayoutData(data);
93
94 _backgroundImageCombo = new StyleCombo(top, SWT.NONE);
95 _backgroundImageCombo.setItems(IStyleConstants.NONE);
96 data = new GridData(GridData.FILL_HORIZONTAL);
97 _backgroundImageCombo.setLayoutData(data);
98 _backgroundImageCombo.addModifyListener(new ModifyListener() {
99 public void modifyText(ModifyEvent e) {
100 String image = _backgroundImageCombo.getText();
101
102 _style.setBackgroundImage(image);
103 }
104 });
105
106 new Label(top, SWT.NONE);
107
108 Label backgroundRepeatLabel = new Label(top, SWT.NONE);
109 backgroundRepeatLabel
110 .setText(DialogsMessages
111 .getString("BackgroundBoxPreferencePage.BackgroundRepeatLabel")); //$NON-NLS-1$
112 data = new GridData(GridData.HORIZONTAL_ALIGN_END);
113 backgroundRepeatLabel.setLayoutData(data);
114
115 _backgroundRepeatCombo = new StyleCombo(top, SWT.NONE);
116 _backgroundRepeatCombo.setItems(IStyleConstants.REPEAT);
117 data = new GridData(GridData.FILL_HORIZONTAL);
118 _backgroundRepeatCombo.setLayoutData(data);
119 _backgroundRepeatCombo.addModifyListener(new ModifyListener() {
120 public void modifyText(ModifyEvent e) {
121 String repeat = _backgroundRepeatCombo.getText();
122
123 _style.setBackgroundRepeat(repeat);
124 }
125 });
126
127 new Label(top, SWT.NONE);
128
129 Label backgroundAttachmentLabel = new Label(top, SWT.NONE);
130 backgroundAttachmentLabel
131 .setText(DialogsMessages
132 .getString("BackgroundBoxPreferencePage.BackgroundAttachmentLabel")); //$NON-NLS-1$
133 data = new GridData(GridData.HORIZONTAL_ALIGN_END);
134 backgroundAttachmentLabel.setLayoutData(data);
135
136 _backgroundAttachmentCombo = new StyleCombo(top, SWT.NONE);
137 _backgroundAttachmentCombo.setItems(IStyleConstants.ATTACHMENT);
138 data = new GridData(GridData.FILL_HORIZONTAL);
139 _backgroundAttachmentCombo.setLayoutData(data);
140 _backgroundAttachmentCombo.addModifyListener(new ModifyListener() {
141 public void modifyText(ModifyEvent e) {
142 String attachment = _backgroundAttachmentCombo.getText();
143
144 _style.setBackgroundAttachment(attachment);
145 }
146 });
147
148 new Label(top, SWT.NONE);
149
150 Label backgroundHorizontalLabel = new Label(top, SWT.NONE);
151 backgroundHorizontalLabel.setText(DialogsMessages
152 .getString("BackgroundBoxPreferencePage.HorizontalLabel")); //$NON-NLS-1$
153 data = new GridData(GridData.HORIZONTAL_ALIGN_END);
154 backgroundHorizontalLabel.setLayoutData(data);
155
156 _horizontalNumberCombo = new StyleCombo(top, SWT.NONE);
157 _horizontalNumberCombo.setItems(IStyleConstants.POSITION);
158 data = new GridData(GridData.FILL_HORIZONTAL);
159 _horizontalNumberCombo.setLayoutData(data);
160 _horizontalNumberCombo.addModifyListener(new ModifyListener() {
161 public void modifyText(ModifyEvent e) {
162 _horizontalUnitCombo.setEnabled(true);
163 try {
164 Integer.valueOf(_horizontalNumberCombo.getText());
165 } catch (NumberFormatException ex) {
166 _horizontalUnitCombo.setEnabled(false);
167 }
168
169 String position = _horizontalNumberCombo.getText();
170 if (_horizontalUnitCombo.isEnabled()) {
171 position += _horizontalUnitCombo.getText();
172 }
173
174 _style.setBackgroundPositionX(position);
175 }
176 });
177
178 _horizontalUnitCombo = new StyleCombo(top, SWT.READ_ONLY);
179 _horizontalUnitCombo.setItems(IStyleConstants.SIZE_UNIT);
180 data = new GridData(GridData.FILL);
181 _horizontalUnitCombo.setLayoutData(data);
182 _horizontalUnitCombo.select(0);
183 _horizontalUnitCombo.setEnabled(false);
184 _horizontalUnitCombo.addModifyListener(new ModifyListener() {
185 public void modifyText(ModifyEvent e) {
186 String position = _horizontalNumberCombo.getText();
187 if (_horizontalUnitCombo.isEnabled()) {
188 position += _horizontalUnitCombo.getText();
189 }
190
191 _style.setBackgroundPositionX(position);
192
193 }
194 });
195
196 Label backgroundVerticalLabel = new Label(top, SWT.NONE);
197 backgroundVerticalLabel.setText(DialogsMessages
198 .getString("BackgroundBoxPreferencePage.VerticalLabel")); //$NON-NLS-1$
199 data = new GridData(GridData.HORIZONTAL_ALIGN_END);
200 backgroundVerticalLabel.setLayoutData(data);
201
202 _verticalNumberCombo = new StyleCombo(top, SWT.NONE);
203 _verticalNumberCombo.setItems(IStyleConstants.POSITION);
204 data = new GridData(GridData.FILL_HORIZONTAL);
205 _verticalNumberCombo.setLayoutData(data);
206 _verticalNumberCombo.addModifyListener(new ModifyListener() {
207 public void modifyText(ModifyEvent e) {
208 _verticalUnitCombo.setEnabled(true);
209 try {
210 Integer.valueOf(_verticalNumberCombo.getText());
211 } catch (NumberFormatException ex) {
212 _verticalUnitCombo.setEnabled(false);
213 }
214
215 String position = _verticalNumberCombo.getText();
216 if (_verticalUnitCombo.isEnabled()) {
217 position += _verticalUnitCombo.getText();
218 }
219
220 _style.setBackgroundPositionY(position);
221 }
222 });
223
224 _verticalUnitCombo = new StyleCombo(top, SWT.READ_ONLY);
225 _verticalUnitCombo.setItems(IStyleConstants.SIZE_UNIT);
226 data = new GridData(GridData.FILL);
227 _verticalUnitCombo.setLayoutData(data);
228 _verticalUnitCombo.select(0);
229 _verticalUnitCombo.setEnabled(false);
230 _verticalUnitCombo.addModifyListener(new ModifyListener() {
231 public void modifyText(ModifyEvent e) {
232 String position = _verticalNumberCombo.getText();
233 if (_verticalUnitCombo.isEnabled()) {
234 position += _verticalUnitCombo.getText();
235 }
236
237 _style.setBackgroundPositionY(position);
238 }
239 });
240
241 initializeControls();
242
243 return top;
244 }
245
246 private void initializeControls() {
247 // background-color
248 String color = _style.getBackgroundColor();
249 if (!isEmptyString(color)) {
250 _backgroundColorField.setTextWithoutUpdate(color);
251 }
252
253 // background-image
254 String image = _style.getBackgroundImage();
255 if (!isEmptyString(image)) {
256 int index = _backgroundImageCombo.indexOf(image);
257 if (index != -1) {
258 _backgroundImageCombo.select(index);
259 } else {
260 _backgroundImageCombo.setText(image);
261 }
262 }
263
264 // background-repeat
265 String repeat = _style.getBackgroundRepeat();
266 if (!isEmptyString(repeat)) {
267 int index = _backgroundRepeatCombo.indexOf(repeat);
268 if (index != -1) {
269 _backgroundRepeatCombo.select(index);
270 } else {
271 _backgroundRepeatCombo.setText(repeat);
272 }
273 }
274
275 // background-attachment
276 String attachment = _style.getBackgroundAttachment();
277 if (!isEmptyString(attachment)) {
278 int index = _backgroundAttachmentCombo.indexOf(repeat);
279 if (index != -1) {
280 _backgroundAttachmentCombo.select(index);
281 } else {
282 _backgroundAttachmentCombo.setText(attachment);
283 }
284 }
285
286 // background-position
287 String position = _style.getBackgroundPositionX();
288 if (!isEmptyString(position)) {
289 int index = _horizontalNumberCombo.indexOf(position);
290 if (index != -1) {
291 _horizontalNumberCombo.select(index);
292 } else {
293 _horizontalNumberCombo.setText(position);
294 }
295 }
296 position = _style.getBackgroundPositionY();
297 if (!isEmptyString(position)) {
298 int index = _verticalNumberCombo.indexOf(position);
299 if (index != -1) {
300 _verticalNumberCombo.select(index);
301 } else {
302 _verticalNumberCombo.setText(position);
303 }
304 }
305 }
306
307 public void setVisible(boolean visible) {
308 super.setVisible(visible);
309
310 getApplyButton().setVisible(false);
311 getDefaultsButton().setVisible(false);
312 }
313
314 private boolean isEmptyString(String str) {
315 if (str == null || str.length() == 0) {
316 return true;
itrimble38bf0b92006-10-30 18:59:16 +0000317 }
cbatemanea2a1012006-11-22 19:31:27 +0000318 return false;
itrimble38bf0b92006-10-30 18:59:16 +0000319 }
320}