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

📄 theme.java

📁 关于J4ME J2ME实例
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * @param height is the height of the title bar in pixels.
	 * 
	 * @see #paintTrackbar(Graphics, int, int, int, int)
	 */
	protected void paintTitleBarBackground (Graphics g, int x, int y, int width, int height)
	{
		// This code would paint the title bar a solid background.
		//	int background = getTitleBackgroundColor();
		//	g.setColor( background );
		//	g.fillRect( x, y, width, height );
		
		// Paint a gradient background.
		int primary = getTitleBarBackgroundColor();
		int secondary = getTitleBarHighlightColor();
		
		gradientFill( g, 0, 0, width, height, true, primary, secondary, TITLE_BAR_SECONDARY_COLOR_MAX );
	}

	/**
	 * Gets the height of the menu bar in pixels.  This method is called
	 * whenever the menu is going to be painted.
	 * 
	 * @return The height of the menu bar in pixels.
	 * 
	 * @see #paintMenuBar(Graphics, String, boolean, String, boolean, int, int)
	 */
	public int getMenuHeight ()
	{
		return getMenuFont().getHeight() + 2;
	}

	/**
	 * Paints the menu bar at the bottom of the canvas.  This method is
	 * not called if the canvas is 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 or functionality of
	 * the menu.  Be careful not to write strings that are too long and
	 * will not fit on the menu bar.
	 * 
	 * @param g is the <code>Graphics</code> object to paint with.
	 * @param left is the text to write on the left side of the menu bar.
	 *  The left side is associated with dimissing input such as a
	 *  "Cancel" button.
	 * @param highlightLeft is <code>true</code> if the menu text <code>left</code>
	 *  should be highlighted to indicate the left menu button is currently
	 *  pressed.
	 * @param right is the text to write on the right side of the menu bar.
	 *  The right side is associated with accepting input such as an
	 *  "OK" button.
	 * @param highlightRight is <code>true</code> if the menu text <code>right</code>
	 *  should be highlighted to indicate the right menu button is currently
	 *  pressed.
	 * @param width is the width of the menu bar in pixels.
	 * @param height is the height of the menu bar in pixels.
	 */
	public void paintMenuBar (Graphics g,
			String left, boolean highlightLeft,
			String right, boolean highlightRight, 
			int width, int height)
	{
		// Fill the menu bar background.
		paintMenuBarBackground( g, 0, 0, width, height );
		
		// Draw a line above the menu bar to separate it from the canvas.
		g.setColor( getMenuBarBorderColor() );
		g.drawLine( 0, 0, width, 0 );

		// Write the menu items.
		int normal = getMenuFontColor();
		int highlighted = getMenuFontHighlightColor();
		
		Font font = getMenuFont();
		g.setFont( font );
		
		int offset = font.charWidth( ' ' ) / 2;
		
		g.setColor( highlightLeft ? highlighted : normal );
		g.drawString( left,  offset,         height, Graphics.BOTTOM | Graphics.LEFT );
		
		g.setColor( highlightRight ? highlighted : normal );
		g.drawString( right, width - offset, height, Graphics.BOTTOM | Graphics.RIGHT );
	}
	
	/**
	 * Paints the background area of the menu bar.  The text will be
	 * added later by the calling <code>paintMenuBar</code> method.
	 *
	 * @param g is the <code>Graphics</code> object to paint with.
	 * @param x is the top-left X-coordinate pixel of the menu bar.
	 * @param y is the top-left Y-coordinate pixel of the menu bar.
	 * @param width is the width of the menu bar in pixels.
	 * @param height is the height of the menu bar in pixels.
	 * 
	 * @see #paintMenuBar(Graphics, String, boolean, String, boolean, int, int)
	 */
	protected void paintMenuBarBackground (Graphics g, int x, int y, int width, int height)
	{
		// This code would paint the menu bar a solid background.
		//	int background = getMenuBackgroundColor();
		//	g.setColor( background );
		//	g.fillRect( x, y, width, height );
		
		// Paint a gradient background.
		int primary = getMenuBarBackgroundColor();
		int secondary = getMenuBarHighlightColor();
		
		gradientFill( g, x, y, width, height, true, primary, secondary, MENU_BAR_SECONDARY_COLOR_MAX );
	}
	
	/**
	 * Gets the localized menu text for OK buttons that appear on
	 * forms.  By default this is "OK".
	 * 
	 * @return The text used for the OK button on forms.
	 */
	public String getMenuTextForOK ()
	{
		return "OK";
	}
	
	/**
	 * Gets the localized menu text for Cancel buttons that appear on
	 * forms.  By default this is "Cancel".
	 * 
	 * @return The text used for the Cancel button on forms.
	 */
	public String getMenuTextForCancel ()
	{
		return "Cancel";
	}
	
	/**
	 * Paints the background of the main section of the screen.  This includes
	 * everything except for the title bar at the top and menu bar at the bottom.
	 * However, if this canvas is in full screen mode, then this method paints the entire
	 * screen.
	 * <p>
	 * After this method is called, the screen's <code>paintCanvas</code> method will be.
	 * <p>
	 * By default this method paints the entire background the color specified
	 * by <code>getBackgroundColor</code>.  Override this implementation to provide
	 * a different background for the entire application, such as an image.
	 * 
	 * @param g is the <code>Graphics</code> object to paint with.
	 */
	public void paintBackground (Graphics g)
	{
		int color = getBackgroundColor();
		
		int x = g.getClipX();
		int y = g.getClipY();
		int w = g.getClipWidth();
		int h = g.getClipHeight();
		
		// Clear the canvas.
		g.setColor( color );
		g.fillRect( x, y, w, h );
	}
	
	/**
	 * Paints the vertical scrollbar.  The scrollbar must go on the right
	 * side of the form and span from the top to the bottom.  Its width
	 * is returned from this method and used to calculate the width of
	 * the remaining form area to draw components in.
	 *
	 * @param g is the <code>Graphics</code> object to paint with.
	 * @param x is the top-left X-coordinate pixel of the form area.
	 * @param y is the top-left Y-coordinate pixel of the form area.
	 * @param width is the width of the form area in pixels.
	 * @param height is the height of the form area in pixels.
	 * @param offset is the vertical scrolling position of the top pixel
	 *  to show on the form area.
	 * @param formHeight is the total height of all the components on the
	 *  form.  This is bigger than <code>height</code>.
	 */
	public void paintVerticalScrollbar (Graphics g, int x, int y, int width, int height, int offset, int formHeight)
	{
		// Make the scrollbar as wide as the rounding diameter.
		int scrollbarWidth = getVerticalScrollbarWidth();
		int left = x + width - scrollbarWidth;

		// Draw the scrollbar background.
		paintScrollbarBackground( g, left, y, scrollbarWidth, height );

		// Draw an edge to the scrollbar.
		int border = getBorderColor();
		g.setColor( border );
		g.drawLine( left, y, left, y + height );

		// Calculate the height of the trackbar.
		int scrollableHeight = formHeight - height;
		double trackbarPercentage = (double)height / (double)formHeight;
		int trackbarHeight = (int)MathFunc.round( height * trackbarPercentage );
		trackbarHeight = Math.max( trackbarHeight, 2 * scrollbarWidth );

		// Calculate the range and location of the trackbar.
		//   The scrollbar doesn't actually go from 0% to 100%.  The top
		//   is actually 1/2 the height of the trackbar from the top of
		//   the screen.  The bottom is 1/2 the height from the bottom.
		int rangeStart = trackbarHeight / 2;
		int range = height - 2 * rangeStart;
		
		double offsetPercentage = (double)offset / (double)scrollableHeight;
		int center = y + rangeStart + (int)MathFunc.round( offsetPercentage * range );
		
		// Draw the trackbar.
		paintTrackbar( g, left, center - rangeStart, scrollbarWidth, trackbarHeight );
	}
	
	/**
	 * Paints the background area of the scrollbar.  This does not include
	 * the trackbar (which will be painted later by <code>paintScrollbarTrackbar</code>).
	 *
	 * @param g is the <code>Graphics</code> object to paint with.
	 * @param x is the top-left X-coordinate pixel of the scrollbar.
	 * @param y is the top-left Y-coordinate pixel of the scrollbar.
	 * @param width is the width of the scrollbar in pixels.
	 * @param height is the height of the scrollbar in pixels.
	 * 
	 * @see #paintVerticalScrollbar(Graphics, int, int, int, int, int, int)
	 * @see #paintTrackbar(Graphics, int, int, int, int)
	 */
	protected void paintScrollbarBackground (Graphics g, int x, int y, int width, int height)
	{
		// This code would paint the scrollbar a solid background.
		//	int background = getScrollbarBackgroundColor();
		//	g.setColor( background );
		//	g.fillRect( x, y, width, height );
		
		// Paint a gradient background.
		int primary = getScrollbarBackgroundColor();
		int secondary = getScrollbarHighlightColor();
		
		gradientFill( g, x, y, width, height, false, primary, secondary, SCROLLBAR_SECONDARY_COLOR_MAX );
	}
	
	/**
	 * Paints the trackbar on the scrollbar.  The trackbar is the sliding bit
	 * found on the scrollbar that shows the user where the current screen
	 * is relative to the scrolling.
	 *
	 * @param g is the <code>Graphics</code> object to paint with.
	 * @param x is the top-left X-coordinate pixel of the trackbar.
	 * @param y is the top-left Y-coordinate pixel of the trackbar.
	 * @param width is the width of the trackbar in pixels.
	 * @param height is the height of the trackbar in pixels.
	 * 
	 * @see #paintVerticalScrollbar(Graphics, int, int, int, int, int, int)
	 * @see #paintScrollbarBackground(Graphics, int, int, int, int)
	 */
	protected void paintTrackbar (Graphics g, int x, int y, int width, int height)
	{
		// This code would paint the scrollbar a solid background.
		//	int trackbar = getScrollbarTrackbarColor();
		//	g.setColor( trackbar );
		//	g.fillRect( x, y, width, height );
		
		// Paint a gradient background.
		int primary = getScrollbarTrackbarColor();
		int secondary = getScrollbarBorderColor();
		
		gradientFill( g, x, y, width, height, false, primary, secondary, 0.80 );
	}

	/**
	 * Returns the width of the vertical scrollbar.
	 * 
	 * @return The number of pixels wide the scrollbar is.
	 */
	public int getVerticalScrollbarWidth ()
	{
		return SCROLLBAR_WIDTH;
	}

	/**
	 * Returns the color of the border around the scrollbar.
	 * Colors are defined as 0xAARRGGBB; the first-byte alpha-channel is ignored.
	 * <p>
	 * By default this is the same as the  border color.
	 * Override this method to change it.
	 * 
	 * @return The color of the border around the scrollbar.
	 * @see #paintVerticalScrollbar(Graphics, int, int, int, int, int, int)
	 */
	public int getScrollbarBorderColor ()
	{
		return getBorderColor();
	}
	
	/**
	 * Returns the color of the background of the scrollbar.  This
	 * is the area without the trackbar on it.
	 * <p>
	 * By default this is the same as the scrollbar's border color.
	 * Override this method to change it.
	 * 
	 * @return The color of the scrollbar background.
	 * @see #paintVerticalScrollbar(Graphics, int, int, int, int, int, int)
	 */
	public int getScrollbarBackgroundColor ()
	{
		return getMenuBarBackgroundColor();
	}
	
	/**
	 * Returns the highlight color applied as a horizontal gradient to the
	 * scrollbar.
	 * <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 scrollbar background.
	 * 
	 * @see #getScrollbarBackgroundColor()
	 */
	public int getScrollbarHighlightColor ()
	{
		return getMenuFontHighlightColor();
	}
	
	/**
	 * Returns the color of the trackbar within the scrollbar.  The
	 * trackbar is the block that moves up and down the scrollbar
	 * to visually inform the user of where in the scrolling they are.
	 * <p>
	 * By default this is the same as the menu bar's background color.
	 * Override this method to change it.
	 * 
	 * @return The color of the scrollbar's trackbar.
	 * @see #paintVerticalScrollbar(Graphics, int, int, int, int, int, int)
	 */
	public int getScrollbarTrackbarColor ()
	{
		return getMenuBarHighlightColor();
	}
	
	/**
	 * Fills a rectangle with linear gradient.  The gradient colors go
	 * from <code>primaryColor</code> to <code>secondaryColor</code> at
	 * <code>maxSecondary</code>.  So if <code>maxSecondary == 0.70</code> then a line
	 * across the fill rectangle 70% of the way would be
	 * <code>secondaryColor</code>.
	 * 
	 * @param g is the <code>Graphics</code> object for painting.
	 * @param x is the left edge of the rectangle.
	 * @param y is the top edge of the rectangle.
	 * @param width is the width of the rectangle.
	 * @param height is the height of the rectangle.
	 * @param fillVertically is <code>true</code> if the gradient goes from
	 *  top-to-bottom or <code>false</code> for left-to-right.
	 * @param primaryColor is the main color.
	 * @param secondaryColor is the highlight color.
	 * @param maxSecondary is between 0.00 and 1.00 and says how far down
	 *  the fill will <code>secondaryColor</code> peak.
	 */
	public static void gradientFill (
			Graphics g,
			int x, int y, int width, int height,
			boolean fillVertically,
			int primaryColor, int secondaryColor, double maxSecondary)
	{
		// Break the primary color into red, green, and blue.
		int pr = (primaryColor & 0x00FF0000) >> 16;
		int pg = (primaryColor & 0x0000FF00) >> 8;
		int pb = (primaryColor & 0x000000FF);
		
		// Break the secondary color into red, green, and blue.
		int sr = (secondaryColor & 0x00FF0000) >> 16;
		int sg = (secondaryColor & 0x0000FF00) >> 8;
		int sb = (secondaryColor & 0x000000FF);
		
		// Draw a horizonal line for each pixel from the top to the bottom.
		int end = (fillVertically ? height : width);
		
		for ( int i = 0; i < end; i++ )
		{
			// Calculate the color for this line.
			double p = (double)i / (double)end;
			double v = Math.abs( maxSecondary - p );
			double v2 = 1.0 - v;
			
			int red   = (int)( pr * v + sr * v2 );
			int green = (int)( pg * v + sg * v2 );
			int blue  = (int)( pb * v + sb * v2 );
			
			g.setColor( red, green, blue );
			
			// Draw the line.
			if ( fillVertically )
			{
				g.drawLine( x, y + i, x + width, y + i );
			}
			else  // horizontal
			{
				g.drawLine( x + i, y, x + i, y + height );
			}
		}
	}
}

⌨️ 快捷键说明

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