diff options
Diffstat (limited to 'qtjava/javalib/examples/addressbook')
-rw-r--r-- | qtjava/javalib/examples/addressbook/ABCentralWidget.java | 357 | ||||
-rw-r--r-- | qtjava/javalib/examples/addressbook/ABMainWindow.java | 102 | ||||
-rw-r--r-- | qtjava/javalib/examples/addressbook/Main.java | 31 | ||||
-rw-r--r-- | qtjava/javalib/examples/addressbook/fileopen.xpm | 22 | ||||
-rw-r--r-- | qtjava/javalib/examples/addressbook/fileprint.xpm | 24 | ||||
-rw-r--r-- | qtjava/javalib/examples/addressbook/filesave.xpm | 22 |
6 files changed, 558 insertions, 0 deletions
diff --git a/qtjava/javalib/examples/addressbook/ABCentralWidget.java b/qtjava/javalib/examples/addressbook/ABCentralWidget.java new file mode 100644 index 00000000..8dd6af37 --- /dev/null +++ b/qtjava/javalib/examples/addressbook/ABCentralWidget.java @@ -0,0 +1,357 @@ +/**************************************************************************** +** $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.kde.qt.*; +import java.util.*; + +public class ABCentralWidget extends QWidget +{ + protected QGridLayout mainGrid; + protected QTabWidget tabWidget; + protected QListView listView; + protected QPushButton add, change, find; + protected QLineEdit iFirstName, iLastName, iAddress, iEMail, + sFirstName, sLastName, sAddress, sEMail; + protected QCheckBox cFirstName, cLastName, cAddress, cEMail; + + +public ABCentralWidget( QWidget parent, String name ) +{ + super( parent, name ); + mainGrid = new QGridLayout( this, 2, 1, 5, 5 ); + + setupTabWidget(); + setupListView(); + + mainGrid.setRowStretch( 0, 0 ); + mainGrid.setRowStretch( 1, 1 ); +} + +public ABCentralWidget( QWidget parent ) +{ + this(parent, null); +} + +public void save( String filename ) +{ + if ( listView.firstChild() == null ) + return; + + QFile f = new QFile( filename ); + if ( !f.open( QIODevice.IO_WriteOnly ) ) + return; + + QTextStream t = new QTextStream( f ); + + Iterator it = listView.itemList().iterator(); + while ( it.hasNext() ) { + QListViewItem currentItem = (QListViewItem) it.next(); + for ( int i = 0; i < 4; i++ ) { + t.writeRawBytes( currentItem.text(i), currentItem.text(i).length() ); + t.writeRawBytes( "\n", 1 ); + } + } + + f.close(); +} + +public void load( String filename ) +{ + listView.clear(); + + QFile f = new QFile( filename ); + if ( !f.open( QIODevice.IO_ReadOnly ) ) + return; + + QTextStream t = new QTextStream( f ); + + while ( !t.atEnd() ) { + QListViewItem item = new QListViewItem( listView ); + for ( int i = 0; i < 4; i++ ) + item.setText( i, t.readLine() ); + } + + f.close(); +} + +public void setupTabWidget() +{ + tabWidget = new QTabWidget( this ); + + QWidget input = new QWidget( tabWidget ); + QGridLayout grid1 = new QGridLayout( input, 2, 5, 5, 5 ); + + QLabel liFirstName = new QLabel( "First &Name", input ); + liFirstName.resize( liFirstName.sizeHint() ); + grid1.addWidget( liFirstName, 0, 0 ); + + QLabel liLastName = new QLabel( "&Last Name", input ); + liLastName.resize( liLastName.sizeHint() ); + grid1.addWidget( liLastName, 0, 1 ); + + QLabel liAddress = new QLabel( "Add&ress", input ); + liAddress.resize( liAddress.sizeHint() ); + grid1.addWidget( liAddress, 0, 2 ); + + QLabel liEMail = new QLabel( "&E-Mail", input ); + liEMail.resize( liEMail.sizeHint() ); + grid1.addWidget( liEMail, 0, 3 ); + + add = new QPushButton( "A&dd", input ); + add.resize( add.sizeHint() ); + grid1.addWidget( add, 0, 4 ); + connect( add, SIGNAL( "clicked()" ), this, SLOT( "addEntry()" ) ); + + iFirstName = new QLineEdit( input ); + iFirstName.resize( iFirstName.sizeHint() ); + grid1.addWidget( iFirstName, 1, 0 ); + liFirstName.setBuddy( iFirstName ); + + iLastName = new QLineEdit( input ); + iLastName.resize( iLastName.sizeHint() ); + grid1.addWidget( iLastName, 1, 1 ); + liLastName.setBuddy( iLastName ); + + iAddress = new QLineEdit( input ); + iAddress.resize( iAddress.sizeHint() ); + grid1.addWidget( iAddress, 1, 2 ); + liAddress.setBuddy( iAddress ); + + iEMail = new QLineEdit( input ); + iEMail.resize( iEMail.sizeHint() ); + grid1.addWidget( iEMail, 1, 3 ); + liEMail.setBuddy( iEMail ); + + change = new QPushButton( "&Change", input ); + change.resize( change.sizeHint() ); + grid1.addWidget( change, 1, 4 ); + connect( change, SIGNAL( "clicked()" ), this, SLOT( "changeEntry()" ) ); + + tabWidget.addTab( input, "&Add/Change Entry" ); + + // -------------------------------------- + + QWidget search = new QWidget( this ); + QGridLayout grid2 = new QGridLayout( search, 2, 5, 5, 5 ); + + cFirstName = new QCheckBox( "First &Name", search ); + cFirstName.resize( cFirstName.sizeHint() ); + grid2.addWidget( cFirstName, 0, 0 ); + connect( cFirstName, SIGNAL( "clicked()" ), this, SLOT( "toggleFirstName()" ) ); + + cLastName = new QCheckBox( "&Last Name", search ); + cLastName.resize( cLastName.sizeHint() ); + grid2.addWidget( cLastName, 0, 1 ); + connect( cLastName, SIGNAL( "clicked()" ), this, SLOT( "toggleLastName()" ) ); + + cAddress = new QCheckBox( "Add&ress", search ); + cAddress.resize( cAddress.sizeHint() ); + grid2.addWidget( cAddress, 0, 2 ); + connect( cAddress, SIGNAL( "clicked()" ), this, SLOT( "toggleAddress()" ) ); + + cEMail = new QCheckBox( "&E-Mail", search ); + cEMail.resize( cEMail.sizeHint() ); + grid2.addWidget( cEMail, 0, 3 ); + connect( cEMail, SIGNAL( "clicked()" ), this, SLOT( "toggleEMail()" ) ); + + sFirstName = new QLineEdit( search ); + sFirstName.resize( sFirstName.sizeHint() ); + grid2.addWidget( sFirstName, 1, 0 ); + + sLastName = new QLineEdit( search ); + sLastName.resize( sLastName.sizeHint() ); + grid2.addWidget( sLastName, 1, 1 ); + + sAddress = new QLineEdit( search ); + sAddress.resize( sAddress.sizeHint() ); + grid2.addWidget( sAddress, 1, 2 ); + + sEMail = new QLineEdit( search ); + sEMail.resize( sEMail.sizeHint() ); + grid2.addWidget( sEMail, 1, 3 ); + + find = new QPushButton( "F&ind", search ); + find.resize( find.sizeHint() ); + grid2.addWidget( find, 1, 4 ); + connect( find, SIGNAL( "clicked()" ), this, SLOT( "findEntries()" ) ); + + cFirstName.setChecked( true ); + sFirstName.setEnabled( true ); + sLastName.setEnabled( false ); + sAddress.setEnabled( false ); + sEMail.setEnabled( false ); + + tabWidget.addTab( search, "&Search" ); + + mainGrid.addWidget( tabWidget, 0, 0 ); +} + +public void setupListView() +{ + listView = new QListView( this ); + listView.addColumn( "First Name" ); + listView.addColumn( "Last Name" ); + listView.addColumn( "Address" ); + listView.addColumn( "E-Mail" ); + + listView.setSelectionMode( QListView.Extended ); + + connect( listView, SIGNAL( "clicked( QListViewItem )" ), this, SLOT( "itemSelected( QListViewItem )" ) ); + + mainGrid.addWidget( listView, 1, 0 ); + listView.setAllColumnsShowFocus( true ); +} + +public void addEntry() +{ + if ( !iFirstName.text().equals("") || !iLastName.text().equals("") || + !iAddress.text().equals("") || !iEMail.text().equals("") ) { + QListViewItem item = new QListViewItem( listView ); + item.setText( 0, iFirstName.text() ); + item.setText( 1, iLastName.text() ); + item.setText( 2, iAddress.text() ); + item.setText( 3, iEMail.text() ); + } + + iFirstName.setText( "" ); + iLastName.setText( "" ); + iAddress.setText( "" ); + iEMail.setText( "" ); +} + +public void changeEntry() +{ + QListViewItem item = listView.currentItem(); + + if ( item != null && + ( !iFirstName.text().equals("") || !iLastName.text().equals("") || + !iAddress.text().equals("") || !iEMail.text().equals("") ) ) { + item.setText( 0, iFirstName.text() ); + item.setText( 1, iLastName.text() ); + item.setText( 2, iAddress.text() ); + item.setText( 3, iEMail.text() ); + } +} + +public void selectionChanged() +{ + iFirstName.setText( "" ); + iLastName.setText( "" ); + iAddress.setText( "" ); + iEMail.setText( "" ); +} + +public void itemSelected( QListViewItem item ) +{ + item.setSelected( true ); + item.repaint(); + + iFirstName.setText( item.text( 0 ) ); + iLastName.setText( item.text( 1 ) ); + iAddress.setText( item.text( 2 ) ); + iEMail.setText( item.text( 3 ) ); +} + +public void toggleFirstName() +{ + sFirstName.setText( "" ); + + if ( cFirstName.isChecked() ) { + sFirstName.setEnabled( true ); + sFirstName.setFocus(); + } + else + sFirstName.setEnabled( false ); +} + +public void toggleLastName() +{ + sLastName.setText( "" ); + + if ( cLastName.isChecked() ) { + sLastName.setEnabled( true ); + sLastName.setFocus(); + } + else + sLastName.setEnabled( false ); +} + +public void toggleAddress() +{ + sAddress.setText( "" ); + + if ( cAddress.isChecked() ) { + sAddress.setEnabled( true ); + sAddress.setFocus(); + } + else + sAddress.setEnabled( false ); +} + +public void toggleEMail() +{ + sEMail.setText( "" ); + + if ( cEMail.isChecked() ) { + sEMail.setEnabled( true ); + sEMail.setFocus(); + } + else + sEMail.setEnabled( false ); +} + +public void findEntries() +{ + if ( !cFirstName.isChecked() && + !cLastName.isChecked() && + !cAddress.isChecked() && + !cEMail.isChecked() ) { + listView.clearSelection(); + return; + } + + Iterator it = listView.itemList().iterator(); + while ( it.hasNext() ) { + QListViewItem currentItem = (QListViewItem) it.next(); + boolean select = true; + + if ( cFirstName.isChecked() ) { + if ( select && currentItem.text( 0 ).indexOf( sFirstName.text() ) != -1 ) + select = true; + else + select = false; + } + if ( cLastName.isChecked() ) { + if ( select && currentItem.text( 1 ).indexOf( sLastName.text() ) != -1 ) + select = true; + else + select = false; + } + if ( cAddress.isChecked() ) { + if ( select && currentItem.text( 2 ).indexOf( sAddress.text() ) != -1 ) + select = true; + else + select = false; + } + if ( cEMail.isChecked() ) { + if ( select && currentItem.text( 3 ).indexOf( sEMail.text() ) != -1 ) + select = true; + else + select = false; + } + + if ( select ) + currentItem.setSelected( true ); + else + currentItem.setSelected( false ); + currentItem.repaint(); + } +} + +} diff --git a/qtjava/javalib/examples/addressbook/ABMainWindow.java b/qtjava/javalib/examples/addressbook/ABMainWindow.java new file mode 100644 index 00000000..588098f4 --- /dev/null +++ b/qtjava/javalib/examples/addressbook/ABMainWindow.java @@ -0,0 +1,102 @@ +/**************************************************************************** +** $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.kde.qt.*; + +class ABMainWindow extends QMainWindow +{ + protected QToolBar fileTools; + protected String filename; + protected ABCentralWidget view; + +public ABMainWindow() +{ + super( null, "example addressbook application" ); + filename = ""; + setupMenuBar(); + setupFileTools(); + setupStatusBar(); + setupCentralWidget(); +} + +public void setupMenuBar() +{ + QPopupMenu file = new QPopupMenu( this ); + menuBar().insertItem( "&File", file ); + + file.insertItem( "New", this, SLOT( "fileNew()" ), new QKeySequence(CTRL + Key_N) ); + file.insertItem( new QIconSet(new QPixmap( "fileopen.xpm" )), "Open", this, SLOT( "fileOpen()" ), new QKeySequence(CTRL + Key_O) ); + file.insertSeparator(); + file.insertItem( new QIconSet(new QPixmap( "filesave.xpm" )), "Save", this, SLOT( "fileSave()" ), new QKeySequence(CTRL + Key_S) ); + file.insertItem( "Save As...", this, SLOT( "fileSaveAs()" ) ); + file.insertSeparator(); + file.insertItem( new QIconSet(new QPixmap( "fileprint.xpm" )), "Print...", this, SLOT( "filePrint()" ), new QKeySequence(CTRL + Key_P) ); + file.insertSeparator(); + file.insertItem( "Close", this, SLOT( "closeWindow()" ), new QKeySequence(CTRL + Key_W) ); + file.insertItem( "Quit", qApp(), SLOT( "quit()" ), new QKeySequence(CTRL + Key_Q) ); +} + +public void setupFileTools() +{ + //fileTools = new QToolBar( this, "file operations" ); +} + +public void setupStatusBar() +{ + //statusBar()->message( "Ready", 2000 ); +} + +public void setupCentralWidget() +{ + view = new ABCentralWidget( this ); + setCentralWidget( view ); +} + +public void closeWindow() +{ + close(); +} + +public void fileNew() +{ +} + +public void fileOpen() +{ + String fn = QFileDialog.getOpenFileName( "", "", this ); + if ( !fn.equals("") ) { + filename = fn; + view.load( filename ); + } +} + +public void fileSave() +{ + if ( filename.equals("") ) { + fileSaveAs(); + return; + } + + view.save( filename ); +} + +public void fileSaveAs() +{ + String fn = QFileDialog.getSaveFileName( "", "", this ); + if ( !fn.equals("") ) { + filename = fn; + fileSave(); + } +} + +public void filePrint() +{ +} + +} diff --git a/qtjava/javalib/examples/addressbook/Main.java b/qtjava/javalib/examples/addressbook/Main.java new file mode 100644 index 00000000..eeda8adc --- /dev/null +++ b/qtjava/javalib/examples/addressbook/Main.java @@ -0,0 +1,31 @@ +/**************************************************************************** +** $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.kde.qt.*; + +public class Main { + +public static void main( String[] args ) +{ + QApplication a = new QApplication( args ); + + ABMainWindow mw = new ABMainWindow(); + mw.setCaption( "Qt Example - Addressbook" ); + a.setMainWidget( mw ); + mw.show(); + + a.connect( a, Qt.SIGNAL( "lastWindowClosed()" ), a, Qt.SLOT( "quit()" ) ); + int result = a.exec(); + return; +} + static { + qtjava.initialize(); + } + +} diff --git a/qtjava/javalib/examples/addressbook/fileopen.xpm b/qtjava/javalib/examples/addressbook/fileopen.xpm new file mode 100644 index 00000000..880417ee --- /dev/null +++ b/qtjava/javalib/examples/addressbook/fileopen.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *fileopen[] = { +" 16 13 5 1", +". c #040404", +"# c #808304", +"a c None", +"b c #f3f704", +"c c #f3f7f3", +"aaaaaaaaa...aaaa", +"aaaaaaaa.aaa.a.a", +"aaaaaaaaaaaaa..a", +"a...aaaaaaaa...a", +".bcb.......aaaaa", +".cbcbcbcbc.aaaaa", +".bcbcbcbcb.aaaaa", +".cbcb...........", +".bcb.#########.a", +".cb.#########.aa", +".b.#########.aaa", +"..#########.aaaa", +"...........aaaaa" +}; diff --git a/qtjava/javalib/examples/addressbook/fileprint.xpm b/qtjava/javalib/examples/addressbook/fileprint.xpm new file mode 100644 index 00000000..6ada912f --- /dev/null +++ b/qtjava/javalib/examples/addressbook/fileprint.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static const char *fileprint[] = { +" 16 14 6 1", +". c #000000", +"# c #848284", +"a c #c6c3c6", +"b c #ffff00", +"c c #ffffff", +"d c None", +"ddddd.........dd", +"dddd.cccccccc.dd", +"dddd.c.....c.ddd", +"ddd.cccccccc.ddd", +"ddd.c.....c....d", +"dd.cccccccc.a.a.", +"d..........a.a..", +".aaaaaaaaaa.a.a.", +".............aa.", +".aaaaaa###aa.a.d", +".aaaaaabbbaa...d", +".............a.d", +"d.aaaaaaaaa.a.dd", +"dd...........ddd" +}; diff --git a/qtjava/javalib/examples/addressbook/filesave.xpm b/qtjava/javalib/examples/addressbook/filesave.xpm new file mode 100644 index 00000000..bd6870f4 --- /dev/null +++ b/qtjava/javalib/examples/addressbook/filesave.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *filesave[] = { +" 14 14 4 1", +". c #040404", +"# c #808304", +"a c #bfc2bf", +"b c None", +"..............", +".#.aaaaaaaa.a.", +".#.aaaaaaaa...", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".##........##.", +".############.", +".##.........#.", +".##......aa.#.", +".##......aa.#.", +".##......aa.#.", +"b............." +}; |