PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms 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
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. * 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. package org.gjt.sp.jedit.gui;
  20. import javax.swing.border.*;
  21. import javax.swing.*;
  22. import java.awt.event.*;
  23. import java.awt.*;
  24. import java.util.*;
  25. import org.gjt.sp.jedit.*;
  26. public class AboutDialog extends EnhancedDialog
  27. {
  28. public AboutDialog(View view)
  29. {
  30. super(view,jEdit.getProperty("about.title"),true);
  31. JPanel content = new JPanel(new BorderLayout());
  32. content.setBorder(new EmptyBorder(12,12,12,12));
  33. setContentPane(content);
  34. content.add(BorderLayout.CENTER,new AboutPanel());
  35. JPanel buttonPanel = new JPanel();
  36. buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.X_AXIS));
  37. buttonPanel.setBorder(new EmptyBorder(12,0,0,0));
  38. buttonPanel.add(Box.createGlue());
  39. close = new JButton(jEdit.getProperty("common.close"));
  40. close.addActionListener(new ActionHandler());
  41. getRootPane().setDefaultButton(close);
  42. buttonPanel.add(close);
  43. buttonPanel.add(Box.createGlue());
  44. content.add(BorderLayout.SOUTH,buttonPanel);
  45. pack();
  46. setResizable(false);
  47. setLocationRelativeTo(view);
  48. show();
  49. }
  50. public void ok()
  51. {
  52. dispose();
  53. }
  54. public void cancel()
  55. {
  56. dispose();
  57. }
  58. // private members
  59. private JButton close;
  60. class ActionHandler implements ActionListener
  61. {
  62. public void actionPerformed(ActionEvent evt)
  63. {
  64. dispose();
  65. }
  66. }
  67. static class AboutPanel extends JComponent
  68. {
  69. ImageIcon image;
  70. Vector text;
  71. int scrollPosition;
  72. AnimationThread thread;
  73. AboutPanel()
  74. {
  75. setFont(UIManager.getFont("Label.font"));
  76. setForeground(new Color(206,206,229));
  77. image = new ImageIcon(getClass().getResource(
  78. "/org/gjt/sp/jedit/icons/about.gif"));
  79. setBorder(new MatteBorder(1,1,1,1,Color.black));
  80. text = new Vector(50);
  81. StringTokenizer st = new StringTokenizer(
  82. jEdit.getProperty("about.text"),"\n");
  83. while(st.hasMoreTokens())
  84. {
  85. text.addElement(st.nextToken());
  86. }
  87. scrollPosition = -300;
  88. thread = new AnimationThread();
  89. }
  90. public void paintComponent(Graphics _g)
  91. {
  92. Graphics2D g = (Graphics2D)_g;
  93. image.paintIcon(this,g,1,1);
  94. FontMetrics fm = g.getFontMetrics();
  95. int height = fm.getHeight();
  96. int firstLine = scrollPosition / height;
  97. int firstLineOffset = height - scrollPosition % height;
  98. int lastLine = (scrollPosition + 320) / height - 3;
  99. int y = 50 + firstLineOffset;
  100. for(int i = firstLine; i <= lastLine; i++)
  101. {
  102. if(i >= 0 && i < text.size())
  103. {
  104. String line = (String)text.elementAt(i);
  105. g.drawString(line,130 + (340
  106. - fm.stringWidth(line)) / 2,y);
  107. }
  108. y += fm.getHeight();
  109. }
  110. String[] args = { jEdit.getVersion() };
  111. String version = jEdit.getProperty("about.version",args);
  112. g.drawString(version,130 + (340 - fm.stringWidth(version)) / 2,
  113. 370);
  114. }
  115. public Dimension getPreferredSize()
  116. {
  117. return new Dimension(1 + image.getIconWidth(),
  118. 1 + image.getIconHeight());
  119. }
  120. public void addNotify()
  121. {
  122. super.addNotify();
  123. thread.start();
  124. }
  125. public void removeNotify()
  126. {
  127. super.removeNotify();
  128. thread.stop();
  129. }
  130. class AnimationThread extends Thread
  131. {
  132. AnimationThread()
  133. {
  134. super("About box animation thread");
  135. setPriority(Thread.MIN_PRIORITY);
  136. }
  137. public void run()
  138. {
  139. for(;;)
  140. {
  141. long start = System.currentTimeMillis();
  142. scrollPosition++;
  143. FontMetrics fm = getFontMetrics(getFont());
  144. int max = text.size() * fm.getHeight();
  145. if(scrollPosition > max)
  146. scrollPosition = -300;
  147. try
  148. {
  149. Thread.sleep(Math.max(0,50 -
  150. (System.currentTimeMillis() - start)));
  151. }
  152. catch(InterruptedException ie)
  153. {
  154. }
  155. repaint();
  156. }
  157. }
  158. }
  159. }
  160. }