01: /*
02: * Copyright 2005 Paul Hinds
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */
16: package org.tp23.antinstaller.renderer.swing;
17:
18: import java.awt.BorderLayout;
19: import java.io.ByteArrayOutputStream;
20: import java.io.InputStream;
21:
22: import javax.swing.ImageIcon;
23: import javax.swing.JLabel;
24:
25: import org.tp23.antinstaller.ValidationException;
26: import org.tp23.antinstaller.page.SplashPage;
27: import org.tp23.antinstaller.runtime.ConfigurationException;
28:
29: /**
30: * A page containing only a single image.
31: *
32: * @author teknopaul
33: */
34: public class SplashPageRenderer extends SwingPageRenderer {
35:
36: private JLabel imagePanel = new JLabel();
37:
38: public SplashPageRenderer() {
39: }
40:
41: public boolean validateFields() throws ValidationException {
42: return true;
43: }
44:
45: public void instanceInit() throws Exception {
46: String resource = ((SplashPage) page).getSplashResource();
47: ByteArrayOutputStream baos = new ByteArrayOutputStream();
48: InputStream in = this .getClass().getResourceAsStream(resource);
49: if (in == null) {
50: throw new ConfigurationException(
51: "Splash page resource is missing: " + resource);
52: }
53: byte[] buffer = new byte[2048];
54: int read = -1;
55: while ((read = in.read(buffer)) != -1) {
56: baos.write(buffer, 0, read);
57: }
58: ImageIcon icon = new ImageIcon(baos.toByteArray());
59: imagePanel.setHorizontalAlignment(JLabel.CENTER);
60: imagePanel.setIcon(icon);
61: dataPanel.add(imagePanel, BorderLayout.CENTER);
62: }
63:
64: public void updateInputFields() {
65: ;
66: }
67:
68: /**
69: * updateDefaultValues
70: */
71: public void updateDefaultValues() {
72: }
73: }
|