Class AbstractButtonBorder<C extends javax.swing.JComponent,​P extends javax.swing.JComponent>

  • Type Parameters:
    C - the class of the contained component
    P - the class of the panel used for the content of the popup window
    All Implemented Interfaces:
    javax.swing.border.Border
    Direct Known Subclasses:
    CalendarButtonBorder

    public abstract class AbstractButtonBorder<C extends javax.swing.JComponent,​P extends javax.swing.JComponent>
    extends java.lang.Object
    implements javax.swing.border.Border
    Abstract class for a border that displays a popup window on mouse click events. The target area for the mouse clicks can be placed on the left or right side of the contained component and subclasses should implement paintBorder(Component, Graphics, int, int, int, int, int) to draw the "button" in the target area. The default "button" area is a square having the same height as the contained component.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  AbstractButtonBorder.Side
      Available sides for displaying the button.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.Insets getBorderInsets​(java.awt.Component c)
      Calculate the insets for a component.
      protected abstract java.awt.Point getPopupLocation​(java.awt.Dimension screenSize, java.awt.Dimension popupSize, C borderComponent)
      Calculate the location to display the popup.
      protected void hidePopup()
      Hide the popup window if it is showing.
      protected abstract void initializePopup​(C borderComponent, P popupComponent)
      Initialize the content of the popup window.
      boolean isBorderOpaque()  
      protected boolean isOverButton​(java.awt.Point point)  
      void paintBorder​(java.awt.Component c, java.awt.Graphics g, int x, int y, int width, int height)  
      protected abstract void paintBorder​(java.awt.Component c, java.awt.Graphics g, int x, int y, int width, int height, int inset)
      Paint the border, including the "button".
      protected javax.swing.JComponent preparePopupPanel()
      Prepare the popup panel for adding to the popup window.
      void setTooltip​(java.lang.String tooltip)
      Set the tooltip to display when the mouse hovers over the "button".
      protected void showPopup()
      Show the popup window.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractButtonBorder

        public AbstractButtonBorder​(C component,
                                    P popupPanel,
                                    AbstractButtonBorder.Side side)
        Construct a new border with the "button" on the specified side.
        Parameters:
        component - the component using the border
        popupPanel - the panel to use for the content of the popup window
        side - the side on which to place the "button" (mouse click target area)
    • Method Detail

      • setTooltip

        public void setTooltip​(java.lang.String tooltip)
        Set the tooltip to display when the mouse hovers over the "button".
      • preparePopupPanel

        protected javax.swing.JComponent preparePopupPanel()
        Prepare the popup panel for adding to the popup window.
        Returns:
        the component to add to the popup window, e.g. a JScrollPane containing the popup panel.
      • getBorderInsets

        public java.awt.Insets getBorderInsets​(java.awt.Component c)
        Calculate the insets for a component. The "button" area will be a square based on the height of the component.
        Specified by:
        getBorderInsets in interface javax.swing.border.Border
        Parameters:
        c - the component
        Returns:
        the calculated border insets for c
      • paintBorder

        public void paintBorder​(java.awt.Component c,
                                java.awt.Graphics g,
                                int x,
                                int y,
                                int width,
                                int height)
        Specified by:
        paintBorder in interface javax.swing.border.Border
      • paintBorder

        protected abstract void paintBorder​(java.awt.Component c,
                                            java.awt.Graphics g,
                                            int x,
                                            int y,
                                            int width,
                                            int height,
                                            int inset)
        Paint the border, including the "button".
        Parameters:
        c - the component for which this border is being painted
        g - the paint graphics
        x - the x position of the painted border
        y - the y position of the painted border
        width - the width of the painted border
        height - the height of the painted border
        inset - the width of the "button"
      • isBorderOpaque

        public boolean isBorderOpaque()
        Specified by:
        isBorderOpaque in interface javax.swing.border.Border
      • getPopupLocation

        protected abstract java.awt.Point getPopupLocation​(java.awt.Dimension screenSize,
                                                           java.awt.Dimension popupSize,
                                                           C borderComponent)
        Calculate the location to display the popup.
        Parameters:
        screenSize - the size of the screen
        popupSize - the size of the popup window
        borderComponent - the contained component
        Returns:
        the location to use to display the popup
      • isOverButton

        protected boolean isOverButton​(java.awt.Point point)
        Parameters:
        point - the mouse position
        Returns:
        true if point is over the "button"
      • hidePopup

        protected void hidePopup()
        Hide the popup window if it is showing.
      • showPopup

        protected void showPopup()
        Show the popup window.
      • initializePopup

        protected abstract void initializePopup​(C borderComponent,
                                                P popupComponent)
        Initialize the content of the popup window.
        Parameters:
        borderComponent - the contained component
        popupComponent - the popup window content panel