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.log;


import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.tree.DefaultMutableTreeNode;

import org.netbeans.lib.cvsclient.command.log.LogCommand;
import org.netbeans.lib.cvsclient.command.log.LogInformation;
import org.netbeans.modules.cvsclient.FsCommandFactory;
import org.openide.util.*;
import org.netbeans.modules.cvsclient.commands.*;
import org.netbeans.modules.javacvs.commands.FileSystemCommand;
import org.netbeans.modules.javacvs.commands.CvsLog;
import org.netbeans.lib.cvsclient.command.*;
/**
 *
 * @author  mkleint
 * @version
 */
public class LogTreeInfoPanel extends AbstractTreeInfoPanel 
                              implements PersistentCommandDisplayer {
    
    private LogInfoPanel logPanel;
    private LogInformation clearLogInfo;
    private CvsLog command;
    private JTextField txFilter;
    private JLabel lblFilter;
    private JLabel lblTitle;
    private String filterString = null;
    private int totalCount = 0;
    private int selectedCount = 0;
    private javax.swing.JLabel lblCount;   

    /** Creates new form StatusTreeInfoPanel */
    public LogTreeInfoPanel(File topDir, CvsLog comm) {        
        super(topDir);        
        command = comm;
        initPanelComponents();
        postInit();
 //       recreateModel();
    }
    
    private void initPanelComponents() {
        JPanel panel = getButtonPanel();
        lblTitle = new javax.swing.JLabel();
        lblFilter = new javax.swing.JLabel();
        txFilter = new javax.swing.JTextField();
        lblCount = new javax.swing.JLabel();
        panel.setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints1;
        
        lblTitle.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/log/Bundle").getString("LogTreeInfoPanel.lblTitle.text")); // NOI18N
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints1.weightx = 1.0;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets (12, 12, 0, 11);
        panel.add(lblTitle, gridBagConstraints1);
        
        lblFilter.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/log/Bundle").getString("LogTreeInfoPanel.filterLog")); // NOI18N
        lblFilter.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/log/Bundle").getString("LogTreeInfoPanel.filterLog.mnemonic").charAt(0)); // NOI18N
        lblFilter.setLabelFor(txFilter);
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 1;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets(5, 24, 11, 0);
        panel.add(lblFilter, gridBagConstraints1);
        
        //txFilter.setPreferredSize(new java.awt.Dimension(100, 20));
        txFilter.setText(""); // NOI18N
        txFilter.setMinimumSize(new java.awt.Dimension(100, 20));
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 1;
        gridBagConstraints1.gridy = 1;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints1.insets = new java.awt.Insets(5, 12, 11, 11);
        panel.add(txFilter, gridBagConstraints1);
        
        lblCount.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/cvsclient/commands/log/Bundle").getString("LogTreeInfoPanel.lblCount")); // NOI18N
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 2;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints1.insets = new java.awt.Insets(5, 12, 2, 11);
        panel.add(lblCount, gridBagConstraints1);
 

//---- ENDO OF COPIED STUFF --- ===================================================
// =========================================================================
        txFilter.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                filterLogMessages();
            }    
        });      
    }    
    
    
  private void initClearInfo() {
      clearLogInfo = new LogInformation();
      clearLogInfo.setFile(new File("")); // NOI18N
      clearLogInfo.setAccessList(""); // NOI18N
      clearLogInfo.setBranch(""); // NOI18N
      clearLogInfo.setDescription(""); // NOI18N
      clearLogInfo.setHeadRevision(""); // NOI18N
      clearLogInfo.setKeywordSubstitution(""); // NOI18N
      clearLogInfo.setLocks(""); // NOI18N
      clearLogInfo.setRepositoryFilename(""); // NOI18N
      clearLogInfo.setSelectedRevisions(""); // NOI18N
      clearLogInfo.setTotalRevisions(""); // NOI18N
  }
  
  
  protected void setPanel(Object infoData) {
      LogInformation logData = (LogInformation)infoData;
      logPanel.setData(logData);
  }
  
  protected JComponent initPanel() {
      initClearInfo();
      logPanel = new LogInfoPanel(command);
      setClearPanel();
      return logPanel;
  }
  
  protected void setClearPanel() {
      logPanel.setData(clearLogInfo);
  }

