1 32 33 package it.businesslogic.ireport.gui.subdataset; 34 35 import it.businesslogic.ireport.gui.sheet.Tag; 36 import it.businesslogic.ireport.util.*; 37 import it.businesslogic.ireport.*; 38 import it.businesslogic.ireport.util.I18n; 39 import java.util.Vector ; 40 44 public class SortFieldDialog extends javax.swing.JDialog { 45 48 private SortField tmpSortField = null; 49 50 public SortFieldDialog(java.awt.Dialog parent, boolean modal) { 51 52 super(parent, modal); 53 initComponents(); 54 jComboBoxSortBy.setEditable(true); 55 applyI18n(); 56 57 58 javax.swing.KeyStroke escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false); 59 javax.swing.Action escapeAction = new javax.swing.AbstractAction () { 60 public void actionPerformed(java.awt.event.ActionEvent e) { 61 jButtonCancelActionPerformed(e); 62 } 63 }; 64 65 getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE"); 66 getRootPane().getActionMap().put("ESCAPE", escapeAction); 67 68 69 this.getRootPane().setDefaultButton(this.jButtonOK); 71 72 applyI18n(); 73 this.pack(); 74 75 } 76 77 public void applyI18n() 78 { 79 this.setTitle( I18n.getString("sortFieldDialog.title","Sort field") ); 82 jLabelSortBy.setText( I18n.getString("sortFieldDialog.labelSortBy","Sort by...")); 83 jLabelSortType.setText( I18n.getString("sortFieldDialog.labelSortType","Sort type")); 84 this.jComboBoxSortType.removeAllItems(); 85 this.jComboBoxSortType.addItem(new Tag("Ascending",I18n.getString("sortFieldDialog.Ascending","Ascending"))); 86 this.jComboBoxSortType.addItem(new Tag("Descending",I18n.getString("sortFieldDialog.Descending","Descending"))); 87 Misc.setComboboxSelectedTagValue(jComboBoxSortType, "Ascending"); 88 jButtonOK.setText( I18n.getString("ok","Ok")); 89 jButtonCancel.setText(I18n.getString("cancel","Cancel")); 90 } 91 92 95 private void setFieldNames(Vector fields) 96 { 97 jComboBoxSortBy.removeAllItems(); 98 if (fields != null) 99 { 100 for (int i=0; i<fields.size(); ++i) 101 { 102 jComboBoxSortBy.addItem( fields.get(i) + "" ); 103 } 104 } 105 106 } 107 108 113 private void initComponents() { 115 java.awt.GridBagConstraints gridBagConstraints; 116 117 jLabelSortBy = new javax.swing.JLabel (); 118 jComboBoxSortBy = new javax.swing.JComboBox (); 119 jSeparator1 = new javax.swing.JSeparator (); 120 jPanel1 = new javax.swing.JPanel (); 121 jButtonOK = new javax.swing.JButton (); 122 jButtonCancel = new javax.swing.JButton (); 123 jLabelSortType = new javax.swing.JLabel (); 124 jComboBoxSortType = new javax.swing.JComboBox (); 125 126 getContentPane().setLayout(new java.awt.GridBagLayout ()); 127 128 setTitle("Add/modify parameter"); 129 setModal(true); 130 addWindowListener(new java.awt.event.WindowAdapter () { 131 public void windowClosing(java.awt.event.WindowEvent evt) { 132 closeDialog(evt); 133 } 134 }); 135 136 jLabelSortBy.setText("Sort by"); 137 gridBagConstraints = new java.awt.GridBagConstraints (); 138 gridBagConstraints.gridx = 0; 139 gridBagConstraints.gridy = 2; 140 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 141 gridBagConstraints.insets = new java.awt.Insets (4, 4, 0, 4); 142 getContentPane().add(jLabelSortBy, gridBagConstraints); 143 144 jComboBoxSortBy.setEditable(true); 145 jComboBoxSortBy.setPreferredSize(new java.awt.Dimension (250, 22)); 146 gridBagConstraints = new java.awt.GridBagConstraints (); 147 gridBagConstraints.gridx = 0; 148 gridBagConstraints.gridy = 3; 149 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 150 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 151 gridBagConstraints.weightx = 1.0; 152 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 4); 153 getContentPane().add(jComboBoxSortBy, gridBagConstraints); 154 155 jSeparator1.setMinimumSize(new java.awt.Dimension (2, 2)); 156 jSeparator1.setPreferredSize(new java.awt.Dimension (2, 2)); 157 gridBagConstraints = new java.awt.GridBagConstraints (); 158 gridBagConstraints.gridx = 0; 159 gridBagConstraints.gridy = 8; 160 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 161 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; 162 gridBagConstraints.weighty = 1.0; 163 getContentPane().add(jSeparator1, gridBagConstraints); 164 165 jPanel1.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.RIGHT)); 166 167 jButtonOK.setMnemonic('o'); 168 jButtonOK.setText("OK"); 169 jButtonOK.addActionListener(new java.awt.event.ActionListener () { 170 public void actionPerformed(java.awt.event.ActionEvent evt) { 171 jButtonOKActionPerformed(evt); 172 } 173 }); 174 175 jPanel1.add(jButtonOK); 176 177 jButtonCancel.setMnemonic('c'); 178 jButtonCancel.setText("Cancel"); 179 jButtonCancel.addActionListener(new java.awt.event.ActionListener () { 180 public void actionPerformed(java.awt.event.ActionEvent evt) { 181 jButtonCancelActionPerformed(evt); 182 } 183 }); 184 185 jPanel1.add(jButtonCancel); 186 187 gridBagConstraints = new java.awt.GridBagConstraints (); 188 gridBagConstraints.gridx = 0; 189 gridBagConstraints.gridy = 9; 190 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 191 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; 192 gridBagConstraints.weightx = 1.0; 193 getContentPane().add(jPanel1, gridBagConstraints); 194 195 jLabelSortType.setText("Sort type"); 196 gridBagConstraints = new java.awt.GridBagConstraints (); 197 gridBagConstraints.gridx = 0; 198 gridBagConstraints.gridy = 4; 199 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 200 gridBagConstraints.insets = new java.awt.Insets (4, 4, 0, 4); 201 getContentPane().add(jLabelSortType, gridBagConstraints); 202 203 gridBagConstraints = new java.awt.GridBagConstraints (); 204 gridBagConstraints.gridx = 0; 205 gridBagConstraints.gridy = 5; 206 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 207 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 208 gridBagConstraints.weightx = 1.0; 209 gridBagConstraints.insets = new java.awt.Insets (4, 4, 8, 4); 210 getContentPane().add(jComboBoxSortType, gridBagConstraints); 211 212 pack(); 213 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 214 java.awt.Dimension dialogSize = getSize(); 215 setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2); 216 } 218 private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) { setVisible(false); 220 this.setDialogResult( javax.swing.JOptionPane.CANCEL_OPTION); 221 dispose(); 222 } 224 private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) { 226 String fieldName = (String )this.jComboBoxSortBy.getSelectedItem(); 227 if (fieldName == null) fieldName=""; 228 fieldName = fieldName.trim(); 229 230 if (fieldName.length() <= 0) 231 { 232 javax.swing.JOptionPane.showMessageDialog(this, 233 I18n.getString("sortFieldDialog.messageNotValidField","Please insert a valid field name!"), 234 I18n.getString("sortFieldDialog.messageTitleNotValidField","Invalid field!"), 235 javax.swing.JOptionPane.WARNING_MESSAGE ); 236 return; 237 } 238 239 tmpSortField = new SortField( 240 fieldName, 241 jComboBoxSortType.getSelectedIndex() == 1 242 ); 243 244 setVisible(false); 245 this.setDialogResult( javax.swing.JOptionPane.OK_OPTION); 246 dispose(); 247 } 249 250 private void closeDialog(java.awt.event.WindowEvent evt) { setVisible(false); 252 this.setDialogResult( javax.swing.JOptionPane.CLOSED_OPTION); 253 dispose(); 254 } 256 257 261 public int getDialogResult() { 262 return dialogResult; 263 } 264 265 269 public void setDialogResult(int dialogResult) { 270 this.dialogResult = dialogResult; 271 } 272 273 private javax.swing.JButton jButtonCancel; 275 private javax.swing.JButton jButtonOK; 276 private javax.swing.JComboBox jComboBoxSortBy; 277 private javax.swing.JComboBox jComboBoxSortType; 278 private javax.swing.JLabel jLabelSortBy; 279 private javax.swing.JLabel jLabelSortType; 280 private javax.swing.JPanel jPanel1; 281 private javax.swing.JSeparator jSeparator1; 282 284 private int dialogResult; 285 286 public void setSubDataset(SubDataset subDataset) { 287 288 setFieldNames( subDataset.getFields() ); 291 292 } 293 294 297 public SortField getSortField() { 298 return tmpSortField; 299 } 300 301 public void setSortField(SortField tmpSortField) { 302 this.tmpSortField = new SortField(tmpSortField); 303 this.jComboBoxSortBy.setSelectedItem( tmpSortField.getFieldName() ); 304 this.jComboBoxSortType.setSelectedIndex( (tmpSortField.isDesc() ? 1 : 0) ); 305 } 306 307 } 308 | Popular Tags |