de.hunsicker.swing.util
Class PopupSupport

java.lang.Object
  |
  +--de.hunsicker.swing.util.PopupSupport

public class PopupSupport
extends java.lang.Object

Helper class which adds popup menu support for text components.

Version:
$Revision: 1.2.2.1 $
Author:
Marco Hunsicker

Constructor Summary
PopupSupport()
          Creates a new PopupSuppport object.
PopupSupport(boolean enable)
          Creates a new PopupSuppport object.
PopupSupport(boolean enable, java.util.List supported)
          Creates a new PopupSuppport object.
PopupSupport(java.util.List supported)
          Creates a new PopupSuppport object.
 
Method Summary
 void addSupport(javax.swing.text.JTextComponent component)
          Adds a default popup menu for the given component.
protected  javax.swing.JPopupMenu getPopup(javax.swing.text.JTextComponent component)
          Returns the popup menu for the given component.
protected  boolean isClipboardEmpty()
          Indicates whether the system clipboard contains text content.
protected  boolean isTextSelected(int start, int end)
          Indicates whether a text selection exists.
 void setEnabled(boolean enable)
          Sets the status of the popup menu support.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PopupSupport

public PopupSupport()
Creates a new PopupSuppport object. The popup menu support is initially enabled. The popup support will only be added for components of the javax.swing hierachy.


PopupSupport

public PopupSupport(java.util.List supported)
Creates a new PopupSuppport object. The popup menu support is initially enabled for the given hierachies or classes.

Parameters:
supported - supported package hierarchies or classes.

PopupSupport

public PopupSupport(boolean enable,
                    java.util.List supported)
Creates a new PopupSuppport object.

Parameters:
enable - if true the popup menu support will be initially enabled.
supported - supported package hierarchies or classes.

PopupSupport

public PopupSupport(boolean enable)
Creates a new PopupSuppport object.

Parameters:
enable - if true the popup menu support will be initially enabled.
Method Detail

setEnabled

public void setEnabled(boolean enable)
Sets the status of the popup menu support.

Parameters:
enable - if true the popup menu support will be enabled.

addSupport

public void addSupport(javax.swing.text.JTextComponent component)
Adds a default popup menu for the given component.

Parameters:
component - component to add the popup menu to.

isClipboardEmpty

protected boolean isClipboardEmpty()
Indicates whether the system clipboard contains text content.

Returns:
true if the system clipboard contains no text content.

getPopup

protected javax.swing.JPopupMenu getPopup(javax.swing.text.JTextComponent component)
Returns the popup menu for the given component. The default implementation returns the same default popup menu for all components.

This popup menu consists of five actions:

 +------------+
 | Copy       |
 | Cut        |
 | Paste      |
 | Delete     |
 +------------+
 | Select all |
 +------------+
 

Parameters:
component - component to return the popup menu for.
Returns:
the popup menu for the given component.

isTextSelected

protected boolean isTextSelected(int start,
                                 int end)
Indicates whether a text selection exists.

Parameters:
start - start offset of the text's selection start.
end - end offset of the text's selection end.
Returns:
true if start > end.


Copyright © 1997-2005 Jalopy. All Rights Reserved.