More addressbook patches from Mauro Botelho.

1. Now we are saving new entries to a file named aBook.nab
2. Sort ascending and descending are working now.
This commit is contained in:
edwin%woudt.nl 1999-03-15 01:59:26 +00:00
Родитель 5732de5232
Коммит 94b9994166
3 изменённых файлов: 320 добавлений и 99 удалений

Просмотреть файл

@ -66,6 +66,9 @@ public class AddressBook extends GeneralFrame {
protected DataSourceList mDataSourceList;
protected JComboBox mSearchSource;
protected JTextField mSearchField;
protected boolean mSortAscending;
protected String ColumnName;
protected int mColumnSorted;
public static void main(String[] args) {
AddressBook AddressBookFrame = new AddressBook();
@ -106,7 +109,7 @@ public class AddressBook extends GeneralFrame {
//create the query
ITerm query = new TermEqual (new AC_Attribute ("sn", aSearchString));
String[] attributes = {"sn", "cn", "o", "mail", "city"};
String[] attributes = {"givenName", "sn", "cn", "o", "mail", "telephoneNumber", "city"};
//query the LDAP server.
System.out.println ("Send query" + query);
@ -155,7 +158,7 @@ public class AddressBook extends GeneralFrame {
mail = attr.getValue();
}
else if (attrName.equals ("sn")) {
else if (attrName.equals ("telephoneNumber")) {
phone = attr.getValue();
}
@ -256,6 +259,10 @@ public class AddressBook extends GeneralFrame {
public AddressBook() {
super("Address Book","0");
// Setting the default values to the variables
mSortAscending = true;
mColumnSorted = 0;
setBackground(Color.lightGray);
getContentPane().setLayout(new BorderLayout());
@ -268,6 +275,11 @@ public class AddressBook extends GeneralFrame {
mMenubar = buildMenu("menus.xml",defaultActions);
Component[] menulist = mMenubar.getComponents();
for(int j = 0 ; j < menulist.length ; j++) {
System.out.println(menulist[j].getName());
}
setJMenuBar(mMenubar);
//collapsble panels holds toolbar.
@ -303,7 +315,7 @@ public class AddressBook extends GeneralFrame {
getContentPane().add(panel1, BorderLayout.CENTER);
setSize (600, 400);
//Create Local Address Book
//myLocalAddressBook = new ACS_Personal ("MyAddressBook.nab", true);
@ -412,10 +424,10 @@ public class AddressBook extends GeneralFrame {
new ByCompany(),
new ByCity(),
new ByNickname(),
// new SortAscending(),
// new SortDescending(),
// new MyAddressBookCard(),
// new WrapLongLines()
new SortAscending(),
new SortDescending(),
// new MyAddressBookCard(),
// new WrapLongLines()
};
//-----------------------
@ -538,84 +550,134 @@ public class AddressBook extends GeneralFrame {
}
}
}
//----------------
// Sort Ascending
//----------------
class SortAscending extends UIAction {
SortAscending() {
super(sortAscendingTag);
this.setEnabled(true);
}
public void actionPerformed(ActionEvent e) {
if (!mSortAscending) {
mSortAscending = true;
DataModel dm = (DataModel) mTable.getModel ();
System.out.println("Column Name is " + ColumnName);
int colnumber = dm.findColumn(ColumnName);
System.out.println("Column Number for " + ColumnName + " is: " + colnumber);
class ResultSorter extends UIAction {
protected String ColumnName;
dm.sortData(colnumber,mSortAscending);
ResultSorter(String Tag){
super(Tag);
mTable.repaint();
}
}
}
public void actionPerformed(ActionEvent e) {
DataModel dm = (DataModel) mTable.getModel ();
int colnumber = dm.findColumn(ColumnName);
System.out.println("Column Number for " + ColumnName + " is: " + colnumber);
dm.sortData(colnumber);
//----------------
// Sort Descending
//----------------
class SortDescending extends UIAction {
SortDescending() {
super(sortDescendingTag);
this.setEnabled(true);
}
public void actionPerformed(ActionEvent e) {
System.out.println("I'm in sort descending");
if (mSortAscending) {
DataModel dm = (DataModel) mTable.getModel ();
mSortAscending = false;
System.out.println("Column Name is " + ColumnName);
int colnumber = dm.findColumn(ColumnName);
System.out.println("Column Number for " + ColumnName + " is: " + colnumber);
dm.fireTableDataChanged();
mTable.repaint();
}
}
//-----------------------
//ByName action
//-----------------------
dm.sortData(colnumber,mSortAscending);
class ByName extends ResultSorter {
ByName() {
super(byNameTag);
ColumnName = new String("Name");
this.setEnabled(true);
mTable.repaint();
}
}
}
}
//----------------------------------
// Base class for sorting the names
//----------------------------------
class ResultSorter extends UIAction {
String myLocalColumnName;
ResultSorter(String Tag){
super(Tag);
}
//-----------------------
//ByEmailAddress action
//-----------------------
public void actionPerformed(ActionEvent e) {
DataModel dm = (DataModel) mTable.getModel ();
ColumnName = myLocalColumnName;
class ByEmailAddress extends ResultSorter {
ByEmailAddress() {
super(byEmailAddressTag);
ColumnName = new String("Email Address");
this.setEnabled(true);
int colnumber = dm.findColumn(ColumnName);
System.out.println("Column Number for " + ColumnName + " is: " + colnumber);
dm.sortData(colnumber,mSortAscending);
mTable.repaint();
}
}
}
//-----------------------
//ByName action
//-----------------------
//-----------------------
//ByCompany action
//-----------------------
class ByName extends ResultSorter {
ByName() {
super(byNameTag);
myLocalColumnName = new String("Name");
this.setEnabled(true);
}
class ByCompany extends ResultSorter {
ByCompany() {
super(byCompanyTag);
ColumnName = new String("Organization");
this.setEnabled(true);
}
}
//-----------------------
//ByCity action
//-----------------------
class ByCity extends ResultSorter {
ByCity() {
super(byCityTag);
ColumnName = new String("City");
this.setEnabled(true);
//-----------------------
//ByEmailAddress action
//-----------------------
class ByEmailAddress extends ResultSorter {
ByEmailAddress() {
super(byEmailAddressTag);
myLocalColumnName = new String("Email Address");
this.setEnabled(true);
}
}
}
//-----------------------
//ByNickname action
//-----------------------
//-----------------------
//ByCompany action
//-----------------------
class ByNickname extends ResultSorter {
ByNickname() {
super(byNicknameTag);
ColumnName = new String("Nickname");
this.setEnabled(true);
class ByCompany extends ResultSorter {
ByCompany() {
super(byCompanyTag);
myLocalColumnName = new String("Organization");
this.setEnabled(true);
}
}
//-----------------------
//ByCity action
//-----------------------
class ByCity extends ResultSorter {
ByCity() {
super(byCityTag);
myLocalColumnName = new String("City");
this.setEnabled(true);
}
}
//-----------------------
//ByNickname action
//-----------------------
class ByNickname extends ResultSorter {
ByNickname() {
super(byNicknameTag);
myLocalColumnName = new String("Nickname");
this.setEnabled(true);
}
}
}
/**
* Create a Toolbar
@ -733,7 +795,7 @@ public class AddressBook extends GeneralFrame {
String nickName = "";
// enumerate thru the card attributes.
for (Enumeration attEnum = attrSet.getEnumeration();
for (Enumeration attEnum = attrSet.getEnumeration();
attEnum.hasMoreElements(); ) {
IAttribute attr = (IAttribute) attEnum.nextElement();
String attrName = attr.getName();
@ -822,20 +884,20 @@ public class AddressBook extends GeneralFrame {
return (((Vector)mVecVec.elementAt(row)).elementAt(column));
}
public void sortData(int column) {
public void sortData(int column, final boolean sortascending) {
Object[][] ColumnValues = new String [mVecVec.size()][2];
int row;
int col;
for(row = 0 ; row < mVecVec.size() ; ++row) {
ColumnValues[row][0] =
ColumnValues[row][0] =
(((Vector)mVecVec.elementAt(row)).elementAt(column));
ColumnValues[row][1] = new Integer(row).toString();
}
System.out.println("Values before sorting");
for(row = 0; row < ColumnValues.length ; ++row) {
System.out.println(ColumnValues[row][0] + " row: "
System.out.println(ColumnValues[row][0] + " row: "
+ ColumnValues[row][1]);
}
@ -848,6 +910,8 @@ public class AddressBook extends GeneralFrame {
catch (NullPointerException e) {
returnValue = 1;
}
if (!sortascending)
returnValue = -1 * returnValue;
return returnValue;
}
});
@ -855,7 +919,7 @@ public class AddressBook extends GeneralFrame {
System.out.println("Values after sorting");
for(row = 0; row < ColumnValues.length ; ++row) {
System.out.println(ColumnValues[row][0] + " row: "
System.out.println(ColumnValues[row][0] + " row: "
+ ColumnValues[row][1]);
}
@ -864,7 +928,7 @@ public class AddressBook extends GeneralFrame {
for(row = 0; row < ColumnValues.length ; ++row) {
Vector thisRow = new Vector(6);
Integer OriginalPosition = new Integer((String)ColumnValues[row][1]);
for(col = 0; col < ((Vector)mVecVec.elementAt(row)).size();
for(col = 0; col < ((Vector)mVecVec.elementAt(row)).size();
++col) {
thisRow.addElement(((Vector)mVecVec.elementAt(OriginalPosition.intValue())).elementAt(col));
}
@ -872,8 +936,8 @@ public class AddressBook extends GeneralFrame {
}
mVecVec = SortedVector;
System.out.println("Hello");
fireTableDataChanged();
}
}

Просмотреть файл

@ -22,6 +22,28 @@
package grendel.addressbook;
import grendel.addressbook.addresscard.*;
// *********************************************************berkeley test stuff
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Folder;
import javax.mail.MessagingException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringWriter;
import java.io.PrintWriter;
import grendel.storage.BerkeleyStore;
// ********************************************************End of berkeley test
import java.awt.*;
import java.awt.event.*;
import java.util.*;
@ -30,31 +52,86 @@ import javax.swing.*;
class NewCardDialog extends JDialog {
private JTextField eFirstName;
private JTextField eLastName;
private JTextField eDisplayName;
private JTextField eEMailAddress;
private JTextField eNickName;
private JTextField eWorkPhone;
private JTextField eHomePhone;
private JTextField eFax;
private JTextField ePager;
private JTextField eCellPhone;
private JTextField eTitle;
private JTextField eOrganization;
private JTextField eDepartment;
private JTextField eAddress;
private JTextField eCity;
private JTextField eState;
private JTextField eZIP;
private JTextField eCountry;
private JTextField eURL;
// *************************************************************Berkeley Stuff
/** The Properties instance that all the javamail stuff will use. We try not
to use calypso.util.Preferences during SelfTest, because there's no real
way to control the values to be found there. Typically, your SelfTest
code will stuff values into this Properties database so that the Store
you're using will pull those values out. */
static protected Properties props;
/** A stupid authenticator that we use to stuff in name/password info into
our tests. */
static private StupidAuthenticator authenticator;
/** The javax.mail.Session object. This is created for you by startTests. */
static protected Session session;
/** The directory where you can store temporary stuff. If you want to use
this, be sure to call makePlayDir() at the beginning of your test; that
will ensure that the directory exists and is empty. */
static protected File playdir = new File("selftestdir");
// *******************************************************End of berkeley stuff
NewCardDialog(Frame aParent) {
//FIX: Resource
super(aParent, "Card for", true);
// setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
JTabbedPane tabbedPane = new JTabbedPane();
getContentPane().add(tabbedPane, BorderLayout.CENTER);
//add (tabbedPane);
JComponent namePanel = createNamePanel ();
tabbedPane.addTab("Name",null,namePanel,"Name Information");
// add (namePanel);
JComponent contactPanel = createContactPanel ();
tabbedPane.addTab("Contact",null,contactPanel,"Contact Information");
// add (contactPanel);
// JComponent netConfPanel = createNetConfPanel ();
// add (netConfPanel);
setResizable(false);
setSize (716, 515);
setResizable(true);
setSize (300, 515);
addWindowListener(new AppCloser());
JButton bOK = new JButton("OK");
bOK.addActionListener(new OKEvents());
JButton bCancel = new JButton("Cancel");
bCancel.addActionListener(new CancelEvents());
JPanel pOKCancel = new JPanel();
pOKCancel.add(bOK);
pOKCancel.add(bCancel);
getContentPane().add(pOKCancel, BorderLayout.SOUTH);
getRootPane().setDefaultButton(bOK);
}
protected final class AppCloser extends WindowAdapter {
@ -63,6 +140,68 @@ class NewCardDialog extends JDialog {
}
}
protected final class OKEvents implements ActionListener {
public void actionPerformed(ActionEvent e) {
ACS_Personal myAddressBook = new ACS_Personal("abook.nab",true);
AddressCardAttribute anAttribute;
AddressCardAttributeSet anAttributeSet = new AddressCardAttributeSet();
AddressCard aCard;
anAttribute = new AddressCardAttribute("cn",eFirstName.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("sn",eLastName.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("mail",eEMailAddress.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("city",eCity.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("telephoneNumber",eHomePhone.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("workPhone",eWorkPhone.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("fax",eFax.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("pager",ePager.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("cellular",eCellPhone.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("Title",eTitle.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("o",eOrganization.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("department",eDepartment.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("postalAddress",eAddress.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("city",eCity.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("state",eState.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("postalCode",eZIP.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("c",eCountry.getText());
anAttributeSet.add(anAttribute);
anAttribute = new AddressCardAttribute("url",eURL.getText());
anAttributeSet.add(anAttribute);
aCard = new AddressCard(myAddressBook,anAttributeSet);
myAddressBook.add(aCard, true);
myAddressBook.close();
System.out.println("First Name: " + eFirstName.getText());
dispose();
}
}
protected final class CancelEvents implements ActionListener{
public void actionPerformed(ActionEvent e) {
dispose();
}
}
private JPanel createNamePanel () {
//the outer most panel has groove etched into it.
JPanel pane = new JPanel(false);
@ -71,9 +210,9 @@ class NewCardDialog extends JDialog {
JPanel namePane = new JPanel(false);
namePane.setLayout (new GridLayout(3,2));
makeField ("First Name:", 20, namePane);
makeField ("Last Name:", 20, namePane);
makeField ("Display Name:",20, namePane);
eFirstName = makeField ("First Name:", 20, namePane);
eLastName = makeField ("Last Name:", 20, namePane);
eDisplayName = makeField ("Display Name:",20, namePane);
pane.add (namePane);
@ -81,8 +220,8 @@ class NewCardDialog extends JDialog {
JPanel eMailPane = new JPanel(false);
eMailPane.setLayout (new GridLayout (2,2));
makeField ("Email Address:", 20, eMailPane);
makeField ("Nick Name:", 20, eMailPane);
eEMailAddress = makeField ("Email Address:", 20, eMailPane);
eNickName = makeField ("Nick Name:", 20, eMailPane);
pane.add (eMailPane);
@ -90,11 +229,11 @@ class NewCardDialog extends JDialog {
JPanel phonePane = new JPanel(false);
phonePane.setLayout (new GridLayout (5,2));
makeField ("Work:", 20, phonePane);
makeField ("Home:", 20, phonePane);
makeField ("Fax:", 20, phonePane);
makeField ("Pager:", 20, phonePane);
makeField ("Cellular:", 20, phonePane);
eWorkPhone = makeField ("Work:", 20, phonePane);
eHomePhone = makeField ("Home:", 20, phonePane);
eFax = makeField ("Fax:", 20, phonePane);
ePager = makeField ("Pager:", 20, phonePane);
eCellPhone = makeField ("Cellular:", 20, phonePane);
pane.add (phonePane);
@ -109,33 +248,35 @@ class NewCardDialog extends JDialog {
JPanel contactPane = new JPanel(false);
contactPane.setLayout (new GridLayout (3,2));
makeField ("Title:", 20, contactPane);
makeField ("Organization:", 20, contactPane);
makeField ("Department:", 20, contactPane);
eTitle = makeField ("Title:", 20, contactPane);
eOrganization = makeField ("Organization:", 20, contactPane);
eDepartment = makeField ("Department:", 20, contactPane);
pane.add (contactPane);
JPanel addressPane = new JPanel(false);
addressPane.setLayout (new GridLayout (6,2));
makeField ("Address:", 20, addressPane);
makeField ("City:", 20, addressPane);
makeField ("State:", 20, addressPane);
makeField ("ZIP:", 20, addressPane);
makeField ("Country:", 20, addressPane);
makeField ("URL:", 20, addressPane);
eAddress = makeField ("Address:", 20, addressPane);
eCity = makeField ("City:", 20, addressPane);
eState = makeField ("State:", 20, addressPane);
eZIP = makeField ("ZIP:", 20, addressPane);
eCountry = makeField ("Country:", 20, addressPane);
eURL = makeField ("URL:", 20, addressPane);
pane.add (addressPane);
return pane;
}
private void makeField (String aTitle, int aCol, JPanel aPanel) {
private JTextField makeField (String aTitle, int aCol, JPanel aPanel) {
JLabel title = new JLabel (aTitle);
aPanel.add (title);
JTextField textField = new JTextField (aCol);
aPanel.add (textField);
return textField;
}
private JTextField makeField (String aTitle, int aCol) {
@ -155,3 +296,19 @@ class NewCardDialog extends JDialog {
return textField;
}
}
class StupidAuthenticator extends Authenticator {
String user;
String password;
StupidAuthenticator() {}
void set(String u, String p) {
user = u;
password = p;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
}

Просмотреть файл