1 32 33 package it.businesslogic.ireport.gui; 34 35 import it.businesslogic.ireport.*; 36 import it.businesslogic.ireport.SubDataset; 37 38 import javax.swing.table.*; 39 import javax.swing.*; 40 import javax.swing.event.*; 41 import it.businesslogic.ireport.*; 42 import it.businesslogic.ireport.util.*; 43 44 import java.util.*; 45 49 public class PropertiesDialog extends javax.swing.JDialog { 50 51 52 public PropertiesDialog(java.awt.Dialog parent, boolean modal) { 53 super(parent, modal); 54 initAll(); 55 } 56 public PropertiesDialog(java.awt.Frame parent, boolean modal) { 57 super(parent, modal); 58 initAll(); 59 } 60 61 public void initAll() 62 { 63 initComponents(); 64 this.setSize(420, 250); 65 68 74 75 DefaultListSelectionModel dlsm = (DefaultListSelectionModel)this.jTableProperties.getSelectionModel(); 76 dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener () { 77 public void valueChanged(ListSelectionEvent e) { 78 jTablePropertiesListSelectionValueChanged(e); 79 } 80 }); 81 82 applyI18n(); 83 it.businesslogic.ireport.util.Misc.centerFrame(this); 85 86 87 javax.swing.KeyStroke escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false); 88 javax.swing.Action escapeAction = new javax.swing.AbstractAction () { 89 public void actionPerformed(java.awt.event.ActionEvent e) { 90 jButtonCloseActionPerformed(e); 91 } 92 }; 93 94 getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE"); 95 getRootPane().getActionMap().put("ESCAPE", escapeAction); 96 97 98 this.getRootPane().setDefaultButton(this.jButtonClose); 100 101 } 102 103 104 public void jTablePropertiesListSelectionValueChanged(javax.swing.event.ListSelectionEvent e) 105 { 106 if (this.jTableProperties.getSelectedRowCount() > 0) { 107 this.jButtonModifyProperty.setEnabled(true); 108 this.jButtonDeleteProperty.setEnabled(true); 109 } 110 else { 111 this.jButtonModifyProperty.setEnabled(false); 112 this.jButtonDeleteProperty.setEnabled(false); 113 } 114 } 115 116 121 private void initComponents() { 123 java.awt.GridBagConstraints gridBagConstraints; 124 125 jPanelFields = new javax.swing.JPanel (); 126 jScrollPane3 = new javax.swing.JScrollPane (); 127 jTableProperties = new it.businesslogic.ireport.gui.JDragTable(); 128 jPanelButtons2 = new javax.swing.JPanel (); 129 jButtonNewProperty = new javax.swing.JButton (); 130 jButtonModifyProperty = new javax.swing.JButton (); 131 jButtonDeleteProperty = new javax.swing.JButton (); 132 jPanel1 = new javax.swing.JPanel (); 133 jButtonClose = new javax.swing.JButton (); 134 135 setTitle("Values"); 136 addWindowListener(new java.awt.event.WindowAdapter () { 137 public void windowClosing(java.awt.event.WindowEvent evt) { 138 closeDialog(evt); 139 } 140 }); 141 142 jPanelFields.setLayout(new java.awt.BorderLayout ()); 143 144 jScrollPane3.setBackground(new java.awt.Color (255, 255, 255)); 145 jScrollPane3.setPreferredSize(new java.awt.Dimension (32767, 32767)); 146 jScrollPane3.addMouseListener(new java.awt.event.MouseAdapter () { 147 public void mouseClicked(java.awt.event.MouseEvent evt) { 148 jScrollPane3MouseClicked(evt); 149 } 150 }); 151 152 jTableProperties.setModel(new javax.swing.table.DefaultTableModel ( 153 new Object [][] { 154 155 }, 156 new String [] { 157 "Name", "Value" 158 } 159 ) { 160 Class [] types = new Class [] { 161 java.lang.Object .class, java.lang.String .class 162 }; 163 boolean[] canEdit = new boolean [] { 164 false, false 165 }; 166 167 public Class getColumnClass(int columnIndex) { 168 return types [columnIndex]; 169 } 170 171 public boolean isCellEditable(int rowIndex, int columnIndex) { 172 return canEdit [columnIndex]; 173 } 174 }); 175 jTableProperties.addMouseListener(new java.awt.event.MouseAdapter () { 176 public void mouseClicked(java.awt.event.MouseEvent evt) { 177 jTablePropertiesMouseClicked(evt); 178 } 179 }); 180 181 jScrollPane3.setViewportView(jTableProperties); 182 183 jPanelFields.add(jScrollPane3, java.awt.BorderLayout.CENTER); 184 185 jPanelButtons2.setLayout(new java.awt.GridBagLayout ()); 186 187 jPanelButtons2.setPreferredSize(new java.awt.Dimension (100, 100)); 188 jPanelButtons2.setMinimumSize(new java.awt.Dimension (100, 10)); 189 jButtonNewProperty.setText("New"); 190 jButtonNewProperty.addActionListener(new java.awt.event.ActionListener () { 191 public void actionPerformed(java.awt.event.ActionEvent evt) { 192 jButtonNewPropertyActionPerformed(evt); 193 } 194 }); 195 196 gridBagConstraints = new java.awt.GridBagConstraints (); 197 gridBagConstraints.gridx = 0; 198 gridBagConstraints.gridy = 0; 199 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 200 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 201 gridBagConstraints.insets = new java.awt.Insets (5, 4, 0, 4); 202 jPanelButtons2.add(jButtonNewProperty, gridBagConstraints); 203 204 jButtonModifyProperty.setText("Modify"); 205 jButtonModifyProperty.setEnabled(false); 206 jButtonModifyProperty.addActionListener(new java.awt.event.ActionListener () { 207 public void actionPerformed(java.awt.event.ActionEvent evt) { 208 jButtonModifyPropertyActionPerformed(evt); 209 } 210 }); 211 212 gridBagConstraints = new java.awt.GridBagConstraints (); 213 gridBagConstraints.gridx = 0; 214 gridBagConstraints.gridy = 1; 215 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 216 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 217 gridBagConstraints.insets = new java.awt.Insets (3, 4, 0, 4); 218 jPanelButtons2.add(jButtonModifyProperty, gridBagConstraints); 219 220 jButtonDeleteProperty.setText("Delete"); 221 jButtonDeleteProperty.setEnabled(false); 222 jButtonDeleteProperty.addActionListener(new java.awt.event.ActionListener () { 223 public void actionPerformed(java.awt.event.ActionEvent evt) { 224 jButtonDeletePropertyActionPerformed(evt); 225 } 226 }); 227 228 gridBagConstraints = new java.awt.GridBagConstraints (); 229 gridBagConstraints.gridx = 0; 230 gridBagConstraints.gridy = 2; 231 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 232 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 233 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 4); 234 jPanelButtons2.add(jButtonDeleteProperty, gridBagConstraints); 235 236 jPanel1.setLayout(new java.awt.BorderLayout ()); 237 238 gridBagConstraints = new java.awt.GridBagConstraints (); 239 gridBagConstraints.gridx = 0; 240 gridBagConstraints.gridy = 3; 241 gridBagConstraints.weighty = 1.0; 242 jPanelButtons2.add(jPanel1, gridBagConstraints); 243 244 jButtonClose.setMnemonic('c'); 245 jButtonClose.setText("Close"); 246 jButtonClose.addActionListener(new java.awt.event.ActionListener () { 247 public void actionPerformed(java.awt.event.ActionEvent evt) { 248 jButtonCloseActionPerformed(evt); 249 } 250 }); 251 252 gridBagConstraints = new java.awt.GridBagConstraints (); 253 gridBagConstraints.gridx = 0; 254 gridBagConstraints.gridy = 4; 255 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 256 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 257 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 4); 258 jPanelButtons2.add(jButtonClose, gridBagConstraints); 259 260 jPanelFields.add(jPanelButtons2, java.awt.BorderLayout.EAST); 261 262 getContentPane().add(jPanelFields, java.awt.BorderLayout.CENTER); 263 264 pack(); 265 } 267 private void jButtonCloseActionPerformed(java.awt.event.ActionEvent evt) { setVisible(false); 269 } 271 private void jScrollPane3MouseClicked(java.awt.event.MouseEvent evt) { } 275 private void jTablePropertiesMouseClicked(java.awt.event.MouseEvent evt) { if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1 && jTableProperties.getSelectedRow() >=0 ) { 277 jButtonModifyPropertyActionPerformed(new java.awt.event.ActionEvent ( jButtonModifyProperty,0, "")); 278 } 279 } 281 private void jButtonNewPropertyActionPerformed(java.awt.event.ActionEvent evt) { java.awt.Frame parent = Misc.frameFromComponent(this); 283 JRPropertyDialog jrpd = new JRPropertyDialog( parent, true); 284 jrpd.setVisible(true); 285 286 if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { 287 JRProperty property = jrpd.getProperty(); 288 this.getDataset().addJRProperty( property ); 289 this.updateProperties(); 290 } 291 } 293 private void jButtonModifyPropertyActionPerformed(java.awt.event.ActionEvent evt) { JRProperty property = (JRProperty)jTableProperties.getValueAt( jTableProperties.getSelectedRow(), 0); 295 java.awt.Frame parent = Misc.frameFromComponent(this); 296 JRPropertyDialog jrpd = new JRPropertyDialog(parent, true); 297 jrpd.setProperty( property ); 298 jrpd.setVisible(true); 299 300 if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) { 301 property.setName( jrpd.getProperty().getName() ); 302 303 304 property.setValue( jrpd.getProperty().getValue() ); 305 306 this.updateProperties(); 307 } 308 } 310 private void jButtonDeletePropertyActionPerformed(java.awt.event.ActionEvent evt) { jTableProperties.getSelectedRows(); 312 int[] rows= jTableProperties.getSelectedRows(); 313 for (int i=rows.length-1; i>=0; --i) { 314 this.getDataset().removeJRProperty( (JRProperty) jTableProperties.getValueAt( rows[i], 0) ); 315 } 317 updateProperties(); 318 } 320 321 private void closeDialog(java.awt.event.WindowEvent evt) { setVisible(false); 323 } 325 328 public static void main(String args[]) { 329 new ValuesDialog(new javax.swing.JFrame (), true).setVisible(true); 330 } 331 332 333 public void setDataset(it.businesslogic.ireport.SubDataset dataset) { 334 this.dataset = dataset; 335 336 if (dataset == null) 338 { 339 setVisible(false); 340 return; 341 } 342 343 if (isVisible()) 344 { 345 this.setTitle(dataset.getName()+" properties..."); 346 updateProperties(); 347 } 348 } 349 350 public void updateProperties() { 351 352 DefaultTableModel dtm = (DefaultTableModel)jTableProperties.getModel(); 353 dtm.setRowCount(0); 354 355 Enumeration e = getDataset().getJRproperties().elements(); 356 while (e.hasMoreElements()) 357 { 358 it.businesslogic.ireport.JRProperty property = (it.businesslogic.ireport.JRProperty)e.nextElement(); 359 Vector row = new Vector(); 360 row.addElement( property); 361 row.addElement( property.getValue()); 362 363 dtm.addRow(row); 364 } 365 } 366 public void applyI18n(){ 367 jButtonNewProperty.setText(it.businesslogic.ireport.util.I18n.getString("new","New")); 370 jButtonModifyProperty.setText(it.businesslogic.ireport.util.I18n.getString("modify","Modify")); 371 jButtonDeleteProperty.setText(it.businesslogic.ireport.util.I18n.getString("delete","Delete")); 372 jButtonClose.setText(it.businesslogic.ireport.util.I18n.getString("close","Close")); 373 374 jTableProperties.getColumnModel().getColumn(0).setHeaderValue( I18n.getString("propertiesDialog.tablecolumn.name","Name") ); 375 jTableProperties.getColumnModel().getColumn(1).setHeaderValue( I18n.getString("propertiesDialog.tablecolumn.value","Value") ); 376 377 } 378 public void languageChanged(LanguageChangedEvent evt) { 379 380 this.applyI18n(); 381 } 382 383 private javax.swing.JButton jButtonClose; 385 private javax.swing.JButton jButtonDeleteProperty; 386 private javax.swing.JButton jButtonModifyProperty; 387 private javax.swing.JButton jButtonNewProperty; 388 private javax.swing.JPanel jPanel1; 389 private javax.swing.JPanel jPanelButtons2; 390 private javax.swing.JPanel jPanelFields; 391 private javax.swing.JScrollPane jScrollPane3; 392 private it.businesslogic.ireport.gui.JDragTable jTableProperties; 393 395 private SubDataset dataset; 396 397 public void setVisible(boolean visible) 398 { 399 if (visible == isVisible()) return; 400 super.setVisible(visible); 401 if (visible == true) 402 { 403 this.setDataset(this.dataset); 404 } 405 } 406 407 public SubDataset getDataset() { 408 return dataset; 409 } 410 411 } 412 | Popular Tags |