org.gnu.gtk
Class Widget

java.lang.Object
  |
  +--org.gnu.glib.GObject
        |
        +--org.gnu.gtk.GtkObject
              |
              +--org.gnu.gtk.Widget
Direct Known Subclasses:
Calendar, Container, DrawingArea, Editable, Invisible, Misc, Progress, Range, Ruler, Separator, SimpleList

public class Widget
extends GtkObject

GtkWidget is the base class of all widgets.


Constructor Summary
Widget(int handle)
          Create a new Widget with a handle to a native resource returned from a call to the native libraries.
 
Method Summary
 boolean activate()
          For widgets that can be activeated (buttons, menu items, etc.) this method activiates them.
 void addListener(DragDestinationListener listener)
          Register an object to receive drag drop (destination) events.
 void addListener(DragSourceListener listener)
          Register an object to receive drag source events.
 void addListener(FocusListener listener)
          Register an object to receive focus event notification.
 void addListener(KeyListener listener)
          Register an object to receive key event notification.
 void addListener(LifeCycleListener listener)
          Register an object to receive life cycle event notification.
 void addListener(MouseListener listener)
          Register an object to receive mouse event notification.
 Context createContext()
          Creates a new Context with the appropriate Colormap, FontDescription, and base direction for drawing text for this widget.
 Layout createLayout(java.lang.String text)
          Creates a new Layout with the appropriate Colormap, FontDescription and base direction for drawing text for this widget.
 void destroy()
          Destroy this widget.
 void draw()
          Causes the entire widget to be redrawn.
 void drawArea(int x, int y, int width, int height)
          Causes the specified area to be redrawn
 void drawArea(Rectangle area)
          Causes the specified area to be redrawn.
 AtkObject getAccessible()
          Returns the accessible object associated with this widget.
 Colormap getColormap()
          Returns the Colormap that will be used to render this widget.
 Context getContext()
          Gets a Context with the appropriate Colormap, FontDescription and base direction for this widget.
 java.lang.Class getEventListenerClass(java.lang.String signal)
           
 GtkEventType getEventType(java.lang.String signal)
           
 RcStyle getModifierStyle()
          Retruns the Widget's RcStyle.
 java.lang.String getName()
          Returns the name for the widget.
 Widget getParent()
          Returns the parent container for this widget
 Window getParentWindow()
          Returns the widget's parent window.
 Point getPointer()
          Returns the location of the mouse pointer in widget coordinates.
 boolean getSensitive()
          Gets the sensitivity of the widget.
 Style getStyle()
          Returns the Widgets Style.
 Widget getToplevel()
          Returns the topmost widget in the container hierarchy.
static Type getType()
          Retrieve the runtime type used by the GLib library.
 void grabDefault()
          Causes the widget to become the default widget.
 void grabFocus()
          Causes the widget to gain focus within its' TOPLEVEL.
 boolean hasFocus()
          Determines if the widget has focus within its' TOPLEVEL.
 void hide()
          Cause this Widget to not be visible.
 void hideAll()
          Cause this Widget and all of its' children to not be visible.
 Rectangle intersect(Rectangle area)
          Computes the intersection of the widget's area and area.
 boolean isAncestor(Widget ancestor)
          Determines whether this widget is somewhere inside of ancestor.
