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: CssEditorAppearanceConfigurationBlock.java,v 1.1 2004-09-02 18:11:51 jsurfer Exp $
14 package net.sourceforge.phpeclipse.css.ui.internal.preferences;
16 import net.sourceforge.phpeclipse.css.ui.internal.CssUIMessages;
17 import net.sourceforge.phpeclipse.css.ui.internal.CssUIPreferences;
19 import org.eclipse.jface.preference.ColorSelector;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.jface.preference.PreferenceConverter;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.SelectionEvent;
24 import org.eclipse.swt.events.SelectionListener;
25 import org.eclipse.swt.graphics.RGB;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Button;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Control;
31 import org.eclipse.swt.widgets.Label;
32 import org.eclipse.swt.widgets.List;
37 final class CssEditorAppearanceConfigurationBlock
38 extends AbstractConfigurationBlock {
40 // Instance Variables ------------------------------------------------------
42 private List fColorList;
43 private final String[][] fColorListModel = new String[][] {
44 { getString("lineNumberForegroundColor"), //$NON-NLS-1$
45 CssUIPreferences.EDITOR_LINE_NUMBER_RULER_COLOR },
46 { getString("matchingBracketsHighlightColor"), //$NON-NLS-1$
47 CssUIPreferences.EDITOR_MATCHING_BRACKETS_COLOR },
48 { getString("currentLineHighlighColor"), //$NON-NLS-1$
49 CssUIPreferences.EDITOR_CURRENT_LINE_COLOR },
50 { getString("printMarginColor"), //$NON-NLS-1$
51 CssUIPreferences.EDITOR_PRINT_MARGIN_COLOR },
53 private ColorSelector fColorSelector;
55 // Constructors ------------------------------------------------------------
57 public CssEditorAppearanceConfigurationBlock(IPreferenceStore store) {
61 // Public Methods ----------------------------------------------------------
63 public Control createControl(Composite parent) {
65 Composite control = new Composite(parent, SWT.NONE);
66 GridLayout layout = new GridLayout();
67 layout.numColumns = 2;
68 control.setLayout(layout);
70 addTextField(control, getString("displayedTabWidth"), //$NON-NLS-1$
71 CssUIPreferences.EDITOR_TAB_WIDTH, 3, 0);
72 addTextField(control, getString("printMarginColumn"), //$NON-NLS-1$
73 CssUIPreferences.EDITOR_PRINT_MARGIN_COLUMN, 3,
75 addBooleanField(control, getString("showOverviewRuler"), //$NON-NLS-1$
76 CssUIPreferences.EDITOR_OVERVIEW_RULER, 0);
77 addBooleanField(control, getString("showLineNumbers"), //$NON-NLS-1$
78 CssUIPreferences.EDITOR_LINE_NUMBER_RULER, 0);
79 addBooleanField(control,
80 getString("highlightMatchingBrackets"), //$NON-NLS-1$
81 CssUIPreferences.EDITOR_MATCHING_BRACKETS, 0);
82 addBooleanField(control,
83 getString("highlightCurrentLine"), //$NON-NLS-1$
84 CssUIPreferences.EDITOR_CURRENT_LINE, 0);
85 addBooleanField(control, getString("showPrintMargin"), //$NON-NLS-1$
86 CssUIPreferences.EDITOR_PRINT_MARGIN, 0);
88 Label label = new Label(control, SWT.LEFT);
89 GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
90 gridData.horizontalSpan = 2;
91 gridData.heightHint = convertHeightInCharsToPixels(control, 1) / 2;
92 label.setLayoutData(gridData);
94 label = new Label(control, SWT.LEFT);
95 label.setText(getString("colorOptions")); //$NON-NLS-1$
96 gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
97 gridData.horizontalSpan = 2;
98 label.setLayoutData(gridData);
100 Composite editorComposite = new Composite(control, SWT.NONE);
101 layout = new GridLayout();
102 layout.numColumns = 2;
103 layout.marginHeight = 0;
104 layout.marginWidth = 0;
105 editorComposite.setLayout(layout);
106 gridData = new GridData(
107 GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
108 gridData.horizontalSpan = 2;
109 editorComposite.setLayoutData(gridData);
111 fColorList = new List(editorComposite,
112 SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
113 gridData = new GridData(
114 GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL);
115 gridData.heightHint = convertHeightInCharsToPixels(control, 8);
116 fColorList.setLayoutData(gridData);
117 fColorList.addSelectionListener(new SelectionListener() {
118 public void widgetDefaultSelected(SelectionEvent e) {
121 public void widgetSelected(SelectionEvent e) {
122 handleColorListSelection();
126 Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
127 layout = new GridLayout();
128 layout.marginHeight = 0;
129 layout.marginWidth = 0;
130 layout.numColumns = 2;
131 stylesComposite.setLayout(layout);
132 stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
133 label = new Label(stylesComposite, SWT.LEFT);
134 label.setText(getString("color")); //$NON-NLS-1$
135 gridData = new GridData();
136 gridData.horizontalAlignment = GridData.BEGINNING;
137 label.setLayoutData(gridData);
139 fColorSelector = new ColorSelector(stylesComposite);
140 Button foregroundColorButton = fColorSelector.getButton();
141 gridData = new GridData(GridData.FILL_HORIZONTAL);
142 gridData.horizontalAlignment = GridData.BEGINNING;
143 foregroundColorButton.setLayoutData(gridData);
144 foregroundColorButton.addSelectionListener(new SelectionListener() {
145 public void widgetDefaultSelected(SelectionEvent e) {
148 public void widgetSelected(SelectionEvent e) {
149 int i = fColorList.getSelectionIndex();
150 String key = fColorListModel[i][1];
151 PreferenceConverter.setValue(getPreferenceStore(), key,
152 fColorSelector.getColorValue());
161 // Event Handlers ----------------------------------------------------------
163 void handleColorListSelection() {
164 int i = fColorList.getSelectionIndex();
165 String key = fColorListModel[i][1];
166 RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
167 fColorSelector.setColorValue(rgb);
170 // Private Methods ---------------------------------------------------------
172 private static String getString(String key) {
173 return CssUIMessages.getString(
174 "CssEditorPreferencePage.appearance." + key); //$NON-NLS-1$
177 private void initialize() {
178 for (int i = 0; i < fColorListModel.length; i++) {
179 fColorList.add(fColorListModel[i][0]);
181 fColorList.getDisplay().asyncExec(new Runnable() {
183 if ((fColorList != null)
184 && !fColorList.isDisposed()) {
185 fColorList.select(0);
186 handleColorListSelection();