1 31 package org.objectweb.proactive.examples.c3d; 32 33 import java.awt.Button ; 34 import java.awt.Canvas ; 35 import java.awt.Color ; 36 import java.awt.Dialog ; 37 import java.awt.Dimension ; 38 import java.awt.Font ; 39 import java.awt.Frame ; 40 import java.awt.Graphics ; 41 import java.awt.GridBagConstraints ; 42 import java.awt.GridBagLayout ; 43 import java.awt.GridLayout ; 44 import java.awt.Image ; 45 import java.awt.Insets ; 46 import java.awt.Label ; 47 import java.awt.List ; 48 import java.awt.Menu ; 49 import java.awt.MenuBar ; 50 import java.awt.MenuItem ; 51 import java.awt.Panel ; 52 import java.awt.TextArea ; 53 import java.awt.TextField ; 54 import java.awt.event.ActionEvent ; 55 import java.awt.event.ActionListener ; 56 import java.awt.event.ItemEvent ; 57 import java.awt.event.ItemListener ; 58 import java.awt.event.MouseEvent ; 59 import java.awt.event.MouseListener ; 60 import java.awt.event.WindowAdapter ; 61 import java.awt.event.WindowEvent ; 62 import java.awt.image.MemoryImageSource ; 63 import java.net.InetAddress ; 64 import java.net.UnknownHostException ; 65 import java.util.Hashtable ; 66 67 import org.apache.log4j.Logger; 68 import org.objectweb.proactive.ProActive; 69 import org.objectweb.proactive.core.config.ProActiveConfiguration; 70 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; 71 import org.objectweb.proactive.core.descriptor.data.VirtualNode; 72 import org.objectweb.proactive.core.node.Node; 73 import org.objectweb.proactive.core.node.NodeException; 74 import org.objectweb.proactive.examples.c3d.geom.Vec; 75 import org.objectweb.proactive.examples.c3d.prim.Light; 76 import org.objectweb.proactive.examples.c3d.prim.Primitive; 77 import org.objectweb.proactive.examples.c3d.prim.Sphere; 78 import org.objectweb.proactive.ext.migration.MigrationStrategyManagerImpl; 79 80 public class C3DUser implements org.objectweb.proactive.RunActive, java.io.Serializable { 81 82 static Logger logger = Logger.getLogger(C3DUser.class.getName()); 83 84 private MigrationStrategyManagerImpl myStrategyManager; 85 private boolean onMigration; 86 private String dispatcher_host; 87 88 protected VirtualNode vnDispatcher; 89 92 private final boolean ACTIVE = true; 93 private C3DUser me; 94 97 private MyDialog about; 98 102 TextArea ta_log; 103 106 TextArea ta_mess; 107 110 Label l_user; 111 114 Label l_c3ddispatcher; 115 118 final int i_height = 270; 119 122 final int i_width = 270; 123 127 transient MemoryImageSource mis; 128 131 transient int pix[]; 132 137 C3DDispatcher c3ddispatcher; 138 143 144 149 private Hashtable h_users = new Hashtable (); 150 153 private transient List li_users; 154 157 private int talkId = -1; 158 161 private static Vec color[] = { 162 new Vec(1, 1, 1), new Vec(0, 0, 0.5), new Vec(0, 0.5, 0), new Vec(0.5, 0, 0), new Vec(1, 0.6, 0), new Vec(1, 0.7, 0.8), new Vec(0.8, 0.8, 1) }; 171 172 173 175 178 public int nRotate = 0; 179 public transient UserFrame userframe; 180 boolean b_isApplet; 181 boolean b_isBot; 182 String botUrl; 183 String s_username; 184 int i_user; 185 186 187 public C3DUser() { 188 } 189 190 191 public C3DUser(Boolean b_isApplet, Boolean b_isBot, String url) { 192 this.b_isApplet = b_isApplet.booleanValue(); 193 this.b_isBot = b_isBot.booleanValue(); 194 this.botUrl = url; 195 this.onMigration = false; 196 } 197 198 199 public void go(ProActiveDescriptor pad) { 200 201 202 me = (C3DUser)org.objectweb.proactive.ProActive.getStubOnThis(); 203 204 vnDispatcher = pad.getVirtualNode("Dispatcher"); 206 userframe = new UserFrame(me); 207 userframe.createWelcomePanel(); 208 209 setOnMigration(true); 210 } 211 212 public void rebuild(){ 213 me = (C3DUser)org.objectweb.proactive.ProActive.getStubOnThis(); 214 userframe = new UserFrame(me); 215 userframe.createPanelAfterMigration(dispatcher_host,s_username); 216 } 217 218 public void clean(){ 219 if (userframe != null){ 220 userframe.dispose(); 221 userframe = null; 222 } 223 } 224 225 public void setOnMigration(boolean value){ 226 this.onMigration = value; 227 } 228 229 public boolean getOnMigration(){ 230 return this.onMigration; 231 } 232 233 public void runActivity(org.objectweb.proactive.Body body) { 234 logger.info("Starting custom live in C3DUser"); 235 org.objectweb.proactive.Service service = new org.objectweb.proactive.Service(body); 237 myStrategyManager = new MigrationStrategyManagerImpl((org.objectweb.proactive.core.body.migration.Migratable) body); 238 myStrategyManager.onDeparture("clean"); 239 if(getOnMigration()) { 240 rebuild(); 244 245 } 246 247 248 service.fifoServing(); 252 253 254 if(getOnMigration()) clean(); 255 258 } 259 260 261 262 265 public static void main(String argv[]) throws NodeException{ 266 267 ProActiveDescriptor proActiveDescriptor = null; 268 269 ProActiveConfiguration.load(); 270 try 271 { 272 proActiveDescriptor = 273 ProActive.getProactiveDescriptor( 274 "file:"+argv[0]); 275 proActiveDescriptor.activateMappings(); 276 277 } 278 catch (Exception e) 279 { 280 e.printStackTrace(); 281 logger.fatal("Pb in main"); 282 } 283 284 VirtualNode user = 285 proActiveDescriptor.getVirtualNode("User"); 286 287 Node node = user.getNode(); 288 Object params[] = { new Boolean (false),new Boolean (false), ""}; 289 try { 290 291 C3DUser c3duser = (C3DUser)org.objectweb.proactive.ProActive.newActive("org.objectweb.proactive.examples.c3d.C3DUser", params, node.getNodeInformation().getURL()); 292 293 c3duser.go(proActiveDescriptor); 294 } catch (Exception e) { 295 e.printStackTrace(); 296 } 297 } 298 299 300 public void log(String s_message) { 301 ta_log.append(s_message + "\n"); 302 } 303 304 305 public void message(String s_message) { 306 ta_mess.append(s_message + "\n"); 307 } 308 309 310 public UserFrame getUserFrame() { 311 return userframe; 312 } 313 314 315 323 public void informNewUser(int nUser, String sName) { 324 li_users.add(sName); 325 h_users.put(sName, new Integer (nUser)); 326 } 327 328 329 335 public void informUserLeft(String sName) { 336 337 try { 339 li_users.remove(sName); 340 } catch (Exception e) { 341 e.printStackTrace(); 342 } 343 344 h_users.remove(sName); 346 347 if (h_users.isEmpty()) { 348 talkId = -1; 349 li_users.select(0); 350 } 351 } 352 354 358 public int ping() { 359 return 0; 360 } 361 362 363 367 private Scene createScene() { 368 int x = 0; 369 int y = 0; 370 371 Scene scene = new Scene(); 372 373 374 Primitive p = new Sphere(new Vec(10, -5.77, 0), 7); 375 p.setColor(1.0, 0.0, 0.0); 376 p.surf.shine = 14.0; 377 p.surf.kd = 0.7; 378 p.surf.ks = 0.3; 379 p.surf.ior = 0.3; 380 scene.addObject(p); 381 382 p = new Sphere(new Vec(0, 11.55, 0), 7); 383 p.setColor(0.0, 1.0, 0.0); 384 p.surf.shine = 14.0; 385 p.surf.kd = 0.7; 386 p.surf.ks = 0.3; 387 scene.addObject(p); 388 389 p = new Sphere(new Vec(-10, -5.77, 0), 7); 390 p.setColor(0.0, 0.0, 1.0); 391 p.surf.shine = 14.0; 392 p.surf.kd = 0.7; 393 p.surf.ks = 0.3; 394 scene.addObject(p); 395 396 433 434 scene.addLight(new Light(100, 100, -50, 1.0)); 435 scene.addLight(new Light(-100, 100, -50, 1.0)); 436 scene.addLight(new Light(100, -100, -50, 1.0)); 437 441 442 View v = new View(); 443 v.from = new Vec(x, y, -30); 445 v.at = new Vec(x, y, -15); 447 v.up = new Vec(0, 1, 0); 448 v.angle = 35.0 * 3.14159265 / 180.0; 449 v.aspect = 1.0; 450 v.dist = 1.0; 451 scene.addView(v); 452 453 return scene; 454 } 455 456 457 462 public void setPixels(int[] newpix, Interval interval) { 463 int from = interval.width * interval.yfrom; 464 465 466 System.arraycopy(newpix, 0, pix, from, newpix.length); 467 468 469 mis.newPixels(0, interval.yfrom, interval.width, interval.yto); 470 471 472 userframe.repaint(); 473 } 474 475 476 481 public void showMessage(String message) { 482 ta_log.append(message + "\n"); 483 if (b_isBot) { 484 if (message.substring(0, 3).compareTo("All") == 0) { 486 if (nRotate < 15) { 488 nRotate++; 489 c3ddispatcher.rotateLeft(i_user); 490 } else { 491 c3ddispatcher.doBenchmarks(); 492 exit(); 493 } 494 } 495 } 496 } 497 498 499 public void showUserMessage(String message) { 500 ta_mess.append(message + '\n'); 501 } 502 503 504 public void dialogMessage(String title, String content) { 505 MsgDialog md = new MsgDialog(userframe, title, content); 506 md.setVisible(true); 507 } 508 509 510 514 515 public Integer getWidth() { 516 return new Integer (i_width); 518 } 519 520 521 525 public Integer getHeight() { 526 return new Integer (i_height); 527 } 528 529 530 533 534 void exit() { 535 try { 536 c3ddispatcher.unregisterConsumer(i_user); 537 userframe.setVisible(false); 538 userframe.dispose(); 539 userframe = null; 540 me.terminate(); 541 542 } catch (NullPointerException ex) { 543 ex.printStackTrace(); 544 } 545 } 550 551 552 private void trace(String s_message) { 553 logger.info("C3DUser: " + s_message); 554 } 555 556 557 public void terminate(){ 558 org.objectweb.proactive.ProActive.getBodyOnThis().terminate(); 559 } 560 561 public class UserFrame extends Frame implements ActionListener , ItemListener { 562 563 566 567 private Button b_up = new EqualButton("Up"); 568 571 private Button b_down = new EqualButton("Down"); 572 575 private Button b_left = new EqualButton("Left"); 576 579 private Button b_right = new EqualButton("Right"); 580 583 private Button b_clock = new EqualButton("Spin right"); 584 587 private Button b_unclock = new EqualButton("Spin left"); 588 591 private Button b_exit = new EqualButton("Exit"); 592 595 private Button b_addSphere = new Button ("Add random sphere"); 596 599 private Button b_connect = new EqualButton("Connect"); 600 603 private Button b_reset = new EqualButton("Reset"); 604 607 private Button b_send = new Button ("Send"); 608 private TextField tf_mess, tf_name, tf_host; 609 private GridBagLayout gridbag = new GridBagLayout ();; 610 private GridBagConstraints c = new GridBagConstraints (); 611 private String s_localhost; 612 private C3DUser c3duser; 613 private MenuItem mi_exit, mi_clear, mi_list,mi_about; 614 private Font f_standard = new Font ("SansSerif", Font.PLAIN, 12); 615 private int i_top; 616 private MenuBar mb; 617 618 619 624 public UserFrame(C3DUser c3d) { 625 super("Collaborative 3D Environment - User Window"); 626 setBackground(Color.lightGray); 627 setLayout(gridbag); 628 setFont(f_standard); 629 addWindowListener(new MyWindowListener()); 630 c3duser = c3d; 631 632 s_localhost = ""; 633 try { 634 s_localhost = InetAddress.getLocalHost().getCanonicalHostName(); 635 } catch (UnknownHostException e) { 636 s_localhost = "unknown!"; 637 } 638 } 639 640 public UserFrame(C3DUser c3d, boolean value) { 641 super("Collaborative 3D Environment - User Window"); 642 setBackground(Color.lightGray); 643 setLayout(gridbag); 644 setFont(f_standard); 645 addWindowListener(new MyWindowListener()); 646 c3duser = c3d; 647 s_localhost = ""; 648 try { 649 s_localhost = InetAddress.getLocalHost().getCanonicalHostName(); 650 } catch (UnknownHostException e) { 651 s_localhost = "unknown!"; 652 } 653 654 } 655 656 public Button getB_up() { 657 return b_up; 658 } 659 660 661 public Button getB_down() { 662 return b_down; 663 } 664 665 666 public Button getB_left() { 667 return b_left; 668 } 669 670 671 public Button getB_right() { 672 return b_right; 673 } 674 675 676 public Button getB_clock() { 677 return b_clock; 678 } 679 680 681 public Button getB_unclock() { 682 return b_unclock; 683 } 684 685 686 689 public void createBot(String url) { 690 s_username = "Benchmarking bot"; 691 } 693 694 695 private void createWelcomePanel() { 696 Label l1 = new Label ("Welcome to the Collaborative 3D Environment -", Label.CENTER); 697 c.insets = new Insets (5, 5, 0, 5); 698 c.gridwidth = GridBagConstraints.REMAINDER; 699 c.weightx = 1.0; 700 gridbag.setConstraints(l1, c); 701 add(l1); 702 703 Label l2 = new Label ("a Java// test application", Label.CENTER); 704 c.insets = new Insets (0, 5, 0, 5); 705 gridbag.setConstraints(l2, c); 706 add(l2); 707 708 Label l3 = new Label ("Please enter your name and the host of the C3DDispatcher.", Label.CENTER); 709 c.insets = new Insets (15, 5, 10, 5); 710 gridbag.setConstraints(l3, c); 711 add(l3); 712 713 Label l4 = new Label ("Name:", Label.RIGHT); 714 Label l5 = new Label ("Host:", Label.RIGHT); 715 c.insets = new Insets (5, 5, 5, 0); 716 c.gridwidth = 1; 717 c.anchor = GridBagConstraints.EAST; 718 gridbag.setConstraints(l4, c); 719 gridbag.setConstraints(l5, c); 720 721 tf_name = new TextField (20); 722 tf_name.addActionListener(this); 723 724 tf_host = new TextField (s_localhost, 20); 725 tf_host.addActionListener(this); 726 c.insets = new Insets (5, 0, 5, 5); 727 c.anchor = GridBagConstraints.CENTER; 728 c.gridwidth = GridBagConstraints.REMAINDER; 729 gridbag.setConstraints(tf_name, c); 730 gridbag.setConstraints(tf_host, c); 731 732 add(l4); 733 add(tf_name); 734 add(l5); 735 add(tf_host); 736 737 c.gridwidth = GridBagConstraints.RELATIVE; 738 c.insets = new Insets (15, 5, 10, 5); 739 c.anchor = GridBagConstraints.EAST; 740 gridbag.setConstraints(b_connect, c); 741 b_connect.addActionListener(this); 742 add(b_connect); 743 c.gridwidth = GridBagConstraints.REMAINDER; 744 c.anchor = GridBagConstraints.CENTER; 745 gridbag.setConstraints(b_exit, c); 746 b_exit.addActionListener(this); 747 add(b_exit); 748 749 pack(); 750 setVisible(true); 751 toFront(); 752 } 753 754 public void createPanel(String s_host,String s_name){ 755 setVisible(false); 756 removeAll(); 757 758 mb = new MenuBar (); 759 Menu m_file = new Menu ("File", false); 760 m_file.setFont(f_standard); 761 mi_exit = new MenuItem ("Exit"); 762 mi_clear = new MenuItem ("Clear log"); 763 mi_list = new MenuItem ("List users"); 764 mi_clear.setFont(f_standard); 765 mi_exit.setFont(f_standard); 766 mi_list.setFont(f_standard); 767 mi_exit.addActionListener(this); 768 mi_clear.addActionListener(this); 769 mi_list.addActionListener(this); 770 m_file.add(mi_list); 771 m_file.add(mi_clear); 772 m_file.addSeparator(); 773 m_file.add(mi_exit); 774 mb.add(m_file); 775 776 Menu m_c3d = new Menu ("C3D ProActive PDC", false); 777 mi_about = new MenuItem ("About ProActive PDC"); 778 mi_about.setFont(f_standard); 779 mi_about.addActionListener(this); 780 m_c3d.add(mi_about); 781 782 mb.setHelpMenu(m_c3d); 783 setMenuBar(mb); 784 785 786 pix = new int[i_width * i_height]; 787 788 789 mis = new MemoryImageSource (i_width, i_height, pix, 0, i_width); 790 791 792 mis.setAnimated(true); 793 794 798 Panel p_image = new Panel (new GridLayout (1, 1)); 799 801 c.insets = new Insets (5, 5, 0, 5); 803 804 c.gridx = 0; 806 c.gridy = 0; 807 c.weightx = 1; 808 c.weighty = 1; 809 810 c.gridwidth = 1; 812 c.gridheight = 1; 813 814 c.fill = GridBagConstraints.BOTH; 817 gridbag.setConstraints(p_image, c); 818 p_image.add(new MyImageContainer(createImage(mis), i_width, i_height, p_image)); 820 add(p_image); 821 822 825 826 Panel p_log = new Panel (); 828 829 c.gridx = 1; 831 gridbag.setConstraints(p_log, c); 832 add(p_log); 833 834 GridBagLayout gb_panel = new GridBagLayout (); 836 p_log.setLayout(gb_panel); 837 838 l_user = new Label ("User " + s_name, Label.CENTER); 840 l_user.setFont(new Font ("SansSerif", Font.ITALIC + Font.BOLD, 18)); 841 842 GridBagConstraints pc = new GridBagConstraints (); 843 844 pc.fill = GridBagConstraints.BOTH; 845 pc.insets = new Insets (5, 5, 0, 5); 846 pc.gridx = 0; 847 pc.gridy = 0; 848 pc.weightx = 1; 849 pc.weighty = 1; 850 pc.gridwidth = GridBagConstraints.REMAINDER; 851 gb_panel.setConstraints(l_user, pc); 852 p_log.add(l_user); 853 854 Label l_machine = new Label ("Local host: " + s_localhost + " (" + System.getProperty("os.name") + " " + System.getProperty("os.version") + ")"); 856 857 pc.gridy = 1; 859 gb_panel.setConstraints(l_machine, pc); 860 p_log.add(l_machine); 861 862 863 l_c3ddispatcher = new Label ("C3DDispatcher host: " + s_host); 865 pc.gridy = 2; 866 gb_panel.setConstraints(l_c3ddispatcher, pc); 867 p_log.add(l_c3ddispatcher); 868 869 pc.gridy = 3; 871 pc.weighty = 2; 872 ta_log = new TextArea (5, 25); 873 ta_log.setEditable(false); 874 gb_panel.setConstraints(ta_log, pc); 875 p_log.add(ta_log); 876 877 878 881 882 Panel p_input = new Panel (); 884 885 GridBagLayout gb_input = new GridBagLayout (); 886 p_input.setLayout(gb_input); 887 888 c.gridx = 0; 889 c.gridy = 1; 890 c.gridwidth = 1; 891 892 gridbag.setConstraints(p_input, c); 893 add(p_input); 894 895 896 pc.gridy = 0; 899 pc.gridx = 0; 900 pc.gridwidth = 1; 901 pc.fill = GridBagConstraints.NONE; 902 903 gb_input.setConstraints(b_unclock, pc); 904 b_unclock.addActionListener(this); 905 p_input.add(b_unclock); 906 907 908 pc.gridx = 2; 910 gb_input.setConstraints(b_clock, pc); 911 b_clock.addActionListener(this); 912 p_input.add(b_clock); 913 914 pc.gridy = 0; 916 pc.gridx = 1; 917 gb_input.setConstraints(b_up, pc); 918 b_up.addActionListener(this); 919 p_input.add(b_up); 920 921 922 pc.gridx = 1; 924 pc.gridy = 2; 925 gb_input.setConstraints(b_down, pc); 926 b_down.addActionListener(this); 927 p_input.add(b_down); 928 929 pc.gridx = 0; 931 pc.gridy = 1; 932 b_left.addActionListener(this); 933 gb_input.setConstraints(b_left, pc); 934 p_input.add(b_left); 935 936 pc.gridx = 2; 938 gb_input.setConstraints(b_right, pc); 939 b_right.addActionListener(this); 940 p_input.add(b_right); 941 942 943 c.gridheight = 1; 947 c.gridx = 1; 948 c.fill = GridBagConstraints.NONE; 949 950 gridbag.setConstraints(b_addSphere, c); 951 b_addSphere.addActionListener(this); 952 add(b_addSphere); 953 954 c.gridx = 2; 957 c.gridy = 1; 958 c.fill = GridBagConstraints.NONE; 959 960 gridbag.setConstraints(b_reset, c); 961 b_reset.addActionListener(this); 962 add(b_reset); 963 964 965 966 969 Panel p_mess = new Panel (); 970 971 c.insets = new Insets (10, 10, 10, 10); 972 c.gridx = 0; 973 c.gridy = 2; 974 c.gridwidth = GridBagConstraints.REMAINDER; 975 c.fill = GridBagConstraints.BOTH; 976 gridbag.setConstraints(p_mess, c); 977 add(p_mess); 978 979 GridBagLayout g_mess = new GridBagLayout (); 980 p_mess.setLayout(g_mess); 981 982 li_users = new List (5, false); 984 li_users.add("~BROADCAST~"); 985 li_users.select(0); 986 li_users.addItemListener(this); 987 988 pc.insets = new Insets (5, 5, 5, 5); 989 pc.gridx = 0; 991 pc.gridy = 0; 992 pc.fill = GridBagConstraints.BOTH; 993 pc.gridwidth = GridBagConstraints.RELATIVE; 994 g_mess.setConstraints(li_users, pc); 995 p_mess.add(li_users); 996 997 ta_mess = new TextArea (5, 30); 999 ta_mess.setEditable(false); 1000 pc.gridwidth = GridBagConstraints.REMAINDER; 1001 pc.gridx = 1; 1002 g_mess.setConstraints(ta_mess, pc); 1003 p_mess.add(ta_mess); 1004 1005 1007 Panel p_msg = new Panel (); 1008 GridBagLayout g_msg = new GridBagLayout (); 1009 pc = new GridBagConstraints (); 1010 p_msg.setLayout(g_msg); 1011 c.gridy = 3; 1012 gridbag.setConstraints(p_msg, c); 1013 add(p_msg); 1014 1015 pc.gridx = 0; 1017 pc.gridy = 0; 1018 pc.fill = GridBagConstraints.NONE; 1019 Label l_mess = new Label ("SpyEvent:"); 1020 g_msg.setConstraints(l_mess, pc); 1021 p_msg.add(l_mess); 1022 1023 tf_mess = new TextField (); 1025 tf_mess.addActionListener(this); 1026 pc.weightx = 1.0; 1027 pc.gridwidth = GridBagConstraints.RELATIVE; 1028 pc.fill = GridBagConstraints.BOTH; 1029 pc.gridx = 1; 1030 g_msg.setConstraints(tf_mess, pc); 1031 p_msg.add(tf_mess); 1032 1033 pc.weightx = 0.0; 1035 pc.gridwidth = GridBagConstraints.REMAINDER; 1036 b_send.addActionListener(this); 1037 pc.fill = GridBagConstraints.NONE; 1038 pc.gridx = 2; 1039 g_msg.setConstraints(b_send, pc); 1040 p_msg.add(b_send); 1041 1042 pack(); 1043 setVisible(true); 1044 toFront(); 1045 1046 } 1047 public void createFinalPanel(String s_host, String s_name){ 1048 createPanel(s_host,s_name); 1049 1050 try { 1051 vnDispatcher.setRuntimeInformations("LOOKUP_HOST",s_host); 1052 c3ddispatcher = (C3DDispatcher)vnDispatcher.getUniqueAO(); 1053 i_user = c3ddispatcher.registerConsumer(me, createScene(), s_name); 1054 l_c3ddispatcher.setText(l_c3ddispatcher.getText() + " (" + c3ddispatcher.getOSString() + ")"); 1055 } catch (Exception ex) { 1056 log("Exception caught: " + ex); 1057 ex.printStackTrace(); 1058 log("Error: C3DDispatcher not found, try to reconnect"); 1059 } 1060 } 1061 1062 public void createPanelAfterMigration(String s_host, String s_name){ 1063 createPanel(s_host,s_name); 1064 1065 c3ddispatcher.registerMigratedUser(i_user); 1066 l_c3ddispatcher.setText(l_c3ddispatcher.getText() + " (" + c3ddispatcher.getOSString() + ")"); 1068 } 1070 1071 1072 1075 public void actionPerformed(ActionEvent e) { 1076 Object source = e.getSource(); 1077 if (source == b_left) { 1078 1079 if (c3ddispatcher != null) { 1080 c3ddispatcher.rotateLeft(i_user); 1082 } 1083 } else if (source == b_right) { 1084 1085 if (c3ddispatcher != null) { 1086 c3ddispatcher.rotateRight(i_user); 1088 } 1089 } else if (source == b_up) { 1090 if (c3ddispatcher != null) { 1092 c3ddispatcher.rotateUp(i_user); 1094 } 1095 } else if (source == b_down) { 1096 if (c3ddispatcher != null) { 1098 c3ddispatcher.rotateDown(i_user); 1100 } 1101 } else if (source == b_clock) { 1102 if (c3ddispatcher != null) { 1104 c3ddispatcher.spinClock(i_user); 1106 } 1107 } else if (source == b_unclock) { 1108 if (c3ddispatcher != null) { 1110 c3ddispatcher.spinUnclock(i_user); 1112 } 1113 } else if ((source == mi_exit) || (source == b_exit)) { 1114 1115 setVisible(false); 1116 exit(); 1117 } else if (source == tf_mess || source == b_send) { 1118 if (c3ddispatcher != null) { 1119 String s_mess = tf_mess.getText(); 1121 if (s_mess.length() > 0) { 1122 if (talkId == -1) { 1123 ta_mess.append("<to all> " + s_mess + '\n'); 1125 c3ddispatcher.showUserMessageExcept(i_user, "[from " + s_username + "] " + s_mess); 1126 } else { 1127 ta_mess.append("<to " + li_users.getSelectedItem() + "> " + s_mess + '\n'); 1129 c3ddispatcher.showUserMessage(talkId, "[Private from " + s_username + "] " + s_mess); 1130 } 1131 tf_mess.setText(""); 1132 } else { 1133 tf_mess.setText("Enter text to send"); 1134 tf_mess.selectAll(); 1135 } 1136 } 1137 } else if (source == b_connect || source == tf_name || source == tf_host) { 1138 1139 String s_name = tf_name.getText(); 1140 String s_host = tf_host.getText(); 1141 if (s_name.length() < 1) 1142 tf_name.setText("Enter your name"); 1143 if (s_host.length() < 1) 1144 tf_host.setText("Enter dispatcher host"); 1145 if ((s_name.length() > 0) && (s_host.length() > 0)) { 1146 s_username = s_name; 1147 dispatcher_host = s_host; 1148 1149 createFinalPanel(s_host, s_name); 1150 } 1151 } else if (source == mi_clear) { 1152 ta_log.setText(""); 1153 } else if (source == mi_list) { 1154 try { 1155 log("List of current users:"); 1156 log(c3ddispatcher.getUserList()); 1157 } catch (Exception ex) { 1158 ex.printStackTrace(); 1159 } 1160 } else if (source == b_addSphere) { 1161 1162 1163 double x,y,z,r; 1165 x = (Math.random() - 0.5) * 20.0; 1166 y = (Math.random() - 0.5) * 20.0; 1167 z = (Math.random() - 0.5) * 20.0; 1168 r = (Math.random()) * 10.0; 1169 1170 Sphere sphere = new Sphere(new Vec(x, y, z), r); 1171 1172 sphere.surf.color = (color[Math.round((float)(Math.random() * (color.length - 1)))]); 1178 1179 sphere.surf.kd = Math.random(); 1181 sphere.surf.ks = Math.random(); 1182 sphere.surf.shine = Math.random() * 20.0; 1183 1186 c3ddispatcher.addSphere(sphere); 1187 } else if (source == mi_about) { 1188 new MyDialog(this); 1189 } else if (source == b_reset) { 1190 c3ddispatcher.resetScene(createScene()); 1191 } 1192 } 1193 1194 1195 1200 public void itemStateChanged(ItemEvent it) { 1201 if (li_users.getSelectedIndex() == 0) 1202 talkId = -1; 1203 else 1204 talkId = ((Integer )h_users.get(li_users.getSelectedItem())).intValue(); 1205 } 1206 1207 1208 public void paint(Graphics g) { 1209 update(g); 1210 } 1211 1212 1213 public void update(Graphics g) { 1214 i_top = this.getInsets().top; 1215 g.setColor(Color.gray); 1216 g.drawLine(0, i_top - 1, 2000, i_top - 1); 1217 g.setColor(Color.white); 1218 g.drawLine(0, i_top, 2000, i_top); 1219 } 1220 1221 1222 1225 class MyWindowListener extends WindowAdapter implements java.io.Serializable { 1226 1227 public void windowClosing(WindowEvent e) { 1228 setVisible(false); 1229 exit(); 1230 } 1231 1232 1233 public void windowOpened(WindowEvent e) { 1234 if (b_isBot) { 1235 s_username = "Benchmarking bot"; 1236 createFinalPanel(botUrl, s_username); 1237 } 1238 } 1239 } 1240 } 1241 1242 1245 class MyDialog extends Dialog implements ActionListener , MouseListener , java.io.Serializable { 1246 1247 private Label d_title = new Label ("ProActive PDC", Label.CENTER); 1248 private Label d_url = new Label ("http://www.inria.fr/proactive/", Label.CENTER); 1249 1252 private Button b_ok = new Button ("OK"); 1253 1254 1255 public MyDialog(UserFrame parent) { 1256 super(parent, "About ProActive PDC", true); 1257 1258 GridBagLayout gb = new GridBagLayout (); 1260 GridBagConstraints c = new GridBagConstraints (); 1261 1262 setLayout(gb); 1263 1264 c.gridy = 0; 1266 c.fill = GridBagConstraints.HORIZONTAL; 1267 gb.setConstraints(d_title, c); 1268 d_title.setForeground(Color.blue); 1269 d_title.setFont(new Font ("arial", Font.BOLD | Font.ITALIC, 16)); 1270 add(d_title); 1271 1272 c.gridy = 1; 1274 gb.setConstraints(d_url, c); 1275 d_url.addMouseListener(this); 1276 add(d_url); 1277 1278 1279 1280 c.gridy = 2; 1282 c.fill = GridBagConstraints.NONE; 1283 gb.setConstraints(b_ok, c); 1284 b_ok.addActionListener(this); 1285 add(b_ok); 1286 1287 pack(); 1288 1289 setLocation(400, 200); 1290 setSize(200, 200); 1291 setVisible(true); 1292 toFront(); 1293 } 1294 1295 1296 public void mouseClicked(MouseEvent e) { 1297 1306 } 1307 1308 1309 public void mouseReleased(MouseEvent e) { 1310 } 1311 1312 1313 public void mouseEntered(MouseEvent e) { 1314 } 1315 1316 1317 public void mouseExited(MouseEvent e) { 1318 } 1319 1320 1321 public void mousePressed(MouseEvent e) { 1322 } 1323 1324 1325 public void actionPerformed(ActionEvent e) { 1326 setVisible(false); 1327 dispose(); 1328 } 1329 } 1330} 1331 1332 1337class MyImageContainer extends Canvas implements java.io.Serializable { 1338 1339 private Image img, scaled_img; 1340 private int minwidth, minheight; 1341 private Insets insets; 1342 private Panel p; 1343 1344 1345 public MyImageContainer(Image img, int width, int height, Panel p) { 1346 this.img = img; 1347 this.scaled_img = img; 1348 this.minwidth = width; 1349 this.minheight = height; 1350 this.p = p; 1351 insets = p.getInsets(); 1353 } 1354 1355 1356 public void paint(Graphics g) { 1357 g.drawImage(scaled_img, insets.left, insets.top, this); 1358 } 1359 1360 1361 public Dimension getPreferredSize() { 1362 insets = p.getInsets(); 1363 return new Dimension (minwidth + insets.left + insets.right, minheight + insets.left + insets.right); 1364 } 1365 1366 1367 public Dimension getMinimumSize() { 1368 insets = p.getInsets(); 1369 return new Dimension (minwidth + insets.left + insets.right, minheight + insets.left + insets.right); 1370 } 1371 1372 1373 public void validate() { 1374 insets = p.getInsets(); 1375 int width = p.getSize().width - insets.left - insets.right; 1377 int height = p.getSize().height - insets.top - insets.bottom; 1378 1383 int size; 1384 if (width > height) 1385 size = height; 1386 else 1387 size = width; 1388 scaled_img = img.getScaledInstance(size, size, Image.SCALE_SMOOTH); 1389 super.validate(); 1390 repaint(); 1391 } 1392} 1393 | Popular Tags |