01: package com.calipso.reportgenerator.userinterface.dinamicchart;
02:
03: import com.calipso.reportgenerator.common.ReportMetricSpec;
04: import javax.swing.*;
05: import java.util.HashMap;
06: import java.util.Iterator;
07: import java.awt.*;
08: import java.awt.event.ItemListener;
09: import java.awt.event.ItemEvent;
10:
11: /**
12: *
13: * User: soliveri
14: * Date: Aug 8, 2003
15: * Time: 1:47:25 PM
16: *
17: */
18: public class ChartMetricsSelection extends JPanel implements
19: ItemListener {
20:
21: private ChartPivotTableManager manager = ChartPivotTableManager
22: .getManager();
23: private HashMap metricsValues;
24:
25: public ChartMetricsSelection(Object[] metrics) {
26: setLayout(new BoxLayout(this , BoxLayout.X_AXIS));
27: fillPanel(metrics);
28: }
29:
30: private void fillPanel(Object[] metrics) {
31: for (int i = 0; i < metrics.length; i++) {
32: ReportMetricSpec metricSpec = (ReportMetricSpec) metrics[i];
33: JCheckBox checkBox = new JCheckBox(metricSpec.getCaption(),
34: metricSpec.getVisible());
35: checkBox
36: .setFont(new Font("Arial", Font.ROMAN_BASELINE, 11));
37: checkBox.setName(metricSpec.getName());
38: checkBox.addItemListener(this );
39: getMetrics().put(metricSpec.getName(), checkBox);
40: add(checkBox);
41: }
42: }
43:
44: public void itemStateChanged(ItemEvent e) {
45: Iterator iterator = getMetrics().keySet().iterator();
46: while (iterator.hasNext()) {
47: JCheckBox box = (JCheckBox) getMetrics().get(
48: iterator.next());
49: if (e.getSource() == box) {
50: manager.metricStateChanged(box.getName(), box
51: .isSelected());
52: break;
53: }
54: }
55: }
56:
57: private HashMap getMetrics() {
58: if (metricsValues == null) {
59: metricsValues = new HashMap();
60: }
61: return metricsValues;
62: }
63: }
|