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 | */
|
---|
16 | package org.tp23.antinstaller.renderer.swing;
|
---|
17 |
|
---|
18 | import java.awt.BorderLayout;
|
---|
19 | import java.awt.Dimension;
|
---|
20 | import java.awt.Insets;
|
---|
21 | import java.awt.Rectangle;
|
---|
22 | import java.awt.event.ActionEvent;
|
---|
23 | import java.awt.event.ActionListener;
|
---|
24 | import java.io.PrintStream;
|
---|
25 | import java.util.ResourceBundle;
|
---|
26 |
|
---|
27 | import javax.swing.BorderFactory;
|
---|
28 | import javax.swing.JLabel;
|
---|
29 | import javax.swing.JButton;
|
---|
30 | import javax.swing.JPanel;
|
---|
31 | import javax.swing.JScrollPane;
|
---|
32 | import javax.swing.JTabbedPane;
|
---|
33 | import javax.swing.JToggleButton;
|
---|
34 | import javax.swing.ImageIcon;
|
---|
35 |
|
---|
36 | import org.tp23.antinstaller.page.ProgressPage;
|
---|
37 | import org.tp23.antinstaller.renderer.AntOutputRenderer;
|
---|
38 | import org.tp23.gui.widget.SystemOutJTextArea;
|
---|
39 | /**
|
---|
40 | *
|
---|
41 | * <p>Copyright: Copyright (c) 2004</p>
|
---|
42 | * <p>Company: tp23</p>
|
---|
43 | * @todo change absolute to Border layout and panels
|
---|
44 | * @author Paul Hinds
|
---|
45 | * @version $Id: ProgressPageRenderer.java,v 1.4 2006/12/21 00:03:00 teknopaul Exp $
|
---|
46 | */
|
---|
47 | public class ProgressPageRenderer
|
---|
48 | extends SwingPageRenderer
|
---|
49 | implements AntOutputRenderer {
|
---|
50 |
|
---|
51 | private static final int MESSAGE_PANEL_HEIGHT = 30;
|
---|
52 |
|
---|
53 | private JPanel contentPanel = new JPanel();
|
---|
54 |
|
---|
55 | private JTabbedPane jTabbedPane = new JTabbedPane();
|
---|
56 | private JPanel messagesPanel = new JPanel();
|
---|
57 | private BorderLayout borderLayout1 = new BorderLayout();
|
---|
58 | private JToggleButton jToggleButton = new JToggleButton();
|
---|
59 | private JLabel feedBackLabel = new JLabel();
|
---|
60 | private JLabel progressOn = null;
|
---|
61 | private JLabel progressOff = null;
|
---|
62 | private JPanel messagesLeft = null;
|
---|
63 | private JPanel messagesRight = null;
|
---|
64 |
|
---|
65 | private SystemOutJTextArea outPanel = new SystemOutJTextArea();
|
---|
66 | private SystemOutJTextArea errPanel = new SystemOutJTextArea();
|
---|
67 |
|
---|
68 | private boolean showTargets = true;
|
---|
69 | private JScrollPane progressScrollPane = new JScrollPane();;
|
---|
70 | private ProgressPanel progressPanel;
|
---|
71 |
|
---|
72 | public ProgressPageRenderer() {
|
---|
73 | errPanel.setAsSystemErr();
|
---|
74 | outPanel.setAsSystemOut();
|
---|
75 | }
|
---|
76 | /**
|
---|
77 | * getErr
|
---|
78 | * @return PrintStream
|
---|
79 | */
|
---|
80 | public PrintStream getErr() {
|
---|
81 | return errPanel.getOut();
|
---|
82 | }
|
---|
83 | /**
|
---|
84 | * getOut
|
---|
85 | * @return PrintStream
|
---|
86 | */
|
---|
87 | public PrintStream getOut() {
|
---|
88 | return outPanel.getOut();
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * instanceInit
|
---|
93 | */
|
---|
94 | public void reInstanceInit() {
|
---|
95 | feedBackLabel.setText(org.tp23.antinstaller.Installer.langPack.getString("click")+" "+ctx.getInstaller().getFinishButtonText()+" "+org.tp23.antinstaller.Installer.langPack.getString("toContinue"));
|
---|
96 | jToggleButton.setText(org.tp23.antinstaller.Installer.langPack.getString("showDetails"));
|
---|
97 |
|
---|
98 | jTabbedPane.removeAll();
|
---|
99 | jTabbedPane.add(org.tp23.antinstaller.Installer.langPack.getString("output"), outPanel);
|
---|
100 | jTabbedPane.add(org.tp23.antinstaller.Installer.langPack.getString("errors"), errPanel);
|
---|
101 | }
|
---|
102 |
|
---|
103 | public void instanceInit() {
|
---|
104 | showTargets = ((ProgressPage)page).isShowTargets();
|
---|
105 | contentPanel.setLayout(borderLayout1);
|
---|
106 | this.add(contentPanel,BorderLayout.CENTER);
|
---|
107 |
|
---|
108 | messagesPanel.setLayout( new BorderLayout() );
|
---|
109 | //Dimension messPanelSize = new Dimension(SizeConstants.PAGE_WIDTH,MESSAGE_PANEL_HEIGHT);
|
---|
110 | //messagesPanel.setSize(messPanelSize);
|
---|
111 | //messagesPanel.setPreferredSize(messPanelSize);
|
---|
112 | //messagesPanel.setMaximumSize(messPanelSize);
|
---|
113 | //messagesPanel.setMinimumSize(messPanelSize);
|
---|
114 |
|
---|
115 | ImageIcon progressOnIcon = createImageIcon("/resources/icons/progressOn.gif");
|
---|
116 | progressOn = new JLabel( progressOnIcon );
|
---|
117 | progressOnIcon.setImageObserver(progressOn);
|
---|
118 | progressOff = new JLabel( createImageIcon("/resources/icons/progressOff.gif") );
|
---|
119 |
|
---|
120 | //FIXME not i18n properly since the sentence is not correct ordering in German
|
---|
121 | feedBackLabel.setText(org.tp23.antinstaller.Installer.langPack.getString("click")+" "+ctx.getInstaller().getFinishButtonText()+" "+org.tp23.antinstaller.Installer.langPack.getString("toContinue"));
|
---|
122 | //feedBackLabel.setBounds(new Rectangle(115, 7, 272, 22));
|
---|
123 | jToggleButton.setText(org.tp23.antinstaller.Installer.langPack.getString("showDetails"));
|
---|
124 | //jToggleButton.setBounds(new Rectangle(5, 7, 104, 22));
|
---|
125 | //jToggleButton.setMargin(new Insets(0,0,0,0));
|
---|
126 |
|
---|
127 | messagesLeft = new JPanel();
|
---|
128 | messagesLeft.add(jToggleButton, null);
|
---|
129 | messagesLeft.add(feedBackLabel, null);
|
---|
130 |
|
---|
131 | messagesRight = new JPanel();
|
---|
132 | messagesRight.add( progressOff );
|
---|
133 |
|
---|
134 | messagesPanel.add(messagesLeft, BorderLayout.WEST);
|
---|
135 | messagesPanel.add(messagesRight, BorderLayout.EAST);
|
---|
136 |
|
---|
137 | jToggleButton.addActionListener(new ActionListener(){
|
---|
138 | public void actionPerformed(ActionEvent e) {
|
---|
139 | if(jToggleButton.isSelected()){
|
---|
140 | if(showTargets){
|
---|
141 | contentPanel.remove(progressScrollPane);
|
---|
142 | }
|
---|
143 | contentPanel.add(jTabbedPane, BorderLayout.CENTER);
|
---|
144 | contentPanel.doLayout();
|
---|
145 | contentPanel.repaint();
|
---|
146 | }
|
---|
147 | else {
|
---|
148 | contentPanel.remove(jTabbedPane);
|
---|
149 | if(showTargets){
|
---|
150 | contentPanel.add(progressScrollPane, BorderLayout.CENTER);
|
---|
151 | progressScrollPane.revalidate();
|
---|
152 | }
|
---|
153 | contentPanel.doLayout();
|
---|
154 | contentPanel.repaint();
|
---|
155 | }
|
---|
156 | }
|
---|
157 | });
|
---|
158 |
|
---|
159 | jToggleButton.setIcon(getImage("/resources/icons/showdetails.png"));
|
---|
160 | contentPanel.add(messagesPanel, BorderLayout.NORTH);
|
---|
161 |
|
---|
162 |
|
---|
163 | if(showTargets){
|
---|
164 | progressScrollPane.setBorder(BorderFactory.createEmptyBorder(10,5,5,5));
|
---|
165 | contentPanel.add(progressScrollPane, BorderLayout.CENTER);
|
---|
166 | }
|
---|
167 | jTabbedPane.add(org.tp23.antinstaller.Installer.langPack.getString("output"), outPanel);
|
---|
168 | jTabbedPane.add(org.tp23.antinstaller.Installer.langPack.getString("errors"), errPanel);
|
---|
169 | // if(OutputField.isTrue( ctx.getInstaller().getAntialiased())){
|
---|
170 | // outPanel.setAntialiased(true);
|
---|
171 | // errPanel.setAntialiased(true);
|
---|
172 | // }
|
---|
173 |
|
---|
174 |
|
---|
175 | //jTabbedPane.setVisible(false);
|
---|
176 | jTabbedPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
177 | contentPanel.setMaximumSize(new Dimension(SizeConstants.PAGE_WIDTH, Integer.MAX_VALUE));
|
---|
178 | contentPanel.setMinimumSize(new Dimension(SizeConstants.PAGE_WIDTH, 100));
|
---|
179 | contentPanel.setPreferredSize(new Dimension(SizeConstants.PAGE_WIDTH, SizeConstants.PAGE_HEIGHT-100));
|
---|
180 | //contentPanel.add(jTabbedPane, null);
|
---|
181 | //jTabbedPane.setBounds(new Rectangle(4, MESSAGE_PANEL_HEIGHT, PAGE_WIDTH-12, 214));
|
---|
182 |
|
---|
183 |
|
---|
184 | this.getNextButton().setVisible(false);
|
---|
185 | this.getFinishButton().setText(ctx.getInstaller().getFinishButtonText());
|
---|
186 | this.getFinishButton().setVisible(true);
|
---|
187 | this.getFinishButton().addActionListener(
|
---|
188 | new ActionListener() {
|
---|
189 | public void actionPerformed( ActionEvent e ) {
|
---|
190 | messagesRight.removeAll();
|
---|
191 | messagesRight.add( progressOn );
|
---|
192 | }
|
---|
193 | }
|
---|
194 | );
|
---|
195 |
|
---|
196 | }
|
---|
197 |
|
---|
198 | public void setContext(SwingInstallerContext swingCtx){
|
---|
199 | super.setContext(swingCtx);
|
---|
200 | if(showTargets){
|
---|
201 | progressPanel = new ProgressPanel(swingCtx.getInstallerContext());
|
---|
202 | progressScrollPane.getViewport().add(progressPanel);
|
---|
203 | this.swingCtx.setProgressPanel(progressPanel);
|
---|
204 | }
|
---|
205 | this.swingCtx.setFeedBackLabel(feedBackLabel);
|
---|
206 | }
|
---|
207 |
|
---|
208 |
|
---|
209 | /**
|
---|
210 | * updateInputFields
|
---|
211 | */
|
---|
212 | public void updateInputFields() {
|
---|
213 |
|
---|
214 | }
|
---|
215 |
|
---|
216 |
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * validateFields
|
---|
220 | *
|
---|
221 | * @return boolean
|
---|
222 | */
|
---|
223 | public boolean validateFields() {
|
---|
224 | return true;
|
---|
225 | }
|
---|
226 |
|
---|
227 |
|
---|
228 |
|
---|
229 | /**
|
---|
230 | * updateDefaultValues
|
---|
231 | */
|
---|
232 | public void updateDefaultValues() {
|
---|
233 | }
|
---|
234 |
|
---|
235 | /** Returns an ImageIcon, or null if the path was invalid. */
|
---|
236 | protected static ImageIcon createImageIcon(String path) {
|
---|
237 | java.net.URL imgURL = org.tp23.antinstaller.Installer.class.getResource(path);
|
---|
238 | if (imgURL != null) {
|
---|
239 | return new ImageIcon(imgURL);
|
---|
240 | } else {
|
---|
241 | System.err.println("Couldn't find file: " + path);
|
---|
242 | return null;
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | public void stopPage() {
|
---|
247 | messagesRight.removeAll();
|
---|
248 | messagesRight.add( progressOff );
|
---|
249 | }
|
---|
250 |
|
---|
251 | }
|
---|