⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stylesheet.java

📁 j2me polish学习的经典代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			//# if (currentScreen != null) {
				//# currentScreen.repaint();
			//# }
		//# }
	//# }
	//#endif
	
	/**
	 * Gets the style with the specified name.
	 * 
	 * @param name the name of the style
	 * @return the specified style or null when no style with the given 
	 * 	       name has been defined.
	 */
	public static Style getStyle( String name ) {
		return (Style) stylesByName.get( name );
	}
	
	//#ifdef polish.useDynamicStyles
	/**
	 * Retrieves the style for the given item.
	 * This function is only available when the <buildSetting>-attribute
	 * [useDynamicStyles] is enabled.
	 * This function allows to set styles without actually using the preprocessing-
	 * directive //#style. Beware that this dynamic style retrieval is not as performant
	 * as the direct-style-setting with the //#style preprocessing directive.
	 *  
	 * @param item the item for which the style should be retrieved
	 * @return the appropriate style. When no specific style is found,
	 *         the default style is returned.
	 */
	public static Style getStyle( Item item ) {
		if (item.screen == null) {
			//#debug error
			//# System.out.println("unable to retrieve style for item [" + item.getClass().getName() + "] without screen.");
			return defaultStyle;
		}
		String itemCssSelector = item.cssSelector;
		String screenCssSelector = item.screen.cssSelector;
		Style style = null;
		String fullStyleName;
		StringBuffer buffer = new StringBuffer();
		buffer.append( screenCssSelector );
		if (item.parent == null) {
			//#debug
			//# System.out.println("item.parent == null");
			buffer.append('>').append( itemCssSelector );
			fullStyleName = buffer.toString();
			style = (Style) stylesByName.get( fullStyleName );
			if (style != null) {
				return style;
			}
			style = (Style) stylesByName.get( screenCssSelector + " " + itemCssSelector );
		} else if (item.parent.parent == null) {
			//#debug
			//# System.out.println("Item has one parent.");
			// this item is propably in a form or list,
			// typical hierarchy is for example "form>container>p"                                                 
			Item parent = item.parent;
			String parentCssSelector = parent.cssSelector;
			if (parentCssSelector == null) {
				parentCssSelector = parent.createCssSelector();
			}
			//#debug
			//# System.out.println( parent.getClass().getName() + "-css-selector: " + parentCssSelector );
			buffer.append('>').append( parentCssSelector )
				  .append('>').append( itemCssSelector );
			fullStyleName = buffer.toString();
			//#debug
			//# System.out.println("trying " + fullStyleName);
			style = (Style) stylesByName.get( fullStyleName );
			if (style != null) {
				return style;
			}
			// 1. try: "screen item":
			String styleName = screenCssSelector + " " + itemCssSelector;
			//#debug
			//# System.out.println("trying " + styleName);
			style = (Style) stylesByName.get( styleName );
			if (style == null) {
				// 2. try: "screen*item":
				styleName = screenCssSelector + "*" + itemCssSelector;
				//#debug
				//# System.out.println("trying " + styleName);
				style = (Style) stylesByName.get( styleName );
				if (style == null) {
					// 3. try: "parent>item"
					styleName = parentCssSelector + ">" + itemCssSelector;
					//#debug
					//# System.out.println("trying " + styleName);
					style = (Style) stylesByName.get( styleName );
					if (style == null) {
						// 4. try: "parent item"
						styleName = parentCssSelector + " " + itemCssSelector;
						//#debug
						//# System.out.println("trying " + styleName);
						style = (Style) stylesByName.get( styleName );
					}
				}
			}
			//#debug
			//# System.out.println("found style: " + (style != null));
		} else {
			//#debug
			//# System.out.println("so far unable to set style: complex item setup");
			// this is a tiny bit more complicated....
			fullStyleName = null;
		}
		if (style == null) {
			// try just the item:
			//#debug
			//# System.out.println("trying " + itemCssSelector);
			style = (Style) stylesByName.get( itemCssSelector );
			if (style == null) {
				//#debug
				//# System.out.println("Using default style for item " + item.getClass().getName() );
				style = defaultStyle;
			}
			//#ifdef polish.debug.debug
				//# else {
					//#debug
					//# System.out.println("Found style " + itemCssSelector );
				//# }
			//#endif
		}
		if ( fullStyleName != null && style != null ) {
			stylesByName.put( fullStyleName, style );
		}
		return style;
	}
	//#endif

	//#ifdef polish.useDynamicStyles
	/**
	 * Retrieves a dynamic style for the given screen.
	 * 
	 * @param screen the screen for which a style should be retrieved
	 * @return the style for the given screen.
	 */
	public static Style getStyle(Screen screen) {
		Style style = (Style) stylesByName.get( screen.cssSelector );
		if (style == null) {
			return defaultStyle;
		}
		return style;
	}		
	//#endif
	
	//#if polish.css.screen-change-animation || polish.ScreenChangeAnimation.forward:defined
	//# /**
	 //# * Includes an animation while changing the screen.
	 //# *  
	 //# * @param display the display
	 //# * @param nextDisplayable the new screen, animations are only included for Screen classes
	 //# */
	//# public static void setCurrent( Display display, Displayable nextDisplayable ) {
		//# if ( nextDisplayable instanceof AccessibleCanvas ) {
			//#if polish.ScreenChangeAnimation.allowConfiguration == true
				//# if (!enableScreenChangeAnimations) {
					//#if polish.Bugs.displaySetCurrentFlickers
						//# Alert.setCurrent( MasterCanvas, display, nextDisplayable );
					//#else
						//# display.setCurrent( nextDisplayable );						
					//#endif
					//# return;	
				//# }
			//#endif
