예제 #1
0
  /**
   * Convenience method for testing purposes. If you know that the type of the value is correct, it
   * is preferable to create a ConfigEntry object and apply it to the component (no type checking
   * necessary).
   *
   * @param <T> Type of the config option (Integer, String etc.).
   * @param component A component.
   * @param optionName The name of the config option.
   * @param value The value of the config option.
   */
  @SuppressWarnings("unchecked")
  public <T> void applyConfigEntry(AbstractComponent component, String optionName, T value) {
    logger.trace(component);
    logger.trace(optionName);
    logger.trace(value);
    logger.trace(value.getClass());
    // first we look whether the component is registered
    if (components.contains(component.getClass())) {

      // look for a config option with the specified name
      ConfigOption<?> option =
          (ConfigOption<?>) componentOptionsByName.get(component.getClass()).get(optionName);
      if (option != null) {
        // check whether the given object has the correct type
        if (!option.checkType(value)) {
          System.out.println(
              "Warning: value "
                  + value
                  + " is not valid for option "
                  + optionName
                  + " in component "
                  + component
                  + ". It does not have the correct type.");
          return;
        }

        // we have checked the type, hence it should now be safe to
        // typecast and
        // create a ConfigEntry object
        ConfigEntry<T> entry = null;
        try {
          entry = new ConfigEntry<T>((ConfigOption<T>) option, value);
          component.applyConfigEntry(entry);
          pool.addConfigEntry(component, entry, true);
        } catch (InvalidConfigOptionValueException e) {
          pool.addConfigEntry(component, entry, false);
          System.out.println(
              "Warning: value "
                  + value
                  + " is not valid for option "
                  + optionName
                  + " in component "
                  + component);
        }
      } else {
        logger.warn("Warning: undefined option " + optionName + " in component " + component);
      }
    } else {
      logger.warn("Warning: unregistered component " + component);
    }
  }
예제 #2
0
  protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)
      throws java.io.IOException {
    super.renderProperties(renderer);

    render(renderer, "prolog", getPrologHalf());
    render(renderer, "epilog", getEpilogHalf());
  }
예제 #3
0
  // clone this loop and all of its sub-components
  public Object clone() throws CloneNotSupportedException {
    Loop loop = new Loop(program);
    loop.type = type;
    loop.numReps = numReps;
    loop.numWarmups = numWarmups;
    loop.sync = sync;
    loop.sequenceName = sequenceName;
    loop.time = time;
    loop.timeUnits = timeUnits;
    loop.sequences = (Vector) sequences.clone();

    for (int i = 0; i < components.size(); i++) {
      AbstractComponent component = (AbstractComponent) components.elementAt(i);
      loop.add((AbstractComponent) component.clone());
    }
    return loop;
  }
예제 #4
0
  @Override
  public void init(Entity entity, ComponentDef componentDef) {
    super.init(entity, componentDef);

    maxLife = getComponentDef().getMaxLife();
    currentLife = maxLife;

    setState(currentLife > 0.0f ? State.ALIVE : State.DEAD);
  }
예제 #5
0
 /**
  * Applies a config entry to a component. If the entry is not valid, the method prints an
  * exception and returns false.
  *
  * @param <T> Type of the config option.
  * @param component A component object.
  * @param entry The configuration entry to set.
  * @return True if the config entry could be applied succesfully, otherwise false.
  */
 public <T> boolean applyConfigEntry(AbstractComponent component, ConfigEntry<T> entry) {
   try {
     component.applyConfigEntry(entry);
     pool.addConfigEntry(component, entry, true);
     return true;
   } catch (InvalidConfigOptionValueException e) {
     pool.addConfigEntry(component, entry, false);
     e.printStackTrace();
     return false;
   }
 }
예제 #6
0
  @Override
  public void writeDesign(Element design, DesignContext designContext) {
    super.writeDesign(design, designContext);

    String altText = getAltText();
    if (altText != null && !altText.isEmpty()) {
      design.append(altText);
    }

    for (Resource r : getSources()) {
      Attributes attr = design.appendElement("source").attributes();
      DesignAttributeHandler.writeAttribute("href", attr, r, null, Resource.class);
    }
  }
예제 #7
0
 @Override
 public void hierarchyChanged() {
   super.hierarchyChanged();
   ExecutionContext ctxt = getLookup().get(ExecutionContext.class);
   if (context != ctxt) {
     if (context != null) {
       context.removeStateListener(this);
       context.removeClockListener(this);
     }
     if (ctxt != null) {
       ctxt.addStateListener(this);
       ctxt.addClockListener(this);
       stateChanged(ctxt);
     }
     context = ctxt;
   }
 }
예제 #8
0
  @Override
  public void readDesign(Element design, DesignContext designContext) {
    super.readDesign(design, designContext);

    String altText = "";
    for (Node child : design.childNodes()) {
      if (child instanceof Element
          && ((Element) child).tagName().equals("source")
          && child.hasAttr("href")) {
        addSource(DesignAttributeHandler.readAttribute("href", child.attributes(), Resource.class));
      } else {
        altText += child.toString();
      }
    }

    altText = altText.trim();
    if (!altText.isEmpty()) {
      setAltText(altText);
    }
  }
예제 #9
0
 /**
  * Works as {@link #getConfigOptionValue(AbstractComponent, ConfigOption)}, but using the name of
  * the option instead of a <code>ConfigOption</code> object.
  *
  * @see #getConfigOptionValue(AbstractComponent, ConfigOption)
  * @param component A component.
  * @param optionName A valid option name for this component.
  * @return The value of the specified option in the specified component.
  */
 public Object getConfigOptionValue(AbstractComponent component, String optionName) {
   ConfigOption<?> option =
       (ConfigOption<?>) componentOptionsByName.get(component.getClass()).get(optionName);
   return getConfigOptionValue(component, option);
 }
