Class AbstractButtonBorder<C extends javax.swing.JComponent,P extends javax.swing.JComponent>
- java.lang.Object
-
- io.github.jonestimd.swing.component.AbstractButtonBorder<C,P>
-
- Type Parameters:
C
- the class of the contained componentP
- 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 implementpaintBorder(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.
-
Constructor Summary
Constructors Constructor Description AbstractButtonBorder(C component, P popupPanel, AbstractButtonBorder.Side side)
Construct a new border with the "button" on the specified side.
-
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.
-
-
-
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 borderpopupPanel
- the panel to use for the content of the popup windowside
- 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 interfacejavax.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 interfacejavax.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 paintedg
- the paint graphicsx
- the x position of the painted bordery
- the y position of the painted borderwidth
- the width of the painted borderheight
- the height of the painted borderinset
- the width of the "button"
-
isBorderOpaque
public boolean isBorderOpaque()
- Specified by:
isBorderOpaque
in interfacejavax.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 screenpopupSize
- the size of the popup windowborderComponent
- 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.
-
-