PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/gui/SplashScreen.java

#
Java | 136 lines | 77 code | 23 blank | 36 comment | 0 complexity | 4c932bbe13d5a5a2a79931a7266d91dc 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. * SplashScreen.java - Splash screen
  3. * Copyright (C) 1998, 2004 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.*;
  21. import java.awt.*;
  22. import org.gjt.sp.jedit.jEdit;
  23. import org.gjt.sp.util.Log;
  24. /**
  25. * The splash screen displayed on startup.
  26. */
  27. public class SplashScreen extends JComponent
  28. {
  29. public SplashScreen()
  30. {
  31. setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  32. setBackground(Color.white);
  33. Font font = new Font("Dialog",Font.PLAIN,10);
  34. setFont(font);
  35. fm = getFontMetrics(font);
  36. image = getToolkit().getImage(
  37. getClass().getResource("/org/gjt/sp/jedit/icons/splash.png"));
  38. MediaTracker tracker = new MediaTracker(this);
  39. tracker.addImage(image,0);
  40. try
  41. {
  42. tracker.waitForAll();
  43. }
  44. catch(Exception e)
  45. {
  46. Log.log(Log.ERROR,this,e);
  47. }
  48. win = new JWindow();
  49. Dimension screen = getToolkit().getScreenSize();
  50. Dimension size = new Dimension(image.getWidth(this) + 2,
  51. image.getHeight(this) + 2 + PROGRESS_HEIGHT);
  52. win.setSize(size);
  53. win.getContentPane().add(BorderLayout.CENTER,this);
  54. win.setLocation((screen.width - size.width) / 2,
  55. (screen.height - size.height) / 2);
  56. win.validate();
  57. win.setVisible(true);
  58. /*synchronized(this)
  59. {
  60. try
  61. {
  62. wait();
  63. }
  64. catch(InterruptedException ie)
  65. {
  66. Log.log(Log.ERROR,this,ie);
  67. }
  68. }*/
  69. }
  70. public void dispose()
  71. {
  72. win.dispose();
  73. }
  74. public synchronized void advance()
  75. {
  76. progress++;
  77. repaint();
  78. // wait for it to be painted to ensure progress is updated
  79. // continuously
  80. try
  81. {
  82. wait();
  83. }
  84. catch(InterruptedException ie)
  85. {
  86. Log.log(Log.ERROR,this,ie);
  87. }
  88. }
  89. public synchronized void paintComponent(Graphics g)
  90. {
  91. Dimension size = getSize();
  92. g.setColor(Color.black);
  93. g.drawRect(0,0,size.width - 1,size.height - 1);
  94. g.drawImage(image,1,1,this);
  95. // XXX: This should not be hardcoded
  96. g.setColor(Color.white);
  97. g.fillRect(1,image.getHeight(this) + 1,
  98. ((win.getWidth() - 2) * progress) / 5,PROGRESS_HEIGHT);
  99. g.setColor(Color.black);
  100. String str = "VERSION " + jEdit.getVersion();
  101. g.drawString(str,
  102. (getWidth() - fm.stringWidth(str)) / 2,
  103. image.getHeight(this) + (PROGRESS_HEIGHT
  104. + fm.getAscent() + fm.getDescent()) / 2);
  105. notify();
  106. }
  107. // private members
  108. private FontMetrics fm;
  109. private JWindow win;
  110. private Image image;
  111. private int progress;
  112. private static final int PROGRESS_HEIGHT = 20;
  113. }