]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2012 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.ui.preferences; | |
12 | ||
13 | import java.util.ArrayList; | |
14 | ||
15 | import org.eclipse.swt.SWT; | |
16 | import org.eclipse.swt.events.SelectionAdapter; | |
17 | import org.eclipse.swt.events.SelectionEvent; | |
18 | import org.eclipse.swt.events.SelectionListener; | |
19 | import org.eclipse.swt.graphics.FontMetrics; | |
20 | import org.eclipse.swt.graphics.GC; | |
21 | import org.eclipse.swt.graphics.Point; | |
22 | import org.eclipse.swt.graphics.RGB; | |
23 | import org.eclipse.swt.layout.GridData; | |
24 | import org.eclipse.swt.layout.GridLayout; | |
25 | import org.eclipse.swt.widgets.Button; | |
26 | import org.eclipse.swt.widgets.Composite; | |
27 | import org.eclipse.swt.widgets.Control; | |
28 | import org.eclipse.swt.widgets.Display; | |
29 | import org.eclipse.swt.widgets.Label; | |
30 | import org.eclipse.swt.widgets.Link; | |
31 | import org.eclipse.swt.widgets.List; | |
32 | import org.eclipse.swt.widgets.Shell; | |
33 | ||
34 | import org.eclipse.jface.dialogs.Dialog; | |
35 | import org.eclipse.jface.layout.PixelConverter; | |
36 | import org.eclipse.jface.preference.ColorSelector; | |
37 | import org.eclipse.jface.preference.PreferenceConverter; | |
38 | import org.eclipse.jface.preference.PreferencePage; | |
39 | import org.eclipse.jface.resource.JFaceResources; | |
40 | ||
41 | import org.eclipse.ui.dialogs.PreferencesUtil; | |
42 | ||
43 | import org.eclipse.jdt.ui.PreferenceConstants; | |
44 | ||
45 | import org.eclipse.jdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey; | |
46 | import org.eclipse.jdt.internal.ui.text.java.hover.SourceViewerInformationControl; | |
47 | ||
48 | ||
49 | /** | |
50 | * Configures Java Editor hover preferences. | |
51 | * | |
52 | * @since 2.1 | |
53 | */ | |
54 | class JavaEditorAppearanceConfigurationBlock extends AbstractConfigurationBlock { | |
55 | ||
56 | private final String[][] fAppearanceColorListModel= new String[][] { | |
57 | {PreferencesMessages.JavaEditorPreferencePage_matchingBracketsHighlightColor2, PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR, null}, | |
58 | {PreferencesMessages.JavaEditorPreferencePage_backgroundForMethodParameters, PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND, null }, | |
59 | {PreferencesMessages.JavaEditorPreferencePage_foregroundForMethodParameters, PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND, null }, | |
60 | {PreferencesMessages.JavaEditorPreferencePage_backgroundForCompletionReplacement, PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND, null }, | |
61 | {PreferencesMessages.JavaEditorPreferencePage_foregroundForCompletionReplacement, PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND, null }, | |
62 | {PreferencesMessages.JavaEditorPreferencePage_sourceHoverBackgroundColor, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT}, | |
63 | ||
64 | }; | |
65 | ||
66 | private List fAppearanceColorList; | |
67 | private ColorSelector fAppearanceColorEditor; | |
68 | private Button fAppearanceColorDefault; | |
69 | ||
70 | private FontMetrics fFontMetrics; | |
71 | ||
72 | private Button fBracketHighlightingCheckbox; | |
73 | ||
74 | private Button fMatchingBracketRadioButton; | |
75 | ||
76 | private Button fMatchingBracketAndCaretLocationRadioButton; | |
77 | ||
78 | private Button fEnclosingBracketsRadioButton; | |
79 | ||
80 | public JavaEditorAppearanceConfigurationBlock(PreferencePage mainPreferencePage, OverlayPreferenceStore store) { | |
81 | super(store, mainPreferencePage); | |
82 | getPreferenceStore().addKeys(createOverlayStoreKeys()); | |
83 | } | |
84 | ||
85 | ||
86 | private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() { | |
87 | ||
88 | ArrayList<OverlayKey> overlayKeys= new ArrayList<OverlayKey>(); | |
89 | ||
90 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR)); | |
91 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MATCHING_BRACKETS)); | |
92 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION)); | |
93 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_ENCLOSING_BRACKETS)); | |
94 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_QUICKASSIST_LIGHTBULB)); | |
95 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION)); | |
96 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS)); | |
97 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SHOW_SEGMENTS)); | |
98 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND)); | |
99 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND)); | |
100 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND)); | |
101 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND)); | |
102 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR)); | |
103 | overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT)); | |
104 | ||
105 | OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; | |
106 | overlayKeys.toArray(keys); | |
107 | return keys; | |
108 | } | |
109 | ||
110 | /** | |
111 | * Creates page for appearance preferences. | |
112 | * | |
113 | * @param parent the parent composite | |
114 | * @return the control for the preference page | |
115 | */ | |
116 | public Control createControl(Composite parent) { | |
117 | initializeDialogUnits(parent); | |
118 | ||
119 | ScrolledPageContent scrolled= new ScrolledPageContent(parent, SWT.H_SCROLL | SWT.V_SCROLL); | |
120 | scrolled.generated_8790166581341291678(); | |
121 | ||
122 | ||
123 | Composite composite= new Composite(scrolled, SWT.NONE); | |
124 | GridLayout layout= new GridLayout(); | |
125 | layout.marginWidth= 0; | |
126 | layout.marginHeight= 0; | |
127 | composite.setLayout(layout); | |
128 | ||
129 | createHeader(composite); | |
130 | createAppearancePage(composite); | |
131 | ||
132 | scrolled.setContent(composite); | |
133 | final Point size= composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); | |
134 | scrolled.setMinSize(size.x, size.y); | |
135 | return scrolled; | |
136 | ||
137 | } | |
138 | ||
139 | ||
140 | private void createHeader(Composite contents) { | |
141 | final Shell shell= contents.getShell(); | |
142 | String text= PreferencesMessages.JavaEditorPreferencePage_link; | |
143 | Link link= new Link(contents, SWT.NONE); | |
144 | link.setText(text); | |
145 | link.addSelectionListener(new SelectionAdapter() { | |
146 | @Override | |
147 | public void widgetSelected(SelectionEvent e) { | |
148 | if ("org.eclipse.ui.preferencePages.GeneralTextEditor".equals(e.text)) //$NON-NLS-1$ | |
149 | PreferencesUtil.createPreferenceDialogOn(shell, e.text, null, null); | |
150 | else if ("org.eclipse.ui.preferencePages.ColorsAndFonts".equals(e.text)) //$NON-NLS-1$ | |
151 | PreferencesUtil.createPreferenceDialogOn(shell, e.text, null, "selectFont:org.eclipse.jdt.ui.editors.textfont"); //$NON-NLS-1$ | |
152 | } | |
153 | }); | |
154 | ||
155 | GridData gridData= new GridData(SWT.FILL, SWT.BEGINNING, true, false); | |
156 | gridData.widthHint= 150; // only expand further if anyone else requires it | |
157 | link.setLayoutData(gridData); | |
158 | ||
159 | addFiller(contents); | |
160 | } | |
161 | ||
162 | private void addFiller(Composite composite) { | |
163 | PixelConverter pixelConverter= new PixelConverter(composite); | |
164 | ||
165 | Label filler= new Label(composite, SWT.LEFT ); | |
166 | GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); | |
167 | gd.horizontalSpan= 2; | |
168 | gd.heightHint= pixelConverter.convertHeightInCharsToPixels(1) / 2; | |
169 | filler.setLayoutData(gd); | |
170 | } | |
171 | ||
172 | /** | |
173 | * Returns the number of pixels corresponding to the width of the given | |
174 | * number of characters. | |
175 | * <p> | |
176 | * This method may only be called after <code>initializeDialogUnits</code> | |
177 | * has been called. | |
178 | * </p> | |
179 | * <p> | |
180 | * Clients may call this framework method, but should not override it. | |
181 | * </p> | |
182 | * | |
183 | * @param chars | |
184 | * the number of characters | |
185 | * @return the number of pixels | |
186 | */ | |
187 | protected int convertWidthInCharsToPixels(int chars) { | |
188 | // test for failure to initialize for backward compatibility | |
189 | if (fFontMetrics == null) | |
190 | return 0; | |
191 | return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars); | |
192 | } | |
193 | ||
194 | /** | |
195 | * Returns the number of pixels corresponding to the height of the given | |
196 | * number of characters. | |
197 | * <p> | |
198 | * This method may only be called after <code>initializeDialogUnits</code> | |
199 | * has been called. | |
200 | * </p> | |
201 | * <p> | |
202 | * Clients may call this framework method, but should not override it. | |
203 | * </p> | |
204 | * | |
205 | * @param chars | |
206 | * the number of characters | |
207 | * @return the number of pixels | |
208 | */ | |
209 | protected int convertHeightInCharsToPixels(int chars) { | |
210 | // test for failure to initialize for backward compatibility | |
211 | if (fFontMetrics == null) | |
212 | return 0; | |
213 | return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars); | |
214 | } | |
215 | ||
216 | private Control createAppearancePage(Composite parent) { | |
217 | ||
218 | Composite appearanceComposite= new Composite(parent, SWT.NONE); | |
219 | GridLayout layout= new GridLayout(); | |
220 | layout.numColumns= 2; | |
221 | appearanceComposite.setLayout(layout); | |
222 | ||
223 | String label; | |
224 | ||
225 | label= PreferencesMessages.JavaEditorPreferencePage_subWordNavigation; | |
226 | addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION, 0); | |
227 | ||
228 | label= PreferencesMessages.JavaEditorPreferencePage_analyseAnnotationsWhileTyping; | |
229 | addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS, 0); | |
230 | ||
231 | String text= PreferencesMessages.SmartTypingConfigurationBlock_annotationReporting_link; | |
232 | addLink(appearanceComposite, text, INDENT); | |
233 | ||
234 | Label spacer= new Label(appearanceComposite, SWT.LEFT ); | |
235 | GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); | |
236 | gd.horizontalSpan= 2; | |
237 | gd.heightHint= convertHeightInCharsToPixels(1) / 2; | |
238 | spacer.setLayoutData(gd); | |
239 | ||
240 | label= PreferencesMessages.JavaEditorPreferencePage_bracketHighlighting; | |
241 | fBracketHighlightingCheckbox= addButton(appearanceComposite, SWT.CHECK, label, 0, new SelectionAdapter() { | |
242 | @Override | |
243 | public void widgetSelected(SelectionEvent e) { | |
244 | getPreferenceStore().setValue(PreferenceConstants.EDITOR_MATCHING_BRACKETS, fBracketHighlightingCheckbox.getSelection()); | |
245 | } | |
246 | }); | |
247 | ||
248 | Composite radioComposite= new Composite(appearanceComposite, SWT.NONE); | |
249 | GridLayout radioLayout= new GridLayout(); | |
250 | radioLayout.marginWidth= 0; | |
251 | radioLayout.marginHeight= 0; | |
252 | radioComposite.setLayout(radioLayout); | |
253 | ||
254 | label= PreferencesMessages.JavaEditorPreferencePage_highlightMatchingBracket; | |
255 | fMatchingBracketRadioButton= addButton(radioComposite, SWT.RADIO, label, 0, new SelectionAdapter() { | |
256 | @Override | |
257 | public void widgetSelected(SelectionEvent e) { | |
258 | if (fMatchingBracketRadioButton.getSelection()) | |
259 | getPreferenceStore().setValue(PreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION, false); | |
260 | } | |
261 | }); | |
262 | createDependency(fBracketHighlightingCheckbox, fMatchingBracketRadioButton); | |
263 | ||
264 | label= PreferencesMessages.JavaEditorPreferencePage_highlightMatchingBracketAndCaretLocation; | |
265 | fMatchingBracketAndCaretLocationRadioButton= addButton(radioComposite, SWT.RADIO, label, 0, new SelectionAdapter() { | |
266 | @Override | |
267 | public void widgetSelected(SelectionEvent e) { | |
268 | if (fMatchingBracketAndCaretLocationRadioButton.getSelection()) | |
269 | getPreferenceStore().setValue(PreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION, true); | |
270 | } | |
271 | }); | |
272 | createDependency(fBracketHighlightingCheckbox, fMatchingBracketAndCaretLocationRadioButton); | |
273 | ||
274 | label= PreferencesMessages.JavaEditorPreferencePage_highlightEnclosingBrackets; | |
275 | fEnclosingBracketsRadioButton= addButton(radioComposite, SWT.RADIO, label, 0, new SelectionAdapter() { | |
276 | @Override | |
277 | public void widgetSelected(SelectionEvent e) { | |
278 | boolean selection= fEnclosingBracketsRadioButton.getSelection(); | |
279 | getPreferenceStore().setValue(PreferenceConstants.EDITOR_ENCLOSING_BRACKETS, selection); | |
280 | if (selection) | |
281 | getPreferenceStore().setValue(PreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION, true); | |
282 | } | |
283 | }); | |
284 | createDependency(fBracketHighlightingCheckbox, fEnclosingBracketsRadioButton); | |
285 | ||
286 | spacer= new Label(appearanceComposite, SWT.LEFT); | |
287 | gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); | |
288 | gd.horizontalSpan= 2; | |
289 | gd.heightHint= convertHeightInCharsToPixels(1) / 2; | |
290 | spacer.setLayoutData(gd); | |
291 | ||
292 | label= PreferencesMessages.JavaEditorPreferencePage_quickassist_lightbulb; | |
293 | addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_QUICKASSIST_LIGHTBULB, 0); | |
294 | ||
295 | label= PreferencesMessages.JavaEditorPreferencePage_showJavaElementOnly; | |
296 | addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_SHOW_SEGMENTS, 0); | |
297 | ||
298 | Label l= new Label(appearanceComposite, SWT.LEFT ); | |
299 | gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); | |
300 | gd.horizontalSpan= 2; | |
301 | gd.heightHint= convertHeightInCharsToPixels(1) / 2; | |
302 | l.setLayoutData(gd); | |
303 | ||
304 | l= new Label(appearanceComposite, SWT.LEFT); | |
305 | l.setText(PreferencesMessages.JavaEditorPreferencePage_appearanceOptions); | |
306 | gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); | |
307 | gd.horizontalSpan= 2; | |
308 | l.setLayoutData(gd); | |
309 | ||
310 | Composite editorComposite= new Composite(appearanceComposite, SWT.NONE); | |
311 | layout= new GridLayout(); | |
312 | layout.numColumns= 2; | |
313 | layout.marginHeight= 0; | |
314 | layout.marginWidth= 0; | |
315 | editorComposite.setLayout(layout); | |
316 | gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); | |
317 | gd.horizontalSpan= 2; | |
318 | editorComposite.setLayoutData(gd); | |
319 | ||
320 | fAppearanceColorList= new List(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); | |
321 | gd= new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL); | |
322 | gd.heightHint= convertHeightInCharsToPixels(12); | |
323 | fAppearanceColorList.setLayoutData(gd); | |
324 | ||
325 | Composite stylesComposite= new Composite(editorComposite, SWT.NONE); | |
326 | layout= new GridLayout(); | |
327 | layout.marginHeight= 0; | |
328 | layout.marginWidth= 0; | |
329 | layout.numColumns= 2; | |
330 | stylesComposite.setLayout(layout); | |
331 | stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
332 | ||
333 | l= new Label(stylesComposite, SWT.LEFT); | |
334 | l.setText(PreferencesMessages.JavaEditorPreferencePage_color); | |
335 | gd= new GridData(); | |
336 | gd.horizontalAlignment= GridData.BEGINNING; | |
337 | l.setLayoutData(gd); | |
338 | ||
339 | fAppearanceColorEditor= new ColorSelector(stylesComposite); | |
340 | Button foregroundColorButton= fAppearanceColorEditor.getButton(); | |
341 | gd= new GridData(GridData.FILL_HORIZONTAL); | |
342 | gd.horizontalAlignment= GridData.BEGINNING; | |
343 | foregroundColorButton.setLayoutData(gd); | |
344 | ||
345 | SelectionListener colorDefaultSelectionListener= new SelectionListener() { | |
346 | public void widgetSelected(SelectionEvent e) { | |
347 | boolean systemDefault= fAppearanceColorDefault.getSelection(); | |
348 | fAppearanceColorEditor.getButton().setEnabled(!systemDefault); | |
349 | ||
350 | int i= fAppearanceColorList.getSelectionIndex(); | |
351 | if (i == -1) | |
352 | return; | |
353 | ||
354 | String key= fAppearanceColorListModel[i][2]; | |
355 | if (key != null) | |
356 | getPreferenceStore().setValue(key, systemDefault); | |
357 | } | |
358 | public void widgetDefaultSelected(SelectionEvent e) {} | |
359 | }; | |
360 | ||
361 | fAppearanceColorDefault= new Button(stylesComposite, SWT.CHECK); | |
362 | fAppearanceColorDefault.setText(PreferencesMessages.JavaEditorPreferencePage_systemDefault); | |
363 | gd= new GridData(GridData.FILL_HORIZONTAL); | |
364 | gd.horizontalAlignment= GridData.BEGINNING; | |
365 | gd.horizontalSpan= 2; | |
366 | fAppearanceColorDefault.setLayoutData(gd); | |
367 | fAppearanceColorDefault.setVisible(false); | |
368 | fAppearanceColorDefault.addSelectionListener(colorDefaultSelectionListener); | |
369 | ||
370 | fAppearanceColorList.addSelectionListener(new SelectionListener() { | |
371 | public void widgetDefaultSelected(SelectionEvent e) { | |
372 | // do nothing | |
373 | } | |
374 | public void widgetSelected(SelectionEvent e) { | |
375 | handleAppearanceColorListSelection(); | |
376 | } | |
377 | }); | |
378 | foregroundColorButton.addSelectionListener(new SelectionListener() { | |
379 | public void widgetDefaultSelected(SelectionEvent e) { | |
380 | // do nothing | |
381 | } | |
382 | public void widgetSelected(SelectionEvent e) { | |
383 | int i= fAppearanceColorList.getSelectionIndex(); | |
384 | if (i == -1) | |
385 | return; | |
386 | ||
387 | String key= fAppearanceColorListModel[i][1]; | |
388 | PreferenceConverter.setValue(getPreferenceStore(), key, fAppearanceColorEditor.getColorValue()); | |
389 | } | |
390 | }); | |
391 | return appearanceComposite; | |
392 | } | |
393 | ||
394 | private Button addButton(Composite parent, int style, String label, int indentation, SelectionListener listener) { | |
395 | Button button= new Button(parent, style); | |
396 | button.setText(label); | |
397 | ||
398 | GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); | |
399 | gd.horizontalIndent= indentation; | |
400 | gd.horizontalSpan= 2; | |
401 | button.setLayoutData(gd); | |
402 | button.addSelectionListener(listener); | |
403 | makeScrollableCompositeAware(button); | |
404 | ||
405 | return button; | |
406 | } | |
407 | ||
408 | private void addLink(Composite composite, String text, int indent) { | |
409 | GridData gd; | |
410 | final Link link= new Link(composite, SWT.NONE); | |
411 | link.setText(text); | |
412 | gd= new GridData(SWT.FILL, SWT.BEGINNING, true, false); | |
413 | gd.widthHint= 300; // don't get wider initially | |
414 | gd.horizontalSpan= 2; | |
415 | gd.horizontalIndent= indent; | |
416 | link.setLayoutData(gd); | |
417 | link.addSelectionListener(new SelectionAdapter() { | |
418 | @Override | |
419 | public void widgetSelected(SelectionEvent e) { | |
420 | PreferencesUtil.createPreferenceDialogOn(link.getShell(), e.text, null, null); | |
421 | } | |
422 | }); | |
423 | } | |
424 | ||
425 | private void handleAppearanceColorListSelection() { | |
426 | int i= fAppearanceColorList.getSelectionIndex(); | |
427 | if (i == -1) | |
428 | return; | |
429 | String key= fAppearanceColorListModel[i][1]; | |
430 | RGB rgb= PreferenceConverter.getColor(getPreferenceStore(), key); | |
431 | fAppearanceColorEditor.setColorValue(rgb); | |
432 | updateAppearanceColorWidgets(fAppearanceColorListModel[i][2]); | |
433 | } | |
434 | ||
435 | private void updateAppearanceColorWidgets(String systemDefaultKey) { | |
436 | if (systemDefaultKey == null) { | |
437 | fAppearanceColorDefault.setSelection(false); | |
438 | fAppearanceColorDefault.setVisible(false); | |
439 | fAppearanceColorEditor.getButton().setEnabled(true); | |
440 | } else { | |
441 | boolean systemDefault= getPreferenceStore().getBoolean(systemDefaultKey); | |
442 | fAppearanceColorDefault.setSelection(systemDefault); | |
443 | fAppearanceColorDefault.setVisible(true); | |
444 | fAppearanceColorEditor.getButton().setEnabled(!systemDefault); | |
445 | } | |
446 | } | |
447 | ||
448 | /* | |
449 | * @see org.eclipse.jdt.internal.ui.preferences.IPreferenceConfigurationBlock#initialize() | |
450 | */ | |
451 | @Override | |
452 | public void initialize() { | |
453 | initializeBracketHighlightingPreferences(); | |
454 | super.initialize(); // also updates state of slaves, hence it is the second call | |
455 | initializeDefaultColors(); | |
456 | ||
457 | for (int i= 0; i < fAppearanceColorListModel.length; i++) | |
458 | fAppearanceColorList.add(fAppearanceColorListModel[i][0]); | |
459 | ||
460 | fAppearanceColorList.getDisplay().asyncExec(new Runnable() { | |
461 | public void run() { | |
462 | if (fAppearanceColorList != null && !fAppearanceColorList.isDisposed()) { | |
463 | fAppearanceColorList.select(0); | |
464 | handleAppearanceColorListSelection(); | |
465 | } | |
466 | } | |
467 | }); | |
468 | ||
469 | } | |
470 | ||
471 | private void initializeBracketHighlightingPreferences() { | |
472 | boolean matchingBrackets= getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_MATCHING_BRACKETS); | |
473 | boolean highlightBracketAtCaretLocation= getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_HIGHLIGHT_BRACKET_AT_CARET_LOCATION); | |
474 | boolean enclosingBrackets= getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ENCLOSING_BRACKETS); | |
475 | ||
476 | fBracketHighlightingCheckbox.setSelection(matchingBrackets); | |
477 | fEnclosingBracketsRadioButton.setSelection(enclosingBrackets); | |
478 | if (!enclosingBrackets) { | |
479 | fMatchingBracketRadioButton.setSelection(!highlightBracketAtCaretLocation); | |
480 | fMatchingBracketAndCaretLocationRadioButton.setSelection(highlightBracketAtCaretLocation); | |
481 | } | |
482 | } | |
483 | ||
484 | /** | |
485 | * Initializes the default colors. | |
486 | * | |
487 | * @since 3.3 | |
488 | */ | |
489 | private void initializeDefaultColors() { | |
490 | if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT)) { | |
491 | Display display= fAppearanceColorList.getDisplay(); | |
492 | RGB rgb= SourceViewerInformationControl.getVisibleBackgroundColor(display); | |
493 | if (rgb == null) | |
494 | rgb= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB(); | |
495 | PreferenceConverter.setValue(getPreferenceStore(), PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR, rgb); | |
496 | } | |
497 | } | |
498 | ||
499 | /* | |
500 | * @see org.eclipse.jdt.internal.ui.preferences.IPreferenceConfigurationBlock#performDefaults() | |
501 | */ | |
502 | @Override | |
503 | public void performDefaults() { | |
504 | initializeBracketHighlightingPreferences(); | |
505 | super.performDefaults(); | |
506 | initializeDefaultColors(); | |
507 | handleAppearanceColorListSelection(); | |
508 | } | |
509 | ||
510 | /** | |
511 | * Initializes the computation of horizontal and vertical dialog units based | |
512 | * on the size of current font. | |
513 | * <p> | |
514 | * This method must be called before any of the dialog unit based conversion | |
515 | * methods are called. | |
516 | * </p> | |
517 | * | |
518 | * @param testControl | |
519 | * a control from which to obtain the current font | |
520 | */ | |
521 | protected void initializeDialogUnits(Control testControl) { | |
522 | // Compute and store a font metric | |
523 | GC gc = new GC(testControl); | |
524 | gc.setFont(JFaceResources.getDialogFont()); | |
525 | fFontMetrics = gc.getFontMetrics(); | |
526 | gc.dispose(); | |
527 | } | |
528 | ||
529 | } |