PageRenderTime 796ms CodeModel.GetById 104ms RepoModel.GetById 3ms app.codeStats 0ms

/src/mpv5/ui/dialogs/SplashScreen.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 220 lines | 136 code | 28 blank | 56 comment | 0 complexity | 5bdff775d2725e77ea742c2222f9030a MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. /*
  6. * SplashScreen.java
  7. *
  8. * Created on 30.03.2009, 21:55:52
  9. */
  10. package mpv5.ui.dialogs;
  11. import java.awt.Graphics;
  12. import java.awt.Image;
  13. import javax.swing.GrayFilter;
  14. import javax.swing.ImageIcon;
  15. import javax.swing.JDialog;
  16. import javax.swing.SwingUtilities;
  17. import mpv5.Main;
  18. import mpv5.globals.Constants;
  19. import mpv5.logging.Log;
  20. import mpv5.ui.misc.Position;
  21. /**
  22. *
  23. *
  24. */
  25. public class SplashScreen extends JDialog {
  26. private static final long serialVersionUID = 1L;
  27. private Image image;
  28. private Image grayImage;
  29. private int progressSteps;
  30. /** Creates new form SplashScreen
  31. * @param imageIcon
  32. */
  33. public SplashScreen(ImageIcon imageIcon) {
  34. initComponents();
  35. setTitle("Yabs start...");
  36. jPanel1.setOpaque(false);
  37. setInfo(Constants.VERSION);
  38. title.setText(Constants.TITLE);
  39. jProgressBar1.setStringPainted(true);
  40. image = imageIcon.getImage();
  41. grayImage = GrayFilter.createDisabledImage(image);
  42. new Position(this);
  43. setVisible(true);
  44. setModalityType(ModalityType.MODELESS);
  45. }
  46. /** This method is called from within the constructor to
  47. * initialize the form.
  48. * WARNING: Do NOT modify this code. The content of this method is
  49. * always regenerated by the Form Editor.
  50. */
  51. @SuppressWarnings("unchecked")
  52. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  53. private void initComponents() {
  54. jPanel1 = new javax.swing.JPanel(){
  55. public void paintComponent(Graphics g) {
  56. g.drawImage(image, 0, 0, this);
  57. super.paintComponent(g);
  58. }
  59. };
  60. progress = new javax.swing.JLabel();
  61. info = new javax.swing.JLabel();
  62. jProgressBar1 = new javax.swing.JProgressBar();
  63. title = new javax.swing.JLabel();
  64. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  65. setTitle("MP Start..");
  66. setResizable(false);
  67. setUndecorated(true);
  68. jPanel1.setBackground(javax.swing.UIManager.getDefaults().getColor("OptionPane.errorDialog.border.background"));
  69. jPanel1.setPreferredSize(new java.awt.Dimension(450, 300));
  70. progress.setForeground(new java.awt.Color(255, 255, 255));
  71. progress.setText("Progress");
  72. info.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
  73. info.setForeground(new java.awt.Color(0, 0, 0));
  74. info.setText("Version info");
  75. jProgressBar1.setBorderPainted(false);
  76. jProgressBar1.setStringPainted(true);
  77. title.setFont(new java.awt.Font("Dialog", 0, 12));
  78. title.setForeground(new java.awt.Color(255, 255, 255));
  79. title.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
  80. title.setText("Title");
  81. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  82. jPanel1.setLayout(jPanel1Layout);
  83. jPanel1Layout.setHorizontalGroup(
  84. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  85. .addGroup(jPanel1Layout.createSequentialGroup()
  86. .addContainerGap()
  87. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  88. .addComponent(progress, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
  89. .addGroup(jPanel1Layout.createSequentialGroup()
  90. .addComponent(info, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
  91. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
  92. .addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE))
  93. .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE))
  94. .addContainerGap())
  95. );
  96. jPanel1Layout.setVerticalGroup(
  97. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  98. .addGroup(jPanel1Layout.createSequentialGroup()
  99. .addContainerGap()
  100. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  101. .addComponent(info)
  102. .addComponent(title))
  103. .addGap(235, 235, 235)
  104. .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
  105. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  106. .addComponent(progress)
  107. .addContainerGap())
  108. );
  109. getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
  110. pack();
  111. }// </editor-fold>//GEN-END:initComponents
  112. // Variables declaration - do not modify//GEN-BEGIN:variables
  113. private javax.swing.JLabel info;
  114. private javax.swing.JPanel jPanel1;
  115. private javax.swing.JProgressBar jProgressBar1;
  116. private javax.swing.JLabel progress;
  117. private javax.swing.JLabel title;
  118. // End of variables declaration//GEN-END:variables
  119. /**
  120. * Initiates the progressbar
  121. * @param steps
  122. */
  123. public void init(int steps) {
  124. jProgressBar1.setMaximum(100);
  125. jProgressBar1.setMinimum(0);
  126. progressSteps = 100 / steps + 1;
  127. nextStep("Don't panik!");
  128. }
  129. /**
  130. * @return the image
  131. */
  132. public Image getImage() {
  133. return image;
  134. }
  135. /**
  136. * @param image the image to set
  137. */
  138. public void setImage(Image image) {
  139. this.image = image;
  140. }
  141. /**
  142. * @return the grayImage
  143. */
  144. public Image getGrayImage() {
  145. return grayImage;
  146. }
  147. /**
  148. * @param grayImage the grayImage to set
  149. */
  150. public void setGrayImage(Image grayImage) {
  151. this.grayImage = grayImage;
  152. }
  153. /**
  154. * @return the info
  155. */
  156. public String getInfo() {
  157. return info.getText();
  158. }
  159. /**
  160. * @param info the info to set
  161. */
  162. public void setInfo(String info) {
  163. this.info.setText(info);
  164. }
  165. /**
  166. * @return the progress
  167. */
  168. public String getProgress() {
  169. return progress.getText();
  170. }
  171. /**
  172. * @param progress the progress to set
  173. */
  174. public void setProgress(String progress) {
  175. this.progress.setText(progress);
  176. }
  177. /**
  178. * Moves the progressbar forward one step
  179. * @param message
  180. */
  181. public synchronized void nextStep(final String message) {
  182. Runnable runnable = new Runnable() {
  183. @Override
  184. public void run() {
  185. setProgress(message);
  186. jProgressBar1.setValue(progressSteps);
  187. progressSteps += progressSteps;
  188. }
  189. };
  190. SwingUtilities.invokeLater(runnable);
  191. }
  192. }