home *** CD-ROM | disk | FTP | other *** search
- /**
- * This is an example program which tests out the new style based
- * interactors.
- */
- package sub_arctic.test;
-
- import sub_arctic.lib.*;
- import sub_arctic.output.*;
- import sub_arctic.input.*;
- import sub_arctic.constraints.std_function;
-
- import java.awt.Font;
- import java.awt.Point;
- import java.awt.Image;
- import java.net.URL;
- import java.net.MalformedURLException;
- import java.util.Vector;
-
- /**
- * This is an example program which tests out the new style based
- * interactors.
- *
- * @author Ian Smith
- * @version $Id: style_test.java,v 1.14 1996/10/03 19:46:51 hudson Exp $
- */
- public class style_test extends interactor_applet implements callback_object {
- String radio_stations[] = { "WREK", "WRAS","KFJC"};
- /* first station tuned to is WREK */
- String station="WREK";
- /* the parent of the popup menu */
- popup_parent pop_parent;
- /* these menus are in the class so we can test for them in the callback */
- /* make the interface */
- menu toolkit_menu, version_menu,file_menu,edit_menu, help_menu;
- public void build_ui(base_parent_interactor top) {
- v_scrollbar vs;
- h_scrollbar hs;
- button b,logo;
- URL url;
- Image image;
- loaded_image loaded_version;
- scale sc;
- text_toggle_collection c1,c2;
- String choices[] = {"Blues","Industrial", "Techno", "Alternapop",
- "Swing"};
- String toolkit[] = {"Motif", "AWT", "SubArctic", "Fresco", "Artkit"};
- String version[] = {"Billings", "Minneapolis", "Edmonton", "Nome"};
- String file[] = {"New","Open","Save", "Quit"};
- String edit[] = {"Cut", "Copy", "Paste", "Select All"};
- String help[] = {"Little Help", "Less Help", "No Help", "Get Help"};
-
- Vector left=new Vector(),right=new Vector();
- menu_button mb;
- menubar mbar;
- display_help_container dhc1, dhc2, dhc3;
- int max,i;
-
- /* make the popup parent cover the whole thing */
- pop_parent=new popup_parent(station);
- pop_parent.set_w_constraint(std_function.offset(PARENT.W(), 0));
- pop_parent.set_h_constraint(std_function.offset(PARENT.H(), 0));
- top.add_child(pop_parent);
- /*
- * put in the menubar
- */
- left.addElement("File");
- left.addElement("Edit");
- right.addElement("Help");
- mbar=new menubar(left,right,100);
- mbar.set_w_constraint(std_function.offset(PARENT.W(), 0));
-
- /* file menu */
- file_menu=menu.create_text_menu(file,null,this);
-
- /* edit menu */
- edit_menu=menu.create_text_menu(edit,null,this);
-
- /* help menu */
- help_menu=menu.create_text_menu(help,null,this);
-
- mbar.associate_menu("File",file_menu);
- mbar.associate_menu("Edit",edit_menu);
- mbar.associate_menu("Help",help_menu);
-
- pop_parent.add_child(mbar);
-
- /*
- * vert scrollbar
- */
- vs=new v_scrollbar(10,35,275,0,100,20,0.25,10,25,null);
- /*
- *button with text
- */
- b=new button(0,0,"Test Button",null);
- dhc1=new display_help_container(b,"This is some help text");
- dhc1.set_x(30);
- dhc1.set_y(35);
- /*
- * scale
- */
- sc=new scale(0,0,200,0,100,10,25,null);
- dhc3=new display_help_container(sc,"You can put display help on any object!");
- dhc3.set_x(30);
- dhc3.set_y(130);
- /*
- * text toggle collection of radio buttons
- */
- c1=new text_toggle_collection(radio_stations,true,60,this);
- c1.set_x(30);
- c1.set_y(160);
- /* set the first object to be on */
- c1.nth_toggle(0).set_cur_state(1);
-
- /*
- * next toggle collection (checkboxes)
- */
- c2=new text_toggle_collection(choices,false,80,null);
- c2.set_x(30);
- c2.set_y(220);
-
- pop_parent.add_child(vs);
- pop_parent.add_child(dhc1);
- pop_parent.add_child(dhc3);
- pop_parent.add_child(c1);
- pop_parent.add_child(c2);
-
- try {
- loaded_version=manager.load_doc_image(this,"images/constrct.gif");
- } catch (java.net.MalformedURLException e) {
- showStatus("Problem loading the gif file");
- return;
- }
- // make the new button and position it
- logo=new button(loaded_version,null);
- dhc2=new display_help_container(logo,"More help text from this one!");
- dhc2.set_x(30);
- dhc2.set_y(70);
- pop_parent.add_child(dhc2);
- /*
- * horizontal scrollbar
- */
- hs=new h_scrollbar(10,320,300,0,100,20,0.25,10,25,null);
- pop_parent.add_child(hs);
-
- /*
- * build the menus ... submenu first
- */
- version_menu=menu.create_text_menu(version,null,null);
-
-
- /*
- * make the main menu
- */
- /* find out the largest one */
- max=text_menu_item.max_item_width(toolkit,null);
- /* make the menu */
- toolkit_menu=new menu();
- /* loop over the strings */
- for (i=0; i<toolkit.length; ++i) {
- if (i!=2) {
- toolkit_menu.add_child(new text_menu_item(toolkit[i],max));
- } else {
- toolkit_menu.add_child(new pullright_menu_item(toolkit[i],
- null,max,
- version_menu));
- }
- }
- /*
- * put the menu button in there
- */
- mb=new menu_button("Toolkits",toolkit_menu);
- mb.set_x(140);
- mb.set_y(160);
- pop_parent.add_child(mb);
- }
- /**
- * This is the callback for the changing of the radio stations
- * and reporting menu selections.
- */
- public void callback(
- interactor from_obj,
- event evt,
- int callback_num,
- Object callback_info) {
-
- interactor i;
- /* is it from the toggle?*/
- if (from_obj instanceof label_toggle) {
- label_toggle lt=(label_toggle)from_obj;
- station=lt.text();
- pop_parent.set_value(station);
- }
- /* is it from a menu */
- if (from_obj instanceof menu) {
- i=(interactor)callback_info;
- if (from_obj.equals(file_menu)) {
- System.out.println("File Menu: " + file_menu.find_child(i));
- }
- if (from_obj.equals(edit_menu)) {
- System.out.println("Edit Menu: " + edit_menu.find_child(i));
- }
- if (from_obj.equals(help_menu)) {
- System.out.println("Help Menu: " + help_menu.find_child(i));
- }
- }
- }
- }
- /**
- * This is a little parent class which can pop up a menu.
- */
- class popup_parent extends base_parent_interactor implements pressable {
- /**
- * Store the popup menu
- */
- menu popup;
- /**
- * This is where we keep all the strings in the menu, except the last one
- */
- String [] menu_items;
- /**
- * This is the current string to put last in the menu
- */
- String _value;
- /* make one of these puppies with a default string */
- public popup_parent(String s ) {
- super(0,0,10,10);
- _value=s;
- popup=new menu();
- menu_items=new String[5];
- menu_items[0]="Cut";
- menu_items[1]="Copy";
- menu_items[2]="Paste";
- menu_items[3]="Select All";
- }
- /**
- * Build the popup menu
- */
- public boolean press(event evt, Object not_used) {
- int max;
- top_level top=get_top_level();
- /* get the point of the mouse press and convert to global coords */
- Point p=new Point(evt.local_x(),evt.local_y());
- p=local_to_global(p);
-
- /* delete all of popup's old children, if any */
- while (popup.num_children()>0) {
- popup.remove_child(0);
- }
- /* setup the array with our value */
- menu_items[4]="Tuned to " + _value;
- max=text_menu_item.max_item_width(menu_items,null);
- for (int i=0; i<5; ++i) {
- popup.add_child(new text_menu_item(menu_items[i],max));
- }
- /* put this menu in the toplevel */
- top.add_child(popup);
- popup.set_visible(true);
- popup.set_x(p.x- (popup.w()/2));
- popup.set_y(p.y);
- /* force the coordinates to be in bounds */
- if (popup.x()<0) popup.set_x(0);
- if (popup.x()+ popup.w() > top.w()) {
- popup.set_x(top.w()-popup.w());
- }
- /* y can't be negative... so only consider the bottom */
- if (popup.y() + popup.h() > top.h()) {
- popup.set_y(top.h()-popup.h());
- }
- menu.agent().set_focus_to(popup,evt,null);
- return true;
- }
- /**
- * Set the value of the last menu item.
- */
- public void set_value(String s) {
- _value=s;
- }
- /**
- * This never gets called because we make something the
- * menu focus.
- */
- public boolean release(event evt, Object not_used) { return false;}
- }
- /*=========================== 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/
-
- ========================================================================*/
-