home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / TEST / DRAG_LIM.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  7.1 KB  |  239 lines

  1. /*
  2.  * $Id: drag_limit_test.java,v 1.15 1996/10/03 19:46:51 hudson Exp $
  3.  * $Author: hudson $
  4.  */
  5.  
  6. package sub_arctic.test;
  7.  
  8. import sub_arctic.lib.interactor;
  9. import sub_arctic.lib.interactor_applet;
  10. import sub_arctic.lib.manager;
  11. import sub_arctic.lib.interactor_consts;
  12. import sub_arctic.lib.top_level;
  13. import sub_arctic.lib.base_parent_interactor;
  14. import sub_arctic.lib.button;
  15. import sub_arctic.lib.drag_icon;
  16. import sub_arctic.lib.std;
  17. import sub_arctic.lib.backdrop;
  18. import sub_arctic.lib.line_display;
  19. import sub_arctic.lib.row;
  20. import sub_arctic.lib.text_toggle_collection;
  21. import sub_arctic.lib.toggle;
  22. import sub_arctic.lib.icon;
  23. import sub_arctic.input.std_drag_filters;
  24. import sub_arctic.input.event;
  25. import sub_arctic.input.callback_object;
  26. import sub_arctic.input.pressable;
  27. import sub_arctic.input.move_draggable;
  28. import sub_arctic.output.loaded_image;
  29. import sub_arctic.output.style;
  30. import sub_arctic.output.style_manager;
  31.  
  32. import java.awt.Point;
  33. import java.awt.Rectangle;
  34.  
  35. public class drag_limit_test extends interactor_applet 
  36. implements interactor_consts, callback_object {
  37.  
  38.   public static int setting = 0;
  39.  
  40.   /**
  41.    * Shorthand for generating a button's image in the default style.
  42.    */
  43.   public static loaded_image[] std_label(String s) {
  44.     style st=style_manager.current_style();
  45.     return st.button_make_images(s,style_manager.default_font(),10,5,false);
  46.   }
  47.  
  48.   public void callback(interactor from_obj, event evt, int cb_n, Object info)
  49.     {
  50.       int i = ((Integer)from_obj.user_info()).intValue();
  51.       System.out.println("setting = " + (i-1));
  52.       setting = i-1;
  53.     }
  54.  
  55.   public void build_ui(base_parent_interactor top) 
  56.     {
  57.       row       r;
  58.       String    labels[] = {
  59.     "\"Grab\" point", "Top-left", "Top-right", "Bottom-left", 
  60.     "Bottom-right", "Center"};
  61.  
  62.       r = new row(5, 5, true, false, row.CENTER_JUSTIFIED);
  63.       top.add_child(r);
  64.       r.add_child(new text_toggle_collection(labels, true, -1, this));
  65.       ((toggle)(r.child(0).child(1))).set_cur_state(1);
  66.  
  67.       base_parent_interactor p1 = new base_parent_interactor(10,10,380,380);
  68.       r.add_child(p1);
  69.       p1.add_child(new backdrop(400,400,std.stipple25()));
  70.  
  71.       loaded_image[] lab1 = std_label("Limited to parent less 10,20");
  72.       drag_icon_t1 drag = new drag_icon_t1(10,10,lab1[0]);
  73.       p1.add_child(drag);
  74.  
  75.       lab1 = std_label("Limited to rect 50,50:200x100");
  76.       drag_icon_t2 drag2 = new drag_icon_t2(60,60,lab1[0]);
  77.       p1.add_child(drag2);
  78.  
  79.       line_display ln = new line_display(50,50,250,50,0);
  80.       p1.add_child(ln);
  81.       ln = new line_display(50,50,50,150,0);
  82.       p1.add_child(ln);
  83.       ln = new line_display(250,50,250,150,0);
  84.       p1.add_child(ln);
  85.       ln = new line_display(50,150,250,150,0);
  86.       p1.add_child(ln);
  87.  
  88.       ln = new line_display(0,p1.h()-20,p1.w()-10,p1.h()-20,0);
  89.       p1.add_child(ln);
  90.  
  91.       ln = new line_display(p1.w()-10,0,p1.w()-10,p1.h()-20,0);
  92.       p1.add_child(ln);
  93.  
  94.       ln = new line_display(10,300,350,20,0);
  95.       p1.add_child(ln);
  96.  
  97.       lab1 = std_label("Limited to line");
  98.       drag_icon_t3 drag3 = new drag_icon_t3(10,300,lab1[0]);
  99.       p1.add_child(drag3);
  100.  
  101.       lab1 = std_label("w/ debug output (slow)");
  102.       drag_icon_t4 drag4 = new drag_icon_t4(200,10,lab1[0]);
  103.       p1.add_child(drag4);
  104.     }
  105. }
  106.  
  107. class drag_icon_t1 extends icon implements pressable, move_draggable {
  108.   public drag_icon_t1(int x, int y, loaded_image img) 
  109.     {super(x,y,img);}
  110.   public int drag_feature_point()
  111.     {
  112.       return drag_limit_test.setting;
  113.     }
  114.   public Point filter_pt(Point orig_pt, interactor drag_obj, Point f_pt)
  115.     {
  116.       return std_drag_filters.limit_to_parent(orig_pt,this,true,10,20, f_pt);
  117.     }
  118.   public boolean press(event evt, Object user_info)
  119.     {
  120.       manager.move_drag_focus.set_focus_to(this, evt, user_info);
  121.       return true;
  122.     }
  123.   public boolean release(event evt, Object user_info)
  124.     {
  125.       return true;
  126.     }
  127.   public boolean drag_start(
  128.     event evt, int xv, int yv, int gx, int gy, Object user_info)
  129.     { return true; }
  130.   public boolean drag_feedback(
  131.     event evt,
  132.     int x_pos, int y_pos,
  133.     int start_x, int start_y,
  134.     int grab_x, int grab_y,
  135.     Object user_info)
  136.     {
  137.       /* move our position */
  138.       set_pos(x_pos, y_pos);
  139.       return true;
  140.     }
  141.   public boolean drag_end(
  142.     event evt,
  143.     int x_pos, int y_pos,
  144.     int start_x, int start_y,
  145.     int grab_x, int grab_y,
  146.     Object user_info)
  147.     {
  148.       /* let drag_feedack to all the work */
  149.       return drag_feedback(evt, x_pos, y_pos, start_x, start_y, grab_x, grab_y,
  150.                                     user_info);
  151.     }
  152. }
  153.  
  154. class drag_icon_t2 extends drag_icon_t1 {
  155.   public drag_icon_t2(int x, int y, loaded_image img) 
  156.     {super(x,y,img);}
  157.   public static Rectangle r = new Rectangle(50,50, 200,100);
  158.   public Point filter_pt(Point orig_pt, interactor drag_obj, Point f_pt)
  159.     {
  160.       return std_drag_filters.limit_to_rect(orig_pt,r);
  161.     }
  162. }
  163.  
  164. class drag_icon_t3 extends drag_icon_t1 {
  165.   public drag_icon_t3(int x, int y, loaded_image img) 
  166.     {super(x,y,img);}
  167.   public Point filter_pt(Point orig_pt, interactor drag_obj, Point f_pt)
  168.     {
  169.       return std_drag_filters.limit_to_line_seg(orig_pt, 10, 300, 350,20);
  170.     }
  171. }
  172.  
  173. class drag_icon_t4 extends drag_icon_t1 {
  174.  
  175.   public drag_icon_t4(int x, int y, loaded_image img) 
  176.     {super(x,y,img);}
  177.  
  178.   public boolean drag_start(
  179.     event evt, 
  180.     int x, int y, 
  181.     int grab_x, int grab_y, 
  182.     Object user_info)
  183.     {
  184.       System.out.println("drag_start(evt, " +
  185.     "x="+ x + "," + "y=" + y + "," +
  186.     "grab_x="+ grab_x + "," + "grab_y=" + grab_y + "," +
  187.     "user_info");
  188.       return super.drag_start(evt,x,y,grab_x,grab_y,user_info);
  189.     }
  190.  
  191.   public boolean drag_feedback(
  192.     event evt,     
  193.     int x, int y, 
  194.     int start_x, int start_y, 
  195.     int grab_x, int grab_y, 
  196.     Object user_info)
  197.     {
  198.       System.out.println("drag_feedback(evt, " +
  199.     "x="+ x + "," + "y=" + y + "," +
  200.     "start_x="+ start_x + "," + "start_y=" + start_y + "," +
  201.     "grab_x="+ grab_x + "," + "grab_y=" + grab_y + "," +
  202.     "user_info");
  203.       return 
  204.       super.drag_feedback(evt,x,y,start_x,start_y,grab_x,grab_y,user_info);
  205.     }
  206.  
  207.   public boolean drag_end(
  208.     event evt,     
  209.     int x, int y, 
  210.     int start_x, int start_y, 
  211.     int grab_x, int grab_y, 
  212.     Object user_info)
  213.     {
  214.       System.out.println("drag_end(evt, " +
  215.     "x="+ x + "," + "y=" + y + "," +
  216.     "start_x="+ start_x + "," + "start_y=" + start_y + "," +
  217.     "grab_x="+ grab_x + "," + "grab_y=" + grab_y + "," +
  218.     "user_info");
  219.       return super.drag_end(evt,x,y,start_x,start_y,grab_x,grab_y,user_info);
  220.     }
  221. }
  222.  
  223. /*=========================== COPYRIGHT NOTICE ===========================
  224.  
  225. This file is part of the subArctic user interface toolkit.
  226.  
  227. Copyright (c) 1996 Scott Hudson and Ian Smith
  228. All rights reserved.
  229.  
  230. The subArctic system is freely available for most uses under the terms
  231. and conditions described in 
  232.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  233. and appearing in full in the lib/interactor.java source file.
  234.  
  235. The current release and additional information about this software can be 
  236. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  237.  
  238. ========================================================================*/
  239.