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;

import org.netbeans.modules.javacvs.events.CommandDisplayerListener;
import org.netbeans.lib.cvsclient.event.MessageEvent;
import javax.swing.*;
import java.awt.*;
import org.openide.util.NbBundle;
import org.openide.*;
import javax.accessibility.*;
import java.util.*;
import org.openide.DialogDisplayer;

import org.openide.util.actions.SystemAction;
import org.openide.windows.WindowManager;

/**
 *
 * @author  mk104111
 */
public class DefaultInfoPanel extends org.openide.windows.TopComponent 
                              implements CommandDisplayerListener,
                                         RuntimeCommandDisplayer {

    public static final String JAVACVS_LIMITED_MODE = "LIMITED JavaCvs mode- for output of update, commit, add, remove etc."; // NOI18N
    private StringBuffer buff;
    
    private boolean runsFromRuntime;
    
    /** Creates new form DefaultInfoPanel */
    public DefaultInfoPanel() {
        super();
        buff = new StringBuffer();
        runsFromRuntime = false;
        putClientProperty("PersistenceType", "Never"); //NOI18N
        // http://www.netbeans.org/issues/show_bug.cgi?id=24199
        // the TabPolicy property's value makes sure that the tab is not shown 
        // for the topcomponent when it is alone in the mode.
        putClientProperty("TabPolicy", "HideWhenAlone");        
    }
    
    /** 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.
     */
    private void initComponents() {//GEN-BEGIN:initComponents

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

    }//GEN-END:initComponents
    
    /**
     * this one is called when the command's execution  fails for any reason.
     */
    public void showExecutionFailed(Exception exception) {
    }
    
    /**
     * When the server generates a line of output/error, the displayer is notified.
     * @param message - the string to be displayed, be it error/message (E/M response)
     */
    public void messageGenerated(MessageEvent e) {
        if (e.isTagged()) {
            String line = e.getMessage();
            if (line.charAt(0) == '+' || line.charAt(0) == '-') {
                return;
            }
            if (line.equals("newline")) { // NOI18N
                buff.append("\n"); // NOI18N
                return;
            }
            int index = line.indexOf(' ');
            if (index > 0) {
                buff.append(line.substring(index + 1));
            }
        }
        else {
            if (e.getMessage().length() > 0) {
                buff.append(e.getMessage() + "\n"); // NOI18N
            }
        }
        if (buff.length() > 36000) { // just approx. constants, tuneup possible..
            buff.delete(0, 8000);
            int index = 0;
            while (index < buff.length() && buff.charAt(index) != '\n') {
                index = index + 1;
            }
            buff.delete(0, index);
            buff.insert(0, NbBundle.getBundle(DefaultInfoPanel.class).getString("DefaultInfoPanel.logCut") + "\n");
        }
    }
    
    /**
     * this method is called before any of the library's commands
     * that is stored in the queue in FileSystemCommand, is run.
     * @param currentCommand shows the command that will be executed.
     */
    public void showBeforeEachExecute(org.netbeans.lib.cvsclient.command.Command currentCommand) {
    }
    
    /**
     * This is the last method to be called in the displayer.
     * Is called when the execution finishes. Any filan touchups can be made here.
     */
    public void showFinishedCommand() {
    }
    
    /**
     * This method is the first one that is called during execution.
     * Here any initial setup of the displayer can be made.
     */
    public void showStartCommand() {
    }
    
    /**
     * this method is called after library's commands execution
     */
    public void showAfterEachExecute() {
    }
    
    /**
     * When the library command's builder generates a FileInfoContainer object, the
     * Displayer is notified.
     * @param info - the generated information object
     */
    public void showFileInfoGenerated(org.netbeans.lib.cvsclient.command.FileInfoContainer info) {
    }
    
    protected String getCurrentCommandLog() {
        return buff.toString();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    protected void doShowCommandLog(final JButton button) {
        // begin visual stuff --------------
        JPanel toReturn = new JPanel();
        toReturn.setLayout(new BorderLayout());
        JScrollPane pane = new JScrollPane();
        JTextArea area = new JTextArea();
        //accessibility stuff..
        ResourceBundle bundle = NbBundle.getBundle(DefaultInfoPanel.class); //NOI18N
        AccessibleContext context = toReturn.getAccessibleContext();
        context.setAccessibleDescription(bundle.getString("ACSD_ShowComandLog"));
        
        context = area.getAccessibleContext();
        context.setAccessibleDescription(bundle.getString("ACSD_ShowCommandLog.area"));
        context.setAccessibleName(bundle.getString("ACSN_ShowCommandLog.area"));

        area.setLineWrap(false);
        if (buff != null) {
            area.setText(getCurrentCommandLog());
        }    
        area.setEditable(false);
        javax.swing.KeyStroke enter = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, 0);
        javax.swing.text.Keymap map = area.getKeymap ();
        map.removeKeyStrokeBinding (enter);

        pane.setPreferredSize(new Dimension(400, 100));
        pane.setViewportView(area);
        toReturn.add(pane, BorderLayout.CENTER);
        // - end visual stuff -------------------
        String title = NbBundle.getBundle(DefaultInfoPanel.class).getString("DefaultInfoPanel.commandLogTitle"); // NOI18N
        toReturn.setSize(new Dimension(450, 200));
        toReturn.setMinimumSize(new Dimension(250, 100));
        DialogDescriptor dd = new DialogDescriptor(toReturn, title);
        JButton btnClose = new JButton();
        btnClose.setText(org.openide.util.NbBundle.getBundle(DefaultInfoPanel.class).getString("DefaultInfoPanel.closeButton")); // NOI18N
        btnClose.setMnemonic(org.openide.util.NbBundle.getBundle(DefaultInfoPanel.class).getString("DefaultInfoPanel.closeButton.mnemonic").charAt(0)); // NOI18N
        btnClose.setDefaultCapable(true);
        dd.setValue(btnClose);
        Object[] options = { btnClose };
        dd.setOptions(options);
/*        dd.setButtonListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
            }
            
        });
 */
        dd.setClosingOptions(options);
        dd.setModal(false);
        Dialog dial = DialogDisplayer.getDefault().createDialog(dd);
        dial.setModal(true);
        dial.show();
        button.setEnabled(true);
    }    
    
    public void setRunInRuntime(boolean runtime) {
        runsFromRuntime = runtime;
    }
    
    protected boolean isRunningFromRuntime() {
        return runsFromRuntime;
    }
    
    protected void closeNotify() {
        super.closeNotify();
    }
    
    protected void openNotify() {
        super.openNotify();
    }
    
    public boolean canClose(org.openide.windows.Workspace workspace, boolean param) {
        return true;
    }
    
        /**
         * Disable serialization.
         * @return null
         */
        protected Object writeReplace () throws java.io.ObjectStreamException {
            return null;
        }
        
    /** Get the system actions which will appear in
     * the popup menu of this component.
     * 

Subclasses are encouraged to override this method to specify * their own sets of actions. *

Remember to call the super method when overriding and add your actions * to the superclass' ones (in some order),? * because the default implementation provides support for standard * component actions like save, close, and clone. * @return system actions for this component */ public SystemAction[] getSystemActions() { SystemAction[] retValue; retValue = super.getSystemActions(); return retValue; } protected void shutDownCommand() { } public class StopActionListener implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent actionEvent) { DefaultInfoPanel.this.shutDownCommand(); } } public class CloseActionListener implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent actionEvent) { DefaultInfoPanel.this.close(); } } public class ViewLogActionListener implements java.awt.event.ActionListener { private JButton button; public ViewLogActionListener(JButton button) { this.button = button; } public void actionPerformed(java.awt.event.ActionEvent actionEvent) { /* boolean ok = false; if (button.isEnabled()) { ok = true; } */ button.setEnabled(false); // if (ok) { DefaultInfoPanel.this.doShowCommandLog(button); // } } } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 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.