/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.ptc.tifworkbench.ui; import com.mks.api.response.APIException; import com.ptc.tifworkbench.integrity.IntegrityApi; import com.ptc.tifworkbench.integrity.IntegrityConnection; import com.ptc.tifworkbench.integrity.IntegrityExceptionEx; import com.ptc.tifworkbench.model.SolutionViewer; import com.ptc.tifworkbench.reader.SolutionReader; import com.ptc.tifworkbench.worker.ReadSolutionWorker; import com.ptc.tifworkbench.worker.StatusReporter; import com.ptc.tifworkbench.worker.Status; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; /** * * @author pbowden */ public class ReadSolutionProgressDlg extends javax.swing.JDialog { private ReadSolutionWorker worker; private SolutionReader reader; /** * Creates new form ReadSolutionProgressDlg */ public ReadSolutionProgressDlg(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); } public void readSolution(SolutionViewer viewer) throws IntegrityExceptionEx { setConnectionTitle(); reader = new SolutionReader(); worker = new ReadSolutionWorker(reader, viewer, this); reader.setReporter(worker); // The worker will fire Status property events when the solution reader sets // any new status. worker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (StatusReporter.STATUS_PROP.equals(evt.getPropertyName())) { Status stat = (Status)evt.getNewValue(); progressBar.setValue(stat.getProgress()); progressTxt.setText(stat.getMessage()); } } }); worker.execute(); } protected void setConnectionTitle()throws IntegrityExceptionEx { IntegrityConnection conn = IntegrityApi.getInstance().getDefaultConnection(); String connStr = conn.getHost() + ":" + conn.getPort(); this.setTitle("Reading from " + connStr); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { progressTxt = new javax.swing.JTextField(); progressBar = new javax.swing.JProgressBar(); cancelBtn = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); progressTxt.setEditable(false); progressTxt.setBackground(new java.awt.Color(255, 255, 255)); progressTxt.setText("Reading solution"); progressBar.setStringPainted(true); cancelBtn.setText("Cancel"); cancelBtn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelBtnActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(progressTxt) .addComponent(progressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(cancelBtn))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(progressTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelBtn) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-416)/2, (screenSize.height-144)/2, 416, 144); }// </editor-fold>//GEN-END:initComponents private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed worker.cancel(true); progressBar.setValue(0); progressTxt.setText("Cancelled read."); }//GEN-LAST:event_cancelBtnActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(ReadSolutionProgressDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(ReadSolutionProgressDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(ReadSolutionProgressDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(ReadSolutionProgressDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the dialog */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { ReadSolutionProgressDlg dialog = new ReadSolutionProgressDlg(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancelBtn; private javax.swing.JProgressBar progressBar; private javax.swing.JTextField progressTxt; // End of variables declaration//GEN-END:variables }