1 6 7 package com.jaspersoft.jasperserver.irplugin.gui; 8 9 import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.ResourceDescriptor; 10 import com.jaspersoft.jasperserver.irplugin.IRPlugin; 11 import com.jaspersoft.jasperserver.irplugin.RepositoryFile; 12 import com.jaspersoft.jasperserver.irplugin.RepositoryFolder; 13 import com.jaspersoft.jasperserver.irplugin.RepositoryJrxmlFile; 14 import it.businesslogic.ireport.ImageReportElement; 15 import it.businesslogic.ireport.ReportElement; 16 import it.businesslogic.ireport.gui.JReportFrame; 17 import it.businesslogic.ireport.gui.MainFrame; 18 import it.businesslogic.ireport.util.Misc; 19 import java.awt.Image ; 20 import java.io.*; 21 import java.util.Enumeration ; 22 import java.util.List ; 23 import java.util.Vector ; 24 import javax.swing.ImageIcon ; 25 import javax.swing.JOptionPane ; 26 import javax.swing.JTree ; 27 31 public class ObjectPropertiesDialog extends javax.swing.JDialog { 32 33 34 private RepositoryFolder resource; 35 private int dialogResult = javax.swing.JOptionPane.CANCEL_OPTION; 36 private AntialiasedEditorPane jEditorPane1 = null; 37 38 39 public ObjectPropertiesDialog(java.awt.Frame parent, boolean modal) { 40 super(parent, modal); 41 initComponents(); 42 43 it.businesslogic.ireport.util.Misc.centerFrame(this); 44 this.jTextFieldLabel.getDocument().addDocumentListener( new javax.swing.event.DocumentListener () { 45 public void changedUpdate(javax.swing.event.DocumentEvent evt) { 46 updateSaveButton(); 47 } 48 public void insertUpdate(javax.swing.event.DocumentEvent evt) { 49 updateSaveButton(); 50 } 51 public void removeUpdate(javax.swing.event.DocumentEvent evt) { 52 updateSaveButton(); 53 } 54 }); 55 56 this.jEditorPaneDescription.getDocument().addDocumentListener( new javax.swing.event.DocumentListener () { 57 public void changedUpdate(javax.swing.event.DocumentEvent evt) { 58 updateSaveButton(); 59 } 60 public void insertUpdate(javax.swing.event.DocumentEvent evt) { 61 updateSaveButton(); 62 } 63 public void removeUpdate(javax.swing.event.DocumentEvent evt) { 64 updateSaveButton(); 65 } 66 }); 67 68 69 jEditorPane1 = new AntialiasedEditorPane(); 70 jEditorPane1.setContentType("text/html"); 71 jEditorPane1.setVisible(false); 72 java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 73 gridBagConstraints.gridx = 0; 74 gridBagConstraints.gridy = 0; 75 gridBagConstraints.gridwidth = 2; 76 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 77 gridBagConstraints.weightx = 1.0; 78 gridBagConstraints.weighty = 1.0; 79 gridBagConstraints.insets = new java.awt.Insets (8, 8, 8, 8); 80 jPanelResourceFile.add(jEditorPane1, gridBagConstraints); 81 jEditorPane1.setEditable(false); 82 83 jPanelSpacer.setVisible(false); 84 85 } 86 87 88 public void updateSaveButton() 89 { 90 if (jTextFieldLabel.getText().length() > 0) 91 { 92 jButtonSave.setEnabled(true); 93 } 94 else 95 { 96 jButtonSave.setEnabled(false); 97 } 98 } 99 104 private void initComponents() { 106 java.awt.GridBagConstraints gridBagConstraints; 107 108 jTabbedPane1 = new javax.swing.JTabbedPane (); 109 jPanel1 = new javax.swing.JPanel (); 110 jLabelUriString = new javax.swing.JLabel (); 111 jTextFieldUriString = new javax.swing.JTextField (); 112 jLabelName = new javax.swing.JLabel (); 113 jTextFieldName = new javax.swing.JTextField (); 114 jSeparator1 = new javax.swing.JSeparator (); 115 jLabelLabel = new javax.swing.JLabel (); 116 jTextFieldLabel = new javax.swing.JTextField (); 117 jLabelDescription = new javax.swing.JLabel (); 118 jScrollPane1 = new javax.swing.JScrollPane (); 119 jEditorPaneDescription = new javax.swing.JEditorPane (); 120 jPanelResourceFile = new javax.swing.JPanel (); 121 jLabelPreview = new javax.swing.JLabel (); 122 jSeparator3 = new javax.swing.JSeparator (); 123 jCheckBoxChangeFile = new javax.swing.JCheckBox (); 124 jTextFieldFile = new javax.swing.JTextField (); 125 jButton1 = new javax.swing.JButton (); 126 jSeparator4 = new javax.swing.JSeparator (); 127 jButton2 = new javax.swing.JButton (); 128 jPanelSpacer = new javax.swing.JPanel (); 129 jPanel2 = new javax.swing.JPanel (); 130 jButtonSave = new javax.swing.JButton (); 131 jButtonClose = new javax.swing.JButton (); 132 133 getContentPane().setLayout(new java.awt.GridBagLayout ()); 134 135 setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); 136 addWindowListener(new java.awt.event.WindowAdapter () { 137 public void windowClosing(java.awt.event.WindowEvent evt) { 138 formWindowClosing(evt); 139 } 140 }); 141 142 jPanel1.setLayout(new java.awt.GridBagLayout ()); 143 144 jPanel1.setPreferredSize(new java.awt.Dimension (350, 250)); 145 jLabelUriString.setText("Location (URI)"); 146 gridBagConstraints = new java.awt.GridBagConstraints (); 147 gridBagConstraints.gridx = 0; 148 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 149 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 4); 150 jPanel1.add(jLabelUriString, gridBagConstraints); 151 152 jTextFieldUriString.setEditable(false); 153 jTextFieldUriString.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); 154 jTextFieldUriString.setOpaque(false); 155 gridBagConstraints = new java.awt.GridBagConstraints (); 156 gridBagConstraints.gridx = 1; 157 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 158 gridBagConstraints.weightx = 1.0; 159 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 4); 160 jPanel1.add(jTextFieldUriString, gridBagConstraints); 161 162 jLabelName.setText("Name"); 163 gridBagConstraints = new java.awt.GridBagConstraints (); 164 gridBagConstraints.gridx = 0; 165 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 166 gridBagConstraints.insets = new java.awt.Insets (0, 4, 4, 4); 167 jPanel1.add(jLabelName, gridBagConstraints); 168 169 jTextFieldName.setEditable(false); 170 jTextFieldName.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); 171 jTextFieldName.setOpaque(false); 172 gridBagConstraints = new java.awt.GridBagConstraints (); 173 gridBagConstraints.gridx = 1; 174 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 175 gridBagConstraints.weightx = 1.0; 176 gridBagConstraints.insets = new java.awt.Insets (0, 4, 4, 4); 177 jPanel1.add(jTextFieldName, gridBagConstraints); 178 179 jSeparator1.setMinimumSize(new java.awt.Dimension (0, 2)); 180 gridBagConstraints = new java.awt.GridBagConstraints (); 181 gridBagConstraints.gridx = 0; 182 gridBagConstraints.gridwidth = 2; 183 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 184 gridBagConstraints.weightx = 1.0; 185 gridBagConstraints.insets = new java.awt.Insets (4, 4, 6, 4); 186 jPanel1.add(jSeparator1, gridBagConstraints); 187 188 jLabelLabel.setText("Label"); 189 gridBagConstraints = new java.awt.GridBagConstraints (); 190 gridBagConstraints.gridx = 0; 191 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 192 gridBagConstraints.insets = new java.awt.Insets (0, 4, 4, 4); 193 jPanel1.add(jLabelLabel, gridBagConstraints); 194 195 gridBagConstraints = new java.awt.GridBagConstraints (); 196 gridBagConstraints.gridx = 1; 197 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 198 gridBagConstraints.weightx = 1.0; 199 gridBagConstraints.insets = new java.awt.Insets (4, 4, 4, 4); 200 jPanel1.add(jTextFieldLabel, gridBagConstraints); 201 202 jLabelDescription.setText("Description"); 203 gridBagConstraints = new java.awt.GridBagConstraints (); 204 gridBagConstraints.gridx = 0; 205 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 206 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 207 gridBagConstraints.insets = new java.awt.Insets (4, 4, 0, 4); 208 jPanel1.add(jLabelDescription, gridBagConstraints); 209 210 jScrollPane1.setViewportView(jEditorPaneDescription); 211 212 gridBagConstraints = new java.awt.GridBagConstraints (); 213 gridBagConstraints.gridx = 1; 214 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 215 gridBagConstraints.weightx = 1.0; 216 gridBagConstraints.weighty = 1.0; 217 gridBagConstraints.insets = new java.awt.Insets (0, 4, 4, 4); 218 jPanel1.add(jScrollPane1, gridBagConstraints); 219 220 jTabbedPane1.addTab("General", jPanel1); 221 222 jPanelResourceFile.setLayout(new java.awt.GridBagLayout ()); 223 224 jLabelPreview.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); 225 jLabelPreview.setText(" "); 226 jLabelPreview.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); 227 jLabelPreview.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 228 jLabelPreview.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); 229 gridBagConstraints = new java.awt.GridBagConstraints (); 230 gridBagConstraints.gridx = 0; 231 gridBagConstraints.gridy = 0; 232 gridBagConstraints.gridwidth = 3; 233 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 234 gridBagConstraints.weightx = 1.0; 235 gridBagConstraints.weighty = 1.0; 236 gridBagConstraints.insets = new java.awt.Insets (8, 8, 8, 8); 237 jPanelResourceFile.add(jLabelPreview, gridBagConstraints); 238 239 jSeparator3.setMinimumSize(new java.awt.Dimension (0, 2)); 240 gridBagConstraints = new java.awt.GridBagConstraints (); 241 gridBagConstraints.gridx = 0; 242 gridBagConstraints.gridy = 1; 243 gridBagConstraints.gridwidth = 3; 244 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 245 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 246 gridBagConstraints.weightx = 1.0; 247 gridBagConstraints.insets = new java.awt.Insets (4, 4, 6, 4); 248 jPanelResourceFile.add(jSeparator3, gridBagConstraints); 249 250 jCheckBoxChangeFile.setText("Replace resource with this file:"); 251 jCheckBoxChangeFile.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 252 jCheckBoxChangeFile.setMargin(new java.awt.Insets (0, 0, 0, 0)); 253 jCheckBoxChangeFile.addActionListener(new java.awt.event.ActionListener () { 254 public void actionPerformed(java.awt.event.ActionEvent evt) { 255 jCheckBoxChangeFileActionPerformed(evt); 256 } 257 }); 258 jCheckBoxChangeFile.addChangeListener(new javax.swing.event.ChangeListener () { 259 public void stateChanged(javax.swing.event.ChangeEvent evt) { 260 jCheckBoxChangeFileStateChanged(evt); 261 } 262 }); 263 264 gridBagConstraints = new java.awt.GridBagConstraints (); 265 gridBagConstraints.gridx = 0; 266 gridBagConstraints.gridy = 2; 267 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 268 gridBagConstraints.weightx = 1.0; 269 gridBagConstraints.insets = new java.awt.Insets (8, 4, 0, 0); 270 jPanelResourceFile.add(jCheckBoxChangeFile, gridBagConstraints); 271 272 gridBagConstraints = new java.awt.GridBagConstraints (); 273 gridBagConstraints.gridx = 0; 274 gridBagConstraints.gridy = 3; 275 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 276 gridBagConstraints.weightx = 1.0; 277 gridBagConstraints.insets = new java.awt.Insets (0, 24, 0, 0); 278 jPanelResourceFile.add(jTextFieldFile, gridBagConstraints); 279 280 jButton1.setText("Browse"); 281 jButton1.setMinimumSize(new java.awt.Dimension (73, 19)); 282 jButton1.addActionListener(new java.awt.event.ActionListener () { 283 public void actionPerformed(java.awt.event.ActionEvent evt) { 284 jButton1ActionPerformed(evt); 285 } 286 }); 287 288 gridBagConstraints = new java.awt.GridBagConstraints (); 289 gridBagConstraints.gridy = 3; 290 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 4); 291 jPanelResourceFile.add(jButton1, gridBagConstraints); 292 293 jSeparator4.setMinimumSize(new java.awt.Dimension (0, 2)); 294 gridBagConstraints = new java.awt.GridBagConstraints (); 295 gridBagConstraints.gridx = 0; 296 gridBagConstraints.gridwidth = 3; 297 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 298 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 299 gridBagConstraints.weightx = 1.0; 300 gridBagConstraints.insets = new java.awt.Insets (4, 4, 6, 4); 301 jPanelResourceFile.add(jSeparator4, gridBagConstraints); 302 303 jButton2.setText("Export file"); 304 jButton2.setMinimumSize(new java.awt.Dimension (73, 19)); 305 jButton2.setPreferredSize(new java.awt.Dimension (100, 23)); 306 jButton2.addActionListener(new java.awt.event.ActionListener () { 307 public void actionPerformed(java.awt.event.ActionEvent evt) { 308 jButton1ActionPerformed1(evt); 309 } 310 }); 311 312 gridBagConstraints = new java.awt.GridBagConstraints (); 313 gridBagConstraints.gridx = 0; 314 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 315 gridBagConstraints.insets = new java.awt.Insets (0, 4, 4, 4); 316 jPanelResourceFile.add(jButton2, gridBagConstraints); 317 318 gridBagConstraints = new java.awt.GridBagConstraints (); 319 gridBagConstraints.gridx = 0; 320 gridBagConstraints.weighty = 1.0; 321 jPanelResourceFile.add(jPanelSpacer, gridBagConstraints); 322 323 jTabbedPane1.addTab("Resource", jPanelResourceFile); 324 325 gridBagConstraints = new java.awt.GridBagConstraints (); 326 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 327 gridBagConstraints.weightx = 1.0; 328 gridBagConstraints.weighty = 1.0; 329 gridBagConstraints.insets = new java.awt.Insets (4, 4, 0, 4); 330 getContentPane().add(jTabbedPane1, gridBagConstraints); 331 332 jPanel2.setLayout(new java.awt.GridBagLayout ()); 333 334 jPanel2.setMinimumSize(new java.awt.Dimension (10, 30)); 335 jPanel2.setPreferredSize(new java.awt.Dimension (10, 30)); 336 jButtonSave.setText("Save"); 337 jButtonSave.setEnabled(false); 338 jButtonSave.addActionListener(new java.awt.event.ActionListener () { 339 public void actionPerformed(java.awt.event.ActionEvent evt) { 340 jButtonSaveActionPerformed(evt); 341 } 342 }); 343 344 gridBagConstraints = new java.awt.GridBagConstraints (); 345 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 346 gridBagConstraints.weightx = 1.0; 347 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 4); 348 jPanel2.add(jButtonSave, gridBagConstraints); 349 350 jButtonClose.setText("Close"); 351 jButtonClose.addActionListener(new java.awt.event.ActionListener () { 352 public void actionPerformed(java.awt.event.ActionEvent evt) { 353 jButtonCloseActionPerformed(evt); 354 } 355 }); 356 357 jPanel2.add(jButtonClose, new java.awt.GridBagConstraints ()); 358 359 gridBagConstraints = new java.awt.GridBagConstraints (); 360 gridBagConstraints.gridx = 0; 361 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 362 gridBagConstraints.insets = new java.awt.Insets (0, 4, 0, 4); 363 getContentPane().add(jPanel2, gridBagConstraints); 364 365 pack(); 366 } 368 private void jButton1ActionPerformed1(java.awt.event.ActionEvent evt) { 370 String fileName = ""; 371 javax.swing.JFileChooser jfc = new javax.swing.JFileChooser (MainFrame.getMainInstance().getCurrentDirectory()); 372 373 jfc.setDialogTitle("Pick a file...."); 374 375 String resType = this.getResource().getDescriptor().getWsType(); 377 if (resType.equals( ResourceDescriptor.TYPE_JRXML)) { 378 jfc.setFileFilter( new javax.swing.filechooser.FileFilter () { 379 public boolean accept(java.io.File file) { 380 String filename = file.getName(); 381 return (filename.toLowerCase().endsWith(".xml") || file.isDirectory() || filename.toLowerCase().endsWith(".jrxml")) ; 382 } 383 public String getDescription() { 384 return "JasperReports XML *.xml, *.jrxml"; 385 } 386 }); 387 } else if (resType.equals( ResourceDescriptor.TYPE_FONT)) { 388 jfc.setFileFilter( new javax.swing.filechooser.FileFilter () { 389 public boolean accept(java.io.File file) { 390 String filename = file.getName(); 391 return (filename.toLowerCase().endsWith(".ttf") || file.isDirectory() || filename.toLowerCase().endsWith(".jrxml")) ; 392 } 393 public String getDescription() { 394 return "TrueType font *.TTF"; 395 } 396 }); 397 } else if (resType.equals( ResourceDescriptor.TYPE_RESOURCE_BUNDLE)) { 398 jfc.setFileFilter( new javax.swing.filechooser.FileFilter () { 399 public boolean accept(java.io.File file) { 400 String filename = file.getName(); 401 return (filename.toLowerCase().endsWith(".properties") || file.isDirectory() || filename.toLowerCase().endsWith(".jrxml")) ; 402 } 403 public String getDescription() { 404 return "ResourceBundle *.properties"; 405 } 406 }); 407 } else if (resType.equals( ResourceDescriptor.TYPE_CLASS_JAR)) { 408 jfc.setFileFilter( new javax.swing.filechooser.FileFilter () { 409 public boolean accept(java.io.File file) { 410 String filename = file.getName(); 411 return (filename.toLowerCase().endsWith(".jar") || file.isDirectory() || filename.toLowerCase().endsWith(".jrxml")) ; 412 } 413 public String getDescription() { 414 return "Java Archive *.jar"; 415 } 416 }); 417 } 418 419 jfc.setMultiSelectionEnabled(false); 420 jfc.setDialogType( javax.swing.JFileChooser.SAVE_DIALOG); 421 if (jfc.showOpenDialog( this) == javax.swing.JOptionPane.OK_OPTION) { 422 423 try { 424 copyFile( new File( ((RepositoryFile)getResource()).getFile() ), 425 jfc.getSelectedFile() ); 426 } catch (Exception ex) 427 { 428 JOptionPane.showMessageDialog(this,"Error: " + ex.getMessage()); 429 ex.printStackTrace(); 430 return; 431 } 432 } 433 434 435 } 437 private void jCheckBoxChangeFileStateChanged(javax.swing.event.ChangeEvent evt) { 439 } 441 private void jCheckBoxChangeFileActionPerformed(java.awt.event.ActionEvent evt) { updateSaveButton(); 443 } 445 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String fileName = ""; 447 javax.swing.JFileChooser jfc = new javax.swing.JFileChooser (MainFrame.getMainInstance().getCurrentDirectory()); 448 449 jfc.setDialogTitle("Pick a file...."); 450 451 String resType = this.getResource().getDescriptor().getWsType(); 453 if (resType.equals( ResourceDescriptor.TYPE_JRXML)) { 454 jfc.setFileFilter( new javax.swing.filechooser.FileFilter () { 455 public boolean accept(java.io.File file) { 456 String filename = file.getName(); 457 return (filename.toLowerCase().endsWith(".xml") || file.isDirectory() || filename.toLowerCase().endsWith(".jrxml")) ; 458 } 459 public String getDescription() { 460 return "JasperReports XML *.xml, *.jrxml"; 461 } 462 }); 463 } else if (resType.equals( ResourceDescriptor.TYPE_FONT)) { 464 jfc.setFileFilter( new javax.swing.filechooser.FileFilter () { 465 public boolean accept(java.io.File file) { 466 String filename = file.getName(); 467 return (filename.toLowerCase().endsWith(".ttf") || file.isDirectory() || filename.toLowerCase().endsWith(".jrxml")) ; 468 } 469 public String getDescription() { 470 return "TrueType font *.TTF"; 471 } 472 }); 473 } else if (resType.equals( ResourceDescriptor.TYPE_RESOURCE_BUNDLE)) { 474 jfc.setFileFilter( new javax.swing.filechooser.FileFilter () { 475 public boolean accept(java.io.File file) { 476 String filename = file.getName(); 477 return (filename.toLowerCase().endsWith(".properties") || file.isDirectory() || filename.toLowerCase().endsWith(".jrxml")) ; 478 } 479 public String getDescription() { 480 return "ResourceBundle *.properties"; 481 } 482 }); 483 } else if (resType.equals( ResourceDescriptor.TYPE_CLASS_JAR)) { 484 jfc.setFileFilter( new javax.swing.filechooser.FileFilter () { 485 public boolean accept(java.io.File file) { 486 String filename = file.getName(); 487 return (filename.toLowerCase().endsWith(".jar") || file.isDirectory() || filename.toLowerCase().endsWith(".jrxml")) ; 488 } 489 public String getDescription() { 490 return "Java Archive *.jar"; 491 } 492 }); 493 } 494 495 jfc.setMultiSelectionEnabled(false); 496 jfc.setDialogType( javax.swing.JFileChooser.OPEN_DIALOG); 497 if (jfc.showOpenDialog( this) == javax.swing.JOptionPane.OK_OPTION) { 498 499 jTextFieldFile.setText( jfc.getSelectedFile()+""); 500 updateSaveButton(); 501 502 if (getResource().getDescriptor().getWsType().equals(ResourceDescriptor.TYPE_IMAGE)) 503 { 504 try { 505 javax.swing.ImageIcon ii = new javax.swing.ImageIcon (jfc.getSelectedFile()+""); 506 jLabelPreview.setText(ii.getIconWidth() + "x" + ii.getIconHeight()); 507 this.doLayout(); 508 ii.setImage( resampleImage( ii.getImage(),jLabelPreview.getWidth(), (int)Math.max(1,jLabelPreview.getHeight()-20))); 509 jLabelPreview.setIcon( ii ); 510 511 } catch (Exception ex) 512 { 513 jLabelPreview.setText(" "); 514 jLabelPreview.setIcon(null); 515 } 516 } 517 } 518 519 jCheckBoxChangeFile.setSelected(true); 520 } 522 private void formWindowClosing(java.awt.event.WindowEvent evt) { 524 jButtonCloseActionPerformed(null); 525 } 527 private void jButtonCloseActionPerformed(java.awt.event.ActionEvent evt) { 529 if (jButtonSave.isEnabled()) 530 { 531 if (JOptionPane.showConfirmDialog(this, "The resource was changed.\n\nDo you want save the changes?") == JOptionPane.OK_OPTION) 532 { 533 jButtonSaveActionPerformed(null); 534 if (jButtonSave.isEnabled()) return; 536 } 537 } 538 this.setVisible(false); 539 this.dispose(); 540 } 542 private void jButtonSaveActionPerformed(java.awt.event.ActionEvent evt) { 544 File newFile = null; 545 if (jCheckBoxChangeFile.isSelected()) 546 { 547 newFile = new File(jTextFieldFile.getText()); 548 if (!newFile.exists()) 549 { 550 JOptionPane.showMessageDialog(this,"The file " +jTextFieldFile.getText() + "\ndoes not exist.\n\nPlease provide a correct file name."); 551 return; 552 } 553 } 554 555 ResourceDescriptor rd = new ResourceDescriptor(); 556 rd.setWsType( getResource().getDescriptor().getWsType() ); 557 rd.setName( getResource().getDescriptor().getName() ); 558 rd.setUriString( getResource().getDescriptor().getUriString() ); 559 rd.setCreationDate( getResource().getDescriptor().getCreationDate() ); 560 rd.setConnectionUrl( getResource().getDescriptor().getConnectionUrl() ); 561 rd.setDataSourceType( getResource().getDescriptor().getDataSourceType() ); 562 rd.setDescription( jEditorPaneDescription.getText().trim() ); rd.setDriverClass( getResource().getDescriptor().getDriverClass() ); 564 rd.setHasData( newFile != null); rd.setIsNew(false); rd.setIsReference( getResource().getDescriptor().getIsReference() ); 567 rd.setJndiName( getResource().getDescriptor().getJndiName()); 568 rd.setLabel(jTextFieldLabel.getText().trim() ); rd.setParentFolder( getResource().getDescriptor().getParentFolder()); 570 rd.setPassword( getResource().getDescriptor().getPassword()); 571 rd.setReferenceUri( getResource().getDescriptor().getReferenceUri()); 572 rd.setResourceType( getResource().getDescriptor().getResourceType() ); 573 rd.setUsername( getResource().getDescriptor().getUsername()); 574 rd.setVersion( getResource().getDescriptor().getVersion()); 575 576 try { 577 ResourceDescriptor newrd = getResource().getServer().getWSClient().addOrModifyResource(rd, newFile); 578 setDialogResult(JOptionPane.OK_OPTION); 579 jButtonSave.setEnabled(false); 580 getResource().setDescriptor( newrd ); 581 582 if (jCheckBoxChangeFile.isSelected()) 583 { 584 if (getResource() instanceof RepositoryFile) 585 { 586 RepositoryFile fileRep = (RepositoryFile)getResource(); 587 if (getResource().getDescriptor().getWsType().equals(ResourceDescriptor.TYPE_IMAGE)) 588 { 589 try { 590 591 String s = fileRep.getFile(); 592 fileRep.resetFileCache(); 593 copyFile(new File(s), newFile); 594 595 RepositoryExplorer rexplorer = IRPlugin.getMainInstance().getRepositoryExplorer(); 597 List list = rexplorer.getOpenedReportSources(getResource().getServer()); 599 for (int i=0; i<list.size(); ++i) 600 { 601 RepositoryJrxmlFile jrxmlRepo = (RepositoryJrxmlFile)list.get(i); 602 603 JReportFrame jrf = jrxmlRepo.getReportFrame(); 604 boolean updateFrame = false; 605 if (jrf != null) 606 { 607 System.out.println(jrf); 608 Vector elements = jrf.getReport().getElements(); 609 Enumeration enumElements = elements.elements(); 610 while (enumElements.hasMoreElements()) 611 { 612 ReportElement re = (ReportElement)enumElements.nextElement(); 613 if (re instanceof ImageReportElement) 614 { 615 ImageReportElement ire = (ImageReportElement)re; 616 String expression =ire.getImageExpression(); 617 expression = Misc.string_replace("\\","\\\\",expression); 618 expression = Misc.string_replace("","\"",expression); 619 620 if ((ire.getImageClass().length() == 0 || ire.getImageClass().equals("java.lang.String")) && 621 expression.toLowerCase().startsWith("repo:") && expression.substring(5).equals(newrd.getUriString() )) 622 { 623 ire.setImg(new ImageIcon (s).getImage()); 624 System.out.println(newrd.getUriString() + " --> " + expression.substring(5)+" " + s); 625 626 updateFrame = true; 627 } 628 } 629 } 630 if (updateFrame) 631 { 632 jrf.getReportPanel().repaint(); 633 } 634 } 635 } 636 637 } catch (Exception ex) 638 { 639 640 } 641 } 642 else 643 { 644 fileRep.resetFileCache(); 645 } 646 } 647 648 } 649 650 } catch (Exception ex) 651 { 652 JOptionPane.showMessageDialog(this,"Error: " + ex.getMessage()); 653 ex.printStackTrace(); 654 return; 655 } 656 657 658 } 660 public void setResource(RepositoryFolder resource) 661 { 662 this.resource = resource; 663 ResourceDescriptor resourceDescriptor = resource.getDescriptor(); 664 this.jTextFieldName.setText( resourceDescriptor.getName() ); 665 this.jTextFieldLabel.setText( resourceDescriptor.getLabel() ); 666 this.jTextFieldUriString.setText( resourceDescriptor.getUriString() ); 667 this.jEditorPaneDescription.setText( resourceDescriptor.getDescription() ); 668 669 jCheckBoxChangeFile.setSelected(false); 670 671 jTabbedPane1.removeAll(); 672 jTabbedPane1.add("General", jPanel1); 673 674 if (resourceDescriptor.getWsType().equals(resourceDescriptor.TYPE_IMAGE) || 675 resourceDescriptor.getWsType().equals(resourceDescriptor.TYPE_JRXML) || 676 resourceDescriptor.getWsType().equals(resourceDescriptor.TYPE_CLASS_JAR) || 677 resourceDescriptor.getWsType().equals(resourceDescriptor.TYPE_FONT) || 678 resourceDescriptor.getWsType().equals(resourceDescriptor.TYPE_RESOURCE_BUNDLE)) 679 { 680 jTabbedPane1.add("Resource", jPanelResourceFile); 681 } 682 683 if (getResource().getDescriptor().getWsType().equals(ResourceDescriptor.TYPE_IMAGE)) 684 { 685 try { 686 if (getResource() instanceof RepositoryFile) 687 { 688 RepositoryFile res = (RepositoryFile)getResource(); 689 String s = res.getFile(); 690 javax.swing.ImageIcon ii = new javax.swing.ImageIcon (s); 691 jLabelPreview.setText(ii.getIconWidth() + "x" + ii.getIconHeight()); 692 ii.setImage( resampleImage( ii.getImage(),300, 115)); 693 jLabelPreview.setIcon( ii ); 694 } 695 } catch (Exception ex) 696 { 697 jLabelPreview.setText(" "); 698 jLabelPreview.setIcon(null); 699 } 700 } 701 else if (getResource().getDescriptor().getWsType().equals(ResourceDescriptor.TYPE_FONT)) 702 { 703 try { 704 if (getResource() instanceof RepositoryFile) 705 { 706 RepositoryFile res = (RepositoryFile)getResource(); 707 String s = res.getFile(); 708 java.awt.Font f = it.businesslogic.ireport.FontListLoader.loadFont(s); 709 if (f != null) 710 { 711 jEditorPane1.setVisible(true); 712 jLabelPreview.setVisible(false); 713 String text = ""; 715 for (int dim=1; dim<=8; dim++) 716 { 717 text += "<font face=\""+ f.getName() + "\" size=\""+ dim + "\">Nel mezzo del cammin di nostra vita...<br></font>"; 718 } 719 720 jEditorPane1.setText( text ); 721 } 725 } 726 } catch (Exception ex) 727 { 728 jLabelPreview.setText(" "); 729 jLabelPreview.setIcon(null); 730 } 731 } 732 else 733 { 734 jEditorPane1.setVisible(false); 735 jLabelPreview.setVisible(false); 736 jSeparator3.setVisible(false); 737 jPanelSpacer.setVisible(true); 738 } 739 740 741 jButtonSave.setEnabled(false); 742 } 743 744 public RepositoryFolder getResource() { 745 return resource; 746 } 747 748 public int getDialogResult() { 749 return dialogResult; 750 } 751 752 public void setDialogResult(int dialogResult) { 753 this.dialogResult = dialogResult; 754 } 755 756 public Image resampleImage(Image inImage, int maxX, int maxY) 757 { 758 double scale1 = (double) maxY / (double) inImage.getHeight(null); 759 double scale2 = (double) maxX / (double) inImage.getWidth(null); 760 double scale = (scale1 < scale2) ? scale1 : scale2; 761 762 int scaledW = (int) (scale * inImage.getWidth(null)); 763 int scaledH = (int) (scale * inImage.getHeight(null)); 764 System.out.println(scale1 + " " + scale2 + " MAX y: " + maxY + " " + jLabelPreview.getHeight() + " " + scaledH); 765 return inImage.getScaledInstance(scaledW , scaledH, Image.SCALE_SMOOTH); 766 767 } 768 769 private javax.swing.JButton jButton1; 771 private javax.swing.JButton jButton2; 772 private javax.swing.JButton jButtonClose; 773 private javax.swing.JButton jButtonSave; 774 private javax.swing.JCheckBox jCheckBoxChangeFile; 775 private javax.swing.JEditorPane jEditorPaneDescription; 776 private javax.swing.JLabel jLabelDescription; 777 private javax.swing.JLabel jLabelLabel; 778 private javax.swing.JLabel jLabelName; 779 private javax.swing.JLabel jLabelPreview; 780 private javax.swing.JLabel jLabelUriString; 781 private javax.swing.JPanel jPanel1; 782 private javax.swing.JPanel jPanel2; 783 private javax.swing.JPanel jPanelResourceFile; 784 private javax.swing.JPanel jPanelSpacer; 785 private javax.swing.JScrollPane jScrollPane1; 786 private javax.swing.JSeparator jSeparator1; 787 private javax.swing.JSeparator jSeparator3; 788 private javax.swing.JSeparator jSeparator4; 789 private javax.swing.JTabbedPane jTabbedPane1; 790 private javax.swing.JTextField jTextFieldFile; 791 private javax.swing.JTextField jTextFieldLabel; 792 private javax.swing.JTextField jTextFieldName; 793 private javax.swing.JTextField jTextFieldUriString; 794 796 797 public void copyFile(File in, File out) throws IOException 798 { 799 800 FileInputStream is = new FileInputStream(in); 801 FileOutputStream os = new FileOutputStream(out); 802 byte[] buffer = new byte[1024]; 803 int bCount = 0; 804 while ( (bCount = is.read(buffer)) > 0) 805 { 806 os.write( buffer, 0, bCount); 807 } 808 is.close(); 809 os.close(); 810 } 811 } 812 | Popular Tags |