示例#1
1
  @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);
    }
  };
示例#2
0
  @Test
  public void testButton() {
    Form form = new Form(request);
    Button button;

    button = Button.button("OK");
    assertOut(button, "<button>OK</button>");
    assertEquals(null, button.getName());
    form.add(button);
    assertEquals(form.getName() + "_button", button.getName());

    button = Button.reset("Reset");
    button.setDisabled();
    assertOut(button, "<button type='reset' disabled>Reset</button>");

    button = Button.submit("Submit");
    button.setName("submit");
    assertOut(button, "<button type='submit' name='submit' value='Submit'>Submit</button>");
    form.add(button);
    assertEquals("submit", button.getName());
    Button defaultButton = button;
    assertSame(form.getDefaultButton(), button);

    button = Button.inputButton("OK");
    assertOut(button, "<input type='button' value='OK'>");

    button = Button.inputReset("Reset");
    assertOut(button, "<input type='reset' value='Reset'>");

    button = Button.inputSubmit("Submit");
    button.setOnClick("alert()");
    assertOut(button, "<input type='submit' value='Submit' onclick='alert()'>");
    button.end(out);
    out.assertOut("");
    form.add(button);
    assertSame(defaultButton, form.getDefaultButton());

    // misc
    assertTrue(button.read(null));
    assertEquals(Control.Category.BUTTON, button.getCategory());

    assertFalse(defaultButton.isClicked());
    setParam(form.getName(), "");
    assertTrue(defaultButton.isClicked());
    assertFalse(button.isClicked());
    setParam(form.getName(), "reload");
    assertFalse(defaultButton.isClicked());
    setParam(defaultButton.getName(), "x");
    assertFalse(defaultButton.isClicked());
    setParam(defaultButton.getName(), defaultButton.getValue());
    assertTrue(defaultButton.isClicked());

    setParam(defaultButton.getName(), null);
    assertFalse(defaultButton.isDirectlyClicked());
    setParam(defaultButton.getName(), "x");
    assertFalse(defaultButton.isDirectlyClicked());
    setParam(defaultButton.getName(), defaultButton.getValue());
    assertTrue(defaultButton.isDirectlyClicked());
  }
 protected void postShow(Form f) {
   if ("Main".equals(f.getName())) {
     postMain(f);
     aboutToShowThisContainer = null;
     return;
   }
 }
 protected void beforeShow(Form f) {
   aboutToShowThisContainer = f;
   if ("Main".equals(f.getName())) {
     beforeMain(f);
     aboutToShowThisContainer = null;
     return;
   }
 }
示例#5
0
 @SuppressWarnings("unused")
 public Form lookup(String name) { // For use by scripts.
   for (Iterator<Form> it = iterator(); it.hasNext(); ) {
     Form f = it.next();
     if (f.getName().equals(name)) return f;
   }
   return null;
 };
示例#6
0
  public FormData(final Form form) {
    description = form.getDescription();
    formItems = form.getFormItems();
    formId = form.getId();
    formName = form.getName();
    showDescription = form.isShowDescription();
    termsAndConditions =
        form instanceof DraftRegistrationForm
            ? ((DraftRegistrationForm) form).getTermsAndConditions()
            : null;
    requireTermsAndConditions =
        form instanceof DraftRegistrationForm
            && ((DraftRegistrationForm) form).isRequireTermsAndConditions();

    updateChildSiteRegistrationFields(form);
  }
示例#7
0
 /** Add a <code>Form</code> to the <code>FormSet</code>. */
 public void addForm(Form f) {
   forms.put(f.getName(), f);
 }