PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/gui/AboutDialog.java

#
Java | 235 lines | 165 code | 41 blank | 29 comment | 7 complexity | e9d4cae3a693fd49b335cbedc69e83d1 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package org.gjt.sp.jedit.gui;
  23. //{{{ Imports
  24. import javax.swing.border.*;
  25. import javax.swing.*;
  26. import java.awt.event.*;
  27. import java.awt.*;
  28. import java.util.*;
  29. import org.gjt.sp.jedit.*;
  30. //}}}
  31. public class AboutDialog extends EnhancedDialog
  32. {
  33. //{{{ AboutDialog constructor
  34. public AboutDialog(View view)
  35. {
  36. super(view,jEdit.getProperty("about.title"),true);
  37. JPanel content = new JPanel(new BorderLayout());
  38. content.setBorder(new EmptyBorder(12,12,12,12));
  39. setContentPane(content);
  40. content.add(BorderLayout.CENTER,new AboutPanel());
  41. JPanel buttonPanel = new JPanel();
  42. buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.X_AXIS));
  43. buttonPanel.setBorder(new EmptyBorder(12,0,0,0));
  44. buttonPanel.add(Box.createGlue());
  45. close = new JButton(jEdit.getProperty("common.close"));
  46. close.addActionListener(new ActionHandler());
  47. getRootPane().setDefaultButton(close);
  48. buttonPanel.add(close);
  49. buttonPanel.add(Box.createGlue());
  50. content.add(BorderLayout.SOUTH,buttonPanel);
  51. pack();
  52. setResizable(false);
  53. setLocationRelativeTo(view);
  54. show();
  55. } //}}}
  56. //{{{ ok() method
  57. public void ok()
  58. {
  59. dispose();
  60. } //}}}
  61. //{{{ cancel() method
  62. public void cancel()
  63. {
  64. dispose();
  65. } //}}}
  66. // private members
  67. private JButton close;
  68. //{{{ ActionHandler class
  69. class ActionHandler implements ActionListener
  70. {
  71. public void actionPerformed(ActionEvent evt)
  72. {
  73. dispose();
  74. }
  75. } //}}}
  76. //{{{ AboutPanel class
  77. static class AboutPanel extends JComponent
  78. {
  79. ImageIcon image;
  80. Vector text;
  81. int scrollPosition;
  82. AnimationThread thread;
  83. int maxWidth;
  84. FontMetrics fm;
  85. public static int TOP = 120;
  86. public static int BOTTOM = 30;
  87. AboutPanel()
  88. {
  89. setFont(UIManager.getFont("Label.font"));
  90. fm = getFontMetrics(getFont());
  91. setForeground(new Color(96,96,96));
  92. image = new ImageIcon(getClass().getResource(
  93. "/org/gjt/sp/jedit/icons/about.png"));
  94. setBorder(new MatteBorder(1,1,1,1,Color.gray));
  95. text = new Vector(50);
  96. StringTokenizer st = new StringTokenizer(
  97. jEdit.getProperty("about.text"),"\n");
  98. while(st.hasMoreTokens())
  99. {
  100. String line = st.nextToken();
  101. text.addElement(line);
  102. maxWidth = Math.max(maxWidth,
  103. fm.stringWidth(line) + 10);
  104. }
  105. scrollPosition = -250;
  106. thread = new AnimationThread();
  107. }
  108. public void paintComponent(Graphics g)
  109. {
  110. g.setColor(new Color(96,96,96));
  111. image.paintIcon(this,g,1,1);
  112. FontMetrics fm = g.getFontMetrics();
  113. String[] args = { jEdit.getVersion() };
  114. String version = jEdit.getProperty("about.version",args);
  115. g.drawString(version,(getWidth() - fm.stringWidth(version)) / 2,
  116. getHeight() - 5);
  117. g = g.create((getWidth() - maxWidth) / 2,TOP,maxWidth,
  118. getHeight() - TOP - BOTTOM);
  119. int height = fm.getHeight();
  120. int firstLine = scrollPosition / height;
  121. int firstLineOffset = height - scrollPosition % height;
  122. int lines = (getHeight() - TOP - BOTTOM) / height;
  123. int y = firstLineOffset;
  124. for(int i = 0; i <= lines; i++)
  125. {
  126. if(i + firstLine >= 0 && i + firstLine < text.size())
  127. {
  128. String line = (String)text.get(i + firstLine);
  129. g.drawString(line,(maxWidth - fm.stringWidth(line))/2,y);
  130. }
  131. y += fm.getHeight();
  132. }
  133. }
  134. public Dimension getPreferredSize()
  135. {
  136. return new Dimension(1 + image.getIconWidth(),
  137. 1 + image.getIconHeight());
  138. }
  139. public void addNotify()
  140. {
  141. super.addNotify();
  142. thread.start();
  143. }
  144. public void removeNotify()
  145. {
  146. super.removeNotify();
  147. thread.kill();
  148. }
  149. class AnimationThread extends Thread
  150. {
  151. private boolean running = true;
  152. private long last;
  153. AnimationThread()
  154. {
  155. super("About box animation thread");
  156. setPriority(Thread.MIN_PRIORITY);
  157. }
  158. public void kill()
  159. {
  160. running = false;
  161. }
  162. public void run()
  163. {
  164. FontMetrics fm = getFontMetrics(getFont());
  165. int max = (text.size() * fm.getHeight());
  166. while (running)
  167. {
  168. scrollPosition += 2;
  169. if(scrollPosition > max)
  170. scrollPosition = -250;
  171. if(last != 0)
  172. {
  173. long frameDelay =
  174. System.currentTimeMillis()
  175. - last;
  176. try
  177. {
  178. Thread.sleep(
  179. 75
  180. - frameDelay);
  181. }
  182. catch(Exception e)
  183. {
  184. }
  185. }
  186. last = System.currentTimeMillis();
  187. repaint(getWidth() / 2 - maxWidth,
  188. TOP,maxWidth * 2,
  189. getHeight() - TOP - BOTTOM);
  190. }
  191. }
  192. }
  193. } //}}}
  194. }