PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/gui/SplashScreen.java

#
Java | 154 lines | 89 code | 26 blank | 39 comment | 2 complexity | 2ef9270848465afe81b9e613a8b0870f 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, 1999, 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 java.awt.*;
  21. import org.gjt.sp.jedit.jEdit;
  22. import org.gjt.sp.util.Log;
  23. /**
  24. * The splash screen displayed on startup.<p>
  25. *
  26. * This file only uses AWT APIs so that it can be displayed as soon as possible
  27. * after jEdit is launched.
  28. */
  29. public class SplashScreen extends Canvas
  30. {
  31. public SplashScreen()
  32. {
  33. setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  34. setBackground(Color.white);
  35. Font font = new Font("Dialog",Font.PLAIN,10);
  36. setFont(font);
  37. fm = getFontMetrics(font);
  38. image = getToolkit().getImage(
  39. getClass().getResource("/org/gjt/sp/jedit/icons/splash.png"));
  40. MediaTracker tracker = new MediaTracker(this);
  41. tracker.addImage(image,0);
  42. try
  43. {
  44. tracker.waitForAll();
  45. }
  46. catch(Exception e)
  47. {
  48. Log.log(Log.ERROR,this,e);
  49. }
  50. win = new Window(new Frame());
  51. Dimension screen = getToolkit().getScreenSize();
  52. Dimension size = new Dimension(image.getWidth(this) + 2,
  53. image.getHeight(this) + 2 + PROGRESS_HEIGHT);
  54. win.setSize(size);
  55. win.setLayout(new BorderLayout());
  56. win.add(BorderLayout.CENTER,this);
  57. win.setLocation((screen.width - size.width) / 2,
  58. (screen.height - size.height) / 2);
  59. win.validate();
  60. win.show();
  61. /*synchronized(this)
  62. {
  63. try
  64. {
  65. wait();
  66. }
  67. catch(InterruptedException ie)
  68. {
  69. Log.log(Log.ERROR,this,ie);
  70. }
  71. }*/
  72. }
  73. public void dispose()
  74. {
  75. win.dispose();
  76. }
  77. public synchronized void advance()
  78. {
  79. progress++;
  80. repaint();
  81. // wait for it to be painted to ensure progress is updated
  82. // continuously
  83. try
  84. {
  85. wait();
  86. }
  87. catch(InterruptedException ie)
  88. {
  89. Log.log(Log.ERROR,this,ie);
  90. }
  91. }
  92. public void update(Graphics g)
  93. {
  94. paint(g);
  95. }
  96. public synchronized void paint(Graphics g)
  97. {
  98. Dimension size = getSize();
  99. if(offscreenImg == null)
  100. {
  101. offscreenImg = createImage(size.width,size.height);
  102. offscreenGfx = offscreenImg.getGraphics();
  103. offscreenGfx.setFont(getFont());
  104. }
  105. offscreenGfx.setColor(Color.gray);
  106. offscreenGfx.drawRect(0,0,size.width - 1,size.height - 1);
  107. offscreenGfx.drawImage(image,1,1,this);
  108. // XXX: This should not be hardcoded
  109. offscreenGfx.setColor(new Color(168,173,189));
  110. offscreenGfx.fillRect(1,image.getHeight(this) + 1,
  111. ((win.getWidth() - 2) * progress) / 5,PROGRESS_HEIGHT);
  112. offscreenGfx.setColor(Color.gray);
  113. String str = "Version " + jEdit.getVersion();
  114. offscreenGfx.drawString(str,
  115. (getWidth() - fm.stringWidth(str)) / 2,
  116. image.getHeight(this)+1 - fm.getDescent() - 10);
  117. g.drawImage(offscreenImg,0,0,this);
  118. notify();
  119. }
  120. // private members
  121. private FontMetrics fm;
  122. private Window win;
  123. private Image image;
  124. private Image offscreenImg;
  125. private Graphics offscreenGfx;
  126. private int progress;
  127. private static final int PROGRESS_HEIGHT = 20;
  128. }