001: /*
002: * Copyright 2005 Paul Hinds
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.tp23.antinstaller.renderer.swing;
017:
018: import java.awt.BorderLayout;
019: import java.awt.Dimension;
020: import java.awt.Insets;
021: import java.awt.Rectangle;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.io.PrintStream;
025:
026: import javax.swing.BorderFactory;
027: import javax.swing.JComponent;
028: import javax.swing.JLabel;
029: import javax.swing.JPanel;
030: import javax.swing.JProgressBar;
031: import javax.swing.JScrollPane;
032: import javax.swing.JTabbedPane;
033: import javax.swing.JToggleButton;
034:
035: import org.tp23.antinstaller.AIResourceBundleHelper;
036: import org.tp23.antinstaller.page.ProgressPage;
037: import org.tp23.antinstaller.renderer.AIResourceBundle;
038: import org.tp23.antinstaller.renderer.AntOutputRenderer;
039: import org.tp23.gui.widget.SystemOutJTextArea;
040:
041: /**
042: *
043: * <p>Copyright: Copyright (c) 2004</p>
044: * <p>Company: tp23</p>
045: * @todo change absolute to Border layout and panels
046: * @author Paul Hinds
047: * @version $Id: ProgressPageRenderer.java,v 1.4 2006/12/21 00:03:00 teknopaul Exp $
048: */
049: public class ProgressPageRenderer extends SwingPageRenderer implements
050: AntOutputRenderer {
051:
052: private static final AIResourceBundleHelper res = new AIResourceBundleHelper();
053: private static final int MESSAGE_PANEL_HEIGHT = 30;
054:
055: private JPanel contentPanel = new AIPanel();
056:
057: private JTabbedPane jTabbedPane = new JTabbedPane();
058: private JPanel messagesPanel = new AIPanel();
059: private BorderLayout borderLayout1 = new BorderLayout();
060: private JToggleButton jToggleButton = new JToggleButton();
061: private JLabel feedBackLabel = new JLabel();
062:
063: private SystemOutJTextArea outPanel = new SystemOutJTextArea();
064: private SystemOutJTextArea errPanel = new SystemOutJTextArea();
065:
066: private boolean showTargets = true;
067: private int showProgress = 0;
068: private JScrollPane progressScrollPane = new JScrollPane();
069: private ProgressPanel progressPanel;
070: private JProgressBar jProgressBar1 = new JProgressBar();
071:
072: public ProgressPageRenderer() {
073: errPanel.setAsSystemErr();
074: outPanel.setAsSystemOut();
075: }
076:
077: /**
078: * getErr
079: * @return PrintStream
080: */
081: public PrintStream getErr() {
082: return errPanel.getOut();
083: }
084:
085: /**
086: * getOut
087: * @return PrintStream
088: */
089: public PrintStream getOut() {
090: return outPanel.getOut();
091: }
092:
093: /**
094: * instanceInit
095: */
096: public void instanceInit() {
097: jTabbedPane.setOpaque(false);
098: //feedBackLabel.setOpaque(false);
099:
100: showTargets = ((ProgressPage) page).isShowTargets();
101: showProgress = ((ProgressPage) page).getShowProgress();
102:
103: contentPanel.setLayout(borderLayout1);
104:
105: dataPanel.add(contentPanel, BorderLayout.CENTER);
106:
107: //progressScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
108: //progressScrollPane.setOpaque(false);
109: //progressScrollPane.getViewport().setOpaque(false);
110:
111: messagesPanel.setLayout(null);
112: Dimension messPanelSize = new Dimension(
113: SizeConstants.PAGE_WIDTH, MESSAGE_PANEL_HEIGHT);
114: messagesPanel.setSize(messPanelSize);
115: messagesPanel.setPreferredSize(messPanelSize);
116: messagesPanel.setMaximumSize(messPanelSize);
117: messagesPanel.setMinimumSize(messPanelSize);
118:
119: feedBackLabel.setText(res.getMessage("click.to.continue", ctx
120: .getInstaller().getFinishButtonText()));
121: feedBackLabel.setBounds(new Rectangle(115, 7, 272, 22));
122: jToggleButton.setText(res.getString("button.show.details"));
123: jToggleButton.setBounds(new Rectangle(5, 7, 104, 22));
124: jToggleButton.setMargin(new Insets(0, 0, 0, 0));
125: messagesPanel.add(jToggleButton, null);
126: messagesPanel.add(feedBackLabel, null);
127: jToggleButton.addActionListener(new ActionListener() {
128: public void actionPerformed(ActionEvent e) {
129: if (jToggleButton.isSelected()) {
130: if (showTargets) {
131: contentPanel.remove(progressScrollPane);
132: }
133: contentPanel.add(jTabbedPane, BorderLayout.CENTER);
134: contentPanel.doLayout();
135: contentPanel.repaint();
136: } else {
137: contentPanel.remove(jTabbedPane);
138: if (showTargets) {
139: contentPanel.add(progressScrollPane,
140: BorderLayout.CENTER);
141: progressScrollPane.revalidate();
142: }
143: contentPanel.doLayout();
144: contentPanel.repaint();
145: }
146: }
147: });
148: jToggleButton
149: .setIcon(getImage("/resources/icons/showdetails.png"));
150: contentPanel.add(messagesPanel, BorderLayout.NORTH);
151:
152: if (showTargets) {
153: progressScrollPane.setBorder(BorderFactory
154: .createEmptyBorder(10, 5, 5, 5));
155: progressScrollPane.setOpaque(true);
156: contentPanel.add(progressScrollPane, BorderLayout.CENTER);
157: ((JComponent) progressScrollPane.getViewport())
158: .setOpaque(true);
159: }
160: if (showProgress > 0) {
161: contentPanel.add(jProgressBar1, BorderLayout.SOUTH);
162: jProgressBar1.setMaximum(showProgress);
163: jProgressBar1.setBorder(BorderFactory.createCompoundBorder(
164: BorderFactory.createEmptyBorder(4, 4, 4, 4),
165: jProgressBar1.getBorder()));
166: //jProgressBar1.setOpaque(false);
167: this .swingCtx.setProgressBar(jProgressBar1);
168: }
169: jTabbedPane.add(res.getString("tab.output"), outPanel);
170: jTabbedPane.add(res.getString("tab.errors"), errPanel);
171: // if(OutputField.isTrue( ctx.getInstaller().getAntialiased())){
172: // outPanel.setAntialiased(true);
173: // errPanel.setAntialiased(true);
174: // }
175:
176: //jTabbedPane.setVisible(false);
177: jTabbedPane.setBorder(BorderFactory.createEmptyBorder());
178: contentPanel.setMaximumSize(new Dimension(
179: SizeConstants.PAGE_WIDTH, Integer.MAX_VALUE));
180: contentPanel.setMinimumSize(new Dimension(
181: SizeConstants.PAGE_WIDTH, 100));
182: contentPanel.setPreferredSize(new Dimension(
183: SizeConstants.PAGE_WIDTH,
184: SizeConstants.PAGE_HEIGHT - 100));
185: //contentPanel.add(jTabbedPane, null);
186: //jTabbedPane.setBounds(new Rectangle(4, MESSAGE_PANEL_HEIGHT, PAGE_WIDTH-12, 214));
187:
188: this .getNextButton().setEnabled(false);
189: this .getFinishButton().setText(
190: ctx.getInstaller().getFinishButtonText());
191: this .getFinishButton().setEnabled(true);
192: }
193:
194: public void setContext(SwingInstallerContext swingCtx) {
195: super .setContext(swingCtx);
196: if (showTargets) {
197: progressPanel = new ProgressPanel(swingCtx
198: .getInstallerContext());
199: progressScrollPane.getViewport().add(progressPanel);
200: this .swingCtx.setProgressPanel(progressPanel);
201: }
202: this .swingCtx.setFeedBackLabel(feedBackLabel);
203: }
204:
205: /**
206: * updateInputFields
207: */
208: public void updateInputFields() {
209:
210: }
211:
212: /**
213: * validateFields
214: *
215: * @return boolean
216: */
217: public boolean validateFields() {
218: return true;
219: }
220:
221: /**
222: * updateDefaultValues
223: */
224: public void updateDefaultValues() {
225: }
226: }
|