source: trunk/tests/SWT/java/SWT008_04.java

Last change on this file was 12, checked in by lpino, 18 years ago
  • Initial commit
File size: 2.7 KB
Line 
1/*
2* SWT008_04.java
3*/
4
5/*
6* Copyright (c) 2002, 2004 EclipseOS2 Team.
7* This file is made available under the terms of the Common Public License v1.0
8* which accompanies this distribution, and is available at
9* http://www.eclipse.org/legal/cpl-v10.html
10*/
11
12import org.eclipse.swt.*;
13import org.eclipse.swt.widgets.*;
14import org.eclipse.swt.events.*;
15import org.eclipse.swt.graphics.*;
16import org.eclipse.swt.layout.*;
17
18/**
19* A simple testcase that allows to call the font dialog changing the font of the text displaying
20 * the fonts attribute.
21*/
22
23public class SWT008_04 extends SWTTestCase {
24 boolean drawCheckers = false;
25 Class fmHndCls;
26 String platform;
27 Image background = null;
28
29 static {
30 STEP = "008";
31 TEST = "04";
32 DESC = "Color Dialog";
33 }
34
35 public static void main (String [] args) {
36 go (new SWT008_04 ());
37 }
38
39 Shell createTopShell (Display display) {
40 return new Shell (display,SWT.SHELL_TRIM | SWT.NO_REDRAW_RESIZE);
41 }
42
43 void initComponents () {
44 super.initComponents();
45 //Initiates the font with SystemFont
46
47 Composite bottom = new Composite (shell, 0);
48 Composite group1 = new Composite (bottom, SWT.NO_BACKGROUND);
49 group1.setLayout (new FillLayout (SWT.HORIZONTAL));
50
51 shell.setLayout(new GridLayout(2, false));
52 final Button button = new Button(group1, SWT.PUSH);
53 button.setText("Change Color...");
54 button.addSelectionListener(new SelectionAdapter() {
55 public void widgetSelected(SelectionEvent event) {
56 ColorDialog dlg = new ColorDialog(shell);
57 dlg.setRGB(new RGB(255, 255, 255));
58 RGB newColor = dlg.open();
59 if (newColor == null){
60 return;
61 }
62 else{
63 shell.setBackground(new Color(display, newColor));
64 System.out.println("RED = " + newColor.red);
65 System.out.println("GREEN = " + newColor.green);
66 System.out.println("BLUE = " + newColor.blue);
67 }
68 }
69 });
70
71 FormData fdata = new FormData();
72 fdata.right = new FormAttachment (100, 0);
73 fdata.bottom = new FormAttachment (100, 0);
74 group1.setLayoutData (fdata);
75 FormLayout formLayout = new FormLayout ();
76 bottom.setLayout (formLayout);
77
78 Rectangle dr = display.getBounds ();
79 Rectangle sr = new Rectangle (0, 0, 300, 100);
80 sr.x = (dr.width-sr.width)/2;
81 sr.y = (dr.height-sr.height)/2;
82 shell.setBounds (sr);
83
84 }
85}
86
87
Note: See TracBrowser for help on using the repository browser.