1
16package org.tp23.antinstaller.renderer.swing;
17
18import java.awt.BorderLayout;
19import java.io.BufferedReader;
20import java.io.InputStream;
21import java.io.InputStreamReader;
22
23import javax.swing.BorderFactory;
24import javax.swing.JLabel;
25import javax.swing.JScrollPane;
26import javax.swing.JTextPane;
27import javax.swing.text.html.HTMLEditorKit;
28
29import org.tp23.antinstaller.ValidationException;
30import org.tp23.antinstaller.page.TextPage;
31import org.tp23.antinstaller.runtime.ConfigurationException;
32
48public class TextPageRenderer extends SwingPageRenderer{
49
50 private JTextPane textPane = new JTextPane();
51 private StringBuffer buffer = new StringBuffer();
52
53 public TextPageRenderer() {
54 }
55
56 public boolean validateFields()throws ValidationException{
57 return true;
58 }
59
60 public void instanceInit() throws Exception {
61 final String resource = ((TextPage)page).getHtmlResource();
62 InputStream in = this.getClass().getResourceAsStream(resource);
63 if(in == null){
64 throw new ConfigurationException("Html page resource is missing:" + resource);
65 }
66 BufferedReader br = new BufferedReader(new InputStreamReader(in));
67 String read = null;
68 while ( (read = br.readLine()) != null) {
69 buffer.append(read);
70 }
71 br.close();
73
74 JLabel defaults = new JLabel();
75 textPane.setBackground(defaults.getBackground());
76 textPane.setEditable(false);
77 textPane.setContentType("text/html");
78 HTMLEditorKit classpathKit = new ClasspathHTMLEditorKit();
79 textPane.setEditorKit(classpathKit);
80 textPane.setAutoscrolls(true);
81
82 String rule = "body{font-family:" + defaults.getFont().getFamily() +
83 ";font-size:" + defaults.getFont().getSize() + "}";
84 classpathKit.getStyleSheet().addRule(rule);
85 textPane.setBorder(BorderFactory.createEmptyBorder());
86
87 JScrollPane scroller = new JScrollPane();
88 scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
89 scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
90 scroller.setBorder(BorderFactory.createCompoundBorder(
91 BorderFactory.createEmptyBorder(4, 4, 4, 4),
92 BorderFactory.createEtchedBorder()
93 ));
94 add(scroller, BorderLayout.CENTER);
95 scroller.getViewport().add(textPane);
96 this.add(scroller, BorderLayout.CENTER);
97 }
98
99 public void updateInputFields(){
00 }
01
02
03
04
07 public void updateDefaultValues() {
08 String parsedHtml = ctx.getInstaller().getResultContainer().getDefaultValue(buffer.toString());
10 textPane.setText(parsedHtml);
11 textPane.setCaretPosition(0);
12 }
13}
14