001: /*
002: * Copyright (c) 2000, Jacob Smullyan.
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: */
022:
023: package org.skunk.dav.client.gui.action;
024:
025: import java.awt.Color;
026: import java.awt.Font;
027: import java.awt.Graphics2D;
028: import java.awt.Image;
029: import java.awt.event.ActionEvent;
030: import java.awt.event.KeyEvent;
031: import java.awt.event.KeyListener;
032: import java.awt.event.MouseAdapter;
033: import java.awt.event.MouseEvent;
034: import java.awt.image.BufferedImage;
035: import java.util.StringTokenizer;
036: import javax.swing.AbstractAction;
037: import javax.swing.ImageIcon;
038: import javax.swing.JLabel;
039: import org.skunk.dav.client.gui.ResourceManager;
040: import org.skunk.swing.SplashScreen;
041:
042: /**
043: * an Action for the "About" menu item. Shows a splash screen.
044: *
045: * @author Jacob Smullyan
046: */
047:
048: public class AboutAction extends AbstractAction {
049: private static final String DEFAULT_ICON_KEY = ResourceManager.SPLASH_SCREEN_ICON;
050: private SplashScreen splash;
051: private String iconKey;
052: private String splashScreenText;
053: private SplashListener listener;
054:
055: public AboutAction() {
056: this (DEFAULT_ICON_KEY);
057: }
058:
059: public AboutAction(String iconKey) {
060: this .iconKey = iconKey;
061: initSplash(iconKey);
062: }
063:
064: private void initSplash(String iconKey) {
065: listener = new SplashListener();
066: String releaseVersion = ResourceManager
067: .getMessage(ResourceManager.RELEASE_VERSION);
068: splashScreenText = ResourceManager.getMessage(
069: ResourceManager.SPLASH_SCREEN_TEXT,
070: new Object[] { releaseVersion });
071: splash = new SplashScreen(getImageIcon(iconKey));
072: splash.addMouseListener(listener);
073: splash.addKeyListener(listener);
074: }
075:
076: /**
077: * obtains the image from the ResourceManager with the given key, and draws text on it.
078: * the drawing is entirely hardcoded, and expects the splash screen text to be in a pipe-delimited
079: * format with exactly five fields.
080: * @param iconKey the key for the ResourceManager
081: */
082: protected ImageIcon getImageIcon(String iconKey) {
083: ImageIcon ii = ResourceManager.getImageIcon(iconKey);
084: if (ii == null)
085: ii = ResourceManager.getImageIcon(DEFAULT_ICON_KEY);
086: if (ii == null)
087: return null;
088: //do custom painting on image.
089: Image im = ii.getImage();
090: //in order to call a components createImage() method,
091: //I need one that has been fully constructed,
092: //or I may get a null pointer.
093: JLabel label = new JLabel();
094: BufferedImage bim = (BufferedImage) label.createImage(im
095: .getWidth(label), im.getHeight(label));
096: if (bim == null) // I don't know why this happens, but it does.
097: bim = new BufferedImage(im.getWidth(label), im
098: .getHeight(label), BufferedImage.TYPE_INT_RGB);
099: Graphics2D g2d = bim.createGraphics();
100: g2d.drawImage(im, 0, 0, label);
101: Font bigFont = new Font("Dialog", Font.BOLD, 18);
102: Font mediumFont = new Font("Dialog", Font.BOLD, 12);
103: Font littleFont = new Font("SansSerif", Font.PLAIN, 9);
104:
105: StringTokenizer st = new StringTokenizer(getSplashScreenText(),
106: "|");
107: String title = st.nextToken();
108: String subtitle = st.nextToken();
109: String copyright = st.nextToken();
110: String acknowledgements1 = st.nextToken();
111: String acknowledgements2 = st.nextToken();
112: g2d.setFont(bigFont);
113: g2d.setColor(Color.red);
114: g2d.drawString(title, 10, 30);
115: g2d.setFont(mediumFont);
116: g2d.drawString(subtitle, 10, 50);
117: g2d.setFont(littleFont);
118: g2d.setColor(Color.white);
119: g2d.drawString(copyright, 10, 160);
120: g2d.drawString(acknowledgements1, 10, 175);
121: g2d.drawString(acknowledgements2, 10, 190);
122: return new ImageIcon(bim);
123: }
124:
125: public void actionPerformed(ActionEvent ae) {
126: splash.setVisible(true);
127: }
128:
129: public String getSplashScreenText() {
130: return splashScreenText;
131: }
132:
133: public void setSplashScreenText(String splashScreenText) {
134: this .splashScreenText = splashScreenText;
135: splash.removeMouseListener(listener);
136: splash.removeKeyListener(listener);
137: this .splash = new SplashScreen(getImageIcon(this .iconKey));
138: splash.addMouseListener(listener);
139: splash.addKeyListener(listener);
140: }
141:
142: private class SplashListener extends MouseAdapter implements
143: KeyListener {
144: public void mouseClicked(MouseEvent mao) {
145: splashAbout();
146: }
147:
148: public void keyPressed(KeyEvent keanu) {
149: splashAbout();
150: }
151:
152: public void keyReleased(KeyEvent keanu) {
153: }
154:
155: public void keyTyped(KeyEvent keanu) {
156: }
157:
158: private void splashAbout() {
159: if (splash.isVisible())
160: splash.setVisible(false);
161: }
162: }
163: }
164:
165: /* $Log: AboutAction.java,v $
166: /* Revision 1.4 2001/07/22 07:04:24 smulloni
167: /* changed the handling of release number.
168: /*
169: /* Revision 1.3 2000/12/21 18:53:13 smulloni
170: /* cosmetic improvements.
171: /*
172: /* Revision 1.2 2000/12/19 22:06:15 smulloni
173: /* adding documentation.
174: /* */
|