예제 #10
0
  /** @see AbstractComponent#setFocus(boolean) */
  public void setFocus(boolean focus) {
    lastKey = -1;

    super.setFocus(focus);
  }
예제 #11
0
 public void unbindLogService(LogService logService) {
   super.unbindLogService(logService);
 }
예제 #12
0
 @Reference(cardinality = ReferenceCardinality.OPTIONAL)
 public void bindLogService(LogService logService) {
   super.bindLogService(logService);
   ;
 }
예제 #13
0
  public void redraw(Writer out) throws java.io.IOException {
    // Note: _tag == null can NOT be handled specially
    final Execution exec = Executions.getCurrent();
    final boolean root =
        getParent() == null
            && (getPage().isComplete()
                || (exec != null && "complete".equals(ExecutionsCtrl.getPageRedrawControl(exec))));
    if (exec == null
        || exec.isAsyncUpdate(null)
        || (!root && !HtmlPageRenders.isDirectContent(exec))) {
      super.redraw(out); // renderProperties (assume in zscript)
      return;
    }

    Writer oldout = null;
    if (exec != null
        && !HtmlPageRenders.isZkTagsGenerated(exec)
        && exec.getAttribute(ATTR_TOP_NATIVE) == null) { // need to check topmost native only
      String tn;
      if (root
          || "html".equals(tn = _tag != null ? _tag.toLowerCase() : "")
          || "body".equals(tn)
          || "head".equals(tn)) {
        exec.setAttribute(ATTR_TOP_NATIVE, Boolean.TRUE);
        oldout = out;
        out = new StringWriter();
      }
    }

    out.write(getPrologHalf());

    // children
    Component child = getFirstChild();
    if (child == null) {
      // need to invoke outStandalone to generate response if any (Bug 3009925)
      // however, it is not required if not root (since others will invoke)
      if (root) HtmlPageRenders.outStandalone(exec, null, out);
    } else {
      if (root) HtmlPageRenders.setDirectContent(exec, true);
      do {
        Component next = child.getNextSibling();
        if (child instanceof Native
            || ((ComponentCtrl) child).getExtraCtrl() instanceof DirectContent) {
          ((ComponentCtrl) child).redraw(out);
        } else {
          HtmlPageRenders.setDirectContent(exec, false);
          HtmlPageRenders.outStandalone(exec, child, out);
          HtmlPageRenders.setDirectContent(exec, true);
        }
        child = next;
      } while (child != null);
    }

    out.write(getEpilogHalf());

    if (oldout != null) {
      exec.removeAttribute(ATTR_TOP_NATIVE);

      // order: <html><head><zkhead><body>
      // 1. replace <zkhead/> if found
      // 2. insert before </head> if found
      // 3. insert after <body> if found
      // 4. insert after <html> if found
      // 5. insert at the end if none of above found
      final StringBuffer sb = ((StringWriter) out).getBuffer();
      if (!HtmlPageRenders.isZkTagsGenerated(exec)) {
        int jhead = -1, // anchor of header
            junav = -1, // anchor of unavailable
            head = -1, // index of <head>
            heade = -1, // index of </head>
            html = -1; // index of <html>
        for (int j = 0, len = sb.length(); (j = sb.indexOf("<", j)) >= 0; ) {
          ++j;
          if (jhead < 0 && startsWith(sb, "zkhead", j)) {
            int l = Strings.indexOf(sb, '>', j) + 1;
            sb.delete(jhead = --j, l); // jhead found
            len = sb.length();
          } else if (head < 0 && startsWith(sb, "head", j)) {
            head = Strings.indexOf(sb, '>', j) + 1;
          } else if (html < 0 && startsWith(sb, "html", j)) {
            html = Strings.indexOf(sb, '>', j) + 1;
          } else if (junav < 0 && startsWith(sb, "body", j)) {
            junav = Strings.indexOf(sb, '>', j) + 1; // junav found
            break; // done
          } else if (sb.charAt(j) == '/' && startsWith(sb, "head", ++j)) {
            heade = j - 2;
          }
        }

        boolean disableUnavailable = false;
        if (jhead < 0
            && ((jhead = heade) < 0) // use </head> if no <zkhead>
            && ((jhead = head) < 0) // use <head> if no </head> (though unlikely)
            && ((jhead = junav) < 0) // use <body> if no <head>
            && ((jhead = html) < 0)) { // use <html> if no <body>
          if (_tag != null) {
            final String tn = _tag.toLowerCase();
            if ("div".equals(tn) || "span".equals(tn)) {
              l_loop:
              for (int j = 0, len = sb.length(); j < len; ++j)
                switch (sb.charAt(j)) {
                  case '>':
                    disableUnavailable = true; // make output cleaner
                    jhead = j + 1; // found
                  case '=': // it might have something depends on JS
                  case '"':
                    break l_loop;
                }
            }
          }
          if (jhead < 0) jhead = 0; // insert at head if not found
        }

        final String msg = HtmlPageRenders.outUnavailable(exec);
        // called if disableUnavailable (so it won't be generated later)
        if (msg != null && !disableUnavailable) {
          if (junav < 0) {
            if (html >= 0) junav = sb.lastIndexOf("</html");
          }
          if (junav >= 0) sb.insert(junav < jhead ? jhead : junav, msg);
          else sb.append(msg);
        }

        final String zktags = HtmlPageRenders.outHeaderZkTags(exec, getPage());
        if (zktags != null) sb.insert(jhead, zktags);
      }

      oldout.write(sb.toString());
    }
  }
예제 #14
0
 // -- Component --//
 public void setId(String id) {
   super.setId(id);
   setDynamicProperty("id", id);
 }