1 package com.calipso.reportgenerator.userinterface.dinamicchart; 2 3 import javax.swing.*; 4 import java.util.*; 5 import java.awt.*; 6 import java.awt.event.*; 7 8 15 16 public class DimensionValues extends JDialog implements WindowFocusListener, ItemListener, MouseListener { 17 18 private HashMap values; 19 private Set dimensionValues; 20 private HashSet excludeDimensionValues; 21 private SourceDimension parent; 22 private JScrollPane pane; 23 private boolean wasLastClickEnable; 24 private ChartPivotTableManager manager = ChartPivotTableManager.getManager(); 25 26 public DimensionValues(SourceDimension parent, HashSet excludeDimensionValues, Set dimensionValues) { 27 this.parent = parent; 28 this.dimensionValues = dimensionValues; 29 this.excludeDimensionValues = excludeDimensionValues; 30 addWindowFocusListener(this); 31 initialize(); 32 setUndecorated(true); 33 getContentPane().add(pane); 34 } 35 36 private void initialize() { 37 JPanel itemsPanel = new JPanel(new GridLayout(dimensionValues.size() , 2)); 38 if(excludeDimensionValues != null) { 39 int excludeCount = 0; 40 String currentExcludedValue = null; 41 Iterator dimensionsIterator = dimensionValues.iterator(); 42 while(dimensionsIterator.hasNext()) { 43 Object currentDimension = dimensionsIterator.next(); 44 if(excludeCount != excludeDimensionValues.size()) { 45 for(Iterator excludedDimensionIterator = excludeDimensionValues.iterator() ; excludedDimensionIterator.hasNext() ; ) { 46 currentExcludedValue = excludedDimensionIterator.next().toString(); 47 if(currentExcludedValue.equals(currentDimension)) { 48 JCheckBox box = new JCheckBox(currentExcludedValue, false); 49 box.addMouseListener(this); 50 box.addItemListener(this); 51 getValues().put(currentExcludedValue, box); 52 itemsPanel.add(box); 53 excludeCount++; 54 break; 55 } 56 } 57 } else { 58 JCheckBox box = new JCheckBox(currentDimension.toString(), true); 59 box.addMouseListener(this); 60 box.addItemListener(this); 61 box.setBackground(Color.white); 62 getValues().put(currentDimension, box); 63 itemsPanel.add(box); 64 } 65 } 66 } else { 67 Iterator dimensionsIterator = dimensionValues.iterator(); 68 while(dimensionsIterator.hasNext()) { 69 Object currentDimension = dimensionsIterator.next(); 70 JCheckBox box = new JCheckBox(currentDimension.toString(), true); 71 box.addMouseListener(this); 72 box.addItemListener(this); 73 box.setBackground(Color.white); 74 Font font = new Font("Arial", Font.BOLD, 10); 75 box.setFont(font); 76 getValues().put(currentDimension, box); 77 itemsPanel.add(box); 78 } 79 } 80 pane = new JScrollPane(itemsPanel); 81 } 82 83 private HashMap getValues() { 84 if(values == null) { 85 values = new HashMap(); 86 } 87 return values; 88 } 89 90 public void windowOpened(WindowEvent e) { 91 } 92 93 public void windowClosing(WindowEvent e) { 94 95 } 96 97 public HashSet getExcludedDimensionsValues() { 98 excludeDimensionValues = new HashSet(); 99 for(Iterator iterator = getValues().keySet().iterator() ; iterator.hasNext() ;) { 100 Object currentKey = iterator.next(); 101 JCheckBox box = (JCheckBox) getValues().get(currentKey); 102 if(!box.isSelected()) { 103 excludeDimensionValues.add(currentKey); 104 } 105 } 106 return excludeDimensionValues; 107 } 108 109 public void windowGainedFocus(WindowEvent e) { 110 } 111 112 public void windowLostFocus(WindowEvent e) { 113 manager.dimensionValuesChanged(parent, getExcludedDimensionsValues()); 114 setVisible(false); 115 dispose(); 116 } 117 118 public void itemStateChanged(ItemEvent e) { 119 JCheckBox box = (JCheckBox) e.getItem(); 120 if(box.isSelected()) { 121 wasLastClickEnable = true; 122 } else { 123 wasLastClickEnable = false; 124 } 125 } 126 127 public void mouseClicked(MouseEvent e) { 128 } 129 130 public void mousePressed(MouseEvent e) { 131 } 132 133 public void mouseReleased(MouseEvent e) { 134 if(e.isControlDown() && !wasLastClickEnable) { 135 deselectAll(); 136 } else if(e.isControlDown() && wasLastClickEnable){ 137 selectAll(); 138 } 139 validate(); 140 } 141 142 private void selectAll() { 143 Iterator iterator = getValues().keySet().iterator(); 144 while(iterator.hasNext()) { 145 JCheckBox box = (JCheckBox) getValues().get(iterator.next()); 146 box.setSelected(true); 147 } 148 } 149 150 private void deselectAll() { 151 Iterator iterator = getValues().keySet().iterator(); 152 while(iterator.hasNext()) { 153 JCheckBox box = (JCheckBox) getValues().get(iterator.next()); 154 box.setSelected(false); 155 } 156 } 157 158 public void mouseEntered(MouseEvent e) { 159 } 160 161 public void mouseExited(MouseEvent e) { 162 } 163 } 164 | Popular Tags |