/** Does the actual display - docking into the javacvs Mode, 
 *  displaying as single Dialog.. whatever.
 */
  public void displayOutputData() {
     String title = NbBundle.getMessage(LogTreeInfoPanel.class, 
                                     "CvsLog.dialogTitle", topDirectory.getName()); // NOI18N
     FsCommandFactory.displayOutputPanel(title, this);

  }
  
  private void filterLogMessages() {
      String filter = txFilter.getText(); 
      if (filter.trim().equals("")) filterString = null; // NOI18N
      else filterString = filter;
      totalCount = 0;
      selectedCount = 0;
      recreateModel();
      Integer selCount = new Integer(selectedCount);
      Integer totCount = new Integer(totalCount);
      String txt = NbBundle.getMessage(LogTreeInfoPanel.class, "LogTreeInfoPanel.lblCount", // NOI18N
                                selCount.toString(), totCount.toString());
      lblCount.setText(txt);
  }    
  
  /** defines which InfoContainer instances will be added to the tree
   * By default adds all, can be overriden by subclasses to define filtering
 */
  protected void addFileNode(FileInfoContainer info,DefaultMutableTreeNode parent) {
      LogInformation logInfo = (LogInformation)info;
      totalCount = totalCount + 1;
      if (shouldAddLogInfo(logInfo)) {
            DefaultMutableTreeNode child = new DefaultMutableTreeNode(info);
            parent.add(child);
            selectedCount = selectedCount + 1;
      }    
  }
  
  /** defines which InfoContainer instances will be added to the table
   * By default adds all, can be overriden by subclasses to define filtering
 */
  protected boolean addToList(FileInfoContainer info) {
      LogInformation logInfo = (LogInformation)info;
      return shouldAddLogInfo(logInfo);
  }
  
  private boolean shouldAddLogInfo(LogInformation info) {
      if (filterString == null) return true;
      List revList = info.getRevisionList();
      Iterator it = revList.iterator();
      while (it.hasNext()) {
          LogInformation.Revision revis = (LogInformation.Revision)it.next();
          if (revis.getMessage() != null && revis.getMessage().indexOf(filterString) >= 0) {
              return true;
          }    
      }    
      return false;
  }    
  
  /** in this method the displayer should use the data returned by the command to
   * produce it's own data structures/ fill in UI components
   * @param resultList - the data from the command. It is assumed the Displayer 
   * knows what command the data comes from and most important in what format. 
   * (which FileInfoContainer class is used).
 */
  public void setDataToDisplay(Collection resultList) {
      totalCount = 0;
      selectedCount = 0;
      super.setDataToDisplay(resultList);
      Integer selCount = new Integer(selectedCount);
      Integer totCount = new Integer(totalCount);
      String txt = NbBundle.getMessage(LogTreeInfoPanel.class, "LogTreeInfoPanel.lblCount", // NOI18N
                                selCount.toString(), totCount.toString());
      lblCount.setText(txt);
  }

  
  public void setCommand(CvsLog comm) {
        command = comm;
  }
 
  public JComponent getComponent() {
      return this;
  }
  
  public Object getComparisonData() {
      return topDirectory;
  }
  
  /**
   * Persistent stuff...
   */
  public boolean equalDisplayedData(File file, Class type, Object comparisonData) {
      if (!getClass().equals(type)) return false;
      if (topDirectory == null || 
                !topDirectory.equals(file)) {
          return false;
      }
      return true;
  }
  
  public File getFileDisplayed() {
      return topDirectory;
  }
  
  
  public String getCommandSwitches() {
      return command.getCVSArguments();
  }
  
  
  public FileSystemCommand getFileSystemCommand() {
      return command;
  }
  
}
... 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.