summaryrefslogtreecommitdiffstats
path: root/qtjava/javalib/examples/wizard/Wizard.java
blob: 5268202ff3d806008ca2fbf80be996d7c21effcc (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/***************************************************************************
* $Id$
**
* Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
* This file is part of an example program for Qt.  This example
* program may be used, distributed and modified without limitation.
**
****************************************************************************/

import org.trinitydesktop.qt.*;

class Wizard  extends TQWizard
{
protected TQHBox page1, page2, page3;
protected TQLineEdit key, firstName, lastName, address, phone, email;
protected TQLabel lKey, lFirstName, lLastName, lAddress, lPhone, lEmail;




Wizard( )
{
	this(null, null);
}

Wizard( TQWidget parent, String name )
{
    super( parent, name, true );
    setupPage1();
    setupPage2();
    setupPage3();
    connect(this, TQ_SIGNAL("selected(String)"), this, TQ_SLOT("doShowPage(String)"));
    connect(finishButton(), TQ_SIGNAL("clicked()"), tqApp(), TQ_SLOT("quit()"));
    key.setFocus();
}

void setupPage1()
{
    page1 = new TQHBox( this );
    page1.setSpacing(8);

    TQLabel info = new TQLabel( page1 );
    info.setPalette( new TQPalette(yellow()) );
    info.setText( "Enter your personal\n"
                   + "key here.\n\n"
                   + "Your personal key\n"
                   + "consists of 4 digits" );
    info.setIndent( 8 );
    info.setMaximumWidth( info.sizeHint().width() );

    TQVBox page = new TQVBox( page1 );

    TQHBox row1 = new TQHBox( page );

    new TQLabel( "Key:", row1 );

    key = new TQLineEdit( row1 );
    key.setMaxLength( 4 );
    key.setValidator( new TQIntValidator( 1000, 9999, key ) );

    connect( key, TQ_SIGNAL(" textChanged( String )"),
	     this, TQ_SLOT(" keyChanged( String )") );

    addPage( page1, "Personal Key" );

    setNextEnabled( page1, false );
    setHelpEnabled( page1, false );
}

void setupPage2()
{
    page2 = new TQHBox( this );
    page2.setSpacing(8);

    TQLabel info = new TQLabel( page2 );
    info.setPalette( new TQPalette(yellow()) );
    info.setText( "\n"
                   + "  Enter your personal  \n"
                   + "  data here.  \n\n"
                   + "  The required fields are  \n"
                   + "  First Name, Last Name \n"
                   + "  and E-Mail.  \n" );
    info.setIndent(8);
    info.setMaximumWidth( info.sizeHint().width() );

    TQVBox page = new TQVBox( page2 );

    TQHBox row1 = new TQHBox( page );
    TQHBox row2 = new TQHBox( page );
    TQHBox row3 = new TQHBox( page );
    TQHBox row4 = new TQHBox( page );
    TQHBox row5 = new TQHBox( page );

    TQLabel label1 = new TQLabel( " First Name: ", row1 );
    label1.setAlignment( Qt.AlignVCenter );
    TQLabel label2 = new TQLabel( " Last Name: ", row2 );
    label2.setAlignment( Qt.AlignVCenter );
    TQLabel label3 = new TQLabel( " Address: ", row3 );
    label3.setAlignment( Qt.AlignVCenter );
    TQLabel label4 = new TQLabel( " Phone Number: ", row4 );
    label4.setAlignment( Qt.AlignVCenter );
    TQLabel label5 = new TQLabel( " E-Mail: ", row5 );
    label5.setAlignment( Qt.AlignVCenter );

    label1.setMinimumWidth( label4.sizeHint().width() );
    label2.setMinimumWidth( label4.sizeHint().width() );
    label3.setMinimumWidth( label4.sizeHint().width() );
    label4.setMinimumWidth( label4.sizeHint().width() );
    label5.setMinimumWidth( label4.sizeHint().width() );

    firstName = new TQLineEdit( row1 );
    lastName = new TQLineEdit( row2 );
    address = new TQLineEdit( row3 );
    phone = new TQLineEdit( row4 );
    email = new TQLineEdit( row5 );

    connect( firstName, TQ_SIGNAL(" textChanged( String )"),
	     this, TQ_SLOT(" dataChanged( String )") );
    connect( lastName, TQ_SIGNAL(" textChanged( String )"),
	     this, TQ_SLOT(" dataChanged( String )") );
    connect( email, TQ_SIGNAL(" textChanged( String )"),
	     this, TQ_SLOT(" dataChanged( String )") );

    addPage( page2, "Personal Data" );

    setHelpEnabled( page2, false );
}

void setupPage3()
{
    page3 = new TQHBox( this );
    page3.setSpacing(8);

    TQLabel info = new TQLabel( page3 );
    info.setPalette( new TQPalette(yellow()) );
    info.setText( "\n"
                   + "  Look here to see of  \n"
                   + "  the data you entered  \n"
                   + "  is correct. To confirm,  \n"
                   + "  press the [Finish] button  \n"
                   + "  else go back to correct  \n"
                   + "  mistakes." );
    info.setIndent(8);
    info.setAlignment( AlignTop|AlignLeft );
    info.setMaximumWidth( info.sizeHint().width() );

    TQVBox page = new TQVBox( page3 );

    TQHBox row1 = new TQHBox( page );
    TQHBox row2 = new TQHBox( page );
    TQHBox row3 = new TQHBox( page );
    TQHBox row4 = new TQHBox( page );
    TQHBox row5 = new TQHBox( page );
    TQHBox row6 = new TQHBox( page );

    TQLabel label1 = new TQLabel( " Personal Key: ", row1 );
    label1.setAlignment( Qt.AlignVCenter );
    TQLabel label2 = new TQLabel( " First Name: ", row2 );
    label2.setAlignment( Qt.AlignVCenter );
    TQLabel label3 = new TQLabel( " Last Name: ", row3 );
    label3.setAlignment( Qt.AlignVCenter );
    TQLabel label4 = new TQLabel( " Address: ", row4 );
    label4.setAlignment( Qt.AlignVCenter );
    TQLabel label5 = new TQLabel( " Phone Number: ", row5 );
    label5.setAlignment( Qt.AlignVCenter );
    TQLabel label6 = new TQLabel( " E-Mail: ", row6 );
    label6.setAlignment( Qt.AlignVCenter );

    label1.setMinimumWidth( label1.sizeHint().width() );
    label2.setMinimumWidth( label1.sizeHint().width() );
    label3.setMinimumWidth( label1.sizeHint().width() );
    label4.setMinimumWidth( label1.sizeHint().width() );
    label5.setMinimumWidth( label1.sizeHint().width() );
    label6.setMinimumWidth( label1.sizeHint().width() );

    lKey = new TQLabel( row1 );
    lFirstName = new TQLabel( row2 );
    lLastName = new TQLabel( row3 );
    lAddress = new TQLabel( row4 );
    lPhone = new TQLabel( row5 );
    lEmail = new TQLabel( row6 );

    addPage( page3, "Finish" );

    setFinish( page3, true );
    setHelpEnabled( page3, false );
}

// The TQWizard.showPage() virtual method callback isn't implemented in the java
// bindings yet, so use the selected() signal connected to this slot 'doShowPage()'
// instead..
public void doShowPage( String title )
{
	TQWidget page = currentPage();

    if ( page == page1 ) {
    } else if ( page == page2 ) {
    } else if ( page == page3 ) {
        lKey.setText( key.text() );
        lFirstName.setText( firstName.text() );
        lLastName.setText( lastName.text() );
        lAddress.setText( address.text() );
        lPhone.setText( phone.text() );
        lEmail.setText( email.text() );
    }

    if ( page == page1 ) {
        keyChanged( key.text() );
        key.setFocus();
    } else if ( page == page2 ) {
        dataChanged( firstName.text() );
        firstName.setFocus();
    } else if ( page == page3 ) {
        finishButton().setEnabled( true );
        finishButton().setFocus();
    }
}

void keyChanged( String text )
{
    StringBuffer t = new StringBuffer(text);
    int[] p = { 0 };
    boolean on = ( key.validator().validate(t, p) == TQValidator.Acceptable );
    nextButton().setEnabled( on );
}

void dataChanged( String s )
{
    if ( !firstName.text().equals("") &&
         !lastName.text().equals("") &&
         !email.text().equals("") )
        nextButton().setEnabled( true );
    else
        nextButton().setEnabled( false );
}
}