001: package com.calipso.reportgenerator.userinterface.dinamicchart;
002:
003: import javax.swing.*;
004: import java.util.*;
005: import java.awt.*;
006: import java.awt.event.*;
007:
008: /**
009: *
010: * User: soliveri
011: * Date: Aug 6, 2003
012: * Time: 4:34:52 PM
013: *
014: */
015:
016: public class DimensionValues extends JDialog implements
017: WindowFocusListener, ItemListener, MouseListener {
018:
019: private HashMap values;
020: private Set dimensionValues;
021: private HashSet excludeDimensionValues;
022: private SourceDimension parent;
023: private JScrollPane pane;
024: private boolean wasLastClickEnable;
025: private ChartPivotTableManager manager = ChartPivotTableManager
026: .getManager();
027:
028: public DimensionValues(SourceDimension parent,
029: HashSet excludeDimensionValues, Set dimensionValues) {
030: this .parent = parent;
031: this .dimensionValues = dimensionValues;
032: this .excludeDimensionValues = excludeDimensionValues;
033: addWindowFocusListener(this );
034: initialize();
035: setUndecorated(true);
036: getContentPane().add(pane);
037: }
038:
039: private void initialize() {
040: JPanel itemsPanel = new JPanel(new GridLayout(dimensionValues
041: .size(), 2));
042: if (excludeDimensionValues != null) {
043: int excludeCount = 0;
044: String currentExcludedValue = null;
045: Iterator dimensionsIterator = dimensionValues.iterator();
046: while (dimensionsIterator.hasNext()) {
047: Object currentDimension = dimensionsIterator.next();
048: if (excludeCount != excludeDimensionValues.size()) {
049: for (Iterator excludedDimensionIterator = excludeDimensionValues
050: .iterator(); excludedDimensionIterator
051: .hasNext();) {
052: currentExcludedValue = excludedDimensionIterator
053: .next().toString();
054: if (currentExcludedValue
055: .equals(currentDimension)) {
056: JCheckBox box = new JCheckBox(
057: currentExcludedValue, false);
058: box.addMouseListener(this );
059: box.addItemListener(this );
060: getValues().put(currentExcludedValue, box);
061: itemsPanel.add(box);
062: excludeCount++;
063: break;
064: }
065: }
066: } else {
067: JCheckBox box = new JCheckBox(currentDimension
068: .toString(), true);
069: box.addMouseListener(this );
070: box.addItemListener(this );
071: box.setBackground(Color.white);
072: getValues().put(currentDimension, box);
073: itemsPanel.add(box);
074: }
075: }
076: } else {
077: Iterator dimensionsIterator = dimensionValues.iterator();
078: while (dimensionsIterator.hasNext()) {
079: Object currentDimension = dimensionsIterator.next();
080: JCheckBox box = new JCheckBox(currentDimension
081: .toString(), true);
082: box.addMouseListener(this );
083: box.addItemListener(this );
084: box.setBackground(Color.white);
085: Font font = new Font("Arial", Font.BOLD, 10);
086: box.setFont(font);
087: getValues().put(currentDimension, box);
088: itemsPanel.add(box);
089: }
090: }
091: pane = new JScrollPane(itemsPanel);
092: }
093:
094: private HashMap getValues() {
095: if (values == null) {
096: values = new HashMap();
097: }
098: return values;
099: }
100:
101: public void windowOpened(WindowEvent e) {
102: }
103:
104: public void windowClosing(WindowEvent e) {
105:
106: }
107:
108: public HashSet getExcludedDimensionsValues() {
109: excludeDimensionValues = new HashSet();
110: for (Iterator iterator = getValues().keySet().iterator(); iterator
111: .hasNext();) {
112: Object currentKey = iterator.next();
113: JCheckBox box = (JCheckBox) getValues().get(currentKey);
114: if (!box.isSelected()) {
115: excludeDimensionValues.add(currentKey);
116: }
117: }
118: return excludeDimensionValues;
119: }
120:
121: public void windowGainedFocus(WindowEvent e) {
122: }
123:
124: public void windowLostFocus(WindowEvent e) {
125: manager.dimensionValuesChanged(parent,
126: getExcludedDimensionsValues());
127: setVisible(false);
128: dispose();
129: }
130:
131: public void itemStateChanged(ItemEvent e) {
132: JCheckBox box = (JCheckBox) e.getItem();
133: if (box.isSelected()) {
134: wasLastClickEnable = true;
135: } else {
136: wasLastClickEnable = false;
137: }
138: }
139:
140: public void mouseClicked(MouseEvent e) {
141: }
142:
143: public void mousePressed(MouseEvent e) {
144: }
145:
146: public void mouseReleased(MouseEvent e) {
147: if (e.isControlDown() && !wasLastClickEnable) {
148: deselectAll();
149: } else if (e.isControlDown() && wasLastClickEnable) {
150: selectAll();
151: }
152: validate();
153: }
154:
155: private void selectAll() {
156: Iterator iterator = getValues().keySet().iterator();
157: while (iterator.hasNext()) {
158: JCheckBox box = (JCheckBox) getValues()
159: .get(iterator.next());
160: box.setSelected(true);
161: }
162: }
163:
164: private void deselectAll() {
165: Iterator iterator = getValues().keySet().iterator();
166: while (iterator.hasNext()) {
167: JCheckBox box = (JCheckBox) getValues()
168: .get(iterator.next());
169: box.setSelected(false);
170: }
171: }
172:
173: public void mouseEntered(MouseEvent e) {
174: }
175:
176: public void mouseExited(MouseEvent e) {
177: }
178: }
|