1 /* 
2  * Copyright 2005 Paul Hinds
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.tp23.antinstaller.renderer.swing;
17
18import java.awt.BorderLayout;
19import java.io.ByteArrayOutputStream;
20import java.io.InputStream;
21
22import javax.swing.ImageIcon;
23import javax.swing.JLabel;
24
25import org.tp23.antinstaller.ValidationException;
26import org.tp23.antinstaller.page.SplashPage;
27import org.tp23.antinstaller.runtime.ConfigurationException;
28/**
29 * A page containing only a single image. 
30 * 
31 * @author teknopaul
32 */
33public class SplashPageRenderer extends SwingPageRenderer{
34
35    private JLabel imagePanel = new JLabel();
36
37    public SplashPageRenderer() {
38    }
39    public boolean validateFields()throws ValidationException{
40        return true;
41    }
42
43    public void instanceInit() throws Exception {
44        String resource = ((SplashPage)page).getSplashResource();
45        ByteArrayOutputStream baos = new ByteArrayOutputStream();
46        InputStream in = this.getClass().getResourceAsStream(resource);
47        if(in == null) {
48            throw new ConfigurationException("Splash page resource is missing: " + resource);
49        }
50        byte[] buffer = new byte[2048];
51        int read = -1;
52        while ( (read = in.read(buffer)) != -1) {
53            baos.write(buffer, 0, read);
54        }
55        ImageIcon icon = new ImageIcon(baos.toByteArray());
56        imagePanel.setHorizontalAlignment(JLabel.CENTER);
57        imagePanel.setIcon(icon);
58        this.add(imagePanel, BorderLayout.CENTER);
59    }
60
61    public void updateInputFields(){
62        ;
63    }
64
65
66
67    /**
68     * updateDefaultValues
69     */
70    public void updateDefaultValues() {
71    }
72}
73