Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/gjt/sp/jedit/gui/AboutDialog.java


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