001: /*
002: * AboutDialog.java - About jEdit dialog box
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2000, 2001, 2002 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.gui;
024:
025: //{{{ Imports
026: import javax.swing.border.*;
027: import javax.swing.*;
028: import java.awt.event.*;
029: import java.awt.*;
030: import java.util.*;
031: import org.gjt.sp.jedit.*;
032:
033: //}}}
034:
035: public class AboutDialog extends EnhancedDialog {
036: //{{{ AboutDialog constructor
037: public AboutDialog(View view) {
038: super (view, jEdit.getProperty("about.title"), true);
039:
040: JPanel content = new JPanel(new BorderLayout());
041: content.setBorder(new EmptyBorder(12, 12, 12, 12));
042: setContentPane(content);
043:
044: content.add(BorderLayout.CENTER, new AboutPanel());
045:
046: JPanel buttonPanel = new JPanel();
047: buttonPanel.setLayout(new BoxLayout(buttonPanel,
048: BoxLayout.X_AXIS));
049: buttonPanel.setBorder(new EmptyBorder(12, 0, 0, 0));
050:
051: buttonPanel.add(Box.createGlue());
052: close = new JButton(jEdit.getProperty("common.close"));
053: close.addActionListener(new ActionHandler());
054: getRootPane().setDefaultButton(close);
055: buttonPanel.add(close);
056: buttonPanel.add(Box.createGlue());
057: content.add(BorderLayout.SOUTH, buttonPanel);
058:
059: pack();
060: setResizable(false);
061: setLocationRelativeTo(view);
062: setVisible(true);
063: } //}}}
064:
065: //{{{ ok() method
066: public void ok() {
067: dispose();
068: } //}}}
069:
070: //{{{ cancel() method
071: public void cancel() {
072: dispose();
073: } //}}}
074:
075: // private members
076: private JButton close;
077:
078: //{{{ ActionHandler class
079: class ActionHandler implements ActionListener {
080: public void actionPerformed(ActionEvent evt) {
081: dispose();
082: }
083: } //}}}
084:
085: //{{{ AboutPanel class
086: static class AboutPanel extends JComponent {
087: ImageIcon image;
088: Vector text;
089: int scrollPosition;
090: AnimationThread thread;
091: int maxWidth;
092: FontMetrics fm;
093:
094: public static int TOP = 120;
095: public static int BOTTOM = 30;
096:
097: AboutPanel() {
098: setFont(UIManager.getFont("Label.font"));
099: fm = getFontMetrics(getFont());
100:
101: setForeground(new Color(96, 96, 96));
102: image = new ImageIcon(getClass().getResource(
103: "/org/gjt/sp/jedit/icons/about.png"));
104:
105: setBorder(new MatteBorder(1, 1, 1, 1, Color.gray));
106:
107: text = new Vector(50);
108: StringTokenizer st = new StringTokenizer(jEdit
109: .getProperty("about.text"), "\n");
110: while (st.hasMoreTokens()) {
111: String line = st.nextToken();
112: text.addElement(line);
113: maxWidth = Math
114: .max(maxWidth, fm.stringWidth(line) + 10);
115: }
116:
117: scrollPosition = -250;
118:
119: thread = new AnimationThread();
120: }
121:
122: public void paintComponent(Graphics g) {
123: g.setColor(new Color(96, 96, 96));
124: image.paintIcon(this , g, 1, 1);
125:
126: FontMetrics fm = g.getFontMetrics();
127:
128: String[] args = { jEdit.getVersion(),
129: System.getProperty("java.version") };
130: String version = jEdit.getProperty("about.version", args);
131: g.drawString(version,
132: (getWidth() - fm.stringWidth(version)) / 2,
133: getHeight() - 5);
134:
135: g = g.create((getWidth() - maxWidth) / 2, TOP, maxWidth,
136: getHeight() - TOP - BOTTOM);
137:
138: int height = fm.getHeight();
139: int firstLine = scrollPosition / height;
140:
141: int firstLineOffset = height - scrollPosition % height;
142: int lines = (getHeight() - TOP - BOTTOM) / height;
143:
144: int y = firstLineOffset;
145:
146: for (int i = 0; i <= lines; i++) {
147: if (i + firstLine >= 0 && i + firstLine < text.size()) {
148: String line = (String) text.get(i + firstLine);
149: g.drawString(line,
150: (maxWidth - fm.stringWidth(line)) / 2, y);
151: }
152: y += fm.getHeight();
153: }
154: }
155:
156: public Dimension getPreferredSize() {
157: return new Dimension(1 + image.getIconWidth(), 1 + image
158: .getIconHeight());
159: }
160:
161: public void addNotify() {
162: super .addNotify();
163: thread.start();
164: }
165:
166: public void removeNotify() {
167: super .removeNotify();
168: thread.kill();
169: }
170:
171: class AnimationThread extends Thread {
172: private boolean running = true;
173: private long last;
174:
175: AnimationThread() {
176: super ("About box animation thread");
177: setPriority(Thread.MIN_PRIORITY);
178: }
179:
180: public void kill() {
181: running = false;
182: }
183:
184: public void run() {
185: FontMetrics fm = getFontMetrics(getFont());
186: int max = (text.size() * fm.getHeight());
187:
188: while (running) {
189: scrollPosition += 2;
190:
191: if (scrollPosition > max)
192: scrollPosition = -250;
193:
194: if (last != 0) {
195: long frameDelay = System.currentTimeMillis()
196: - last;
197:
198: try {
199: Thread.sleep(75 - frameDelay);
200: } catch (Exception e) {
201: }
202: }
203:
204: last = System.currentTimeMillis();
205:
206: repaint(getWidth() / 2 - maxWidth, TOP,
207: maxWidth * 2, getHeight() - TOP - BOTTOM);
208: }
209: }
210: }
211: } //}}}
212: }
|