KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > DimensionOrderEditor


1 package com.calipso.reportgenerator.userinterface;
2
3 import com.calipso.reportgenerator.common.ReportGeneratorConfiguration;
4 import javax.swing.*;
5 import java.util.Map JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.Vector JavaDoc;
8 import java.awt.event.*;
9 import java.awt.*;
10
11
12 /**
13  * Genera el orden con que se visualizan los datos de la vista
14  */

15 public class DimensionOrderEditor extends javax.swing.JDialog JavaDoc {
16   private Map JavaDoc dimensionOrders;
17   private Map JavaDoc dimensionCaptions;
18   private boolean accepted;
19
20
21   public static boolean editDimensionOrder(Frame owner, Map JavaDoc dimensionOrders, Map JavaDoc 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   /** Creates new form DimensionOrderEditor */
33   public DimensionOrderEditor(java.awt.Frame JavaDoc 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 JavaDoc dimensionOrders, Map JavaDoc dimensionCaptions) {
43     setDimensionOrders(dimensionOrders);
44     setDimensionCaptions(dimensionCaptions);
45     loadAllDimensionValues();
46     setTitle(com.calipso.reportgenerator.common.LanguageTraslator.traslate("192"));
47   }
48
49   /**
50    * Inicializa el componente
51    */

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 JavaDoc(85, 26));
101     aceptarBtn.setMinimumSize(new java.awt.Dimension JavaDoc(85, 26));
102     aceptarBtn.setPreferredSize(new java.awt.Dimension JavaDoc(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 JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
127     setSize(new java.awt.Dimension JavaDoc(412, 205));
128     setLocation((screenSize.width - 412) / 2, (screenSize.height - 205) / 2);
129   }
130
131   private void updateCurrentOrder(Object JavaDoc 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 JavaDoc(item.ascending));
156     }
157   }
158
159   private void Cancel() {
160     accepted = false;
161     setVisible(false);
162   }
163
164   /**
165    * Carga en el JComboBox los nombres de las dimensiones
166    */

167   private void loadAllDimensionValues() {
168     DefaultComboBoxModel model = new DefaultComboBoxModel(getComboModelVector());
169     dimensionComboBox.setModel(model);
170   }
171
172   private Vector JavaDoc getComboModelVector() {
173     Vector JavaDoc result = new Vector JavaDoc();
174     Iterator JavaDoc iterator = getDimensionCaptions().entrySet().iterator();
175     while (iterator.hasNext()) {
176       Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iterator.next();
177       String JavaDoc key = entry.getKey().toString();
178       String JavaDoc caption = entry.getValue().toString();
179       boolean ascending = ((Boolean JavaDoc)getDimensionOrders().get(key)).booleanValue();
180       result.add(new ComboDimensionItem(key, caption, ascending));
181     }
182     return result;
183   }
184
185   // Variables declaration - do not modify
186
private javax.swing.ButtonGroup JavaDoc buttonGroup;
187   private javax.swing.JLabel JavaDoc dimensionLabel;
188   private javax.swing.JComboBox JavaDoc dimensionComboBox;
189   private javax.swing.JButton JavaDoc cancelarBtn;
190   private javax.swing.JRadioButton JavaDoc checkAsc;
191   private javax.swing.JRadioButton JavaDoc checkDec;
192   private javax.swing.JLabel JavaDoc labelCriterio;
193   private javax.swing.JButton JavaDoc aceptarBtn;
194
195
196   public Map JavaDoc getDimensionCaptions() {
197     return dimensionCaptions;
198   }
199
200   public void setDimensionCaptions(Map JavaDoc dimensionCaptions) {
201     this.dimensionCaptions = dimensionCaptions;
202   }
203
204   public Map JavaDoc getDimensionOrders() {
205     return dimensionOrders;
206   }
207
208   public void setDimensionOrders(Map JavaDoc dimensionOrders) {
209     this.dimensionOrders = dimensionOrders;
210   }
211
212   private class ComboDimensionItem {
213     private String JavaDoc name;
214     private String JavaDoc caption;
215     private boolean ascending;
216
217     public String JavaDoc getName() {
218       return name;
219     }
220
221     public void setName(String JavaDoc name) {
222       this.name = name;
223     }
224
225     public String JavaDoc getCaption() {
226       return caption;
227     }
228
229     public void setCaption(String JavaDoc 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 JavaDoc name, String JavaDoc caption, boolean ascending) {
242       this.name = name;
243       this.caption = caption;
244       this.ascending = ascending;
245     }
246
247     public String JavaDoc toString() {
248       return caption;
249     }
250   }
251
252 }
253
Popular Tags