1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets; 22 23 24 import org.eclipse.jface.dialogs.Dialog; 25 import org.eclipse.jface.dialogs.IDialogConstants; 26 import org.eclipse.jface.resource.JFaceResources; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.graphics.FontMetrics; 29 import org.eclipse.swt.graphics.GC; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.layout.GridLayout; 32 import org.eclipse.swt.widgets.Button; 33 import org.eclipse.swt.widgets.Combo; 34 import org.eclipse.swt.widgets.Composite; 35 import org.eclipse.swt.widgets.Group; 36 import org.eclipse.swt.widgets.Label; 37 import org.eclipse.swt.widgets.Link; 38 import org.eclipse.swt.widgets.Text; 39 40 41 47 public class BaseWidgetUtils 48 { 49 50 58 public static Group createGroup( Composite parent, String label, int span ) 59 { 60 Group group = new Group( parent, SWT.NONE ); 61 GridData gd = new GridData( GridData.FILL_BOTH ); 62 gd.horizontalSpan = span; 63 group.setLayoutData( gd ); 64 group.setText( label ); 65 group.setLayout( new GridLayout() ); 66 return group; 67 } 68 69 70 79 public static Composite createColumnContainer( Composite parent, int columnCount, int span ) 80 { 81 Composite container = new Composite( parent, SWT.NONE ); 82 GridLayout gl = new GridLayout( columnCount, false ); 83 gl.marginHeight = gl.marginWidth = 0; 84 container.setLayout( gl ); 85 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 86 gd.horizontalSpan = span; 87 container.setLayoutData( gd ); 88 return container; 89 } 90 91 92 100 public static Label createLabel( Composite parent, String text, int span ) 101 { 102 Label l = new Label( parent, SWT.NONE ); 103 GridData gd = new GridData(); 104 gd.horizontalSpan = span; 105 l.setLayoutData( gd ); 107 l.setText( text ); 108 return l; 109 } 110 111 112 121 public static Label createWrappedLabel( Composite parent, String text, int span ) 122 { 123 Label l = new Label( parent, SWT.WRAP ); 124 GridData gd = new GridData(); 125 gd.horizontalSpan = span; 126 l.setLayoutData( gd ); 128 l.setText( text ); 129 return l; 130 } 131 132 133 142 public static Text createText( Composite parent, String text, int span ) 143 { 144 Text t = new Text( parent, SWT.NONE | SWT.BORDER ); 145 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 146 gd.horizontalSpan = span; 147 t.setLayoutData( gd ); 148 t.setText( text ); 149 return t; 150 } 151 152 153 163 public static Text createText( Composite parent, String text, int textWidth, int span ) 164 { 165 Text t = new Text( parent, SWT.NONE | SWT.BORDER ); 166 GridData gd = new GridData(); 167 gd.horizontalSpan = span; 168 gd.widthHint = 9 * textWidth; 169 t.setLayoutData( gd ); 170 t.setText( text ); 171 t.setTextLimit( textWidth ); 172 return t; 173 } 174 175 176 185 public static Text createPasswordText( Composite parent, String text, int span ) 186 { 187 Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.PASSWORD ); 188 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 189 gd.horizontalSpan = span; 190 t.setLayoutData( gd ); 191 t.setText( text ); 192 return t; 193 } 194 195 196 206 public static Text createReadonlyPasswordText( Composite parent, String text, int span ) 207 { 208 Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.PASSWORD | SWT.READ_ONLY ); 209 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 210 gd.horizontalSpan = span; 211 t.setLayoutData( gd ); 212 t.setEditable( false ); 213 t.setBackground( parent.getBackground() ); 214 t.setText( text ); 215 return t; 216 } 217 218 219 230 public static Text createLabeledText( Composite parent, String text, int span ) 231 { 232 Text t = new Text( parent, SWT.NONE ); 233 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 234 gd.horizontalSpan = span; 235 t.setLayoutData( gd ); 236 t.setEditable( false ); 237 t.setBackground( parent.getBackground() ); 238 t.setText( text ); 239 return t; 240 } 241 242 243 255 public static Text createWrappedLabeledText( Composite parent, String text, int span ) 256 { 257 Text t = new Text( parent, SWT.WRAP ); 258 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 259 gd.horizontalSpan = span; 260 gd.widthHint = 10; 261 gd.grabExcessHorizontalSpace = true; 262 gd.horizontalAlignment = GridData.FILL; 263 t.setLayoutData( gd ); 264 t.setEditable( false ); 265 t.setBackground( parent.getBackground() ); 266 t.setText( text ); 267 return t; 268 } 269 270 271 281 public static Text createReadonlyText( Composite parent, String text, int span ) 282 { 283 Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.READ_ONLY ); 284 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 285 gd.horizontalSpan = span; 286 t.setLayoutData( gd ); 287 t.setEditable( false ); 288 t.setBackground( parent.getBackground() ); 289 t.setText( text ); 290 return t; 291 } 292 293 294 305 public static Combo createCombo( Composite parent, String [] items, int selectedIndex, int span ) 306 { 307 Combo c = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER ); 308 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 309 gd.horizontalSpan = span; 310 c.setLayoutData( gd ); 311 c.setItems( items ); 312 c.select( selectedIndex ); 313 c.setVisibleItemCount( 20 ); 314 return c; 315 } 316 317 318 329 public static Combo createReadonlyCombo( Composite parent, String [] items, int selectedIndex, int span ) 330 { 331 Combo c = new Combo( parent, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER ); 332 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 333 gd.horizontalSpan = span; 334 c.setLayoutData( gd ); 335 c.setItems( items ); 337 c.select( selectedIndex ); 338 c.setVisibleItemCount( 20 ); 339 return c; 340 } 341 342 343 351 public static Button createCheckbox( Composite parent, String text, int span ) 352 { 353 Button checkbox = new Button( parent, SWT.CHECK ); 354 checkbox.setText( text ); 355 GridData gd = new GridData(); 356 gd.horizontalSpan = span; 357 checkbox.setLayoutData( gd ); 358 return checkbox; 359 } 360 361 362 370 public static Button createRadiobutton( Composite parent, String text, int span ) 371 { 372 Button radio = new Button( parent, SWT.RADIO ); 373 radio.setText( text ); 374 GridData gd = new GridData(); 375 gd.horizontalSpan = span; 376 radio.setLayoutData( gd ); 377 return radio; 378 } 379 380 381 390 public static Button createButton( Composite parent, String text, int span ) 391 { 392 GC gc = new GC( parent ); 393 gc.setFont( JFaceResources.getDialogFont() ); 394 FontMetrics fontMetrics = gc.getFontMetrics(); 395 gc.dispose(); 396 397 Button button = new Button( parent, SWT.PUSH ); 398 GridData gd = new GridData(); 399 gd.widthHint = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH ); 400 button.setLayoutData( gd ); 401 button.setText( text ); 402 return button; 403 } 404 405 406 412 public static void createRadioIndent( Composite parent, int span ) 413 { 414 Label l = new Label( parent, SWT.NONE ); 415 GridData gd = new GridData(); 416 gd.horizontalSpan = span; 417 gd.horizontalIndent = 22; 418 l.setLayoutData( gd ); 419 } 420 421 422 428 public static void createSpacer( Composite parent, int span ) 429 { 430 Label l = new Label( parent, SWT.NONE ); 431 GridData gd = new GridData(); 433 gd.horizontalSpan = span; 434 gd.heightHint = 1; 435 l.setLayoutData( gd ); 436 } 437 438 439 445 public static void createSeparator( Composite parent, int span ) 446 { 447 Label l = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL ); 448 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 449 gd.horizontalSpan = span; 450 l.setLayoutData( gd ); 452 } 453 454 455 463 public static Link createLink( Composite parent, String text, int span ) 464 { 465 Link link = new Link( parent, SWT.NONE ); 466 link.setText( text ); 467 GridData gd = new GridData( SWT.FILL, SWT.BEGINNING, true, false ); 468 gd.horizontalSpan = span; 469 gd.widthHint = 150; 470 link.setLayoutData( gd ); 471 return link; 472 } 473 474 } 475 | Popular Tags |