//# 
			//# try {
				//# Screen nextScreen = null;
				//# if ( nextDisplayable instanceof Screen ) {
					//# nextScreen = (Screen) nextDisplayable;
				//# }
				//# ScreenChangeAnimation screenAnimation = null;
				//# Displayable lastDisplayable = null;
				//#if polish.Bugs.displaySetCurrentFlickers
					//# if ( MasterCanvas.instance != null ) {
						//# lastDisplayable = MasterCanvas.instance.currentDisplayable;
					//# }
				//#else
					//# lastDisplayable = display.getCurrent();
				//#endif
//# 	
				//# Screen lastScreen = null;
				//# Style screenstyle = null;
				//#if polish.ScreenChangeAnimation.forward:defined
					//# if (lastDisplayable != null && lastDisplayable instanceof Screen) {
						//# lastScreen = (Screen) lastDisplayable;
						//# Command lastCommand = lastScreen.lastTriggeredCommand;
						//# if (lastCommand != null && lastCommand.getCommandType() == Command.BACK ) {
							//# screenAnimation = backwardAnimation;
							//# screenstyle = lastScreen.style;
						//# }
					//# }
					//# if ( screenAnimation == null ) {
						//# screenAnimation = forwardAnimation;
						//# if (nextScreen != null) {
							//# screenstyle = nextScreen.style;
						//# }
					//# }
				//#else					
					//# if (nextScreen != null && nextScreen.style != null) {
						//# screenstyle = nextScreen.style;
						//# screenAnimation = (ScreenChangeAnimation) screenstyle.getObjectProperty(62);
					//# }
					//# if (lastDisplayable != null && lastDisplayable instanceof ScreenChangeAnimation ) {
						//#debug
						//# System.out.println("StyleSheet: last displayable is a ScreenChangeAnomation" );
						//# lastDisplayable = ((ScreenChangeAnimation) lastDisplayable).nextDisplayable;
					//# }
					//# if (lastDisplayable != null && lastDisplayable instanceof Screen) {
						//#debug
						//# System.out.println("StyleSheet: last displayble is a Screen");
						//# lastScreen = (Screen) lastDisplayable;
						//# if (screenAnimation == null && lastScreen.style != null) {
							//# screenstyle = lastScreen.style;
							//# screenAnimation = (ScreenChangeAnimation) screenstyle.getObjectProperty(62);
							//#debug
							//# System.out.println("StyleSheet: Using screen animation of last screen");
						//# }
					//# }
					//#if polish.Screen.showScreenChangeAnimationOnlyForScreen
						//# if ( nextScreen == null ) {
							//# screenAnimation = null;
						//# }
					//#endif
					//# if ( screenAnimation == null ) {
						//#debug
						//# System.out.println("StyleSheet: found no screen animation");
						//#if polish.Bugs.displaySetCurrentFlickers
							//# Alert.setCurrent( MasterCanvas, display, nextDisplayable );
						//#else
							//# display.setCurrent( nextDisplayable );						
						//#endif
						//# return;
					//# }
				//#endif
