1998-09-09 00:52:38 +00:00
|
|
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-02 01:51:54 +00:00
|
|
|
* 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/
|
1998-09-09 00:52:38 +00:00
|
|
|
*
|
1999-11-02 01:51:54 +00:00
|
|
|
* 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.
|
1998-09-09 00:52:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is the Grendel mail/news client.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-02 01:51:54 +00:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1997 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-09-09 00:52:38 +00:00
|
|
|
*
|
|
|
|
* Created: Will Scullin <scullin@netscape.com>, 3 Sep 1997.
|
1999-03-07 19:58:40 +00:00
|
|
|
*
|
|
|
|
* Contributors: Jeff Galyan <talisman@anamorphic.com>
|
|
|
|
* Giao Nguyen <grail@cafebabe.org>
|
1999-05-15 22:42:27 +00:00
|
|
|
* Mauro Botelho <mabotelh@bellsouth.net>
|
1999-06-15 11:44:40 +00:00
|
|
|
* Edwin Woudt <edwin@woudt.nl>
|
1998-09-09 00:52:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package grendel.ui;
|
|
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
|
import java.awt.Component;
|
|
|
|
import java.awt.Container;
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.Font;
|
1999-01-10 21:48:15 +00:00
|
|
|
import java.awt.GridBagConstraints;
|
|
|
|
import java.awt.GridBagLayout;
|
1998-09-09 00:52:38 +00:00
|
|
|
import java.awt.Insets;
|
|
|
|
import java.awt.Rectangle;
|
|
|
|
import java.awt.event.WindowAdapter;
|
|
|
|
import java.awt.event.WindowEvent;
|
|
|
|
import java.beans.PropertyChangeEvent;
|
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.Enumeration;
|
|
|
|
import java.util.Hashtable;
|
|
|
|
import java.util.MissingResourceException;
|
1999-01-11 07:01:27 +00:00
|
|
|
import java.util.Properties;
|
1998-09-09 00:52:38 +00:00
|
|
|
import java.util.ResourceBundle;
|
|
|
|
import java.util.StringTokenizer;
|
|
|
|
import java.util.Vector;
|
|
|
|
|
1999-01-09 03:55:32 +00:00
|
|
|
import javax.swing.Action;
|
1999-01-11 07:01:27 +00:00
|
|
|
import javax.swing.ButtonGroup;
|
1999-01-09 03:55:32 +00:00
|
|
|
import javax.swing.Icon;
|
|
|
|
import javax.swing.ImageIcon;
|
|
|
|
import javax.swing.JButton;
|
1999-01-11 07:01:27 +00:00
|
|
|
import javax.swing.JComponent;
|
1999-01-09 03:55:32 +00:00
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
import javax.swing.JMenuBar;
|
1999-01-16 05:24:25 +00:00
|
|
|
/*
|
1999-01-09 03:55:32 +00:00
|
|
|
import javax.swing.JMenu;
|
|
|
|
import javax.swing.JMenuItem;
|
|
|
|
import javax.swing.JCheckBoxMenuItem;
|
|
|
|
import javax.swing.JRadioButtonMenuItem;
|
1999-01-16 05:24:25 +00:00
|
|
|
import javax.swing.JSeparator;
|
|
|
|
*/
|
1999-01-09 03:55:32 +00:00
|
|
|
import javax.swing.JOptionPane;
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
import javax.swing.JToolBar;
|
|
|
|
import javax.swing.SwingUtilities;
|
1999-01-11 07:01:27 +00:00
|
|
|
import javax.swing.SwingConstants;
|
1999-01-09 03:55:32 +00:00
|
|
|
import javax.swing.UIManager;
|
|
|
|
import javax.swing.BoxLayout;
|
|
|
|
|
|
|
|
//import netscape.orion.toolbars.BarLayout;
|
|
|
|
//import netscape.orion.toolbars.CollapsibleToolbarPanel;
|
|
|
|
//import netscape.orion.toolbars.NSButton;
|
|
|
|
//import netscape.orion.toolbars.NSToolbar;
|
|
|
|
//import netscape.orion.toolbars.ToolBarLayout;
|
|
|
|
//import netscape.orion.uimanager.AbstractUICmd;
|
|
|
|
//import netscape.orion.uimanager.IUICmd;
|
|
|
|
//import netscape.orion.uimanager.IUIMMenuBar;
|
|
|
|
//import netscape.orion.uimanager.UIMConstants;
|
|
|
|
|
|
|
|
//import xml.tree.TreeBuilder;
|
|
|
|
//import xml.tree.XMLNode;
|
1998-09-09 00:52:38 +00:00
|
|
|
|
1999-06-15 11:44:40 +00:00
|
|
|
import grendel.prefs.base.InvisiblePrefs;
|
1999-01-10 21:48:15 +00:00
|
|
|
import grendel.ui.ToolBarLayout;
|
1999-05-15 22:42:27 +00:00
|
|
|
import grendel.widgets.*;
|
1998-09-09 00:52:38 +00:00
|
|
|
|
|
|
|
public class GeneralFrame extends JFrame
|
|
|
|
{
|
|
|
|
GeneralFrame fThis;
|
|
|
|
|
|
|
|
BiffIcon fBiffIcon;
|
|
|
|
|
|
|
|
protected Container fPanel;
|
|
|
|
protected Animation fAnimation;
|
|
|
|
protected JMenuBar fMenu;
|
1999-01-10 21:48:15 +00:00
|
|
|
protected CollapsiblePanel fToolBarPanel;
|
|
|
|
protected GridBagLayout fToolBarPanelLayout;
|
|
|
|
protected GridBagConstraints fToolBarPanelConstraints;
|
|
|
|
protected GrendelToolBar fToolBar;
|
1998-09-09 00:52:38 +00:00
|
|
|
protected Component fStatusBar;
|
|
|
|
protected String fResourceBase = "grendel.ui";
|
|
|
|
protected String fID;
|
|
|
|
protected JLabel fStatusLabel;
|
|
|
|
|
1999-01-09 03:55:32 +00:00
|
|
|
// protected netscape.orion.uimanager.UIManager fUIManager;
|
1998-09-09 00:52:38 +00:00
|
|
|
|
|
|
|
private LAFListener fLAFListener;
|
1999-01-11 07:01:27 +00:00
|
|
|
private Properties prop;
|
1998-09-09 00:52:38 +00:00
|
|
|
|
|
|
|
static Vector fFrameList = new Vector();
|
|
|
|
static boolean sExternalShell = false;
|
|
|
|
|
|
|
|
protected ResourceBundle fLabels =
|
|
|
|
ResourceBundle.getBundle("grendel.ui.Labels", getLocale());
|
|
|
|
|
|
|
|
public GeneralFrame(String aTitle, String aID) {
|
|
|
|
fThis = this;
|
|
|
|
fID = aID;
|
|
|
|
|
|
|
|
String title = aTitle;
|
|
|
|
try {
|
|
|
|
title = fLabels.getString(title);
|
|
|
|
} catch (MissingResourceException e) {}
|
|
|
|
|
|
|
|
setTitle(title);
|
|
|
|
|
|
|
|
addWindowListener(new WindowAdapter() {
|
|
|
|
public void windowClosing(WindowEvent e) {
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
updateUI();
|
|
|
|
fLAFListener = new LAFListener();
|
|
|
|
UIManager.addPropertyChangeListener(fLAFListener);
|
|
|
|
|
|
|
|
fPanel = getContentPane();
|
|
|
|
|
|
|
|
fAnimation = new Animation();
|
1999-07-02 14:20:06 +00:00
|
|
|
fAnimation.setImageTemplate("/grendel/ui/images/animation/Contest{0,number,00}.gif",
|
1999-03-08 14:45:52 +00:00
|
|
|
30);
|
1998-09-09 00:52:38 +00:00
|
|
|
|
1999-01-10 21:48:15 +00:00
|
|
|
fToolBarPanel = new CollapsiblePanel(true);
|
|
|
|
fToolBarPanelLayout = new ToolBarLayout();
|
|
|
|
fToolBarPanelConstraints = new GridBagConstraints();
|
|
|
|
fToolBarPanel.setLayout(fToolBarPanelLayout);
|
|
|
|
fPanel.add(fToolBarPanel, BorderLayout.NORTH);
|
1999-01-09 03:55:32 +00:00
|
|
|
// fUIManager = new netscape.orion.uimanager.UIManager(fToolBarPanel);
|
1998-09-09 00:52:38 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
fFrameList.addElement(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void dispose() {
|
|
|
|
if (fBiffIcon != null) {
|
|
|
|
fBiffIcon.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
fFrameList.removeElement(this);
|
|
|
|
|
|
|
|
super.dispose();
|
|
|
|
|
|
|
|
if (!sExternalShell && fFrameList.size() == 0) {
|
1999-01-10 21:48:15 +00:00
|
|
|
ActionFactory.GetExitAction().actionPerformed(null);
|
1999-01-09 03:55:32 +00:00
|
|
|
System.out.println("Exiting...");
|
1999-01-10 21:48:15 +00:00
|
|
|
|
1998-09-09 00:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UIManager.removePropertyChangeListener(fLAFListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateUI() {
|
|
|
|
setBackground(UIManager.getColor("control"));
|
|
|
|
getContentPane().setBackground(UIManager.getColor("control"));
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Sets the frame's id.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void setID(String aID) {
|
|
|
|
fID = aID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the frame's id.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public String getID() {
|
|
|
|
return fID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the last created frame of a given id.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static GeneralFrame FindFrameByID(String aID) {
|
|
|
|
return FindFrameByID(aID, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the last created frame of a given id.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static GeneralFrame FindFrameByID(String aID, GeneralFrame aExclude) {
|
|
|
|
for (int i = fFrameList.size() - 1; i >= 0; i--) {
|
|
|
|
GeneralFrame frame = (GeneralFrame) fFrameList.elementAt(i);
|
|
|
|
if (frame.getID().equals(aID) && frame != aExclude) {
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a frame for use by dialogs
|
|
|
|
*/
|
|
|
|
|
|
|
|
static public GeneralFrame GetDefaultFrame() {
|
|
|
|
if (fFrameList.size() > 0) {
|
|
|
|
return (GeneralFrame) fFrameList.elementAt(0);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether or not this frame is working with an external application.
|
|
|
|
* Important to prevent exiting the system when all our frames close.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static public void SetExternalShell(boolean aShell) {
|
|
|
|
sExternalShell = aShell;
|
|
|
|
}
|
|
|
|
|
|
|
|
static public boolean IsExternalShell() {
|
|
|
|
return sExternalShell;
|
|
|
|
}
|
|
|
|
|
|
|
|
static public GeneralFrame[] GetFrameList() {
|
|
|
|
GeneralFrame res[] = new GeneralFrame[fFrameList.size()];
|
|
|
|
fFrameList.copyInto(res);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static public synchronized void CloseAllFrames() {
|
|
|
|
while (fFrameList.size() > 0) {
|
|
|
|
GeneralFrame frame = (GeneralFrame) fFrameList.elementAt(0);
|
|
|
|
frame.dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-11 07:01:27 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
1999-05-15 22:42:27 +00:00
|
|
|
protected MenuBarCtrl buildMenu(String file, UIAction[] actions) {
|
|
|
|
MenuBarCtrl menubar = null;
|
1999-01-16 05:24:25 +00:00
|
|
|
URL url;
|
1999-01-20 06:40:01 +00:00
|
|
|
XMLMenuBuilder builder =
|
|
|
|
new XMLMenuBuilder(this, actions);
|
1998-09-09 00:52:38 +00:00
|
|
|
|
1999-01-11 07:01:27 +00:00
|
|
|
try {
|
1999-01-16 05:24:25 +00:00
|
|
|
url = getClass().getResource(file);
|
|
|
|
builder.buildFrom(url.openStream());
|
1999-01-20 06:40:01 +00:00
|
|
|
menubar = builder.getComponent();
|
1999-01-11 07:01:27 +00:00
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
1999-06-16 05:13:53 +00:00
|
|
|
|
|
|
|
menubar.setFont(new Font("Helvetica", Font.PLAIN, 12));
|
1999-01-11 07:01:27 +00:00
|
|
|
return menubar;
|
|
|
|
}
|
|
|
|
|
1998-09-09 00:52:38 +00:00
|
|
|
protected Component buildStatusBar() {
|
1999-01-09 03:55:32 +00:00
|
|
|
JPanel res = new JPanel();
|
|
|
|
res.setLayout(new BoxLayout(res, BoxLayout.X_AXIS));
|
1998-09-09 00:52:38 +00:00
|
|
|
|
|
|
|
fBiffIcon = new BiffIcon();
|
|
|
|
fBiffIcon.setSize(fBiffIcon.getPreferredSize());
|
|
|
|
|
|
|
|
fStatusLabel = new JLabel("Grendel");
|
|
|
|
fStatusLabel.setFont(Font.decode("Dialog-12"));
|
|
|
|
|
1999-01-09 03:55:32 +00:00
|
|
|
res.add(fStatusLabel);
|
|
|
|
res.add(fBiffIcon);
|
1998-09-09 00:52:38 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void startAnimation() {
|
|
|
|
fAnimation.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void stopAnimation() {
|
|
|
|
fAnimation.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void setStatusText(String aString) {
|
|
|
|
if (fStatusLabel != null) {
|
|
|
|
fStatusLabel.setText(aString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void saveBounds(String aName) {
|
1999-06-15 11:44:40 +00:00
|
|
|
InvisiblePrefs.GetMaster().setBounds(aName, getBounds());
|
1998-09-09 00:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void saveBounds() {
|
|
|
|
saveBounds(fID);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void restoreBounds(String aName, int aWidth, int aHeight) {
|
1999-06-15 11:44:40 +00:00
|
|
|
setBounds(InvisiblePrefs.GetMaster().getBounds(aName, aWidth, aHeight));
|
1998-09-09 00:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void restoreBounds(int aWidth, int aHeight) {
|
|
|
|
GeneralFrame frame = FindFrameByID(fID, this);
|
|
|
|
if (frame == null) {
|
|
|
|
restoreBounds(fID, aWidth, aHeight);
|
|
|
|
} else {
|
|
|
|
Rectangle bounds = frame.getBounds();
|
|
|
|
Insets insets = frame.getInsets();
|
|
|
|
setBounds(bounds.x + insets.top, bounds.y + insets.top,
|
|
|
|
bounds.width, bounds.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void restoreBounds() {
|
|
|
|
Dimension screenSize = getToolkit().getScreenSize();
|
|
|
|
|
|
|
|
restoreBounds(screenSize.width * 2 / 3,
|
|
|
|
screenSize.height * 2 / 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
class LAFListener implements PropertyChangeListener {
|
|
|
|
public void propertyChange(PropertyChangeEvent aEvent) {
|
|
|
|
SwingUtilities.updateComponentTreeUI(fThis);
|
|
|
|
invalidate();
|
|
|
|
validate();
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|