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.Color;
|
---|
20 | import java.awt.Dimension;
|
---|
21 | import java.awt.Font;
|
---|
22 | import java.awt.GridBagLayout;
|
---|
23 | import java.awt.GridLayout;
|
---|
24 | import javax.swing.BoxLayout;
|
---|
25 | import java.awt.FlowLayout;
|
---|
26 | import java.awt.Insets;
|
---|
27 | import java.util.ArrayList;
|
---|
28 |
|
---|
29 | import javax.swing.BorderFactory;
|
---|
30 | import javax.swing.JFrame;
|
---|
31 | import javax.swing.JLabel;
|
---|
32 | import javax.swing.JPanel;
|
---|
33 | import javax.swing.JScrollPane;
|
---|
34 | import javax.swing.JTextArea;
|
---|
35 | import javax.swing.ToolTipManager;
|
---|
36 |
|
---|
37 | import org.tp23.antinstaller.ValidationException;
|
---|
38 | import org.tp23.antinstaller.input.CommentOutput;
|
---|
39 | import org.tp23.antinstaller.input.OutputField;
|
---|
40 | import org.tp23.antinstaller.page.SimpleInputPage;
|
---|
41 | import org.tp23.antinstaller.renderer.RendererFactory;
|
---|
42 | import org.tp23.gui.GBCF;
|
---|
43 |
|
---|
44 | /**
|
---|
45 | *
|
---|
46 | * <p>This PageRenderer just renders a list of SwingInputRenderers using
|
---|
47 | * a BoxLayout </p>
|
---|
48 | * <p> </p>
|
---|
49 | * <p>Copyright: Copyright (c) 2004</p>
|
---|
50 | * <p>Company: tp23</p>
|
---|
51 | * @author Paul Hinds
|
---|
52 | * @version $Id: SimpleInputPageRenderer.java,v 1.6 2006/12/27 21:46:35 teknopaul Exp $
|
---|
53 | */
|
---|
54 | public class SimpleInputPageRenderer
|
---|
55 | extends SwingPageRenderer {
|
---|
56 |
|
---|
57 | //Prevent displayText and explanatoryText being rendered using different fonts
|
---|
58 | private static final Font defaultFont = new JLabel().getFont();
|
---|
59 |
|
---|
60 | private JPanel contentPanel = new JPanel();
|
---|
61 |
|
---|
62 |
|
---|
63 | //private GridBagLayout gridLayout = new GridBagLayout();
|
---|
64 | private BoxLayout layout = new BoxLayout(contentPanel,BoxLayout.Y_AXIS);
|
---|
65 | //private BorderLayout layout = new BorderLayout();
|
---|
66 | private GBCF cf = new GBCF(); // GridBagConstraintsFactory
|
---|
67 | private boolean overflow = false;
|
---|
68 | // used in overflow
|
---|
69 | JScrollPane scroller = null;
|
---|
70 |
|
---|
71 |
|
---|
72 | private ArrayList renderers = new ArrayList();
|
---|
73 |
|
---|
74 | public SimpleInputPageRenderer(){
|
---|
75 | }
|
---|
76 |
|
---|
77 | public boolean validateFields() throws ValidationException {
|
---|
78 | OutputField[] fields = page.getOutputField();
|
---|
79 | for (int i = 0; i < fields.length; i++) {
|
---|
80 | if(!fields[i].validate(ctx)){
|
---|
81 | SwingOutputFieldRenderer renderer = (SwingOutputFieldRenderer)renderers.get(i);
|
---|
82 | renderer.renderError();
|
---|
83 | return false;
|
---|
84 | }
|
---|
85 | }
|
---|
86 | return true;
|
---|
87 | }
|
---|
88 | public void updateInputFields(){
|
---|
89 | for (int i = 0; i < renderers.size(); i++) {
|
---|
90 | ((SwingOutputFieldRenderer)renderers.get(i)).updateInputField();
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | public void updateDefaultValues(){
|
---|
95 | for (int i = 0; i < renderers.size(); i++) {
|
---|
96 | ((SwingOutputFieldRenderer)renderers.get(i)).updateDefaultValue();
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | public void reInstanceInit() {}
|
---|
101 |
|
---|
102 | public void instanceInit() throws Exception {
|
---|
103 | ToolTipManager.sharedInstance().setInitialDelay(0);
|
---|
104 | ToolTipManager.sharedInstance().setDismissDelay(Integer.MAX_VALUE);
|
---|
105 | overflow = ((SimpleInputPage)page).isOverflow();
|
---|
106 | if(overflow){
|
---|
107 | //WARNING this causes flickering in the UI
|
---|
108 | //contentPanel.setMaximumSize(new Dimension(SizeConstants.PAGE_WIDTH - 50, SizeConstants.PAGE_HEIGHT));
|
---|
109 | scroller = new JScrollPane();
|
---|
110 | scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
---|
111 | scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
---|
112 | scroller.setBorder(BorderFactory.createCompoundBorder(
|
---|
113 | BorderFactory.createEmptyBorder(4,4,4,4),
|
---|
114 | BorderFactory.createEtchedBorder()
|
---|
115 | ));
|
---|
116 | scroller.getViewport().add(contentPanel);
|
---|
117 |
|
---|
118 | masterPanel.add( scroller, BorderLayout.CENTER );
|
---|
119 | //contentPanel.setBackground(Color.red);
|
---|
120 | }
|
---|
121 | else {
|
---|
122 | masterPanel.add(contentPanel, BorderLayout.CENTER);
|
---|
123 | contentPanel.setBorder(BorderFactory.createEmptyBorder(SizeConstants.TOP_INDENT, 4, 4, 4));
|
---|
124 | }
|
---|
125 |
|
---|
126 | OutputField[] fields = page.getOutputField();
|
---|
127 | contentPanel.setDoubleBuffered(true);
|
---|
128 | contentPanel.setLayout(layout);
|
---|
129 | int row = 0;
|
---|
130 | for (int i = 0; i < fields.length; i++) {
|
---|
131 | SwingOutputFieldRenderer renderer = RendererFactory.getSwingRenderer(fields[i]);
|
---|
132 | /* String text = fields[i].getExplanatoryText();
|
---|
133 | if(fields[i].getExplanatoryText() != null){
|
---|
134 | JTextArea area = new DisplayTextArea(contentPanel.getBackground(), contentPanel.getForeground());
|
---|
135 | //JTextArea area = new JTextArea();
|
---|
136 | //area.setBackground( new Color(0xaaaaff) );
|
---|
137 | area.setIgnoreRepaint(true);
|
---|
138 | area.setFont( defaultFont );
|
---|
139 | area.setText(text);
|
---|
140 | //area.setLineWrap(true);
|
---|
141 | contentPanel.add(area, cf.getSpan(row++));
|
---|
142 | if(fields[i] instanceof CommentOutput){
|
---|
143 | CommentOutputRenderer crenderer = (CommentOutputRenderer)renderer;
|
---|
144 | crenderer.setExplanatoryTextField(area);
|
---|
145 | if(fields[i].getDisplayText() == null){
|
---|
146 | continue;
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|
150 | */
|
---|
151 | renderer.setOutputField(fields[i]);
|
---|
152 | renderer.setInstallerContext(ctx);
|
---|
153 | renderer.initComponent(contentPanel);
|
---|
154 | row = renderer.addSelf(contentPanel, cf, row, overflow);
|
---|
155 | renderers.add(renderer);
|
---|
156 | }
|
---|
157 | contentPanel.add(new JPanel(), cf.getVertGlue(row++));
|
---|
158 | }
|
---|
159 | }
|
---|
160 | /**
|
---|
161 | * A JTextArea that is not editable and looks like a JLabel but uses
|
---|
162 | * JTextAreas ability to wrap. Also has a fixed prefered width;
|
---|
163 | * @author Paul Hinds
|
---|
164 | * @version $Id: SimpleInputPageRenderer.java,v 1.6 2006/12/27 21:46:35 teknopaul Exp $
|
---|
165 | */
|
---|
166 | class DisplayTextArea extends JTextArea{
|
---|
167 | DisplayTextArea(Color back, Color fore){
|
---|
168 | super();
|
---|
169 | this.setBackground(back);
|
---|
170 | this.setForeground(fore);
|
---|
171 | this.setLineWrap(true);
|
---|
172 | this.setWrapStyleWord(true);
|
---|
173 | this.setEditable(false);
|
---|
174 | this.setSelectionColor(back);
|
---|
175 | this.setSelectionColor(back);
|
---|
176 | this.setMargin(new Insets(5,0,0,0));
|
---|
177 | }
|
---|
178 |
|
---|
179 | /* public Dimension getPreferredSize(){
|
---|
180 | Dimension pref = super.getPreferredSize();
|
---|
181 | return new Dimension(SizeConstants.PAGE_WIDTH - 40, pref.height);
|
---|
182 | }
|
---|
183 | public Dimension getMinimumSize(){
|
---|
184 | Dimension pref = super.getMinimumSize();
|
---|
185 | return new Dimension(SizeConstants.PAGE_WIDTH - 40, pref.height);
|
---|
186 | }*/
|
---|
187 | }
|
---|