1 2 import java.awt.Dimension; 3 import java.awt.Image; 4 import java.io.File; 5 import javax.swing.ImageIcon; 6 import javax.swing.JLabel; 7 import javax.swing.SwingWorker; 8 9 /* 10 ************************************************************************** 11 * 12 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13 * 14 * Copyright 2000, 2010 Oracle and/or its affiliates. 15 * 16 * OpenOffice.org - a multi-platform office productivity suite 17 * 18 * This file is part of OpenOffice.org. 19 * 20 * OpenOffice.org is free software: you can redistribute it and/or modify 21 * it under the terms of the GNU Lesser General Public License version 3 22 * only, as published by the Free Software Foundation. 23 * 24 * OpenOffice.org is distributed in the hope that it will be useful, 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 * GNU Lesser General Public License version 3 for more details 28 * (a copy is included in the LICENSE file that accompanied this code). 29 * 30 * You should have received a copy of the GNU Lesser General Public License 31 * version 3 along with OpenOffice.org. If not, see 32 * <http://www.openoffice.org/license.html> 33 * for a copy of the LGPLv3 License. 34 * 35 ************************************************************************** 36 */ 37 38 /* 39 * Simple windows, which should show differences if there are some 40 */ 41 42 public class ConvwatchGUI extends javax.swing.JFrame 43 { 44 private ImageIcon[] m_aImageIcon; 45 private String m_sInifile; 46 private int m_nMaxPages; 47 private int m_nCurrentPage; 48 49 /** Creates new form ConvwatchGUI 50 * @param args 51 */ 52 53 private ConvwatchGUI(String args[]) 54 { 55 if (args.length > 0) 56 { 57 if (args[0].endsWith(".ini")) 58 { 59 m_sInifile = args[0]; 60 fillImageIconsFromInifile(); 61 } 62 else 63 { 64 fillImageIcons(args); 65 } 66 } 67 68 String sVersion = System.getProperty("java.version"); 69 Float f = Float.valueOf(sVersion.substring(0,3)); 70 if (f.floatValue() < (float)1.6) 71 { 72 System.out.println("You need at least Java version 1.6"); 73 System.exit(1); 74 } 75 76 initComponents(); 77 jLabelDocumentName.setText("Document: " + m_sInifile); 78 } 79 80 void fillImageIconsFromInifile() 81 { 82 File aFile = new File(m_sInifile); 83 if (!aFile.exists()) 84 { 85 GlobalLogWriter.println("Inifile '" + m_sInifile + "' not found."); 86 printUsage(); 87 System.exit(1); 88 } 89 90 IniFile aIniFile = new IniFile(aFile); 91 int nPages = aIniFile.getIntValue("global", "pages", 0); 92 if (nPages < 1) 93 { 94 System.out.println("No pages found."); 95 } 96 m_nMaxPages = nPages; 97 m_nCurrentPage = 1; 98 fillImageIcons(); 99 } 100 101 private void fillImageIcons() 102 { 103 File aFile = new File(m_sInifile); 104 IniFile aIniFile = new IniFile(aFile); 105 String sSection = "page" + m_nCurrentPage; 106 String[] files = new String[3]; 107 files[0] = aIniFile.getValue(sSection, "newgfx"); // current created picture 108 files[1] = aIniFile.getValue(sSection, "oldgfx"); // reference picture 109 files[2] = aIniFile.getValue(sSection, "diffgfx"); 110 fillImageIcons(files); 111 } 112 113 /** 114 * Give 3 file names 115 * @param args 116 */ 117 private void fillImageIcons(String args[]) 118 { 119 boolean bLoadImages = false; 120 m_aImageIcon = new ImageIcon[3]; 121 for (int i=0;i<3;i++) 122 { 123 if (args.length > i && args[i] != null) 124 { 125 File aFile = new File(args[i]); 126 if (aFile.exists()) 127 { 128 // TODO: Load images 129 // Image aImage = new BufferedImage(100,100, BufferedImage.TYPE_INT_RGB); 130 // aImage. 131 m_aImageIcon[i] = new ImageIcon(args[i]); 132 if (m_aImageIcon[i] != null) 133 { 134 bLoadImages = true; 135 } 136 } 137 else 138 { 139 System.out.println("Can't read file: " + aFile.getName()); 140 bLoadImages = false; 141 } 142 } 143 else 144 { 145 System.out.println("There is no #" + (i + 1) + " image given."); 146 bLoadImages = false; 147 } 148 } 149 // if (!bLoadImages) 150 // { 151 // printUsage(); 152 // System.exit(1); 153 // } 154 155 156 157 // TODO: Set images. 158 159 // formComponentResized(null); 160 } 161 162 private void printUsage() 163 { 164 System.out.println("Usage:"); 165 System.out.println(" ConvwatchGUI <pic1> <pic2> <pic3>"); 166 System.out.println("or ConvwatchGUI <inifile>"); 167 } 168 169 // private int m_nOldWidth; 170 171 /** This method is called from within the constructor to 172 * initialize the form. 173 * WARNING: Do NOT modify this code. The content of this method is 174 * always regenerated by the Form Editor. 175 */ 176 @SuppressWarnings("unchecked") 177 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 178 private void initComponents() { 179 180 jPanelOriginal = new javax.swing.JPanel(); 181 jLabelOriginalImage = new javax.swing.JLabel(); 182 jPanelReference = new javax.swing.JPanel(); 183 jLabelReferenceImage = new javax.swing.JLabel(); 184 jPanelDifference = new javax.swing.JPanel(); 185 jLabelDifferenceImage = new javax.swing.JLabel(); 186 jPanel4 = new javax.swing.JPanel(); 187 jButton1 = new javax.swing.JButton(); 188 jButton2 = new javax.swing.JButton(); 189 jButton3 = new javax.swing.JButton(); 190 jLabelCurrentPage = new javax.swing.JLabel(); 191 jPanel5 = new javax.swing.JPanel(); 192 jLabel1 = new javax.swing.JLabel(); 193 jLabelDocumentName = new javax.swing.JLabel(); 194 195 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 196 addComponentListener(new java.awt.event.ComponentAdapter() { 197 public void componentResized(java.awt.event.ComponentEvent evt) { 198 formComponentResized(evt); 199 } 200 }); 201 addPropertyChangeListener(new java.beans.PropertyChangeListener() { 202 public void propertyChange(java.beans.PropertyChangeEvent evt) { 203 formPropertyChange(evt); 204 } 205 }); 206 207 jPanelOriginal.setBorder(javax.swing.BorderFactory.createTitledBorder("Picture")); 208 209 javax.swing.GroupLayout jPanelOriginalLayout = new javax.swing.GroupLayout(jPanelOriginal); 210 jPanelOriginal.setLayout(jPanelOriginalLayout); 211 jPanelOriginalLayout.setHorizontalGroup( 212 jPanelOriginalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 213 .addGroup(jPanelOriginalLayout.createSequentialGroup() 214 .addContainerGap() 215 .addComponent(jLabelOriginalImage, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE) 216 .addContainerGap()) 217 ); 218 jPanelOriginalLayout.setVerticalGroup( 219 jPanelOriginalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 220 .addGroup(jPanelOriginalLayout.createSequentialGroup() 221 .addComponent(jLabelOriginalImage, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE) 222 .addContainerGap()) 223 ); 224 225 jPanelReference.setBorder(javax.swing.BorderFactory.createTitledBorder("Reference Picture")); 226 227 javax.swing.GroupLayout jPanelReferenceLayout = new javax.swing.GroupLayout(jPanelReference); 228 jPanelReference.setLayout(jPanelReferenceLayout); 229 jPanelReferenceLayout.setHorizontalGroup( 230 jPanelReferenceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 231 .addGroup(jPanelReferenceLayout.createSequentialGroup() 232 .addContainerGap() 233 .addComponent(jLabelReferenceImage, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE) 234 .addContainerGap()) 235 ); 236 jPanelReferenceLayout.setVerticalGroup( 237 jPanelReferenceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 238 .addGroup(jPanelReferenceLayout.createSequentialGroup() 239 .addComponent(jLabelReferenceImage, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE) 240 .addContainerGap()) 241 ); 242 243 jPanelDifference.setBorder(javax.swing.BorderFactory.createTitledBorder("Difference")); 244 245 jLabelDifferenceImage.setName("DifferenceImage"); // NOI18N 246 247 javax.swing.GroupLayout jPanelDifferenceLayout = new javax.swing.GroupLayout(jPanelDifference); 248 jPanelDifference.setLayout(jPanelDifferenceLayout); 249 jPanelDifferenceLayout.setHorizontalGroup( 250 jPanelDifferenceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 251 .addGroup(jPanelDifferenceLayout.createSequentialGroup() 252 .addContainerGap() 253 .addComponent(jLabelDifferenceImage, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE) 254 .addContainerGap()) 255 ); 256 jPanelDifferenceLayout.setVerticalGroup( 257 jPanelDifferenceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 258 .addGroup(jPanelDifferenceLayout.createSequentialGroup() 259 .addComponent(jLabelDifferenceImage, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE) 260 .addContainerGap()) 261 ); 262 263 jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Action")); 264 265 jButton1.setText("Close"); 266 jButton1.addActionListener(new java.awt.event.ActionListener() { 267 public void actionPerformed(java.awt.event.ActionEvent evt) { 268 jButton1ActionPerformed(evt); 269 } 270 }); 271 272 jButton2.setLabel("prev page"); 273 jButton2.addActionListener(new java.awt.event.ActionListener() { 274 public void actionPerformed(java.awt.event.ActionEvent evt) { 275 jButton2ActionPerformed(evt); 276 } 277 }); 278 279 jButton3.setLabel("next page"); 280 jButton3.addActionListener(new java.awt.event.ActionListener() { 281 public void actionPerformed(java.awt.event.ActionEvent evt) { 282 jButton3ActionPerformed(evt); 283 } 284 }); 285 286 jLabelCurrentPage.setText("Current page: 1"); 287 288 javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); 289 jPanel4.setLayout(jPanel4Layout); 290 jPanel4Layout.setHorizontalGroup( 291 jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 292 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup() 293 .addContainerGap() 294 .addComponent(jButton2) 295 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 296 .addComponent(jButton3) 297 .addGap(18, 18, 18) 298 .addComponent(jLabelCurrentPage, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE) 299 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 614, Short.MAX_VALUE) 300 .addComponent(jButton1) 301 .addContainerGap()) 302 ); 303 jPanel4Layout.setVerticalGroup( 304 jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 305 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup() 306 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 307 .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 308 .addComponent(jButton1) 309 .addComponent(jButton2) 310 .addComponent(jButton3) 311 .addComponent(jLabelCurrentPage)) 312 .addContainerGap()) 313 ); 314 315 jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Information")); 316 317 jLabel1.setText("<html>Here you see a graphical compare by pictures created with a current running office, a stored reference picture and the difference between those both pictures created by ImageMagicks 'composite'.\n</html>"); // NOI18N 318 319 jLabelDocumentName.setText("jLabel2"); 320 321 javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); 322 jPanel5.setLayout(jPanel5Layout); 323 jPanel5Layout.setHorizontalGroup( 324 jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 325 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup() 326 .addContainerGap() 327 .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 328 .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 972, Short.MAX_VALUE) 329 .addComponent(jLabelDocumentName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 972, Short.MAX_VALUE)) 330 .addContainerGap()) 331 ); 332 jPanel5Layout.setVerticalGroup( 333 jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 334 .addGroup(jPanel5Layout.createSequentialGroup() 335 .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE) 336 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 337 .addComponent(jLabelDocumentName, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE) 338 .addContainerGap()) 339 ); 340 341 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 342 getContentPane().setLayout(layout); 343 layout.setHorizontalGroup( 344 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 345 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 346 .addContainerGap() 347 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 348 .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 349 .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 350 .addGroup(layout.createSequentialGroup() 351 .addComponent(jPanelOriginal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 352 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 353 .addComponent(jPanelReference, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 354 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 355 .addComponent(jPanelDifference, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) 356 .addContainerGap()) 357 ); 358 layout.setVerticalGroup( 359 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 360 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 361 .addContainerGap() 362 .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 363 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 364 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 365 .addComponent(jPanelReference, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 366 .addComponent(jPanelOriginal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 367 .addComponent(jPanelDifference, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 368 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 369 .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 370 .addContainerGap()) 371 ); 372 373 pack(); 374 }// </editor-fold>//GEN-END:initComponents 375 376 private boolean bAdd = false; 377 378 private void formComponentResized(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_formComponentResized 379 {//GEN-HEADEREND:event_formComponentResized 380 // TODO add your handling code here: 381 // we need to set icons to null 382 // if we don't do this, icons can only grow, but not shrink :-( 383 384 initialiseImages(); 385 } 386 private void initialiseImages() 387 { 388 if (jLabelOriginalImage.getIcon() != null) 389 { 390 jLabelOriginalImage.setIcon(null); 391 jLabelReferenceImage.setIcon(null); 392 jLabelDifferenceImage.setIcon(null); 393 394 int w = getWidth(); 395 int h = getHeight(); 396 if (bAdd) 397 { 398 this.setSize(w, h + 1); 399 bAdd = false; 400 } 401 else 402 { 403 this.setSize(w, h - 1); 404 bAdd = true; 405 } 406 } 407 else 408 { 409 new ResizeImage(jLabelOriginalImage, m_aImageIcon[0]).execute(); 410 new ResizeImage(jLabelReferenceImage, m_aImageIcon[1]).execute(); 411 new ResizeImage(jLabelDifferenceImage, m_aImageIcon[2]).execute(); 412 } 413 int dummy=0; 414 }//GEN-LAST:event_formComponentResized 415 416 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed 417 {//GEN-HEADEREND:event_jButton1ActionPerformed 418 // TODO add your handling code here: 419 System.exit(1); 420 }//GEN-LAST:event_jButton1ActionPerformed 421 422 private void formPropertyChange(java.beans.PropertyChangeEvent evt)//GEN-FIRST:event_formPropertyChange 423 {//GEN-HEADEREND:event_formPropertyChange 424 // TODO add your handling code here: 425 int dummy = 0; 426 }//GEN-LAST:event_formPropertyChange 427 428 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed 429 {//GEN-HEADEREND:event_jButton2ActionPerformed 430 // TODO add your handling code here: 431 int nOldPage = m_nCurrentPage; 432 if (m_nCurrentPage > 1) 433 { 434 m_nCurrentPage--; 435 } 436 if (nOldPage != m_nCurrentPage) 437 { 438 jLabelCurrentPage.setText("Current page: " + m_nCurrentPage); 439 fillImageIcons(); 440 initialiseImages(); 441 } 442 }//GEN-LAST:event_jButton2ActionPerformed 443 444 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton3ActionPerformed 445 {//GEN-HEADEREND:event_jButton3ActionPerformed 446 // TODO add your handling code here: 447 int nOldPage = m_nCurrentPage; 448 if (m_nCurrentPage < m_nMaxPages) 449 { 450 m_nCurrentPage++; 451 } 452 if (nOldPage != m_nCurrentPage) 453 { 454 jLabelCurrentPage.setText("Current page: " + m_nCurrentPage); 455 fillImageIcons(); 456 initialiseImages(); 457 } 458 }//GEN-LAST:event_jButton3ActionPerformed 459 460 class ResizeImage extends SwingWorker <ImageIcon, Object> 461 { 462 private JLabel m_jLabel; 463 private ImageIcon m_aImageIcon; 464 private int w; 465 private int h; 466 467 public ResizeImage(JLabel _aLabel, ImageIcon _aImageIcon) 468 { 469 m_jLabel = _aLabel; 470 m_aImageIcon = _aImageIcon; 471 w = _aLabel.getWidth(); 472 h = _aLabel.getHeight(); 473 } 474 475 // dont access here anything to "Event Swing Thread" 476 @Override 477 public ImageIcon doInBackground() 478 { 479 Image aImage = m_aImageIcon.getImage().getScaledInstance(w, h, Image.SCALE_AREA_AVERAGING); // SCALE_SMOOTH 480 final ImageIcon aIcon = new ImageIcon(aImage); 481 // m_jLabel.setIcon(aIcon); 482 return aIcon; 483 } 484 485 @Override 486 protected void done() 487 { 488 try 489 { 490 m_jLabel.setIcon(get()); 491 } 492 catch (Exception e) 493 {} 494 } 495 496 } 497 498 /** 499 * @param args the command line arguments 500 */ 501 public static void main(final String args[]) 502 { 503 504 // Start GUI 505 506 java.awt.EventQueue.invokeLater(new Runnable() 507 { 508 509 public void run() 510 { 511 ConvwatchGUI aGUI = new ConvwatchGUI(args); 512 aGUI.setTitle("Graphical Compare"); 513 aGUI.setPreferredSize(new Dimension(1024, 768)); 514 515 aGUI.setVisible(true); 516 } 517 }); 518 } 519 // Variables declaration - do not modify//GEN-BEGIN:variables 520 private javax.swing.JButton jButton1; 521 private javax.swing.JButton jButton2; 522 private javax.swing.JButton jButton3; 523 private javax.swing.JLabel jLabel1; 524 private javax.swing.JLabel jLabelCurrentPage; 525 private javax.swing.JLabel jLabelDifferenceImage; 526 private javax.swing.JLabel jLabelDocumentName; 527 private javax.swing.JLabel jLabelOriginalImage; 528 private javax.swing.JLabel jLabelReferenceImage; 529 private javax.swing.JPanel jPanel4; 530 private javax.swing.JPanel jPanel5; 531 private javax.swing.JPanel jPanelDifference; 532 private javax.swing.JPanel jPanelOriginal; 533 private javax.swing.JPanel jPanelReference; 534 // End of variables declaration//GEN-END:variables 535 } 536