📄 theme.java
字号:
package org.j4me.ui;
import javax.microedition.lcdui.*;
import org.j4me.util.*;
/**
* Derive this class to set the application's theme. A theme controls
* the color scheme and background graphics used to skin the application.
* <p>
* Themes do not alter the shapes or functionality of components. To
* change the behavior of appearance of any component it is up to you to
* derive a new component type and implement the changes.
*/
public class Theme
{
// Colors.
// There are many online lists of colors. One is available at
// http://www.december.com/html/spec/colordec.html
/** Black */ public static final int BLACK = 0x00000000;
/** Brown */ public static final int BROWN = 0x00804000;
/** Blue */ public static final int BLUE = 0x000000FF;
/** Navy blue */ public static final int NAVY = 0x00000080;
/** Neon blue */ public static final int NEON_BLUE = 0x004DFFFF;
/** Light blue */ public static final int LIGHT_BLUE = 0x000080FF;
/** Red */ public static final int RED = 0x00FF0000;
/** Maroon */ public static final int MAROON = 0x00802020;
/** Light red */ public static final int LIGHT_RED = 0x00FF5050;
/** Magenta */ public static final int MAGENTA = 0x00FF28FF;
/** Orange */ public static final int ORANGE = 0x00FF8000;
/** Burnt orange */ public static final int BURNT_ORANGE = 0x00D07000;
/** Yellow */ public static final int YELLOW = 0x00FFFF00;
/** Green */ public static final int GREEN = 0x0066FF33;
/** Medium green */ public static final int MEDIUM_GREEN = 0x0000A700;
/** Light green */ public static final int LIGHT_GREEN = 0x0030C020;
/** Dark green */ public static final int DARK_GREEN = 0x001F432D;
/** Forest green*/ public static final int FOREST_GREEN = 0x0033773A;
/** Blue-green */ public static final int BLUE_GREEN = 0x00008080;
/** Cyan */ public static final int CYAN = 0x0033FFFF;
/** Silver */ public static final int SILVER = 0x00C0C0C0;
/** Gray */ public static final int GRAY = 0x00808080;
/** Light gray */ public static final int LIGHT_GRAY = 0x00C0C0C0;
/** Lavendar */ public static final int LAVENDAR = 0x00E6E6FA;
/** White */ public static final int WHITE = 0x00FFFFFF;
/**
* The percentage of the way down the title bar that the secondary color
* used in the gradient fill is at its max.
*/
private static final double TITLE_BAR_SECONDARY_COLOR_MAX = 0.60; // 60%
/**
* The percentage of the way down the menu bar that the secondary color
* used in the gradient fill is at its max.
*/
private static final double MENU_BAR_SECONDARY_COLOR_MAX = 0.10; // 10%
/**
* The percentage of the way across the scrollbar that the secondary color
* used in the gradient fill is at its max.
*/
private static final double SCROLLBAR_SECONDARY_COLOR_MAX = 0.80; // 80%
/**
* The width of the scrollbar in pixels.
*/
private static final int SCROLLBAR_WIDTH = 6;
/**
* The font used for writing text in the normal canvas area. It
* is the default font used by components.
*/
private final Font defaultFont;
/**
* The font used to write menu bar options.
*/
private final Font menuFont;
/**
* The font used in the title area.
*/
private final Font titleFont;
/**
* Creates a <code>Theme</code> object. After creating the theme it must
* be attached to the UI manager to use it through the <code>setTheme</code>
* method.
*/
public Theme ()
{
// Get the application's fonts.
Font base = Font.getDefaultFont();
int face = base.getFace();
int size = base.getSize();
defaultFont = Font.getFont( face, Font.STYLE_PLAIN, size );
menuFont = Font.getFont( face, Font.STYLE_PLAIN, size );
titleFont = Font.getFont( face, Font.STYLE_BOLD, size );
}
/**
* Gets the basic default font. This font is used for writing menu
* options, labels, and regular text throughout the UI.
*
* @return The font used for normal text within the UI.
* @see #getFontColor()
*/
public Font getFont ()
{
return defaultFont;
}
/**
* Returns the font used in the menu bar at the bottom of the canvas.
* <p>
* By default this font is the system font.
* Override this font to change the style of the title text.
*
* @return The font used for writing menu text.
*
* @see #getMenuFontColor()
* @see #paintMenuBar(Graphics, String, boolean, String, boolean, int, int)
*/
public Font getMenuFont ()
{
return menuFont;
}
/**
* Returns the font used for writing the title in the screen's title
* area.
* <p>
* By default this font is the system font in bold.
* Override this font to change the style of the title text.
*
* @return The font used for writing the title in the title area at
* the top of the screen.
* @see #getTitleFontColor()
* @see #paintTrackbar(Graphics, int, int, int, int)
*/
public Font getTitleFont ()
{
return titleFont;
}
/**
* The color of the text written with the font returned by <code>getFont</code>.
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel is ignored.
* <p>
* Override this method to change the text color.
*
* @return The color of text written with the font from <code>getFont</code>.
* @see #getFontColor()
*/
public int getFontColor ()
{
return NAVY;
}
/**
* The color of the text written with the font returned by <code>getMenuFont</code>.
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel is ignored.
* <p>
* Override this method to change the text color.
*
* @return The color of text written with the font from <code>getMenuFont</code>.
* @see #getMenuFont()
* @see #paintMenuBar(Graphics, String, boolean, String, boolean, int, int)
*/
public int getMenuFontColor ()
{
return WHITE;
}
/**
* The color of the menu text when the menu button is pressed. Normally it
* will be the color returned by <code>getMenuFontColor</code>.
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel is ignored.
* <p>
* Override this method to change the text color.
*
* @return The color of the menu text when its menu button is pressed.
* @see #getMenuFont()
* @see #getMenuFontColor()
* @see #paintMenuBar(Graphics, String, boolean, String, boolean, int, int)
*/
public int getMenuFontHighlightColor ()
{
return SILVER;
}
/**
* The color of the text written with the font returned by <code>getTitleFont</code>.
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel is ignored.
* <p>
* Override this method to change the text color.
*
* @return The color of text written with the font from <code>getTitleFont</code>.
* @see #getTitleFont()
* @see #paintTrackbar(Graphics, int, int, int, int)
*/
public int getTitleFontColor ()
{
return getMenuFontColor();
}
/**
* Returns the color used for borders in the canvas section of the
* UI. An example of a border is the outline around a text box.
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel
* is ignored.
* <p>
* Override this method to change it.
*
* @return The color of the borders in the UI.
*/
public int getBorderColor ()
{
return NAVY;
}
/**
* Returns the color used as the background for the canvas section
* of the screen. This is the area that is not the title bar
* at the top or menu bar at the bottom. Colors are defined as
* 0xAARRGGBB; the first-byte alpha-channel is ignored.
* <p>
* Override this method to change it.
*
* @return The color of the title border.
*/
public int getBackgroundColor ()
{
return WHITE;
}
/**
* Returns the main color used in painting components. For example
* a progress bar will use this color to show the completed progress.
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel
* is ignored.
* <p>
* Override this method to change it.
*
* @return The primary color used to paint components.
*/
public int getHighlightColor ()
{
return LIGHT_BLUE;
}
/**
* Returns the color of the border around the title bar.
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel is ignored.
* <p>
* By default this is the same color as the menu border. Override
* this method to change it.
*
* @return The color of the title border.
* @see #paintTrackbar(Graphics, int, int, int, int)
*/
public int getTitleBarBorderColor ()
{
return getMenuBarBorderColor();
}
/**
* Returns the primary color of the background of the title bar. A second
* color defined by <code>getTitleBarHighlightColor</code> is overlaid with
* a vertical gradient.
* <p>
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel is ignored.
* <p>
* By default this is the same color as the menu bar background. Override
* this method to change it.
*
* @return The primary color of the title bar background.
*
* @see #getTitleBarHighlightColor()
*/
public int getTitleBarBackgroundColor ()
{
return getMenuBarBackgroundColor();
}
/**
* Returns the highlight color applied as a vertical gradient to the title
* bar.
* <p>
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel is ignored.
* <p>
* By default this is the same color as the menu bar highlight. Override
* this method to change it.
*
* @return The highlight color of the title bar background.
*
* @see #getTitleBarBackgroundColor()
*/
public int getTitleBarHighlightColor ()
{
return getMenuBarHighlightColor();
}
/**
* Returns the color of the border around the menu bar.
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel is ignored.
* <p>
* Override this method to change it.
*
* @return The color of the border around the menu bar.
* @see #paintMenuBar(Graphics, String, boolean, String, boolean, int, int)
*/
public int getMenuBarBorderColor ()
{
return getFontColor();
}
/**
* Returns the primary color of the background of the menu bar. A second
* color defined by <code>getMenuBarHighlightColor</code> is overlaid with
* a vertical gradient.
* <p>
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel is ignored.
* <p>
* Override this method to change it.
*
* @return The color of the border around the menu bar.
*
* @see #getMenuBarHighlightColor()
*/
public int getMenuBarBackgroundColor ()
{
return NAVY;
}
/**
* Returns the highlight color applied as a vertical gradient to the menu
* bar.
* <p>
* Colors are defined as 0xAARRGGBB; the first-byte alpha-channel is ignored.
* <p>
* Override this method to change it.
*
* @return The highlight color of the menu bar background.
*
* @see #getMenuBarBackgroundColor()
*/
public int getMenuBarHighlightColor ()
{
return LIGHT_BLUE;
}
/**
* Gets the height of the title bar in pixels. This method is called
* whenever the title is set and the title bar is going to be painted.
*
* @return The height of the title bar in pixels.
* @see #paintTrackbar(Graphics, int, int, int, int)
*/
public int getTitleHeight ()
{
return getTitleFont().getHeight() + 2;
}
/**
* Paints the title bar of the canvas. This method is called only
* when the title has been set through <code>setTitle</code> and the canvas
* is not in full screen mode.
* <p>
* The supplied <code>Graphics</code> will be set with an appropriate clip
* and translated such that (0,0) is the top-left corner of the title
* bar.
* <p>
* Override this method to change the appearance of the title bar.
* For example background or logo images can be placed throughout the
* application by painting them here.
*
* @param g is the <code>Graphics</code> object to paint with.
* @param title is the text for the title bar as defined by the
* canvas class.
* @param width is the width of the title bar in pixels.
* @param height is the height of the title bar in pixels.
*/
public void paintTitleBar (Graphics g, String title, int width, int height)
{
// Fill the background of the title bar.
paintTitleBarBackground( g, 0, 0, width, height );
// Draw a line below the title bar to separate it from the canvas.
g.setColor( getTitleBarBorderColor() );
g.drawLine( 0, height - 1, width, height - 1 );
// Write the title text.
g.setFont( getTitleFont() );
g.setColor( getTitleFontColor() );
g.drawString( title, width / 2, 1, Graphics.HCENTER | Graphics.TOP );
}
/**
* Paints the background area of the title bar. The text will be
* added later by the calling <code>paintTitleBar</code> method.
*
* @param g is the <code>Graphics</code> object to paint with.
* @param x is the top-left X-coordinate pixel of the title bar.
* @param y is the top-left Y-coordinate pixel of the title bar.
* @param width is the width of the title bar in pixels.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -