@MinDoc(copyright="Copyright 2000 - 2005, 2009 A. Weinert", author="Albrecht Weinert", version="V.44", lastModified="6.05.2021", purpose="graphical helpers and factories") public interface GrafHelper extends ColorHelper, ColorVal
awt.Button
),awt.MenuBar
,
swing.JMenuBar
) as well asModifier and Type | Interface and Description |
---|---|
static class |
GrafHelper.MBarFactory
The menu bar factory.
|
ColorHelper.Impl
Modifier and Type | Field and Description |
---|---|
static Action.Filter |
colourChooseFilter
A filter for Actions by code.
|
static String |
DEF_DIAG_FONT_DES
Default dialogue font description.
|
static CleverSSS |
rkColIs
The subsequence "color=" for white space
and case ignoring search.
|
colourCmap
Modifier and Type | Method and Description |
---|---|
static CheckboxMenuItem |
byAction(MenuComponent menuComp,
String actionCommand)
Determine the CheckboxMenuItem to an action command.
|
static JCheckBoxMenuItem |
byAction(MenuElement menuComp,
String actionCommand)
Determine the JCheckboxMenuItem to an action command.
|
static JMenuItem |
byAction(MenuElement menuComp,
String actionCommand,
boolean check)
Determine the JMenuItem to an action command.
|
static MenuItem |
byAction(Object menuComp,
String actionCommand,
boolean check)
Determine the MenuItems to an action command.
|
static Color |
calcFgColor(Color bg)
Determine a foreground colour for a given background colour.
|
static boolean |
fillRect(Graphics g,
Color c,
Image i,
int x,
int y,
int w,
int h)
Filling a rectangle.
|
static int |
getButtonNo()
(Serial) number of last made button.
|
static Color |
getColor(CharSequence colourDef)
Determine a colour by a character sequence.
|
static Font |
getFont(CharSequence fontDef)
Fetch a character set (font) by a character sequence.
|
static Font |
getFont(CharSequence name,
int style,
int size)
Fetch a character set (font) by name and attributes.
|
static void |
initMenu(JMenu m,
ActionListener aL,
ItemListener iL)
Setting the listeners of a (J)Menu.
|
static void |
initMenu(Menu m,
ActionListener aL,
ItemListener iL)
Setting the listeners of a Menu.
|
static void |
initMenuBar(MenuContainer mb,
ActionListener aL,
ItemListener iL)
Setting the listeners of a MenuBar.
|
static Button |
makeButton(String text,
Font font,
String command,
Color bgColor,
Color fgColor,
ActionListener al)
Making a button (Button).
|
static JButton |
makeJButton(String text,
Font font,
Color bgColor,
Color fgColor,
Border bo)
Making a button (JButton).
|
static JButton |
makeJButton(String text,
Font font,
String command,
Color bgColor,
Color fgColor,
ActionListener al,
Border bo)
Making a button (JButton).
|
static IntPairFix |
paintString(Graphics g,
ConstIntPair p,
ConstIntPair d,
String text,
Color fgColor,
Font font)
Centred painting of a text in (p, d).
|
static IntPairFix |
paintString(Graphics g,
int x,
int y,
int width,
int height,
String text,
Color fgColor,
Font font)
Centred painting of a text in (x,y), (width,height)).
|
static void |
removeListenersMenu(JMenu m)
Removing all listeners of a (J)Menu.
|
static void |
removeListenersMenu(Menu m)
Removing all listeners of a Menu.
|
static void |
removeListenersMenuBar(MenuContainer mb)
Removing all listeners from a MenuBar.
|
static BufferedImage |
scaleImage(Image img,
Color bgColor,
int newWidth,
int newHeight)
Scaling a picture.
|
static void |
setBgColor(Component c,
Color bg)
Set a component's foreground and background colours.
|
static BufferedImage |
surrondImage(Image img,
Color bgColor,
int upM,
int loM,
int leM,
int riM)
Surround a picture.
|
static boolean |
xmlEncode(MenuContainer mb,
OutputStream out)
XML coding a menu bar (MenuBar).
|
static final CleverSSS rkColIs
static final Action.Filter colourChooseFilter
Action
,
Action.SCOLOR
static final String DEF_DIAG_FONT_DES
static int getButtonNo()
makeButton()
and by
makeJButton()
will be numbered.static Button makeButton(String text, Font font, String command, Color bgColor, Color fgColor, ActionListener al)
awt.Button
) with text, command, colours and
ActionListener
.text
null "Button56" (serial number) will
be used.font
null, the Button class takes the parent container's
font setting.command
null, the text
will be used (which
is usually a mistake in (inter) nationalisable applications).text
- the button's labelling. Should be changed by (inter)
nationalising.font
- for labellingcommand
- the action command initiated by this button. Often chosen
equal or similar to the labelling. Must keep its value even
under (inter) nationalising.bgColor
- background colourfgColor
- text coloural
- the ActionListener (the object obeying to or forwarding
the action command)static JButton makeJButton(String text, Font font, String command, Color bgColor, Color fgColor, ActionListener al, Border bo)
swing.JButton
) with text, command,
colours and
ActionListener
.swing.JButton JButton
's extra
possibility to define margins via Border objects this method is
equivalent to (see there) makeButton()
.bo
is given, it will (of course) be used. Is
bo
null and bgColor not null, a (Line-) Border object in
bgColor
will be fetched and set. This makes the JButton rimless.
In many respects is a "rimless" JButton a better substitute
for a JLabel; see also
makeJButton(String, Font, Color, Color, Border)
.text
is longer than 3 and does not yet start by <html>
(match case insensitive) and does contain <, > or &,
<html> will be put in front. (JButtons, friendly, allow
text formatting by HTML tags.)command
independent from the label gets more
important in the light of those HTML-features, not to say
indispensable.static JButton makeJButton(String text, Font font, Color bgColor, Color fgColor, Border bo)
swing.JButton
) with text, colour and so on
but with no command nor
ActionListener
.makeJButton(String, Font, String, Color, Color, ActionListener, Border)
when generating (pseudo) labels.static boolean fillRect(Graphics g, Color c, Image i, int x, int y, int w, int h)
g.drawImage(i,...)
will be returned.g
- graphical contextc
- (background) colouri
- picturex
- starting point (upper left)y
- starting point (upper left)w
- widthh
- heightstatic IntPairFix paintString(Graphics g, ConstIntPair p, ConstIntPair d, String text, Color fgColor, Font font)
g
is null, nothing happens. static IntPairFix paintString(Graphics g, int x, int y, int width, int height, String text, Color fgColor, Font font)
paintString(Graphics g, ConstIntPair p, ConstIntPair d, String text,
Color fG, Font f)
just getting (x, y) from p and (width, height) from d.static Color calcFgColor(Color bg)
bg
is
either white ColorVal.ws
) or black (ColorVal.sw
), depending
on the (weighted) brightness of bg
.bg
's RGB values a gray value will be calculated,
using ITU standard weights (222, 707, 71; according to recommendation 709,
D65). About 51% will be used as threshold.calcFgColor
in interface ColorHelper
bg
- the background colour (null returns black)static void setBgColor(Component c, Color bg)
c
will be set by bg
.bg
.setBgColor
in interface ColorHelper
calcFgColor(Color)
static Color getColor(CharSequence colourDef)
colourDef
is stripped from surrounding
whitespace and quotes. If null or empty null is returned.colourDef
only the token following the = is
considered.colourDef
or its remaining token is interpreted
decimal, octal or hexadecimal as 24 bit number to define a colour
as RGB (0xrrggbb); see also
Color.decode(String)
. A leading sharp (#)
will be replaced before by 0x (#FFC0C0 -> 0xffcoco) to accept HTML
colour values, too.colourDef
is as an English,
German or French colour name or industry standard abbreviation.GrafVal.COLOR_CHOOSE
.colourDef
is used as key
to a cache
used and filled by this method.
This partly avoids double decoding and generating.getColor
in interface ColorHelper
colourDef
- the colour definitionColorVal.COLOR_CHOOSE
,
Action
static Font getFont(CharSequence name, int style, int size)
cache
or constructed.Font
.Font(name, style, size)
.name
- a font's name
(not empty after stripping surrounding white space)style
- the Font's style value (Font class constants ORed)size
- the Font's the point size (4..200)getFont(CharSequence)
static Font getFont(CharSequence fontDef)
DEF_DIAG_FONT_DES
. The
resulting sequence is used for getting a Font as returned by
Font
.decode()
. cache
or uses Font
.decode()
to get (and cache) it.fontDef
- Font definition (face-style-size)getFont(CharSequence, int, int)
static boolean xmlEncode(MenuContainer mb, OutputStream out)
awt.MenuBar
given as parameter mb
or any other awt.MenuMenuContainer
or swing.JMenuBar
will be XML encoded
including all its contained
Menus
and
MenuItems
respectively
JMenus
and JMenuItems
.MLHelper.xmlEncode(Object, String)
static void initMenuBar(MenuContainer mb, ActionListener aL, ItemListener iL)
mb
all (J)MenuItems will get the
ActionListener aL and all (J)CheckboxMenuItems will get the
ItemListener iL
if they have no such listener yet (using the
method
initMenu()
).mb
- MenuBar, may be a awt.MenuBar
or a swing.JMenuBar
seinstatic void initMenu(Menu m, ActionListener aL, ItemListener iL)
Menu
m all MenuItem
s get
the ActionListener aL
.CheckboxMenuItem
s get the
ItemListener iL (instead of aL).MenuItem
s having no such
listener yet.static void initMenu(JMenu m, ActionListener aL, ItemListener iL)
JMenu
m all JMenuItem
s get
the ActionListener aL
.CheckboxMenuItem
s get the
ItemListener iL (instead of aL).MenuItem
s having no such
listener yet.static void removeListenersMenuBar(MenuContainer mb)
mb
the menu items will be freed from the
listeners (ActionListener or ItemListener) using the (fitting overloaded)
method removeListenersMenu()
.mb
- MenuBar, may be a awt.MenuBar
or a swing.JMenuBar
static void removeListenersMenu(JMenu m)
static void removeListenersMenu(Menu m)
static MenuItem byAction(Object menuComp, String actionCommand, boolean check)
menuComp
- the containing menu componentactionCommand
- the search criterion action commandcheck
- true: consider only CheckboxMenuItemsstatic CheckboxMenuItem byAction(MenuComponent menuComp, String actionCommand)
(CheckBoxMenuItem)byAction(menuComp, actionCommand, true)
Only for better readability.menuComp
- the containing menu componentactionCommand
- the search criterion action commandstatic JMenuItem byAction(MenuElement menuComp, String actionCommand, boolean check)
menuComp
- the containing JMenu componentactionCommand
- the search criterion action commandcheck
- true: consider only JCheckboxMenuItemsstatic JCheckBoxMenuItem byAction(MenuElement menuComp, String actionCommand)
(CheckBoxMenuItem)byAction(menuComp, actionCommand, true)
menuComp
- the containing JMenu componentactionCommand
- the search criterion action commandstatic BufferedImage surrondImage(Image img, Color bgColor, int upM, int loM, int leM, int riM)
img
( 3 * 8 bit colour model) will be enlarged
by the given margins (the result being returned as new image).img
null or of zero or unknown size, null will be
returned.surrondImage
in interface ColorHelper
img
- the picture to be surroundedbgColor
- background respectively margin colour (default ColorVal.ws
).upM
- upper margin in pixel (0..400).loM
- leM - riM - ditto lower, left and right.static BufferedImage scaleImage(Image img, Color bgColor, int newWidth, int newHeight)
img
( 3 * 8 bit colour model) will be stretched
or shrunk to the given size and returned as BufferedImage
.img
null or of zero or unknown size, null or is the one of the
wanted sizes less than 1, null will be returned.img
of type
BufferedImage
, img
itself will be returned (not
copied).scaleImage
in interface ColorHelper
img
- the picture to scalebgColor
- background colour (used to prefill the new buffered
image, if not null)newHeight
- new heightnewWidth
- new width