public void testListeners() {
    Cascade cascade = new BaseCascade();

    CascadeListener listener =
        new CascadeListener() {
          @Override
          public void onStarting(Cascade cascade) {}

          @Override
          public void onStopping(Cascade cascade) {}

          @Override
          public void onCompleted(Cascade cascade) {}

          @Override
          public boolean onThrowable(Cascade cascade, Throwable throwable) {
            return false;
          }
        };

    cascade.addListener(listener);

    assertTrue("no listener found", cascade.hasListeners());

    cascade.removeListener(listener);

    assertFalse("listener found", cascade.hasListeners());
  }
 void initDelegate(Map attributes) throws TransformerException {
   attributes.put(Cascade.DIRECTION, wired);
   try {
     delegate.init(attributes);
   } catch (InvalidKeyException x) {
     throw new TransformerException("initDelegate()", x);
   }
   blockSize = delegate.currentBlockSize();
 }
Example #3
0
 static {
   MultiCascade mc = new MultiCascade();
   Cascade c = mc.getOrCreateCascade("default");
   c.put(TEXT, Keyword.AUTO);
   Node n = new Node();
   n.put("name", "dummy");
   SIMPLE_NODE_TEXT_ELEMSTYLE =
       create(
           new Environment(n, mc, "default", null),
           NodeElemStyle.SIMPLE_NODE_ELEMSTYLE.getBoxProvider());
   if (SIMPLE_NODE_TEXT_ELEMSTYLE == null) throw new AssertionError();
 }
Example #4
0
  public static BoxTextElemStyle create(Environment env, BoxProvider boxProvider, Rectangle box) {
    initDefaultParameters();
    Cascade c = env.mc.getCascade(env.layer);

    TextElement text = TextElement.create(c, DEFAULT_TEXT_COLOR, false);
    if (text == null) return null;
    // Skip any primtives that don't have text to draw. (Styles are recreated for any tag change.)
    // The concrete text to render is not cached in this object, but computed for each
    // repaint. This way, one BoxTextElemStyle object can be used by multiple primitives (to save
    // memory).
    if (text.labelCompositionStrategy.compose(env.osm) == null) return null;

    HorizontalTextAlignment hAlign = HorizontalTextAlignment.RIGHT;
    Keyword hAlignKW = c.get("text-anchor-horizontal", Keyword.RIGHT, Keyword.class);
    if (equal(hAlignKW.val, "left")) {
      hAlign = HorizontalTextAlignment.LEFT;
    } else if (equal(hAlignKW.val, "center")) {
      hAlign = HorizontalTextAlignment.CENTER;
    } else if (equal(hAlignKW.val, "right")) {
      hAlign = HorizontalTextAlignment.RIGHT;
    }
    VerticalTextAlignment vAlign = VerticalTextAlignment.BOTTOM;
    String vAlignStr = c.get("text-anchor-vertical", Keyword.BOTTOM, Keyword.class).val;
    if (equal(vAlignStr, "above")) {
      vAlign = VerticalTextAlignment.ABOVE;
    } else if (equal(vAlignStr, "top")) {
      vAlign = VerticalTextAlignment.TOP;
    } else if (equal(vAlignStr, "center")) {
      vAlign = VerticalTextAlignment.CENTER;
    } else if (equal(vAlignStr, "bottom")) {
      vAlign = VerticalTextAlignment.BOTTOM;
    } else if (equal(vAlignStr, "below")) {
      vAlign = VerticalTextAlignment.BELOW;
    }

    return new BoxTextElemStyle(c, text, boxProvider, box, hAlign, vAlign);
  }
 private byte[] updateInternal(byte[] in, int offset, int length) {
   byte[] result;
   for (int i = 0; i < length; i++) {
     inBuffer.write(in[offset++] & 0xFF);
     if (inBuffer.size() >= blockSize) {
       result = inBuffer.toByteArray();
       inBuffer.reset();
       delegate.update(result, 0, result, 0);
       outBuffer.write(result, 0, blockSize);
     }
   }
   result = outBuffer.toByteArray();
   outBuffer.reset();
   return result;
 }
 void resetDelegate() {
   delegate.reset();
   blockSize = 0;
 }