Let's get grendel runnin' :D. This checkin might be a bit rough so expect a couple of build bustages.

bug 86953 - Grendel uses old jaxp
bug 272345 - Grendel doesn't compile on Java 1.4
bug 292916 - Move Grendel to use Ant instead of Makefiles for compilation (partial fix)
partial fix for bug 293079 - Move grendel to use XUL
This commit is contained in:
rj.keller%beonex.com 2005-05-06 19:02:09 +00:00
Родитель 0a220a0d93
Коммит 0e1ed43639
55 изменённых файлов: 743 добавлений и 7291 удалений

126
grendel/build.xml Normal file
Просмотреть файл

@ -0,0 +1,126 @@
<?xml version="1.0"?>
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is Grendel mail/news client.
-
- The Initial Developer of the Original Code is
- R.J. Keller.
- Portions created by the Initial Developer are Copyright (C) 2005
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the LGPL or the GPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<project name="Grendel" default="build" basedir=".">
<target name="build" description="Compiles Grendel.">
<mkdir dir="dist"/>
<unzip dest="dist" overwrite="false">
<fileset dir="extlibs">
<include name="**/*.jar"/>
</fileset>
</unzip>
<copy todir="dist">
<fileset dir="sources/grendel">
<include name="**/*.gif"/>
<include name="**/*.jpg"/>
<include name="**/*.tmpl"/>
<include name="**/*.xml"/>
<include name="**/*.dtd"/>
</fileset>
</copy>
<copy todir="dist">
<fileset dir="sources">
<include name="**/*.properties"/>
</fileset>
</copy>
<javac srcdir="." destdir="dist"
optimize="false"
debug="true"
includes="**/*.java"/>
</target>
<target name="unzipResources">
<copy todir="dist/resources">
<fileset dir="sources/grendel">
<include name="**/*.gif"/>
<include name="**/*.jpg"/>
<include name="**/*.tmpl"/>
<include name="**/*.xml"/>
<include name="**/*.dtd"/>
</fileset>
</copy>
<copy todir="dist">
<fileset dir="sources">
<include name="**/*.properties"/>
</fileset>
</copy>
</target>
<target name="makeJar" description="Pumps all the libs into one big JAR for distribution. Grendel must be built before running this.">
<jar destfile="grendel.jar">
<fileset dir="dist">
<include name="**/*.*"/>
</fileset>
<manifest>
<attribute name="Main-Class" value="grendel.Main"/>
</manifest>
</jar>
<zip destfile="dist/grendel.zip">
<fileset dir="dist">
<include name="images/*.gif"/>
<include name="xml/*.xml"/>
<include name="dtd/*.dtd"/>
<include name="templates/*.tmpl"/>
<include name="images/*.jpg"/>
</fileset>
<fileset dir=".">
<include name="*.jar"/>
</fileset>
</zip>
</target>
<target name="run" description="Runs Grendel after compiling.">
<java classname="grendel.Main" classpath="dist"/>
</target>
<target name="clean" description="Cleans up generated class files.">
<delete dir="dist"/>
<delete file="grendel.jar"/>
<delete dir="javadoc"/>
</target>
<target name="javadoc" description="Generate JavaDoc API information">
<mkdir dir="javadoc"/>
<javadoc destdir="javadoc">
<fileset dir="." includes="**/*.java"/>
</javadoc>
</target>
</project>

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Frank Tang <ftang@netscape.com>
*/
@ -32,7 +32,7 @@ import java.lang.String;
* ByteToCharConverterEnumeration return a Enumeration of String which
* represent ByteToCharConverter available in the classpath
* @author ftang
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
* @see
*
*/
@ -41,7 +41,7 @@ public class ByteToCharConverterEnumeration extends PrefetchEnumeration {
/*
*
* @author ftang
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
* @see
*
*/
@ -52,7 +52,7 @@ public class ByteToCharConverterEnumeration extends PrefetchEnumeration {
/*
*
* @author ftang
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
* @see
*
*/
@ -69,7 +69,7 @@ public class ByteToCharConverterEnumeration extends PrefetchEnumeration {
/*
*
* @author ftang
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
* @see
*
*/

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -26,11 +26,13 @@
package grendel.addressbook;
import grendel.addressbook.addresscard.*;
import grendel.ui.UIAction;
import grendel.ui.GeneralFrame;
import grendel.widgets.*;
import grendel.ui.XMLMenuBuilder;
import calypso.util.*;
import com.trfenv.parsers.Event;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
@ -43,8 +45,6 @@ import javax.swing.table.*;
import javax.swing.event.TableModelEvent;
import javax.swing.border.EmptyBorder;
import netscape.ldap.*;
/**
*
* @author Lester Schueler
@ -54,7 +54,7 @@ public class AddressBook extends GeneralFrame {
private Hashtable mMenuItems;
// private ACS_Personal myLocalAddressBook;
private MenuBarCtrl mMenuBarCtrl;
private JMenuBar mMenuBarCtrl;
private GrendelToolBar mTtoolbar;
// private Component mStatusbar;
private JTable mTable;
@ -70,7 +70,7 @@ public class AddressBook extends GeneralFrame {
public static void main(String[] args) {
AddressBook AddressBookFrame = new AddressBook();
AddressBookFrame.addWindowListener(new AppCloser());
AddressBookFrame.show();
AddressBookFrame.setVisible(true);
}
protected static final class AppCloser extends WindowAdapter {
@ -96,75 +96,75 @@ public class AddressBook extends GeneralFrame {
public String getReadableName () { return mReadableName; }
public Vector query (String aSearchString) {
Vector retVecVec = new Vector(); //return vector of vectors.
// try {
//open a connection to the LDAP server
System.out.println ("Opening server " + mReadableName);
ICardSource Four11AddressBook = getCardSource();
//create the query
ITerm query = new TermEqual (new AC_Attribute ("sn", aSearchString));
String[] attributes = {"givenName", "sn", "cn", "o", "mail", "telephoneNumber", "city"};
//query the LDAP server.
System.out.println ("Send query" + query);
ICardSet cardSet = Four11AddressBook.getCardSet (query, attributes);
//Sort the list.
String[] sortOrder = {"sn", "cn"};
cardSet.sort (sortOrder);
//hack. I've put the for loop in a try block to catch the exception
//thrown when cardEnum.hasMoreElements() incorrectly returns true.
try {
//enumerate thru the cards.
for (Enumeration cardEnum = cardSet.getEnumeration();
for (Enumeration cardEnum = cardSet.getEnumeration();
cardEnum.hasMoreElements(); ) {
System.out.println ("got card");
//get the addres card
ICard card = (ICard) cardEnum.nextElement();
ICard card = (ICard) cardEnum.nextElement();
//get the attributes for this card
IAttributeSet attrSet = card.getAttributeSet ();
IAttributeSet attrSet = card.getAttributeSet ();
//create a simple vector to hold the attributes values for this card.
Vector thisRow = new Vector(6);
Vector thisRow = new Vector(6);
String commonName = "";
String organization = "";
String mail = "";
String phone = "";
String city = "";
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();
if (attrName.equals ("cn")) {
commonName = attr.getValue();
}
else if (attrName.equals ("o")) {
organization = attr.getValue();
}
else if (attrName.equals ("mail")) {
mail = attr.getValue();
}
else if (attrName.equals ("telephoneNumber")) {
phone = attr.getValue();
}
else if (attrName.equals ("city")) {
city = attr.getValue();
}
}
//create this row for the table.
thisRow.addElement (commonName);
thisRow.addElement (mail);
@ -172,7 +172,7 @@ public class AddressBook extends GeneralFrame {
thisRow.addElement (phone);
thisRow.addElement (city);
thisRow.addElement (nickName);
//add this row to the table
retVecVec.addElement (thisRow);
}
@ -183,7 +183,7 @@ public class AddressBook extends GeneralFrame {
// catch( LDAPException e ) {
// System.out.println( "Error: " + e.toString() );
// }
System.out.println ("Done.");
return retVecVec;
}
@ -224,7 +224,7 @@ public class AddressBook extends GeneralFrame {
return new ACS_Personal (mFileName, false);
}
public String getFileName () { return mFileName; }
}
//***************************
@ -270,17 +270,18 @@ public class AddressBook extends GeneralFrame {
// FIXME - need to build the menu bar
// (Jeff)
mMenuBarCtrl = buildMenu("menus.xml",defaultActions);
XMLMenuBuilder builder = new XMLMenuBuilder(defaultActions);
mMenuBarCtrl = builder.buildFrom("ui/menus.xml", this);
JMenuItem aMenuItem = mMenuBarCtrl.getCtrlByName("sortAscending");
JMenuItem aMenuItem = (JMenuItem)builder.getElementsAndIDs().get("sortAscending");
if (aMenuItem != null) {
aMenuItem.setSelected(true);
}
}
aMenuItem = mMenuBarCtrl.getCtrlByName("byName");
aMenuItem = (JMenuItem)builder.getElementsAndIDs().get("byName");
if (aMenuItem != null) {
aMenuItem.setSelected(true);
}
}
setJMenuBar(mMenuBarCtrl);
@ -398,7 +399,7 @@ public class AddressBook extends GeneralFrame {
public static final String myAddressBookCardTag ="myAddressBookCard";
// --- action implementations -----------------------------------
private UIAction[] defaultActions = {
private Event[] defaultActions = {
//"File" actions
new NewCard(),
// new NewList(),
@ -442,9 +443,9 @@ public class AddressBook extends GeneralFrame {
//-----------------------
/**
*/
class NewCard extends UIAction {
class NewCard extends Event {
NewCard() {
super(newCardTag);
super(newCardTag, null);
this.setEnabled(true);
}
@ -452,14 +453,14 @@ public class AddressBook extends GeneralFrame {
NewCardDialog aDialog = new NewCardDialog(getParentFrame());
//display the new card dialog
aDialog.show ();
aDialog.setVisible(true);
aDialog.dispose();
}
}
class SearchDirectory extends UIAction {
class SearchDirectory extends Event {
SearchDirectory() {
super(searchDirectoryTag);
super(searchDirectoryTag, null);
this.setEnabled(true);
}
@ -467,13 +468,13 @@ public class AddressBook extends GeneralFrame {
SearchDirectoryDialog aDialog = new SearchDirectoryDialog(getParentFrame());
//display the new card dialog
aDialog.show ();
aDialog.setVisible(true);
aDialog.dispose();
}
}
class SaveAs extends UIAction {
class SaveAs extends Event {
SaveAs() {
super(saveAsTag);
this.setEnabled(true);
@ -482,12 +483,12 @@ public class AddressBook extends GeneralFrame {
NewCardDialog aDialog = new NewCardDialog(getParentFrame());
//display the new card dialog
aDialog.show ();
aDialog.setVisible(true);
aDialog.dispose();
}
}
class CloseWindow extends UIAction {
class CloseWindow extends Event {
CloseWindow() {
super(closeWindowTag);
this.setEnabled(true);
@ -506,7 +507,7 @@ public class AddressBook extends GeneralFrame {
//-----------------------
//"Edit" actions
//-----------------------
class Undo extends UIAction {
class Undo extends Event {
Undo() {
super(undoTag);
this.setEnabled(true);
@ -517,7 +518,7 @@ public class AddressBook extends GeneralFrame {
//-----------------------
//"View" actions
//-----------------------
class HideMessageToolbar extends UIAction {
class HideMessageToolbar extends Event {
HideMessageToolbar() {
super(hideMessageToolbarTag);
this.setEnabled(true);
@ -528,7 +529,7 @@ public class AddressBook extends GeneralFrame {
//-----------------------
//-----------------------
class Search extends UIAction {
class Search extends Event {
Search() {
super(newListTag);
this.setEnabled(true);
@ -560,7 +561,7 @@ public class AddressBook extends GeneralFrame {
//----------------
// Sort Ascending
//----------------
class SortAscending extends UIAction {
class SortAscending extends Event {
SortAscending() {
super(sortAscendingTag);
this.setEnabled(true);
@ -584,7 +585,7 @@ public class AddressBook extends GeneralFrame {
//----------------
// Sort Descending
//----------------
class SortDescending extends UIAction {
class SortDescending extends Event {
SortDescending() {
super(sortDescendingTag);
this.setEnabled(true);
@ -608,7 +609,7 @@ public class AddressBook extends GeneralFrame {
//----------------------------------
// Base class for sorting the names
//----------------------------------
class ResultSorter extends UIAction {
class ResultSorter extends Event {
String myLocalColumnName;
ResultSorter(String Tag){
super(Tag);
@ -712,8 +713,8 @@ public class AddressBook extends GeneralFrame {
* @param aToolTip The buttons tool tip. like "Save the current file".
* @see createToolbar
*/
public void addToolbarButton(GrendelToolBar aToolBar,
UIAction aActionListener,
public void addToolbarButton(GrendelToolBar aToolBar,
Event aActionListener,
String aImageName, String aToolTip) {
JButton b = new JButton();
@ -747,7 +748,7 @@ public class AddressBook extends GeneralFrame {
// b.setPad(new Insets(3,3,3,3));
if (aActionListener != null) {
b.addActionListener(aActionListener);}
aToolBar.add(b);
}
@ -760,7 +761,7 @@ public class AddressBook extends GeneralFrame {
/* This function is now obsolete, the responsible for querying is now
** the datasource, so that we can create other types of datasources (files!)
public Vector queryLDAP (String aServerName, int aPort,
public Vector queryLDAP (String aServerName, int aPort,
String aSearchString) {
Vector retVecVec = new Vector(); //return vector of vectors.
@ -788,15 +789,15 @@ public class AddressBook extends GeneralFrame {
//thrown when cardEnum.hasMoreElements() incorrectly returns true.
try {
//enumerate thru the cards.
for (Enumeration cardEnum = cardSet.getEnumeration();
for (Enumeration cardEnum = cardSet.getEnumeration();
cardEnum.hasMoreElements(); ) {
System.out.println ("got card");
//get the addres card
ICard card = (ICard) cardEnum.nextElement();
ICard card = (ICard) cardEnum.nextElement();
//get the attributes for this card
IAttributeSet attrSet = card.getAttributeSet ();
IAttributeSet attrSet = card.getAttributeSet ();
//create a simple vector to hold the attributes values for this card.
Vector thisRow = new Vector(6);
Vector thisRow = new Vector(6);
String commonName = "";
String organization = "";
@ -804,7 +805,7 @@ public class AddressBook extends GeneralFrame {
String phone = "";
String city = "";
String nickName = "";
// enumerate thru the card attributes.
for (Enumeration attEnum = attrSet.getEnumeration();
attEnum.hasMoreElements(); ) {
@ -884,7 +885,7 @@ public class AddressBook extends GeneralFrame {
/* This method is now obsolete, since I moved the query function
** from the AddressBook to the datasource
**
public void reloadData (String aServerName, int aPort,
public void reloadData (String aServerName, int aPort,
String aSearchString) {
//reload the data from LDAP.
mVecVec = queryLDAP (aServerName, aPort, aSearchString);
@ -981,55 +982,55 @@ public class AddressBook extends GeneralFrame {
/**
*/
class AddressPanel extends JPanel {
public AddressPanel(DataSourceList aDataSourceList) {
//super(true);
setBorder (new EmptyBorder(10,10,10,10));
this.setLayout (new BorderLayout(10, 5));
add(createSearchPane(aDataSourceList), BorderLayout.NORTH);
add(createTable(), BorderLayout.CENTER);
}
private Box createSearchPane (DataSourceList aDataSourceList) {
//explaination
JLabel explaination = new JLabel ("Type in the name you're looking for:");
explaination.setAlignmentX((float)0.0); //align left
//text field
mSearchField = new JTextField (20);
mSearchField.setAlignmentX((float)0.0); //align left
//box for explain and text field
Box innerBoxPane = new Box (BoxLayout.Y_AXIS);
// innerBoxPane.setAlignmentY((float)0.0); //align to bottom
innerBoxPane.add (explaination);
innerBoxPane.add (mSearchField);
//drop down combo box
mSearchSource = new JComboBox();
mSearchSource.setAlignmentY((float)0.0); //align to bottom
for (Enumeration e = aDataSourceList.getEnumeration() ;
for (Enumeration e = aDataSourceList.getEnumeration() ;
e.hasMoreElements() ;) {
DataSource ds = (DataSource) e.nextElement();
mSearchSource.addItem(ds.getReadableName());
}
//label
JLabel lbl = new JLabel ("in:");
lbl.setAlignmentY((float)0.0); //align to bottom
//search button
mSearchButton = new JButton ("Search");
mSearchButton.addActionListener(new Search());
mSearchButton.setAlignmentY((float)0.0); //align to bottom
Dimension spacer = new Dimension (10, 10);
//assemble all the pieces together.
Box boxPane = new Box (BoxLayout.X_AXIS);
boxPane.add (innerBoxPane); //explaination and text field
boxPane.add (Box.createRigidArea(spacer)); //spacer
boxPane.add (lbl); //"in:" label
@ -1037,10 +1038,10 @@ public class AddressBook extends GeneralFrame {
boxPane.add (mSearchSource); //drop down combo box
boxPane.add (Box.createRigidArea(spacer)); //spacer
boxPane.add (mSearchButton); //search buttton
return boxPane;
}
private JScrollPane createTable () {
String[] columnNames = {
"Name",
@ -1049,52 +1050,52 @@ public class AddressBook extends GeneralFrame {
"Phone",
"City",
"Nickname"};
//create the data model.
DataModel dm = new DataModel (columnNames);
//create the table.
mTable = new JTable(dm);
// mTable.setAutoCreateColumnsFromModel(false);
// Add our columns into the column model
// for (int columnIndex = 0; columnIndex < columnNames.length; columnIndex++){
// Create a column object for each column of data
// TableColumn newColumn = new TableColumn(columnNames[columnIndex]);
// Set a tool tip for the column header cell
// TableCellRenderer renderer2 = newColumn.getHeaderRenderer();
// if (renderer2 instanceof DefaultCellRenderer)
// ((DefaultCellRenderer)renderer2).setToolTipText(columnNames[columnIndex]);
// newColumn.setWidth(200);
// mTable.addColumn(newColumn);
// }
//no selection, no grid.
mTable.setColumnSelectionAllowed(false);
mTable.setShowGrid(false);
// Put the table and header into a scrollPane
JScrollPane scrollpane = new JScrollPane(mTable);
// JTableHeader tableHeader = mTable.getTableHeader();
// create and add the column heading to the scrollpane's
// column header viewport
// JViewport headerViewport = new JViewport();
// headerViewport.setLayout(new BoxLayout(headerViewport, BoxLayout.X_AXIS));
// headerViewport.add(tableHeader);
// scrollpane.setColumnHeader(headerViewport);
// add the table to the viewport
/// JViewport mainViewPort = scrollpane.getViewport();
// mainViewPort.add(mTable);
// mainViewPort.setBackground (Color.white);
// speed up resizing repaints by turning off live cell updates
// tableHeader.setUpdateTableInRealTime(false);
//return the JScrollPane with the table in it.
return scrollpane;
}

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

@ -1,241 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Lester Schueler <lesters@netscape.com>, 14 Nov 1997.
*
* Contributors: Christoph Toshok <toshok@netscape.com>
* Jeff Galyan <talisman@anamorphic.com>
*/
package grendel.addressbook.addresscard;
import grendel.storage.intertwingle.*;
import java.util.Enumeration;
import java.io.File;
import java.io.IOException;
//import java.util.Vector;
//************************
//************************
public class ACS_Personal implements ICardSource, IQuerySet {
private DB fDB;
public ACS_Personal (String FileName, boolean CreateOnOpen) {
File DBFile = new File(FileName);
try {
fDB = new SimpleDB(DBFile);
} catch (Exception e) {}
}
/** Get the next card ID for this DB.
*/
private String getNextCardID () {
int nextCardIntID = 0;
String nextCardStrID;
try {
//initalize the next card ID
nextCardStrID = fDB.findFirst ("Control", "NextCardID", false);
//if the value wasn't found then assume this is the first time.
if ((null == nextCardStrID) || (nextCardStrID.equals (""))) {
nextCardIntID = 0;
}
//if the value WAS found then try to extract an integer value from the text.
else {
try {
nextCardIntID = Integer.valueOf(nextCardStrID).intValue();
} catch (NumberFormatException nfe) {
nextCardIntID = 0;
}
}
} catch (Exception e) {
nextCardIntID = 0;
}
//create a string representation of the card's ID.
nextCardStrID = String.valueOf(++nextCardIntID);
try {
//write the new value out to the DB.
fDB.assert ("Control", "NextCardID", nextCardStrID);
} catch (IOException ioe) {
}
return nextCardStrID;
}
/**
* closing the source
*/
public void close () {
try {
((BGDB) fDB).flushChanges();
} catch (IOException ioe) {
}
}
/**
* No-op implementations for now (just to get this building properly)
* (Jeff)
*/
public AC_IDSet opEqual(IAttribute anAttribute) { return null; }
public AC_IDSet opNotEqual(IAttribute anAttribute) { return null; }
/**
* retrieving address cards
*/
public ICardSet getCardSet (ITerm aQueryTerm, String[] anAttributesArray) {
//get the card ID's that satisfy the query.
AC_IDSet CardIDSet = aQueryTerm.evaluate_ACSP (this);
//create the address card set that'll be returned.
AddressCardSet retCardSet = new AddressCardSet ();
for (int i = 0; i < CardIDSet.size(); i++) {
//create an attribute set for the card.
AddressCardAttributeSet attrSet = new AddressCardAttributeSet();
//get all attributes for this card.
for (int j = 0; j < anAttributesArray.length; j++) {
String attrName = anAttributesArray[j];
//read the attribute from the DB.
try {
String attrValue = fDB.findFirst((String) CardIDSet.elementAt(i), attrName, false);
//if found then add to the attribute set for this card.
if (null != attrValue) {
attrSet.add (new AddressCardAttribute (attrName, attrValue));
}
} catch (IOException ioe) {}
}
//create the new card, and add to the return card set.
retCardSet.add (new AddressCard(this, attrSet));
}
//return the card set
return retCardSet;
}
/** Add a single card to this addressbook.
*/
public void add (AddressCard aCard, boolean OverWrite) {
//give the card a new ID
String thisCardID = getNextCardID ();
aCard.setID (thisCardID);
//get the set of attributes and enumerate thruough them.
AddressCardAttributeSet attrSet =
(AddressCardAttributeSet)aCard.getAttributeSet();
for (Enumeration enum = attrSet.elements (); enum.hasMoreElements(); ) {
//get the next attribute
AddressCardAttribute attr = (AddressCardAttribute) enum.nextElement ();
//write the attribute to the DB
try {
fDB.assert (thisCardID, attr.getName(), attr.getValue());
} catch (IOException ioe) {}
}
}
/** Add a set of cards to this addressbook.
*/
public void add (AddressCardSet aCardSet, boolean OverWrite) {
for (Enumeration enum = aCardSet.getCardEnumeration (); enum.hasMoreElements() ;) {
AddressCard card = (AddressCard) enum.nextElement();
add (card, OverWrite);
}
}
/** No-op implementation of the add(ICard) method from ICardSource
*/
public void add (ICard card) { }
/** No-op implementation of update(ICard) from ICardSource
*/
public void update(ICard card) { }
/** No-op implementation of delete(ICard) from ICardSource
*/
public void delete(ICard card) { }
//*******************************
//**** Operational functions ****
//*******************************
/** Search the database for all cards that match this value
* and return a set Adddress Card ID's (ACID's).
*/
public AC_IDSet opEqual (AC_Attribute ACA) {
AC_IDSet retIDSet = new AC_IDSet();
if (null != ACA) {
try { //the RDFish DB returns an enumeration of a matching card ID's
for (Enumeration enum = fDB.findAll(ACA.getName(), ACA.getValue (), false); enum.hasMoreElements() ;) {
retIDSet.addElement (enum.nextElement());
}
} catch (IOException exc) {
exc.printStackTrace();
}
}
return retIDSet;
}
/** Search the database for all cards that DO NOT match this value
* and return a set Adddress Card ID's (ACID's).
*/
public AC_IDSet opNotEqual (AC_Attribute ACA) {
AC_IDSet retIDSet = new AC_IDSet();
return retIDSet;
}
/*
1.Boolean RDF_HasAssertion (RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, Boolean tv);
Returns true if there is an arc in the graph whose origin is u, whose label is s, whose target is v and whose truth value is true.
2.void* RDF_GetSlotValue (RDF_Resource u, RDF_Resource s, RDF_ValueType type, Boolean inversep, Boolean tv);
Returns the target (whose datatype is type) of (any) one of the arcs whose source is u, label is s and truth value is tv. If inversep is true,
then it return the source (whose datatype is type) of (any) one of the arcs whose target is u, label is s and truth value is tv.
3.RDF_Cursor RDF_GetSlotValues (RDF_Resource u, RDF_Resource s, RDF_ValueType type, Boolean inversep, Boolean tv);
Returns a cursor that can be used to enumerate through the targets (of datatype type) of the arcs whose source is u, label is s and truth
value is tv. If inversep is true, then the cursor enumerates through the sources of the arcs whose label is s, target is u and truth value is tv.
You can store your private data on the pdata field of the cursor. Cursors are cheap.
4.void* RDF_NextValue(RDF_Cursor c);
Returns the next value from this cursor. Returns NULL if there are no more values. The fields value and type hold the value and datatype
of the value respectively.
5.RDF_Error RDF_DisposeCursor (RDF_Cursor c);
When you are done with a cursor, call this function. Remember to free your pdata before calling this.
*/
}

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

@ -1,72 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Jeff Galyan.
* Portions created by Jeff Galyan are
* Copyright (C) 1997 Jeff Galyan. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Jeff Galyan <talisman@anamorphic.com>, 16 Jan 1999
*/
package grendel.addressbook.addresscard;
import java.util.Enumeration;
import java.util.Vector;
/** Defines an addresscard set.
*/
public class AddressCardSet implements ICardSet {
private Vector cards;
public AddressCardSet() {
cards = new Vector();
}
public Enumeration getCardEnumeration() {
return getEnumeration();
}
//*********************************
// Methods defined for ICardSet
//*********************************
public void add(ICard aCard) {
cards.addElement(aCard);
}
public void remove(ICard aCard) {
for (int i = 0; i < cards.size(); i++) {
if (cards.elementAt(i).equals(aCard)) {
cards.removeElementAt(i);
}
}
cards.trimToSize();
}
public void sort(String[] anAttributeArray) {
Enumeration enum = getEnumeration();
while (enum.hasMoreElements()) {
}
}
public Enumeration getEnumeration() {
return cards.elements();
}
}

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

@ -1,280 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Lester Schueler <lesters@netscape.com>, 14 Nov 1997.
*
* Contributors: Christoph Toshok <toshok@netscape.com>
*/
package grendel.addressbook.addresscard;
import netscape.ldap.*;
import java.util.*;
//************************
//************************
public class LDAP_Server implements ICardSource, IQueryString {
LDAPConnection fConnection;
public LDAP_Server (String ServerName) {
this (ServerName, 389, "", "");
}
public LDAP_Server (String aServerName, int aPort, String aUserName, String aPassword) {
try {
// Connect to server.
fConnection = new LDAPConnection();
fConnection.connect (aServerName, aPort);
// authenticate to the directory as nobody.
//fConnection.authenticate( aUserName, aPassword );
} catch( LDAPException e ) {
System.out.println( "Error: " + e.toString() );
}
return;
}
/** Close the addres card source
*/
public void close () {
}
private final static String LEFT_PAREN = "(";
private final static String RIGHT_PARAN = ")";
private String escape (String aStringToEscape) {
String escapeChars = LEFT_PAREN + RIGHT_PARAN + "*";
//FIX
return aStringToEscape;
}
public String opAnd (ITerm aLeftTerm, ITerm aRightTerm) {
return LEFT_PAREN + "&" + aLeftTerm.getExpression (this) + aRightTerm.getExpression (this) + RIGHT_PARAN;
}
public String opOr (ITerm aLeftTerm, ITerm aRightTerm) {
return LEFT_PAREN + "|" + aLeftTerm.getExpression (this) + aRightTerm.getExpression (this) + RIGHT_PARAN;
}
public String opEqual (IAttribute ACA) {
return LEFT_PAREN + ACA.getName() + "=" + escape (ACA.getValue ()) + RIGHT_PARAN;
}
public String opNotEqual (IAttribute ACA) {
return LEFT_PAREN + "!" + opEqual (ACA) + RIGHT_PARAN;
}
public String opGTE (IAttribute ACA) {
return LEFT_PAREN + ACA.getName() + ">=" + escape (ACA.getValue ()) + RIGHT_PARAN;
}
public String opLTE (IAttribute ACA) {
return LEFT_PAREN + ACA.getName() + "<=" + escape (ACA.getValue ()) + RIGHT_PARAN;
}
/** Retrieveing address cards as a set.
*/
public ICardSet getCardSet (ITerm aQueryTerm, String[] anAttributesArray) {
final String COMMON_NAME_ID = "cn";
final String ORGANIZATION_ID = "o";
final String COUNTRY_ID = "c";
final String SIR_NAME_ID = "sn";
final String MAIL_ID = "mail";
LDAPSearchResults queryResults = null;
try {
String filter = aQueryTerm.getExpression(this);
String searchBase = COUNTRY_ID + "=" + "US";
LDAPSearchConstraints cons = fConnection.getSearchConstraints();
cons.setBatchSize( 1 );
queryResults = fConnection.search( searchBase,
LDAPConnection.SCOPE_ONE,
filter,
anAttributesArray,
false,
cons);
}
catch( LDAPException e ) {
System.out.println( "Error: " + e.toString() );
}
return new LDAP_CardSet (this, queryResults);
}
/** Add an entry to the server.
*/
public void add (ICard aCard) throws AC_Exception {
//get all attributes for this card as a set
IAttributeSet AC_attrSet = aCard.getAttributeSet (); //From AddressCard
LDAPAttributeSet LDAP_attrSet = new LDAPAttributeSet(); //To LDAP
//enumerate thru each attribute and translate from CA attributes into LDAP attributes.
for (Enumeration enum = AC_attrSet.getEnumeration(); enum.hasMoreElements() ;) {
//Get the old
IAttribute AC_attr = (IAttribute) enum.nextElement();
//Create the new
LDAPAttribute LDAP_attr = new LDAPAttribute(AC_attr.getName(), AC_attr.getValue());
//add the attribute to the LDAP set.
LDAP_attrSet.add( LDAP_attr );
}
try {
//FIX!!!
//create a new enry for the LDAP server
String dn = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US";
LDAPEntry anEntry = new LDAPEntry( dn, LDAP_attrSet );
//*** ADD THE ENTRY ***
fConnection.add( anEntry );
} catch (LDAPException le) {
//FIX
throw new AC_Exception ("Couldn't add card to server.");
}
}
/** Delete an entry from the server.
*/
public LDAP_Card checkMyCard (ICard aCard) throws AC_Exception {
//check that the etnry came from an LDAP server.
if (aCard instanceof LDAP_Card) {
LDAP_Card card = (LDAP_Card) aCard;
//check that the entry can from this LDAP server.
if (this == card.getParent ()) {
//everthing's fine so return the card.
return card;
}
else {
throw new AC_Exception ("Not from this server.");
}
}
else {
throw new AC_Exception ("Not from an LDAP server.");
}
}
/** Delete an entry from the server.
*/
public void delete (ICard aCard) throws AC_Exception {
try {
//make sure the card came from this server.
LDAP_Card card = checkMyCard(aCard); //throws AC_Exception.
//FIX
//?? What can still LOCALY happen to the card after it's deleted from the LDPA server??
try {
//*** DELETE THE ENTRY ***
fConnection.delete ( card.getDN() );
} catch (LDAPException le) {
//FIX
throw new AC_Exception ("Couldn't delete card from server.");
}
}
//BAD card. The card didn't come from this server.
catch (AC_Exception ace) {
//rethrow the exception
throw ace;
}
}
/** Update an entries attributes on the server.
*/
public void update (ICard aCard) throws AC_Exception {
try {
//make sure the card came from this server.
LDAP_Card card = checkMyCard(aCard); //throws AC_Exception.
//Ok, the card came from us so lets try to update the server.
//Get the set of attributes that have changed.
IAttributeSet AC_attrSet = card.getAttributeSet ();
//Create a modifcation set to provide to the LDAP server.
LDAPModificationSet LDAP_modSet = new LDAPModificationSet();
//enumerate thru each attribute
for (Enumeration enum = AC_attrSet.getEnumeration() ; enum.hasMoreElements() ;) {
IAttribute AC_attr = (IAttribute) enum.nextElement();
int LDAP_mod = 0;
boolean attributeModified = false;
//Has the attribute been added?
if (true == AC_attr.isNew ()) {
LDAP_mod = LDAPModification.ADD;
attributeModified = true;
}
//Has the attribute been deleted?
else if (true == AC_attr.isDeleted ()) {
LDAP_mod = LDAPModification.DELETE;
attributeModified = true;
}
//Has the attribute been changed?
else if (true == AC_attr.isModified ()) {
LDAP_mod = LDAPModification.REPLACE;
attributeModified = true;
}
//if modified then add to mod set.
if (true == attributeModified) {
LDAPAttribute LDAP_attr = new LDAPAttribute(AC_attr.getName(), AC_attr.getValue());
LDAP_modSet.add (LDAP_mod, LDAP_attr);
}
}
//Did we get any modifcations to send to the server?
if (0 < LDAP_modSet.size()) {
//submit the modifcation set to the server
try {
//*** MODIFY THE ENTRY ***
fConnection.modify (card.getDN(), LDAP_modSet);
} catch (LDAPException le) {
//FIX
throw new AC_Exception ("Couldn't update server.");
}
}
}
//BAD card. The card didn't come from this server.
catch (AC_Exception ace) {
//rethrow the exception
throw ace;
}
// //else the card didn't come from this server so throw excpetion
// else {
// //FIX
// //Need to consider weather is ok for a card from one connection to update
// //to another connection of both connections are talking to the same server.
// throw new AC_Exception ("Address Card didn't originate from this connection.");
// }
}
}

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

@ -1,393 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): Jeff Galyan <talisman@anamorphic.com>
* Edwin Woudt <edwin@woudt.nl>
*/
package grendel.composition;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
class AddressDialog extends Dialog implements ActionListener {
private final int BUTTON_WIDTH = 100;
private final int BUTTON_HEIGHT = 28;
private List mSendToList; //ListBox gadget that holds recipients names.
private JTable mTable; //Tbale displays the address book entries.
private Vector mAddresses; //a parallel list of recipients with mSendToList.
private boolean wasCanceled = true; //true if Cancel button was used to dismiss dialog.
//FIX remove
final Object[][] data = {
{"Name",
"Lester Schueler",
"Don Vale",
"Chris Dreckman",
"Fred Cutler",
"Rod Spears"
},
{"Email Address",
"lesters@netscape.com",
"dvale@netscape.com",
"chrisd@netscape.com",
"fredc@netscape.com",
"rods@netscape.com"
},
{"Organization",
"Netscape Comm.",
"Netscape Comm.",
"Netscape Comm.",
"Netscape Comm.",
"Netscape Comm."
},
{"Phone",
"(619)618-2227",
"(619)618-2224",
"(619)618-2211",
"(619)618-2206",
"(619)618-2228"
}
};
//FIX remove
public static void main(String[] args) {
Frame frame = new JFrame();
frame.setBackground(Color.lightGray);
AddressDialog aDialog = new AddressDialog(frame);
aDialog.show ();
aDialog.dispose();
frame.show();
}
/**
*
*/
AddressDialog(Frame aParent) {
//FIX: Resource
super(aParent, "Select Addresses", true);
mAddresses = new Vector();
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
JComponent lookupPanel = createLookupPanel ();
add (lookupPanel);
JComponent SendToPanel = createSendToPanel ();
add (SendToPanel);
JComponent bottomPanel = createBottomPanel ();
add (bottomPanel);
setResizable(false);
setSize (716, 480);
}
/**
*
*/
private JPanel createLookupPanel () {
//the outer most panel has groove etched into it.
JPanel outerPanel = new JPanel(true);
//FIX: Resource
outerPanel.setBorder(new TitledBorder(new EtchedBorder(), "Type in the name you are looking for:"));
outerPanel.setLayout (new BorderLayout ());
outerPanel.setPreferredSize(new Dimension (500, 225));
// "North" panel
JPanel northPanel = new JPanel (true);
northPanel.setLayout (new FlowLayout (FlowLayout.LEFT, 5, 5));
northPanel.setPreferredSize(new Dimension (500, 35));
//Search text field
JTextField searchTxt = new JTextField (20);
northPanel.add (searchTxt);
//FIX: Resource
northPanel.add (new JLabel ("In:"));
JComboBox combo = new JComboBox();
combo.setPreferredSize(new Dimension (275, 25));
northPanel.add (combo);
//FIX: Resource
JButton b = makeButton ("Search", BUTTON_WIDTH, BUTTON_HEIGHT);
ButtonModel bm = b.getModel();
bm.setEnabled(false);
northPanel.add (b);
// Center table
TableModel dataModel;
// Create the table data model
dataModel = new AbstractTableModel() {
public int getRowCount() { return data[0].length - 1; }
public int getColumnCount() { return data.length; }
public Object getValueAt(int rowIndex, int columnIndex) {
return data[columnIndex][rowIndex+1];
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
data[columnIndex][rowIndex+1] = aValue;
}
public int getColumnIndex(Object aID) {
for (int i = 0; i < data.length; i++) {
if (data[i][0].equals(aID)) {
return i;
}
}
return -1;
}
};
// Create the table
mTable = new JTable(dataModel);
// Added our columns into the column model
for (int columnIndex = 0; columnIndex < data.length; columnIndex++){
// Create a column object for each column of data
TableColumn newColumn = new TableColumn(columnIndex);
newColumn.setWidth(200);
mTable.addColumn(newColumn);
}
mTable.setColumnSelectionAllowed(false);
mTable.setShowGrid(false);
// Put the table and header into a scrollPane
JScrollPane scrollpane = new JScrollPane();
JTableHeader tableHeader = mTable.getTableHeader();
// create and add the column heading to the scrollpane's
// column header viewport
JViewport headerViewport = new JViewport();
headerViewport.setLayout(new BoxLayout(headerViewport, BoxLayout.X_AXIS));
headerViewport.add(tableHeader);
scrollpane.setColumnHeader(headerViewport);
// add the table to the viewport
JViewport mainViewPort = scrollpane.getViewport();
mainViewPort.add(mTable);
// speed up resizing repaints by turning off live cell updates
tableHeader.setUpdateTableInRealTime(false);
// South panel
JPanel southPanel = new JPanel (true);
//FIX: Resource
southPanel.setLayout (new FlowLayout (FlowLayout.LEFT, 10, 0));
southPanel.add (makeButton ("To:", BUTTON_WIDTH, BUTTON_HEIGHT));
southPanel.add (makeButton ("Cc:", BUTTON_WIDTH, BUTTON_HEIGHT));
southPanel.add (makeButton ("Bcc:", BUTTON_WIDTH, BUTTON_HEIGHT));
//FIX
JButton jb = makeButton ("Add to Address Book", 184, BUTTON_HEIGHT);
ButtonModel jbm = jb.getModel();
jbm.setEnabled(false);
southPanel.add (jb);
JPanel panel2 = new JPanel (new BorderLayout (5, 5), true);
panel2.setBorder (new EmptyBorder (5, 5, 5, 5));
panel2.add (northPanel, BorderLayout.NORTH);
panel2.add (scrollpane, BorderLayout.CENTER);
panel2.add (southPanel, BorderLayout.SOUTH);
outerPanel.add (panel2, BorderLayout.CENTER);
return outerPanel;
}
/**
* The Send To Panel holds the list people.
*/
private JPanel createSendToPanel () {
//the outer most panel has groove etched into it.
JPanel etchedPanel = new JPanel();
//FIX: Resource
etchedPanel.setBorder(new TitledBorder(new EtchedBorder(), "This message will be sent to:"));
etchedPanel.setLayout (new BorderLayout (5, 5));
etchedPanel.setPreferredSize(new Dimension (500, 175));
JPanel panel2 = new JPanel (new BorderLayout (5, 5), true);
panel2.setBorder (new EmptyBorder(5, 5, 5, 5));
// Center Listbox panel
mSendToList = new List();
mSendToList.setBackground (Color.white);
panel2.add (mSendToList, BorderLayout.CENTER);
JPanel panel3 = new JPanel (new BorderLayout(), true);
//FIX: Resource
panel3.add (makeButton ("Remove", BUTTON_WIDTH, BUTTON_HEIGHT), BorderLayout.WEST);
panel2.add (panel3, BorderLayout.SOUTH);
etchedPanel.add (panel2, BorderLayout.CENTER);
return etchedPanel;
}
/**
* The bottom panel has the ok, cancel and help buttons.
*/
private JPanel createBottomPanel () {
JPanel panel = new JPanel (true);
panel.setLayout (new FlowLayout (FlowLayout.CENTER, 25, 8));
//FIX: Resource
panel.add (makeButton ("OK", BUTTON_WIDTH, BUTTON_HEIGHT));
panel.add (makeButton ("Cancel", BUTTON_WIDTH, BUTTON_HEIGHT));
//FIX
JButton b = makeButton ("Help", BUTTON_WIDTH, BUTTON_HEIGHT);
panel.add (b);
ButtonModel bm = b.getModel();
bm.setEnabled(false);
return panel;
}
private JButton makeButton (String aLabel, int aWidth, int aHeight) {
JButton button = new JButton (aLabel);
button.setPreferredSize(new Dimension (aWidth, aHeight));
button.addActionListener (this);
return button;
}
public Insets getInsets () {
return (new Insets (25, 10, 10, 10));
}
/**
* Adds an entry to the send list.
* @param The Addressee to be added to the list.
*/
private void addToSendList (Addressee aAddressee) {
if (null != aAddressee) {
mSendToList.add (aAddressee.deliveryString () + " " + aAddressee.getText());
mAddresses.addElement (aAddressee);
}
}
/**
* Removes the specified entry from the list.
* @param The index of the entry to remove.
*/
private void removeFromSendList (int aIndex) {
if (-1 < aIndex) {
mSendToList.remove (aIndex);
mAddresses.removeElementAt (aIndex);
}
}
/**
* Sets the address from aa Array.
* @param aAddresses An array of addresses.
* @see getAddresses
*/
public void setAddresses (Addressee[] aAddresses) {
mAddresses.removeAllElements();
mSendToList.removeAll();
if (null != aAddresses) {
for (int i = 0; i < aAddresses.length; i++) {
addToSendList (aAddresses[i]);
}
}
}
/**
* Returns the addresses in the form of an array.
* @returns An array of addresses.
* @see setAddresses
*/
public Addressee[] getAddresses () {
int arrSize = mAddresses.size();
if (0 < arrSize) {
Addressee[] anArray = new Addressee[arrSize];
mAddresses.copyInto(anArray);
return anArray;
}
return null;
}
/**
* Return true if cancel was pressed.
*/
public boolean getCanceled () { return wasCanceled; }
/**
* Actions to respond to are button pressed for "To", "Cc", "Bcc", "Ok", and "Canel"
*/
public void actionPerformed (ActionEvent e) {
String s = e.getActionCommand ();
//FIX: Resource
if (s.equals ("To:")) {
int selectedRow = mTable.getSelectedRow();
if (-1 != selectedRow)
addToSendList (new Addressee ((String) data[1][selectedRow + 1], Addressee.TO));
}
//FIX: Resource
else if (s.equals ("Cc:")) {
int selectedRow = mTable.getSelectedRow();
if (-1 != selectedRow)
addToSendList (new Addressee ((String) data[1][selectedRow + 1], Addressee.CC));
}
//FIX: Resource
else if (s.equals ("Bcc:")) {
int selectedRow = mTable.getSelectedRow();
if (-1 != selectedRow)
addToSendList (new Addressee ((String) data[1][selectedRow + 1], Addressee.BCC));
}
//FIX: Resource
else if (s.equals ("Remove")) {
int index = mSendToList.getSelectedIndex();
if (-1 < index)
removeFromSendList (index);
}
//FIX: Resource
else if (s.equals ("Cancel")) {
wasCanceled = true;
setVisible(false);
}
//FIX: Resource
else if (s.equals ("OK")) {
wasCanceled = false;
setVisible(false);
}
}
}

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

@ -534,7 +534,7 @@ public class AddressList extends JScrollPane implements Serializable {
//create image icon for drag and drop.
mIcon = new ImageIcon(getClass().getResource("images/card.gif"));
mIcon = new ImageIcon("composition/images/card.gif");
}
public void paint (Graphics g) {

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

@ -1,130 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
package grendel.composition;
import java.beans.*;
import java.lang.reflect.Method;
/** BeanInfo for AttachmentsList:
*/
public class AttachmentsListBeanInfo extends SimpleBeanInfo {
private final static Class beanClass = AttachmentsList.class;
// getIcon returns an image object which can be used by toolboxes, toolbars
// to represent this bean. Icon images are in GIF format.
public java.awt.Image getIcon(int iconKind)
{
if (iconKind == BeanInfo.ICON_COLOR_16x16 ||
iconKind == BeanInfo.ICON_MONO_16x16)
{
java.awt.Image img = loadImage("images/AttachmentsListIcon16.gif");
return img;
}
if (iconKind == BeanInfo.ICON_COLOR_32x32 ||
iconKind == BeanInfo.ICON_MONO_32x32)
{
java.awt.Image img = loadImage("images/AttachmentsListIcon32.gif");
return img;
}
return null;
}
// getPropertyDescriptors returns an array of PropertyDescriptors which describe
// the editable properties of this bean.
public PropertyDescriptor[] getPropertyDescriptors() {
/*
try {
PropertyDescriptor prop1 = new PropertyDescriptor("prop1", beanClass);
prop1.setBound(true);
prop1.setDisplayName("Property 1");
PropertyDescriptor rv[] = {prop1, prop2};
return rv;
}
catch (IntrospectionException e) {
throw new Error(e.toString());
}
*/
return null;
}
public MethodDescriptor[] getMethodDescriptors() {
try {
Method mthd;
//showDialog requests that the AddressList display its file dialog.
//public void showDialog () {
mthd = beanClass.getMethod ("showDialog", null);
MethodDescriptor showDialogDesc = new MethodDescriptor (mthd);
showDialogDesc.setShortDescription ("Displays the file dialog");
//Sets this gadgets enabled state.
//public void setEnabled (boolean aEnabled) {
ParameterDescriptor setEnabledPD = new ParameterDescriptor ();
setEnabledPD.setShortDescription ("Boolean value for enabled");
ParameterDescriptor[] setEnabledPDA = { setEnabledPD };
Class[] setEnabledParams = { java.lang.Boolean.TYPE };
mthd = beanClass.getMethod ("setEnabled", setEnabledParams);
MethodDescriptor setEnabledDesc = new MethodDescriptor (mthd, setEnabledPDA);
setEnabledDesc.setShortDescription ("Sets this gadgets enabled state");
//Delets all attachments from the list.
//public void removeAllAttachments () {
mthd = beanClass.getMethod ("removeAllAttachments", null);
MethodDescriptor removeAllAttachmentsDesc = new MethodDescriptor (mthd);
removeAllAttachmentsDesc.setShortDescription ("Delets all attachments from the list");
//Remove an entry at index from the list.
//public void removeAttachment (int aIndex) {
ParameterDescriptor removeAttachmentPD = new ParameterDescriptor ();
removeAttachmentPD.setShortDescription ("The index of the attachment to remove");
ParameterDescriptor[] removeAttachmentPDA = { removeAttachmentPD };
Class[] removeAttachmentParams = { java.lang.Integer.TYPE };
mthd = beanClass.getMethod ("removeAttachment", removeAttachmentParams);
MethodDescriptor removeAttachmentDesc = new MethodDescriptor (mthd, removeAttachmentPDA);
removeAttachmentDesc.setShortDescription ("Remove an entry at index from the list");
//Adds an file to the list.
//public void addAttachment (String aFilePath) {
ParameterDescriptor addAttachmentPD = new ParameterDescriptor ();
addAttachmentPD.setShortDescription ("A file path");
ParameterDescriptor[] addAttachmentPDA = { addAttachmentPD };
Class[] addAttachmentParams = { String.class };
mthd = beanClass.getMethod ("addAttachment", addAttachmentParams);
MethodDescriptor addAttachmentDesc = new MethodDescriptor (mthd, addAttachmentPDA);
addAttachmentDesc.setShortDescription ("Adds an file to the list");
//pull it all together now.
MethodDescriptor [] mda = { showDialogDesc, setEnabledDesc, removeAllAttachmentsDesc, removeAttachmentDesc, addAttachmentDesc }; return mda;
}
catch (SecurityException e) {
return null;
}
catch (NoSuchMethodException e) {
return null;
}
}
}

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

@ -42,6 +42,7 @@ import grendel.widgets.GrendelToolBar;
import grendel.ui.FolderPanel;
import grendel.ui.GeneralFrame;
import grendel.ui.StoreFactory;
import grendel.ui.XMLMenuBuilder;
import javax.mail.Address;
import javax.mail.Message;
@ -87,8 +88,8 @@ public class Composition extends GeneralFrame {
//create menubar (top)
// fMenu = buildMenu("mainMenubar",
// mCompositionPanel.getActions());
fMenu = buildMenu("menus.xml",
mCompositionPanel.getActions());
XMLMenuBuilder builder = new XMLMenuBuilder(mCompositionPanel.getActions());
fMenu = builder.buildFrom("ui/menus.xml", (JFrame)this);
getRootPane().setJMenuBar(fMenu);
@ -122,12 +123,14 @@ public class Composition extends GeneralFrame {
fPanel.add(BorderLayout.NORTH, mBox);
fStatusBar = buildStatusBar();
fPanel.add(BorderLayout.SOUTH, fStatusBar);
fPanel.add(mCompositionPanel);
restoreBounds();
restoreBounds();
mCompositionPanel.AddSignature();
setSize(670, 490);
}
public void dispose() {
@ -194,7 +197,7 @@ public class Composition extends GeneralFrame {
mCompositionPanel.QuoteOriginalMessage();
}
/** Initialize the headers and body of this composition
/** Initialize the headers and body of this composition
as being a message that is forwarded 'quoted'. */
public void initializeAsForward(Message msg, int aScope) {
mCompositionPanel.setReferredMessage(msg);
@ -213,7 +216,7 @@ public class Composition extends GeneralFrame {
if (aScope == FolderPanel.kInline) {
mCompositionPanel.InlineOriginalMessage();
}
}
class PanelListener implements CompositionPanelListener {

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 20 Oct 1997.
*
@ -89,10 +89,11 @@ import grendel.storage.MessageExtra;
import grendel.storage.MessageExtraFactory;
import grendel.ui.ActionFactory;
import grendel.ui.GeneralPanel;
import grendel.ui.UIAction;
import grendel.widgets.CollapsiblePanel;
import grendel.widgets.GrendelToolBar;
import com.trfenv.parsers.Event;
public class CompositionPanel extends GeneralPanel {
private Hashtable mCommands;
private Hashtable mMenuItems;
@ -150,7 +151,7 @@ public class CompositionPanel extends GeneralPanel {
* of actions supported by the embedded JTextComponent
* augmented with the actions defined locally.
*/
public UIAction[] getActions() {
public Event[] getActions() {
return defaultActions;
// XXX WHS need to translate Actions to UICmds
// return TextAction.augmentList(mEditor.getActions(), defaultActions);
@ -187,7 +188,7 @@ public class CompositionPanel extends GeneralPanel {
public void addCompositionPanelListener(CompositionPanelListener l) {
mListeners.add(CompositionPanelListener.class, l);
}
/**
* Remove a CompositionPanelListener
*/
@ -199,7 +200,7 @@ public class CompositionPanel extends GeneralPanel {
/**
* Quote the orgininal message in a reply
*/
public void QuoteOriginalMessage() {
QuoteOriginalText qot = new QuoteOriginalText();
qot.actionPerformed(new ActionEvent(this,0,""));
@ -208,7 +209,7 @@ public class CompositionPanel extends GeneralPanel {
/**
* Inline the orgininal message when forwarding
*/
public void InlineOriginalMessage() {
InlineOriginalText iot = new InlineOriginalText();
iot.actionPerformed(new ActionEvent(this,0,""));
@ -217,7 +218,7 @@ public class CompositionPanel extends GeneralPanel {
/**
* Add a signature
*/
public void AddSignature() {
AddSignatureAction asa = new AddSignatureAction();
asa.actionPerformed(new ActionEvent(this,0,""));
@ -316,11 +317,11 @@ public class CompositionPanel extends GeneralPanel {
public static final String viewAttachmentsTag ="viewAttachments";
public static final String viewOptionsTag ="viewOptions";
public static final String wrapLongLinesTag ="wrapLongLines";
// --- action implementations -----------------------------------
private UIAction[] defaultActions = {
private Event[] defaultActions = {
//"File" actions
// new SaveDraft(),
new SaveAs(),
@ -370,7 +371,7 @@ public class CompositionPanel extends GeneralPanel {
* Try to save the message to the "draft" mailbox.
* @see SaveAs
*/
class SaveDraft extends UIAction {
class SaveDraft extends Event {
SaveDraft() {
super(saveDraftTag);
this.setEnabled(true);
@ -382,7 +383,7 @@ public class CompositionPanel extends GeneralPanel {
* Try to save the message to a text file.
* @see SaveDraft
*/
class SaveAs extends UIAction {
class SaveAs extends Event {
SaveAs() {
super(saveAsTag);
this.setEnabled(true);
@ -391,7 +392,7 @@ public class CompositionPanel extends GeneralPanel {
public void actionPerformed(ActionEvent e) {
FileDialog fileDialog = new FileDialog (getParentFrame(), "Save As", FileDialog.SAVE);
fileDialog.setFile("untitled.txt");
fileDialog.show(); //blocks
fileDialog.setVisible(true); //blocks
String fileName = fileDialog.getFile();
//check for canel
@ -420,7 +421,7 @@ public class CompositionPanel extends GeneralPanel {
/**
* Send the mail message now.
*/
class SendNow extends UIAction {
class SendNow extends Event {
SendNow() {
super(sendNowTag);
this.setEnabled(true);
@ -462,7 +463,7 @@ public class CompositionPanel extends GeneralPanel {
try {
IdentityStructure ident = IdentityArray.GetMaster().get(
mAddressBar.getOptionsPanel().getSelectedIdentity());
//set who's sending this message.
msg.setFrom (new InternetAddress(ident.getEMail(), ident.getName()));
@ -492,7 +493,7 @@ public class CompositionPanel extends GeneralPanel {
msg.setSubject(mSubject.getText()); //set subject from text
//field.
msg.setHeader("X-Mailer", "Grendel [development version]");
//and proud of it!
//and proud of it!
msg.setSentDate(new java.util.Date()); //set date to now.
String [] attachments = mAttachmentsList.getAttachments();
@ -500,7 +501,7 @@ public class CompositionPanel extends GeneralPanel {
msg.setContent(messageText, "text/plain"); //contents.
} else {
MimeMultipart multi = new MimeMultipart();
MimeBodyPart mainText = new MimeBodyPart();
mainText.setText(messageText);
multi.addBodyPart(mainText);
@ -530,7 +531,7 @@ public class CompositionPanel extends GeneralPanel {
encName = "base64";
}
att.setText(new String(bs));
att.setText(new String(bs));
att.setHeader("Content-Type", mimeString);
att.setHeader("Content-Transfer-Encoding", encName);
att.setFileName(new File(attachments[i]).getName());
@ -553,7 +554,7 @@ public class CompositionPanel extends GeneralPanel {
} catch (MessagingException exc) {
exc.printStackTrace();
}
success = true;
} catch (javax.mail.SendFailedException sex) {
sex.printStackTrace();
@ -584,7 +585,7 @@ public class CompositionPanel extends GeneralPanel {
* Quote the original text message into the editor.
* @see PasteAsQuotation
*/
class QuoteOriginalText extends UIAction {
class QuoteOriginalText extends Event {
QuoteOriginalText() {
super(quoteOriginalTextTag);
this.setEnabled(true);
@ -669,7 +670,7 @@ public class CompositionPanel extends GeneralPanel {
* Inline the original text message into the editor.
* @see QuoteOriginalText
*/
class InlineOriginalText extends UIAction {
class InlineOriginalText extends Event {
InlineOriginalText() {
super(inlineOriginalTextTag);
this.setEnabled(true);
@ -762,7 +763,7 @@ public class CompositionPanel extends GeneralPanel {
/**
* Add a signature
*/
class AddSignatureAction extends UIAction {
class AddSignatureAction extends Event {
AddSignatureAction() {
super(addSignatureTag);
this.setEnabled(true);
@ -771,7 +772,7 @@ public class CompositionPanel extends GeneralPanel {
Document doc = mEditor.getDocument();
int oldPosition = mEditor.getCaretPosition();
//remove the old signature
for (int i=0; i<doc.getLength()-4;i++) {
try {
@ -784,10 +785,10 @@ public class CompositionPanel extends GeneralPanel {
ble.printStackTrace();
}
}
//the signature will be added at the end
int position = doc.getEndPosition().getOffset() - 1;
//compose the string including the separator
String s = "\n-- \n";
int ident = mAddressBar.getOptionsPanel().getSelectedIdentity();
@ -801,13 +802,13 @@ public class CompositionPanel extends GeneralPanel {
ble.printStackTrace();
}
}
mEditor.setCaretPosition(oldPosition);
}
}
class SelectAddresses extends UIAction {
class SelectAddresses extends Event {
SelectAddresses() {
super(selectAddressesTag);
this.setEnabled(true);
@ -822,7 +823,7 @@ public class CompositionPanel extends GeneralPanel {
//display the addressee dialog
aDialog.setAddresses (mAddresses); //initialize the dialog
aDialog.show (); //blocks
aDialog.setVisible (true); //blocks
if (false == aDialog.getCanceled()) {
//get the addresses from dialog
@ -843,7 +844,7 @@ public class CompositionPanel extends GeneralPanel {
//-----------------------
// "file->attach" actions
//-----------------------
class AttachFile extends UIAction {
class AttachFile extends Event {
AttachFile() {
super(fileTag);
this.setEnabled(true);
@ -864,7 +865,7 @@ public class CompositionPanel extends GeneralPanel {
* Quote and paste whatever string that's on the clipboard into the editor.
* @see QuoteOriginalText
*/
class PasteAsQuotation extends UIAction {
class PasteAsQuotation extends Event {
PasteAsQuotation() {
super(pasteAsQuotationTag);
this.setEnabled(true);

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

@ -1,107 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): Jeff Galyan <talisman@anamorphic.com>
Test program for the Composition Editor.
This program's only function is to get a SMTP server name and
a mail user name then perform the following two lines...
Composition CompFrame = new Composition(mailServerName, userName);
CompFrame.show();
(look near the bottom of this file)
*/
package grendel.composition;
import javax.swing.text.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class CompositionTest extends JPanel implements ActionListener {
JTextField mServerName;
JTextField mUserName;
JButton mSendMailButton;
public static void main(String[] args) {
JFrame frame = new JFrame("Composition test");
frame.addWindowListener(new AppCloser());
frame.setLayout (new BorderLayout ());
frame.add (new CompositionTest(), BorderLayout.CENTER);
//frame.setSize(450, 200);
frame.pack();
frame.show();
}
/**
* Closes the appliction.
*/
protected static final class AppCloser extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
CompositionTest () {
super (true);
setBackground (Color.lightGray);
setLayout(new FlowLayout());
add (new JLabel("Mail Server:"));
mServerName = new JTextField ("nsmail-2.mcom.com", 25);
add (mServerName);
add (new JLabel("User Name:"));
mUserName = new JTextField ("", 25);
add (mUserName);
mSendMailButton = new JButton ("Send Mail");
add (mSendMailButton);
mSendMailButton.addActionListener (this);
}
public void actionPerformed(ActionEvent evt) {
if (mSendMailButton == evt.getSource()) {
//check fields
String mailServerName = mServerName.getText().trim();
if (mailServerName.equals("")) {
System.out.println ("Please enter mail server name.");
return;
}
String userName = mUserName.getText().trim();
if (userName.equals("")) {
System.out.println ("Please enter a user name.");
return;
}
//This is where the compsiton editor is started.
Composition CompFrame = new Composition();
CompFrame.pack();
CompFrame.show();
}
}
}

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

@ -1,229 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Class FilterMaster.
*
* Created: David Williams <djw@netscape.com>, 1 Oct 1997.
*/
package grendel.filters;
import java.io.Reader;
import java.io.FileReader;
import java.io.File;
import java.io.EOFException;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.Hashtable;
import java.util.Enumeration;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Store;
import javax.mail.Session;
import javax.mail.MessagingException;
import javax.mail.search.SearchTerm;
import javax.mail.search.SubjectTerm;
import javax.mail.search.FromTerm;
import javax.mail.event.MessageCountEvent;
import grendel.storage.BerkeleyStore;
import grendel.ui.StoreFactory;
import grendel.filters.FilterSyntaxException;
import grendel.filters.MoveFilterActionFactory;
import grendel.filters.DeleteFilterActionFactory;
import grendel.filters.SubjectTermFactory;
public class FilterMaster extends Object {
// class slots
static private FilterMaster fTheMaster = null;
// class methods
public static FilterMaster Get() {
if (fTheMaster == null)
fTheMaster = new FilterMaster();
return fTheMaster;
}
// instance slots
private Hashtable fFilters; // to hold named filters
private Hashtable fFilterActionFactories;
private Hashtable fFilterTermFactories;
// constructor API
private FilterMaster() {
fFilters = new Hashtable();
fFilterTermFactories = new Hashtable();
fFilterActionFactories = new Hashtable();
// Register built-in terms.
registerFilterTermFactory(new SubjectTermFactory());
// Register built-in filter actions.
registerFilterActionFactory(new MoveFilterActionFactory());
registerFilterActionFactory(new DeleteFilterActionFactory());
// Locate and read the filters description file.
String home_dir = System.getProperties().getProperty("user.home");
File home_dir_file = new File(home_dir);
File mail_filters_file = new File(home_dir_file, "mail.filters");
FileReader fr = null;
try {
fr = new FileReader(mail_filters_file);
} catch (FileNotFoundException e) {
System.err.println("mail.filters not found, skipping loadFilters()");
fr = null;
}
// We must do this as loadFilters calls Get(), and we don't want to
// go recursive. This is a reasonable thing to do, because at this
// point, the constructor has succeeded, so we know we will be the
// FilterMaster.
fTheMaster = this;
if (fr != null)
loadFilters(fr);
}
// instance methods
private void loadFilters(Reader reader) {
IFilter filter;
FilterRulesParser parser = new FilterRulesParser(reader);
try {
while ((filter = parser.getNext()) != null) {
String name = filter.toString();
// System.err.println("got filter: " + name);
fFilters.put(name, filter);
}
} catch (FilterSyntaxException e) {
System.err.println("Error in filter rules: " + e);
} catch (IOException e) {
System.err.println("IO error reading filter rules: " + e);
}
parser = null;
}
/*package*/
void registerFilterActionFactory(IFilterActionFactory factory) {
String key = factory.getName();
if (fFilterActionFactories.get(key) != null) {
// FIXME
System.err.println("FilterMaster.registerFilterAction(): duplicate");
return;
}
fFilterActionFactories.put(key, factory);
}
/*package*/
IFilterActionFactory getFilterActionFactory(String name) {
return (IFilterActionFactory)fFilterActionFactories.get(name);
}
/*package*/
void registerFilterTermFactory(IFilterTermFactory factory) {
String key = factory.getName();
if (fFilterTermFactories.get(key) != null) {
// FIXME
System.err.println("FilterMaster.registerFilterTerm(): duplicate");
return;
}
fFilterTermFactories.put(key, factory);
}
/*package*/
IFilterTermFactory getFilterTermFactory(String name) {
return (IFilterTermFactory)fFilterTermFactories.get(name);
}
// tell me what you can do. Something like this will need to be created
// so that you can build a UI. Caller uses object.toString() on the
// elements to create user visible labels, etc..
public Enumeration getFilterActionFactories() {
return fFilterActionFactories.elements();
}
public Enumeration getFilterTermFactories() {
return fFilterTermFactories.elements();
}
public Enumeration getFilters() {
return fFilters.elements();
}
// The verb that this whole sub-system is about. Apply all the defined
// filters to the specified message.
public void applyFilters(Message message) {
boolean deleted = false;
try {
deleted = message.isSet(Flags.Flag.DELETED);
} catch (MessagingException e) {
deleted = false;
}
if (deleted)
return; // don't need to be here
Enumeration filters = getFilters();
while (filters.hasMoreElements()) {
IFilter filter = (IFilter)filters.nextElement();
if (filter.match(message)) {
filter.exorcise(message);
break; // only do first match
}
}
}
// Utilities:
public Folder getFolder(String name) {
Session session = StoreFactory.Instance().getSession();
// ### Definitely wrong:
Store store = BerkeleyStore.GetDefaultStore(session);
Folder folder;
try {
folder = store.getFolder(name);
if (!folder.exists())
folder = null;
} catch (MessagingException e) {
folder = null;
}
return folder;
}
// For Testing.
public void applyFiltersToTestInbox() {
Folder inbox = getFolder("TestInbox");
if (inbox != null) {
synchronized (inbox) {
Message[] messages;
try {
messages = inbox.getMessages();
} catch (MessagingException e) {
messages = null;
}
if (messages != null) {
for (int i = 0; i < messages.length; i++) {
applyFilters(messages[i]);
}
}
}
}
}
}

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 16 Oct 1997.
*
@ -180,7 +180,9 @@ public class MailServerPrefsEditor implements PropertyEditor
fHostListModel = new HostListModel();
URL url = getClass().getResource("PrefDialogs.xml");
fPanel = new PageUI(url, "id", "serverPrefs", fModel, getClass());
//XXXrlk: why does this constructor have parameters?
// fPanel = new PageUI(url, "id", "serverPrefs", fModel, getClass());
fPanel = new PageUI();
JComponent c;
ChangeAction ca = new ChangeAction();
@ -193,7 +195,7 @@ public class MailServerPrefsEditor implements PropertyEditor
c = fPanel.getCtrlByName(kMailDirectoryKey);
c.addPropertyChangeListener(ca);
c = fPanel.getCtrlByName(kChooseKey);
c.addPropertyChangeListener(ca);
@ -274,7 +276,7 @@ public class MailServerPrefsEditor implements PropertyEditor
fListeners.removePropertyChangeListener(l);
}
class ListListener
class ListListener
implements ListSelectionListener {
public void valueChanged(ListSelectionEvent e) {
System.out.println("foo");

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

@ -1,232 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 23 Dec 1997.
*
* Contributors: Jeff Galyan <talisman@anamorphic.com>
* Giao Nguyen <grail@cafebabe.org>
*/
package grendel.prefs;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyEditor;
import java.net.URL;
import java.util.EventObject;
import java.util.Hashtable;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.swing.JList;
import javax.swing.JComponent;
import javax.swing.AbstractListModel;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.JPanel;
import grendel.ui.XMLPageBuilder;
import grendel.ui.PageModel;
import grendel.ui.PageUI;
public class UIPrefsEditor extends JPanel
implements PropertyEditor {
UIPrefs fPrefs = new UIPrefs();
PropertyChangeSupport fListeners = new PropertyChangeSupport(this);
ResourceBundle fLabels =
ResourceBundle.getBundle("grendel.prefs.PrefLabels");
static final String kLAFKey="LAFList";
Hashtable fValues = null;
PageUI fPanel;
UIPrefsModel fModel;
class UIPrefsModel extends PageModel {
public UIPrefsModel() {
fValues = new Hashtable();
setStore(fValues);
}
public void actionPerformed(ActionEvent aEvent) {
}
}
public UIPrefsEditor() {
fModel = new UIPrefsModel();
// XMLNode root = null;
URL url = getClass().getResource("PrefDialogs.xml");
fPanel = new PageUI(url, "id", "UIPrefs", fModel, getClass());
JComponent c;
ChangeAction ca = new ChangeAction();
c = fPanel.getCtrlByName(kLAFKey);
c.addPropertyChangeListener(ca);
if (c instanceof JList) {
((JList) c).setModel(new LAFListModel());
}
}
public String getAsText() {
return null;
}
public Component getCustomEditor() {
return fPanel;
}
public String getJavaInitializationString() {
return "";
}
public String[] getTags() {
return null;
}
public Object getValue() {
fPanel.saveAll();
JList l = (JList)fPanel.getCtrlByName(kLAFKey);
String str = (String)l.getSelectedValue();
// sigh. we now search for the LAF
UIManager.LookAndFeelInfo[] info =
UIManager.getInstalledLookAndFeels();
LookAndFeel lf = null;
for (int i = 0; i < info.length; i++) {
try {
String cn = info[i].getClassName();
Class c = Class.forName(cn);
LookAndFeel current = (LookAndFeel)c.newInstance();
if (current.getDescription().equals(str)) {
lf = current;
}
} catch (Exception e) {
}
}
if (lf != null) { // fPrefs.setLAF((LookAndFeel) c.getValue());
fPrefs.setLAF(lf);
}
return fPrefs;
}
public boolean isPaintable() {
return false;
}
public void paintValue (Graphics g, Rectangle r) {
}
public void setAsText(String aValue) {
}
public void setValue(Object aValue) {
if (aValue instanceof UIPrefs) {
UIPrefs oldPrefs = fPrefs;
fPrefs = (UIPrefs) aValue;
JList l = (JList)fPanel.getCtrlByName(kLAFKey);
l.setSelectedValue(fPrefs.getLAF().getDescription(), true);
fListeners.firePropertyChange(null, oldPrefs, fPrefs);
}
}
public boolean supportsCustomEditor() {
return true;
}
public void addPropertyChangeListener(PropertyChangeListener l) {
fListeners.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
fListeners.removePropertyChangeListener(l);
}
class ChangeAction implements PropertyChangeListener {
void event(EventObject aEvent) {
getValue();
fListeners.firePropertyChange(null, null, fPrefs);
}
public void propertyChange(PropertyChangeEvent aEvent) {
event(aEvent);
}
}
class LAFListModel extends AbstractListModel {
LookAndFeel fLAFs[] = null;
LAFListModel() {
UIManager.LookAndFeelInfo[] info =
UIManager.getInstalledLookAndFeels();
fLAFs = new LookAndFeel[info.length];
for (int i = 0; i < info.length; i++) {
try {
String name = info[i].getClassName();
Class c = Class.forName(name);
fLAFs[i] = (LookAndFeel)c.newInstance();
} catch (Exception e){
}
}
}
public int getSize() {
if (fLAFs != null) {
return fLAFs.length;
}
return 0;
}
public Object getElementAt(int index) {
if (fLAFs != null && index < fLAFs.length) {
// this is a hack. the toString() returns a string which is
// best described as "unwieldly"
return fLAFs[index].getDescription();
}
return null;
}
}
public static void main(String[] args) throws Exception {
javax.swing.JFrame frame = new javax.swing.JFrame("Foo bar");
UIPrefsEditor ui = new UIPrefsEditor();
frame.getContentPane().add(ui.fPanel);
frame.pack();
frame.setVisible(true);
}
}

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

@ -1,226 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 16 Oct 1997.
*
* Contributors: Jeff Galyan <talisman@anamorphic.com>
* Giao Nguyen <grail@cafebabe.org>
*/
package grendel.prefs;
import java.io.File;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyEditor;
import java.net.URL;
import java.util.EventObject;
import java.util.Hashtable;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
//import netscape.orion.dialogs.AbstractCtrl;
//import netscape.orion.dialogs.AttrNotFoundException;
//import netscape.orion.dialogs.PageModel;
//import netscape.orion.dialogs.PageUI;
//import xml.tree.XMLNode;
//import xml.tree.TreeBuilder;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JFileChooser;
import javax.swing.text.JTextComponent;
import grendel.ui.XMLPageBuilder;
import grendel.ui.PageModel;
import grendel.ui.PageUI;
public class UserPrefsEditor
implements PropertyEditor {
UserPrefs fPrefs = new UserPrefs();
PropertyChangeSupport fListeners = new PropertyChangeSupport(this);
ResourceBundle fLabels =
ResourceBundle.getBundle("grendel.prefs.PrefLabels");
static final String kNameKey="userNameField";
static final String kOrganizationKey="userOrganizationField";
static final String kEmailAddressKey="userEmailAddressField";
static final String kSignatureKey = "signatureField";
static final String kChooseKey = "signatureButton";
Hashtable fValues = null;
PageUI fPanel;
UserPrefsModel fModel;
class UserPrefsModel extends PageModel {
public UserPrefsModel() {
fValues = new Hashtable();
fValues.put(kNameKey, "");
fValues.put(kOrganizationKey, "");
fValues.put(kEmailAddressKey, "");
fValues.put(kSignatureKey, "");
setStore(fValues);
}
// this is where you handle the magic of buttons in this page
public void actionPerformed(ActionEvent aEvent) {
String action = aEvent.getActionCommand();
if (action.equals(kChooseKey)) {
JFileChooser chooser = new JFileChooser();
File selected;
String path;
chooser.showDialog(fPanel, "Okay");
selected = chooser.getSelectedFile();
path = selected.getAbsolutePath();
((JTextComponent)
fPanel.getCtrlByName(kSignatureKey)).setText(path);
fPrefs.setSignatureFile(path);
fListeners.firePropertyChange(null, null, fPrefs);
}
}
}
public UserPrefsEditor() {
fModel = new UserPrefsModel();
URL url = getClass().getResource("PrefDialogs.xml");
fPanel = new PageUI(url, "id", "userPrefs", fModel, getClass());
ChangeAction ca = new ChangeAction();
JComponent c;
Prefs prefs = new Prefs();
UserPrefs user = prefs.getUserPrefs();
setValue(user);
c = fPanel.getCtrlByName(kNameKey);
c.addPropertyChangeListener(ca);
c = fPanel.getCtrlByName(kOrganizationKey);
c.addPropertyChangeListener(ca);
c = fPanel.getCtrlByName(kEmailAddressKey);
c.addPropertyChangeListener(ca);
c = fPanel.getCtrlByName(kSignatureKey);
c.addPropertyChangeListener(ca);
}
public String getAsText() {
return null;
}
public Component getCustomEditor() {
return fPanel;
}
public String getJavaInitializationString() {
return "";
}
public String[] getTags() {
return null;
}
public Object getValue() {
fPanel.saveAll();
String name = (String) fValues.get(kNameKey);
String org = (String) fValues.get(kOrganizationKey);
String email = (String) fValues.get(kEmailAddressKey);
String sig = (String)fValues.get(kSignatureKey);
fPrefs.setUserName(name);
fPrefs.setUserOrganization(org);
fPrefs.setUserEmailAddress(email);
fPrefs.setSignatureFile(sig);
return fPrefs;
}
public boolean isPaintable() {
return false;
}
public void paintValue (Graphics g, Rectangle r) {
}
public void setAsText(String aValue) {
}
public void setValue(Object aValue) {
if (aValue instanceof UserPrefs) {
UserPrefs oldPrefs = fPrefs;
fPrefs = (UserPrefs) aValue;
fValues.put(kNameKey, fPrefs.getUserName());
fValues.put(kOrganizationKey, fPrefs.getUserOrganization());
fValues.put(kEmailAddressKey, fPrefs.getUserEmailAddress());
fValues.put(kSignatureKey, fPrefs.getSignatureFile());
fPanel.initAll();
fListeners.firePropertyChange(null, oldPrefs, fPrefs);
}
}
public boolean supportsCustomEditor() {
return true;
}
public void addPropertyChangeListener(PropertyChangeListener l) {
fListeners.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
fListeners.removePropertyChangeListener(l);
}
class ChangeAction implements PropertyChangeListener {
void event(EventObject aEvent) {
fListeners.firePropertyChange(null, null, fPrefs);
}
public void propertyChange(PropertyChangeEvent aEvent) {
event(aEvent);
}
}
public static void main(String[] args) throws Exception {
javax.swing.JFrame frame = new javax.swing.JFrame("Foo bar");
UserPrefsEditor d = new UserPrefsEditor();
frame.getContentPane().add(d.getCustomEditor());
((PageUI)d.getCustomEditor()).saveAll();
frame.pack();
frame.setVisible(true);
}
}

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

@ -1,124 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Edwin Woudt
* <edwin@woudt.nl>. Portions created by Edwin Woudt are
* Copyright (C) 1999 Edwin Woudt. All
* Rights Reserved.
*
* Contributor(s):
*/
package grendel.prefs.ui;
import java.util.Vector;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import grendel.prefs.base.GeneralPrefs;
import grendel.ui.UnifiedMessageDisplayManager;
public class General extends JFrame {
GeneralPrefs prefs = GeneralPrefs.GetMaster();
JTextField tfSMTP;
public static void main(String argv[]) {
General ui = new General();
ui.show();
}
public General() {
super();
setSize(500,354);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
JLabel label = new JLabel("SMTP Server");
label.setBounds(12,12,label.getPreferredSize().width,label.getPreferredSize().height);
getContentPane().add(label);
tfSMTP = new JTextField("");
tfSMTP.setBounds(100,12,300,tfSMTP.getPreferredSize().height);
getContentPane().add(tfSMTP);
JButton button = new JButton("Cancel");
button.setBounds(334,290,68,button.getPreferredSize().height);
button.addActionListener(new CancelActionListener());
button.setMargin(new Insets(0,0,0,0));
getContentPane().add(button);
button = new JButton("Finish");
button.setBounds(414,290,68,button.getPreferredSize().height);
button.addActionListener(new FinishActionListener());
button.setMargin(new Insets(0,0,0,0));
getContentPane().add(button);
getData();
}
void getData() {
tfSMTP.setText(prefs.getSMTPServer());
}
void setData() {
prefs.setSMTPServer(tfSMTP.getText());
}
class FinishActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
setData();
prefs.writePrefs();
hide();
dispose();
}
}
class CancelActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
hide();
dispose();
}
}
}

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

@ -1,259 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Edwin Woudt
* <edwin@woudt.nl>. Portions created by Edwin Woudt are
* Copyright (C) 1999 Edwin Woudt. All
* Rights Reserved.
*
* Contributor(s):
*/
package grendel.prefs.ui;
import java.util.Vector;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.AbstractListModel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import grendel.prefs.base.IdentityArray;
import grendel.prefs.base.IdentityStructure;
public class Identities extends JFrame {
JList list;
JTextField tfDesc;
JTextField tfName;
JTextField tfEMail;
JTextField tfReply;
JTextField tfOrg;
JTextArea taSig;
IdentityArray ida;
IdentityListModel ilm;
int currentSelection = -1;
public static void main(String argv[]) {
Identities ident = new Identities();
ident.show();
}
public Identities() {
super();
ida = IdentityArray.GetMaster();
setSize(500,354);
getContentPane().setLayout(null);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
ilm = new IdentityListModel();
list = new JList(ilm);
list.setSelectedIndex(0);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setBounds(12,12,142,306);
list.addListSelectionListener(new SelectionChangedListener());
getContentPane().add(list);
JLabel label = new JLabel("Description");
label.setBounds(174,12,label.getPreferredSize().width,label.getPreferredSize().height);
getContentPane().add(label);
label = new JLabel("Name");
label.setBounds(174,44,label.getPreferredSize().width,label.getPreferredSize().height);
getContentPane().add(label);
label = new JLabel("E-Mail");
label.setBounds(174,76,label.getPreferredSize().width,label.getPreferredSize().height);
getContentPane().add(label);
label = new JLabel("Reply-To");
label.setBounds(174,108,label.getPreferredSize().width,label.getPreferredSize().height);
getContentPane().add(label);
label = new JLabel("Organization");
label.setBounds(174,140,label.getPreferredSize().width,label.getPreferredSize().height);
getContentPane().add(label);
label = new JLabel("Signature");
label.setBounds(174,172,label.getPreferredSize().width,label.getPreferredSize().height);
getContentPane().add(label);
tfDesc = new JTextField();
tfDesc.setBounds(254,12,228,tfDesc.getPreferredSize().height);
getContentPane().add(tfDesc);
tfName = new JTextField();
tfName.setBounds(254,44,228,tfName.getPreferredSize().height);
getContentPane().add(tfName);
tfEMail = new JTextField();
tfEMail.setBounds(254,76,228,tfEMail.getPreferredSize().height);
getContentPane().add(tfEMail);
tfReply = new JTextField();
tfReply.setBounds(254,108,228,tfReply.getPreferredSize().height);
getContentPane().add(tfReply);
tfOrg = new JTextField();
tfOrg.setBounds(254,140,228,tfOrg.getPreferredSize().height);
getContentPane().add(tfOrg);
taSig = new JTextArea();
taSig.setFont(new Font("monospaced",Font.PLAIN,12));
JScrollPane scroll = new JScrollPane(taSig);
scroll.setBounds(174,190,308,88);
getContentPane().add(scroll);
JButton button = new JButton("Add New");
button.setBounds(174,290,94,button.getPreferredSize().height);
button.addActionListener(new AddNewActionListener());
getContentPane().add(button);
button = new JButton("Delete");
button.setBounds(281,290,94,button.getPreferredSize().height);
button.addActionListener(new DeleteActionListener());
getContentPane().add(button);
button = new JButton("Finish");
button.setBounds(388,290,94,button.getPreferredSize().height);
button.addActionListener(new FinishActionListener());
getContentPane().add(button);
update();
}
private void update() {
if (currentSelection > -1) {
ida.get(currentSelection).setDescription(tfDesc.getText());
ida.get(currentSelection).setName(tfName.getText());
ida.get(currentSelection).setEMail(tfEMail.getText());
ida.get(currentSelection).setReplyTo(tfReply.getText());
ida.get(currentSelection).setOrganization(tfOrg.getText());
ida.get(currentSelection).setSignature(taSig.getText());
}
tfDesc.setText(ida.get(list.getSelectedIndex()).getDescription());
tfName.setText(ida.get(list.getSelectedIndex()).getName());
tfEMail.setText(ida.get(list.getSelectedIndex()).getEMail());
tfReply.setText(ida.get(list.getSelectedIndex()).getReplyTo());
tfOrg.setText(ida.get(list.getSelectedIndex()).getOrganization());
taSig.setText(ida.get(list.getSelectedIndex()).getSignature());
currentSelection = list.getSelectedIndex();
}
class SelectionChangedListener implements ListSelectionListener {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
update();
}
}
}
class AddNewActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
ida.add(new IdentityStructure("New Identity"));
ilm.fireAdded(ida.size()-1);
list.setSelectedIndex(ida.size()-1);
update();
}
}
class DeleteActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
int index = list.getSelectedIndex();
ida.remove(index);
ilm.fireRemoved(index);
currentSelection = -1;
if (index >= ida.size()) {
index = ida.size()-1;
}
if (ida.size() <= 0) {
ida.add(new IdentityStructure("New Identity"));
index = 0;
}
list.setSelectedIndex(index);
update();
}
}
class FinishActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
update();
ida.writePrefs();
hide();
dispose();
}
}
class IdentityListModel extends AbstractListModel {
public Object getElementAt(int index) {
return ida.get(index).getDescription();
}
public int getSize() {
return ida.size();
}
public void fireAdded(int index) {
fireIntervalAdded(this, index, index);
}
public void fireRemoved(int index) {
fireIntervalRemoved(this, index, index);
}
}
}

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

@ -1,214 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Terry Weissman <terry@netscape.com>, 26 Sep 1997.
*/
package grendel.storage.intertwingle;
import calypso.util.Assert;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Enumeration;
import java.util.Vector;
/** This implements a RDF-ish database, where changes take very little time.
It works by queueing up those changes, and having a low-priority
background thread process that queue into real changes. The pending changes
also get reflected into a disk file, so that if we crash, we'll recover
unfinished stuff when the app next starts.
<p>
Queries on the database will search the queue for pending changes that
could affect that query, and will commit those changes immediately. */
public final class BGDB extends BaseDB implements Runnable {
static final boolean DEBUG = false;
static void Spew(String s) {
if (DEBUG) System.err.println("BGDB: " + s);
}
class Command {
public String command;
public String name;
public String slot;
public String value;
Command(String c, String n, String s, String v) {
command = c;
name = n;
slot = s;
value = v;
}
public String toString() {
return command + ": '" + name + "','" + slot + "','" + value + "'";
}
};
DB base;
File log;
RandomAccessFile logfid;
Vector queue = new Vector();
Thread thread;
BGDB(DB d, File t) throws IOException {
log = t;
base = d;
logfid = new RandomAccessFile(log, "rw");
long length = logfid.length();
while (logfid.getFilePointer() < length) {
try {
queue.addElement(new Command(logfid.readUTF(),
logfid.readUTF(),
logfid.readUTF(),
logfid.readUTF()));
} catch (IOException e) {
break;
}
}
thread = new Thread(this);
thread.setDaemon(true);
thread.setPriority(Thread.NORM_PRIORITY - 1);
thread.start();
}
public synchronized void assert(String name, String slot, String value)
throws IOException
{
logfid.seek(logfid.length());
logfid.writeUTF("assert");
logfid.writeUTF(name);
logfid.writeUTF(slot);
logfid.writeUTF(value);
queue.addElement(new Command("assert", name, slot, value));
notifyAll(); // Inform bg thread it has work to do.
}
public synchronized void unassert(String name, String slot, String value)
throws IOException
{
logfid.seek(logfid.length());
logfid.writeUTF("unassert");
logfid.writeUTF(name);
logfid.writeUTF(slot);
logfid.writeUTF(value);
queue.addElement(new Command("unassert", name, slot, value));
notifyAll(); // Inform bg thread it has work to do.
}
public synchronized String findFirst(String name, String slot,
boolean reverse) throws IOException
{
flushChanges(name, slot, reverse);
return base.findFirst(name, slot, reverse);
}
public synchronized Enumeration findAll(String name, String slot,
boolean reverse)
throws IOException
{
flushChanges(name, slot, reverse);
return base.findAll(name, slot, reverse);
}
private void flushChanges(String name, String slot, boolean reverse)
throws IOException
{
for (int i=0 ; i<queue.size() ; i++) {
Command c = (Command) queue.elementAt(i);
while (slot.equals(c.slot) && name.equals(reverse ? c.value : c.name)) {
flushCommand(c);
queue.removeElementAt(i);
if (i >= queue.size()) break;
c = (Command) queue.elementAt(i);
}
}
}
private void truncateLog() {
try {
logfid.close();
} catch (IOException e) {
// ### What to do...
System.out.println("logfid.close() failed in BGDB.truncateLog: " + e);
}
logfid = null;
log.delete();
try {
logfid = new RandomAccessFile(log, "rw");
} catch (IOException e) {
// ### What to do...
System.out.println("opening logfid failed in BGDB.truncateLog: " + e);
}
}
public synchronized void flushChanges() throws IOException {
while (queue.size() > 0) {
flushCommand((Command) queue.elementAt(0));
queue.removeElementAt(0);
}
truncateLog();
}
private void flushCommand(Command c) throws IOException {
if (DEBUG) {
String who;
Spew(((Thread.currentThread() == thread) ? "bg" : "fg") + " executing " +
c);
}
if (c.command.equals("assert")) {
base.assert(c.name, c.slot, c.value);
} else if (c.command.equals("unassert")) {
base.unassert(c.name, c.slot, c.value);
} else {
Assert.NotReached("Unknown command type in BGDB.flushCommand");
}
}
public void run() {
Spew("bg Startup.");
for (;;) {
synchronized(this) {
if (queue.size() > 0) {
try {
flushCommand((Command) queue.elementAt(0));
} catch (IOException e) {
// ### What to do...
System.out.println("flushCommand failed in BGDB.run: " + e);
}
queue.removeElementAt(0);
} else {
truncateLog();
try {
Spew("bg waiting...");
wait();
Spew("bg awake.");
} catch (InterruptedException e) {
return; // ### Is this right???
}
}
}
}
}
}

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

@ -1,47 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Terry Weissman <terry@netscape.com>, 26 Sep 1997.
*/
package grendel.storage.intertwingle;
import java.io.IOException;
import java.util.Enumeration;
/** An interface to a RDF-ish database. */
public interface DB {
public void assert(String name, String slot, String value)
throws IOException;
public void unassert(String name, String slot, String value)
throws IOException;
public String findFirst(String name, String slot, boolean reverse)
throws IOException;
public Enumeration findAll(String name, String slot, boolean reverse)
throws IOException;
public boolean isAsserted(String name, String slot, String value)
throws IOException;
};

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

@ -1,200 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Terry Weissman <terry@netscape.com>, 26 Sep 1997.
*/
package grendel.storage.intertwingle;
import calypso.util.Assert;
import calypso.util.NullJavaEnumeration;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.NoSuchElementException;
/** This is a completely wretched thing that implements a RDF-ish database.
It works by generating zillions of tiny files. We should never ever really
use this; it's just for playing. If we actually ever do ship this, I will
be forced to spend the rest of my life hunting down every copy on every
machine in the world and eradicating it. */
final class HackDB extends BaseDB {
private File top;
private File tmpfile;
private Hashtable slotdirs = new Hashtable();
private Hashtable reverseslotdirs = new Hashtable();
HackDB(File f) throws IOException {
top = f;
ensureDirectory(top);
tmpfile = new File(top, "--tmp--");
}
private void ensureDirectory(File f) throws IOException {
if (!f.exists()) f.mkdirs();
if (!f.isDirectory()) {
throw new IOException("Must be a directory: " + f);
}
}
private File findSlotFile(String name, boolean reverse) throws IOException {
Hashtable table = (reverse ? reverseslotdirs : slotdirs);
File result = (File) table.get(name);
if (result == null) {
result = new File(top, reverse ? "reverse-" + name : name);
ensureDirectory(result);
table.put(name, result);
}
return result;
}
private void putone(File dir, String name, String value) throws IOException {
File n = new File(dir, name);
RandomAccessFile file = new RandomAccessFile(n, "rw");
String line;
long length = file.length();
while (file.getFilePointer() < length) {
line = file.readUTF();
if (line.equals(value)) {
file.close();
return;
}
}
file.writeUTF(value);
file.close();
}
private void nukeone(File dir, String name, String value)
throws IOException
{
File n = new File(dir, name);
if (!n.exists()) return;
RandomAccessFile file = new RandomAccessFile(n, "r");
tmpfile.delete();
RandomAccessFile out = new RandomAccessFile(tmpfile, "rw");
long length = file.length();
boolean found = false;
int count = 0;
while (file.getFilePointer() < length) {
String line = file.readUTF();
if (line.equals(value)) {
found = true;
} else {
out.writeUTF(line);
count++;
}
}
file.close();
out.close();
if (found) {
n.delete();
if (count > 0) {
tmpfile.renameTo(n);
} else {
tmpfile.delete();
}
} else {
tmpfile.delete();
}
}
public synchronized void assert(String name, String slot, String value)
throws IOException
{
File s = findSlotFile(slot, false);
File r = findSlotFile(slot, true);
putone(s, name, value);
putone(r, value, name);
}
public synchronized void unassert(String name, String slot, String value)
throws IOException
{
File s = findSlotFile(slot, false);
File r = findSlotFile(slot, true);
nukeone(s, name, value);
nukeone(r, value, name);
}
public synchronized String findFirst(String name, String slot,
boolean reverse) throws IOException {
File f = new File(findSlotFile(slot, reverse), name);
if (!f.exists()) return null;
RandomAccessFile fid = new RandomAccessFile(f, "r");
String line = null;
if (fid.length() > 0) {
line = fid.readUTF();
}
fid.close();
return line;
}
public Enumeration findAll(String name, String slot, boolean reverse)
throws IOException
{
File f = new File(findSlotFile(slot, reverse), name);
if (!f.exists()) return NullJavaEnumeration.kInstance;
final RandomAccessFile thefid = new RandomAccessFile(f, "r");
return new Enumeration() {
RandomAccessFile fid = thefid;
String next = null;
public boolean hasMoreElements() {
if (next != null) return true;
if (fid == null) return false;
try {
next = fid.readUTF();
} catch (IOException e) {
next = null;
}
if (next == null) {
try {
fid.close();
} catch (IOException e) {
}
fid = null;
return false;
}
return true;
}
public Object nextElement() throws NoSuchElementException {
if (!hasMoreElements()) throw new NoSuchElementException();
String result = next;
next = null;
return result;
}
};
}
};

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

@ -1,159 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Terry Weissman <terry@netscape.com>, 4 Oct 1997.
*/
package grendel.storage.intertwingle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
public class PhoneTest {
public static void main(String args[])
throws IOException
{
String home = System.getProperties().getProperty("user.home");
String filename = args.length == 0 ? "__phonedb__" : args[0];
File top = new File(home, filename);
DB db = new SimpleDB(top);
db = new BGDB(db, new File(home, filename + ".queue"));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (;;) {
System.out.print("Phonetest> ");
System.out.flush();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
String line = in.readLine();
if (line == null) break;
if (line.length() == 0) continue;
if (line.charAt(0) == '<') {
BufferedReader fid = null;
String name = null;
int count = 0;
try {
fid = new BufferedReader(new InputStreamReader(new FileInputStream(line.substring(1))));
String str;
while ((str = fid.readLine()) != null) {
str = str.trim();
if (str.length() == 0) {
name = null;
} else if (name == null) {
name = str;
} else {
int i = str.indexOf(':');
if (i > 0) {
String slot = str.substring(0, i).trim();
String value = str.substring(i + 1).trim();
// System.out.println("Adding '" + name + "','" + slot + "','" +
// value + "'");
System.out.print(".");
count++;
db.assert(name, slot, value);
} else {
name = str;
}
}
}
} catch (IOException e) {
}
System.out.println("");
System.out.println(count + " assertions made.");
if (fid != null) fid.close();
} else {
String name = null;
String slot = null;
String value = null;
int nameend = line.indexOf(',');
int slotend = line.indexOf(',', nameend + 1);
if (nameend < 0) {
name = line;
} else {
name = line.substring(0, nameend);
if (slotend < 0) {
slot = line.substring(nameend + 1);
} else {
slot = line.substring(nameend + 1, slotend);
value = line.substring(slotend + 1);
}
}
if (name != null && name.length() == 0) name = null;
if (slot != null && slot.length() == 0) slot = null;
if (value != null && value.length() == 0) value = null;
// System.out.println("name: '" + name + "' slot: '" + slot + "' value: '" + value + "'");
if (slot == null) {
System.out.println("Gotta have a slot!");
} else if (name == null && value == null) {
System.out.println("Gotta have a name or value!");
} else {
Enumeration e = null;
if (name == null) {
e = db.findAll(value, slot, true);
} else if (value == null) {
e = db.findAll(name, slot, false);
} else {
if (name.charAt(0) == '-') {
db.unassert(name.substring(1), slot, value);
System.out.println("Unasserted.");
} else {
db.assert(name, slot, value);
System.out.println("Asserted.");
}
}
if (e != null) {
while (e.hasMoreElements()) {
String result = (String) e.nextElement();
System.out.println(result);
}
}
}
}
}
if (db instanceof BGDB) {
((BGDB) db).flushChanges();
}
}
}

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

@ -1,74 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Terry Weissman <terry@netscape.com>, 26 Sep 1997.
*/
package grendel.storage.intertwingle;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
public class SelfTest {
public static void main(String args[])
throws IOException
{
String home = System.getProperties().getProperty("user.home");
File top = new File(home, "__hackdb__");
// DB db = new HackDB(top);
DB db = new SimpleDB(top);
db = new BGDB(db, new File(home, "__hackdb__queue"));
db.assert("terry", "fullname", "Terry Weissman");
db.assert("jwz", "fullname", "Jamie Zawinski");
db.assert("terry", "phone", "650-937-2756");
db.assert("terry", "phone", "408-338-8227");
db.assert("jwz", "phone", "650-937-2620");
db.assert("jwz", "phone", "415-ACRIDHE");
for (int j=0 ; j<2 ; j++) {
for (int i=0 ; i<2 ; i++) {
String n = (i == 0 ? "terry" : "jwz");
System.out.println(n + "'s fullname is " + db.findFirst(n, "fullname",
false));
for (Enumeration e = db.findAll(n, "phone", false) ;
e.hasMoreElements() ;
) {
String p = (String) e.nextElement();
System.out.println(n + "'s phone is " + p);
}
}
db.unassert("jwz", "phone", "415-ACRIDHE");
System.out.println("");
}
if (db instanceof BGDB) {
((BGDB) db).flushChanges();
}
}
}

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

@ -1,503 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Terry Weissman <terry@netscape.com>, 30 Sep 1997.
*/
package grendel.storage.intertwingle;
import calypso.util.Assert;
import calypso.util.NullEnumeration;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.PrintStream;
import java.util.Enumeration;
import java.util.NoSuchElementException;
/** Simplistic implementation of a RDF-ish database. This is basically a
massive hashtable hack. Almost certainly we shouldn't ship this, but it
ought to be good enough to play with for a while.
<p>
Here's how it works:
<p>
There are five files. One is the "store", and it stores the data. All
data is accessed via a hash table, so each entry in the store contains
one or two pointers to other entries with the same hash. ("two" is in
the case where there are two hash tables into the same data.)
<p>
The other four files are head pointers into the hashtable, for various
hashes.
<p>
Random strings are stored in the store. They get hashed using
String.hashCode(), the hash value is masked off to HASHMASK, and the
first pointer to the hashtable appear in the "strhead" file. Each
entry consists of a pointer to the next string with the same hashcode, and
then a refcount, and then the UTF version of the string itself.
<p>
Assertions are stored in the store. Each assertion is three strings:
name, slot, and value. The strings are first put into the store, and
then the assertion is recorded by writing down the location of the
strings. Each assertion is hashed twice: once by combining the name and
slot, and once by combining the value and slot. So, each assertion records
the next value for both hash tables, followed by the three string
locations. So, each assertion costs 20 bytes on disk, not counting the
string storage. The "head[]" files are the first pointers for each
hashtable.
<p>
Finally, a free list of unused chunks in the store are kept. The
"freehead" file points to the first free entry of a given size; each
free entry points to the next free entry of the same size.
*/
public final class SimpleDB extends BaseDB {
private File storename;
private RandomAccessFile store;
private RandomAccessFile head[] = new RandomAccessFile[2];
private RandomAccessFile strhead;
private RandomAccessFile freehead;
private static final int MINALLOC = 12; // Try not to leave free chunks
// smaller than this.
private static final int MAXALLOC = 1024;// Don't bother recording free
// chunks bigger than this.
private static final int HASHMASK = 0xfff; // Only use these bits in our
// hashtables.
public SimpleDB(File f) throws IOException {
storename = f;
String name = f.getPath();
store = new RandomAccessFile(f, "rw");
head[0] = new RandomAccessFile(name + ".key0", "rw");
head[1] = new RandomAccessFile(name + ".key1", "rw");
freehead = new RandomAccessFile(name + ".free", "rw");
strhead = new RandomAccessFile(name + ".strings", "rw");
if (store.length() == 0) {
store.write(("# DO NOT EDIT THIS FILE; it contains binary data.\n").getBytes());
}
}
private int alloc(int length) throws IOException {
int biggest = (int) (freehead.length() / 4);
if (length > biggest) {
return (int) store.length();
}
freehead.seek(length * 4);
int t = length;
while (t <= biggest) {
int result = freehead.readInt();
if (result > 0 && (t == length || t > length + MINALLOC)) {
store.seek(result);
freehead.seek(t * 4);
freehead.writeInt(store.readInt());
free(result + length, t - length);
return result;
}
}
return (int) store.length();
}
private void free(int ptr, int length) throws IOException {
if (length == 0) return;
if (length > MAXALLOC) {
while (length > MAXALLOC * 2) {
free(ptr, MAXALLOC);
ptr += MAXALLOC;
length -= MAXALLOC;
}
free(ptr, length / 2);
ptr += length / 2;
length -= (length / 2);
free(ptr, length);
return;
}
int biggest = (int) (freehead.length() / 4);
if (length >= biggest) {
freehead.seek(freehead.length());
while (biggest <= length) {
freehead.writeInt(0);
biggest++;
}
}
freehead.seek(length * 4);
store.seek(ptr);
store.writeInt(freehead.readInt());
freehead.seek(length * 4);
freehead.writeInt(ptr);
}
private int LookupString(String str, boolean create) throws IOException {
int hash = (str.hashCode() & HASHMASK) * 4;
//System.out.println("LookupString: Looking up '" + str + "' [hashcode is " + hash + "]");
int result;
int firstval = 0;
if (hash < strhead.length()) {
strhead.seek(hash);
firstval = strhead.readInt();
result = firstval;
while (result > 0) {
//System.out.println("LookupString: Seeking to " + result);
store.seek(result);
int next = store.readInt();
int refcount = store.readInt();
String t = store.readUTF();
if (str.equals(t)) {
return result;
}
//System.out.println("LookupString: Skipping past " + t);
result = next;
}
}
if (!create) return 0;
if (hash > strhead.length()) {
strhead.seek(strhead.length());
for (int i=(int) strhead.length() ; i<hash ; i+=4) {
strhead.writeInt(0);
}
}
// Figure out the UTF length. Code stolen from java.io.RandomAccessFile.
// Ick.
int strlen = str.length();
int utflen = 0;
for (int i = 0 ; i < strlen ; i++) {
int c = str.charAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
utflen++;
} else if (c > 0x07FF) {
utflen += 3;
} else {
utflen += 2;
}
}
int totallength = 4 + // Pointer to next entry with same hash
2 + // Space to write down length of string
utflen; // Length of string itself.
result = alloc(totallength);
store.seek(result);
store.writeInt(firstval);
store.writeInt(0); // Initial value of refcount. The caller
// better update this soon!
store.writeUTF(str);
strhead.seek(hash);
strhead.writeInt(result);
//System.out.println("LookupString: Added entry at " + result);
return result;
}
private void addStringRef(int loc) throws IOException {
store.seek(loc + 4);
int refcount = store.readInt();
store.seek(loc + 4);
store.writeInt(refcount + 1);
}
private void removeStringRef(int loc) throws IOException {
store.seek(loc + 4);
int refcount = store.readInt();
if (refcount <= 1) {
int length = store.readShort() + 8;
free(loc, length);
} else {
store.seek(loc + 4);
store.writeInt(refcount - 1);
}
}
public synchronized void assert(String name, String slot, String value)
throws IOException
{
int n = LookupString(name, true);
int s = LookupString(slot, true);
int v = LookupString(value, true);
int hash0 = ((name.hashCode() + slot.hashCode()) & HASHMASK) * 4;
int firstval0 = 0;
if (head[0].length() > hash0) {
head[0].seek(hash0);
firstval0 = head[0].readInt();
int ptr = firstval0;
while (ptr > 0) {
store.seek(ptr);
ptr = store.readInt();
store.readInt();
if (n == store.readInt()) {
if (s == store.readInt()) {
if (v == store.readInt()) {
// Gee, we already have this one. No-op.
return;
}
}
}
}
}
// OK, we know this isn't already in the database. Add it.
int hash1 = ((value.hashCode() + slot.hashCode()) & HASHMASK) * 4;
int firstval1 = 0;
if (head[1].length() > hash1) {
head[1].seek(hash1);
firstval1 = head[1].readInt();
}
addStringRef(n);
addStringRef(s);
addStringRef(v);
int result = alloc(5 * 4);
store.seek(result);
store.writeInt(firstval0);
store.writeInt(firstval1);
store.writeInt(n);
store.writeInt(s);
store.writeInt(v);
for (int i=0 ; i<2 ; i++) {
int hash = (i==0 ? hash0 : hash1);
if (hash > head[i].length()) {
head[i].seek(head[i].length());
for (int j=(int) head[i].length() ; j<hash ; j+=4) {
head[i].writeInt(0);
}
}
head[i].seek(hash);
head[i].writeInt(result);
}
//System.out.println("assert: Added '" + name + "','" + slot + "','" + value + "' at position " + result);
}
public synchronized void unassert(String name, String slot, String value)
throws IOException
{
int n = LookupString(name, false);
int s = LookupString(slot, false);
int v = LookupString(value, false);
if (n == 0 || s == 0 || v == 0) {
// Gee, one of these strings was never defined, so we never could
// have made this assertion in the first place.
return;
}
int hash0 = ((name.hashCode() + slot.hashCode()) & HASHMASK) * 4;
int hash1 = ((value.hashCode() + slot.hashCode()) & HASHMASK) * 4;
int location = 0;
for (int w=0 ; w<2 ; w++) {
int hash = ((w==0) ? hash0 : hash1);
if (head[w].length() <= hash) continue;
head[w].seek(hash);
int last = 0;
int ptr = head[w].readInt();
while (ptr > 0) {
store.seek(ptr);
int next0 = store.readInt();
int next1 = store.readInt();
int next = ((w==0) ? next0 : next1);
if (store.readInt() == n) {
if (store.readInt() == s) {
if (store.readInt() == v) {
// Found it! Remove it from the chain.
Assert.Assertion(location == 0 || location == ptr);
location = ptr;
if (last == 0) {
head[w].seek(hash);
head[w].writeInt(next);
} else {
store.seek(last + w*4);
store.writeInt(next);
}
next = 0; // To break out of loop.
}
}
}
last = ptr;
ptr = next;
}
}
if (location > 0) {
free(location, 5 * 4);
removeStringRef(n);
removeStringRef(s);
removeStringRef(v);
}
}
public synchronized String findFirst(String name, String slot, boolean reverse)
throws IOException
{
int w = reverse ? 1 : 0;
int n = LookupString(name, false);
int s = LookupString(slot, false);
//System.out.println("findFirst: Name: '" + name + "' (" + n + ")");
//System.out.println("findFirst: Slot: '" + slot + "' (" + s + ")");
if (n == 0 || s == 0) return null;
int hash = ((name.hashCode() + slot.hashCode()) & HASHMASK) * 4;
//System.out.println("findFirst: hash is " + hash);
if (head[w].length() <= hash) return null;
head[w].seek(hash);
int ptr = head[w].readInt();
while (ptr > 0) {
//System.out.println("findFirst: checking position " + ptr);
store.seek(ptr);
int next0 = store.readInt();
int next1 = store.readInt();
int n1 = store.readInt();
int s1 = store.readInt();
if (s1 == s) {
int v1 = store.readInt();
if ((w == 0 && n == n1) || (w == 1 && n == v1)) {
int result = (w == 0) ? v1 : n1;
store.seek(result + 8);
return store.readUTF();
}
}
ptr = (w == 0) ? next0 : next1;
}
return null;
}
public synchronized Enumeration findAll(String name, String slot, boolean reverse)
throws IOException
{
final int w = reverse ? 1 : 0;
final int n = LookupString(name, false);
if (n == 0) return null;
final int s = LookupString(slot, false);
if (s == 0) return null;
int hash = ((name.hashCode() + slot.hashCode()) & HASHMASK) * 4;
//System.out.println("findFirst: hash is " + hash);
if (head[w].length() <= hash) return null;
head[w].seek(hash);
final int ptr = head[w].readInt();
return new AllEnumerator(this, ptr, n, s, w);
}
class AllEnumerator implements Enumeration {
SimpleDB db;
int ptr;
int n;
int s;
int w;
String next;
AllEnumerator(SimpleDB d, int p, int nm, int sl, int ww) {
db = d;
ptr = p;
n = nm;
s = sl;
w = ww;
}
public boolean hasMoreElements() {
if (next != null) return true;
while (ptr > 0) {
synchronized(db) {
try {
db.store.seek(ptr);
int next0 = db.store.readInt();
int next1 = db.store.readInt();
int n1 = db.store.readInt();
int s1 = db.store.readInt();
ptr = ((w == 0) ? next0 : next1);
if (s1 == s) {
int v1 = db.store.readInt();
if ((w == 0 && n == n1) || (w == 1 && n == v1)) {
db.store.seek(((w == 0) ? v1 : n1) + 8);
next = db.store.readUTF();
return true;
}
}
} catch (IOException e) {
ptr = 0;
return false;
}
}
}
return false;
}
public Object nextElement() throws NoSuchElementException {
if (!hasMoreElements()) throw new NoSuchElementException();
String result = next;
next = null;
return result;
}
}
private void dumpString(int loc) throws IOException {
store.seek(loc + 4);
int refcount = store.readInt();
String str = store.readUTF();
System.out.print(str);
System.out.print("[" + refcount + "]");
}
public synchronized void dump(PrintStream out) throws IOException {
int length = (int) head[0].length();
head[0].seek(0);
int id[] = new int[3];
for (int hash=0 ; hash < length ; hash += 4) {
int position = head[0].readInt();
while (position > 0) {
store.seek(position);
position = store.readInt();
store.readInt();
for (int i=0 ; i<3 ; i++) {
id[i] = store.readInt();
}
for (int i=0 ; i<3 ; i++) {
dumpString(id[i]);
if (i < 2) System.out.print(",");
}
System.out.println("");
}
}
length = (int) freehead.length();
for (int hash=0 ; hash < length ; hash += 4) {
int position = freehead.readInt();
if (position > 0) {
System.out.print(" -- Free chunks of size " + (hash/4) + ":");
while (position > 0) {
System.out.print(" " + position);
store.seek(position);
position = store.readInt();
}
System.out.println("");
}
}
}
}

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

@ -1,198 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Terry Weissman <terry@netscape.com>, 7 Oct 1997.
*/
package grendel.storage.intertwingle;
import javax.mail.Folder;
import javax.mail.internet.InternetHeaders;
import calypso.util.Preferences;
import calypso.util.PreferencesFactory;
import java.io.File;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Vector;
/** This is the glue between the storage of intertwingle data and the rest
of the mail system. It will probably get thrown out or extensively
rewritten; I'm still playing. */
public class Twingle implements Runnable {
static final private boolean DEBUG = false;
static void Spew(String s) {
if (DEBUG) System.err.println("Twingle: " + s);
}
static private Twingle Singleton = null;
static private boolean Initialized = false;
static public Twingle GetSingleton() {
if (!Initialized) {
synchronized (Twingle.class) {
if (!Initialized) {
File f = PreferencesFactory.Get().getFile("twingle.database", null);
if (f != null) {
try {
Singleton = new Twingle(f);
} catch (IOException e) {
// ### What to do...
System.out.println("Twingle.GetSingleton() failed: " + e);
}
}
Initialized = true;
}
}
}
return Singleton;
}
protected DB db;
protected Thread thread;
protected Vector queue = new Vector();
Twingle(File f) throws IOException {
db = new BGDB(new SimpleDB(f), new File(f.getPath() + ".queue"));
thread = new Thread(this);
thread.setDaemon(true);
thread.start();
}
void assert(String name, String slot, String value) {
if (name != null && value != null) {
try {
db.assert(name, slot, value);
} catch (IOException e) {
// ### What to do...
System.out.println("db.assert() failed in Twingle.assert: " + e);
}
}
}
class AddCommand {
InternetHeaders headers;
Folder folder;
AddCommand(InternetHeaders h, Folder f) {
headers = h;
folder = f;
}
}
public void add(InternetHeaders headers, Folder folder) {
synchronized (queue) {
queue.addElement(new AddCommand(headers, folder));
queue.notifyAll();
}
}
/** Find the given header ("to" or "cc"), and assert an entry for each
address in it. This needs the code to parse the zillions of different
kinds of addresses; for now, we just assume everything is of the form
"Full name <mail@addr.com>". */
protected void hackAddressList(String id, InternetHeaders headers,
String slot) {
String hh[] = headers.getHeader(slot);
if (hh == null || hh.length == 0) return;
String list = "";
for (int i = 0; i < hh.length; i++) {
if (i > 0) list += ",\r\n\t";
list += hh[i];
}
StringTokenizer st = new StringTokenizer(list, ",");
while (st.hasMoreTokens()) {
String str = st.nextToken();
String name;
String addr;
int at = str.indexOf('@');
if (at < 0) continue; // Some garbage that isn't an email address.
int lt = str.indexOf('<');
int gt = lt > 0 ? str.indexOf('>', lt) : -1;
if (lt > 0 && lt < at && gt > at) {
name = str.substring(0, lt).trim();
addr = str.substring(lt + 1, gt).trim();
} else {
name = null;
addr = str.trim();
}
if (name != null) {
assert(addr, "fullname", name);
}
assert(id, slot, addr);
}
}
public void run() {
for (;;) {
Object cmd;
synchronized(queue) {
while (queue.size() == 0) {
try {
Spew("bg: waiting");
queue.wait();
Spew("bg: awake");
} catch (InterruptedException e) {
return;
}
}
cmd = queue.elementAt(0);
queue.removeElementAt(0);
}
Spew("bg: doing one...");
if (cmd instanceof AddCommand) {
AddCommand addcmd = (AddCommand) cmd;
InternetHeaders headers = addcmd.headers;
Folder folder = addcmd.folder;
String ids[] = headers.getHeader("Message-ID");
String id;
if (ids == null || ids.length == 0) {
// MD5-hash-hack? Well, maybe. Not right now, though. ###
continue;
}
id = ids[0];
if (id.charAt(0) == '<' && id.endsWith(">")) {
id = id.substring(1, id.length() - 1);
}
assert(id, "parent", folder.getName());
String subj[] = headers.getHeader("Subject");
if (subj != null && subj.length != 0)
assert(id, "subject", subj[0]);
hackAddressList(id, headers, "from");
hackAddressList(id, headers, "to");
hackAddressList(id, headers, "cc");
}
Spew("bg: ...did one.");
}
}
}

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 8 Sep 1997.
*
@ -55,7 +55,7 @@ import grendel.filters.FilterMaster;
*/
import grendel.composition.Composition;
import grendel.ui.UIAction;
import com.trfenv.parsers.Event;
public class ActionFactory {
static ExitAction fExitAction = new ExitAction();
@ -69,9 +69,9 @@ public class ActionFactory {
static RunServerPrefsAction fRunServerPrefsAction = new RunServerPrefsAction();
static RunGeneralPrefsAction fRunGeneralPrefsAction = new RunGeneralPrefsAction();
static RunUIPrefsAction fRunUIPrefsAction = new RunUIPrefsAction();
static int fIdent = 0;
static Runnable fComposeMessageThread = new DummyComposeMessageThread();
static public ExitAction GetExitAction() {
@ -89,7 +89,7 @@ public class ActionFactory {
static public void SetComposeMessageThread(Runnable aThread) {
fComposeMessageThread = aThread;
}
static public void setIdent(int aIdent) {
System.out.println("setIdent "+aIdent);
fIdent = aIdent;
@ -115,11 +115,11 @@ public class ActionFactory {
static public ShowTooltipsAction GetShowTooltipsAction() {
return fShowTooltipsAction;
}
static public RunIdentityPrefsAction GetRunIdentityPrefsAction() {
return fRunIdentityPrefsAction;
}
static public RunServerPrefsAction GetRunServerPrefsAction() {
return fRunServerPrefsAction;
}
@ -127,20 +127,20 @@ public class ActionFactory {
static public RunGeneralPrefsAction GetRunGeneralPrefsAction() {
return fRunGeneralPrefsAction;
}
static public RunUIPrefsAction GetRunUIPrefsAction() {
return fRunUIPrefsAction;
}
}
class ExitAction extends UIAction {
class ExitAction extends Event {
public ExitAction() {
super("appExit");
setEnabled(true);
}
public void actionPerformed(ActionEvent aEvent) {
GeneralFrame.CloseAllFrames();
@ -151,21 +151,21 @@ class ExitAction extends UIAction {
}
}
class NewMailAction extends UIAction {
class NewMailAction extends Event {
public NewMailAction() {
super("msgGetNew");
setEnabled(true);
}
public void actionPerformed(ActionEvent aEvent) {
ProgressFactory.NewMailProgress();
}
}
class ComposeMessageAction extends UIAction {
class ComposeMessageAction extends Event {
public ComposeMessageAction() {
super("msgNew");
@ -185,55 +185,20 @@ class DummyComposeMessageThread implements Runnable {
}
}
class PreferencesAction extends UIAction {
PreferencesAction fThis;
public PreferencesAction() {
super("appPrefs");
fThis = this;
setEnabled(true);
}
public void actionPerformed(ActionEvent aEvent) {
Object source = aEvent.getSource();
if (source instanceof Component) {
Frame frame = Util.GetParentFrame((Component) source);
if (frame instanceof JFrame) {
new Thread(new PrefThread((JFrame) frame), "Prefs").start();
}
}
}
class PrefThread implements Runnable {
JFrame fFrame;
PrefThread(JFrame aFrame) {
fFrame = aFrame;
}
public void run() {
synchronized(fThis) {
setEnabled(false);
new PrefsDialog(fFrame);
setEnabled(true);
}
}
}
}
class SearchAction extends UIAction {
class SearchAction extends Event {
SearchAction() {
super("appSearch");
}
public void actionPerformed(ActionEvent aEvent) {
Frame frame = new SearchFrame();
frame.show();
frame.setVisible(true);
frame.toFront();
frame.requestFocus();
}
}
class RunFiltersAction extends UIAction {
class RunFiltersAction extends Event {
RunFiltersAction() {
super("appRunFilters");
@ -247,7 +212,7 @@ class RunFiltersAction extends UIAction {
}
}
class ShowTooltipsAction extends UIAction {
class ShowTooltipsAction extends Event {
ShowTooltipsAction() {
super("appShowTooltips");
@ -266,50 +231,50 @@ class ShowTooltipsAction extends UIAction {
}
}
class RunIdentityPrefsAction extends UIAction {
class RunIdentityPrefsAction extends Event {
RunIdentityPrefsAction() {
super("prefIds");
}
public void actionPerformed(ActionEvent aEvent) {
JFrame prefs = new Identities();
prefs.show();
prefs.setVisible(true);
}
}
class RunServerPrefsAction extends UIAction {
class RunServerPrefsAction extends Event {
RunServerPrefsAction() {
super("prefSrvs");
}
public void actionPerformed(ActionEvent aEvent) {
JFrame prefs = new Servers();
prefs.show();
prefs.setVisible(true);
}
}
class RunGeneralPrefsAction extends UIAction {
class RunGeneralPrefsAction extends Event {
RunGeneralPrefsAction() {
super("prefGeneral");
}
public void actionPerformed(ActionEvent aEvent) {
JFrame prefs = new General();
prefs.show();
prefs.setVisible(true);
}
}
class RunUIPrefsAction extends UIAction {
class RunUIPrefsAction extends Event {
RunUIPrefsAction() {
super("prefUI");
}
public void actionPerformed(ActionEvent aEvent) {
JFrame prefs = new UI();
prefs.show();
prefs.setVisible(true);
}
}

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

@ -1,89 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 19 Sep 1997.
*
* Contributors: Jeff Galyan <talisman@anamorphic.com>
*/
package grendel.ui;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import grendel.storage.MailDrop;
/**
* This is a simple biff label. It watches the BiffThread
* to update its state.
*/
class BiffIcon extends JLabel implements ChangeListener {
BiffThread fThread;
static Icon fIconUnknown;
static Icon fIconNew;
static Icon fIconNone;
public BiffIcon() {
if (fIconUnknown == null) {
fIconUnknown =
new ImageIcon(getClass().getResource("images/biffUnknown.gif"));
fIconNew =
new ImageIcon(getClass().getResource("images/biffNew.gif"));
fIconNone =
new ImageIcon(getClass().getResource("images/biffNone.gif"));
}
setText(null); // Necessary for icon size to be used for preferred size
setBiffState(MailDrop.UNKNOWN);
fThread = BiffThread.Get();
fThread.addChangeListener(this);
setBiffState(fThread.getBiffState());
}
public void dispose() {
fThread.removeChangeListener(this);
}
public void stateChanged(ChangeEvent aEvent) {
setBiffState(fThread.getBiffState());
repaint();
}
void setBiffState(int aState) {
switch (aState) {
case MailDrop.NEW:
setIcon(fIconNew);
break;
case MailDrop.NONE:
setIcon(fIconNone);
break;
case MailDrop.UNKNOWN:
setIcon(fIconUnknown);
break;
}
}
}

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

@ -1,185 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 6 Nov 1997.
*
* Contributors: Jeff Galyan <talisman@anamorphic.com>
* Giao Nguyen <grail@cafebabe.org>
* Edwin Woudt <edwin@woudt.nl>
*/
package grendel.ui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Insets;
import java.util.StringTokenizer;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Folder;
import javax.swing.ImageIcon;
import javax.swing.ListCellRenderer;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.border.EmptyBorder;
import javax.swing.UIManager;
import grendel.view.ViewedStore;
import grendel.view.ViewedFolder;
public class FolderCombo extends JComboBox {
int fExclude;
int fInclude;
Color fTextColor;
Color fHighlightTextColor;
Color fWindowColor;
Color fHighlightColor;
public FolderCombo() {
updateUI();
}
public void populate() {
populate(-1, 0);
}
public void populate(int aInclude, int aExclude) {
ViewedStore stores[] = StoreFactory.Instance().getStores();
fInclude = aInclude;
fExclude = aExclude;
// this hack is getting old. why do i need it in the first place?
// this sucks!
if (getItemCount() > 0) {
removeAllItems();
}
try {
for (int i = 0; i < stores.length; i++) {
populateRecurse(stores[i], fInclude, fExclude);
}
} catch (MessagingException e) {
e.printStackTrace();
}
}
int populateRecurse(ViewedFolder aFolder, int fInclude, int fExclude)
throws MessagingException {
int total = 0;
while (aFolder != null) {
int idx = getItemCount();
int count = populateRecurse(aFolder.getFirstSubFolder(),
fInclude, fExclude);
total += count;
if ((aFolder.getFolder().getType() & fInclude) != 0 &&
(aFolder.getFolder().getType() & fExclude) == 0) {
insertItemAt(aFolder, idx);
total++;
} else if (count > 0) {
insertItemAt(aFolder, idx);
total++;
}
aFolder = aFolder.getNextFolder();
}
return total;
}
public ViewedFolder getSelectedFolder() {
return (ViewedFolder) getSelectedItem();
}
class FolderRenderer extends JLabel implements ListCellRenderer {
public FolderRenderer() {
setIcon(new ImageIcon(getClass().getResource("/grendel/ui/images/folder-small.gif")));
setOpaque(true);
}
public Component getListCellRendererComponent(JList aList,
Object aValue,
int aIndex,
boolean aIsSelected,
boolean aHasFocus) {
boolean isEnabled = true;
Folder folder = null;
if (aValue != null) {
folder = ((ViewedFolder) aValue).getFolder();
}
if (folder != null) {
try {
StringTokenizer counter =
new StringTokenizer(folder.getFullName(),
"" +
folder.getSeparator());
int depth = counter.countTokens();
setBorder(new EmptyBorder(0, depth * 16, 0, 0));
setText(folder.getName());
if ((folder.getType() & fInclude) == 0 ||
(folder.getType() & fExclude) != 0) {
isEnabled = false;
}
} catch (MessagingException e) {
e.printStackTrace();
}
} else {
setText("");
}
this.setEnabled(isEnabled);
if (aIsSelected) {
setBackground(fHighlightColor);
setForeground(fHighlightTextColor);
} else {
setBackground(fWindowColor);
setForeground(fTextColor);
}
return this;
}
}
public void updateUI() {
super.updateUI();
fTextColor = UIManager.getColor("textText");
fHighlightTextColor = UIManager.getColor("textHighlightText");
fWindowColor = UIManager.getColor("window");
fHighlightColor = UIManager.getColor("textHighlight");
setRenderer(new FolderRenderer());
}
}

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 18 Nov 1997.
*
@ -40,10 +40,11 @@ import grendel.view.ViewedMessage;
import javax.swing.event.ChangeEvent;
import grendel.ui.UIAction;
import grendel.widgets.StatusEvent;
import grendel.widgets.TreePath;
import com.trfenv.parsers.Event;
public class FolderFrame extends GeneralFrame {
static Vector fFolderFrames = new Vector();
FolderPanel fFolderPanel;
@ -56,8 +57,8 @@ public class FolderFrame extends GeneralFrame {
fPanel.add(fFolderPanel);
// fMenu = buildMenu("folderMain", Util.MergeActions(actions,
// fFolderPanel.getActions()));
fMenu = buildMenu("menus.xml",
Util.MergeActions(actions, fFolderPanel.getActions()));
XMLMenuBuilder builder = new XMLMenuBuilder(Util.MergeActions(actions, fFolderPanel.getActions()));
fMenu = builder.buildFrom("ui/menus.xml", this);
getRootPane().setJMenuBar(fMenu);
fToolBar = fFolderPanel.getToolBar();
@ -142,7 +143,7 @@ public class FolderFrame extends GeneralFrame {
}
}
}
UIAction actions[] = { ActionFactory.GetExitAction(),
Event actions[] = { ActionFactory.GetExitAction(),
ActionFactory.GetNewMailAction(),
ActionFactory.GetComposeMessageAction()};
}

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 3 Sep 1997.
*
@ -72,7 +72,6 @@ import grendel.composition.Composition;
import grendel.prefs.base.InvisiblePrefs;
import grendel.storage.MessageExtra;
import grendel.storage.MessageExtraFactory;
import grendel.ui.UIAction;
import grendel.view.FolderView;
import grendel.view.FolderViewFactory;
import grendel.view.MessageSetView;
@ -100,6 +99,8 @@ import grendel.widgets.TreeTableDataModel;
import calypso.util.Assert;
import com.trfenv.parsers.Event;
/**
* Panel to display the <em>contents</em> of a folder.
*/
@ -214,7 +215,7 @@ public class FolderPanel extends GeneralPanel {
ThreadAction fThreadAction = new ThreadAction();
// The big action list
UIAction fActions[] = {ActionFactory.GetNewMailAction(),
Event fActions[] = {ActionFactory.GetNewMailAction(),
ActionFactory.GetComposeMessageAction(),
fDeleteMessageAction,
fOpenMessageAction,
@ -273,8 +274,8 @@ public class FolderPanel extends GeneralPanel {
ToggleCellRenderer renderer;
ToggleCellEditor editor;
Icon unreadIcon = new ImageIcon(getClass().getResource("images/unread.gif"));
Icon readIcon = new ImageIcon(getClass().getResource("images/read.gif"));
Icon unreadIcon = new ImageIcon("ui/images/unread.gif");
Icon readIcon = new ImageIcon("ui/images/read.gif");
renderer = new ToggleCellRenderer();
renderer.getCheckBox().setIcon(unreadIcon);
@ -292,8 +293,8 @@ public class FolderPanel extends GeneralPanel {
column.setCellEditor(editor);
fMessageTree.addColumn(column);
Icon unflaggedIcon = new ImageIcon(getClass().getResource("images/unflagged.gif"));
Icon flaggedIcon = new ImageIcon(getClass().getResource("images/flagged.gif"));
Icon unflaggedIcon = new ImageIcon("ui/images/unflagged.gif");
Icon flaggedIcon = new ImageIcon("ui/images/flagged.gif");
renderer = new ToggleCellRenderer();
renderer.getCheckBox().setIcon(unflaggedIcon);
@ -311,8 +312,8 @@ public class FolderPanel extends GeneralPanel {
column.setCellEditor(editor);
fMessageTree.addColumn(column);
Icon deletedIcon = new ImageIcon(getClass().getResource("images/deleted.gif"));
Icon undeletedIcon = new ImageIcon(getClass().getResource("images/unflagged.gif"));
Icon deletedIcon = new ImageIcon("ui/images/deleted.gif");
Icon undeletedIcon = new ImageIcon("ui/images/unflagged.gif");
renderer = new ToggleCellRenderer();
renderer.getCheckBox().setIcon(undeletedIcon);
@ -429,7 +430,7 @@ public class FolderPanel extends GeneralPanel {
* Returns the actions available for this panel
*/
public UIAction[] getActions() {
public Event[] getActions() {
return Util.MergeActions(fActions, fSortActions);
}
@ -751,7 +752,7 @@ public class FolderPanel extends GeneralPanel {
}
}
class OpenMessageAction extends UIAction implements Runnable {
class OpenMessageAction extends Event implements Runnable {
OpenMessageAction() {
super("msgOpen");
@ -785,7 +786,7 @@ public class FolderPanel extends GeneralPanel {
// DeleteMessageAction class
//
class DeleteMessageAction extends UIAction {
class DeleteMessageAction extends Event {
DeleteMessageAction() {
super("msgDelete");
@ -801,7 +802,7 @@ public class FolderPanel extends GeneralPanel {
// CopyMessageAction class
//
class CopyMessageAction extends UIAction {
class CopyMessageAction extends Event {
Folder fDest;
@ -820,7 +821,7 @@ public class FolderPanel extends GeneralPanel {
// MoveMessageAction class
//
class MoveMessageAction extends UIAction {
class MoveMessageAction extends Event {
Folder fDest;
@ -839,7 +840,7 @@ public class FolderPanel extends GeneralPanel {
// ThreadAction class
//
class ThreadAction extends UIAction {
class ThreadAction extends Event {
boolean selected;
@ -865,7 +866,7 @@ public class FolderPanel extends GeneralPanel {
// SortAction class
//
class SortAction extends UIAction {
class SortAction extends Event {
int fType;
boolean selected;
@ -877,7 +878,7 @@ public class FolderPanel extends GeneralPanel {
public int getType() {
return fType;
}
public void setSelected(boolean isSelected) {
selected = isSelected;
}
@ -896,7 +897,7 @@ public class FolderPanel extends GeneralPanel {
// ReplyAction class
//
class ReplyAction extends UIAction {
class ReplyAction extends Event {
boolean replyall;
public ReplyAction(String aAction, boolean r) {
super(aAction);
@ -913,7 +914,7 @@ public class FolderPanel extends GeneralPanel {
}
Composition frame = new Composition();
frame.initializeAsReply((Message) (selection.elementAt(0)), replyall);
frame.show();
frame.setVisible(true);
frame.requestFocus();
}
}
@ -922,7 +923,7 @@ public class FolderPanel extends GeneralPanel {
// ForwardAction class
//
class ForwardAction extends UIAction {
class ForwardAction extends Event {
int fScope;
ForwardAction(String aName, int aScope) {
@ -940,7 +941,7 @@ public class FolderPanel extends GeneralPanel {
}
Composition frame = new Composition();
frame.initializeAsForward((Message) (selection.elementAt(0)), fScope);
frame.show();
frame.setVisible(true);
frame.requestFocus();
}
}
@ -949,7 +950,7 @@ public class FolderPanel extends GeneralPanel {
// MarkAction class
//
class MarkAction extends UIAction {
class MarkAction extends Event {
int fScope;
MarkAction(String aName, int aScope) {
@ -1021,7 +1022,7 @@ public class FolderPanel extends GeneralPanel {
}
}
}
//
// Cut-n-paste stuff
@ -1033,7 +1034,7 @@ public class FolderPanel extends GeneralPanel {
}
}
class CopyToClipboardAction extends UIAction {
class CopyToClipboardAction extends Event {
CopyToClipboardAction() {
super("copy-to-clipboard");
@ -1051,7 +1052,7 @@ public class FolderPanel extends GeneralPanel {
}
}
class PasteFromClipboardAction extends UIAction {
class PasteFromClipboardAction extends Event {
PasteFromClipboardAction() {
super("paste-from-clipboard");

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 3 Sep 1997.
*
@ -158,12 +158,8 @@ public class GeneralFrame extends JFrame
// We need to use Class.forName because getClass() might return a child
// class in another package.
try {
URL url = Class.forName("grendel.ui.GeneralFrame").getResource("images/GrendelIcon32.gif");
setIconImage(getToolkit().getImage(url));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
ImageIcon curImage = new ImageIcon("ui/images/GrendelIcon32.gif");
setIconImage(curImage.getImage());
fFrameList.addElement(this);
}
@ -266,30 +262,6 @@ public class GeneralFrame extends JFrame
}
}
/**
* Creates the MenuBar by reading from an XML file
*
* @param file the XML file to build the menu from
* @return a menubar built from the file
*/
protected MenuBarCtrl buildMenu(String file, UIAction[] actions) {
MenuBarCtrl menubar = null;
URL url;
XMLMenuBuilder builder =
new XMLMenuBuilder(this, actions);
try {
url = getClass().getResource(file);
builder.buildFrom(url.openStream());
menubar = builder.getComponent();
} catch (Throwable t) {
t.printStackTrace();
}
menubar.setFont(new Font("Helvetica", Font.PLAIN, 12));
return menubar;
}
protected Component buildStatusBar() {
JPanel res = new JPanel();
res.setLayout(new BoxLayout(res, BoxLayout.X_AXIS));

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 13 Oct 1997.
*
@ -27,7 +27,6 @@
package grendel.ui;
import grendel.ui.UIAction;
import grendel.ui.ToolBarLayout;
import grendel.widgets.GrendelToolBar;
@ -50,6 +49,8 @@ import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JButton;
import com.trfenv.parsers.Event;
public class GeneralPanel extends JPanel {
private final boolean DEBUG = false;
static ResourceBundle fLabels = ResourceBundle.getBundle("grendel.ui.Labels",
@ -65,21 +66,21 @@ public class GeneralPanel extends JPanel {
setFont(new Font("Helvetica", Font.PLAIN, 12));
}
public UIAction[] getActions() {
public Event[] getActions() {
return null;
}
protected GrendelToolBar buildToolBar(String aToolbar, UIAction[] aActions) {
protected GrendelToolBar buildToolBar(String aToolbar, Event[] aActions) {
GrendelToolBar res = null;
Hashtable commands = new Hashtable();
for (int i = 0; i < aActions.length; i++)
{
UIAction a = aActions[i];
Event a = aActions[i];
String name = a.getName();
commands.put(name, a);
}
try {
res = new GrendelToolBar();
@ -94,11 +95,11 @@ public class GeneralPanel extends JPanel {
if (DEBUG) {
System.out.println("Local token = " + token);
}
UIAction action = (UIAction)commands.get(token);
Event action = (Event)commands.get(token);
String icon = toolbarresources.getString(token + "Icon");
String label = toolbarresources.getString(token + "Label");
String tooltip = toolbarresources.getString(token + "Tooltip");
res.addButton(action, icon, label, tooltip);
}
} catch (MissingResourceException e) {

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

@ -1,74 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Grendel mail/news client.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1997 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Jeff Galyan <talisman@anamorphic.com>
# Giao Nguyen <grail@cafebabe.org>
TOPDIR=../../..
SRCS= \
ActionFactory.java \
BiffIcon.java \
BiffThread.java \
DialogAuthenticator.java \
EditHostDialog.java \
FolderCombo.java \
FolderFrame.java \
FolderListTransferable.java \
FolderPanel.java \
FolderPanelListener.java \
GeneralDialog.java \
GeneralFrame.java \
GeneralPanel.java \
MasterPanel.java \
MasterPanelListener.java \
MessageCellRenderer.java \
MessageDisplayManager.java \
MessageFrame.java \
MessageHeader.java \
MessageListTransferable.java \
MessageModel.java \
MessagePanel.java \
MessagePanelListener.java \
MultiMessageDisplayManager.java \
NewFolderDialog.java \
PageUI.java \
PageModel.java \
PrefsDialog.java \
ProgressFactory.java \
ProgressFrame.java \
SimpleAuthenticator.java \
SimpleMessageHeader.java \
StoreFactory.java \
ToolBarLayout.java \
UIAction.java \
UIFactory.java \
UnifiedMessageDisplayManager.java \
Util.java \
XMLPageBuilder.java \
XMLMenuBuilder.java \
XMLWidgetBuilder.java \
$(NULL)
include ../../../rules.mk
resources::
cp *.xml $(DISTDIR)/grendel/ui
cp *.properties $(DISTDIR)/grendel/ui
cp -r images $(DISTDIR)/grendel/ui

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 3 Sep 1997.
*
@ -80,7 +80,6 @@ import grendel.prefs.base.InvisiblePrefs;
import grendel.prefs.base.ServerArray;
import grendel.storage.FolderExtraFactory;
import grendel.storage.SearchResultsFolderFactory;
import grendel.ui.UIAction;
import grendel.view.ViewedFolder;
import grendel.view.ViewedStore;
import grendel.view.ViewedStoreEvent;
@ -104,6 +103,8 @@ import grendel.widgets.TreeTableModelBroadcaster;
import grendel.widgets.TreeTableModelEvent;
import grendel.widgets.TreeTableModelListener;
import com.trfenv.parsers.Event;
/**
* Panel to display the <em>contents</em> of a folder.
*/
@ -117,7 +118,7 @@ public class MasterPanel extends GeneralPanel {
StoreChangeListener fStoreChangeListener = null;
ViewedStore fStores[];
UIAction fActions[] = {ActionFactory.GetNewMailAction(),
Event fActions[] = {ActionFactory.GetNewMailAction(),
ActionFactory.GetComposeMessageAction(),
new CopyToClipboardAction(),
new PasteFromClipboardAction(),
@ -211,7 +212,7 @@ public class MasterPanel extends GeneralPanel {
fStoreChangeListener = new StoreChangeListener();
StoreFactory.Instance().addChangeListener(fStoreChangeListener);
ActionFactory.SetComposeMessageThread(new ComposeMessageThread());
fPanel.setFont(new Font("Helvetica", Font.PLAIN, 12));
}
@ -228,7 +229,7 @@ public class MasterPanel extends GeneralPanel {
* Returns the actions associated with this panel.
*/
public UIAction[] getActions() {
public Event[] getActions() {
return fActions;
}
@ -341,7 +342,7 @@ public class MasterPanel extends GeneralPanel {
}
}
class NewFolderAction extends UIAction {
class NewFolderAction extends Event {
NewFolderAction() {
super("folderNew");
@ -360,7 +361,7 @@ public class MasterPanel extends GeneralPanel {
}
}
class DeleteFolderAction extends UIAction {
class DeleteFolderAction extends Event {
DeleteFolderAction() {
super("folderDelete");
}
@ -394,8 +395,8 @@ public class MasterPanel extends GeneralPanel {
ActionFactory.setIdent(identity);
Composition frame = new Composition();
frame.show();
frame.setVisible(true);
frame.requestFocus();
}
}
@ -406,7 +407,7 @@ public class MasterPanel extends GeneralPanel {
}
}
class CopyToClipboardAction extends UIAction {
class CopyToClipboardAction extends Event {
CopyToClipboardAction() {
super("copy-to-clipboard");
@ -424,7 +425,7 @@ public class MasterPanel extends GeneralPanel {
}
}
class PasteFromClipboardAction extends UIAction {
class PasteFromClipboardAction extends Event {
PasteFromClipboardAction() {
super("paste-from-clipboard");
@ -714,7 +715,7 @@ class FolderModel implements TreeTableDataModel {
node = getFolder(aNode);
if (aID == MasterPanel.kNameID) {
parent = node.getParent();
}
String newName = (String) aValue;
@ -765,7 +766,7 @@ class FolderModel implements TreeTableDataModel {
} catch (MessagingException e) {
}
}
Folder getFolder(Object aObject) {
Folder res = null;

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

@ -0,0 +1,190 @@
<!--
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Grendel mail/news client.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1997 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Will Scullin <scullin@meer.net>
# Edwin Woudt <edwin@woudt.nl>
# R.J. Keller <rj.keller@beonex.com
# -->
<!-- multipane menu labels -->
<!ENTITY multiFileLabel "File" >
<!ENTITY multiFileAccel "F" >
<!ENTITY multiEditLabel "Edit" >
<!ENTITY multiEditAccel "E" >
<!ENTITY multiViewLabel "View" >
<!ENTITY multiViewAccel "V" >
<!ENTITY multiMessageLabel "Message" >
<!ENTITY multiMessageAccel "M" >
<!-- Master menu labels -->
<!ENTITY masterFileLabel "File" >
<!ENTITY masterFileAccel "F" >
<!ENTITY masterEditLabel "Edit" >
<!ENTITY masterEditAccel "E" >
<!-- Folder menu labels -->
<!ENTITY folderFileLabel "File" >
<!ENTITY folderFileAccel "F" >
<!ENTITY folderEditLabel "Edit" >
<!ENTITY folderEditAccel "E" >
<!ENTITY folderMessageLabel "Message" >
<!ENTITY folderMessageAccel "M" >
<!-- Message menu labels -->
<!ENTITY messageFileLabel "File" >
<!ENTITY messageFileAccel "F" >
<!ENTITY messageEditLabel "Edit" >
<!ENTITY messageEditAccel "E" >
<!ENTITY messageMessageLabel "Message" >
<!ENTITY messageMessageAccel "M" >
<!-- View menu labels -->
<!ENTITY viewLayoutLabel "Layout" >
<!ENTITY viewLayoutAccel "L" >
<!ENTITY splitLeftLabel "Split Left" >
<!ENTITY splitLeftAccel "L" >
<!ENTITY splitRightLabel "Split Right" >
<!ENTITY splitRightAccel "R" >
<!ENTITY splitTopLabel "Split Top" >
<!ENTITY splitTopAccel "T" >
<!ENTITY stackedLabel "Stacked" >
<!ENTITY stackedAccel "S" >
<!ENTITY appShowTooltipsLabel "Show Tooltips" >
<!ENTITY appShowTooltipsAccel "T" >
<!-- Common menu labels -->
<!ENTITY windowLabel "Window" >
<!ENTITY windowAccel "W" >
<!-- Application menu item labels -->
<!ENTITY appExitLabel "Exit" >
<!ENTITY appExitAccel "x" >
<!ENTITY appPrefsLabel "Preferences..." >
<!ENTITY appPrefsAccel "r" >
<!ENTITY appSearchLabel "Search" >
<!ENTITY appSearchAccel "S" >
<!ENTITY appRunFiltersLabel "Run Filters on TestInbox" >
<!ENTITY appRunFiltersAccel "F" >
<!-- Edit menu item labels -->
<!ENTITY editUndoLabel "Undo" >
<!ENTITY editUndoAccel "U" >
<!ENTITY editCutLabel "Cut" >
<!ENTITY editCutAccel "t" >
<!ENTITY editCopyLabel "Copy" >
<!ENTITY editCopyAccel "C" >
<!ENTITY editPasteLabel "Paste" >
<!ENTITY editPasteAccel "P" >
<!ENTITY editClearLabel "Delete" >
<!ENTITY editClearAccel "D" >
<!-- Folder menu item labels -->
<!ENTITY folderOpenLabel "Open Folder" >
<!ENTITY folderOpenAccel "O" >
<!-- Message menu item labels -->
<!ENTITY folderNewLabel "New Folder..." >
<!ENTITY folderNewAccel "F" >
<!ENTITY folderDeleteLabel "Delete Folder" >
<!ENTITY folderDeleteAccel "D" >
<!ENTITY msgGetNewLabel "Get New Messages" >
<!ENTITY msgGetNewAccel "G" >
<!ENTITY msgOpenLabel "Open Message" >
<!ENTITY msgOpenAccel "M" >
<!ENTITY msgSaveAsLabel "Save As..." >
<!ENTITY msgSaveAsAccel "A" >
<!ENTITY msgNewLabel "New Message" >
<!ENTITY msgNewAccel "N" >
<!ENTITY msgReplyLabel "Reply" >
<!ENTITY msgReplyAccel "R" >
<!ENTITY msgReplyAllLabel "Reply All" >
<!ENTITY msgReplyAllAccel "A" >
<!ENTITY fwdQuotedLabel "Forward Quoted" >
<!ENTITY fwdQuotedAccel "Q" >
<!ENTITY fwdInlineLabel "Forward Inline" >
<!ENTITY fwdInlineAccel "I" >
<!ENTITY fwdAttachmentLabel "Forward Attachment" >
<!ENTITY fwdAttachmentAccel "A" >
<!ENTITY msgMoveLabel "File to" >
<!ENTITY msgMoveAccel "F" >
<!ENTITY msgMovePopupLabel "File to" >
<!ENTITY msgCopyLabel "Copy to" >
<!ENTITY msgCopyAccel "C" >
<!ENTITY msgCopyPopupLabel "Copy to" >
<!ENTITY msgDeleteLabel "Delete Message" >
<!ENTITY msgDeleteAccel "D" >
<!ENTITY msgDeletePopupLabel "Delete Message" >
<!ENTITY msgMarkLabel "Mark" >
<!ENTITY msgMarkAccel "M" >
<!-- Mark menu labels -->
<!ENTITY markMsgReadLabel "As Read" >
<!ENTITY markMsgReadAccel "R" >
<!ENTITY markThreadReadLabel "Thread Read" >
<!ENTITY markThreadReadAccel "T" >
<!ENTITY markAllReadLabel "All Read" >
<!ENTITY markAllReadAccel "A" >
<!-- Sort menu labels -->
<!ENTITY viewSortLabel "Sort" >
<!ENTITY viewSortAccel "S" >
<!ENTITY toggleThreadingLabel "Toggle Threading" >
<!ENTITY toggleThreadingAccel "T" >
<!ENTITY sortDateLabel "by Date" >
<!ENTITY sortDateAccel "D" >
<!ENTITY sortSubjectLabel "by Subject" >
<!ENTITY sortSubjectAccel "S" >
<!ENTITY sortAuthorLabel "by Author" >
<!ENTITY sortAuthorAccel "A" >
<!ENTITY sortNumberLabel "by Number" >
<!ENTITY sortNumberAccel "N" >
<!-- Window menu item labels -->
<!ENTITY windowListLabel "Window List..." >
<!ENTITY windowListAccel "W" >
<!-- Preferences menu labels -->
<!ENTITY multiPrefsLabel "Preferences" >
<!ENTITY multiPrefsAccel "P" >
<!ENTITY prefIdsLabel "Identities" >
<!ENTITY prefIdsAccel "I" >
<!ENTITY prefSrvsLabel "Servers" >
<!ENTITY prefSrvsAccel "S" >
<!ENTITY prefGeneralLabel "General" >
<!ENTITY prefGeneralAccel "G" >
<!ENTITY prefUILabel "User interface" >
<!ENTITY prefUIAccel "U" >

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 18 Nov 1997.
*
@ -35,10 +35,9 @@ import java.util.Vector;
import javax.mail.Message;
import javax.mail.MessagingException;
//import netscape.orion.toolbars.ToolbarFactory;
//import netscape.orion.toolbars.ToolBarLayout;
//import netscape.orion.uimanager.AbstractUICmd;
//import netscape.orion.uimanager.IUICmd;
import grendel.ui.XMLMenuBuilder;
import com.trfenv.parsers.Event;
public class MessageFrame extends GeneralFrame {
static Vector fMessageFrames = new Vector();
@ -56,9 +55,9 @@ public class MessageFrame extends GeneralFrame {
fPanel.add(fMessagePanel);
// fMenu = buildMenu("messageMain", Util.MergeActions(actions,
// fMessagePanel.getActions()));
fMenu = buildMenu("menus.xml",
Util.MergeActions(actions,
XMLMenuBuilder builder = new XMLMenuBuilder(Util.MergeActions(actions,
fMessagePanel.getActions()));
fMenu = builder.buildFrom("ui/menus.xml", this);
getRootPane().setJMenuBar(fMenu);
fToolBar = fMessagePanel.getToolBar();
@ -128,6 +127,6 @@ public class MessageFrame extends GeneralFrame {
return null;
}
UIAction actions[] = { ActionFactory.GetExitAction(),
Event actions[] = { ActionFactory.GetExitAction(),
ActionFactory.GetComposeMessageAction() };
}

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

@ -64,8 +64,8 @@ class MessageModel implements TreeTableDataModel {
Icon fMessageReadIcon;
public MessageModel() {
fMessageIcon = new ImageIcon(getClass().getResource("images/msg-small.gif"));
fMessageReadIcon = new ImageIcon(getClass().getResource("images/msgRead-small.gif"));
fMessageIcon = new ImageIcon("ui/images/msg-small.gif");
fMessageReadIcon = new ImageIcon("ui/images/msgRead-small.gif");
}
public void setFolderView(FolderView aView) {

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 3 Sep 1997.
*
@ -71,11 +71,12 @@ import grendel.mime.parser.MimeParserFactory;
import grendel.mime.html.MimeHTMLOperatorFactory;
import grendel.storage.MessageExtra;
import grendel.storage.MessageExtraFactory;
import grendel.ui.UIAction;
import grendel.widgets.GrendelToolBar;
import grendel.widgets.StatusEvent;
import com.trfenv.parsers.Event;
/* ####
import calypso.net.URLSource;
*/
@ -102,7 +103,7 @@ public class MessagePanel extends GeneralPanel {
EventListenerList fListeners = new EventListenerList();
UIAction fActions[] = {ActionFactory.GetNewMailAction(),
Event fActions[] = {ActionFactory.GetNewMailAction(),
ActionFactory.GetComposeMessageAction()};
/**
* Constructs a new message panel.
@ -270,7 +271,7 @@ public class MessagePanel extends GeneralPanel {
if (makeRealHTML) {
stream = new MakeItHTML(stream).getHTMLInputStream();
}
// Okay, let's try to read from the stream and set the
// Okay, let's try to read from the stream and set the
// text from the InputStream. We may need to put this
// stuff back later. (talisman)
//InputStreamReader reader = new InputStreamReader(stream);

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 3 Sep 1997.
*
@ -39,11 +39,12 @@ import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Store;
import grendel.ui.UIAction;
import grendel.view.ViewedFolder;
import grendel.view.ViewedMessage;
import grendel.widgets.TreePath;
import com.trfenv.parsers.Event;
public class MultiMessageDisplayManager extends MessageDisplayManager {
MasterFrame fMasterFrame;
@ -136,7 +137,8 @@ class MasterFrame extends GeneralFrame {
fMasterPanel.addMasterPanelListener(new FolderSelectionListener());
fPanel.add(fMasterPanel);
// fMenu = buildMenu("masterMain", actions);
fMenu = buildMenu("menus.xml", actions);
XMLMenuBuilder builder = new XMLMenuBuilder(actions);
fMenu = builder.buildFrom("ui/menus.xml", this);
getRootPane().setJMenuBar(fMenu);
fToolBar = fMasterPanel.getToolBar();
@ -200,7 +202,7 @@ class MasterFrame extends GeneralFrame {
// Action array
UIAction actions[] = { ActionFactory.GetExitAction(),
Event actions[] = { ActionFactory.GetExitAction(),
ActionFactory.GetNewMailAction(),
ActionFactory.GetComposeMessageAction()};
}

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

@ -1,198 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Giao Nguyen
* <grail@cafebabe.org>. Portions created by Giao Nguyen are
* Copyright (C) 1999 Giao Nguyen. All
* Rights Reserved.
*
* Contributor(s):
*/
package grendel.ui;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;
import java.awt.Container;
import java.awt.Component;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.RootPaneContainer;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JToggleButton;
import javax.swing.JScrollPane;
import javax.swing.JComboBox;
import javax.swing.ComboBoxModel;
import javax.swing.text.JTextComponent;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import com.sun.xml.parser.Resolver;
import com.sun.xml.parser.Parser;
import com.sun.xml.tree.XmlDocument;
import com.sun.xml.tree.XmlDocumentBuilder;
import com.sun.xml.tree.TreeWalker;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class PageUI extends JPanel {
Hashtable table = new Hashtable();
PageModel model;
String title;
public PageUI() {
}
private void build(XMLPageBuilder pb, URL url, PageModel model) {
setModel(model);
try {
pb.buildFrom(url.openStream());
title = pb.getTitle();
} catch (Exception e) {
}
}
/**
* Get the model for the page.
*
* @return the model
*/
public PageModel getModel() {
return model;
}
/**
* Set the model for the page.
*
* @param model the model as the backing for the page
*/
public void setModel(PageModel model) {
this.model = model;
}
public void addCtrl(String name, JComponent component) {
System.out.println("addCtrl2: "+name);
if (name != null) table.put(name, component);
if (component instanceof JList) {
component = new JScrollPane(component);
}
add(component);
}
public void addCtrl(String name, JComponent component,
Object constraints) {
System.out.println("addCtrl: "+name);
if (name != null) table.put(name, component);
if (component instanceof JList) {
component = new JScrollPane(component);
}
add(component, constraints);
}
/**
* Get a component by its name.
*
* @param key the name of the component to retrieve
* @param return the component identiified by the key
*/
public JComponent getCtrlByName(String key) {
return (JComponent)table.get(key);
}
/**
* Get the title of this page.
*
* @return the title for this page
*/
public String getTitle() {
return title;
}
/**
* Store the values set in the input fields of the page.
*/
public void saveAll() {
Enumeration e = table.keys();
while(e.hasMoreElements()) {
String k = (String)e.nextElement();
Object obj = table.get(k);
Object val = null;
if (obj instanceof JTextComponent) {
JTextComponent tc = (JTextComponent)obj;
String str = tc.getText();
val = str;
} else if (obj instanceof JToggleButton) {
JToggleButton button = (JToggleButton)obj;
Boolean b = new Boolean(button.isSelected());
val = b;
}
if (val != null) {
model.setAttribute(k, val);
}
}
}
/**
* Initialize input fields to known values.
*/
public void initAll() {
Enumeration e = table.keys();
while (e.hasMoreElements()) {
String s = (String)e.nextElement();
System.out.println(s);
Object obj = table.get(s);
Object val = model.getAttribute(s);
if (obj instanceof JTextComponent) {
JTextComponent tf = (JTextComponent)obj;
tf.setText((String)val);
} else if (obj instanceof JToggleButton) {
JToggleButton button = (JToggleButton)obj;
Boolean b = (Boolean)model.getAttribute(s);
button.setSelected(((Boolean)val).booleanValue());
} else if (obj instanceof JComboBox) {
System.out.println("combo!");
JComboBox combo = (JComboBox)obj;
ComboBoxModel cbmodel = (ComboBoxModel)model.getAttribute(s);
combo.setModel(cbmodel);
}
}
}
}

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

@ -17,11 +17,11 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Jeff Galyan (talisman@anamorphic.com), 20 March, 2001.
*
* Contributors:
* Contributors:
*/
package grendel.ui;
@ -53,10 +53,10 @@ import grendel.filters.FilterMaster;
*/
import grendel.composition.Composition;
import grendel.ui.UIAction;
import com.trfenv.parsers.Event;
class PreferencesAction extends UIAction {
class PreferencesAction extends Event {
PreferencesAction fThis;
public PreferencesAction() {

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

@ -1,179 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 26 Sep 1997.
*
* Contributors: Jeff Galyan <talisman@anamorphic.com>
* Edwin Woudt <edwin@woudt.nl>
*/
package grendel.ui;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.UIManager;
public abstract class ProgressFrame extends GeneralFrame implements Runnable {
int fMax;
JProgressBar fMeter;
JButton fCancel;
JLabel fStatus;
Thread fThread;
boolean fDone;
boolean fCanceled;
boolean fDisposed;
Container fContentPanel;
public ProgressFrame(String aCaption) {
super("", "progress");
setTitle(fLabels.getString(aCaption));
setBackground(UIManager.getColor("control"));
fContentPanel = new Panel();
getContentPane().add(fContentPanel);
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
fContentPanel.setLayout(gridbag);
fStatus = new JLabel("Status");
fMeter = new JProgressBar();
fMeter.setMinimum(0);
fMeter.setMaximum(1);
fMeter.setValue(0);
fCancel = new JButton("Cancel");
fCancel.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent aEvent) {
setCanceled(true);
}
});
c.weightx = 1;
c.weighty = 1;
c.gridheight = 1;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = GridBagConstraints.REMAINDER;
c.insets = new Insets(5,5,5,5);
gridbag.setConstraints(fStatus, c);
fContentPanel.add(fStatus);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = GridBagConstraints.REMAINDER;
c.insets = new Insets(0,5,0,5);
gridbag.setConstraints(fMeter, c);
fContentPanel.add(fMeter);
c.fill = GridBagConstraints.NONE;
c.gridwidth = 1;
c.insets = new Insets(5,5,5,5);
gridbag.setConstraints(fCancel, c);
fContentPanel.add(fCancel);
// Dimension size = getPreferredSize();
restoreBounds(320, 200);
setVisible(true);
}
public synchronized void dispose() {
if (!fDisposed) {
super.dispose();
fDisposed = true;
setCanceled(true);
}
}
public synchronized void setMax(int aMax) {
fMax = aMax;
fMeter.setMaximum(aMax);
}
public synchronized int getMax() {
return fMax;
}
public synchronized void setProgress(int aProgress) {
fMeter.setValue(aProgress);
}
public synchronized int getProgress() {
return fMeter.getValue();
}
public synchronized void setStatus(String aStatus) {
fStatus.setText(aStatus);
}
public synchronized String getStatus() {
return fStatus.getText();
}
public synchronized void setDone(boolean aDone) {
fDone = aDone;
}
public synchronized boolean getDone() {
return fDone;
}
public synchronized void setCanceled(boolean aCanceled) {
fCanceled = aCanceled;
}
public synchronized boolean isCanceled() {
return fCanceled;
}
public void start() {
fThread = new Thread(this);
fThread.start();
}
public void run() {
progressLoop();
fThread = null;
// Is this right? (edwin)
// this.dispose();
this.hide();
}
public abstract void progressLoop();
}

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

@ -12,12 +12,12 @@
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s): Jeff Galyan <jeffrey.galyan@sun.com>
* Contributor(s): Jeff Galyan <jeffrey.galyan@sun.com>
*/
package grendel.ui;
@ -34,10 +34,10 @@ public class Splash extends JWindow {
public Splash() {
super();
ImageIcon image = new ImageIcon(getClass().getResource("images/GrendelSplash.jpg"));
ImageIcon image = new ImageIcon("ui/images/GrendelSplash.jpg");
JLabel splashLabel = new JLabel(image);
getContentPane().add(splashLabel);
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
setLocation(screensize.width/2 - 150, screensize.height/2 - 150);

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

@ -1,123 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 10 Dec 1997.
*
* Contributors: Jeff Galyan <talisman@anamorphic.com>
*/
package grendel.ui;
import java.awt.Image;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import grendel.view.ViewedFolder;
import grendel.view.ViewedStore;
public class UIFactory {
static UIFactory fInstance;
ImageIcon fInboxIcon;
ImageIcon fFolderIcon;
ImageIcon fNewsgroupIcon;
ImageIcon fLocalStoreIcon;
ImageIcon fRemoteStoreIcon;
ImageIcon fConnectedIcon;
private UIFactory() {
fFolderIcon =
new ImageIcon(getClass().getResource("images/folder-small.gif"));
fNewsgroupIcon =
new ImageIcon(getClass().getResource("images/newsgroup-small.gif"));
fLocalStoreIcon =
new ImageIcon(getClass().getResource("images/storeLocal-small.gif"));
fRemoteStoreIcon =
new ImageIcon(getClass().getResource("images/storeRemote-small.gif"));
fInboxIcon =
new ImageIcon(getClass().getResource("images/inbox-small.gif"));
fConnectedIcon =
new ImageIcon(getClass().getResource("images/connected-small.gif"));
}
public static UIFactory Instance() {
if (fInstance == null) {
fInstance = new UIFactory();
}
return fInstance;
}
ImageIcon getFolderImageIcon(ViewedFolder aFolder,
boolean open,
boolean large) {
ViewedStore store = aFolder.getViewedStore();
if (aFolder == store) {
if (store.getHost() == null) {
return fLocalStoreIcon;
} else {
return fRemoteStoreIcon;
}
} else {
if (store.getProtocol().equals("news")) {
return fNewsgroupIcon;
} else {
if (aFolder.isInbox()) {
return fInboxIcon;
} else {
return fFolderIcon;
}
}
}
}
ImageIcon getFolderOverlayImageIcon(ViewedFolder aFolder,
boolean open,
boolean large) {
ViewedStore store = aFolder.getViewedStore();
if (aFolder == store) {
if (store.isConnected()) {
return fConnectedIcon;
}
}
return null;
}
public Icon getFolderIcon(ViewedFolder aFolder,
boolean open,
boolean large) {
return getFolderImageIcon(aFolder, open, large);
}
public Icon getFolderOverlayIcon(ViewedFolder aFolder,
boolean open,
boolean large) {
return getFolderOverlayImageIcon(aFolder, open, large);
}
public Image getFolderImage(ViewedFolder aFolder,
boolean open,
boolean large) {
return getFolderImageIcon(aFolder, open, large).getImage();
}
}

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

@ -52,7 +52,6 @@ import javax.mail.MessagingException;
import grendel.prefs.base.InvisiblePrefs;
import grendel.prefs.base.UIPrefs;
import grendel.ui.UIAction;
import grendel.view.ViewedMessage;
import grendel.widgets.CollapsiblePanel;
import grendel.widgets.GrendelToolBar;
@ -60,6 +59,8 @@ import grendel.widgets.Spring;
import grendel.widgets.StatusEvent;
import grendel.widgets.TreePath;
import com.trfenv.parsers.Event;
/**
* The legendary three pane UI.
*/
@ -183,8 +184,8 @@ class UnifiedMessageFrame extends GeneralFrame {
layoutPanels(layout);
fMenu = buildMenu("menus.xml",
Util.MergeActions(actions, Util.MergeActions(fFolders.getActions(), Util.MergeActions(fThreads.getActions(), fMessage.getActions()))));
XMLMenuBuilder builder = new XMLMenuBuilder(Util.MergeActions(actions, Util.MergeActions(fFolders.getActions(), Util.MergeActions(fThreads.getActions(), fMessage.getActions()))));
fMenu = builder.buildFrom("ui/menus.xml", this);
getRootPane().setJMenuBar(fMenu);
@ -205,7 +206,7 @@ class UnifiedMessageFrame extends GeneralFrame {
fToolBarPanelConstraints.fill = GridBagConstraints.NONE;
fToolBarPanelConstraints.gridwidth = GridBagConstraints.REMAINDER;
fToolBarPanelConstraints.anchor = GridBagConstraints.EAST;
fToolBarPanel.add(fAnimation, fToolBarPanelConstraints);
fStatusBar = buildStatusBar();
@ -225,7 +226,7 @@ class UnifiedMessageFrame extends GeneralFrame {
fFolders.getSize().width, fFolders.getSize().height,
fThreads.getSize().width, fThreads.getSize().height
);
UIPrefs.GetMaster().setMultiPaneLayout(fLayout);
UIPrefs.GetMaster().writePrefs();
@ -250,7 +251,7 @@ class UnifiedMessageFrame extends GeneralFrame {
if (fLayout.equals(layout)) {
return; // nothing to do
}
fLayout = layout;
remove(splitter1);
remove(splitter2);
@ -275,7 +276,7 @@ class UnifiedMessageFrame extends GeneralFrame {
threadX = tx;
threadY = ty;
// if the try bails, we use default
} catch (NumberFormatException nf_ty) {
} catch (NumberFormatException nf_ty) {
nf_ty.printStackTrace();
} finally {
relayout = true;
@ -299,7 +300,7 @@ class UnifiedMessageFrame extends GeneralFrame {
} else if (layout.equals(UnifiedMessageDisplayManager.SPLIT_LEFT)) {
splitter1.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
splitter2.setOrientation(JSplitPane.VERTICAL_SPLIT);
splitter2.setLeftComponent(fFolders);
splitter2.setRightComponent(fThreads);
@ -321,7 +322,7 @@ class UnifiedMessageFrame extends GeneralFrame {
splitter2.setLeftComponent(fFolders);
splitter2.setRightComponent(fThreads);
splitter1.setTopComponent(splitter2);
splitter1.setBottomComponent(fMessage);
}
@ -345,7 +346,7 @@ class UnifiedMessageFrame extends GeneralFrame {
LayoutAction fStackedLayoutAction =
new LayoutAction(UnifiedMessageDisplayManager.STACKED);
UIAction[] actions = { ActionFactory.GetExitAction(),
Event[] actions = { ActionFactory.GetExitAction(),
ActionFactory.GetNewMailAction(),
ActionFactory.GetComposeMessageAction(),
ActionFactory.GetPreferencesAction(),
@ -473,15 +474,14 @@ class UnifiedMessageFrame extends GeneralFrame {
// LayoutAction class
//
class LayoutAction extends UIAction {
class LayoutAction extends Event {
ImageIcon fIcon;
String action;
public LayoutAction(String aAction) {
super(aAction);
this.setEnabled(true);
action = aAction;
fIcon = new ImageIcon(getClass().getResource("images/" +
aAction + ".gif"));
fIcon = new ImageIcon("ui/images/" + aAction + ".gif");
}
public void actionPerformed(ActionEvent aEvent) {

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 9 Sep 1997.
*
@ -50,9 +50,10 @@ import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import grendel.ui.ToolBarLayout;
import grendel.ui.UIAction;
import grendel.widgets.GrendelToolBar;
import com.trfenv.parsers.Event;
public class Util {
static final boolean DEBUG = false;
public static final int LEFT = 0;
@ -108,9 +109,9 @@ public class Util {
g.drawChars(fChars, first, length, x, y);
}
static UIAction FindAction(Vector aVector, String aAction) {
static Event FindAction(Vector aVector, String aAction) {
for (int i = 0; i < aVector.size(); i++) {
UIAction action = (UIAction)aVector.elementAt(i);
Event action = (Event)aVector.elementAt(i);
if (action.equals(aAction)) {
return action;
}
@ -118,7 +119,7 @@ public class Util {
return null;
}
static public UIAction[] MergeActions(UIAction aActions1[], UIAction aActions2[]) {
static public Event[] MergeActions(Event aActions1[], Event aActions2[]) {
Vector resVector = new Vector();
int i;
if (aActions1 != null) {
@ -133,7 +134,7 @@ public class Util {
}
}
}
UIAction res[] = new UIAction[resVector.size()];
Event res[] = new Event[resVector.size()];
resVector.copyInto(res);
return res;
}
@ -141,7 +142,7 @@ public class Util {
static public GrendelToolBar MergeToolBars(GrendelToolBar aBar1, GrendelToolBar aBar2) {
GrendelToolBar res = new GrendelToolBar();
res.setLayout(new ToolBarLayout());
Component barArray1[] = aBar1.getComponents();
Component barArray2[] = aBar2.getComponents();
int count1 = aBar1.getComponentCount();
@ -193,16 +194,16 @@ public class Util {
{
button2 = (JButton) barArray2[j];
}
if (button2 != null)
if (button2 != null)
{
res.add(button2);
}
j++;
}
return res;
}
public static void RegisterScrollingKeys(JScrollPane aScrollPane) {
aScrollPane.registerKeyboardAction(new ScrollAction(aScrollPane, KeyEvent.VK_UP),
@ -277,7 +278,7 @@ public class Util {
}
}
class ScrollAction extends UIAction {
class ScrollAction extends Event {
JScrollPane fScrollPane;
int fAction;

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

@ -17,303 +17,83 @@
* Copyright (C) 1999 Giao Nguyen. All
* Rights Reserved.
*
* Contributor(s): Morgan Schweers <morgan@vixen.com>
* Contributor(s):
* Morgan Schweers <morgan@vixen.com>
* R.J. Keller <rj.keller@beonex.com>
*/
package grendel.ui;
import java.io.InputStream;
import java.io.IOException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.Hashtable;
import java.util.Properties;
import java.awt.Container;
import java.awt.Font;
import java.util.Map;
import java.util.HashMap;
import javax.swing.JMenuBar;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.ButtonGroup;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Document;
import com.sun.xml.parser.Resolver;
import com.sun.xml.parser.Parser;
import com.sun.xml.tree.XmlDocument;
import com.sun.xml.tree.TreeWalker;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import grendel.widgets.MenuCtrl;
import grendel.widgets.MenuBarCtrl;
import grendel.widgets.Control;
import com.trfenv.parsers.xul.XulParser;
import com.trfenv.parsers.Event;
/**
* Build a menu bar from an XML data source. This builder supports:
* <UL>
* <LI>Text label cross referencing to a properties file.
* <LI>Text label cross referencing to a DTD file.
* <LI>Action lookups.
* </UL>
*/
public class XMLMenuBuilder extends XMLWidgetBuilder {
static final String id_attr = "id";
static final String menu_tag = "menu";
static final String label_attr = "label";
static final String separator_attr = "separator";
static final String menuitem_tag = "menuitem";
static final String checkbox_attr = "checkbox";
static final String radio_attr = "radio";
static final String group_attr = "group";
static final String accel_attr = "accel";
static final String type_attr = "type";
public class XMLMenuBuilder {
private Event[] mListener;
private Element root;
private JMenuBar mMenuBar;
/**
* The button group indexed by its name.
*/
protected Hashtable button_group;
Hashtable actions;
MenuBarCtrl component;
private Map<String, JComponent> mIDs;
/**
* Build a menu builder which operates on XML formatted data
*
* @param ref the reference point for properties location
* @param actionList array of UIAction objects to map to
*
* @param aListener The action listener that contains the events
* for all the tags that will be parsed.
*/
public XMLMenuBuilder(Class ref, UIAction[] actionList) {
button_group = new Hashtable();
actions = new Hashtable();
this.ref = ref;
if (actionList != null) {
for (int i = 0; i < actionList.length; i++) {
actions.put(actionList[i].getName(), actionList[i]);
}
}
}
/**
* Build a menu builder which operates on XML formatted data
*
* @param frame reference point for properties location
* @param actionList array of UIAction objects to map to
*/
public XMLMenuBuilder(JFrame frame, UIAction[] actionList) {
this(frame.getClass(), actionList);
public XMLMenuBuilder(Event[] aListener) {
mListener = aListener;
mIDs = new HashMap<String, JComponent>();
}
/**
* Read the input stream and build a menubar from it
*
* @param stream the stream containing the XML data
*Builds a JMenuBar based on the input stream data.
*
* @param stream The input stream to read the XML data from.
* @param aWindow The parent window of this menubar.
*/
public JComponent buildFrom(InputStream stream) {
XmlDocument doc;
TreeWalker tree;
Node node;
URL linkURL;
Element current;
public JMenuBar buildFrom(String file, JFrame aWindow) {
XulParser parser = new XulParser(mListener, aWindow);
try {
doc = XmlDocument.createXmlDocument(stream, false);
current = doc.getDocumentElement();
tree = new TreeWalker(current);
Document doc = XulParser.makeDocument(file);
root = doc.getDocumentElement();
// get the link tag for this file
node = tree.getNextElement("head").getFirstChild().getNextSibling();
// set the configuration contained in this node
setConfiguration((Element)node);
// skip to the body
buildFrom(tree.getNextElement("body"));
} catch (Throwable t) {
t.printStackTrace();
} finally {
return component;
}
}
public JMenu buildMenu(Element element) {
Node node;
MenuCtrl menu = new MenuCtrl();
String my_id = element.getAttribute(id_attr);
menu.setText(getReferencedLabel(element, label_attr).trim());
menu.setActionCommand(element.getAttribute(id_attr));
node = element.getFirstChild().getNextSibling();
while (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element current = (Element)node;
String tag = current.getTagName();
JComponent comp = buildComponent((Element)node);
menu.add(comp);
}
node = node.getNextSibling();
}
return menu;
}
public JComponent buildFrom(Element element) {
Node node =
element.getFirstChild().getNextSibling().getFirstChild().getNextSibling();
component = new MenuBarCtrl();
while (node != null) {
// if it's an element, we process.
// otherwise, it's probably a closing tag
if (node.getNodeType() == Node.ELEMENT_NODE) {
JMenu menu = buildMenu((Element)node);
component.addItemByName(menu.getActionCommand(), menu);
}
node = node.getNextSibling();
}
return component;
//no, we don't support multiple menu bars. If there are multiple menubars, just take
//the first one.
Element menubarTag = (Element)root.getElementsByTagName("menubar").item(0);
mMenuBar = (JMenuBar)parser.parseTag(null, menubarTag);
mIDs = parser.getIDs();
return mMenuBar;
}
/**
* @return the menubar built by this builder
*Returns a map containing the element ID as a string and the JComponent being
*the component that the ID connects to.
*/
public MenuBarCtrl getComponent() {
return component;
}
public void configureForOwner(JComponent component) {
}
/**
* Build the component at the current XML element and add to the parent
* @param current the current element
*/
protected JComponent buildComponent(Element current) {
String tag = current.getTagName();
JComponent comp = null;
// menu tag
if (tag.equals(menu_tag)) {
comp = buildMenu(current);
} else if (tag.equals(menuitem_tag)) { // menuitem tag
String type = current.getAttribute(type_attr);
// which type of menuitem?
if (type.equals("")) {
// no type ? it's a regular menuitem
comp = buildMenuItem(current);
} else if (type.equals(separator_attr)) { // separator
comp = buildSeparator(current);
} else if (type.equals(checkbox_attr)) { // checkboxes
comp = buildCheckBoxMenuItem(current);
} else if (type.equals(radio_attr)) { // radio
comp = buildRadioMenuItem(current);
}
}
comp.setFont(new Font("Helvetica", Font.PLAIN, 12));
return comp;
}
/**
* Build a JRadioMenuItem
* @param current the element that describes the JRadioMenuItem
* @return the built component
*/
protected JRadioButtonMenuItem buildRadioMenuItem(Element current) {
String group = current.getAttribute(group_attr);
ButtonGroup bg;
JRadioButtonMenuItem comp = new JRadioButtonMenuItem();
finishComponent(comp, current);
// do we add to a button group?
if (button_group.containsKey(group)) {
bg = (ButtonGroup)button_group.get(group);
} else {
bg = new ButtonGroup();
button_group.put(group, bg);
}
bg.add((JRadioButtonMenuItem)comp);
comp.setFont(new Font("Helvetica", Font.PLAIN, 12));
return comp;
}
/**
* Build a JCheckBoxMenuItem.
* @param current the element that describes the JCheckBoxMenuItem
* @return the built component
*/
protected JCheckBoxMenuItem buildCheckBoxMenuItem(Element current) {
JCheckBoxMenuItem item = new JCheckBoxMenuItem();
finishComponent(item, current);
item.setFont(new Font("Helvetica", Font.PLAIN, 12));
return item;
}
/**
* Build a JSeparator.
* @param current the element that describes the JSeparator
* @return the built component
*/
protected JSeparator buildSeparator(Element current) {
return new JSeparator();
}
/**
* Build a JMenuItem.
* @param current the element that describes the JMenuItem
* @return the built component
*/
protected JMenuItem buildMenuItem(Element current) {
JMenuItem item = new JMenuItem();
finishComponent(item, current);
item.setFont(new Font("Helvetica", Font.PLAIN, 12));
return item;
}
private void finishComponent(JMenuItem item, Element current) {
String label = getReferencedLabel(current, label_attr);
UIAction action = null;
if (label.length() > 0) {
item.setText(label);
}
label = current.getAttribute("action");
if ((action = (UIAction)actions.get(label)) != null) {
item.addActionListener(action);
}
label = getReferencedLabel(current, accel_attr);
if (label.length() > 0) {
item.setMnemonic(label.charAt(0));
}
}
public static void main(String[] args) throws Exception {
javax.swing.JFrame frame = new javax.swing.JFrame("Foo bar");
XMLMenuBuilder builder = new XMLMenuBuilder(frame, new UIAction[0]);
URL url = builder.getClass().getResource("menus.xml");
builder.buildFrom(url.openStream());
frame.setJMenuBar((JMenuBar)builder.getComponent());
frame.pack();
frame.setVisible(true);
public Map<String, JComponent> getElementsAndIDs()
{
return mIDs;
}
}

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

@ -1,476 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Giao Nguyen
* <grail@cafebabe.org>. Portions created by Giao Nguyen are
* Copyright (C) 1999 Giao Nguyen. All
* Rights Reserved.
*
* Contributor(s): Morgan Schweers <morgan@vixen.com>
*/
package grendel.ui;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;
import java.awt.Container;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.RootPaneContainer;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import com.sun.xml.parser.Resolver;
import com.sun.xml.parser.Parser;
import com.sun.xml.tree.XmlDocument;
import com.sun.xml.tree.TreeWalker;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/**
* Build a panel from an XML data source.
*/
public class XMLPageBuilder extends XMLWidgetBuilder {
static final String id_attr = "id";
static final String label_attr = "label";
static final String separator_attr = "separator";
static final String radio_attr = "radio";
static final String group_attr = "group";
static final String accel_attr = "accel";
static final String type_attr = "type";
static final String dialog_tag = "dialog";
static final String panel_tag = "panel";
static final String input_tag = "input";
static final String label_tag = "label";
static final String image_tag = "image";
static final String layout_attr = "layout";
PageUI component;
String title;
String id;
String attr;
PageModel model;
Hashtable group = new Hashtable();
/**
* Build a menu builder which operates on XML formatted data
*
* @param attr attribute
* @param id the value of the attribute to have a match
* @param model the page model for the page to be created
*/
public XMLPageBuilder(String attr, String id, PageModel model) {
this.attr = attr;
this.id = id;
this.model = model;
}
/**
* Read the input stream and build a menubar from it
*
* @param stream the stream containing the XML data
*/
public JComponent buildFrom(InputStream stream) {
XmlDocument doc;
TreeWalker tree;
Node node;
URL linkURL;
Element current;
try {
doc = XmlDocument.createXmlDocument(stream, false);
current = doc.getDocumentElement();
tree = new TreeWalker(current);
// get the link tag for this file
// get into head and get the first element
node =
tree.getNextElement("head").getFirstChild().getNextSibling();
// set the configuration contained in this node
setConfiguration((Element)node);
// skip to the body and find the element
current = findTargetElement(tree.getNextElement("body"));
if (current != null) {
component = (PageUI)buildFrom(current);
}
} catch (Throwable t) {
t.printStackTrace();
}
return component;
}
/**
* Locates the element targeted.
* @param element the element that contains all nodes to search
* @return the element matching the target description
*/
private Element findTargetElement(Element element) {
Node node = element.getFirstChild().getNextSibling();
while (node != null) {
// make sure we're looking at an ELEMENT_NODE
if (node.getNodeType() == Node.ELEMENT_NODE) {
element = (Element)node;
// found it
if (element.getAttribute(attr).equals(id)) break;
}
// proceed to the next node in the tree
node = node.getNextSibling();
}
// we didn't find it otherwise we wouldn't be here.
return element;
}
/**
* Build a page from this element.
* @param element figure it out you twit
* @return the component built
*/
public JComponent buildFrom(Element element) {
Node node;
PageUI my_component = buildPanel((Element)element.getFirstChild().getNextSibling());
title = getReferencedLabel(element, "title");
return my_component;
}
/**
* Build a panel.
* @param element the panel element
* @return the panel object as a PageUI type
*/
public PageUI buildPanel(Element element) {
Node node = element.getFirstChild().getNextSibling();
PageUI my_component = new PageUI();
// every pageui in a dialog shares the same model. pageui just
// spec the layout.
my_component.setModel(model);
// in the future, we'll determine what the layout manager is. for now,
// the only one we support is GridBagLayout
my_component.setLayout(new GridBagLayout());
while (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
element = (Element)node;
JComponent child = buildComponent(element);
GridBagConstraints cons = buildConstraints(element);
my_component.addCtrl(element.getAttribute("ID"), child, cons);
}
node = node.getNextSibling();
}
return my_component;
}
private int parseGridConstant(String data) {
int result = 1;
try {
data = data.trim();
result = Integer.parseInt(data);
} catch (NumberFormatException nfe) {
if (data.equals("remainder")) {
result = GridBagConstraints.REMAINDER;
} else if (data.equals("relative")) {
result = GridBagConstraints.RELATIVE;
}
} finally {
return result;
}
}
private int parseFillConstant(String fill) {
int result = GridBagConstraints.NONE;
fill = fill.trim();
if (fill.equals("horizontal")) {
result = GridBagConstraints.HORIZONTAL;
} else if (fill.equals("vertical")) {
result = GridBagConstraints.VERTICAL;
} else if (fill.equals("both")) {
result = GridBagConstraints.BOTH;
}
return result;
}
private float parseWeightConstant(String weight) {
float result = 0.0f;
try {
result = Float.valueOf(weight).floatValue();
} catch (NumberFormatException nfe) {
} finally {
return result;
}
}
/**
* Build a constraint from the element's details.
*
* @param current the XML element containing constraint information.
* @return extracted constraints
*/
protected GridBagConstraints buildConstraints(Element current) {
GridBagConstraints constraints = new GridBagConstraints();
CustomInsets inset =
new CustomInsets(current.getAttribute("insets"));
constraints.weightx =
parseWeightConstant(current.getAttribute("weightx"));
constraints.weighty =
parseWeightConstant(current.getAttribute("weighty"));
// fill
constraints.fill = parseFillConstant(current.getAttribute("fill"));
constraints.gridwidth =
parseGridConstant(current.getAttribute("gridwidth"));
constraints.gridheight =
parseGridConstant(current.getAttribute("gridheight"));
constraints.insets = inset;
return constraints;
}
protected JComponent buildComponent(Element current) {
JComponent item = null;
String tag = current.getTagName();
if (tag.equals(input_tag)) { // input tag
item = buildInput(current);
} else if (tag.equals(label_tag)) {
item = buildLabel(current);
} else if (tag.equals(panel_tag)) {
item = buildPanel(current);
} else if (tag.equals(image_tag)) {
item = buildImage(current);
}
return item;
}
protected JPasswordField buildPasswordField(Element current) {
JPasswordField item = null;
item = new JPasswordField();
textFieldAdjustments(item, current);
return item;
}
private void textFieldAdjustments(JTextField item, Element current) {
String s = current.getAttribute("columns");
s = s.trim();
try {
int column = Integer.parseInt(s);
item.setColumns(column);
} catch (NumberFormatException nfe) {
}
}
protected JTextField buildTextField(Element current) {
JTextField item = new JTextField();
textFieldAdjustments(item, current);
return item;
}
protected JRadioButton buildRadioButton(Element current) {
JRadioButton item = new JRadioButton();
String label = getReferencedLabel(current, "title");
String group_str = current.getAttribute("group");
if (label.length() > 0) {
item.setText(label);
}
// button group matters
if (group_str.length() > 0) {
ButtonGroup bg;
if (group.containsKey(group_str)) {
bg = (ButtonGroup)group.get(group_str);
} else {
bg = new ButtonGroup();
group.put(group_str, bg);
}
bg.add(item);
}
return item;
}
private JComponent buildInput(Element current) {
JComponent item = null;
String type = current.getAttribute("type");
String ID = current.getAttribute("ID");
if (type.equals("radio")) { // radio type
item = buildRadioButton(current);
} else if (type.equals("text")) { // text type
item = buildTextField(current);
} else if (type.equals("password")) {
item = buildPasswordField(current);
} else if (type.equals("button")) { // buttons
item = buildButton(current);
} else if (type.equals("checkbox")) {
item = buildCheckBox(current);
} else if (type.equals("jlist")) {
item = buildList(current);
} else if (type.equals("combobox")) {
item = buildComboBox(current);
}
return item;
}
protected JCheckBox buildCheckBox(Element current) {
return new JCheckBox(getReferencedLabel(current, "title"));
}
protected JButton buildButton(Element current) {
JButton button = new JButton(getReferencedLabel(current, "title"));
button.addActionListener(model);
button.setActionCommand(getReferencedLabel(current, "command"));
return button;
}
protected JList buildList(Element current) {
JList list = new JList();
return list;
}
protected JComboBox buildComboBox(Element current) {
JComboBox combobox = new JComboBox();
return combobox;
}
protected JLabel buildLabel(Element current) {
JLabel label = new JLabel(getReferencedLabel(current, "title"));
return label;
}
protected JLabel buildImage(Element current) {
URL iconURL = ref.getResource(getReferencedLabel(current, "href"));
JLabel label = new JLabel(new ImageIcon(iconURL));
return label;
}
public JPanel getComponent() {
return component;
}
public String getTitle() {
return title;
}
public static void main(String[] args) throws Exception {
javax.swing.JFrame frame = new javax.swing.JFrame("Foo bar");
PageModel model = new PageModel();
XMLPageBuilder builder = new XMLPageBuilder(args[0], args[1], model);
URL url = builder.getClass().getResource("dialogs.xml");
builder.buildFrom(url.openStream());
JPanel panel = builder.getComponent();
JDialog dialog = new JDialog();
dialog.getContentPane().setLayout(new java.awt.GridBagLayout());
dialog.getContentPane().add(panel, null);
dialog.setTitle(builder.getTitle());
dialog.pack();
dialog.setVisible(true);
}
}
class CustomInsets extends Insets {
CustomInsets(String inset) {
super(0, 0, 0, 0);
inset = inset.trim();
if (inset != null && inset.length() >= 9
&& (inset.charAt(0) == '['
|| inset.charAt(inset.length() - 1) == ']')) {
inset = inset.substring(1, inset.length() - 1);
int[] val = parseInset(inset); // guaranteed to be a length of 4
top = val[0];
left = val[1];
bottom = val[2];
right = val[3];
}
}
private int[] parseInset(String inset) {
// if all else fails, it's 0
int[] val = { 0, 0, 0, 0 };
StringTokenizer tok = new StringTokenizer(inset, ",");
// assign the values into
for (int i = 0; i < val.length; i++) {
try {
String s = tok.nextToken();
val[i] = Integer.parseInt(s);
} catch (NoSuchElementException nse) {
// ignore. if it's fubared, we use 0 as the value
} catch (NumberFormatException nfe) {
// ignore. if it's fubared, we use 0 as the value
}
}
return val;
}
}

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

@ -1,136 +1,89 @@
<?xml version="1.0"?>
<xml>
<head>
<link role="stringprops" href="MenuLabels.properties"/>
</head>
<body>
<!DOCTYPE window [
<!ENTITY % menuLabelsDTD SYSTEM "MenuLabels.dtd" >
%menuLabelsDTD;
]>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<keyset><!--
<key modifiers="accel" key="&folderNewAccel;" oncommand="msgNew"/>
--></keyset>
<menubar id="mail.multi_pane">
<menu id="FileMenu" category="file"
label="$multiFileLabel" accel="F">
<menuitem id="msgNew" category="file" action="msgNew"
label="$msgNewLabel" accel="$msgNewAccel"
description=""/>
<menuitem id="folderNew" category="file" action="folderNew"
label="$folderNewLabel" accel="$folderNewAccel"
description=""/>
<menuitem id="msgOpen" category="file" action="msgOpen"
label="$msgOpenLabel" accel="$msgOpenAccel"
description=""/>
<menuitem id="msgSaveAs" category="file" action="msgSaveAs"
label="$msgSaveAsLabel" accel="$msgSaveAsAccel"
description=""/>
<menuitem type="separator"/>
<menuitem id="msgGetNew" category="file" action="msgGetNew"
label="$msgGetNewLabel" accel="$msgGetNewAccel"
description=""/>
<menuitem type="separator"/>
<menuitem id="appExit" category="quit" action="appExit"
label="$appExitLabel" accel="$appExitAccel"
description=""/>
<menu id="FileMenu" label="&multiFileLabel;" accesskey="&multiFileAccel;">
<menupopup>
<menuitem id="msgNew" onclick="msgNew" label="&msgNewLabel;" accesskey="&msgNewAccel;"/>
<menuitem id="folderNew" onclick="folderNew" label="&folderNewLabel;" accesskey="&folderNewAccel;"/>
<menuitem id="msgOpen" onclick="msgOpen" label="&msgOpenLabel;" accesskey="&msgOpenAccel;"/>
<menuitem id="msgSaveAs" onclick="msgSaveAs" label="&msgSaveAsLabel;" accesskey="&msgSaveAsAccel;"/>
<menuseparator/>
<menuitem id="msgGetNew" onclick="msgGetNew" label="&msgGetNewLabel;" accesskey="&msgGetNewAccel;"/>
<menuseparator/>
<menuitem id="appExit" onclick="appExit" label="&appExitLabel;" accesskey="&appExitAccel;"/>
</menupopup>
</menu>
<menu id="EditMenu" category="edit"
label="$multiEditLabel" accel="$multiEditAccel">
<menuitem id="editUndo" category="edit" action="editUndo"
label="$editUndoLabel" accel="$editUndoAccel"
description=""/>
<menuitem id="editCut" category="edit" action="editCut"
label="$editCutLabel" accel="$editCutAccel"
description=""/>
<menuitem id="editCopy" category="edit" action="editCopy"
label="$editCopyLabel" accel="$editCopyAccel"
description=""/>
<menuitem id="editPaste" category="edit" action="editPaste"
label="$editPasteLabel" accel="$editPasteAccel"
description=""/>
<menuitem type="separator"/>
<menuitem id="folderDelete" category="edit" action="folderDelete"
label="$folderDeleteLabel" accel="$folderDeleteAccel"
description=""/>
<menuitem type="separator"/>
<menuitem id="appSearch" category="edit" action="appSearch"
label="$appSearchLabel" accel="$appSearchAccel"
description=""/>
<menuitem id="appRunFilters" category="edit" action="appRunFilters"
label="$appRunFiltersLabel" accel="$appRunFiltersAccel"
description=""/>
<menu id="EditMenu" label="&multiEditLabel;" accesskey="&multiEditAccel;">
<menupopup>
<menuitem id="editUndo" onclick="editUndo" label="&editUndoLabel;" accesskey="&editUndoAccel;"/>
<menuitem id="editCut" onclick="editCut" label="&editCutLabel;" accesskey="&editCutAccel;"/>
<menuitem id="editCopy" onclick="editCopy" label="&editCopyLabel;" accesskey="&editCopyAccel;"/>
<menuitem id="editPaste" onclick="editPaste" label="&editPasteLabel;" accesskey="&editPasteAccel;"/>
<menuseparator/>
<menuitem id="folderDelete" onclick="folderDelete" label="&folderDeleteLabel;" accesskey="&folderDeleteAccel;"/>
<menuseparator/>
<menuitem id="appSearch" onclick="appSearch" label="&appSearchLabel;" accesskey="&appSearchAccel;"/>
<menuitem id="appRunFilters" onclick="appRunFilters" label="&appRunFiltersLabel;" accesskey="&appRunFiltersAccel;"/>
</menupopup>
</menu>
<menu id="ViewMenu" category="view"
label="$multiViewLabel" accel="$multiViewAccel">
<menu id="SortMenu" category="view"
label="$viewSortLabel" accel="$viewSortAccel">
<menuitem id="toggleThreading" category="view" action="toggleThreading"
type="checkbox"
label="$toggleThreadingLabel" accel="$toggleThreadingAccel"
description=""/>
<menuitem type="separator"/>
<menuitem id="sortAuthor" category="view" action="sortAuthor"
type="radio" group="sort"
label="$sortAuthorLabel" accel="$sortAuthorAccel"
description=""/>
<menuitem id="sortDate" category="view" action="sortDate"
type="radio" group="sort"
label="$sortDateLabel" accel="$sortDateAccel"
description=""/>
<menuitem id="sortNumber" category="view" action="sortNumber"
type="radio" group="sort"
label="$sortNumberLabel" accel="$sortNumberAccel"
description=""/>
<menuitem id="sortSubject" category="view" action="sortSubject"
type="radio" group="sort"
label="$sortSubjectLabel" accel="$sortSubjectAccel"
description=""/>
</menu>
<menu id="ViewMenu" label="&multiViewLabel;" accesskey="&multiViewAccel;">
<menupopup>
<menu id="SortMenu" label="&viewSortLabel;" accesskey="&viewSortAccel;">
<menupopup>
<menuitem id="toggleThreading" onclick="toggleThreading" label="&toggleThreadingLabel;" accesskey="&toggleThreadingAccel;"/>
<menuseparator/>
<menuitem id="sortAuthor" onclick="sortAuthor" label="&sortAuthorLabel;" accesskey="&sortAuthorAccel;"/>
<menuitem id="sortDate" onclick="sortDate" label="&sortDateLabel;" accesskey="&sortDateAccel;"/>
<menuitem id="sortNumber" onclick="sortNumber" label="&sortNumberLabel;" accesskey="&sortNumberAccel;"/>
<menuitem id="sortSubject" onclick="sortSubject" label="&sortSubjectLabel;" accesskey="&sortSubjectAccel;"/>
</menupopup>
</menu>
</menupopup>
</menu>
<menu id="MessageMenu" category="message"
label="$multiMessageLabel" accel="$multiMessageAccel">
<menuitem id="msgNew" category="message" action="msgNew"
label="$msgNewLabel" accel="$msgNewAccel"
description=""/>
<menuitem type="separator"/>
<menuitem id="msgReply" category="message" action="msgReply"
label="$msgReplyLabel" accel="$msgReplyAccel"
description=""/>
<menuitem id="msgReplyAll" category="message" action="msgReplyAll"
label="$msgReplyAllLabel" accel="$msgReplyAllAccel"
description=""/>
<menuitem id="fwdQuoted" category="message" action="fwdQuoted"
label="$fwdQuotedLabel" accel="$fwdQuotedAccel"
description=""/>
<menuitem id="fwdInline" category="message" action="fwdInline"
label="$fwdInlineLabel" accel="$fwdInlineAccel"
description=""/>
<menuitem id="fwdAttachment" category="message" action="fwdAttachment"
label="$fwdAttachmentLabel" accel="$fwdAttachmentAccel"
description=""/>
<menuitem type="separator"/>
<menu id="msgMark" category="message"
label="$msgMarkLabel" accel="$msgMarkAccel">
<menuitem id="markMsgRead" category="message" action="markMsgRead"
label="$markMsgReadLabel" accel="$markMsgReadAccel"
description=""/>
<menuitem id="markThreadRead" category="message" action="markThreadRead"
label="$markThreadReadLabel" accel="$markThreadReadAccel"
description=""/>
<menuitem id="markAllRead" category="message" action="markAllRead"
label="$markAllReadLabel" accel="$markAllReadAccel"
description=""/>
</menu>
<menu id="MessageMenu" label="&multiMessageLabel;" accesskey="&multiMessageAccel;">
<menupopup>
<menuitem id="msgNew" onclick="msgNew" label="&msgNewLabel;" accesskey="&msgNewAccel;"/>
<menuseparator/>
<menuitem id="msgReply" onclick="msgReply" label="&msgReplyLabel;" accesskey="&msgReplyAccel;"/>
<menuitem id="msgReplyAll" onclick="msgReplyAll" label="&msgReplyAllLabel;" accesskey="&msgReplyAllAccel;"/>
<menuitem id="fwdQuoted" onclick="fwdQuoted" label="&fwdQuotedLabel;" accesskey="&fwdQuotedAccel;"/>
<menuitem id="fwdInline" onclick="fwdInline" label="&fwdInlineLabel;" accesskey="&fwdInlineAccel;"/>
<menuitem id="fwdAttachment" onclick="fwdAttachment" label="&fwdAttachmentLabel;" accesskey="&fwdAttachmentAccel;"/>
<menuseparator/>
<menu id="msgMark" label="&msgMarkLabel;" accesskey="&msgMarkAccel;">
<menupopup>
<menuitem id="markMsgRead" onclick="markMsgRead" label="&markMsgReadLabel;" accesskey="&markMsgReadAccel;"/>
<menuitem id="markThreadRead" onclick="markThreadRead" label="&markThreadReadLabel;" accesskey="&markThreadReadAccel;"/>
<menuitem id="markAllRead" onclick="markAllRead" label="&markAllReadLabel;" accesskey="&markAllReadAccel;"/>
</menupopup>
</menu>
</menupopup>
</menu>
<menu id="PrefsMenu" category="prefs"
label="$multiPrefsLabel" accel="$multiPrefsAccel">
<menuitem id="prefGeneral" category="prefs" action="prefGeneral"
label="$prefGeneralLabel" accel="$prefGeneralAccel"
description=""/>
<menuitem id="prefIds" category="prefs" action="prefIds"
label="$prefIdsLabel" accel="$prefIdsAccel"
description=""/>
<menuitem id="prefSrvs" category="prefs" action="prefSrvs"
label="$prefSrvsLabel" accel="$prefSrvsAccel"
description=""/>
<menuitem id="prefUI" category="prefs" action="prefUI"
label="$prefUILabel" accel="$prefUIAccel"
description=""/>
<menu id="PrefsMenu" label="&multiPrefsLabel;" accesskey="&multiPrefsAccel;">
<menupopup>
<menuitem id="prefGeneral" onclick="prefGeneral" label="&prefGeneralLabel;" accesskey="&prefGeneralAccel;"/>
<menuitem id="prefIds" onclick="prefIds" label="&prefIdsLabel;" accesskey="&prefIdsAccel;"/>
<menuitem id="prefSrvs" onclick="prefSrvs" label="&prefSrvsLabel;" accesskey="&prefSrvsAccel;"/>
<menuitem id="prefUI" onclick="prefUI" label="&prefUILabel;" accesskey="&prefUIAccel;"/>
</menupopup>
</menu>
</menubar>
</body>
</xml>
</window>

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

@ -1 +1 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is the Grendel mail/news client. * * The Initial Developer of the Original Code is Netscape Communications * Corporation. Portions created by Netscape are * Copyright (C) 1997 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): Brandon Wiley * * Created: Brandon Wiley */ package grendel.view; import java.util.*; public class EnumerationIterator implements Iterator { Enumeration enum; */ .nextElement();} public void remove() {} }
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is the Grendel mail/news client. * * The Initial Developer of the Original Code is Netscape Communications * Corporation. Portions created by Netscape are * Copyright (C) 1997 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): Brandon Wiley * * Created: Brandon Wiley */ package grendel.view; import java.util.*; public class EnumerationIterator implements Iterator { Enumeration enumer; import java.util.*; public class EnumerationIterator implements Iterator { .nextElement();} public void remove() {} }

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

@ -1,514 +0,0 @@
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* Created: Jamie Zawinski <jwz@netscape.com>, 13 Jun 1995.
* Ported from C on 14 Aug 1997.
*/
/** Test harness for Threader and Sorter.
@see Threader
@see Sorter
*/
package grendel.view;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import java.util.Date;
import calypso.util.ByteBuf;
import calypso.util.ArrayEnumeration;
import calypso.util.QSort;
import calypso.util.Comparer;
import calypso.util.NetworkDate;
class TestMessageThread implements IThreadable, ISortable {
TestMessageThread next;
TestMessageThread kid;
String subject;
String author;
long date;
Object id;
Object[] refs;
int message_number;
private String subject2;
private boolean has_re;
TestMessageThread() {
subject = null; // this means "dummy".
}
public TestMessageThread (TestMessageThread next, String subject, Object id,
Object references[]) {
this.next = next;
this.subject = subject;
this.id = id;
this.refs = references;
}
public String toString() {
if (isDummy())
return "[dummy]";
String s = "[ " + id + ": " + subject + " (";
if (refs != null)
for (int i = 0; i < refs.length; i++)
s += " " + refs[i];
if (date > 0)
s += " \"" + new Date(date) + "\"";
return s + " ) ]";
}
void simplifySubject() {
int start = 0;
int L = subject.length();
boolean done = false;
while (!done) {
done = true;
// skip whitespace.
while (subject.charAt(start) <= ' ')
start++;
if (start < (L-2) &&
(subject.charAt(start) == 'r' || subject.charAt(start) == 'R') &&
(subject.charAt(start+1) == 'e' || subject.charAt(start+1) == 'e')) {
if (subject.charAt(start+2) == ':') {
start += 3; // Skip over "Re:"
has_re = true; // yes, we found it.
done = false; // keep going.
done = false;
} else if (start < (L-2) &&
(subject.charAt(start+2) == '[' ||
subject.charAt(start+2) == '(')) {
int i = start+3; // skip over "Re[" or "Re("
// Skip forward over digits after the "[" or "(".
while (i < L &&
subject.charAt(i) >= '0' &&
subject.charAt(i) <= '9')
i++;
// Now ensure that the following thing is "]:" or "):"
// Only if it is do we alter `start'.
if (i < (L-1) &&
(subject.charAt(i) == ']' ||
subject.charAt(i) == ')') &&
subject.charAt(i+1) == ':') {
start = i+2; // Skip over "]:"
has_re = true; // yes, we found it.
done = false; // keep going.
}
}
}
if (subject2 == "(no subject)") // #### i18n
subject2 = "";
}
int end = L;
// Strip trailing whitespace.
while (end > start && subject.charAt(end-1) < ' ')
end--;
if (start == 0 && end == L)
subject2 = subject;
else
subject2 = subject.substring(start, end);
}
void flushSubjectCache() {
subject2 = null;
}
// for IThreadable
public synchronized Enumeration allElements() {
return new TestMessageThreadEnumeration(this, true);
}
public Object messageThreadID() {
return id;
}
public Object[] messageThreadReferences() {
return refs;
}
public String simplifiedSubject() {
if (subject2 == null) simplifySubject();
return subject2;
}
public boolean subjectIsReply() {
if (subject2 == null) simplifySubject();
return has_re;
}
// Used by both IThreadable and ISortable
public void setNext (Object next) {
this.next = (TestMessageThread) next;
flushSubjectCache();
}
// Used by both IThreadable and ISortable
public void setChild (Object kid) {
this.kid = (TestMessageThread) kid;
flushSubjectCache();
}
public IThreadable makeDummy() {
return (IThreadable) new TestMessageThread();
}
public boolean isDummy() {
return (subject == null);
}
// For ISortable
public synchronized Enumeration children() {
return new TestMessageThreadEnumeration(this, false);
}
}
class TestMessageThreadEnumeration implements Enumeration {
TestMessageThread tail;
Enumeration kids;
boolean recursive_p;
TestMessageThreadEnumeration(TestMessageThread thread, boolean recursive_p) {
this.recursive_p = recursive_p;
if (recursive_p)
tail = thread;
else
tail = thread.kid;
}
public synchronized Object nextElement() {
if (kids != null) {
// if `kids' is non-null, then we've already returned a node,
// and we should now go to work on its children.
TestMessageThread result = (TestMessageThread) kids.nextElement();
if (!kids.hasMoreElements())
kids = null;
return result;
} else if (tail != null) {
// Return `tail', but first note its children, if any.
// We will descend into them the next time around.
TestMessageThread result = tail;
if (recursive_p && tail.kid != null)
kids = new TestMessageThreadEnumeration(tail.kid, true);
tail = tail.next;
return result;
} else {
throw new NoSuchElementException();
}
}
public synchronized boolean hasMoreElements() {
if (tail != null)
return true;
else if (kids != null && kids.hasMoreElements())
return true;
else
return false;
}
}
class TestThreader {
private static TestMessageThread first, last;
private static int count = 0;
private static final int SORT_NUMBER = 0;
private static final int SORT_DATE = 1;
private static final int SORT_SUBJECT = 2;
private static final int SORT_AUTHOR = 3;
private static void make_thread(String subject, String id, String refs) {
TestMessageThread thread = new TestMessageThread();
thread.subject = subject;
thread.id = id;
thread.message_number = ++count;
if (refs != null) {
StringTokenizer st = new StringTokenizer(refs);
Vector v = new Vector(5);
while (st.hasMoreTokens())
v.addElement(st.nextToken());
thread.refs = new Object[v.size()];
for (int i = 0; i < v.size(); i++)
thread.refs[i] = (String) v.elementAt(i);
}
if (first == null)
first = thread;
else
last.next = thread;
last = thread;
}
private static void make_thread2(String subject, String id, String date,
String refs) {
TestMessageThread thread = new TestMessageThread();
thread.subject = subject;
thread.id = id;
thread.date = NetworkDate.parseLong(new ByteBuf(date), false);
thread.message_number = ++count;
if (refs != null) {
StringTokenizer st = new StringTokenizer(refs);
Vector v = new Vector(5);
while (st.hasMoreTokens())
v.addElement(st.nextToken());
thread.refs = new Object[v.size()];
for (int i = 0; i < v.size(); i++)
thread.refs[i] = (String) v.elementAt(i);
}
if (first == null)
first = thread;
else
last.next = thread;
last = thread;
}
public static void main(String[] args) {
int sort_type = SORT_NUMBER;
make_thread("A", "1", null);
make_thread("B", "2", "1");
make_thread("C", "3", "1 2");
make_thread("D", "4", "1");
make_thread("E", "5", "3 x1 x2 x3");
make_thread("F", "6", "2");
make_thread("G", "7", "nonesuch");
make_thread("H", "8", "nonesuch");
make_thread("Loop1", "loop1", "loop2 loop3");
make_thread("Loop2", "loop2", "loop3 loop1");
make_thread("Loop3", "loop3", "loop1 loop2");
make_thread("Loop4", "loop4", "loop5");
make_thread("Loop5", "loop5", "loop4");
make_thread("Loop6", "loop6", "loop6");
make_thread("Loop7", "loop7", "loop8 loop9 loop10 loop8 loop9 loop10");
make_thread("Loop8", "loop8", "loop9 loop10 loop7 loop9 loop10 loop7");
make_thread("Loop8", "loop9", "loop10 loop7 loop8 loop10 loop7 loop8");
make_thread("Loop10", "loop10","loop7 loop8 loop9 loop7 loop8 loop9");
make_thread("Ambig1", "ambig1", null);
make_thread("Ambig2", "ambig2", "ambig1");
make_thread("Ambig3", "ambig3", "ambig1 ambig2");
make_thread("Ambig4", "ambig4", "ambig1 ambig2 ambig3");
make_thread("Ambig5a", "ambig5a", "ambig1 ambig2 ambig3 ambig4");
make_thread("Ambig5b", "ambig5b", "ambig1 ambig3 ambig2 ambig4");
make_thread("dup", "dup", null);
make_thread("dup-kid", "dup-kid", "dup");
make_thread("dup-kid", "dup-kid", "dup");
make_thread("dup-kid-2", "dup-kid-2", "dup");
make_thread("dup-kid-2", "dup-kid-2", "dup");
make_thread("dup-kid-2", "dup-kid-2", "dup");
make_thread("same subject 1", "ss1.1", null);
make_thread("same subject 1", "ss1.2", null);
make_thread("missingmessage", "missa", null);
make_thread("missingmessage", "missc", "missa missb");
make_thread2("liar 1", "<liar.1>", "", "<liar.a> <liar.c>");
make_thread2("liar 2", "<liar.2>", "", "<liar.a> <liar.b> <liar.c>");
make_thread2("liar2 1", "<liar2.1>", "", "<liar2.a> <liar2.b> <liar2.c>");
make_thread2("liar2 2", "<liar2.2>", "", "<liar2.a> <liar2.c>");
make_thread2("xx",
"<331F7D61.2781@netscape.com>",
"Thu, 06 Mar 1997 18:28:50 -0800",
null);
make_thread2("lkjhlkjh",
"<3321E51F.41C6@netscape.com>",
"Sat, 08 Mar 1997 14:15:59 -0800",
null);
make_thread2("test 2",
"<3321E5A6.41C6@netscape.com>",
"Sat, 08 Mar 1997 14:18:14 -0800",
null);
make_thread2("enc",
"<3321E5C0.167E@netscape.com>",
"Sat, 08 Mar 1997 14:18:40 -0800",
null);
make_thread2("lkjhlkjh",
"<3321E715.15FB@netscape.com>",
"Sat, 08 Mar 1997 14:24:21 -0800",
null);
make_thread2("eng",
"<3321E7A4.59E2@netscape.com>",
"Sat, 08 Mar 1997 14:26:44 -0800",
null);
make_thread2("lkjhl",
"<3321E7BB.1CFB@netscape.com>",
"Sat, 08 Mar 1997 14:27:07 -0800",
null);
make_thread2("Re: certs and signed messages",
"<332230AA.41C6@netscape.com>",
"Sat, 08 Mar 1997 19:38:18 -0800",
"<33222A5E.ED4@netscape.com>");
make_thread2("from dogbert",
"<3323546E.BEE44C78@netscape.com>",
"Sun, 09 Mar 1997 16:23:10 -0800",
null);
make_thread2("lkjhlkjhl",
"<33321E2A.1C849A20@netscape.com>",
"Thu, 20 Mar 1997 21:35:38 -0800",
null);
make_thread2("le:/u/jwz/mime/smi",
"<33323C9D.ADA4BCBA@netscape.com>",
"Thu, 20 Mar 1997 23:45:33 -0800",
null);
make_thread2("ile:/u/jwz",
"<33323F62.402C573B@netscape.com>",
"Thu, 20 Mar 1997 23:57:22 -0800",
null);
make_thread2("ljkljhlkjhl",
"<336FBAD0.864BC1F4@netscape.com>",
"Tue, 06 May 1997 16:12:16 -0700",
null);
make_thread2("lkjh",
"<336FBB46.A0028A6D@netscape.com>",
"Tue, 06 May 1997 16:14:14 -0700",
null);
make_thread2("foo",
"<337265C1.5C758C77@netscape.com>",
"Thu, 08 May 1997 16:46:09 -0700",
null);
make_thread2("Welcome to Netscape",
"<337AAB3D.C8BCE069@netscape.com>",
"Wed, 14 May 1997 23:20:45 -0700",
null);
make_thread2("Re: Welcome to Netscape",
"<337AAE46.903032E4@netscape.com>",
"Wed, 14 May 1997 23:33:45 -0700",
"<337AAB3D.C8BCE069@netscape.com>");
make_thread2("[Fwd: enc/signed test 1]",
"<338B6EE2.BB26C74C@netscape.com>",
"Tue, 27 May 1997 16:31:46 -0700",
null);
Threader t = new Threader();
last = null;
first = (TestMessageThread) t.thread (first);
System.out.print("\n------- threaded:\n\n");
printThread(first, 0);
// System.out.print("\n------- pass 2\n\n");
// t = new Threader();
// first = (TestMessageThread) t.thread (first);
// printThread(first, 0);
// System.out.print("\n------- pass 3\n\n");
// t = new Threader();
// first = (TestMessageThread) t.thread (first);
// printThread(first, 0);
Comparer comparer;
if (sort_type == SORT_DATE) {
comparer = new Comparer() {
public int compare(Object oa, Object ob) {
TestMessageThread ta = (TestMessageThread) oa;
TestMessageThread tb = (TestMessageThread) ob;
TestMessageThread a = (ta.subject == null ? ta.kid : ta);
TestMessageThread b = (tb.subject == null ? tb.kid : tb);
if (a.date == b.date) return 0;
else if (a.date < b.date) return -1;
else return 1;
}
};
} else if (sort_type == SORT_SUBJECT) {
comparer = new Comparer() {
public int compare(Object oa, Object ob) {
TestMessageThread ta = (TestMessageThread) oa;
TestMessageThread tb = (TestMessageThread) ob;
TestMessageThread a = (ta.subject == null ? ta.kid : ta);
TestMessageThread b = (tb.subject == null ? tb.kid : tb);
return a.simplifiedSubject().compareTo(b.simplifiedSubject());
}
};
} else if (sort_type == SORT_AUTHOR) {
comparer = new Comparer() {
public int compare(Object oa, Object ob) {
TestMessageThread ta = (TestMessageThread) oa;
TestMessageThread tb = (TestMessageThread) ob;
TestMessageThread a = (ta.subject == null ? ta.kid : ta);
TestMessageThread b = (tb.subject == null ? tb.kid : tb);
return a.author.compareTo(b.author);
}
};
} else { // (sort_type == SORT_NUMBER)
comparer = new Comparer() {
public int compare(Object oa, Object ob) {
TestMessageThread ta = (TestMessageThread) oa;
TestMessageThread tb = (TestMessageThread) ob;
TestMessageThread a = (ta.subject == null ? ta.kid : ta);
TestMessageThread b = (tb.subject == null ? tb.kid : tb);
if (a.message_number == b.message_number) return 0;
else if (a.message_number < b.message_number) return -1;
else return 1;
}
};
}
Sorter s = new Sorter(comparer);
TestMessageThread dummy = new TestMessageThread();
dummy.kid = first;
s.sortMessageChildren(dummy);
first = dummy.kid;
dummy = null;
System.out.print("\n------- sorted:\n\n");
printThread(first, 0);
}
private static void printThread(TestMessageThread thread, int depth) {
for (int i = 0; i < depth; i++) System.out.print(" ");
System.out.println(thread.toString());
if (thread.kid != null) printThread(thread.kid, depth+1);
if (thread.next != null) printThread(thread.next, depth);
}
}

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

@ -17,7 +17,7 @@
* Copyright (C) 1997 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
*
* Created: Will Scullin <scullin@netscape.com>, 23 Oct 1997.
*/
@ -105,8 +105,8 @@ public class Animation extends Component implements Runnable
for (int i = 0; i < iFrames; i++)
{
Integer arg[] = { new Integer(i) };
String name = MessageFormat.format(template, arg);
fGlyphs[i] = new ImageIcon(getClass().getResource(name));
String name = MessageFormat.format(template, arg, null);
fGlyphs[i] = new ImageIcon(name);
}
}

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

@ -12,7 +12,7 @@
*
* The Original Code is the Grendel mail/news client.
*
* The Initial Developer of the Original Code is Jeff Galyan
* The Initial Developer of the Original Code is Jeff Galyan
* <talisman@anamorphic.com>. Portions created by Jeff Galyan are
* Copyright (C) 1997 Jeff Galyan. All
* Rights Reserved.
@ -35,14 +35,14 @@ import javax.swing.JToolBar;
import javax.swing.JButton;
import grendel.ui.ToolBarLayout;
import grendel.ui.UIAction;
import grendel.widgets.Animation;
import grendel.widgets.Spring;
import grendel.widgets.ToolBarButton;
import com.trfenv.parsers.Event;
public class GrendelToolBar extends JToolBar {
private ToolBarLayout layout;
public GrendelToolBar() {
@ -50,17 +50,19 @@ public class GrendelToolBar extends JToolBar {
layout = new ToolBarLayout();
setLayout(layout);
setFloatable(false);
setBackground(new java.awt.Color(238,238,238));
}
public Spring makeNewSpring() {
return layout.createSpring();
}
public void addButton(UIAction aActionListener,
public void addButton(Event aActionListener,
String aImageName,
String aText,
String aToolTip) {
ToolBarButton b = new ToolBarButton();
JButton b = new JButton();
b.setHorizontalTextPosition(JButton.CENTER);
b.setVerticalTextPosition(JButton.BOTTOM);
@ -72,9 +74,8 @@ public class GrendelToolBar extends JToolBar {
b.setRolloverEnabled(true);
b.setBorder(BorderFactory.createEmptyBorder());
b.setToolTipText(aToolTip);
URL iconUrl = getClass().getResource("toolbar/mozilla/" + aImageName + ".gif");
b.setIcon(new ImageIcon(iconUrl));
b.setIcon(new ImageIcon("widgets/toolbar/mozilla/" + aImageName + ".gif"));
Dimension d=b.getPreferredSize();
double w=d.getWidth();

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

@ -1170,8 +1170,8 @@ public class TreeTable extends JComponent implements Scrollable,
public void updateUI() {
super.updateUI();
fPlusIcon = new ImageIcon(getClass().getResource("images/plus.gif"));
fMinusIcon = new ImageIcon(getClass().getResource("images/minus.gif"));
fPlusIcon = new ImageIcon("widgets/images/plus.gif");
fMinusIcon = new ImageIcon("widgets/images/minus.gif");
fWindowColor = UIManager.getColor("window");
fHighlightColor = UIManager.getColor("textHighlight");