/** Adds a Style used to display pictures */
  private void addImageStyle(String uri) throws MalformedURLException {
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style s = this.addStyle("picture", def);
    URL path = new java.net.URL(uri);
    ImageIcon icon = new ImageIcon(path, "ddd");
    if (icon != null) {
      StyleConstants.setIcon(s, icon);
    }
  }
Beispiel #2
0
  public void showImage(Object obj) {
    System.out.println("Got ImageIcon");
    ImageIcon icon = (ImageIcon) obj;
    StyleConstants.setIcon(clientUI.chatStyle.imageStyle, icon);

    try {
      clientUI.doc.insertString(
          clientUI.doc.getLength(), "ignored text\n", clientUI.chatStyle.imageStyle);
    } catch (BadLocationException e1) {
      e1.printStackTrace();
    }
    // clientUI.endScroll();
  }
Beispiel #3
0
  public void showImage(ChatData cd) {
    System.out.println("Got ImageIcon");
    ImageIcon icon = (ImageIcon) cd.data;
    StyleConstants.setIcon(serverUI.chatStyle.imageStyle, icon);

    try {
      // StyledEditorKit sek; //이미지 크기를 조절하기위해서는 에디터킷을 이용해야 할듯
      serverUI.doc.insertString(
          serverUI.doc.getLength(), "Image from: " + cd.from + "\n", serverUI.chatStyle.mainStyle);
      serverUI.doc.insertString(
          serverUI.doc.getLength(), "ignored text\n", serverUI.chatStyle.imageStyle);
    } catch (BadLocationException e1) {
      e1.printStackTrace();
    }
    serverUI.endScroll();
  }
Beispiel #4
0
  public void showImage(Object obj) {
    System.out.println("Got ImageIcon");
    ImageIcon icon = (ImageIcon) obj;
    JLabel comp = new JLabel("Image", icon, JLabel.CENTER);
    StyleConstants.setIcon(clientUI.chatStyle.imageStyle, icon);

    try {
      clientUI.doc.insertString(
          clientUI.doc.getLength(), "ignored text\n", clientUI.chatStyle.imageStyle);
    } catch (BadLocationException e1) {
      e1.printStackTrace();
    }
    clientUI
        .sp
        .getVerticalScrollBar()
        .setValue(clientUI.sp.getVerticalScrollBar().getMaximum()); // 스크롤을 가장 아래로
  }
Beispiel #5
0
 public void addDiceRoll(Player player, DiceType type, List<DiceFace> result) {
   try {
     StyleConstants.setForeground(userNameStyle, player.getColor().getColor());
     String line = player.getName() + " rolled " + result.size() + " " + type.getName() + " :\n";
     text.insertString(text.getEndPosition().getOffset(), line, userNameStyle);
     for (DiceFace face : result) {
       ImageIcon icon = new ImageIcon(face.getImage().getAbsolutePath());
       StyleConstants.setIcon(iconStyle, icon);
       text.insertString(text.getEndPosition().getOffset(), " ", iconStyle);
       text.insertString(text.getEndPosition().getOffset(), " ", textStyle);
     }
     text.insertString(text.getEndPosition().getOffset(), "\n", userNameStyle);
     // The pane auto-scrolls with each new response added
     textPane.setCaretPosition(text.getEndPosition().getOffset() - 1);
   } catch (BadLocationException e) {
     e.printStackTrace();
   }
 }
Beispiel #6
0
  void createStyles() {
    // no attributes defined
    Style s = styles.addStyle(null, null);
    runAttr.put("none", s);
    s = styles.addStyle(null, null);
    StyleConstants.setItalic(s, true);
    StyleConstants.setForeground(s, new Color(153, 153, 102));
    runAttr.put("cquote", s); // catepillar quote

    s = styles.addStyle(null, null);
    StyleConstants.setItalic(s, true);
    StyleConstants.setForeground(s, new Color(51, 102, 153));
    runAttr.put("aquote", s); // alice quote

    try {
      ResourceBundle resources =
          ResourceBundle.getBundle("resources.Stylepad", Locale.getDefault());
      s = styles.addStyle(null, null);
      Icon alice = new ImageIcon(resources.getString("aliceGif"));
      StyleConstants.setIcon(s, alice);
      runAttr.put("alice", s); // alice

      s = styles.addStyle(null, null);
      Icon caterpillar = new ImageIcon(resources.getString("caterpillarGif"));
      StyleConstants.setIcon(s, caterpillar);
      runAttr.put("caterpillar", s); // caterpillar

      s = styles.addStyle(null, null);
      Icon hatter = new ImageIcon(resources.getString("hatterGif"));
      StyleConstants.setIcon(s, hatter);
      runAttr.put("hatter", s); // hatter

    } catch (MissingResourceException mre) {
      // can't display image
    }

    Style def = styles.getStyle(StyleContext.DEFAULT_STYLE);

    Style heading = styles.addStyle("heading", def);
    // StyleConstants.setFontFamily(heading, "SansSerif");
    StyleConstants.setBold(heading, true);
    StyleConstants.setAlignment(heading, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove(heading, 10);
    StyleConstants.setSpaceBelow(heading, 10);
    StyleConstants.setFontSize(heading, 18);

    // Title
    Style sty = styles.addStyle("title", heading);
    StyleConstants.setFontSize(sty, 32);

    // edition
    sty = styles.addStyle("edition", heading);
    StyleConstants.setFontSize(sty, 16);

    // author
    sty = styles.addStyle("author", heading);
    StyleConstants.setItalic(sty, true);
    StyleConstants.setSpaceBelow(sty, 25);

    // subtitle
    sty = styles.addStyle("subtitle", heading);
    StyleConstants.setSpaceBelow(sty, 35);

    // normal
    sty = styles.addStyle("normal", def);
    StyleConstants.setLeftIndent(sty, 10);
    StyleConstants.setRightIndent(sty, 10);
    // StyleConstants.setFontFamily(sty, "SansSerif");
    StyleConstants.setFontSize(sty, 14);
    StyleConstants.setSpaceAbove(sty, 4);
    StyleConstants.setSpaceBelow(sty, 4);
  }
Beispiel #7
0
 /**
  * Diese Methode ermöglicht das einfügen von Bildern
  *
  * @param pos Position an der eingefügt wird
  * @param ico Welches Bild (ImageIcon) soll eingefügt werden
  * @throws BadLocationException
  */
 public void setIcon(int pos, ImageIcon ico) throws BadLocationException {
   SimpleAttributeSet sas = new SimpleAttributeSet();
   StyleConstants.setIcon(sas, ico);
   insertString(pos, " ", sas);
 }