guicomponents

## Class GComponent

- java.lang.Object
- - guicomponents.GComponent

- All Implemented Interfaces:
    GConstants, Comparable<Object>, PConstants
  Direct Known Subclasses:
    FPanel, FScrollbar, FTextComponent, GActivityBar, GButton, GCheckbox, GCombo, GImageButton, GLabel, GOption, GPanel, GRoundControl, GSlider, GTextField

      public abstract class GComponent
      extends Object
      implements PConstants, GConstants, Comparable<Object>

  CLASS FOR INTERNAL USE ONLY Abstract base class for all GUI components
  Author:
    Peter Lager

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `GComponent.Z_Order` Comparator used for controlling the order components are drawn

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `int` | `eventType`
    `static Font` | `fGlobalFont`
    `static GCScheme` | `globalColor`
    `static int` | `globalColorScheme`
    `static PFont` | `globalFont`
    `GCScheme` | `localColor`
    `PFont` | `localFont`
    `String` | `tag` Simple tag that can be used by the user
    `int` | `tagNo` Allows user to specify a number for this component
    `int` | `z` Used to when components overlap

    - ### Fields inherited from interface processing.core.PConstants

      `ADD, ALPHA, ALPHA_MASK, ALT, AMBIENT, ARC, ARGB, ARROW, BACKSPACE, BASELINE, BEVEL, BEZIER_VERTEX, BLEND, BLUE_MASK, BLUR, BOTTOM, BOX, BREAK, BURN, CENTER, CHATTER, CLAMP, CLOSE, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CURVE_VERTEX, CUSTOM, DARKEST, DEG_TO_RAD, DELETE, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ACCURATE_2D, DISABLE_ACCURATE_TEXTURES, DISABLE_DEPTH_MASK, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_NATIVE_FONTS, DISABLE_OPENGL_ERRORS, DISABLE_STROKE_PERSPECTIVE, DISABLE_TEXTURE_CACHE, DISABLE_TEXTURE_MIPMAPS, DISABLE_TRANSFORM_CACHE, DODGE, DOWN, DXF, ELLIPSE, ENABLE_ACCURATE_2D, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_MASK, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_ERRORS, ENABLE_STROKE_PERSPECTIVE, ENABLE_TEXTURE_CACHE, ENABLE_TEXTURE_MIPMAPS, ENABLE_TRANSFORM_CACHE, ENTER, EPSILON, ERODE, ERROR_BACKGROUND_IMAGE_FORMAT, ERROR_BACKGROUND_IMAGE_SIZE, ERROR_PUSHMATRIX_OVERFLOW, ERROR_PUSHMATRIX_UNDERFLOW, ERROR_TEXTFONT_NULL_PFONT, ESC, EXCLUSION, GIF, GRAY, GREEN_MASK, GROUP, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LANDSCAPE, LEFT, LIGHTEST, LINE, LINE_LOOP, LINE_STRIP, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MODELVIEW, MOVE, MULTIPLY, NORMAL, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, platformNames, POINT, POINTS, POLYGON, PORTRAIT, POSTERIZE, PROBLEM, PROJECT, PROJECTION, QUAD, QUAD_BEZIER_VERTEX, QUAD_STRIP, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RECT, RED_MASK, REPEAT, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SHAPE, SHIFT, SOFT_LIGHT, SPHERE, SPOT, SQUARE, SUBTRACT, TAB, TARGA, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, UP, VERTEX, WAIT, WHITESPACE, WINDOWS, X, Y, Z`

    - ### Fields inherited from interface guicomponents.GConstants

      `ADD_DUPLICATE, BACKGROUND, CHANGED, CLICKED, CLOSE_WINDOW, COLLAPSED, CTRL_ANGULAR, CTRL_HORIZONTAL, CTRL_VERTICAL, DESELECTED, DISABLE_AUTO_DRAW, DRAGGED, ENTERED, EXCP_IN_HANDLER, EXIT_APP, EXPANDED, FAMILY, FOREGROUND, HUD_UNSUPPORTED, INVALID_STATUS, JUSTIFICATION, JUSTIFICATION_FULL, JUSTIFICATION_NONE, KEEP_OPEN, MISSING, NONEXISTANT, NOT_PEASYCAM, POSTURE, POSTURE_OBLIQUE, POSTURE_REGULAR, PRESSED, RELEASED, RUNTIME_ERROR, SCROLL_DOWN, SCROLL_LEFT, SCROLL_RIGHT, SCROLL_UP, SCROLLBAR_HORIZONTAL, SCROLLBAR_VERTICAL, SCROLLBARS_AUTOHIDE, SCROLLBARS_BOTH, SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NONE, SCROLLBARS_VERTICAL_ONLY, SELECTED, SET, SIZE, STRIKETHROUGH, STRIKETHROUGH_OFF, STRIKETHROUGH_ON, SUPERSCRIPT, SUPERSCRIPT_SUB, SUPERSCRIPT_SUPER, USER_COL_SCHEME, WEIGHT, WEIGHT_BOLD, WEIGHT_DEMIBOLD, WEIGHT_DEMILIGHT, WEIGHT_EXTRA_LIGHT, WEIGHT_EXTRABOLD, WEIGHT_HEAVY, WEIGHT_LIGHT, WEIGHT_MEDIUM, WEIGHT_REGULAR, WEIGHT_SEMIBOLD, WEIGHT_ULTRABOLD, WIDTH, WIDTH_CONDENSED, WIDTH_EXTENDED, WIDTH_REGULAR, WIDTH_SEMI_CONDENSED, WIDTH_SEMI_EXTENDED`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GComponent(PApplet theApplet, float p0, float p1, float p2, float p3)`
    `GComponent(PApplet theApplet, int x, int y)` INTERNAL USE ONLY This constructor MUST be called by all constructors of any child class e.g.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `add(GComponent child)` Add a GUI component to this GComponent at the position specified by component being added.
    `void` | `addAbsoluteControl(GComponent c)` The control to be added has absolute screen coordinates.
    `void` | `addCompoundControl(GComponent c, float x, float y, float angle)` This will set the rotation of the control to angle overwriting any previous rotation set.
    `void` | `addEventHandler(Object obj, String methodName)` Attempt to create the default event handler for the component class.
    `void` | `addEventHandler(Object obj, String methodName, Class[] parameters)` Attempt to create the default event handler for the component class.
    `void` | `addRelativeControl(GComponent c)` The control to be added has screen coordinates relative to this control
    `boolean` | `addXXX(GComponent c)`
    `void` | `calcAbsPosition(Point d)` This method will calculate the absolute top left position of this component taking into account any ancestors.
    `void` | `changeWindow(PApplet newWindowApp)` Called when we add a component to another window.
    `int` | `compareTo(Object o)`
    `boolean` | `contains(float px, float py)` NOT REQD Remove this method from the release version performs the same task as calcTransformedOrigin(px,py) but also tests to see if it is over the control.
    `static void` | `ctrlMode(int mode)` Change the way position and size parameters are interpreted when a control is created.
    `void` | `dispose()` Completely dispose of this component.
    `void` | `draw()` Override in child classes
    `int` | `getAlpha()` How transparent / opaque is this component
    `int` | `getBorder()` Get the border width
    `static int` | `getCtrlMode()` Get the control creation mode @see ctrlMode(int mode)
    `int` | `getEventType()` This can be used to detect the type of event
    `static GComponent` | `getFocusObject()` Get a the object (if any) that currently has focus
    `float` | `getHeight()`
    `boolean` | `getOpaque()` Find out if the component is opaque
    `PApplet` | `getPApplet()` Get the PApplet object
    `GComponent` | `getParent()`
    `StyledString` | `getStyledText()` Get the StyledString used for display
    `String` | `getText()`
    `AffineTransform` | `getTransform(AffineTransform aff)` Get an affine transformation that is the compound of all transformations including parents
    `float` | `getWidth()`
    `float` | `getX()`
    `float` | `getY()`
    `boolean` | `hasFocus()` Does this component have focus
    `boolean` | `hasKeyFocus()` Does this component have key focus
    `boolean` | `isEnabled()` Is this component enabled
    `boolean` | `isOver(int ax, int ay)` Determines whether the position ax, ay is over this component.
    `boolean` | `isVisible()`
    `void` | `keyPressed(KeyEvent event)` Override in child classes
    `void` | `mouseEvent(MouseEvent event)` Override in child classes.
    `void` | `pre()` Override in child classes
    `void` | `remove(GComponent component)` Remove a GUI component from this component
    `void` | `setAlpha(int alpha)` Controls the transparency of this component 0 = fully transparent 255 = fully opaque
    `void` | `setBorder(int border)` The user can add a border by specifying it's thickness a value of 0 means no border (this is the default)
    `void` | `setColorScheme(int schemeNo)` Sets the local color scheme
    `void` | `setEnabled(boolean enable)` Enable or disable the ability of the component to generate mouse events. GTextField - it also controls key press events GPanel - controls whether the panel can be moved/collapsed/expanded
    `void` | `setFocus(boolean focus)` Determines whether this component is to have focus or not
    `void` | `setFont(String fontname, int fontsize)` Override in child classes
    `void` | `setFontNew(Font font)` Set the global font to be used by all controls.
    `void` | `setFontNew(PFont pfont)` Set the global font to be used by all controls.
    `void` | `setHeight(int height)`
    `void` | `setLocalColorScheme(int cs)`
    `void` | `setOpaque(boolean opaque)` Determines wheher to show tha back color or not.
    `void` | `setRotation(float rot)`
    `void` | `setText(String text)`
    `void` | `setText(String text, int align)`
    `void` | `setTextAlign(int align)` Set the text alignment inside the box.
    `void` | `setTextNew(String text)` Set the text to be displayed.
    `void` | `setTextNew(String text, int wrapWidth)`
    `void` | `setVisible(boolean visible)`
    `void` | `setWidth(float width)`
    `void` | `setX(int x)` Sets the x position of a component
    `void` | `setXY(int x, int y)` Sets the position of a component
    `void` | `setY(int y)` Sets the x position of a component
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### globalColor

          public static GCScheme globalColor

    - #### localColor

          public GCScheme localColor

    - #### globalColorScheme

          public static int globalColorScheme

    - #### fGlobalFont

          public static Font fGlobalFont

    - #### globalFont

          public static PFont globalFont

    - #### localFont

          public PFont localFont

    - #### z

          public int z

      Used to when components overlap

    - #### tag

          public String tag

      Simple tag that can be used by the user

    - #### tagNo

          public int tagNo

      Allows user to specify a number for this component

    - #### eventType

          public int eventType

  - ### Constructor Detail

    - #### GComponent

          public GComponent(PApplet theApplet,
                    int x,
                    int y)

      INTERNAL USE ONLY This constructor MUST be called by all constructors of any child class e.g. GPanel, GLabel etc. Each component registers itself with G4P, the first component register the mainWinApp for later use. Only create the GScheme the first time it is called.
      Parameters:
        `theApplet` -
        `x` -
        `y` -

    - #### GComponent

          public GComponent(PApplet theApplet,
                    float p0,
                    float p1,
                    float p2,
                    float p3)

  - ### Method Detail

    - #### ctrlMode

          public static void ctrlMode(int mode)

      Change the way position and size parameters are interpreted when a control is created. There are 3 modes.

           PApplet.CORNER  (x, y, w, h)
           PApplet.CORNERS         (x0, y0, x1, y1)
           PApplet.CENTER  (cx, cy, w, h)

      Parameters:
        `mode` - illegal values are ignored leaving the mode unchanged

    - #### getCtrlMode

          public static int getCtrlMode()

      Get the control creation mode @see ctrlMode(int mode)
      Returns:

    - #### setLocalColorScheme

          public void setLocalColorScheme(int cs)

    - #### addAbsoluteControl

          public void addAbsoluteControl(GComponent c)

      The control to be added has absolute screen coordinates.
      Parameters:
        `c` -

    - #### addRelativeControl

          public void addRelativeControl(GComponent c)

      The control to be added has screen coordinates relative to this control
      Parameters:
        `c` -

    - #### addCompoundControl

          public void addCompoundControl(GComponent c,
                                float x,
                                float y,
                                float angle)

      This will set the rotation of the control to angle overwriting any previous rotation set. Then it calculates the centre position so that the original top left corner of the control will be the position indicated by x,y with respect to the top left corner of parent
      Parameters:
        `c` -
        `x` -
        `y` -
        `angle` -

    - #### addXXX

          public boolean addXXX(GComponent c)

    - #### setRotation

          public void setRotation(float rot)

    - #### getTransform

          public AffineTransform getTransform(AffineTransform aff)

      Get an affine transformation that is the compound of all transformations including parents
      Parameters:
        `aff` -
      Returns:

    - #### contains

          public boolean contains(float px,
                         float py)

      NOT REQD Remove this method from the release version performs the same task as calcTransformedOrigin(px,py) but also tests to see if it is over the control.
      Parameters:
        `px` -
        `py` -
      Returns:

    - #### addEventHandler

          public void addEventHandler(Object obj,
                             String methodName)

      Attempt to create the default event handler for the component class. The default event handler is a method that returns void and has a single parameter of the same type as the component class generating the event and a method name specific for that class.
      Parameters:
        `obj` - the object to handle the event
        `methodName` - the method to execute in the object handler class

    - #### addEventHandler

          public void addEventHandler(Object obj,
                             String methodName,
                             Class[] parameters)

      Attempt to create the default event handler for the component class. The default event handler is a method that returns void and has a single parameter of the same type as the component class generating the event and a method name specific for that class.
      Parameters:
        `obj` - the object to handle the event
        `methodName` - the method to execute in the object handler class
        `parameters` - the parameter classes.

    - #### getPApplet

          public PApplet getPApplet()

      Get the PApplet object
      Returns:
        the PApplet this component is drawn on

    - #### setFocus

          public void setFocus(boolean focus)

      Determines whether this component is to have focus or not
      Parameters:
        `focus` -

    - #### hasFocus

          public boolean hasFocus()

      Does this component have focus
      Returns:
        true if this component has focus else false

    - #### hasKeyFocus

          public boolean hasKeyFocus()

      Does this component have key focus
      Returns:
        true if this component has key focus else false

    - #### getFocusObject

          public static GComponent getFocusObject()

      Get a the object (if any) that currently has focus
      Returns:
        a reference to the object with focus (maybe null!)

    - #### getEventType

          public int getEventType()

      This can be used to detect the type of event
      Returns:
        the eventType

    - #### add

          public boolean add(GComponent child)

      Add a GUI component to this GComponent at the position specified by component being added. If transparency has been applied to this GComponent then the same level will be applied to the component to be added. Unregister the component for drawing this is managed by the GComponent draw method to preserve z-ordering
      Returns:
        always true

    - #### remove

          public void remove(GComponent component)

      Remove a GUI component from this component
      Parameters:
        `component` -

    - #### pre

          public void pre()

      Override in child classes

    - #### draw

          public void draw()

      Override in child classes

    - #### mouseEvent

          public void mouseEvent(MouseEvent event)

      Override in child classes. Every object will execute this method when an event is to be processed.

    - #### keyPressed

          public void keyPressed(KeyEvent event)

      Override in child classes
      Parameters:
        `event` -

    - #### dispose

          public void dispose()

      Completely dispose of this component. This operation cannot be undone.

    - #### changeWindow

          public void changeWindow(PApplet newWindowApp)

      Called when we add a component to another window. Transfers autos to new window for this component and all it's children.
      Parameters:
        `newWindowApp` -

    - #### isOver

          public boolean isOver(int ax,
                       int ay)

      Determines whether the position ax, ay is over this component. This is the default implementation and assumes the component is a rectangle where x & y is the top-left corner and the size is defined by width and height. Override this method where necessary in child classes e.g. GPanel
      Parameters:
        `ax` - mouse x position
        `ay` - mouse y position
      Returns:
        true if mouse is over the component else false

    - #### calcAbsPosition

          public void calcAbsPosition(Point d)

      This method will calculate the absolute top left position of this component taking into account any ancestors.
      Parameters:
        `d` -

    - #### getParent

          public GComponent getParent()

      Returns:
        the parent

    - #### setColorScheme

          public void setColorScheme(int schemeNo)

      Sets the local color scheme
      Parameters:
        `schemeNo` -

    - #### getText

          public String getText()

      Returns:
        the text

    - #### getStyledText

          public StyledString getStyledText()

      Get the StyledString used for display
      Returns:

    - #### setTextNew

          public void setTextNew(String text)

      Set the text to be displayed. NEW version for FPanel etc.
      Parameters:
        `text` -

    - #### setTextNew

          public void setTextNew(String text,
                        int wrapWidth)

    - #### setText

          public void setText(String text)

      Parameters:
        `text` - use this function to set the text so that the text length is calculated

    - #### setText

          public void setText(String text,
                     int align)

      Parameters:
        `text` - the text to set with alignment

    - #### setTextAlign

          public void setTextAlign(int align)

      Set the text alignment inside the box.
      Horizontal must be one of the following GAlign.LEFT or GAlign.CENTER or GAlign.RIGHT
      Vertical must be one of the following GAlign.TOP or GAlign.MIDDLE or GAlign.BOTTOM
      Both horizontal and vertical alignment can be set in one call using bitwise OR e.g. GAlign.BOTTOM | GAlign.CENTER
      Parameters:
        `align` - the alignment flag

    - #### setFont

          public void setFont(String fontname,
                     int fontsize)

      Override in child classes
      Parameters:
        `fontname` -
        `fontsize` -

    - #### setFontNew

          public void setFontNew(Font font)

      Set the global font to be used by all controls.
      You can override the font used by individual controls with the equivalent setFont method for the control.
      Parameters:
        `font` - the java.awt.Font to use

    - #### setFontNew

          public void setFontNew(PFont pfont)

      Set the global font to be used by all controls.
      You can override the font used by individual controls with the equivalent setFont method for the control.
      Parameters:
        `pfont` - the Processing font to use

    - #### setXY

          public void setXY(int x,
                   int y)

      Sets the position of a component
      Parameters:
        `x` -
        `y` -

    - #### setX

          public void setX(int x)

      Sets the x position of a component
      Parameters:
        `x` -

    - #### setY

          public void setY(int y)

      Sets the x position of a component
      Parameters:
        `y` -

    - #### getX

          public float getX()

      Returns:
        the x

    - #### getY

          public float getY()

      Returns:
        the y

    - #### getWidth

          public float getWidth()

      Returns:
        the width

    - #### setWidth

          public void setWidth(float width)

      Parameters:
        `width` - the width to set

    - #### getHeight

          public float getHeight()

      Returns:
        the height

    - #### setHeight

          public void setHeight(int height)

      Parameters:
        `height` - the height to set

    - #### isVisible

          public boolean isVisible()

      Returns:
        the component's visibility

    - #### setEnabled

          public void setEnabled(boolean enable)

      Enable or disable the ability of the component to generate mouse events.
      GTextField - it also controls key press events
      GPanel - controls whether the panel can be moved/collapsed/expanded
      Parameters:
        `enable` - true to enable else false

    - #### isEnabled

          public boolean isEnabled()

      Is this component enabled
      Returns:
        true if the component is enabled

    - #### setVisible

          public void setVisible(boolean visible)

      Parameters:
        `visible` - the visibility to set

    - #### setBorder

          public void setBorder(int border)

      The user can add a border by specifying it's thickness a value of 0 means no border (this is the default)
      Parameters:
        `border` - width in pixels

    - #### getBorder

          public int getBorder()

      Get the border width
      Returns:
        the border width

    - #### setOpaque

          public void setOpaque(boolean opaque)

      Determines wheher to show tha back color or not. Only applies to some components
      Parameters:
        `opaque` -

    - #### getOpaque

          public boolean getOpaque()

      Find out if the component is opaque
      Returns:
        true if the background is visible

    - #### setAlpha

          public void setAlpha(int alpha)

      Controls the transparency of this component 0 = fully transparent 255 = fully opaque
      Parameters:
        `alpha` -

    - #### getAlpha

          public int getAlpha()

      How transparent / opaque is this component
      Returns:
        0 (transparent) 255 (opaque)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### compareTo

          public int compareTo(Object o)

      Specified by:
        `compareTo` in interface `Comparable<Object>`

Processing library guicomponents by Peter Lager. (C) 2012