1 10 11 import java.awt.*; 12 import java.beans.*; 13 import java.lang.reflect.Method ; 14 import java.io.*; 15 import java.awt.event.*; 16 17 22 public class CompViewer extends Frame implements WindowListener { 23 24 27 public CompViewer(){ 28 super("Component"); 29 this.initCompViewer(null); 30 } 31 32 public CompViewer(String name){ 33 super(name); 34 this.initCompViewer(name); 35 } 36 37 public void initCompViewer(String name){ 38 if (name != null) 39 setTitle(name); 40 setSize(400,400); 41 setLayout(new BorderLayout()); 42 this.addWindowListener(this); 43 } 44 45 void setBean(Component new_bean) 48 { 49 Dimension start_dim = null; 50 add((Component)new_bean, "Center"); 51 start_dim = ((Component)new_bean).getPreferredSize(); 52 53 if(start_dim.width != 0 && start_dim.height != 0) { 54 start_dim.height += 40; 56 start_dim.width += 15; 57 this.setSize( start_dim ); 58 ((Component)new_bean).invalidate(); 59 ((Component)new_bean).validate(); 60 ((Component)new_bean).doLayout(); 61 show(); 62 } 63 else { 64 show(); 68 start_dim = ((Component)new_bean).getPreferredSize(); 69 start_dim.height += 40; 70 start_dim.width += 15; 71 this.setSize( start_dim ); 72 ((Component)new_bean).validate(); 73 } 74 this.setSize(this.getSize()); 75 validate(); 76 } 77 78 79 82 private Object makeBean(ClassLoader cls, String beanName) { 83 Object new_bean = null; 84 85 try { 86 try { 87 new_bean = java.beans.Beans.instantiate(cls, beanName); 88 } 89 catch(IOException e) { 90 System.out.println("CompViewer:Beans.instantiate:IOException " + beanName + "."); 91 System.out.println(e); 92 System.exit(1); 93 } 94 } 95 catch (ClassNotFoundException e) { 96 System.out.println("CompViewer:Beans.instantiate:ClassNotFoundException " + beanName + "."); 97 System.out.println(e); 98 System.exit(1); 99 } 100 101 if( !(new_bean instanceof Component) ) { 102 System.out.println("CompViewer: " + beanName + " not instance of awt.Component exiting"); 103 System.exit(1); 104 } 105 return new_bean; 106 } 107 108 public void windowOpened(WindowEvent e) {} 109 public void windowClosing(WindowEvent e) { 110 this.setVisible(false); 111 } 112 public void windowClosed(WindowEvent e) {} 113 public void windowIconified(WindowEvent e) {} 114 public void windowDeiconified(WindowEvent e) {} 115 public void windowActivated(WindowEvent e) {} 116 public void windowDeactivated(WindowEvent e) {} 117 118 } 119 120 121 122 | Popular Tags |