001: package com.calipso.reportgenerator.userinterface;
002:
003: import com.calipso.reportgenerator.common.ReportGeneratorConfiguration;
004: import javax.swing.*;
005: import java.util.Map;
006: import java.util.Iterator;
007: import java.util.Vector;
008: import java.awt.event.*;
009: import java.awt.*;
010:
011: /**
012: * Genera el orden con que se visualizan los datos de la vista
013: */
014: public class DimensionOrderEditor extends javax.swing.JDialog {
015: private Map dimensionOrders;
016: private Map dimensionCaptions;
017: private boolean accepted;
018:
019: public static boolean editDimensionOrder(Frame owner,
020: Map dimensionOrders, Map dimensionCaptions,
021: ReportGeneratorConfiguration conf) {
022: DimensionOrderEditor editor = new DimensionOrderEditor(owner,
023: true, conf);
024: editor.initContents(dimensionOrders, dimensionCaptions);
025: editor.setVisible(true);
026: return editor.accepted();
027: }
028:
029: private boolean accepted() {
030: return accepted;
031: }
032:
033: /** Creates new form DimensionOrderEditor */
034: public DimensionOrderEditor(java.awt.Frame parent, boolean modal,
035: ReportGeneratorConfiguration conf) {
036: super (parent, modal);
037: Image icon = conf.getImage("icon");
038: if (icon != null) {
039: parent.setIconImage(icon);
040: }
041: initComponents();
042: }
043:
044: private void initContents(Map dimensionOrders, Map dimensionCaptions) {
045: setDimensionOrders(dimensionOrders);
046: setDimensionCaptions(dimensionCaptions);
047: loadAllDimensionValues();
048: setTitle(com.calipso.reportgenerator.common.LanguageTraslator
049: .traslate("192"));
050: }
051:
052: /**
053: * Inicializa el componente
054: */
055: private void initComponents() {
056: buttonGroup = new ButtonGroup();
057: dimensionLabel = new JLabel();
058: dimensionComboBox = new JComboBox();
059: aceptarBtn = new JButton();
060: cancelarBtn = new JButton();
061: checkAsc = new JRadioButton();
062: labelCriterio = new JLabel();
063: checkDec = new JRadioButton();
064: getContentPane().setLayout(null);
065: checkAsc.setSelected(true);
066:
067: aceptarBtn.addActionListener(new ActionListener() {
068: public void actionPerformed(ActionEvent e) {
069: Accept();
070: }
071: });
072:
073: cancelarBtn.addActionListener(new ActionListener() {
074: public void actionPerformed(ActionEvent e) {
075: Cancel();
076: }
077: });
078: checkDec.addActionListener(new ActionListener() {
079: public void actionPerformed(ActionEvent e) {
080: selectRadioButton((JRadioButton) e.getSource());
081:
082: }
083: });
084: checkAsc.addActionListener(new ActionListener() {
085: public void actionPerformed(ActionEvent e) {
086: selectRadioButton((JRadioButton) e.getSource());
087: }
088: });
089:
090: dimensionComboBox.addItemListener(new ItemListener() {
091: public void itemStateChanged(ItemEvent e) {
092: updateCurrentOrder(e.getItem());
093: }
094: });
095: dimensionLabel
096: .setText(com.calipso.reportgenerator.common.LanguageTraslator
097: .traslate("188"));
098: getContentPane().add(dimensionLabel);
099: dimensionLabel.setBounds(21, 24, 74, 16);
100:
101: getContentPane().add(dimensionComboBox);
102: dimensionComboBox.setBounds(106, 22, 282, 25);
103:
104: aceptarBtn
105: .setText(com.calipso.reportgenerator.common.LanguageTraslator
106: .traslate("112"));
107: aceptarBtn.setMaximumSize(new java.awt.Dimension(85, 26));
108: aceptarBtn.setMinimumSize(new java.awt.Dimension(85, 26));
109: aceptarBtn.setPreferredSize(new java.awt.Dimension(85, 26));
110: getContentPane().add(aceptarBtn);
111: aceptarBtn.setBounds(196, 140, 85, 26);
112:
113: cancelarBtn
114: .setText(com.calipso.reportgenerator.common.LanguageTraslator
115: .traslate("113"));
116: getContentPane().add(cancelarBtn);
117: cancelarBtn.setBounds(292, 142, 92, 26);
118:
119: checkAsc
120: .setText(com.calipso.reportgenerator.common.LanguageTraslator
121: .traslate("189"));
122: checkAsc.setName("A");
123: buttonGroup.add(checkAsc);
124: getContentPane().add(checkAsc);
125: checkAsc.setBounds(126, 80, 93, 24);
126: labelCriterio
127: .setText(com.calipso.reportgenerator.common.LanguageTraslator
128: .traslate("191"));
129: getContentPane().add(labelCriterio);
130: labelCriterio.setBounds(22, 80, 60, 16);
131:
132: checkDec
133: .setText(com.calipso.reportgenerator.common.LanguageTraslator
134: .traslate("190"));
135: checkDec.setName("D");
136: buttonGroup.add(checkDec);
137: getContentPane().add(checkDec);
138: checkDec.setBounds(252, 82, 104, 24);
139:
140: pack();
141: java.awt.Dimension screenSize = java.awt.Toolkit
142: .getDefaultToolkit().getScreenSize();
143: setSize(new java.awt.Dimension(412, 205));
144: setLocation((screenSize.width - 412) / 2,
145: (screenSize.height - 205) / 2);
146: }
147:
148: private void updateCurrentOrder(Object item) {
149: ComboDimensionItem comboItem = (ComboDimensionItem) item;
150: if (comboItem.ascending) {
151: checkAsc.setSelected(true);
152: } else {
153: checkDec.setSelected(true);
154: }
155: }
156:
157: private void selectRadioButton(JRadioButton radioButton) {
158: radioButton.setSelected(true);
159: ((ComboDimensionItem) dimensionComboBox.getSelectedItem())
160: .setAscending(checkAsc.isSelected());
161: }
162:
163: private void Accept() {
164: accepted = true;
165: updateDimensionOrder();
166: setVisible(false);
167: }
168:
169: private void updateDimensionOrder() {
170: for (int i = 0; i < dimensionComboBox.getItemCount(); i++) {
171: ComboDimensionItem item = (ComboDimensionItem) dimensionComboBox
172: .getItemAt(i);
173: getDimensionOrders().put(item.getName(),
174: new Boolean(item.ascending));
175: }
176: }
177:
178: private void Cancel() {
179: accepted = false;
180: setVisible(false);
181: }
182:
183: /**
184: * Carga en el JComboBox los nombres de las dimensiones
185: */
186: private void loadAllDimensionValues() {
187: DefaultComboBoxModel model = new DefaultComboBoxModel(
188: getComboModelVector());
189: dimensionComboBox.setModel(model);
190: }
191:
192: private Vector getComboModelVector() {
193: Vector result = new Vector();
194: Iterator iterator = getDimensionCaptions().entrySet()
195: .iterator();
196: while (iterator.hasNext()) {
197: Map.Entry entry = (Map.Entry) iterator.next();
198: String key = entry.getKey().toString();
199: String caption = entry.getValue().toString();
200: boolean ascending = ((Boolean) getDimensionOrders()
201: .get(key)).booleanValue();
202: result.add(new ComboDimensionItem(key, caption, ascending));
203: }
204: return result;
205: }
206:
207: // Variables declaration - do not modify
208: private javax.swing.ButtonGroup buttonGroup;
209: private javax.swing.JLabel dimensionLabel;
210: private javax.swing.JComboBox dimensionComboBox;
211: private javax.swing.JButton cancelarBtn;
212: private javax.swing.JRadioButton checkAsc;
213: private javax.swing.JRadioButton checkDec;
214: private javax.swing.JLabel labelCriterio;
215: private javax.swing.JButton aceptarBtn;
216:
217: public Map getDimensionCaptions() {
218: return dimensionCaptions;
219: }
220:
221: public void setDimensionCaptions(Map dimensionCaptions) {
222: this .dimensionCaptions = dimensionCaptions;
223: }
224:
225: public Map getDimensionOrders() {
226: return dimensionOrders;
227: }
228:
229: public void setDimensionOrders(Map dimensionOrders) {
230: this .dimensionOrders = dimensionOrders;
231: }
232:
233: private class ComboDimensionItem {
234: private String name;
235: private String caption;
236: private boolean ascending;
237:
238: public String getName() {
239: return name;
240: }
241:
242: public void setName(String name) {
243: this .name = name;
244: }
245:
246: public String getCaption() {
247: return caption;
248: }
249:
250: public void setCaption(String caption) {
251: this .caption = caption;
252: }
253:
254: public boolean isAscending() {
255: return ascending;
256: }
257:
258: public void setAscending(boolean ascending) {
259: this .ascending = ascending;
260: }
261:
262: public ComboDimensionItem(String name, String caption,
263: boolean ascending) {
264: this .name = name;
265: this .caption = caption;
266: this .ascending = ascending;
267: }
268:
269: public String toString() {
270: return caption;
271: }
272: }
273:
274: }
|