47
48 /**
49 * The panel for the Surface, Custom Controls & Tools.
50 * Other component types welcome.
51 */
52 @SuppressWarnings("serial")
53 public class DemoPanel extends JPanel {
54 private final DemoInstVarsAccessor demoInstVars;
55 public Surface surface;
56 public CustomControlsContext ccc;
57 public Tools tools;
58 public String className;
59
60 public DemoPanel(Object obj, DemoInstVarsAccessor demoInstVars) {
61 this.demoInstVars = demoInstVars;
62
63 setLayout(new BorderLayout());
64 try {
65 if (obj instanceof String) {
66 className = (String) obj;
67 obj = Class.forName(className).newInstance();
68 }
69 if (obj instanceof Component) {
70 add((Component) obj);
71 }
72 if (obj instanceof Surface) {
73 add("South", tools = new Tools(surface = (Surface) obj, demoInstVars));
74 }
75 if (obj instanceof CustomControlsContext) {
76 ccc = (CustomControlsContext) obj;
77 Component[] cmps = ccc.getControls();
78 String[] cons = ccc.getConstraints();
79 for (int i = 0; i < cmps.length; i++) {
80 add(cmps[i], cons[i]);
81 }
82 }
83 } catch (Exception e) {
84 Logger.getLogger(DemoPanel.class.getName()).log(Level.SEVERE, null,
85 e);
86 }
87 }
|
47
48 /**
49 * The panel for the Surface, Custom Controls & Tools.
50 * Other component types welcome.
51 */
52 @SuppressWarnings("serial")
53 public class DemoPanel extends JPanel {
54 private final DemoInstVarsAccessor demoInstVars;
55 public Surface surface;
56 public CustomControlsContext ccc;
57 public Tools tools;
58 public String className;
59
60 public DemoPanel(Object obj, DemoInstVarsAccessor demoInstVars) {
61 this.demoInstVars = demoInstVars;
62
63 setLayout(new BorderLayout());
64 try {
65 if (obj instanceof String) {
66 className = (String) obj;
67 obj = Class.forName(className).getDeclaredConstructor().newInstance();
68 }
69 if (obj instanceof Component) {
70 add((Component) obj);
71 }
72 if (obj instanceof Surface) {
73 add("South", tools = new Tools(surface = (Surface) obj, demoInstVars));
74 }
75 if (obj instanceof CustomControlsContext) {
76 ccc = (CustomControlsContext) obj;
77 Component[] cmps = ccc.getControls();
78 String[] cons = ccc.getConstraints();
79 for (int i = 0; i < cmps.length; i++) {
80 add(cmps[i], cons[i]);
81 }
82 }
83 } catch (Exception e) {
84 Logger.getLogger(DemoPanel.class.getName()).log(Level.SEVERE, null,
85 e);
86 }
87 }
|