1 package com.calipso.reportgenerator.userinterface; 2 3 import com.calipso.reportgenerator.common.ReportGeneratorConfiguration; 4 import javax.swing.*; 5 import java.util.Map ; 6 import java.util.Iterator ; 7 import java.util.Vector ; 8 import java.awt.event.*; 9 import java.awt.*; 10 11 12 15 public class DimensionOrderEditor extends javax.swing.JDialog { 16 private Map dimensionOrders; 17 private Map dimensionCaptions; 18 private boolean accepted; 19 20 21 public static boolean editDimensionOrder(Frame owner, Map dimensionOrders, Map dimensionCaptions, ReportGeneratorConfiguration conf) { 22 DimensionOrderEditor editor = new DimensionOrderEditor(owner, true, conf); 23 editor.initContents(dimensionOrders, dimensionCaptions); 24 editor.setVisible(true); 25 return editor.accepted(); 26 } 27 28 private boolean accepted() { 29 return accepted; 30 } 31 32 33 public DimensionOrderEditor(java.awt.Frame parent, boolean modal, ReportGeneratorConfiguration conf) { 34 super(parent, modal); 35 Image icon = conf.getImage("icon"); 36 if(icon != null) { 37 parent.setIconImage(icon); 38 } 39 initComponents(); 40 } 41 42 private void initContents(Map dimensionOrders, Map dimensionCaptions) { 43 setDimensionOrders(dimensionOrders); 44 setDimensionCaptions(dimensionCaptions); 45 loadAllDimensionValues(); 46 setTitle(com.calipso.reportgenerator.common.LanguageTraslator.traslate("192")); 47 } 48 49 52 private void initComponents() { 53 buttonGroup = new ButtonGroup(); 54 dimensionLabel = new JLabel(); 55 dimensionComboBox = new JComboBox(); 56 aceptarBtn = new JButton(); 57 cancelarBtn = new JButton(); 58 checkAsc = new JRadioButton(); 59 labelCriterio = new JLabel(); 60 checkDec = new JRadioButton(); 61 getContentPane().setLayout(null); 62 checkAsc.setSelected(true); 63 64 aceptarBtn.addActionListener(new ActionListener() { 65 public void actionPerformed(ActionEvent e) { 66 Accept(); 67 } 68 }); 69 70 cancelarBtn.addActionListener(new ActionListener() { 71 public void actionPerformed(ActionEvent e) { 72 Cancel(); 73 } 74 }); 75 checkDec.addActionListener(new ActionListener() { 76 public void actionPerformed(ActionEvent e) { 77 selectRadioButton((JRadioButton)e.getSource()); 78 79 } 80 }); 81 checkAsc.addActionListener(new ActionListener() { 82 public void actionPerformed(ActionEvent e) { 83 selectRadioButton((JRadioButton)e.getSource()); 84 } 85 }); 86 87 dimensionComboBox.addItemListener(new ItemListener() { 88 public void itemStateChanged(ItemEvent e) { 89 updateCurrentOrder(e.getItem()); 90 } 91 }); 92 dimensionLabel.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("188")); 93 getContentPane().add(dimensionLabel); 94 dimensionLabel.setBounds(21, 24, 74, 16); 95 96 getContentPane().add(dimensionComboBox); 97 dimensionComboBox.setBounds(106, 22, 282, 25); 98 99 aceptarBtn.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("112")); 100 aceptarBtn.setMaximumSize(new java.awt.Dimension (85, 26)); 101 aceptarBtn.setMinimumSize(new java.awt.Dimension (85, 26)); 102 aceptarBtn.setPreferredSize(new java.awt.Dimension (85, 26)); 103 getContentPane().add(aceptarBtn); 104 aceptarBtn.setBounds(196, 140, 85, 26); 105 106 cancelarBtn.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("113")); 107 getContentPane().add(cancelarBtn); 108 cancelarBtn.setBounds(292, 142, 92, 26); 109 110 checkAsc.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("189")); 111 checkAsc.setName("A"); 112 buttonGroup.add(checkAsc); 113 getContentPane().add(checkAsc); 114 checkAsc.setBounds(126, 80, 93, 24); 115 labelCriterio.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("191")); 116 getContentPane().add(labelCriterio); 117 labelCriterio.setBounds(22, 80, 60, 16); 118 119 checkDec.setText(com.calipso.reportgenerator.common.LanguageTraslator.traslate("190")); 120 checkDec.setName("D"); 121 buttonGroup.add(checkDec); 122 getContentPane().add(checkDec); 123 checkDec.setBounds(252, 82, 104, 24); 124 125 pack(); 126 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 127 setSize(new java.awt.Dimension (412, 205)); 128 setLocation((screenSize.width - 412) / 2, (screenSize.height - 205) / 2); 129 } 130 131 private void updateCurrentOrder(Object item) { 132 ComboDimensionItem comboItem = (ComboDimensionItem) item; 133 if (comboItem.ascending) { 134 checkAsc.setSelected(true); 135 } 136 else { 137 checkDec.setSelected(true); 138 } 139 } 140 141 private void selectRadioButton(JRadioButton radioButton) { 142 radioButton.setSelected(true); 143 ((ComboDimensionItem)dimensionComboBox.getSelectedItem()).setAscending(checkAsc.isSelected()); 144 } 145 146 private void Accept() { 147 accepted = true; 148 updateDimensionOrder(); 149 setVisible(false); 150 } 151 152 private void updateDimensionOrder() { 153 for (int i = 0; i < dimensionComboBox.getItemCount(); i++){ 154 ComboDimensionItem item = (ComboDimensionItem) dimensionComboBox.getItemAt(i); 155 getDimensionOrders().put(item.getName(), new Boolean (item.ascending)); 156 } 157 } 158 159 private void Cancel() { 160 accepted = false; 161 setVisible(false); 162 } 163 164 167 private void loadAllDimensionValues() { 168 DefaultComboBoxModel model = new DefaultComboBoxModel(getComboModelVector()); 169 dimensionComboBox.setModel(model); 170 } 171 172 private Vector getComboModelVector() { 173 Vector result = new Vector (); 174 Iterator iterator = getDimensionCaptions().entrySet().iterator(); 175 while (iterator.hasNext()) { 176 Map.Entry entry = (Map.Entry ) iterator.next(); 177 String key = entry.getKey().toString(); 178 String caption = entry.getValue().toString(); 179 boolean ascending = ((Boolean )getDimensionOrders().get(key)).booleanValue(); 180 result.add(new ComboDimensionItem(key, caption, ascending)); 181 } 182 return result; 183 } 184 185 private javax.swing.ButtonGroup buttonGroup; 187 private javax.swing.JLabel dimensionLabel; 188 private javax.swing.JComboBox dimensionComboBox; 189 private javax.swing.JButton cancelarBtn; 190 private javax.swing.JRadioButton checkAsc; 191 private javax.swing.JRadioButton checkDec; 192 private javax.swing.JLabel labelCriterio; 193 private javax.swing.JButton aceptarBtn; 194 195 196 public Map getDimensionCaptions() { 197 return dimensionCaptions; 198 } 199 200 public void setDimensionCaptions(Map dimensionCaptions) { 201 this.dimensionCaptions = dimensionCaptions; 202 } 203 204 public Map getDimensionOrders() { 205 return dimensionOrders; 206 } 207 208 public void setDimensionOrders(Map dimensionOrders) { 209 this.dimensionOrders = dimensionOrders; 210 } 211 212 private class ComboDimensionItem { 213 private String name; 214 private String caption; 215 private boolean ascending; 216 217 public String getName() { 218 return name; 219 } 220 221 public void setName(String name) { 222 this.name = name; 223 } 224 225 public String getCaption() { 226 return caption; 227 } 228 229 public void setCaption(String caption) { 230 this.caption = caption; 231 } 232 233 public boolean isAscending() { 234 return ascending; 235 } 236 237 public void setAscending(boolean ascending) { 238 this.ascending = ascending; 239 } 240 241 public ComboDimensionItem(String name, String caption, boolean ascending) { 242 this.name = name; 243 this.caption = caption; 244 this.ascending = ascending; 245 } 246 247 public String toString() { 248 return caption; 249 } 250 } 251 252 } 253 | Popular Tags |