@SuppressWarnings("unchecked") public AnimatorCore(File file) throws FileNotFoundException { Beans.setDesignTime(false); rootContext = new BeanContextServicesSupport(); try { URL specURL = new URL("file:///E:/czt/zml/examples/z/birthdaybook_unfolded.tex"); history = new ZLiveHistory("BirthdayBook", "InitBirthdayBook", specURL); } catch (MalformedURLException ex) { ex.printStackTrace(); } XMLDecoder decoder; decoder = new XMLDecoder(new FileInputStream(file), this); try { while (true) { final Form newForm; newForm = (Form) decoder.readObject(); final JFrame frame = new JFrame() { /** */ private static final long serialVersionUID = 4731706062562233200L; public void setVisible(boolean b) { super.setVisible(b); if (newForm.isVisible() != b) newForm.setVisible(b); }; }; newForm.addComponentListener( new ComponentAdapter() { public void componentHidden(ComponentEvent e) { // If the last form was closed, then quit. Vector<Form> visibleForms = new Vector<Form>(forms_); for (Iterator<Form> i = visibleForms.iterator(); i.hasNext(); ) if (!i.next().isVisible()) i.remove(); visibleForms.remove(e.getComponent()); if (visibleForms.isEmpty()) System.exit(0); }; }); newForm.addPropertyChangeListener( "title", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { frame.setTitle((String) evt.getNewValue()); }; }); if (!newForm.isPreferredSizeSet()) newForm.setPreferredSize(newForm.getSize()); newForm.setLocation(0, 0); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(newForm, BorderLayout.CENTER); frame.pack(); frame.setTitle(newForm.getTitle()); // XXX URGENT setVisible should be moved after the init scripts. // If somebody starts using the interface before the init script // finishes it can have `weird and fun' side-effects // frame.setVisible(newForm.getStartsVisible()); forms_.add(newForm); decoder.readObject(); // beanWrappers // unchecked Vector<BeanLink> beanLinks = (Vector<BeanLink>) decoder.readObject(); // eventLinks for (Iterator<BeanLink> iter = beanLinks.iterator(); iter.hasNext(); ) { BeanLink bl = iter.next(); IntrospectionHelper.addBeanListener(bl.source, bl.listenerType, bl.listener); } rootContext.add(newForm); // unchecked } } catch (ArrayIndexOutOfBoundsException ex) { } finally { decoder.close(); } // XXX Load Z specification. // XXX Display appropriate forms. BSFManager bsfm = new BSFManager(); // XXX (register any new scripting languages) // XXX register and declare beans in bsfm try { bsfm.declareBean("History", history, history.getClass()); bsfm.declareBean("AnimatorCore", this, this.getClass()); bsfm.declareBean("Forms", forms_, forms_.getClass()); bsfm.declareBean("err", System.err, System.err.getClass()); bsfm.declareBean("out", System.out, System.out.getClass()); } catch (BSFException ex) { throw new Error( "History,AnimatorCore, or Forms couldn't be declared " + "with the Scripting Engine. " + ex); } rootContext.addService(BSFManager.class, new BSFServiceProvider(bsfm)); rootContext.addService(History.class, new HistoryServiceProvider(history)); try { bsfm.exec(initScriptLanguage_, "init", 1, 1, initScript_); } catch (BSFException ex) { // XXX Do something? // error dialog? // send message back? // make it settable? System.err.println("Init Script caught BSFException:"); System.err.println(ex); ex.printStackTrace(); System.err.println("------"); ex.getTargetException().printStackTrace(); } ; for (Iterator<Form> it = forms_.iterator(); it.hasNext(); ) { Form form = it.next(); boolean v = form.getStartsVisible(); form.setVisible(v); System.err.println("Setting visible " + form.getName() + " = " + v); } };
public void performAction() { // TODO workaround; remove AFAIK Beans.setDesignTime(false); JDialog dialog = new JDialog(WindowManager.getDefault().getMainWindow(), "OpenGL Capabilities", false); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setResizable(false); dialog.addWindowListener(createWindowObserver()); capsPanel = new GLCapabilitiesPanel(); dialog.setContentPane(capsPanel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); EventQueue.invokeLater(createGLCapabilitiesQuery()); }