static Widget makeWidget(int handle)
          Create a Java-GNOME Widget subclass from an existing native GTK+ handle.
 void modifyStyle(RcStyle style)
          Modifies style values on the Widget.
 void popColormap()
          Pops the top colormap off of the stack of colormaps.
 void pushColormap(Colormap colormap)
          Pushes a Colormap onto the stack of colormaps.
 void realize()
          Creates a native window resource associated with this widget.
 void removeListener(DragDestinationListener listener)
          Unregister an object that was receiving dragDestination event notification.
 void removeListener(DragSourceListener listener)
          Unregister an object that was receiving drag source event notification.
 void removeListener(FocusListener listener)
          Unregister an object that was receiving focus event notification.
 void removeListener(KeyListener listener)
          Unregister an object that was receiving key event notification.
 void removeListener(LifeCycleListener listener)
          Unregister an object that was receiving life cycle event notification.
 void removeListener(MouseListener listener)
          Unregister an object that was receiving mouse event notification.
 void reparent(Widget newParent)
          Moves a widget from one Container to another.
 void setBackgroundColor(StateType state, Color color)
          Sets the background color for a widget in a particular state.
 void setBaseColor(StateType state, Color color)
          Sets the base color used for a widget in a particular state.
 void setColormap(Colormap colormap)
          Set the Colormap that will be used to render this widget.
 void setDoubleBuffered(boolean doubleBuffered)
          Enables/Disables double buffering for this widget.
 void setDragDestination(DestDefaults flags, TargetEntry[] targets, DragAction actions)
          Sets up the widget so that is can receive drops as part of drag drop events and specifies what sort of drops it will accept
 void setDragSource(ModifierType buttons, TargetEntry[] targets, DragAction actions)
          Sets up the widget so that it can be the source of drag and drop operations.
 void setFont(FontDescription fontDesc)
          Sets the font to use for the widget.
 void setForegroundColor(StateType state, Color color)
          Sets the foreground color for a widget in a particular state.
 void setMinimumSize(int width, int height)
          Sets the minimum size of a widget.
 void setName(java.lang.String name)
          Sets the name for this widget.
 void setNoDragDestination()
          Removes support for this widget being a drag and drop target
 void setNoDragSource()
          Removes support for this widget being a drag and drop source.
 void setSensitive(boolean sensitive)
          Sets the sensitivity of the widget.
 void setTextColor(StateType state, Color color)
          Sets the text color for a widget in a particilar state.
 void shapeCombineMask(Bitmap shapeMask, int x, int y)
          Sets the shape of this widgets OS window.
 void show()
          Cause this Widget to be visible.
 void showAll()
          Cause this Widget and all of its' children to be visible.
 
Methods inherited from class org.gnu.glib.GObject
addEventHandler, addEventHandler, addEventHandler, addEventHandler, addEventHandler, addEventHandler, equals, getData, getHandle, removeEventHandler, setData
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Widget

public Widget(int handle)
Create a new Widget with a handle to a native resource returned from a call to the native libraries.

Parameters:
handle - The handle that represents a pointer to a native resource.
Method Detail

show

public void show()
Cause this Widget to be visible.


showAll

public void showAll()
Cause this Widget and all of its' children to be visible.


hide

public void hide()
Cause this Widget to not be visible.


hideAll

public void hideAll()
Cause this Widget and all of its' children to not be visible.


destroy

public void destroy()
Destroy this widget. If this widget is inside a container the widget will be removed from the container. All of this widget's children are also destroyed.

Overrides:
destroy in class GtkObject

realize

public void realize()
Creates a native window resource associated with this widget. Normally a widget realization happens implicitly; if you show a widget and all of its' parent containers then the widget will be realized automatically.


draw

public void draw()
Causes the entire widget to be redrawn.


drawArea

public void drawArea(Rectangle area)
Causes the specified area to be redrawn.

Parameters:
area - The area to be redrawn.

drawArea

public void drawArea(int x,
                     int y,
                     int width,
                     int height)
Causes the specified area to be redrawn

Parameters:
x - The x coordinate for the area to be redrawn.
y - The y coordinate for the area to be redrawn.
width - The width of the area to be redrawn.
height - The height of the area to be redrawn.

activate

public boolean activate()
For widgets that can be activeated (buttons, menu items, etc.) this method activiates them. Activation is what happens when you press Enter on a widget during keyboard navigation.

Returns:
False if this widget is not activatable.

reparent

public void reparent(Widget newParent)
Moves a widget from one Container to another.

Parameters:
newParent - The widget that will be the new parent.

getParent

public Widget getParent()
Returns the parent container for this widget

Returns:
The parent container for this widget.

getParentWindow

public Window getParentWindow()
Returns the widget's parent window.

Returns:
Returns the widget's parent window.

intersect

public Rectangle intersect(Rectangle area)
Computes the intersection of the widget's area and area.

Parameters:
area - The area to use to compute the intersection.
Returns:
The intersection. If the areas don't intersect this method returns null.

hasFocus

public boolean hasFocus()
Determines if the widget has focus within its' TOPLEVEL.

Returns:
true if the widget has focus.

grabFocus

public void grabFocus()
Causes the widget to gain focus within its' TOPLEVEL.


grabDefault

public void grabDefault()
Causes the widget to become the default widget. The default widget is activated when the user presses Enter in the window. Default widgets must be activatable.


setName

public void setName(java.lang.String name)
Sets the name for this widget. Widgets can be named which allows you to refer to them from a gtkrc file. You can apply a style to widgets with a particular name in the gtkrc file.

