📄 stylesheet.java
字号:
/*
* Created on 05-Jan-2004 at 20:41:52.
*
* Copyright (c) 2004-2005 Robert Virkus / Enough Software
*
* This file is part of J2ME Polish.
*
* J2ME Polish is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* J2ME Polish is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with J2ME Polish; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Commercial licenses are also available, please
* refer to the accompanying LICENSE.txt or visit
* http://www.j2mepolish.org for details.
*/
// package de.enough.polish.ui;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Timer;
import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.AlertType; import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Font; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image;
//import ImageTask;
//import Locale;
/**
* <p>Manages all defined styles of a specific project.</p>
* <p>This class is actually pre-processed to get the styles specific for the project and the device.</p>
*
* @author Robert Virkus, robert@enough.de
* <pre>
* history
* 05-Jan-2004 - rob creation
* </pre>
*/
public final class StyleSheet {
protected static Hashtable imagesByName;
//#ifdef polish.images.backgroundLoad
//# private static Hashtable scheduledImagesByName;
//# //private static final Boolean TRUE = new Boolean( true );
//# private static Timer timer;
//#endif
//#ifdef false
//# public static Style defaultStyle = null;
//# public static Style focusedStyle = null;
//# public static Style labelStyle = null;
//# public static Style menuStyle = null;
//# private static Hashtable stylesByName = new Hashtable();
//#endif
//#if polish.ScreenChangeAnimation.forward:defined
//#if false
//# private static ScreenChangeAnimation forwardAnimation;
//# private static ScreenChangeAnimation backwardAnimation;
//#endif
//#= private static ScreenChangeAnimation forwardAnimation = ${polish.ScreenChangeAnimation.forward};
//#if polish.ScreenChangeAnimation.back:defined
//#= private static ScreenChangeAnimation backwardAnimation = ${polish.ScreenChangeAnimation.back};
//#elif polish.ScreenChangeAnimation.backward:defined
//#= private static ScreenChangeAnimation backwardAnimation = ${polish.ScreenChangeAnimation.backward};
//#else
//#abort You need to define the polish.ScreenChangeAnimation.backward screen change animation as well, when you define the forward animation!
//#endif
//#endif
// do not change the following line!
//$$IncludeStyleSheetDefinitionHere$$//
public final static int defaultFontColor = 0x000000;
public final static Font defaultFont = Font.getFont( Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM );
public final static Background defaultBackground = null;
public final static Border defaultBorder = null;
public final static Style defaultStyle = new Style (
0,0,0,0, // default margin
1,1,1,1,1,1, // default padding
Item.LAYOUT_DEFAULT, // default layout
defaultFontColor,
null,
defaultFont,
defaultBackground,
defaultBorder
, null, null // no additional attributes have been defined
);
//static and referenced styles:
public final static Style mainscreenStyle = new Style (
0,0,0,0, // default margin
15,15,5,5,5,5, // padding
Item.LAYOUT_DEFAULT, // default layout
defaultFontColor, // font-color is not defined
null, // font-color is not defined
defaultFont,
new SimpleBackground( new Color( 0xeef1e5, false)),
null // no border
, null, null // no additional attributes have been defined
);
public final static Style titleStyle = new Style (
0,0,0,5, // margin
2,2,2,2,2,2, // padding
Item.LAYOUT_CENTER | Item.LAYOUT_EXPAND,
0xFF0000, // font-color
new Color(0xFF0000, false), // font-color
Font.getFont( Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL ), //font
new SimpleBackground( new Color( 0x848f60, false)),
null // border:none was specified
, null, null // no additional attributes have been defined
);
public final static Style alertcontentStyle = new Style (
0,0,0,0, // default margin
1,1,1,1,1,1, // default padding
Item.LAYOUT_DEFAULT, // default layout
0x1e5556, // font-color
new Color(0x1e5556, false), // font-color
Font.getFont( Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL ), //font
null, // no background
null // no border
, null, null // no additional attributes have been defined
);
public final static Style alertStyle = new Style (
0,0,0,0, // default margin
15,15,5,5,5,5, // padding
Item.LAYOUT_DEFAULT, // default layout
defaultFontColor, // font-color is not defined
null, // font-color is not defined
defaultFont,
new SimpleBackground( new Color( 0xeef1e5, false)),
null // no border
, null, null // no additional attributes have been defined
);
public final static Style menuitemStyle = new Style (
0,0,2,0, // margin
5,2,2,2,2,2, // padding
Item.LAYOUT_RIGHT,
0x1e5556, // font-color
new Color(0x1e5556, false), // font-color
Font.getFont( Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM ), //font
null, // no background
null // no border
, null, null // no additional attributes have been defined
);
public final static Style mystyleStyle = new Style (
0,0,0,0, // default margin
1,1,1,1,1,1, // default padding
Item.LAYOUT_EXPAND | Item.LAYOUT_CENTER,
defaultFontColor, // font-color is not defined
null, // font-color is not defined
defaultFont,
null, // no background
null // no border
, null, null // no additional attributes have been defined
);
public final static Style focusedStyle = new Style (
0,0,0,0, // default margin
5,5,5,5,5,5, // padding
Item.LAYOUT_EXPAND | Item.LAYOUT_CENTER,
0x1e5556, // font-color
new Color(0x1e5556, false), // font-color
Font.getFont( Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL ), //font
new BorderedRoundRectBackground( 0xeef1e5,8, 8, 0x1e5556, 2),
null // no border
, null, null // no additional attributes have been defined
);
public final static Style menufocusedStyle = new Style (
0,0,2,0, // margin
5,2,2,2,2,2, // padding
Item.LAYOUT_LEFT | Item.LAYOUT_EXPAND,
0xeef1e5, // font-color
new Color(0xeef1e5, false), // font-color
Font.getFont( Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM ), //font
new SimpleBackground( new Color( 0x848f60, false)),
null // no border
, null, null // no additional attributes have been defined
);
public final static Style menuStyle = new Style (
2,0,0,0, // margin
2,2,2,2,2,2, // padding
Item.LAYOUT_DEFAULT, // default layout
0xeef1e5, // font-color
new Color(0xeef1e5, false), // font-color
Font.getFont( Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM ), //font
new BorderedRoundRectBackground( 0xFF0000,10, 10, 0x848f60, 2),
null // no border
, new short[]{ 1, 16}
, new Object[]{ menufocusedStyle, new Color( 0x000000, false)}
);
public final static String lic="GPL";
public static Style labelStyle = defaultStyle; // no specific label-style has been defined
//dynamic styles:
static final Hashtable stylesByName = new Hashtable(10);
static { //register referenced and dynamic styles:
stylesByName.put( "0", menufocusedStyle );
stylesByName.put( "mystyle", mystyleStyle );
stylesByName.put( "mainscreen", mainscreenStyle );
defaultStyle.name = "default"; // the selector of the above style
mainscreenStyle.name = "mainscreen"; // the selector of the above style
titleStyle.name = "title"; // the selector of the above style
alertcontentStyle.name = "alertcontent"; // the selector of the above style
alertStyle.name = "alert"; // the selector of the above style
menuitemStyle.name = "menuitem"; // the selector of the above style
mystyleStyle.name = "mystyle"; // the selector of the above style
focusedStyle.name = "focused"; // the selector of the above style
menufocusedStyle.name = "menufocused"; // the selector of the above style
menuStyle.name = "menu"; // the selector of the above style
}
public static Screen currentScreen;
public static Display display;
public static AnimationThread animationThread;
//#ifdef polish.i18n.useDynamicTranslations
//# public static Command OK_CMD = new Command( "OK", Command.OK, 2 );
//#elifdef polish.command.ok:defined
public static final Command OK_CMD = new Command("OK", Command.OK, 2 );
//#else
//# public static final Command OK_CMD = new Command("OK", Command.OK, 2 );
//#endif
//#ifdef polish.i18n.useDynamicTranslations
//# public static Command CANCEL_CMD = new Command("Cancel", Command.CANCEL, 2 );
//#elifdef polish.command.cancel:defined
public static final Command CANCEL_CMD = new Command("Cancel", Command.CANCEL, 3 );
//#else
//# public static final Command CANCEL_CMD = new Command("Cancel", Command.CANCEL, 3 );
//#endif
//#if polish.ScreenChangeAnimation.allowConfiguration == true
//# public static boolean enableScreenChangeAnimations = true;
//#endif
/**
* Retrieves the image with the given name.
* When the image has been cached before, it will be returned immediately.
* When it has not been cached before, it either will be loaded directly
* or in a background thread. This behaviour is set in the
* <a href="../../../../definitions/polish_xml.html">polish.xml</a> file.
*
* @param url the URL of the Image, e.g. "/background.png"
* @param parent the object which needs the image, when the image should be loaded
* in the background, the parent need to implement
* the ImageConsumer interface when it wants to be notified when
* the picture has been loaded.
* @param cache true when the image should be cached for later retrieval.
* This costs RAM obviously, so you should decide carefully if
* large images should be cached.
* @return the image when it either was cached or is loaded directly.
* When the should be loaded in the background, it will be later
* set via the ImageConsumer.setImage()-method.
* @throws IOException when the image could not be loaded directly
* @see ImageConsumer#setImage(String, Image)
*/
public static Image getImage( String url, Object parent, boolean cache )
throws IOException
{
// check if the image has been cached before:
//#if polish.allowImageCaching != false
if ( imagesByName != null ) {
Image image = (Image) imagesByName.get( url );
if (image != null) {
return image;
}
}
//#endif
//#ifdef polish.images.directLoad
// when images should be loaded directly, try to do so now:
//#ifdef polish.classes.ImageLoader:defined
//#= Image image = ${ classname( polish.classes.ImageLoader ) }.loadImage( url );
//#else
Image image = Image.createImage( url );
//#endif
//#if polish.allowImageCaching != false
if (cache) {
if (imagesByName == null ) {
imagesByName = new Hashtable();
}
imagesByName.put( url, image );
}
//#endif
return image;
//#else
//# // when images should be loaded in the background,
//# // tell the background-thread to do so now:
//# if ( ! (parent instanceof ImageConsumer)) {
//#debug error
//# System.out.println("StyleSheet.getImage(..) needs an ImageConsumer when images are loaded in the background!");
//# return null;
//# }
//# if (scheduledImagesByName == null ) {
//# scheduledImagesByName = new Hashtable();
//# }
//# ImageQueue queue = (ImageQueue) scheduledImagesByName.get(url);
//# if (queue != null) {
//# // this image is already scheduled to load:
//# queue.addConsumer((ImageConsumer) parent);
//# return null;
//# }
//# scheduledImagesByName.put( url, new ImageQueue( (ImageConsumer) parent, cache ) );
//# if (imagesByName == null ) {
//# imagesByName = new Hashtable();
//# }
//# if (timer == null) {
//# timer = new Timer();
//# }
//# ImageTask task = new ImageTask( url );
//# timer.schedule( task, 10 );
//# return null;
//#endif
}
//#ifdef polish.images.backgroundLoad
//# /**
//# * Notifies the GUI items which requested images about the successful loading of thoses images.
//# *
//# * @param name the URL of the image
//# * @param image the image
//# */
//# public static void notifyImageConsumers( String name, Image image ) {
//# ImageQueue queue = (ImageQueue) scheduledImagesByName.remove(name);
//# if (queue != null) {
//# if (queue.cache) {
//# imagesByName.put( name, image );
//# }
//# queue.notifyConsumers(name, image);
//# if (true) {
//# return;
//# }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -