2 * Copyright (c) 2003-2004 Christopher Lenz and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Christopher Lenz - initial API and implementation
11 * $Id: CssEditorAnnotationsConfigurationBlock.java,v 1.1 2004-09-02 18:11:50 jsurfer Exp $
14 package net.sourceforge.phpeclipse.css.ui.internal.preferences;
16 import java.util.ArrayList;
17 import java.util.Iterator;
19 import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages;
21 import org.eclipse.jface.preference.ColorSelector;
22 import org.eclipse.jface.preference.IPreferenceStore;
23 import org.eclipse.jface.preference.PreferenceConverter;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.events.SelectionListener;
27 import org.eclipse.swt.graphics.RGB;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Control;
33 import org.eclipse.swt.widgets.Label;
34 import org.eclipse.swt.widgets.List;
35 import org.eclipse.ui.texteditor.AnnotationPreference;
36 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
41 final class CssEditorAnnotationsConfigurationBlock
42 extends AbstractConfigurationBlock {
44 // Instance Variables ------------------------------------------------------
46 private List fColorList;
47 private String[][] fColorListModel;
48 private ColorSelector fColorSelector;
49 private Button fShowInTextCheckBox;
50 private Button fShowInOverviewRulerCheckBox;
52 // Constructors ------------------------------------------------------------
54 public CssEditorAnnotationsConfigurationBlock(IPreferenceStore store) {
56 MarkerAnnotationPreferences preferences =
57 new MarkerAnnotationPreferences();
58 fColorListModel = createAnnotationTypeListModel(preferences);
61 // Public Methods ----------------------------------------------------------
63 public Control createControl(Composite parent) {
65 Composite composite = new Composite(parent, SWT.NONE);
66 GridLayout layout = new GridLayout();
67 layout.numColumns = 2;
68 composite.setLayout(layout);
70 Label label = new Label(composite, SWT.LEFT);
71 label.setText(getString("presentationOptions")); //$NON-NLS-1$
72 GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
73 gridData.horizontalSpan = 2;
74 label.setLayoutData(gridData);
76 Composite editorComposite = new Composite(composite, SWT.NONE);
77 layout = new GridLayout();
78 layout.numColumns = 2;
79 layout.marginHeight = 0;
80 layout.marginWidth = 0;
81 editorComposite.setLayout(layout);
82 gridData = new GridData(
83 GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
84 gridData.horizontalSpan = 2;
85 editorComposite.setLayoutData(gridData);
87 fColorList = new List(editorComposite,
88 SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
89 gridData = new GridData(
90 GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
91 gridData.heightHint = convertHeightInCharsToPixels(composite, 8);
92 fColorList.setLayoutData(gridData);
93 fColorList.addSelectionListener(new SelectionListener() {
94 public void widgetDefaultSelected(SelectionEvent e) { }
95 public void widgetSelected(SelectionEvent e) {
96 handleAnnotationColorListSelection();
100 Composite optionsComposite = new Composite(editorComposite, SWT.NONE);
101 layout = new GridLayout();
102 layout.marginHeight = 0;
103 layout.marginWidth = 0;
104 layout.numColumns = 2;
105 optionsComposite.setLayout(layout);
106 optionsComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
108 fShowInTextCheckBox = new Button(optionsComposite, SWT.CHECK);
109 fShowInTextCheckBox.setText(getString(
110 "showInText")); //$NON-NLS-1$
111 gridData = new GridData(GridData.FILL_HORIZONTAL);
112 gridData.horizontalAlignment = GridData.BEGINNING;
113 gridData.horizontalSpan = 2;
114 fShowInTextCheckBox.setLayoutData(gridData);
115 fShowInTextCheckBox.addSelectionListener(new SelectionListener() {
116 public void widgetDefaultSelected(SelectionEvent e) { }
117 public void widgetSelected(SelectionEvent e) {
118 int i = fColorList.getSelectionIndex();
119 String key = fColorListModel[i][2];
120 getPreferenceStore().setValue(key,
121 fShowInTextCheckBox.getSelection());
125 fShowInOverviewRulerCheckBox = new Button(optionsComposite, SWT.CHECK);
126 fShowInOverviewRulerCheckBox.setText(getString(
127 "showInOverviewRuler")); //$NON-NLS-1$
128 gridData = new GridData(GridData.FILL_HORIZONTAL);
129 gridData.horizontalAlignment = GridData.BEGINNING;
130 gridData.horizontalSpan = 2;
131 fShowInOverviewRulerCheckBox.setLayoutData(gridData);
132 fShowInOverviewRulerCheckBox.addSelectionListener(
133 new SelectionListener() {
134 public void widgetDefaultSelected(SelectionEvent e) { }
135 public void widgetSelected(SelectionEvent e) {
136 int i = fColorList.getSelectionIndex();
137 String key = fColorListModel[i][3];
138 getPreferenceStore().setValue(key,
139 fShowInOverviewRulerCheckBox.getSelection());
143 label = new Label(optionsComposite, SWT.LEFT);
144 label.setText(getString("color")); //$NON-NLS-1$
145 gridData = new GridData();
146 gridData.horizontalAlignment = GridData.BEGINNING;
147 label.setLayoutData(gridData);
149 fColorSelector = new ColorSelector(optionsComposite);
150 Button foregroundColorButton = fColorSelector.getButton();
151 gridData = new GridData(GridData.FILL_HORIZONTAL);
152 gridData.horizontalAlignment = GridData.BEGINNING;
153 foregroundColorButton.setLayoutData(gridData);
154 foregroundColorButton.addSelectionListener(new SelectionListener() {
155 public void widgetDefaultSelected(SelectionEvent e) { }
156 public void widgetSelected(SelectionEvent e) {
157 int i = fColorList.getSelectionIndex();
158 String key = fColorListModel[i][1];
159 PreferenceConverter.setValue(getPreferenceStore(), key,
160 fColorSelector.getColorValue());
169 // Event Handlers ----------------------------------------------------------
171 void handleAnnotationColorListSelection() {
172 int i = fColorList.getSelectionIndex();
173 String key = fColorListModel[i][1];
174 RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
175 fColorSelector.setColorValue(rgb);
176 key = fColorListModel[i][2];
177 fShowInTextCheckBox.setSelection(getPreferenceStore().getBoolean(key));
178 key = fColorListModel[i][3];
179 fShowInOverviewRulerCheckBox.setSelection(
180 getPreferenceStore().getBoolean(key));
183 // Private Methods ---------------------------------------------------------
185 private String[][] createAnnotationTypeListModel(
186 MarkerAnnotationPreferences preferences) {
188 ArrayList listModelItems = new ArrayList();
189 Iterator i = preferences.getAnnotationPreferences().iterator();
190 while (i.hasNext()) {
191 AnnotationPreference info = (AnnotationPreference) i.next();
192 listModelItems.add(new String[] {
193 info.getPreferenceLabel(),
194 info.getColorPreferenceKey(),
195 info.getTextPreferenceKey(),
196 info.getOverviewRulerPreferenceKey()
200 String[][] listModel = new String[listModelItems.size()][];
201 listModelItems.toArray(listModel);
205 private static String getString(String key) {
206 return CssUIMessages.getString(
207 "CssEditorPreferencePage.annotations." + key); //$NON-NLS-1$
210 private void initialize() {
211 for (int i = 0; i < fColorListModel.length; i++) {
212 fColorList.add(fColorListModel[i][0]);
214 fColorList.getDisplay().asyncExec(new Runnable() {
216 if ((fColorList != null)
217 && !fColorList.isDisposed()) {
218 fColorList.select(0);
219 handleAnnotationColorListSelection();