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.event.ActionEvent;
|
---|
19 | import java.awt.event.ActionListener;
|
---|
20 |
|
---|
21 | import java.awt.BorderLayout;
|
---|
22 | import java.awt.FlowLayout;
|
---|
23 | import java.awt.Dimension;
|
---|
24 |
|
---|
25 | import javax.swing.JPanel;
|
---|
26 | import javax.swing.JLabel;
|
---|
27 | import javax.swing.JCheckBox;
|
---|
28 | import javax.swing.ImageIcon;
|
---|
29 | import javax.swing.JButton;
|
---|
30 | import javax.swing.JOptionPane;
|
---|
31 |
|
---|
32 | import org.tp23.antinstaller.input.InputField;
|
---|
33 | import org.tp23.antinstaller.input.OutputField;
|
---|
34 | import org.tp23.antinstaller.input.TargetInput;
|
---|
35 | import org.tp23.gui.GBCF;
|
---|
36 |
|
---|
37 | public 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 | }
|
---|