PageRenderTime 138ms CodeModel.GetById 60ms app.highlight 16ms RepoModel.GetById 54ms app.codeStats 5ms

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