home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-10-04 | 56.4 KB | 1,681 lines |
- package sub_arctic.output;
-
-
- import sub_arctic.input.*;
- import sub_arctic.lib.manager;
-
- import java.awt.Font;
- import java.awt.Color;
- import java.awt.FontMetrics;
- import java.awt.Dimension;
- import java.awt.Rectangle;
- import java.util.Vector;
-
- /**
- * This is an implementation for generating the styles for a
- * motifish look and feel.
- *
- * @author Ian Smith
- */
-
- public class motif_style extends style {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* ********************* IMAGES ****************/
- // (generated from ppm file)
- protected static int check_width = 13;
- protected static int[] check_data = {
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xffffffff,0xffffffff,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xffffffff,0xffffffff,0xffffffff,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xffffffff,0xffffffff,0xffffffff,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xffffffff,0xffffffff,0xffffffff,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xffffffff,0xffffffff,0xffffffff,0xff000000,0xff000000,0xff000000,
- 0xffffffff,0xffffffff,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xffffffff,0xffffffff,0xffffffff,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xffffffff,0xffffffff,0xffffffff,0xff000000,0xff000000,
- 0xffffffff,0xffffffff,0xffffffff,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xffffffff,0xffffffff,0xffffffff,
- 0xffffffff,0xffffffff,0xffffffff,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xffffffff,
- 0xffffffff,0xffffffff,0xffffffff,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xffffffff,0xffffffff,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,0xff000000,
- 0xff000000,};
- protected static int check_height = 13;
- protected static sub_arctic.output.loaded_image _check = null;
-
- public static sub_arctic.output.loaded_image check() {
- if (_check == null)
- calculate_check();
- return _check;
- }
-
- public static void calculate_check() {
- loaded_image tmp;
- tmp = new sub_arctic.output.loaded_image(check_data,
- check_width,check_height);
-
- /* the 150 is to avoid the "black line syndrome" of feathered
- images */
- _check=loaded_image.
- image_from_intensity_map(tmp,
- style_manager.default_color_scheme().splash(),
- 150);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* ********************* BEVELING CODE ****************/
- /*
- * This code generates beveled rectangles ala motif.
- *
- * @param loaded_image img the image to bevel (the contents of this image,
- * if any, are lost).
- * @param boolean raised should this image be draw as raised or lowered.
- * @param boolean base should this image be draw with the base color.
- * as the main color (if true) or the background
- * color (if false).
- * @param boolean one_pix true if you want one pixel of beveling,
- * false if you want two.
- * @param boolean left bevel the left edge.
- * @param boolean right bevel the right edge.
- * @param boolean top bevel the top edge.
- * @param boolean bottom bevel the bottom edge.
- * @param color_scheme colors the color scheme to use for the beveling.
- */
- static public void bevel_rect(loaded_image img,
- boolean raised, boolean base,
- boolean one_pix,
- boolean left, boolean right,
- boolean top, boolean bottom,
- color_scheme colors) {
-
- int w=img.width(), h=img.height();
- drawable d=img.get_drawable();
-
- /* fill with the base or with the background*/
- if (base) {
- d.setColor(colors.base());
- } else {
- d.setColor(colors.background());
- }
- d.fillRect(0,0,w,h);
-
- /* put a one pixel wide strip of highlight/shadow on right ...
- you want to to the bottom and right first to mimic motif */
- if (raised) {
- d.setColor(colors.shadow());
- } else {
- d.setColor(colors.highlight());
- }
-
- /* right hand side */
- if (right) {
- d.fillRect(w-1,0,1,h);
- /* if we are two pixels wide, do another line */
- if (!one_pix) {
- d.fillRect(w-2,0,1,h);
- }
- }
-
- /* put a one pixel wide strip of shadow/highlight on bottom */
- if (bottom) {
- d.fillRect(0,h-1,w,1);
- /* if we are two pixels wide, do another line */
- if (!one_pix) {
- d.fillRect(0,h-2,w,1);
- }
- }
-
- /* put a one pixel wide strip of highlight/shadow along the top */
- if (raised) {
- d.setColor(colors.highlight());
- } else {
- d.setColor(colors.shadow());
- }
-
- /* handle top */
- if (top) {
- d.fillRect(0,0,w,1);
- /* are we two pixels? */
- if (!one_pix) {
- /* this is supposed to be one pixel shorter */
- d.fillRect(0,1,w-1,1);
- }
- }
-
- /* same for left */
- if (left) {
- d.fillRect(0,0,1,h);
- /* is it two pixels?*/
- if (!one_pix) {
- /* again, this is one pixel short of a whole line */
- d.fillRect(1,0,1,h-1);
- }
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Bevel an up triangle for the top of a scrollbar.
- *
- * @param loaded_image img the image you want to put the triangle in (any
- * contents of this rectangle are erased).
- * @param color_scheme s the color scheme to use for the drawing.
- */
- public static void bevel_triangle_up(loaded_image img, color_scheme s) {
- int triangle_pts_x[]=new int[3];
- int triangle_pts_y[]=new int[3];
- int w=img.width(), h=img.height();
- drawable d=img.get_drawable();
-
- /* put the stuff around the edge to connect it to the groove */
- bevel_rect(img,false,false,true,true,true,true,false,s);
-
- /* start at a point two from the top in the middle */
- triangle_pts_x[0]=w/2;
- triangle_pts_y[0]=2;
-
- /* far right point is 3rd from right, 3rd from bottom */
- triangle_pts_x[1]=w-3;
- triangle_pts_y[1]=h-3;
-
- /* far left point is 3rd from left and 3rd from bottom*/
- triangle_pts_x[2]=2;
- triangle_pts_y[2]=h-3;
-
- /* draw the polygon */
- d.setColor(s.base());
- d.fillPolygon(triangle_pts_x, triangle_pts_y, 3);
-
- /* first do the shadow , just above the top point to just to the right*/
- d.setColor(s.shadow());
- d.drawLine(w/2,1,w-2,h-3);
-
- /* add a shadow line along the bottom */
- d.drawLine(2,h-2,w-2,h-2);
-
- /* now add the left highlight from just left to just above
- the top point */
- d.setColor(s.highlight());
- d.drawLine(1,h-3,w/2,1);
-
- /* add a point just below the far left corner*/
- d.drawLine(1,h-2,1,h-2);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Bevel a down triangle for the bottom of a scrollbar.
- *
- * @param loaded_image img the image you want to put the triangle in (any
- * contents of this rectangle are erased).
- * @param color_scheme s the color scheme to use for the drawing.
- */
- public static void bevel_triangle_down(loaded_image img, color_scheme s) {
- int triangle_pts_x[]=new int[3];
- int triangle_pts_y[]=new int[3];
- int w=img.width(), h=img.height();
- drawable d=img.get_drawable();
-
- /* put the stuff around the edge to connect it to it to the groove */
- bevel_rect(img,false,false,true,true,true,false,true,s);
-
- /*first point is 3rd from left, 3rd from top */
- triangle_pts_x[0]=2;
- triangle_pts_y[0]=2;
-
- /* second point is 3rd from right, 3rd from top */
- triangle_pts_x[1]=w-3;
- triangle_pts_y[1]=2;
-
- /* final point is in the middle 2 from bottom */
- triangle_pts_x[2]=w/2;
- triangle_pts_y[2]=h-3;
-
- /* draw the polygon */
- d.setColor(s.base());
- d.fillPolygon(triangle_pts_x, triangle_pts_y, 3);
-
- /* highlight on top */
- d.setColor(s.highlight());
- d.drawLine(1,1,h-2,1);
-
- /* highlight on left */
- d.drawLine(1,2,w/2,h-2);
-
- /* shadow on right */
- d.setColor(s.shadow());
- d.drawLine(h-2,2,w/2,h-2);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Bevel a down triangle for the menu icon.
- *
- * @param loaded_image img the image you want to put the triangle in
- * @param int x_offset the offset you want the icon at in X
- * @param int y_offset the offset you want the icon at in Y
- * @param int w the width of the icon you want
- * @param int h the height of the icon you want
- * @param boolean up true if you want this icon to appear raised
- * @param color_scheme s the color scheme to use for the drawing
- */
- public static void bevel_menu_icon(loaded_image img,
- int x_offset,
- int y_offset,
- int w, int h,
- boolean up,
- color_scheme s) {
-
- int triangle_pts_x[]=new int[3];
- int triangle_pts_y[]=new int[3];
- drawable d=img.get_drawable();
-
- /*first point is 3rd from left, 3rd from top */
- triangle_pts_x[0]=x_offset+2;
- triangle_pts_y[0]=y_offset+2;
-
- /* second point is 3rd from right, 3rd from top */
- triangle_pts_x[1]=x_offset+w-3;
- triangle_pts_y[1]=y_offset+2;
-
- /* final point is in the middle 2 from bottom */
- triangle_pts_x[2]=x_offset+ (w/2);
- triangle_pts_y[2]=y_offset+h-3;
-
- /* draw the polygon */
- if (up) {
- d.setColor(s.base());
- } else {
- d.setColor(s.background());
- }
- d.fillPolygon(triangle_pts_x, triangle_pts_y, 3);
-
- /* highlight/shadow on top */
- if (up) {
- d.setColor(s.highlight());
- } else {
- d.setColor(s.shadow());
- }
- d.drawLine(x_offset+1,y_offset+1,x_offset+h-2,y_offset+1);
-
- /* highlight on left */
- d.drawLine(x_offset+1,y_offset+2,x_offset+(w/2),y_offset+h-2);
-
- /* shadow on right */
- if (up) {
- d.setColor(s.shadow());
- } else {
- d.setColor(s.highlight());
- }
- d.drawLine(x_offset+h-2,y_offset+2,x_offset+(w/2),y_offset+h-2);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Bevel a triangle for the pullright menu icon.
- * @param drawable d the surface to bevel on.
- * @param boolean up true if you want this object to appear raised.
- * @param int x x offset on the drawable.
- * @param int y y offset on the drawable.
- * @param color_scheme s the color scheme to bevel in.
- */
- public void bevel_pullright_triangle(drawable d, boolean up,
- int x, int y, color_scheme s) {
-
- int triangle_pts_x[]=new int[3];
- int triangle_pts_y[]=new int[3];
- int w=menu_pullright_size, h=menu_pullright_size;
-
- /* first point is 3rd from the right in the middle */
- triangle_pts_x[0]=x+ w-3;
- triangle_pts_y[0]=y+ (h/2);
-
- /* second point is third from the top 3rd from the left */
- triangle_pts_x[1]=x+2;
- triangle_pts_y[1]=y+2;
-
- /* last point is 3rd from bottom, 3rd from left */
- triangle_pts_x[2]=x+2;
- triangle_pts_y[2]=y+h-3;
-
- /* fill in the polygon */
- if (up) {
- d.setColor(s.base());
- } else {
- d.setColor(s.background());
- }
- d.fillPolygon(triangle_pts_x,triangle_pts_y,3);
-
- /* highlight on left */
- if (up) {
- d.setColor(s.highlight());
- } else {
- d.setColor(s.shadow());
- }
- d.drawLine(x+1,y+1,x+1,y+h-2);
-
- /* highlight along top */
- d.drawLine(x+2,y+1,x+w-2,y+(h/2));
-
- /* shadow on the bottom */
- if (up) {
- d.setColor(s.shadow());
- } else {
- d.setColor(s.highlight());
- }
- d.drawLine(x+w-2,y+(h/2),x+2,y+h-2);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Bevel a left triangle for the left of a scrollbar.
- *
- * @param loaded_image img the image you want to put the triangle in (any
- * contents of this rectangle are erased).
- * @param color_scheme s the color scheme to use for the drawing.
- */
- public static void bevel_triangle_left(loaded_image img, color_scheme s) {
- int triangle_pts_x[]=new int[3];
- int triangle_pts_y[]=new int[3];
- int w=img.width(), h=img.height();
- drawable d=img.get_drawable();
-
- /* put the stuff around the edge to connect it to it to the groove */
- bevel_rect(img,false,false,true,
- true,false,true,true,s);
-
- /* first point is 3rd from right and halfway down */
- triangle_pts_x[0]=2;
- triangle_pts_y[0]=h/2;
-
- /* second point is third from top, and third from right */
- triangle_pts_x[1]=w-3;
- triangle_pts_y[1]=2;
-
- /* last point is 3rd from bottom, third from right */
- triangle_pts_x[2]=w-3;
- triangle_pts_y[2]=h-3;
-
- /* fill in the polygon */
- d.setColor(s.base());
- d.fillPolygon(triangle_pts_x,triangle_pts_y,3);
-
- /* shadow behind */
- d.setColor(s.shadow());
- d.drawLine(w-2,1,w-2,h-2);
-
- /* shadow below */
- d.drawLine(1,h/2,w-2,h-2);
-
- /* highlight along top */
- d.setColor(s.highlight());
- d.drawLine(1,h/2,w-3,1);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Bevel a right triangle for the right of a scrollbar.
- *
- * @param loaded_image img the image you want to put the triangle in (any
- * contents of this rectangle are erased).
- * @param color_scheme s the color scheme to use for the drawing
- */
- public static void bevel_triangle_right(loaded_image img, color_scheme s) {
- int triangle_pts_x[]=new int[3];
- int triangle_pts_y[]=new int[3];
- int w=img.width(), h=img.height();
- drawable d=img.get_drawable();
-
- /* put the stuff around the edge to connect it to it to the groove */
- bevel_rect(img,false,false,true,false,true,true,true,s);
-
- /* first point is 3rd from the right in the middle */
- triangle_pts_x[0]=w-3;
- triangle_pts_y[0]=h/2;
-
- /* second point is third from the top 3rd from the left */
- triangle_pts_x[1]=2;
- triangle_pts_y[1]=2;
-
- /* last point is 3rd from bottom, 3rd from left */
- triangle_pts_x[2]=2;
- triangle_pts_y[2]=h-3;
-
- /* fill in the polygon */
- d.setColor(s.base());
- d.fillPolygon(triangle_pts_x,triangle_pts_y,3);
-
- /* highlight on left */
- d.setColor(s.highlight());
- d.drawLine(1,1,1,h-2);
-
- /* highlight along top */
- d.drawLine(2,1,w-2,h/2);
-
- /* shadow on the bottom */
- d.setColor(s.shadow());
- d.drawLine(w-2,h/2,2,h-2);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is the number of degrees of offset for this beveling
- * of circles.
- */
- protected static int bevel_start_angle=60;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Bevel a circle for use with radio buttons. This code also inserts
- *
- * @param loaded_image img the image to put the circle in.
- * @param boolean up whether to bevel this image in the "up position"
- * (true) or the "down position" (false).
- * @param color_scheme s the color scheme we are using.
- */
- public void bevel_circle(loaded_image img,boolean up,color_scheme s) {
- drawable d=img.get_drawable();
- int w=img.width(), h=img.height();
-
- /* fill with the background */
- d.setColor(s.base());
- d.fillRect(0,0,w,h);
-
- /* are we doing up? */
- if (up) {
- d.setColor(s.highlight());
- d.drawArc(0,0,w-1,h-1,bevel_start_angle,180);
- d.setColor(s.shadow());
- d.drawArc(0,0,w-1,h-1,bevel_start_angle+180,180);
- } else {
- /* its down */
- d.setColor(s.shadow());
- d.drawArc(0,0,w-1,h-1,bevel_start_angle,180);
- d.setColor(s.highlight());
- d.drawArc(0,0,w-1,h-1,bevel_start_angle+180,180);;
-
- /* smaller splash circle in middle */
- d.setColor(s.splash());
- d.fillArc(3,3,w-6,h-6,0,360);
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* ****************** VERTICAL SCROLLBAR ***************/
- /**
- * This is how wide the vertical scrollbar is.. the thumb is
- * two pixels less.
- */
- static int v_scrollbar_width=15;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct three images for a vertical scrollbar. Vertical scrollbars
- * in sub_arctic are assumed to be of fixed width (although this
- * is really not true for motif). Image #0 is the up image,
- * image #1 is the down image, #2 is the background image (which will
- * get tiled along the length of the scrollbar) and #3 is the thumb.
- * #0, #1, and #2 must be the same width and #3 be no larger than
- * the other three.
- *
- * @return loaded_image[] an array of 3 images for displaying a scrollbar in
- * your style
- */
- public loaded_image[] v_scrollbar_images() {
- loaded_image img[]=new loaded_image[3];
-
- /* we are going to make them 15 pixels wide cause I like them
- * that size. IES */
-
- //up image
- img[0]=new loaded_image(v_scrollbar_width,v_scrollbar_width);
-
- //down image
- img[1]=new loaded_image(v_scrollbar_width,v_scrollbar_width);
-
- //background image
- img[2]=new loaded_image(v_scrollbar_width,200);
-
- // make the groove
- bevel_rect(img[2],false,false,true /* one pixel */,
- true, true, false, false, /* want left right only */
- style_manager.default_color_scheme());
-
- /* make the up and down */
- bevel_triangle_up(img[0],style_manager.default_color_scheme());
- bevel_triangle_down(img[1],style_manager.default_color_scheme());
-
- /* send em home */
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This method should return how far from the left edge the scrollbar
- * is placed in this style.
- * @return int the "shift" of the v_scrollbar thumb to the right
- */
- public int v_scrollbar_thumb_shift() { return 1;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This method should return an image of a thumb of a given
- * height.
- * @param int h the height of the thumb in pixels
- * @return loaded_image the thumb image.
- */
- public loaded_image v_scrollbar_thumb(int h) {
-
- // make the image
- loaded_image img=new loaded_image(v_scrollbar_width-2,h);
-
- /* bevel a thumb, one pixel wide, raised */
- bevel_rect(img,true /* raised */, true /* base */,
- true /* one_pix */, true /* left */,
- true /* right */, true /* top */,
- true /*bottom */,style_manager.default_color_scheme());
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is the minimum height of a scrollbar thumb.
- * @return the minimum usable size of a scrollbar thumb (in pixels)
- */
- public int v_scrollbar_minimum_thumb_size() { return 10;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* ****************** HORIZONTAL SCROLLBAR ***************/
- /**
- * This is how tall the horizontal scrollbar is.. the thumb is
- * two pixels less.
- */
- static int h_scrollbar_height=15;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct three images for a horizontal scrollbar. Horizontal scrollbars
- * in sub_arctic are assumed to be of fixed height (although this
- * is really not true for motif). Image #0 is the left image,
- * image #1 is the right image, #2 is the background image (which will
- * get tiled along the length of the scrollbar) and #3 is the thumb.
- * #0, #1, and #2 must be the same width and #3 be no larger than
- * the other three.
- *
- * @return loaded_image[] an array of 3 images for displaying a scrollbar
- * in your style
- */
- public loaded_image[] h_scrollbar_images() {
- loaded_image img[]=new loaded_image[3];
-
- /* we are going to make them 15 pixels hight cause I like them
- * that size. IES */
-
- //up image
- img[0]=new loaded_image(h_scrollbar_height,h_scrollbar_height);
-
- //down image
- img[1]=new loaded_image(h_scrollbar_height,h_scrollbar_height);
-
- //background image
- img[2]=new loaded_image(200,h_scrollbar_height);
-
- // make the groove
- bevel_rect(img[2],false,false,true /* one pixel */,
- false, false, true, true, /* want top/bottom only */
- style_manager.default_color_scheme());
-
- /* make the up and down */
- bevel_triangle_left(img[0],style_manager.default_color_scheme());
- bevel_triangle_right(img[1],style_manager.default_color_scheme());
-
- /* send em home */
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This method should return how far from the top edge the scrollbar
- * is placed in this style.
- * @return int the "shift" of the v_scrollbar thumb to the right
- */
- public int h_scrollbar_thumb_shift() { return 1;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This method should return an image of a thumb of a given
- * width.
- * @param int w the width of the thumb in pixels.
- * @return loaded_image the resulting thumb image.
- */
- public loaded_image h_scrollbar_thumb(int w) {
-
- // make the image
- loaded_image img=new loaded_image(w,h_scrollbar_height-2);
-
- /* bevel a thumb, one pixel wide, raised */
- bevel_rect(img,true /* raised */, true /* base */,
- true /* one_pix */, true /* left */,
- true /* right */, true /* top */,
- true /*bottom */,style_manager.default_color_scheme());
-
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is the minimum thumb width of a scrollbar.
- * @return the minimum usable size of a scrollbar thumb (in pixels)
- */
- public int h_scrollbar_minimum_thumb_size() { return 10;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* ****************** BUTTON ***************/
- /**
- * This is the amount of space used to bevel a button. It is
- * the same in x and y.
- */
- private static final int bevel_space=4;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is the amount of extra space needed to the right of the
- * menu label to fit the menu icon.
- */
- private static final int menu_icon_space=14;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is the size of the width and the height of the menu icon.
- */
- private static final int menu_icon_size=10;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct the images for a button. In the returned array,
- * img 0 is the up and img 1 is the depressed (unhappy) appearance.
- *
- * @param String label the string for the button.
- * @param Font the font to draw the button with.
- * @param int x_spacing the amount of x border (appears on left and right).
- * @param int y_spacing the amount of y border (appears on top and bottom).
- * @param boolean menu true if you want the appearance of a menu button.
- * @return loaded_image[] resulting array of 2 images.
- */
- public loaded_image[] button_make_images(String label,
- Font font,
- int x_spacing,
- int y_spacing,
- boolean menu) {
-
- int string_width,total_width,string_height,x,y,total_height ;
- int menu_width= menu ? menu_icon_space : 0, width_no_menu;
-
- // grab the font metrics
- FontMetrics metrics=manager.get_metrics(font);
- loaded_image img[]=new loaded_image[2];
- drawable d;
- int extra;
-
- /* figure out how big the string is in x and y */
- string_width=metrics.stringWidth(label);
- string_height=metrics.getHeight() - metrics.getLeading();
-
- /* get the total width without considering the menu */
- width_no_menu=string_width + (2*x_spacing) + bevel_space ;
-
- /* compute total width and total height */
- total_height= string_height + (2*y_spacing) + bevel_space;
- total_width=width_no_menu + menu_width;
-
- /* make the images and bevel */
- img[0]=new loaded_image(total_width, total_height);
- img[1]=new loaded_image(total_width, total_height);
-
- /* .... now bevel */
- bevel_rect(img[0],true /* raised */,true /* base color */,
- false /*one_pix*/, true, true, true, true,
- style_manager.default_color_scheme());
- bevel_rect(img[1],false /* raised*/,false /* base */,
- false /*one_pix */, true, true, true, true,
- style_manager.default_color_scheme());
-
- /* where does the text go */
- x=x_spacing + bevel_space/2;
- y=y_spacing + metrics.getAscent() + bevel_space/2;
-
- /* draw the text */
- d=img[0].get_drawable();
- d.setFont(font);
- d.setColor(style_manager.default_color_scheme().foreground());
- d.drawString(label,x,y);
- d=img[1].get_drawable();
- d.setColor(style_manager.default_color_scheme().foreground());
- d.setFont(font);
- d.drawString(label,x,y);
-
- /* are we doing a menu? */
- if (menu) {
- // the last subtract is to account for the fact of being left
- // of the right border
- int xshift=width_no_menu + ((menu_icon_space - menu_icon_size)/2) -
- (bevel_space/2);
- int yshift=(total_height-menu_icon_size)/2;
-
- /* do the up icon */
- bevel_menu_icon(img[0],xshift,yshift,menu_icon_size,
- menu_icon_size, true,
- style_manager.default_color_scheme());
-
- /* do the down icon */
- bevel_menu_icon(img[1],xshift,yshift,menu_icon_size,
- menu_icon_size,false,
- style_manager.default_color_scheme());
- }
-
- /* return the images */
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct the images for a blank button.
- *
- * @param int width this is the <I>usable</I> width you desire for
- * this button.
- * @param int height this is the <I>usable</I> height you desire for
- * this button.
- * @param int x_spacing the amount of x border (appears on left and
- * right).
- * @param int y_spacing the amount of y border (appears on top and
- * bottom).
- * @param boolean menu true if you want the appearance of a menu button
- * @returns loaded_image[] resulting array of 2 images.
- */
- public loaded_image[] button_make_images(int width,
- int height,
- int x_spacing,
- int y_spacing,
- boolean menu) {
- loaded_image img[]=new loaded_image[2];
- drawable d;
- int menu_width= menu ? menu_icon_space : 0;
-
- /* make the space for the picture, plus the border, plus the
- room for the beveling */
- img[0]=new loaded_image(width + (2*x_spacing) + bevel_space
- + menu_width ,
- height + (2*y_spacing) + bevel_space);
- img[1]=new loaded_image(width + (2*x_spacing) + bevel_space +
- menu_width,
- height + (2*y_spacing) + bevel_space);
-
- /* .... now bevel */
- bevel_rect(img[0],true,true,false, true, true, true, true,
- style_manager.default_color_scheme());
- bevel_rect(img[1],false,false,false, true, true, true, true,
- style_manager.default_color_scheme());
-
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return the amount of shift in x required for an image to placed
- * on this style of button. This does NOT including the x spacing
- * but rather only the pixels that the button code isn't normally
- * allowed to use (the beveling).
- * @return int the amount to shift the image on a button in x
- */
- public int button_x_shift() {
- return bevel_space/2;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return the amount of shift in y required for an image to placed
- * on this style of button. This does NOT including the y spacing
- * but rather only the pixels that the button code isn't normally
- * allowed to use (the beveling).
- * @return int the amount to shift the image on a button in y
- */
- public int button_y_shift() {
- return bevel_space/2;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* ****************** RADIOBUTTON ***************/
- /**
- * We like motif images at 15 pixels x 15 pixels.
- */
- protected static int motif_radio_button_size=15;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return a pair of images which give the off (img[0]) and the
- * on (img[1]) appearance for a radio button. Note: For some styles,
- * this is the same appearance as a checkbox. These images should
- * be the same size.
- *
- * @return loaded_image[] an array of 2 images for the off and on look of
- * a radio button.
- */
- public loaded_image[] radio_button_make_images() {
- loaded_image img[]=new loaded_image[2];
- img[0]=new loaded_image(motif_radio_button_size,motif_radio_button_size);
- img[1]=new loaded_image(motif_radio_button_size,motif_radio_button_size);
-
- bevel_circle(img[0],true,style_manager.default_color_scheme());
- bevel_circle(img[1],false,style_manager.default_color_scheme());
-
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return a pair of transitions images for the transitions from
- * (img[0]) off to on and (img[1])on to off. A style may return
- * null here there will be no special transition used.
- */
- public loaded_image[] radio_button_make_transitions() {
- return null;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* ****************** CHECKBOX ***************/
- /**
- * Return a pair of images which give the off (img[0]) and the
- * on (img[1]) appearance for a checkbox. Note: For some styles,
- * this is the same appearance as a radiobutton. These images should
- * be the same size.
- *
- * @return loaded_image[] an array of 2 images for the off and on look of
- * a checkbox
- */
- public loaded_image[] checkbox_make_images() {
- loaded_image img[]=new loaded_image[2];
- img[0]=new loaded_image(motif_radio_button_size,motif_radio_button_size);
- img[1]=new loaded_image(motif_radio_button_size,motif_radio_button_size);
- loaded_image orig_check, real_check;
-
- /* step one, is to create the boxes */
- bevel_rect(img[0],true,true,true,
- true,true,true,true, /* all four walls */
- style_manager.default_color_scheme());
- bevel_rect(img[1],false,false,true,
- true,true,true,true, /* all four walls */
- style_manager.default_color_scheme());
-
- /* now add the check */
- img[1].get_drawable().drawImage(check(),1,1);
-
- /* send it home */
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return a pair of transitions images for the transitions from
- * (img[0]) off to on and (img[1])on to off. A style may return
- * null here there will be no special transition used.
- * @return loaded_image[] resulting array of 2 images.
- */
- public loaded_image[] checkbox_make_transitions() {
- return null;
- }
-
-
- /* ********************** MISC *************************/
- /**
- * This function gets called to inform the style that the
- * default_color_scheme has changed. This is to allow the
- * style to do any necessary recalculation of images based
- * on the new color_scheme before interactors become notified
- * that there is a new color_scheme.
- */
- public void color_scheme_changed() {
- calculate_check();
- }
-
- /* ************************ DRAWABLE ***********************/
- /**
- * This function gets called to force the style to set up
- * a rectangular area of a drawable. The caller is requesting
- * that the drawable be prepared for further drawing by caller.
- * This is useful interactors which do their drawing in
- * draw_self_local() and/or people wishing to implement new
- * interactors which can "fit in" with the style.
- *
- * @param drawable d the drawable to prepare. It assumed that the style
- * will be called <I>before</I> the caller does his
- * drawing, so the style can and should fill the
- * background.
- * @param int x the x coordinate of the top left corner of the area to
- * prepare.
- * @param int y the y coordinate of the top left corner of the area to
- * prepare.
- * @param int w the width of the area to prepare.
- * @param int h the height of the area of prepare.
- * @param boolean up if this is true the style may draw this area raised,
- * if this is false the style may draw this area lowered.
- * The style is under no obligation to follow this hint.
- * @param boolean fill true if the style system should fill the background.
- */
- public void drawable_prepare_rect(drawable d, int x, int y,
- int w, int h, boolean up, boolean fill) {
-
- color_scheme colors=style_manager.default_color_scheme();
- Color c=d.getColor();
-
- /* fill with the base or with the background*/
- if (up) {
- d.setColor(colors.base());
- } else {
- d.setColor(colors.background());
- }
-
- if (fill) {
- d.fillRect(x,y,w,h);
- }
-
- /* put a one pixel wide strip of highlight/shadow on right ...
- you want to to the bottom and right first to mimic motif */
- if (up) {
- d.setColor(colors.shadow());
- } else {
- d.setColor(colors.highlight());
- }
- d.fillRect(x+w-1,y,1,h);
-
- /* we are two pixels wide*/
- d.fillRect(x+w-2,y,1,h);
-
- /* put a one pixel wide strip of shadow/highlight on bottom */
- d.fillRect(x,y+h-1,w,1);
- d.fillRect(x,y+h-2,w,1);
-
- /* put a one pixel wide strip of highlight/shadow along the top */
- if (up) {
- d.setColor(colors.highlight());
- } else {
- d.setColor(colors.shadow());
- }
- d.fillRect(x,y,w,1);
-
- /* this is supposed to be one pixel shorter */
- d.fillRect(x,y+1,w-1,1);
-
- /* left side */
- d.fillRect(x,y,1,h);
-
- /* again, this is one pixel short of a whole line */
- d.fillRect(x+1,y,1,h-1);
-
- /* reset the color to what it was before */
- d.setColor(c);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This function is called to allow the caller to determine what area
- * of the drawable has been prepared by the style.
- * @return int the amount of horizontal space used by the style (XXX
- * assumes left/right symmetry)
- */
- public int drawable_horizontal_space() { return 2;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This function is called to allow the caller to determine what area
- * of the drawable has been prepared by the style.
- * @return int the amount of vertical space used by the style (XXX
- * assumes up/down symmetry)
- */
- public int drawable_vertical_space() { return 2;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* ************************ SCALE ***********************/
- /**
- * This is how tall we want our scales to be.
- */
- protected int motif_scale_height=15;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is how big we want our thumbs to be.
- */
- protected int motif_scale_thumb_width=30;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is how far to shift the thumb.
- */
- protected int motif_scale_thumb_shift=1;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This function returns the image of a scale's background
- * at a given width in pixels.
- * @param int w the width of the scale in pixels.
- * @return loaded_image the image of the scale's background.
- */
- public loaded_image scale_background(int w) {
- loaded_image img=new loaded_image(w,motif_scale_height);
-
- bevel_rect(img,false,false /* dark background for darker look*/,
- true, true /*left */, true /*right */, true /*top */,
- true /* bottom */, style_manager.default_color_scheme());
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This returns the height of the scale in pixels. We assume
- * that scales are not resizable in height.
- * @return int the height of the scale
- */
- public int scale_height() {
- return motif_scale_height;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This returns the image of the thumb of a scale.
- * @return loaded_image the image of the thumb
- */
- public loaded_image scale_thumb() {
- loaded_image img=new loaded_image(motif_scale_thumb_width,
- motif_scale_height-2);
- drawable d=img.get_drawable();
- int xpos=motif_scale_thumb_width/2;
-
- bevel_rect(img,true,true /*base */,true,
- true /* left */, true /* right */, true /* top */,
- true /* bottom */, style_manager.default_color_scheme());
-
- /* now add a small "knicknack" to the thumb */
- d.setColor(style_manager.default_color_scheme().shadow());
-
- /* we draw from 1 so as to not screw up the top beveling */
- d.drawLine(xpos,1,xpos,img.height());
- d.setColor(style_manager.default_color_scheme().highlight());
- d.drawLine(xpos+1,1,xpos+1,img.height());
-
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This returns the number of pixels the thumb is shifted
- * down from the top of the scale.
- * @return int the amount of the shift of the thumb in y
- */
- public int scale_thumb_shift() {
- return motif_scale_thumb_shift;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This returns the amount of space on both ends which
- * is used by the system for its beveling/color scheme.
- * If you are using a 1 pixel bevel return 1 here.
- * @return int the number of pixels to shift the display of the thumb to
- * the right when doing the display
- */
- public int scale_unusable_width() { return 1;};
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* ************************ MENU ***********************/
- /**
- * This function determines if a menu pops to the right and
- * down from an menu button interactor or if it pops directly
- * down. Return true for the (mac style) pop to the right
- * type and false for the (motif style) pop string down type.
- * @return boolean true for pop-right false for pop-down
- */
- public boolean menu_pop_right() { return false;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This holds amount of space we are going to leave on the left
- * of the text to assure that we can put a small "knicknack" of
- * some kind in there if necessary.
- */
- private static int menu_space_left = 10 ;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This holds amount of space we are going to leave on the right
- * of the text to assure that we can put a pullright icon in
- * place.
- */
- private static int menu_space_right = 12 ;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is the size of the pullright menu icon.
- */
- private static int menu_pullright_size = 8;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This function determines the "natural" size of menu item
- * of text. Menu items can be made any width, but this expresses
- * the natural size of the object. The style object may include
- * extra space for interactors that are placed on the menu
- * item.
- * @param String s the string to display.
- * @param Font f the font to display the text in.
- * @param int x_spacing the amount of horizontal spacing desired.
- * @param int y_spacing the amount of vertical spacing desired.
- * @return Dimension the natural size of this menu item.
- */
- public Dimension menu_item_natural_size(String s, Font f,
- int x_spacing,
- int y_spacing) {
-
- int w,h;
- FontMetrics metrics=manager.get_metrics(f);
-
- /* just a font computation plus the motif beveling */
- w=menu_space_left + metrics.stringWidth(s) + menu_space_right +
- (2*x_spacing) + 2; /* 2 is for beveling */
- h=(metrics.getHeight()-metrics.getLeading()) + (2*y_spacing) + 2;
-
- return new Dimension(w,h);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This function creates the two images of a menu up (unhighlighted)
- * & down (highlighted). You must supply the width and height of
- * the images you wish to create; use menu_item_natural_size()
- * to determine the natural size of menu items. The style
- * object is expected to observe the x_spacing and y_spacing
- * arguments, even if this forces clipping or overdrawing
- * to occur.
- *
- * @param String s the string to display.
- * @param Font f the font to display the text in.
- * @param int x_spacing the amount of horizontal spacing desired.
- * @param int y_spacing the amount of vertical spacing desired.
- * @param int w width of the image.
- * @param int h height of the image.
- * @param boolean pullright true if you want a notation for a pullright
- * image on this menu item.
- * @return loaded_image[] resulting array of 2 images.
- */
- public loaded_image[] menu_item_image(String s, Font f,
- int x_spacing, int y_spacing,
- int w, int h, boolean pullright) {
-
- loaded_image img[]=new loaded_image[2];
- int xoff, yoff;
- FontMetrics metrics=manager.get_metrics(f);
- drawable d;
-
- /* make the images */
- img[0]=new loaded_image(w,h);
- img[1]=new loaded_image(w,h);
-
- /* bevel the rectangles, first is flat in base and the
- second a down in background */
- bevel_rect(img[0],true /* up */,true /* base */, true /*one pix */,
- false /* no left */, false /* no right */,
- false /* no top */, false /* no bottom */,
- style_manager.default_color_scheme());
- bevel_rect(img[1],false /* down */,false /* bkgrnd */, true /*one pix */,
- true, true, true, true,
- style_manager.default_color_scheme());
-
- /* place the text on the up */
- xoff=x_spacing + menu_space_left + 1 /* 1 is the bevel */;
- yoff=y_spacing + metrics.getAscent() + 1 /* 1 is bevel */;
- d=img[0].get_drawable();
- d.setFont(f);
- d.setColor(style_manager.default_color_scheme().foreground());
- d.setFont(f);
- d.drawString(s,xoff,yoff);
- if (pullright) {
- bevel_pullright_triangle(d,true /*up */,
- w-x_spacing-menu_pullright_size,
- (h-menu_pullright_size)/2,
- style_manager.default_color_scheme());
-
-
- }
-
- /* do the down */
- d=img[1].get_drawable();
- d.setFont(f);
- d.setColor(style_manager.default_color_scheme().foreground());
- d.drawString(s,xoff,yoff);
-
- /* do we have a pullright? */
- if (pullright) {
- bevel_pullright_triangle(d,false /*down */,
- w-x_spacing-menu_pullright_size,
- (h-menu_pullright_size)/2,
- style_manager.default_color_scheme());
-
-
- }
-
- /* send the images back */
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * How tall is a separator.
- */
- private static final int separator_height=2;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Return the image of a menu separator. The style may choose
- * to return a zero height object for this separator if it does
- * not allow menu separators.
- * @return loaded_image the image of the separator.
- */
- public loaded_image menu_item_separator(int w) {
-
- loaded_image img=new loaded_image(w,separator_height);
- drawable d=img.get_drawable();
- d.setColor(style_manager.default_color_scheme().shadow());
- d.drawLine(0,0,w,0);
- d.setColor(style_manager.default_color_scheme().highlight());
- d.drawLine(0,1,w,1);
-
- return img;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /* ************************ MENUBAR ***********************/
-
- /** left and right edge spacing */
- private static final int menubar_edge_space=10;
-
- /** space between menu buttons */
- private static final int menubar_inter_child_space=20;
-
- /** space above menu bar items */
- private static final int menubar_top_space=5;
-
- /** space below the menu bar items */
- private static final int menubar_bottom_space=5;
-
- /**
- * This is the most complex of the style functions, and the one that
- * certainly leaves the most room for improvement. The caller of
- * this function is requesting several things. First, an image to
- * display for a menu bar of a given width. Second, a set of
- * rectangles that tell the menubar infrastructure what regions of
- * the menu bar are "hot." Finally, the caller is asking for
- * a set of images that corresponds to the "depressed" images
- * of each hotspt. <P>
- *
- * The caller supplies the style system with two vectors. Each
- * vector must contain <I>only</I> strings or loaded_images. (If
- * the loaded images are taller than the height of the font supplied,
- * they will be clipped.) The caller is responsible for making
- * sure the types of the objects are correct. The style system will
- * create it set of hot spots and images with the first vector
- * occupying the "normal" or left positions and the the second
- * vector occupying the "special" or right positions. These vectors
- * may not be null, although they may be empty.
- *
- * @param Vector left this should be a non-null (but possibly empty)
- * vector of strings and images. Items in this
- * vector will be replaced with loaded_images
- * representing that items "down" image. These
- * items will appear on the left of the menu
- * bar, in the order supplied.
- * @param Vector right this should be a non-null (but possibly empty)
- * vector of strings and images. Items in this
- * vector will be replaced with loaded_images
- * representing that items "down" image. These
- * items will appear on the right of the
- * menubar in the order supplied (last in the
- * Vector being the rightmost).
- * @param int width width of the menubar in pixels (items which
- * don't fit on the menubar will be clipped)
- * @param Font font the font to use for rendering strings. If
- * you have a menubar which has only images on
- * it, the menu bar is still the height of this
- * font.
- * @param Vector left_hotspots the caller should pass a non-null but empty
- * vector which will be filled in which
- * Rectangle objects indicating the positions
- * of the objects in the left vector on the
- * returned image.
- * @param Vector right_hotspots the caller should pass a non-null but empty
- * vector which will be filled in which
- * Rectangle objects indicating the positions
- * of the objects in the right vector on the
- * returned image.
- * @return loaded_image the image of the menu bar at the selected width
- */
- public loaded_image make_menubar_images(Vector left_items,
- Vector right_items,
- int width,
- Font font,
- Vector left_hotspots,
- Vector right_hotspots) {
- /* figure out how tall the bar is */
- FontMetrics metrics=manager.get_metrics(font);
- int height,i,left=menubar_edge_space,right,item_width,farthest_right=0;
- loaded_image menubar,image=null,depressed;
- drawable d;
- String text=null;
- Object o;
- Rectangle rect;
-
- /* we are just going to disallow menubars if they get too small */
- if (width<4*menubar_edge_space) {
- return null;
- }
-
- /* set the size of the hotspot objects */
- left_hotspots.setSize(left_items.size());
- right_hotspots.setSize(right_items.size());
-
- /* how tall is the object's font */
- height=metrics.getHeight() - metrics.getLeading();
-
- /* add in the spacing */
- height+=menubar_top_space + menubar_bottom_space;
-
- /* make the menubar image */
- menubar=new loaded_image(width,height);
-
- /* bevel it */
- bevel_rect(menubar, true, true, false /* two pixels on bars */,
- true, true, true, true, style_manager.default_color_scheme());
-
- /* compute area for left objects */
- for (i=0; i<left_items.size(); ++i) {
-
- /* figure out how wide this item is... first get the item */
- o=left_items.elementAt(i);
-
- /* is it string or image? */
- if (o instanceof String) {
- /* string, so use the font metrics to figure out size */
- text=(String)o;
- item_width=metrics.stringWidth(text) + menubar_inter_child_space;
- } else {
- /* we assume this cause we figure the layer above us will check */
- /* convert to image and just ask its size*/
- image=(loaded_image)o;
- item_width=image.width() + menubar_inter_child_space;
- }
-
- /* is the left edge past the end of the menu bar? */
- if (left>menubar.width()) {
- /* set the image of this to be null */
- left_items.setElementAt(null,i);
- left_hotspots.setElementAt(null,i);
-
- /* make sure we don't end up with stuff from the right part
- hosing us */
- farthest_right=left;
-
- /* next iter */
- continue;
- }
-
- /* normal case... the object is going to at least partially fit */
- /* where is the right edge */
- right=left+item_width;
-
- /* make sure the area doesn't go past the edge */
- if (right>menubar.width()) {
- right=menubar.width();
- }
-
- /* we now have a new farthest right */
- farthest_right=right;
-
- /* build the image of the depressed button */
- depressed=new loaded_image(right-left,height-(2*menubar_image_shift()));
-
- /* bevel it down */
- bevel_rect(depressed, false /* lowered */, false /* background */,
- true /* one pix */, true, true, true, true,
- style_manager.default_color_scheme());
-
- /* draw on the main menubar */
- d=menubar.get_drawable();
-
- /* is it text or not? */
- if (o instanceof String) {
- d.setFont(font);
- d.drawString(text,left + (menubar_inter_child_space/2),
- menubar_top_space + metrics.getAscent());
- } else {
- /* its an image, figure out where to put its top left corner */
- d.drawImage(image,left + (menubar_inter_child_space/2),
- menubar_top_space);
- }
-
- /* draw on the down image */
- d=depressed.get_drawable();
-
- /* is it text or not? */
- if (o instanceof String) {
- d.setFont(font);
- d.drawString(text,menubar_inter_child_space/2,
- (menubar_top_space + metrics.getAscent()) -
- (menubar_image_shift()));
- } else {
- /* its an image, figure out where to put its top left corner */
- d.drawImage(image,menubar_inter_child_space/2,
- menubar_top_space);
- }
-
- /* put the depressed image in the slot for the object */
- left_items.setElementAt(depressed,i);
-
- /* put the coordinates of this guy in his rectangle */
- rect=new Rectangle(left,0,right-left,height);
- left_hotspots.setElementAt(rect,i);
-
- /* reset the left coordinate */
- left=right+1;
- }
-
- /*
- * Walk the right hand set of objects
- */
- /* initialize right to be the right hand side */
- right=width-menubar_edge_space;
-
- /* walk along the right_items data structure in reverse order */
- for (i=right_items.size()-1; i>=0; --i) {
-
- /* figure out how wide this item is... first get the item */
- o=right_items.elementAt(i);
-
- /* is it string or image? */
- if (o instanceof String) {
- /* string, so use the font metrics to figure out size */
- text=(String)o;
- item_width=metrics.stringWidth(text) + menubar_inter_child_space;
- } else {
- /* we assume this cause we figure the layer above us will check */
- /* convert to image and just ask its size*/
- image=(loaded_image)o;
- item_width=image.width() + menubar_inter_child_space;
- }
-
- /* compute the left edge of the object */;
- left=right-item_width;
-
- /* is it too far over to be displayed at all? */
- if ((right<0)|| (right<farthest_right) /* of the left objects */) {
- /* nothing to do except bail out */
- /* set the image of this to be null */
- right_items.setElementAt(null,i);
- right_hotspots.setElementAt(null,i);
-
- /* next iter */
- continue;
- }
-
- /* it will at least partially fit, so make sure it isn't partial */
- if ((left<0) || (left<farthest_right)) {
- if (left<0) left=0;
- if (left<farthest_right) left=farthest_right;
- }
-
- /* build the image of the depressed button */
- depressed=new loaded_image(right-left,height-(2*menubar_image_shift()));
-
- /* bevel it down */
- bevel_rect(depressed, false /* lowered */, false /* background */,
- true /* one pix */, true, true, true, true,
- style_manager.default_color_scheme());
-
- /* draw on the main menubar */
- d=menubar.get_drawable();
-
- /* is it text or not? */
- if (o instanceof String) {
- d.setFont(font);
- d.drawString(text,left + (menubar_inter_child_space/2),
- menubar_top_space + metrics.getAscent());
- } else {
- /* its an image, figure out where to put its top left corner */
- d.drawImage(image,left + (menubar_inter_child_space/2),
- menubar_top_space);
- }
-
- /* draw on the down image */
- d=depressed.get_drawable();
-
- /* is it text or not? */
- if (o instanceof String) {
- d.setFont(font);
- d.drawString(text,menubar_inter_child_space/2,
- (menubar_top_space + metrics.getAscent()) -
- menubar_image_shift());
- } else {
- /* its an image, figure out where to put its top left corner */
- d.drawImage(image,menubar_inter_child_space/2,
- menubar_top_space);
- }
-
- /* put the depressed image in place */
- right_items.setElementAt(depressed,i);
-
- /* put the coordinates of this guy in his rectangle */
- rect=new Rectangle(left,0,right-left,height);
- right_hotspots.setElementAt(rect,i);
-
- /* update the right coordinate */
- right=left-1;
- }
-
- /* done with everything, return the menubar */
- return menubar;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This parameter controls how far down the images resulting from
- * a menubar should be shifted down (in their hotspot) to compensate
- * for potential style system beveling.
- *
- * @return int the number of pixels the depressed images should be shifted
- * down in their hotspot when the button is depressed.
- */
- public int menubar_image_shift() {
- return 2; /* two pixel bevel on menubars */
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-