Class ComponentHelper
java.lang.Object
net.simplace.ui.service.ComponentHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcenterWindow(Window aWindow) Centers the given window relative to its parent.static ColorcombineColors(Color aColor1, Color aColor2) Mixes two colors by averaging their RGB components.static ImageIconcombineIcons(ImageIcon aIcon, int aIconX, int aIconY, ImageIcon aCoIcon, int aCoIconX, int aCoIconY) Combines a main icon with an overlay icon (e.g.static ImageIconcombineIcons(ImageIcon aIcon, int aIconX, int aIconY, ImageIcon aCoIcon, int aCoIconX, int aCoIconY, boolean aFadeIcon) Combines a main icon with an overlay icon (e.g.static ColorcreateColor(String aColorString) Creates an RGB color from a string like127,0,0or127|0|0.static ImageIconfadeIconColors(ImageIcon aImageIcon) Converts an icon to grey scale, e.g.static JTextAreafindFirstJTextArea(JComponent aComponent) Searches the component tree depth-first for the first descendant of type JTextArea.static voidfitColumnWidth(JTable aTable, int aMaxWidth, boolean aResizable) Sets the width of all columns of a table to fit their header and cell contents.static intfitColumnWidth(JTable aTable, int aColumnIndex, int aMaxWidth, boolean aResizable) Sets the width of a column to fit its header and cell contents.static intfitColumnWidth(JTable aTable, int aColumnIndex, int aMinWidth, int aMaxWidth, boolean aResizable) Sets the width of a column to fit its header and cell contents.static TableColumnReturns the table column for a model column index, regardless of the column's current position in the view.static ComponentgetComponentByBounds(Container aParent, int aX, int aY) Returns the deepest descendant component that contains the given point.static booleanisAnchestor(Component aComponent, Component aAnchestorComponent) Checks whether the second component is an ancestor of the first component, i.e.static booleanisToolkitTrueColor(Component aComponent) Checks if the color depth of the component's toolkit is at least 24 bit.static voidsetDefaultWindowBounds(Window aWindow) Sets the default size and location of a window: 1024x748 pixels centered if the usable screen area is larger, otherwise the whole usable screen area.static voidsetHeight(JComponent aComponent, int aHeight) Sets the minimum and preferred height of a component, keeping its widths.static ColortransformColor(Color aColor, double aRelativeChangeValue) Returns a brighter or darker color by multiplying each RGB component with a factor.static ColortransformColor(Color aColor, int aAbsoluteChangeValue) Returns a brighter or darker color by adding a value to each RGB component.
-
Method Details
-
isAnchestor
Checks whether the second component is an ancestor of the first component, i.e. whether it is found when walking up the parent chain of the first component. A component counts as its own ancestor.- Parameters:
aComponent- the component whose parent chain is searchedaAnchestorComponent- the possible ancestor- Returns:
trueif aAnchestorComponent is aComponent or one of its ancestors
-
findFirstJTextArea
Searches the component tree depth-first for the first descendant of type JTextArea.- Parameters:
aComponent- root of the search; not checked itself- Returns:
- the first descendant of type JTextArea, or
nullif there is none
-
getColumn
Returns the table column for a model column index, regardless of the column's current position in the view.- Parameters:
aTable- the tableaModelIndex- column index in the table model- Returns:
- the table column, or
nullif no column shows this model index
-
fitColumnWidth
Sets the width of all columns of a table to fit their header and cell contents.- Parameters:
aTable- the tableaMaxWidth- maximum width of a column in pixelsaResizable- iffalse, the columns are fixed to the calculated width
-
fitColumnWidth
public static int fitColumnWidth(JTable aTable, int aColumnIndex, int aMaxWidth, boolean aResizable) Sets the width of a column to fit its header and cell contents.- Parameters:
aTable- the tableaColumnIndex- column index in the table modelaMaxWidth- maximum width of the column in pixelsaResizable- iffalse, the column is fixed to the calculated width- Returns:
- the calculated column width in pixels
-
fitColumnWidth
public static int fitColumnWidth(JTable aTable, int aColumnIndex, int aMinWidth, int aMaxWidth, boolean aResizable) Sets the width of a column to fit its header and cell contents.- Parameters:
aTable- the tableaColumnIndex- column index in the table modelaMinWidth- minimum width of the column in pixelsaMaxWidth- maximum width of the column in pixelsaResizable- iffalse, the column is fixed to the calculated width- Returns:
- the calculated column width in pixels
-
transformColor
Returns a brighter or darker color by adding a value to each RGB component. The results are limited to 0..255.- Parameters:
aColor- the original coloraAbsoluteChangeValue- value added to each component; positive values brighten, negative values darken- Returns:
- the transformed color
-
transformColor
Returns a brighter or darker color by multiplying each RGB component with a factor. The results are limited to 0..255.- Parameters:
aColor- the original coloraRelativeChangeValue- factor: < 1.0 darker, 1.0 unchanged, > 1.0 brighter- Returns:
- the transformed color
-
isToolkitTrueColor
Checks if the color depth of the component's toolkit is at least 24 bit.- Parameters:
aComponent- component whose toolkit is checked- Returns:
trueif the color depth is at least 24 bit
-
setDefaultWindowBounds
Sets the default size and location of a window: 1024x748 pixels centered if the usable screen area is larger, otherwise the whole usable screen area.- Parameters:
aWindow- the window to size and position
-
getComponentByBounds
Returns the deepest descendant component that contains the given point.- Parameters:
aParent- container to search inaX- x coordinate relative to aParentaY- y coordinate relative to aParent- Returns:
- the deepest component containing the point, or
nullif no child contains it
-
centerWindow
Centers the given window relative to its parent. If no parent is available, the window is centered on the screen.- Parameters:
aWindow- the window to center
-
combineIcons
public static ImageIcon combineIcons(ImageIcon aIcon, int aIconX, int aIconY, ImageIcon aCoIcon, int aCoIconX, int aCoIconY) Combines a main icon with an overlay icon (e.g. a status symbol).- Parameters:
aIcon- the main iconaIconX- x offset of the main iconaIconY- y offset of the main iconaCoIcon- the overlay icon, drawn aligned to the bottom edgeaCoIconX- x offset of the overlay iconaCoIconY- extra height added to the image for the overlay icon- Returns:
- the combined icon
- See Also:
-
combineIcons
public static ImageIcon combineIcons(ImageIcon aIcon, int aIconX, int aIconY, ImageIcon aCoIcon, int aCoIconX, int aCoIconY, boolean aFadeIcon) Combines a main icon with an overlay icon (e.g. a status symbol). If the overlay icon is at least as large as the main icon, the main icon is moved 3 pixels to the right.- Parameters:
aIcon- the main iconaIconX- x offset of the main iconaIconY- y offset of the main iconaCoIcon- the overlay icon, drawn aligned to the bottom edgeaCoIconX- x offset of the overlay iconaCoIconY- extra height added to the image for the overlay iconaFadeIcon- iftrue, the main icon is converted to grey scale first- Returns:
- the combined icon
-
combineColors
-
createColor
-
setHeight
Sets the minimum and preferred height of a component, keeping its widths.- Parameters:
aComponent- the componentaHeight- height in pixels
-
fadeIconColors
-