PageRenderTime 80ms CodeModel.GetById 64ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/gui/AboutDialog.java

#
Java | 193 lines | 141 code | 33 blank | 19 comment | 5 complexity | 639dd217941dad14ab2c55baaa438a68 MD5 | raw file
  1/*
  2 * AboutDialog.java - About jEdit dialog box
  3 * Copyright (C) 2000, 2001 Slava Pestov
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License
  7 * as published by the Free Software Foundation; either version 2
  8 * of the License, or any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18 */
 19
 20package org.gjt.sp.jedit.gui;
 21
 22import javax.swing.border.*;
 23import javax.swing.*;
 24import java.awt.event.*;
 25import java.awt.*;
 26import java.util.*;
 27import org.gjt.sp.jedit.*;
 28
 29public class AboutDialog extends EnhancedDialog
 30{
 31	public AboutDialog(View view)
 32	{
 33		super(view,jEdit.getProperty("about.title"),true);
 34
 35		JPanel content = new JPanel(new BorderLayout());
 36		content.setBorder(new EmptyBorder(12,12,12,12));
 37		setContentPane(content);
 38
 39		content.add(BorderLayout.CENTER,new AboutPanel());
 40
 41		JPanel buttonPanel = new JPanel();
 42		buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.X_AXIS));
 43		buttonPanel.setBorder(new EmptyBorder(12,0,0,0));
 44
 45		buttonPanel.add(Box.createGlue());
 46		close = new JButton(jEdit.getProperty("common.close"));
 47		close.addActionListener(new ActionHandler());
 48		getRootPane().setDefaultButton(close);
 49		buttonPanel.add(close);
 50		buttonPanel.add(Box.createGlue());
 51		content.add(BorderLayout.SOUTH,buttonPanel);
 52
 53		pack();
 54		setResizable(false);
 55		setLocationRelativeTo(view);
 56		show();
 57	}
 58
 59	public void ok()
 60	{
 61		dispose();
 62	}
 63
 64	public void cancel()
 65	{
 66		dispose();
 67	}
 68
 69	// private members
 70	private JButton close;
 71
 72	class ActionHandler implements ActionListener
 73	{
 74		public void actionPerformed(ActionEvent evt)
 75		{
 76			dispose();
 77		}
 78	}
 79
 80	static class AboutPanel extends JComponent
 81	{
 82		ImageIcon image;
 83		Vector text;
 84		int scrollPosition;
 85		AnimationThread thread;
 86
 87		AboutPanel()
 88		{
 89			setFont(UIManager.getFont("Label.font"));
 90			setForeground(new Color(206,206,229));
 91			image = new ImageIcon(getClass().getResource(
 92				"/org/gjt/sp/jedit/icons/about.gif"));
 93			setBorder(new MatteBorder(1,1,1,1,Color.black));
 94
 95			text = new Vector(50);
 96			StringTokenizer st = new StringTokenizer(
 97				jEdit.getProperty("about.text"),"\n");
 98			while(st.hasMoreTokens())
 99			{
100				text.addElement(st.nextToken());
101			}
102
103			scrollPosition = -300;
104
105			thread = new AnimationThread();
106		}
107
108		public void paintComponent(Graphics _g)
109		{
110			Graphics2D g = (Graphics2D)_g;
111
112			image.paintIcon(this,g,1,1);
113
114			FontMetrics fm = g.getFontMetrics();
115			int height = fm.getHeight();
116			int firstLine = scrollPosition / height;
117
118			int firstLineOffset = height - scrollPosition % height;
119			int lastLine = (scrollPosition + 320) / height - 3;
120
121			int y = 50 + firstLineOffset;
122
123			for(int i = firstLine; i <= lastLine; i++)
124			{
125				if(i >= 0 && i < text.size())
126				{
127					String line = (String)text.elementAt(i);
128					g.drawString(line,130 + (340
129						- fm.stringWidth(line)) / 2,y);
130				}
131				y += fm.getHeight();
132			}
133
134			String[] args = { jEdit.getVersion() };
135			String version = jEdit.getProperty("about.version",args);
136			g.drawString(version,130 + (340 - fm.stringWidth(version)) / 2,
137				370);
138		}
139
140		public Dimension getPreferredSize()
141		{
142			return new Dimension(1 + image.getIconWidth(),
143				1 + image.getIconHeight());
144		}
145
146		public void addNotify()
147		{
148			super.addNotify();
149			thread.start();
150		}
151
152		public void removeNotify()
153		{
154			super.removeNotify();
155			thread.stop();
156		}
157
158		class AnimationThread extends Thread
159		{
160			AnimationThread()
161			{
162				super("About box animation thread");
163				setPriority(Thread.MIN_PRIORITY);
164			}
165
166			public void run()
167			{
168				for(;;)
169				{
170					long start = System.currentTimeMillis();
171
172					scrollPosition++;
173
174					FontMetrics fm = getFontMetrics(getFont());
175					int max = text.size() * fm.getHeight();
176					if(scrollPosition > max)
177						scrollPosition = -300;
178
179					try
180					{
181						Thread.sleep(Math.max(0,50 -
182							(System.currentTimeMillis() - start)));
183					}
184					catch(InterruptedException ie)
185					{
186					}
187
188					repaint();
189				}
190			}
191		}
192	}
193}