KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > layout > TrimDragPreferenceDialog


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.ui.internal.layout;
13
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.swt.widgets.Text;
24 import org.eclipse.ui.internal.TrimDragPreferences;
25
26 /**
27  * This dialog allows the User to modify the <code>TrimDragPreferences</code>.
28  *
29  * <p><b>
30  * NOTE: this is a test harness at this time. This class may be removed
31  * before the release of 3.2.
32  * </b></p>
33  *
34  * @since 3.2
35  *
36  */

37 public class TrimDragPreferenceDialog extends Dialog {
38
39     private Text thresholdValue;
40     private Button raggedTrimButton;
41     
42     /**
43      * @param parentShell
44      */

45     public TrimDragPreferenceDialog(Shell parentShell) {
46         super(parentShell);
47     }
48
49     /* (non-Javadoc)
50      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
51      */

52     protected Control createDialogArea(Composite parent) {
53         Composite composite = new Composite(parent, SWT.NONE);
54         composite.setLayout(new GridLayout(2, false));
55         
56         Label disclaimer = new Label(composite, SWT.BORDER | SWT.WRAP);
57         disclaimer.setText("NOTE: This dialog is for testing purposes -only- and "+ //$NON-NLS-1$
58
" will be removed from the code before release."); //$NON-NLS-1$
59
disclaimer.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
60
61         // Filler to leave a blank line
62
new Label(composite, SWT.NONE);
63         new Label(composite, SWT.NONE);
64         
65         GridData dgd = new GridData();
66         dgd.grabExcessHorizontalSpace = true;
67         dgd.horizontalSpan = 2;
68         dgd.minimumWidth = 50;
69         disclaimer.setLayoutData(dgd);
70         
71         // Create a control to change the threshold value
72
Label tLabel = new Label(composite, SWT.NONE);
73         tLabel.setText("Drag Threshold"); //$NON-NLS-1$
74

75         thresholdValue = new Text(composite, SWT.SINGLE | SWT.BORDER);
76         thresholdValue.setText(Integer.toString(TrimDragPreferences.getThreshold()));
77         thresholdValue.setToolTipText("The minimum distance to snap to"); //$NON-NLS-1$
78

79         GridData tgd = new GridData();
80         tgd.grabExcessHorizontalSpace = true;
81         tgd.minimumWidth = 50;
82         thresholdValue.setLayoutData(tgd);
83         
84         // Create a control to change the layout to show 'ragged' trim
85
raggedTrimButton = new Button(composite, SWT.CHECK);
86         raggedTrimButton.setText("Ragged Trim"); //$NON-NLS-1$
87
raggedTrimButton.setSelection(TrimDragPreferences.showRaggedTrim());
88         raggedTrimButton.setToolTipText("Allows trim in the same area to have different heights if checked"); //$NON-NLS-1$
89

90         GridData rgd = new GridData();
91         rgd.horizontalSpan = 2;
92         raggedTrimButton.setLayoutData(rgd);
93             
94         return composite;
95     }
96
97     /* (non-Javadoc)
98      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
99      */

100     protected void okPressed() {
101         // Update the 'threshold' pref
102
try {
103             TrimDragPreferences.setThreshold(Integer.parseInt(thresholdValue.getText()));
104         } catch (NumberFormatException JavaDoc e) {
105             // If it fails...just leave it...
106
}
107         
108         // Update the 'ragged trim' pref
109
boolean val = raggedTrimButton.getSelection();
110         TrimDragPreferences.setRaggedTrim(val);
111         
112         super.okPressed();
113     }
114
115 }
116
Popular Tags