Parameters:
name - The name for the widget.

getName

public java.lang.String getName()
Returns the name for the widget.

Returns:
The name for the widget.

setSensitive

public void setSensitive(boolean sensitive)
Sets the sensitivity of the widget.

Parameters:
sensitive - Indicates if the widget should be sensitive.

getSensitive

public boolean getSensitive()
Gets the sensitivity of the widget.

Returns:
true if the widget is sensitive, false otherwise.

getToplevel

public Widget getToplevel()
Returns the topmost widget in the container hierarchy.

Returns:
The topmost widget.

getColormap

public Colormap getColormap()
Returns the Colormap that will be used to render this widget.

Returns:
The colormap used for this widget.

setColormap

public void setColormap(Colormap colormap)
Set the Colormap that will be used to render this widget.

Parameters:
colormap - The colormap to be used.

getPointer

public Point getPointer()
Returns the location of the mouse pointer in widget coordinates. This method will return null if the mouse is not currently in the widget.

Returns:
The location of the mouse or null

isAncestor

public boolean isAncestor(Widget ancestor)
Determines whether this widget is somewhere inside of ancestor.

Parameters:
ancestor - The possible parent widget

pushColormap

public void pushColormap(Colormap colormap)
Pushes a Colormap onto the stack of colormaps. The topmost Colormap on the stack will be used to create all Widgets.

Parameters:
colormap - The Colormap to push onto the stack.

popColormap

public void popColormap()
Pops the top colormap off of the stack of colormaps. The topmost Colormap on the stack will be used to create all Widgets.


shapeCombineMask

public void shapeCombineMask(Bitmap shapeMask,
                             int x,
                             int y)
Sets the shape of this widgets OS window. This allows for transparent windows.

Parameters:
shapeMask - Shape to be added or null to remove an existing shape.
x - X Position of the shape mask with respect to the window.
y - Y Position of the shape mask with respect to the window.

setForegroundColor

public void setForegroundColor(StateType state,
                               Color color)
Sets the foreground color for a widget in a particular state. All other style values are left untouched.

Parameters:
state - The widget state to modify.
color - The color to set the foreground.

setBackgroundColor

public void setBackgroundColor(StateType state,
                               Color color)
Sets the background color for a widget in a particular state. All other style values are left untouched.

Parameters:
state - The widget state to modify.
color - The color to set the background.

setTextColor

public void setTextColor(StateType state,
                         Color color)
Sets the text color for a widget in a particilar state. All other style values are left untouched. The text color is the foreground color along with the base color for widgets such as Entry, TextView, etc.

Parameters:
state - The widget state to modify.
color - The color to set the text.

setBaseColor

public void setBaseColor(StateType state,
                         Color color)
Sets the base color used for a widget in a particular state. The base color is the backgound color used along with the text color for widgets such as Entry, TextView, etc.

Parameters:
state - The widget state to modify.
color - The color to set.

setFont

public void setFont(FontDescription fontDesc)
Sets the font to use for the widget.

Parameters:
fontDesc - The font description to use.

modifyStyle

public void modifyStyle(RcStyle style)
Modifies style values on the Widget. Modifications made using this technique take precedence over style values set via an RC file.

Parameters:
style - The style to apply to the Widget

getModifierStyle

public RcStyle getModifierStyle()
Retruns the Widget's RcStyle.

Returns:
The current RcStyle for the Widget.

getStyle

public Style getStyle()
Returns the Widgets Style.

Returns:
The current Style for the Widget.

createContext

public Context createContext()
Creates a new Context with the appropriate Colormap, FontDescription, and base direction for drawing text for this widget.

Returns:
A context that can be used for drawig text.

getContext

public Context getContext()
Gets a Context with the appropriate Colormap, FontDescription and base direction for this widget. Unlike the createContext method, this context is owned by the widget and can be as long as the widget exists. This context will be updated to match any changes to the widget's attributes.

Returns:
A context that can be used for drawing text.

createLayout

public Layout createLayout(java.lang.String text)
Creates a new Layout with the appropriate Colormap, FontDescription and base direction for drawing text for this widget.

Parameters:
text - The text used for the layout.
Returns:
The layout that can be used for drawing text.

setDoubleBuffered

public void setDoubleBuffered(boolean doubleBuffered)
Enables/Disables double buffering for this widget. Widgets are double buffered by default.