//# 				
				//# int width;
				//# int height;
				//#if polish.FullCanvasSize:defined
					//#= width = ${polish.FullCanvasWidth};
					//#= height = ${polish.FullCanvasHeight};
				//#else
					//#if polish.midp2
						//# width = nextDisplayable.getWidth();
						//# height = nextDisplayable.getHeight();
					//#else
						//# if (nextScreen != null) {
							//# width = lastScreen.getWidth();
							//# height = lastScreen.getHeight();
						//# } else if (nextDisplayable instanceof Canvas) {
							//# width = ((Canvas) nextDisplayable).getWidth();
							//# height = ((Canvas) nextDisplayable).getHeight();
						//# } else {
							//# Canvas canvas = new Canvas() {
								//# public void paint( Graphics g) {}
							//# };
							//# width = canvas.getWidth();
							//# height = canvas.getHeight();
						//# }
					//#endif
				//#endif
				//# Image lastScreenImage = Image.createImage(width, height);
				//# Graphics g = lastScreenImage.getGraphics(); 
				//# if ( lastDisplayable != null && lastDisplayable instanceof AccessibleCanvas) {
					//#debug
					//# System.out.println("StyleSheet: last screen is painted");
					//# ( (AccessibleCanvas)lastDisplayable).paint( g );
				//#if polish.ScreenChangeAnimation.blankColor:defined
					//# } else {
						//#= g.setColor( ${polish.ScreenChangeAnimation.blankColor} );
						//# g.fillRect( 0, 0, width, height );
				//#endif
				//# }
				//# Image nextScreenImage = Image.createImage(width, height);
				//# g = nextScreenImage.getGraphics();
				//# AccessibleCanvas nextCanvas = (AccessibleCanvas) nextDisplayable;
				//# nextCanvas.showNotify();
				//# nextCanvas.paint( g );
				//#debug
				//# System.out.println("StyleSheet: showing screen animation " + screenAnimation.getClass().getName() );
				//# if ( screenstyle == null ) {
					//# screenstyle = defaultStyle;
				//# }
				//# screenAnimation.show( screenstyle, display, width, height, lastScreenImage, nextScreenImage, nextCanvas, nextDisplayable );
			//# } catch (Exception e) {
				//#debug error
				//# System.out.println("Screen: unable to start screen change animation" + e );
				//#if polish.Bugs.displaySetCurrentFlickers
					//# Alert.setCurrent( MasterCanvas, display, nextDisplayable );
				//#else
					//# display.setCurrent( nextDisplayable );						
				//#endif
			//# }
//# 			
		//# } else {
			//#if polish.Bugs.displaySetCurrentFlickers
				//# Alert.setCurrent( MasterCanvas, display, nextDisplayable );
			//#else
				//# display.setCurrent( nextDisplayable );						
			//#endif
		//# }
	//# }
	//#endif
	
	/**
	 * Releases all (memory intensive) resources such as images or RGB arrays of this style sheet.
	 */
	public static void releaseResources() {
		//#if polish.allowImageCaching != false
		if (imagesByName != null) {
			imagesByName.clear();
		}
		//#endif
		//#ifdef polish.useDynamicStyles
			Enumeration enumeration = stylesByName.elements();
			while (enumeration.hasMoreElements()) {
				Style style = (Style) enumeration.nextElement();
				style.releaseResources();
			}
		//#endif
		//#ifdef polish.StyleSheet.releaseResources:defined
			//#include ${polish.StyleSheet.releaseResources}
		//#endif
	}

	
	
//#ifdef polish.StyleSheet.additionalMethods:defined
	//#include ${polish.StyleSheet.additionalMethods}
//#endif

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -