Debian Codegraph @

demo/src/main/java/CompViewer.java

raw
1 /*
2 * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0, which is available at
6 * http://www.eclipse.org/org/documents/edl-v10.php.
7 *
8 * SPDX-License-Identifier: BSD-3-Clause
9 */
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 /**
18 * Class <code>CompViewer</code> creates a 'viewer' component
19 * that implements the CommandObject interface.
20 *
21 */
22 public class CompViewer extends Frame implements WindowListener {
23
24 /**
25 * Our constructor...
26 */
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 ////////////////////////////////////////////////////////////////////////
46 // we got our bean as a component display it!
47 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 // this is what we do under normal conditions
55 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 // we get here if for some reason our child's
65 // getPref size needs to have it's peer created
66 // first...
67 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 /**
80 * Make the bean based on it's class loader and name
81 */
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