Parameters:
doubleBuffered - Set if the widget should be double buffered.

getAccessible

public AtkObject getAccessible()
Returns the accessible object associated with this widget.


setMinimumSize

public void setMinimumSize(int width,
                           int height)
Sets the minimum size of a widget. You can use this method to force a widget to be either larger or smaller that it normally be.

In most cases Window.setDefaultSize() is a better choice for toplevel windows than this method. Setting the default size will still allow users to shrink the window. Setting the minimum size will force them to leave the window at least as large as the request.

Note the inherent danger of setting any fixed size - themes, translations into other languages, different fonts, and user action can change the appropriate size for a given widget. So, it's basically impossible to hardcode a size that will always be correct.

If the minimum size in a given direction is -1 then the "natural" size for the widget will be used instead.

Parameters:
width - The minimum width size to use.
height - The minimum height size to use.

getEventListenerClass

public java.lang.Class getEventListenerClass(java.lang.String signal)

getEventType

public GtkEventType getEventType(java.lang.String signal)

addListener

public void addListener(LifeCycleListener listener)
Register an object to receive life cycle event notification.

Parameters:
listener - The object that has implemented the LifeCycleListener interface that is to receive the life cycle events.

removeListener

public void removeListener(LifeCycleListener listener)
Unregister an object that was receiving life cycle event notification.

Parameters:
listener - The object that is to no longer receive life cycle events.

addListener

public void addListener(FocusListener listener)
Register an object to receive focus event notification.

Parameters:
listener - The object that has implemented the FocusListener interface that is to receive the focus events.

removeListener

public void removeListener(FocusListener listener)
Unregister an object that was receiving focus event notification.

Parameters:
listener - The object that is to no longer receive focus events.

addListener

public void addListener(KeyListener listener)
Register an object to receive key event notification.

Parameters:
listener - The object that has implemented the KeyListener interface that is to receive the key events.

removeListener

public void removeListener(KeyListener listener)
Unregister an object that was receiving key event notification.

Parameters:
listener - The object that is to no longer receive key events.

addListener

public void addListener(MouseListener listener)
Register an object to receive mouse event notification.

Parameters:
listener - The object that has implemented the MouseListener interface that is to receive the mouse events.

removeListener

public void removeListener(MouseListener listener)
Unregister an object that was receiving mouse event notification.

Parameters:
listener - The object that is to no longer receive mouse events.

getType

public static Type getType()
Retrieve the runtime type used by the GLib library.


makeWidget

public static Widget makeWidget(int handle)
                         throws java.lang.ClassNotFoundException
Create a Java-GNOME Widget subclass from an existing native GTK+ handle.

Parameters:
handle - The handle that represents a pointer to a native resource.
Throws:
java.lang.ClassNotFoundException - if a Java-GNOME class cannot be found for the specified handle.

setDragSource

public void setDragSource(ModifierType buttons,
                          TargetEntry[] targets,
                          DragAction actions)
Sets up the widget so that it can be the source of drag and drop operations.

Parameters:
buttons - Buttons which can start the drag
targets - An array of names of drag and drop operations accepted (these are made up by the application designers. Widgets must set as drag sources and destinations with one of these the same)

setNoDragSource

public void setNoDragSource()
Removes support for this widget being a drag and drop source.


setDragDestination

public void setDragDestination(DestDefaults flags,
                               TargetEntry[] targets,
                               DragAction actions)
Sets up the widget so that is can receive drops as part of drag drop events and specifies what sort of drops it will accept

Parameters:
flags -

setNoDragDestination

public void setNoDragDestination()
Removes support for this widget being a drag and drop target


addListener

public void addListener(DragDestinationListener listener)
Register an object to receive drag drop (destination) events.

Parameters:
listener - The object that has implemented the DragDestinationListener interface

removeListener

public void removeListener(DragDestinationListener listener)
Unregister an object that was receiving dragDestination event notification.

Parameters:
listener - The object that is to no longer receive dragDestination events

addListener

public void addListener(DragSourceListener listener)
Register an object to receive drag source events.

Parameters:
listener - The object that has implemented the DragSourceListener interface

removeListener

public void removeListener(DragSourceListener listener)
Unregister an object that was receiving drag source event notification.

Parameters:
listener - The object that is to no longer receive drag source events

Please send any bug reports, comments, or suggestions for the API or documentation to java-gnome-developer@lists.sf.net