1 11 package org.eclipse.team.internal.ui.dialogs; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.jface.dialogs.*; 18 import org.eclipse.jface.dialogs.Dialog; 19 import org.eclipse.jface.util.IPropertyChangeListener; 20 import org.eclipse.jface.util.PropertyChangeEvent; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.graphics.*; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.layout.GridLayout; 25 import org.eclipse.swt.widgets.*; 26 27 31 public abstract class DialogArea { 32 33 private FontMetrics fontMetrics; 34 private List listeners; 35 36 39 protected DialogArea() { 40 this.listeners = new ArrayList (); 41 } 42 43 50 public void addPropertyChangeListener(IPropertyChangeListener listener) { 51 if (!listeners.contains(listener)) 52 listeners.add(listener); 53 } 54 59 public void removePropertyChangeListener(IPropertyChangeListener listener) { 60 listeners.remove(listener); 61 } 62 63 protected void firePropertyChangeChange(String property, Object oldValue, Object newValue) { 64 PropertyChangeEvent event = new PropertyChangeEvent(this, property, oldValue, newValue); 65 for (Iterator iter = listeners.iterator(); iter.hasNext();) { 66 IPropertyChangeListener listener = (IPropertyChangeListener) iter.next(); 67 listener.propertyChange(event); 68 } 69 } 70 71 79 protected void initializeDialogUnits(Control control) { 80 GC gc = new GC(control); 82 gc.setFont(control.getFont()); 83 fontMetrics = gc.getFontMetrics(); 84 gc.dispose(); 85 } 86 87 91 public abstract void createArea(Composite parent); 92 93 protected Button createCheckbox(Composite parent, String label, int span) { 94 Button button = new Button(parent, SWT.CHECK | SWT.LEFT); 95 button.setText(label); 96 button.setFont(parent.getFont()); 97 GridData data = new GridData(); 98 data.horizontalSpan = span; 99 button.setLayoutData(data); 100 return button; 101 } 102 103 protected Button createButton(Composite parent, String label, int style) { 104 Button button = new Button(parent, SWT.PUSH); 105 button.setText(label); 106 button.setFont(parent.getFont()); 108 GridData data = new GridData(style); 109 data.heightHint = Dialog.convertVerticalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_HEIGHT); 110 int widthHint = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH); 111 data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); 112 button.setLayoutData(data); 113 return button; 114 } 115 116 protected Button createRadioButton(Composite parent, String label, int span) { 117 Button button = new Button(parent, SWT.RADIO); 118 button.setText(label); 119 GridData data = new GridData(); 120 data.horizontalSpan = span; 121 button.setLayoutData(data); 122 return button; 123 } 124 protected Label createWrappingLabel(Composite parent, String text, int horizontalSpan) { 125 Label label = new Label(parent, SWT.LEFT | SWT.WRAP); 126 label.setText(text); 127 label.setFont(parent.getFont()); 128 GridData data = new GridData(); 129 data.horizontalSpan = horizontalSpan; 130 data.horizontalAlignment = GridData.FILL; 131 data.grabExcessHorizontalSpace = true; 132 data.widthHint= 0; 133 label.setLayoutData(data); 134 return label; 135 } 136 protected Label createLabel(Composite parent, String text, int horizontalSpan) { 137 Label label = new Label(parent, SWT.LEFT); 138 label.setText(text); 139 GridData data = new GridData(); 140 data.horizontalSpan = horizontalSpan; 141 data.horizontalAlignment = GridData.FILL; 142 label.setLayoutData(data); 143 return label; 144 } 145 152 protected Composite createComposite(Composite parent, int numColumns, boolean grab) { 153 final Composite composite = new Composite(parent, SWT.NULL); 154 final Font font = parent.getFont(); 155 composite.setFont(font); 156 157 composite.setLayout(new GridLayout(numColumns, false)); 158 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, grab, grab)); 159 160 return composite; 161 } 162 163 170 protected Composite createGrabbingComposite(Composite parent, int numColumns) { 171 Composite composite = new Composite(parent, SWT.NULL); 172 Font font = parent.getFont(); 173 composite.setFont(font); 174 175 GridLayout layout = new GridLayout(); 177 layout.numColumns = numColumns; 178 layout.marginHeight = 0; 179 layout.marginWidth = 0; 180 composite.setLayout(layout); 181 182 GridData data = new GridData(); 184 data.verticalAlignment = GridData.FILL; 185 data.horizontalAlignment = GridData.FILL; 186 data.grabExcessHorizontalSpace = true; 187 data.grabExcessVerticalSpace = true; 188 composite.setLayoutData(data); 189 return composite; 190 } 191 192 protected int convertVerticalDLUsToPixels(int dlus) { 193 return Dialog.convertVerticalDLUsToPixels(fontMetrics, dlus); 194 } 195 196 protected int convertHorizontalDLUsToPixels(int dlus) { 197 return Dialog.convertHorizontalDLUsToPixels(fontMetrics, dlus); 198 } 199 } 200 | Popular Tags |