コード例 #1
0
    public MyViewController() {
        // Get the view of this view controller.
        UIView view = getView();

        // Setup background.
        view.setBackgroundColor(UIColor.white());

        // Setup label.
        label = new UILabel(new CGRect(20, 250, 280, 44));
        label.setFont(UIFont.getSystemFont(24));
        label.setTextAlignment(NSTextAlignment.Center);
        view.addSubview(label);

        // Setup button.
        button = UIButton.create(UIButtonType.RoundedRect);
        button.setFrame(new CGRect(110, 150, 100, 40));
        button.setTitle("Click me!", UIControlState.Normal);
        button.getTitleLabel().setFont(UIFont.getBoldSystemFont(22));

        button.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener() {
            @Override
            public void onTouchUpInside (UIControl control, UIEvent event) {
                label.setText("Click Nr. " + (++clickCount));
            }
        });
        view.addSubview(button);
    }
コード例 #2
0
ファイル: UIChart.java プロジェクト: subaochen/seam
  @Override
  public void createITextObject(FacesContext context) {

    if (getBorderBackgroundPaint() != null) {
      chart.setBackgroundPaint(findColor(getBorderBackgroundPaint()));
    }

    if (getBorderPaint() != null) {
      chart.setBorderPaint(findColor(getBorderPaint()));
    }

    if (getBorderStroke() != null) {
      chart.setBorderStroke(findStroke(getBorderStroke()));
    }

    chart.setBorderVisible(getBorderVisible());

    configurePlot(chart.getPlot());

    try {
      UIDocument doc = (UIDocument) findITextParent(getParent(), UIDocument.class);
      if (doc != null) {
        PdfWriter writer = (PdfWriter) doc.getWriter();
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(getWidth(), getHeight());

        UIFont font = (UIFont) findITextParent(this, UIFont.class);

        DefaultFontMapper fontMapper;
        if (font == null) {
          fontMapper = new DefaultFontMapper();
        } else {
          fontMapper = new AsianFontMapper(font.getName(), font.getEncoding());
        }

        Graphics2D g2 = tp.createGraphics(getWidth(), getHeight(), fontMapper);
        chart.draw(g2, new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
        g2.dispose();

        image = new ImgTemplate(tp);
      } else {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        ChartUtilities.writeChartAsJPEG(stream, chart, getWidth(), getHeight());

        imageData = stream.toByteArray();
        stream.close();
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
コード例 #3
0
ファイル: NSString.java プロジェクト: deepakworld07/xmlvm.svn
 public static void drawAtPoint(String texttodisplay, CGPoint point, UIFont font) {
   Graphics2D graphicsContext = CGContext.UICurrentContext().xmlvmGetGraphics2D();
   Font savedFont = graphicsContext.getFont();
   graphicsContext.setFont(font.xmlvmGetFont());
   graphicsContext.drawString(texttodisplay, point.x, point.y);
   graphicsContext.setFont(savedFont);
 }
コード例 #4
0
ファイル: NSString.java プロジェクト: deepakworld07/xmlvm.svn
 public static CGSize sizeWithFont(String text, UIFont font) {
   Graphics2D graphicsContext = CGContext.UICurrentContext().xmlvmGetGraphics2D();
   Font savedFont = graphicsContext.getFont();
   Font awtFont = font.xmlvmGetFont();
   graphicsContext.setFont(awtFont);
   Rectangle2D size = awtFont.getStringBounds(text, graphicsContext.getFontRenderContext());
   graphicsContext.setFont(savedFont);
   return new CGSize(
       (float) size.getWidth(),
       text != null && text.length() > 0 ? (float) size.getHeight() : 0.0f);
 }
コード例 #5
0
ファイル: UIButton.java プロジェクト: selmanon/crossmobile
public class UIButton extends UIControl {

  private static final UIFont BUTTONFONT = UIFont.boldSystemFontOfSize(UIFont.buttonFontSize());
  //
  private final int buttonType;
  private xmButtonStates states = new xmButtonStates();
  private UILabel title;
  private UIImageView fore;
  private boolean imagefills = true;
  private boolean updatableBackImage = true;

  public static UIButton buttonWithType(int UIButtonType) {
    UIButton result;
    if (UIButtonType != RoundedRect) {
      result = new UIButton(UIButtonType);
      UIImage img = null;
      switch (UIButtonType) {
        case DetailDisclosure:
          img = UIImage.imageWithContentsOfFile(FileBridge.RESOURCEPREFIX + "detaildisclosure");
          break;
        case ContactAdd:
          img = UIImage.imageWithContentsOfFile(FileBridge.RESOURCEPREFIX + "contactadd");
          break;
        case InfoDark:
          img = UIImage.imageWithContentsOfFile(FileBridge.RESOURCEPREFIX + "infodark");
          break;
        case InfoLight:
          img = UIImage.imageWithContentsOfFile(FileBridge.RESOURCEPREFIX + "infolight");
          break;
      }
      result.setImage(img, Normal);
    } else result = new UIRoundRectButton();
    return result;
  }

  UIButton(int UIButtonType) {
    super();
    this.buttonType = UIButtonType;
  }

  public int getButtonType() {
    return buttonType;
  }

  @Override
  public void setFrame(CGRect frame) {
    super.setFrame(frame);
    frame.origin.x = 0;
    frame.origin.y = 0;
    if (title != null) title.setFrame(frame);
    if (fore != null) fore.setFrame(frame);
  }

  public void setFont(UIFont font) {
    initText();
    title.setFont(font);
  }

  public UIFont getFont() {
    initText();
    return title.getFont();
  }

  public void setTitle(String title, int UIControlState) {
    initText();
    states.setTitle(UIControlState, title);
    updateText(UIControlState);
  }

  public String titleForState(int UIControlState) {
    return states.getTitle(UIControlState);
  }

  public String getCurrentTitle() {
    return titleForState(Normal);
  }

  public void setTitleColor(UIColor titleColor, int UIControlState) {
    states.setTitlecolor(UIControlState, titleColor);
    updateText(UIControlState);
  }

  public UIColor titleColorForState(int UIControlState) {
    return states.getTitlecolor(UIControlState);
  }

  public UIColor getCurrentTitleColor() {
    return titleColorForState(UIControlState.Normal);
  }

  public void setTitleShadowColor(UIColor shadowcolor, int UIControlState) {
    states.setShadowColor(UIControlState, shadowcolor);
    updateText(UIControlState);
  }

  public UIColor titleShadowColorForState(int UIControlState) {
    return states.getShadowColor(UIControlState);
  }

  public UIColor getCurrentTitleShadowColor() {
    return titleShadowColorForState(Normal);
  }

  public void setTitleShadowOffset(CGSize titleShadowOffset) {
    initText();
    title.setShadowOffset(titleShadowOffset);
  }

  public CGSize getTitleShadowOffset() {
    initText();
    return title.getShadowOffset();
  }

  public void setImage(UIImage img, int UIControlState) {
    states.setFore(UIControlState, img);
    updateImage(UIControlState);
  }

  public UIImage imageForState(int UIControlState) {
    return states.getFore(UIControlState);
  }

  public UIImage getCurrentImage() {
    return imageForState(Normal);
  }

  public void setBackgroundImage(UIImage img, int UIControlState) {
    states.setBack(UIControlState, img);
    updateImage(UIControlState);
  }

  public UIImage backgroundImageForState(int UIControlState) {
    return states.getBack(UIControlState);
  }

  public UIImage getCurrentBackgroundImage() {
    return backgroundImageForState(Normal);
  }

  @Override
  public void setHighlighted(boolean highlighted) {
    super.setHighlighted(highlighted);
    int state = highlighted ? Highlighted : isSelected() ? Selected : Normal;
    states.setState(state);
    updateText(state);
    updateImage(state);
  }

  @Override
  public void setSelected(boolean selected) {
    super.setSelected(selected);
    int state = selected ? Selected : Normal;
    states.setState(state);
    updateText(state);
    updateImage(state);
  }

  public boolean isAdjustsImageWhenDisabled() {
    return states.adjustsImageWhenDisabled;
  }

  public void setAdjustsImageWhenDisabled(boolean adjustsImageWhenDisabled) {
    states.adjustsImageWhenDisabled = adjustsImageWhenDisabled;
  }

  public boolean isAdjustsImageWhenHighlighted() {
    return states.adjustsImageWhenHighlighted;
  }

  public void setAdjustsImageWhenHighlighted(boolean adjustsImageWhenHighlighted) {
    states.adjustsImageWhenHighlighted = adjustsImageWhenHighlighted;
  }

  public boolean isShowsTouchWhenHighlighted() {
    return states.showsTouchWhenHighlighted;
  }

  public void setShowsTouchWhenHighlighted(boolean showsTouchWhenHighlighted) {
    states.showsTouchWhenHighlighted = showsTouchWhenHighlighted;
  }

  private void initText() {
    if (title == null) {
      title = new UILabel();
      title.setBackgroundColor(UIColor.clearColor);
      title.setTextAlignment(UITextAlignment.Center);
      title.setFont(BUTTONFONT);
      CGSize size = getFrame().size;
      title.setFrame(new CGRect(0, 0, size.width, size.height));

      addSubview(title);
      if (fore != null) { // Fix Z-order
        fore.removeFromSuperview();
        addSubview(fore);
      }
    }
  }

  private void initForeground() {
    if (fore == null) {
      fore = new UIImageView();
      if (imagefills) fore.setContentMode(UIViewContentMode.ScaleToFill);
      else fore.setContentMode(UIViewContentMode.Center);
      CGSize size = getFrame().size;
      fore.setFrame(new CGRect(0, 0, size.width, size.height));
      addSubview(fore);
    }
  }

  void updateText(int state) {
    if (!states.isInState(state)) return;
    if (title != null) {
      title.setText(states.getTitle());
      if (states.getTitlecolor() != null) title.setTextColor(states.getTitlecolor());
      if (states.getShadowColor() != null) title.setShadowColor(states.getShadowColor());
    }
  }

  void updateImage(int state) {
    if (!states.isInState(state)) return;
    UIRunner.runSynced(
        new UIRunner() {

          @Override
          public void exec() {
            UIImage foreimg = states.getFore();
            if (foreimg == null && fore != null) {
              fore.removeFromSuperview();
              fore = null;
            } else if (foreimg != null) {
              initForeground();
              fore.setImage(foreimg);
            }

            if (updatableBackImage) {
              UIImage backimg = states.getBack();
              if (backimg != null) xm_model().setBackgroundDrawable(backimg.getModel());
              else xm_model().setBackgroundDrawable(null);
            }
          }
        });
  }

  float getPrefferedWidth() {
    xm_model().measure(0, 0);
    int max = xm_model().getMeasuredWidth();
    if (title != null) {
      title.xm_model().measure(0, 0);
      max = Math.max(max, title.xm_model().getMeasuredWidth() + 16);
    }
    if (fore != null) {
      fore.xm_model().measure(0, 0);
      max = Math.max(max, fore.xm_model().getMeasuredWidth());
    }
    return IOSView.x2IOS(max);
  }

  void setImageFillsArea(boolean imagefills) {
    this.imagefills = imagefills;
  }

  // The background images would not be updated automatically
  void setUpdatableBackImage(boolean status) {
    updatableBackImage = status;
  }
}