BaseLogPanel.java :  » UML » MetaBoss » com » metaboss » applications » designstudio » Java Open Source

Java Open Source » UML » MetaBoss 
MetaBoss » com » metaboss » applications » designstudio » BaseLogPanel.java
// THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
// OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Copyright 2000-2005  Softaris Pty.Ltd. All Rights Reserved.
package com.metaboss.applications.designstudio;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;

/*    Base Log Output Panel    */

public class BaseLogPanel extends JPanel
{
  // UI
  protected JEditorPane          mInformationPane = new JEditorPane();
  protected JToolBar           mToolBar = null; 
  // actions
  protected CopyToClipBoardAction   mCopyToClipBoardAction = new CopyToClipBoardAction();
  protected ClearAction        mClearAction = new ClearAction();

  
  public BaseLogPanel()
  {
    super(new BorderLayout());

    setLayout(new BorderLayout());

    mInformationPane.setEditable(false);
    mInformationPane.setContentType("text/plain");
    
    mToolBar = new JToolBar()
    {
          public Dimension getMinimumSize()
          {
        Dimension lResult = super.getMinimumSize();
        lResult.height = 1;
              return lResult;
          }
    };
    
    mToolBar.setBorder(null);
    mToolBar.setOrientation(JToolBar.VERTICAL);
    mToolBar.setRollover(true);

    fillChildControls();
  }
  
    public void setVisible(boolean aFlag)
    {
        super.setVisible(aFlag);
        if (aFlag)
      Application.fillActions(getActions(), mToolBar, null, null);
    }

  
  protected void fillChildControls()
  {
    add(mToolBar, BorderLayout.WEST);
    add(new JScrollPane(mInformationPane));
  }
  
  // get Actions list
  protected Object[] getActions()
  {
    ArrayList lList = new ArrayList();
    fillActions(lList);
    return lList.toArray();
  }
  
  protected void fillActions(ArrayList pList)
  {
    pList.add(mCopyToClipBoardAction);
    pList.add(mClearAction);
  }
  
  protected void copyToClipboard()
  {
    String lContent = mInformationPane.getText();
    Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
    cb.setContents(new StringSelection(lContent), null);
  }
  
  protected void clearContent()
  {
    mInformationPane.setText("");
  }
  
  /*      Actions      */
  
  public class CopyToClipBoardAction extends BaseAction
  {
    public CopyToClipBoardAction()
    {
      super("Copy", "Copy contents of the log to clipboard (Eg. for e-mailing to MetaBoss Support)", Application.COPYTOCLIP_ICON);
    }
    
    public void actionPerformed(ActionEvent arg0)
    {
      copyToClipboard();
    }
  }
  
  public class ClearAction extends BaseAction
  {
    public ClearAction()
    {
      super("Clear", Application.CLEAR_ICON);
    }
    
    public void actionPerformed(ActionEvent arg0)
    {
      clearContent();
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.