001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.ui.internal.layout;
011:
012: import org.eclipse.jface.dialogs.Dialog;
013: import org.eclipse.swt.SWT;
014: import org.eclipse.swt.layout.GridData;
015: import org.eclipse.swt.layout.GridLayout;
016: import org.eclipse.swt.widgets.Button;
017: import org.eclipse.swt.widgets.Composite;
018: import org.eclipse.swt.widgets.Control;
019: import org.eclipse.swt.widgets.Label;
020: import org.eclipse.swt.widgets.Shell;
021: import org.eclipse.swt.widgets.Text;
022: import org.eclipse.ui.internal.TrimDragPreferences;
023:
024: /**
025: * This dialog allows the User to modify the <code>TrimDragPreferences</code>.
026: *
027: * <p><b>
028: * NOTE: this is a test harness at this time. This class may be removed
029: * before the release of 3.2.
030: * </b></p>
031: *
032: * @since 3.2
033: *
034: */
035: public class TrimDragPreferenceDialog extends Dialog {
036:
037: private Text thresholdValue;
038: private Button raggedTrimButton;
039:
040: /**
041: * @param parentShell
042: */
043: public TrimDragPreferenceDialog(Shell parentShell) {
044: super (parentShell);
045: }
046:
047: /* (non-Javadoc)
048: * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
049: */
050: protected Control createDialogArea(Composite parent) {
051: Composite composite = new Composite(parent, SWT.NONE);
052: composite.setLayout(new GridLayout(2, false));
053:
054: Label disclaimer = new Label(composite, SWT.BORDER | SWT.WRAP);
055: disclaimer
056: .setText("NOTE: This dialog is for testing purposes -only- and " + //$NON-NLS-1$
057: " will be removed from the code before release."); //$NON-NLS-1$
058: disclaimer.setForeground(getShell().getDisplay()
059: .getSystemColor(SWT.COLOR_DARK_RED));
060:
061: // Filler to leave a blank line
062: new Label(composite, SWT.NONE);
063: new Label(composite, SWT.NONE);
064:
065: GridData dgd = new GridData();
066: dgd.grabExcessHorizontalSpace = true;
067: dgd.horizontalSpan = 2;
068: dgd.minimumWidth = 50;
069: disclaimer.setLayoutData(dgd);
070:
071: // Create a control to change the threshold value
072: Label tLabel = new Label(composite, SWT.NONE);
073: tLabel.setText("Drag Threshold"); //$NON-NLS-1$
074:
075: thresholdValue = new Text(composite, SWT.SINGLE | SWT.BORDER);
076: thresholdValue.setText(Integer.toString(TrimDragPreferences
077: .getThreshold()));
078: thresholdValue
079: .setToolTipText("The minimum distance to snap to"); //$NON-NLS-1$
080:
081: GridData tgd = new GridData();
082: tgd.grabExcessHorizontalSpace = true;
083: tgd.minimumWidth = 50;
084: thresholdValue.setLayoutData(tgd);
085:
086: // Create a control to change the layout to show 'ragged' trim
087: raggedTrimButton = new Button(composite, SWT.CHECK);
088: raggedTrimButton.setText("Ragged Trim"); //$NON-NLS-1$
089: raggedTrimButton.setSelection(TrimDragPreferences
090: .showRaggedTrim());
091: raggedTrimButton
092: .setToolTipText("Allows trim in the same area to have different heights if checked"); //$NON-NLS-1$
093:
094: GridData rgd = new GridData();
095: rgd.horizontalSpan = 2;
096: raggedTrimButton.setLayoutData(rgd);
097:
098: return composite;
099: }
100:
101: /* (non-Javadoc)
102: * @see org.eclipse.jface.dialogs.Dialog#okPressed()
103: */
104: protected void okPressed() {
105: // Update the 'threshold' pref
106: try {
107: TrimDragPreferences.setThreshold(Integer
108: .parseInt(thresholdValue.getText()));
109: } catch (NumberFormatException e) {
110: // If it fails...just leave it...
111: }
112:
113: // Update the 'ragged trim' pref
114: boolean val = raggedTrimButton.getSelection();
115: TrimDragPreferences.setRaggedTrim(val);
116:
117: super.okPressed();
118: }
119:
120: }
|