001: package com.calipso.reportgenerator.userinterface;
002:
003: import com.calipso.reportgenerator.common.ReportGeneratorConfiguration;
004: import javax.swing.*;
005: import java.util.*;
006: import java.util.List;
007: import java.awt.event.*;
008: import java.awt.*;
009:
010: public class RankMetricEditor extends javax.swing.JDialog {
011: private Map dimensionRankMetrics;
012: private Map fieldCaptions;
013: private List metricNames;
014: private boolean accepted;
015: private Map comboMetricItems;
016: private ComboMetricItem noneComboMetricItem;
017:
018: /** Creates new form RankMetricEditor */
019:
020: public static boolean editRankMetrics(Frame owner,
021: Map dimensionRankMetrics, List metricNames,
022: Map fieldCaptions, ReportGeneratorConfiguration conf) {
023: RankMetricEditor editor = new RankMetricEditor(owner, true,
024: conf);
025: editor.InitContents(dimensionRankMetrics, metricNames,
026: fieldCaptions);
027: editor.setVisible(true);
028: return editor.accepted();
029: }
030:
031: public RankMetricEditor(java.awt.Frame parent, boolean modal,
032: ReportGeneratorConfiguration conf) {
033: super (parent, modal);
034: Image icon = conf.getImage("ICON");
035: if (icon != null) {
036: parent.setIconImage(icon);
037: }
038: initComponents();
039: }
040:
041: private void initComponents() {
042: dimensionLabel = new javax.swing.JLabel();
043: metricaComboBox = new javax.swing.JComboBox();
044: metricaLabel = new javax.swing.JLabel();
045: dimensionComboBox = new javax.swing.JComboBox();
046: aceptarBtn = new javax.swing.JButton();
047: cancelBtn = new javax.swing.JButton();
048:
049: getContentPane().setLayout(null);
050:
051: dimensionLabel
052: .setText(com.calipso.reportgenerator.common.LanguageTraslator
053: .traslate("188"));
054: getContentPane().add(dimensionLabel);
055: dimensionLabel.setBounds(21, 15, 76, 16);
056:
057: getContentPane().add(dimensionComboBox);
058: dimensionComboBox.setBounds(106, 10, 192, 25);
059:
060: getContentPane().add(metricaComboBox);
061: metricaComboBox.setBounds(106, 54, 192, 25);
062:
063: metricaLabel
064: .setText(com.calipso.reportgenerator.common.LanguageTraslator
065: .traslate("133"));
066: getContentPane().add(metricaLabel);
067: metricaLabel.setBounds(21, 54, 76, 16);
068:
069: dimensionComboBox.addItemListener(new ItemListener() {
070: public void itemStateChanged(ItemEvent e) {
071: updateFromCurrentDimension((ComboDimensionRankMetricItem) e
072: .getItem());
073: }
074: });
075:
076: metricaComboBox.addItemListener(new ItemListener() {
077: public void itemStateChanged(ItemEvent e) {
078: updateDimensionRankMetric((ComboMetricItem) e.getItem());
079: }
080: });
081:
082: aceptarBtn
083: .setText(com.calipso.reportgenerator.common.LanguageTraslator
084: .traslate("112"));
085: getContentPane().add(aceptarBtn);
086: aceptarBtn.setBounds(110, 110, 88, 26);
087: aceptarBtn.addActionListener(new ActionListener() {
088: public void actionPerformed(ActionEvent e) {
089: Accept();
090: }
091: });
092: cancelBtn
093: .setText(com.calipso.reportgenerator.common.LanguageTraslator
094: .traslate("113"));
095: getContentPane().add(cancelBtn);
096: cancelBtn.setBounds(210, 110, 88, 26);
097: cancelBtn.addActionListener(new ActionListener() {
098: public void actionPerformed(ActionEvent e) {
099: Cancel();
100: }
101: });
102: pack();
103: java.awt.Dimension screenSize = java.awt.Toolkit
104: .getDefaultToolkit().getScreenSize();
105: setSize(new java.awt.Dimension(312, 168));
106: setLocation((screenSize.width - 312) / 2,
107: (screenSize.height - 168) / 2);
108: }
109:
110: private void updateDimensionRankMetric(
111: ComboMetricItem comboMetricItem) {
112: ((ComboDimensionRankMetricItem) dimensionComboBox
113: .getSelectedItem()).setRankMetricName(comboMetricItem
114: .getName());
115: }
116:
117: private void updateFromCurrentDimension(
118: ComboDimensionRankMetricItem comboDimensionRankMetricItem) {
119: metricaComboBox
120: .setSelectedItem(getComboMetricItem(comboDimensionRankMetricItem
121: .getRankMetricName()));
122: }
123:
124: private ComboMetricItem getComboMetricItem(String name) {
125: if (getComboMetricItems().containsKey(name)) {
126: return (ComboMetricItem) getComboMetricItems().get(name);
127: }
128: return getNoneComboMetricItem();
129: }
130:
131: private ComboMetricItem getNoneComboMetricItem() {
132: if (noneComboMetricItem == null) {
133: noneComboMetricItem = new ComboMetricItem(
134: "",
135: com.calipso.reportgenerator.common.LanguageTraslator
136: .traslate("187"));
137: }
138: return noneComboMetricItem;
139: }
140:
141: private void Cancel() {
142: accepted = false;
143: setVisible(false);
144: }
145:
146: private void Accept() {
147: accepted = true;
148: updateDimensionRankMetricNames();
149: setVisible(false);
150: }
151:
152: private void updateDimensionRankMetricNames() {
153: for (int i = 0; i < dimensionComboBox.getItemCount(); i++) {
154: ComboDimensionRankMetricItem item = (ComboDimensionRankMetricItem) dimensionComboBox
155: .getItemAt(i);
156: getDimensionRankMetrics().put(item.getName(),
157: item.getRankMetricName());
158: }
159: }
160:
161: private void InitContents(Map dimensionRankMetrics,
162: List metricNames, Map fieldCaptions) {
163: setDimensionRankMetrics(dimensionRankMetrics);
164: setFieldCaptions(fieldCaptions);
165: setMetricNames(metricNames);
166: loadAllDimensionValues();
167: loadAllMetricValues();
168: setTitle(com.calipso.reportgenerator.common.LanguageTraslator
169: .traslate("193"));
170: }
171:
172: private JLabel metricaLabel;
173: private JLabel dimensionLabel;
174: private JComboBox metricaComboBox;
175: private JComboBox dimensionComboBox;
176: private JButton aceptarBtn;
177: private JButton cancelBtn;
178:
179: private void loadAllDimensionValues() {
180: Vector vector = new Vector();
181: Iterator iterator = dimensionRankMetrics.entrySet().iterator();
182: while (iterator.hasNext()) {
183: Map.Entry entry = (Map.Entry) iterator.next();
184: String name = (String) entry.getKey();
185: String rankMetricName = (String) entry.getValue();
186: String caption = (String) getFieldCaptions().get(name);
187: vector.add(new ComboDimensionRankMetricItem(name, caption,
188: rankMetricName));
189: }
190: dimensionComboBox.setModel(new DefaultComboBoxModel(vector));
191: }
192:
193: private void loadAllMetricValues() {
194: Vector vector = new Vector();
195: vector.add(getNoneComboMetricItem());
196: Iterator iterator = metricNames.iterator();
197: while (iterator.hasNext()) {
198: String name = (String) iterator.next();
199: ComboMetricItem item = new ComboMetricItem(name,
200: (String) fieldCaptions.get(name));
201: vector.add(item);
202: getComboMetricItems().put(name, item);
203: }
204: metricaComboBox.setModel(new DefaultComboBoxModel(vector));
205: }
206:
207: private Map getComboMetricItems() {
208: if (comboMetricItems == null) {
209: comboMetricItems = new HashMap();
210: }
211: return comboMetricItems;
212: }
213:
214: public boolean accepted() {
215: return accepted;
216: }
217:
218: public Map getDimensionRankMetrics() {
219: return dimensionRankMetrics;
220: }
221:
222: public Map getFieldCaptions() {
223: return fieldCaptions;
224: }
225:
226: public void setDimensionRankMetrics(Map dimensionRankMetrics) {
227: this .dimensionRankMetrics = dimensionRankMetrics;
228: }
229:
230: public void setFieldCaptions(Map fieldCaptions) {
231: this .fieldCaptions = fieldCaptions;
232: }
233:
234: public List getMetricNames() {
235: return metricNames;
236: }
237:
238: public void setMetricNames(List metricNames) {
239: this .metricNames = metricNames;
240: }
241:
242: private class ComboDimensionRankMetricItem {
243: private String name;
244: private String caption;
245: private String rankMetricName;
246:
247: public ComboDimensionRankMetricItem(String name,
248: String caption, String rankMetricName) {
249: this .name = name;
250: this .caption = caption;
251: this .rankMetricName = rankMetricName;
252: }
253:
254: public String getName() {
255: return name;
256: }
257:
258: public void setName(String name) {
259: this .name = name;
260: }
261:
262: public String getCaption() {
263: return caption;
264: }
265:
266: public void setCaption(String caption) {
267: this .caption = caption;
268: }
269:
270: public String getRankMetricName() {
271: return rankMetricName;
272: }
273:
274: public void setRankMetricName(String rankMetricName) {
275: this .rankMetricName = rankMetricName;
276: }
277:
278: public String toString() {
279: return caption;
280: }
281: }
282:
283: private class ComboMetricItem {
284: private String name;
285: private String caption;
286:
287: public ComboMetricItem(String name, String caption) {
288: this .name = name;
289: this .caption = caption;
290: }
291:
292: public String getName() {
293: return name;
294: }
295:
296: public void setName(String name) {
297: this .name = name;
298: }
299:
300: public String getCaption() {
301: return caption;
302: }
303:
304: public void setCaption(String caption) {
305: this .caption = caption;
306: }
307:
308: public String toString() {
309: return caption;
310: }
311: }
312: }
|