Class FlatButton

  • All Implemented Interfaces:
    org.eclipse.swt.graphics.Drawable

    class FlatButton
    extends org.eclipse.swt.widgets.Canvas
    Instances of this class represent a flat button.
    Styles:
    UP, DOWN, LEFT, RIGHT, CENTER
    Events:
    Selection

    Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int alignment  
      private org.eclipse.swt.graphics.Color backgroundColor  
      private static int DEFAULT_PADDING  
      private org.eclipse.swt.graphics.Image image  
      private java.util.List<org.eclipse.swt.events.SelectionListener> listeners  
      private boolean mouseIn  
      private org.eclipse.swt.graphics.Color mouseOverColor  
      private org.eclipse.swt.graphics.Color selectedColor  
      private org.eclipse.swt.graphics.Color selectedTextColor  
      private boolean selection  
      private java.lang.String text  
      • Fields inherited from class org.eclipse.swt.widgets.Composite

        embeddedHandle
      • Fields inherited from class org.eclipse.swt.widgets.Widget

        handle
    • Constructor Summary

      Constructors 
      Constructor Description
      FlatButton​(org.eclipse.swt.widgets.Composite parent, int style)
      Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addListener​(int eventType, org.eclipse.swt.widgets.Listener listener)  
      private void addListeners()  
      void addSelectionListener​(org.eclipse.swt.events.SelectionListener listener)
      Adds the listener to the collection of listeners who will be notified when the control is selected by the user, by sending it one of the messages defined in the SelectionListener interface.
      private void buildAlignmentFromStyle​(int style)  
      org.eclipse.swt.graphics.Point computeSize​(int wHint, int hHint, boolean changed)  
      private void drawBackground​(org.eclipse.swt.graphics.GC gc)  
      private void drawImage​(org.eclipse.swt.graphics.GC gc)  
      private void drawText​(org.eclipse.swt.graphics.GC gc)  
      int getAlignment()
      Returns a value which describes the position of the text in the receiver.
      org.eclipse.swt.graphics.Color getBackgroundColor()
      Returns a value which describes the default background color
      org.eclipse.swt.graphics.Image getImage()
      Returns the receiver's image if it has one, or null if it does not.
      org.eclipse.swt.graphics.Color getMouseOverColor()
      Returns a value which describes the color when the mouse is over the button
      org.eclipse.swt.graphics.Color getSelectedColor()
      Returns a value which describes the color when the button is selected
      org.eclipse.swt.graphics.Color getSelectedTextColor()
      Returns a value which describes the color of the text when the button is selected
      boolean getSelection()
      Returns true if the receiver is selected, and false otherwise.
      java.lang.String getText()
      Returns the receiver's text.
      private void initializeDefaultColors()  
      private void paintControl​(org.eclipse.swt.events.PaintEvent e)  
      void removeSelectionListener​(org.eclipse.swt.events.SelectionListener listener)
      Removes the listener from the collection of listeners who will be notified when the control is selected by the user.
      void setAlignment​(int alignment)
      Controls how text, images and arrows will be displayed in the receiver.
      void setBackgroundColor​(org.eclipse.swt.graphics.Color backgroundColor)
      Sets the receiver's background color to the color specified by the argument.
      void setImage​(org.eclipse.swt.graphics.Image image)
      Sets the receiver's image to the argument, which may be null indicating that no image should be displayed.
      void setMouseOverColor​(org.eclipse.swt.graphics.Color mouseOverColor)
      Sets the receiver's color when the mouse if over the button.
      void setSelectedColor​(org.eclipse.swt.graphics.Color selectedColor)
      Sets the receiver's color when the button is selected.
      void setSelectedTextColor​(org.eclipse.swt.graphics.Color selectedTextColor)
      Sets the receiver's text color when the button is selected.
      void setSelection​(boolean selected)
      Sets the selection state of the receiver.
      void setText​(java.lang.String text)
      Sets the receiver's text.
      • Methods inherited from class org.eclipse.swt.widgets.Canvas

        drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIME
      • Methods inherited from class org.eclipse.swt.widgets.Composite

        changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
      • Methods inherited from class org.eclipse.swt.widgets.Scrollable

        computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
      • Methods inherited from class org.eclipse.swt.widgets.Control

        addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isAutoScalable, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
      • Methods inherited from class org.eclipse.swt.widgets.Widget

        addDisposeListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • image

        private org.eclipse.swt.graphics.Image image
      • text

        private java.lang.String text
      • selection

        private boolean selection
      • alignment

        private int alignment
      • listeners

        private final java.util.List<org.eclipse.swt.events.SelectionListener> listeners
      • mouseIn

        private boolean mouseIn
      • backgroundColor

        private org.eclipse.swt.graphics.Color backgroundColor
      • selectedColor

        private org.eclipse.swt.graphics.Color selectedColor
      • selectedTextColor

        private org.eclipse.swt.graphics.Color selectedTextColor
      • mouseOverColor

        private org.eclipse.swt.graphics.Color mouseOverColor
    • Constructor Detail

      • FlatButton

        public FlatButton​(org.eclipse.swt.widgets.Composite parent,
                          int style)
        Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

        The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

        Parameters:
        parent - a composite control which will be the parent of the new instance (cannot be null)
        style - the style of control to construct
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the parent is null
        org.eclipse.swt.SWTException -
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
        • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
        See Also:
        SWT.DOWN, SWT.LEFT, SWT.RIGHT, SWT.CENTER
    • Method Detail

      • buildAlignmentFromStyle

        private void buildAlignmentFromStyle​(int style)
      • addListeners

        private void addListeners()
      • initializeDefaultColors

        private void initializeDefaultColors()
      • paintControl

        private void paintControl​(org.eclipse.swt.events.PaintEvent e)
      • drawBackground

        private void drawBackground​(org.eclipse.swt.graphics.GC gc)
      • drawImage

        private void drawImage​(org.eclipse.swt.graphics.GC gc)
      • drawText

        private void drawText​(org.eclipse.swt.graphics.GC gc)
      • addSelectionListener

        public void addSelectionListener​(org.eclipse.swt.events.SelectionListener listener)
        Adds the listener to the collection of listeners who will be notified when the control is selected by the user, by sending it one of the messages defined in the SelectionListener interface.

        widgetSelected is called when the control is selected by the user. widgetDefaultSelected is not called.

        Parameters:
        listener - the listener which should be notified
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the listener is null
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
        See Also:
        SelectionListener, removeSelectionListener(org.eclipse.swt.events.SelectionListener), SelectionEvent
      • computeSize

        public org.eclipse.swt.graphics.Point computeSize​(int wHint,
                                                          int hHint,
                                                          boolean changed)
        Overrides:
        computeSize in class org.eclipse.swt.widgets.Control
        See Also:
        Control.computeSize(int, int, boolean)
      • getAlignment

        public int getAlignment()
        Returns a value which describes the position of the text in the receiver. The value will be one of LEFT, RIGHT or CENTER.
        Returns:
        the alignment
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • getBackgroundColor

        public org.eclipse.swt.graphics.Color getBackgroundColor()
        Returns a value which describes the default background color
        Returns:
        the default background color
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • getImage

        public org.eclipse.swt.graphics.Image getImage()
        Returns the receiver's image if it has one, or null if it does not.
        Returns:
        the receiver's image
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • getMouseOverColor

        public org.eclipse.swt.graphics.Color getMouseOverColor()
        Returns a value which describes the color when the mouse is over the button
        Returns:
        the color when the mouse is over the button
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • getSelectedColor

        public org.eclipse.swt.graphics.Color getSelectedColor()
        Returns a value which describes the color when the button is selected
        Returns:
        the color when the button is selected
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • getSelectedTextColor

        public org.eclipse.swt.graphics.Color getSelectedTextColor()
        Returns a value which describes the color of the text when the button is selected
        Returns:
        the color of the text when the button is selected
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • getSelection

        public boolean getSelection()
        Returns true if the receiver is selected, and false otherwise.

        Returns:
        the selection state
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • getText

        public java.lang.String getText()
        Returns the receiver's text.
        Returns:
        the receiver's text
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • removeSelectionListener

        public void removeSelectionListener​(org.eclipse.swt.events.SelectionListener listener)
        Removes the listener from the collection of listeners who will be notified when the control is selected by the user.
        Parameters:
        listener - the listener which should no longer be notified
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the listener is null
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
        See Also:
        SelectionListener, addSelectionListener(org.eclipse.swt.events.SelectionListener)
      • setAlignment

        public void setAlignment​(int alignment)
        Controls how text, images and arrows will be displayed in the receiver. The argument should be one of LEFT, RIGHT or CENTER.
        Parameters:
        alignment - the new alignment
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • setBackgroundColor

        public void setBackgroundColor​(org.eclipse.swt.graphics.Color backgroundColor)
        Sets the receiver's background color to the color specified by the argument.
        Parameters:
        color - the new color
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_INVALID_ARGUMENT - if the argument has been disposed
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • setImage

        public void setImage​(org.eclipse.swt.graphics.Image image)
        Sets the receiver's image to the argument, which may be null indicating that no image should be displayed.

        Note that a Button can display an image and text simultaneously on Windows (starting with XP), GTK+ and OSX. On other platforms, a Button that has an image and text set into it will display the image or text that was set most recently.

        Parameters:
        image - the image to display on the receiver (may be null)
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_INVALID_ARGUMENT - if the image has been disposed
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • setMouseOverColor

        public void setMouseOverColor​(org.eclipse.swt.graphics.Color mouseOverColor)
        Sets the receiver's color when the mouse if over the button.
        Parameters:
        color - the new color
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_INVALID_ARGUMENT - if the argument has been disposed
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • setSelectedColor

        public void setSelectedColor​(org.eclipse.swt.graphics.Color selectedColor)
        Sets the receiver's color when the button is selected.
        Parameters:
        color - the new color
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_INVALID_ARGUMENT - if the argument has been disposed
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • setSelectedTextColor

        public void setSelectedTextColor​(org.eclipse.swt.graphics.Color selectedTextColor)
        Sets the receiver's text color when the button is selected.
        Parameters:
        color - the new color
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_INVALID_ARGUMENT - if the argument has been disposed
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • setSelection

        public void setSelection​(boolean selected)
        Sets the selection state of the receiver.
        Parameters:
        selected - the new selection state
        Throws:
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • setText

        public void setText​(java.lang.String text)
        Sets the receiver's text.
        Parameters:
        string - the new text
        Throws:
        java.lang.IllegalArgumentException -
        • ERROR_NULL_ARGUMENT - if the text is null
        org.eclipse.swt.SWTException -
        • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
        • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • addListener

        public void addListener​(int eventType,
                                org.eclipse.swt.widgets.Listener listener)
        Overrides:
        addListener in class org.eclipse.swt.widgets.Widget
        See Also:
        Widget.addListener(int, org.eclipse.swt.widgets.Listener)