source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/renderer/swing/TargetInputRenderer.java@ 17569

Last change on this file since 17569 was 17569, checked in by oranfry, 16 years ago

HCI changes to the installer

File size: 4.2 KB
Line 
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 */
16package org.tp23.antinstaller.renderer.swing;
17
18import java.awt.event.ActionEvent;
19import java.awt.event.ActionListener;
20
21import java.awt.BorderLayout;
22import java.awt.FlowLayout;
23import java.awt.Dimension;
24
25import javax.swing.JPanel;
26import javax.swing.JLabel;
27import javax.swing.JCheckBox;
28import javax.swing.ImageIcon;
29import javax.swing.JButton;
30import javax.swing.JOptionPane;
31
32import org.tp23.antinstaller.input.InputField;
33import org.tp23.antinstaller.input.OutputField;
34import org.tp23.antinstaller.input.TargetInput;
35import org.tp23.gui.GBCF;
36
37public class TargetInputRenderer
38 extends SwingOutputFieldRenderer {
39
40 protected TargetInput outputField;
41
42 protected AILabel fieldLabel = new AILabel();
43 protected AIShortLabel sizeLabel = new AIShortLabel();
44 protected JCheckBox targetCheckBox = new JCheckBox();
45
46 JPanel parent = null;
47 public TargetInputRenderer() {
48 }
49 public void initComponent(JPanel parent){
50 this.parent = parent;
51
52 try {
53 jbInit();
54 }
55 catch(Exception e) {
56 ctx.log(e.getMessage());
57 if(ctx.getInstaller().isVerbose()) {
58 ctx.log(e);
59 }
60
61 }
62 }
63
64
65
66 public void setOutputField(OutputField outputField) {
67 this.outputField = (TargetInput)outputField;
68 }
69 public void updateInputField(){
70 String target = outputField.getTarget();
71 int targetIdx = outputField.getIdx();
72 boolean selected = targetCheckBox.isSelected();
73 outputField.setInputResult(String.valueOf(selected));
74 if(selected && !ctx.getCurrentPage().getAllTargets().contains(target)){
75 ctx.getCurrentPage().addTarget(targetIdx, target);
76 }
77 else if(!selected && ctx.getCurrentPage().isTarget(target)){
78 ctx.getCurrentPage().removeTarget(targetIdx);
79 }
80 }
81 public void updateDefaultValue(){
82 if(!outputField.isEditted()){
83 targetCheckBox.setSelected(InputField.isTrue(outputField.getDefaultValue()));
84 }
85 }
86
87 private void jbInit() throws Exception {
88 fieldLabel.setText(outputField.getDisplayText());
89 sizeLabel.setText(outputField.getDiskRequirement());
90 sizeLabel.setMinimumSize( new Dimension( 80, 0 ) );
91 targetCheckBox.setSelected(InputField.isTrue(outputField.getDefaultValue()));
92 if(InputField.isTrue(outputField.getForce())){
93 targetCheckBox.setEnabled(false);
94 }
95
96 targetCheckBox.addActionListener(new ActionListener() {
97 public void actionPerformed(ActionEvent e) {
98 updateInputField();
99 outputField.setEditted(true);
100 }
101 });
102 }
103 public int addSelf(JPanel content,GBCF cf, int row,boolean overflow) {
104
105
106 ImageIcon helpIcon = createImageIcon("/resources/help.png");
107 JButton hlp = new JButton(org.tp23.antinstaller.Installer.langPack.getString("info"), helpIcon);
108
109 hlp.addActionListener(
110 new ActionListener() {
111 public void actionPerformed(ActionEvent e) {
112 JOptionPane.showMessageDialog(parent, outputField.getExplanatoryText(), outputField.getDisplayText(), JOptionPane.QUESTION_MESSAGE);
113 }
114 }
115 );
116
117 //hlp.setToolTipText();
118
119 JPanel spacer = new JPanel();
120 spacer.setPreferredSize(new Dimension(50, 1));
121
122 JPanel p;
123
124 p = new JPanel(new FlowLayout(FlowLayout.LEFT));
125 p.add( fieldLabel );
126 p.add( sizeLabel );
127 p.add( targetCheckBox );
128 p.add( spacer );
129 p.add( hlp );
130 content.add(p);
131
132 return ++row;
133 }
134
135
136
137 /**
138 * renderError
139 */
140 public void renderError() {
141 }
142
143 /** Returns an ImageIcon, or null if the path was invalid. */
144 protected static ImageIcon createImageIcon(String path) {
145 java.net.URL imgURL = org.tp23.antinstaller.Installer.class.getResource(path);
146 if (imgURL != null) {
147 return new ImageIcon(imgURL);
148 } else {
149 //System.err.println("Couldn't find file: " + path);
150 return null;
151 }
152 }
153
154}
Note: See TracBrowser for help on using the repository browser.