KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > console > ConsolePreferencesPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.team.internal.ccvs.ui.console;
12
13 import org.eclipse.jface.dialogs.Dialog;
14 import org.eclipse.jface.preference.*;
15 import org.eclipse.jface.util.PropertyChangeEvent;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.team.internal.ccvs.ui.*;
21 import org.eclipse.ui.*;
22
23 public class ConsolePreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
24
25     public ConsolePreferencesPage() {
26         super(GRID);
27         setPreferenceStore(CVSUIPlugin.getPlugin().getPreferenceStore());
28     }
29     private ColorFieldEditor commandColorEditor;
30     private ColorFieldEditor messageColorEditor;
31     private ColorFieldEditor errorColorEditor;
32     private BooleanFieldEditor showOnMessage;
33     private BooleanFieldEditor restrictOutput;
34     private BooleanFieldEditor wrap;
35     private IntegerFieldEditor highWaterMark;
36     private IntegerFieldEditor width;
37
38     protected void createFieldEditors() {
39         final Composite composite = getFieldEditorParent();
40         createLabel(composite, CVSUIMessages.ConsolePreferencesPage_9);
41         IPreferenceStore store = getPreferenceStore();
42         
43         // ** WRAP
44
wrap = new BooleanFieldEditor(ICVSUIConstants.PREF_CONSOLE_WRAP, CVSUIMessages.ConsolePreferencesPage_6, composite);
45         addField(wrap);
46         
47         width = new IntegerFieldEditor(ICVSUIConstants.PREF_CONSOLE_WIDTH, CVSUIMessages.ConsolePreferencesPage_7, composite); //)
48
width.setValidRange(80, Integer.MAX_VALUE - 1);
49         addField(width);
50         width.setEnabled(store.getBoolean(ICVSUIConstants.PREF_CONSOLE_WRAP), composite);
51         
52         // ** RESTRICT OUTPUT
53
restrictOutput = new BooleanFieldEditor(ICVSUIConstants.PREF_CONSOLE_LIMIT_OUTPUT, CVSUIMessages.ConsolePreferencesPage_5, composite);
54         addField(restrictOutput);
55         
56         highWaterMark = new IntegerFieldEditor(ICVSUIConstants.PREF_CONSOLE_HIGH_WATER_MARK, CVSUIMessages.ConsolePreferencesPage_8, composite); //)
57
highWaterMark.setValidRange(1000, Integer.MAX_VALUE - 1);
58         addField(highWaterMark);
59         highWaterMark.setEnabled(store.getBoolean(ICVSUIConstants.PREF_CONSOLE_LIMIT_OUTPUT), composite);
60         
61         // ** SHOW AUTOMATICALLY
62
showOnMessage = new BooleanFieldEditor(ICVSUIConstants.PREF_CONSOLE_SHOW_ON_MESSAGE, CVSUIMessages.ConsolePreferencesPage_4, composite);
63         addField(showOnMessage);
64         
65         createLabel(composite, CVSUIMessages.ConsolePreferencePage_consoleColorSettings);
66         
67         // ** COLORS AND FONTS
68
commandColorEditor = createColorFieldEditor(ICVSUIConstants.PREF_CONSOLE_COMMAND_COLOR,
69             CVSUIMessages.ConsolePreferencePage_commandColor, composite);
70         addField(commandColorEditor);
71         
72         messageColorEditor = createColorFieldEditor(ICVSUIConstants.PREF_CONSOLE_MESSAGE_COLOR,
73             CVSUIMessages.ConsolePreferencePage_messageColor, composite);
74         addField(messageColorEditor);
75         
76         errorColorEditor = createColorFieldEditor(ICVSUIConstants.PREF_CONSOLE_ERROR_COLOR,
77             CVSUIMessages.ConsolePreferencePage_errorColor, composite);
78         addField(errorColorEditor);
79         
80         Dialog.applyDialogFont(composite);
81         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.CONSOLE_PREFERENCE_PAGE);
82     }
83     
84     
85     public void propertyChange(PropertyChangeEvent event) {
86         super.propertyChange(event);
87         highWaterMark.setEnabled(restrictOutput.getBooleanValue(), getFieldEditorParent());
88         width.setEnabled(wrap.getBooleanValue(), getFieldEditorParent());
89     }
90
91     /**
92      * Utility method that creates a label instance
93      * and sets the default layout data.
94      *
95      * @param parent the parent for the new label
96      * @param text the text for the new label
97      * @return the new label
98      */

99     private Label createLabel(Composite parent, String JavaDoc text) {
100         Label label = new Label(parent, SWT.LEFT);
101         label.setText(text);
102         GridData data = new GridData();
103         data.horizontalSpan = 2;
104         data.horizontalAlignment = GridData.FILL;
105         label.setLayoutData(data);
106         return label;
107     }
108     /**
109      * Creates a new color field editor.
110      */

111     private ColorFieldEditor createColorFieldEditor(String JavaDoc preferenceName, String JavaDoc label, Composite parent) {
112         ColorFieldEditor editor = new ColorFieldEditor(preferenceName, label, parent);
113         editor.setPreferencePage(this);
114         editor.setPreferenceStore(getPreferenceStore());
115         return editor;
116     }
117
118     /* (non-Javadoc)
119      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
120      */

121     public void init(IWorkbench workbench) {
122     }
123     
124     /* (non-Javadoc)
125      * @see org.eclipse.jface.preference.IPreferencePage#performOk()
126      */

127     public boolean performOk() {
128         CVSUIPlugin.getPlugin().savePluginPreferences();
129         return super.performOk();
130     }
131 }
132
Popular Tags