Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3b5cb365ed57601848149f7baa5e5ab04a1c24a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*******************************************************************************
 * Copyright (c) 2000, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.examples.controlexample;


import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;

class DateTimeTab extends Tab {
	/* Example widgets and groups that contain them */
	DateTime dateTime1;
	Group dateTimeGroup;
	
	/* Style widgets added to the "Style" group */
	Button dateButton, timeButton, calendarButton, shortButton, mediumButton, longButton;
	
	/**
	 * Creates the Tab within a given instance of ControlExample.
	 */
	DateTimeTab(ControlExample instance) {
		super(instance);
	}
	
	/**
	 * Creates the "Example" group.
	 */
	void createExampleGroup () {
		super.createExampleGroup ();
		
		/* Create a group for the list */
		dateTimeGroup = new Group (exampleGroup, SWT.NONE);
		dateTimeGroup.setLayout (new GridLayout ());
		dateTimeGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
		dateTimeGroup.setText ("DateTime");
	}
	
	/**
	 * Creates the "Example" widgets.
	 */
	void createExampleWidgets () {
		
		/* Compute the widget style */
		int style = getDefaultStyle();
		if (dateButton.getSelection ()) style |= SWT.DATE;
		if (timeButton.getSelection ()) style |= SWT.TIME;
		if (calendarButton.getSelection ()) style |= SWT.CALENDAR;
		if (shortButton.getSelection ()) style |= SWT.SHORT;
		if (mediumButton.getSelection ()) style |= SWT.MEDIUM;
		if (longButton.getSelection ()) style |= SWT.LONG;
		if (borderButton.getSelection ()) style |= SWT.BORDER;
	
		/* Create the example widgets */		
		dateTime1 = new DateTime (dateTimeGroup, style);
	}
	
	/**
	 * Creates the "Style" group.
	 */
	void createStyleGroup() {
		super.createStyleGroup ();
		
		/* Create the extra widgets */
		dateButton = new Button(styleGroup, SWT.RADIO);
		dateButton.setText("SWT.DATE");
		timeButton = new Button(styleGroup, SWT.RADIO);
		timeButton.setText("SWT.TIME");
		calendarButton = new Button(styleGroup, SWT.RADIO);
		calendarButton.setText("SWT.CALENDAR");
		Group formatGroup = new Group(styleGroup, SWT.NONE);
		formatGroup.setLayout(new GridLayout());
		shortButton = new Button(formatGroup, SWT.RADIO);
		shortButton.setText("SWT.SHORT");
		mediumButton = new Button(formatGroup, SWT.RADIO);
		mediumButton.setText("SWT.MEDIUM");
		longButton = new Button(formatGroup, SWT.RADIO);
		longButton.setText("SWT.LONG");
		borderButton = new Button(styleGroup, SWT.CHECK);
		borderButton.setText("SWT.BORDER");
	}
	
	/**
	 * Gets the "Example" widget children.
	 */
	Widget [] getExampleWidgets () {
		return new Widget [] {dateTime1};
	}
	
	/**
	 * Returns a list of set/get API method names (without the set/get prefix)
	 * that can be used to set/get values in the example control(s).
	 */
	String[] getMethodNames() {
		return new String[] {"Day", "Hours", "Minutes", "Month", "Seconds", "Year"};
	}
	
	/**
	 * Gets the text for the tab folder item.
	 */
	String getTabText () {
		return "DateTime";
	}

	/**
	 * Sets the state of the "Example" widgets.
	 */
	void setExampleWidgetState () {
		super.setExampleWidgetState ();
		dateButton.setSelection ((dateTime1.getStyle () & SWT.DATE) != 0);
		timeButton.setSelection ((dateTime1.getStyle () & SWT.TIME) != 0);
		calendarButton.setSelection ((dateTime1.getStyle () & SWT.CALENDAR) != 0);
		shortButton.setSelection ((dateTime1.getStyle () & SWT.SHORT) != 0);
		mediumButton.setSelection ((dateTime1.getStyle () & SWT.MEDIUM) != 0);
		longButton.setSelection ((dateTime1.getStyle () & SWT.LONG) != 0);
		borderButton.setSelection ((dateTime1.getStyle () & SWT.BORDER) != 0);
	}
}

Back to the top