alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.cvsclient.commands.update;

/**
 *
 * @author  mkleint
 * @version
 */

import org.netbeans.lib.cvsclient.command.checkout.*;
import org.netbeans.lib.cvsclient.command.*;
import org.netbeans.modules.vcscore.util.Debug;
import org.netbeans.modules.cvsclient.commands.*;
import org.netbeans.modules.cvsclient.FsCommandFactory;
import org.netbeans.modules.javacvs.events.*;
import org.netbeans.modules.javacvs.commands.*;
import org.openide.filesystems.FileUtil;
import javax.swing.text.*;
import javax.swing.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;
import java.io.File;
import java.util.*;
import org.openide.util.NbBundle;
import javax.accessibility.*;
import org.openide.filesystems.FileObject;

public class UpdateStdOutPanel extends javax.swing.JPanel 
                               implements PersistentCommandDisplayer {
    private Debug E=new Debug("UpdateStdOutPanel", true); // NOI18N
    private Debug D=E;
    private FileSystemCommand currentCommand;
    private ClientProvider provider;
    private PipedFileInformation currentInfo;
    
    /** Creates new form UpdateStdOutPanel */
    public UpdateStdOutPanel(FileSystemCommand comm) {
        initComponents ();
        initAccessibility();
        currentCommand = comm;
        epFile.setEditable(false);
    }
    
    public void setCommand(FileSystemCommand comm) {
        currentCommand = comm;
    }
    
    /** 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 FormEditor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        pnlHeader = new javax.swing.JPanel();
        lblFileName = new javax.swing.JLabel();
        lblRevNumber = new javax.swing.JLabel();
        lblRevFile = new javax.swing.JLabel();
        txRevFile = new javax.swing.JTextField();
        txFileName = new javax.swing.JTextField();
        txRevNumber = new javax.swing.JTextField();
        spFile = new javax.swing.JScrollPane();
        epFile = new javax.swing.JEditorPane();

        setLayout(new java.awt.GridBagLayout());

        pnlHeader.setLayout(new java.awt.GridBagLayout());

        lblFileName.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/update/Bundle").getString("ACS_lblFileName_mnc").charAt(0));
        lblFileName.setLabelFor(txFileName);
        lblFileName.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/update/Bundle").getString("UpdateStdOutPanel.lblFileName.text"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        pnlHeader.add(lblFileName, gridBagConstraints);

        lblRevNumber.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/update/Bundle").getString("ACS_lblRevNumber_mnc").charAt(0));
        lblRevNumber.setLabelFor(txRevNumber);
        lblRevNumber.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/update/Bundle").getString("UpdateStdOutPanel.lblRevNumber.text"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
        pnlHeader.add(lblRevNumber, gridBagConstraints);

        lblRevFile.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/update/Bundle").getString("ACS_lblRevFile_mnc").charAt(0));
        lblRevFile.setLabelFor(txRevFile);
        lblRevFile.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/update/Bundle").getString("UpdateStdOutPanel.lblRevFile.text"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
        pnlHeader.add(lblRevFile, gridBagConstraints);

        txRevFile.setEditable(false);
        txRevFile.setText("jTextField1");
        txRevFile.setMinimumSize(new java.awt.Dimension(60, 20));
        txRevFile.setPreferredSize(new java.awt.Dimension(400, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0);
        pnlHeader.add(txRevFile, gridBagConstraints);

        txFileName.setEditable(false);
        txFileName.setText("jTextField1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0);
        pnlHeader.add(txFileName, gridBagConstraints);

        txRevNumber.setEditable(false);
        txRevNumber.setText("jTextField1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        pnlHeader.add(txRevNumber, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 11);
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        add(pnlHeader, gridBagConstraints);

        spFile.setViewportView(epFile);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(0, 12, 11, 11);
        gridBagConstraints.weighty = 1.0;
        add(spFile, gridBagConstraints);

    }//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JEditorPane epFile;
    private javax.swing.JLabel lblRevFile;
    private javax.swing.JPanel pnlHeader;
    private javax.swing.JTextField txFileName;
    private javax.swing.JTextField txRevNumber;
    private javax.swing.JLabel lblRevNumber;
    private javax.swing.JScrollPane spFile;
    private javax.swing.JTextField txRevFile;
    private javax.swing.JLabel lblFileName;
    // End of variables declaration//GEN-END:variables

    private static final java.util.ResourceBundle bundle = NbBundle.getBundle(UpdateStdOutPanel.class);     // NOI18N
    
    private void initAccessibility() {
        txFileName.selectAll();
        txRevNumber.selectAll();
        txRevFile.selectAll();
        
        SelectAllListener focusListener = new SelectAllListener();
        txFileName.addFocusListener(focusListener);
        txRevNumber.addFocusListener(focusListener);
        txRevFile.addFocusListener(focusListener);
        
        AccessibleContext context = this.getAccessibleContext();
        context.setAccessibleName(bundle.getString("ACSD_UpdateStdOutPanel"));
        
        context = epFile.getAccessibleContext();
        context.setAccessibleName(bundle.getString("ACSD_UpdateStdOutPanel.epFile"));
        
    }  
    
    class SelectAllListener implements java.awt.event.FocusListener{
        public void focusLost(java.awt.event.FocusEvent e){}
        public void focusGained(java.awt.event.FocusEvent e){
            ((javax.swing.JTextField)e.getComponent()).selectAll();
        }
    }
    
    public void setData(PipedFileInformation info) {
        currentInfo = info;
        txFileName.setText(info.getFile().getAbsolutePath());
        txRevNumber.setText(info.getRepositoryRevision());
        txRevFile.setText(info.getRepositoryFileName());
        //setting up editor kit
        if (info.getTempFile().exists()) {
            String mime = getMIMEType(info);
            epFile.setContentType(mime);
            EditorKit kit = JEditorPane.createEditorKitForContentType(mime);
            D.deb("MIME = "+mime+": I have kit = "+kit); // NOI18N
            if (kit == null) {
                epFile.setContentType("text/plain"); // NOI18N
                kit = JEditorPane.createEditorKitForContentType("text/plain"); // NOI18N
            }
            epFile.setEditorKit(kit);
            Document doc = kit.createDefaultDocument();
            try {
                URL flURL = info.getTempFile().toURL();
                try {
                    kit.read(flURL.openStream(), doc, 0);
                    kit.install(epFile);
                    epFile.setDocument(doc);
                } catch (javax.swing.text.BadLocationException e) {
                    E.err("BadLocationException"); // NOI18N
                    return;
                } catch (IOException ex) {
                    E.err("IOException"); // NOI18N
                    return;
                }
                
            } catch (MalformedURLException exc) {
                E.err("malformed URL"); // NOI18N
            }
            epFile.setDocument(doc);
        }
        
    }
    
    private String getMIMEType(PipedFileInformation info) {
        File file = info.getFile();
        if (file == null) return "text/plain"; //NOI18N
        String mime;
        FileObject[] fos = FileUtil.fromFile(file);
        if (fos.length > 0) {
            mime = FileUtil.getMIMEType(fos[0]);
        } else {
            String ext = FileUtil.getExtension(file.getName());
            mime = FileUtil.getMIMEType(ext);
        }
        if (mime == null) {
            mime = "text/plain"; //NOI18N
        }
        return mime;
    }
    
    
    /** Does the actual display - docking into the javacvs Mode, 
 *  displaying as single Dialog.. whatever.
 */
    public void displayOutputData() {
       FsCommandFactory.displayOutputPanel(NbBundle.getBundle(UpdateStdOutPanel.class).getString("CvsUpdate.pipedOutDialogTitle")  // NOI18N
               + currentInfo.getFile().getName() + ":" + currentInfo.getRepositoryRevision(),  // NOI18N
                 this);                    
    }
    

    
   // --------------------------------------------
  // persistantDisplayer stuff..
  // --------------------------------------------
    
  public boolean equalDisplayedData(File file, Class type, Object comparisonData) {
      if (!getClass().equals(type)) return false;
      if (currentInfo == null || currentInfo.getFile() == null
                || !currentInfo.getFile().equals(file)) {
          return false;
      }
      PipedFileInformation info = (PipedFileInformation)comparisonData;
      if (info == null) {
          return false;
      }
      if (!currentInfo.getRepositoryRevision().equals(info.getRepositoryRevision())) {
          return false;
      }
      return true;
  }

  public File getFileDisplayed() {
      return currentInfo.getFile();
  }
   
  public Object getComparisonData() {
      return currentInfo;
  }
   
  public JComponent getComponent() {
      return this;
  }

  public FileSystemCommand getFileSystemCommand() {
      return currentCommand; //TODO
  }  
    
  public String getCommandSwitches() {
      return currentCommand.getCVSArguments();
  }
  
  public void closeNotify() {
/**      if (currentInfo != null && currentInfo.getTempFile() != null) {
          currentInfo.getTempFile().deleteOnExit();
      }
 */
  }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.