Exemple #1
0
  public JSONArray convertHTMLToFlag(HTMLDocument htmlDoc) {
    boolean isExistFace = false;
    ElementIterator it = new ElementIterator(htmlDoc);
    Element element;
    while ((element = it.next()) != null) {
      if (element.getName().equals(HTML.Tag.IMG.toString())) {
        isExistFace = true;
        try {
          String name = element.getAttributes().getAttribute(HTML.Attribute.NAME).toString();
          // String src = element.getAttributes().getAttribute(HTML.Attribute.SRC).toString();

          int offset = element.getStartOffset();
          htmlDoc.replace(offset, element.getEndOffset() - offset, "~face:" + name + "~", null);

        } catch (BadLocationException ex) {
          Logger.getLogger(QQImageUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    }
    String text = null;
    try {
      text = htmlDoc.getText(0, htmlDoc.getLength());
      htmlDoc.remove(0, htmlDoc.getLength());
    } catch (BadLocationException ex) {
      Logger.getLogger(QQImageUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (isExistFace) {
      text = text.replaceFirst("\\n", "");
    }
    // Log.println(text);
    JSONArray msg = new JSONArray();
    String[] arr = text.split("~");
    for (int i = 0; i < arr.length; i++) {
      String temp = arr[i];
      // Log.println(temp);
      if (temp.startsWith("face:")) {
        String[] tempArray = temp.split(":");
        JSONArray face = new JSONArray();
        face.add(tempArray[0]);
        String regex = ",([0-9]*):" + tempArray[1] + ",";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(faceFlag);
        String result = null;
        if (m.find()) {
          result = m.group(1);
        } else {
          result = tempArray[1];
        }
        int faceNumber = Integer.parseInt(result);
        face.add(faceNumber);
        msg.add(face);
      } else {
        msg.add(temp);
      }
    }

    // Log.println(msg);
    return msg;
  }
Exemple #2
0
 // appends a message to the log tab and system out.
 public void Log(String msg) {
   try {
     kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
     int over_length = doc.getLength() - msg.length() - 5000;
     doc.remove(0, over_length);
   } catch (BadLocationException e) {
     // TODO Auto-generated catch block
     // e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     // e.printStackTrace();
   }
 }
  public void toChatScreen(String toScreen, boolean selfSeen)
      throws IOException, BadLocationException {
    // Timestamp ts = new Timestamp();
    String toScreenFinal = "";
    Date now = Calendar.getInstance().getTime();
    SimpleDateFormat format = new SimpleDateFormat("hh:mm");
    String ts = format.format(now);

    // chatScreen.append(ts + " " + toScreen + "\n");
    toScreenFinal = "<font color=gray>" + ts + "</font> ";
    if (selfSeen) toScreenFinal = toScreenFinal + "<font color=red>" + toScreen + "</font>";
    else toScreenFinal = toScreenFinal + toScreen;

    // chatter.addTo(toScreen);

    // if(standardWindow) {
    //    chatScreen.setCaretPosition(chatScreen.getDocument().getLength());
    // }
    // else {
    JScrollBar vBar = scrollChat.getVerticalScrollBar();
    int vSize = vBar.getVisibleAmount();
    int maxVBar = vBar.getMaximum();
    int currVBar = vBar.getValue() + vSize;
    kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null);
    if (maxVBar == currVBar) {
      chatScreen.setCaretPosition(chatScreen.getDocument().getLength());
    }

    // }

    // kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null);

  }
 private void addHTML(String text) {
   HTMLDocument hdoc = (HTMLDocument) doc;
   try {
     hdoc.insertAfterEnd(hdoc.getCharacterElement(hdoc.getLength()), text);
   } catch (BadLocationException | IOException ex) {
     ex.printStackTrace();
   }
 }
 @Override
 public void writeSource(String x) {
   try {
     htmlKit.insertHTML(htmlDoc, htmlDoc.getLength(), x, 0, 0, null);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 private void appendMsg(String msg) {
   HTMLDocument doc = (HTMLDocument) textArea.getDocument();
   HTMLEditorKit kit = (HTMLEditorKit) textArea.getEditorKit();
   try {
     kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
   } catch (Exception e) {
     Debug.error(me + "Problem appending text to message area!\n%s", e.getMessage());
   }
 }
Exemple #7
0
 private void addHTML(String html) {
   synchronized (kit) {
     try {
       kit.insertHTML(doc, doc.getLength(), html, 0, 0, null);
     } catch (BadLocationException | IOException ignored) {
       Logger.logError(ignored.getMessage(), ignored);
     }
     displayArea.setCaretPosition(displayArea.getDocument().getLength());
   }
 }
Exemple #8
0
  /**
   * Extracts text from an HTML document and stores it in the document.
   *
   * @param filesInputStream An input stream pointing to the HTML document to be read.
   * @throws BadLocationException
   * @throws IOException
   */
  private static char[] loadHTML(InputStream filesInputStream)
      throws IOException, BadLocationException {
    EditorKit kit = new HTMLEditorKit();
    HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
    doc.putProperty("IgnoreCharsetDirective", true);
    kit.read(filesInputStream, doc, 0);
    char[] origText = doc.getText(0, doc.getLength()).toCharArray();

    return origText;
  }
 @Override
 public void write(int b) throws IOException {
   try {
     htmlKit.insertHTML(
         htmlDoc, htmlDoc.getLength(), new String(new byte[] {(byte) b}), 0, 0, null);
   } catch (BadLocationException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Exemple #10
0
 public void ClearLog() {
   try {
     doc.replace(0, doc.getLength(), "", null);
     kit.insertHTML(doc, 0, "", 0, 0, null);
   } catch (BadLocationException e) {
     // TODO Auto-generated catch block
     // e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     // e.printStackTrace();
   }
 }
  public String getPlainText() {

    try {
      StringWriter stringWriter = new StringWriter();
      HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
      htmlEditorKit.write(stringWriter, document, 0, document.getLength());
      return stringWriter.toString();
    } catch (Exception e) {
      ExceptionHandler.log(e);
    }
    return null;
  }
 public void saveDocument() {
   try {
     view.selectHtmlTab();
     if (currentFile != null) {
       try (FileWriter writer = new FileWriter(currentFile)) {
         new HTMLEditorKit().write(writer, document, 0, document.getLength());
       }
     } else saveDocumentAs();
   } catch (Exception e) {
     ExceptionHandler.log(e);
   }
 }
 private static void appendHTML(JEditorPane editor, String html) {
   try {
     html = StringUtil.replaceAll(html, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
     html = StringUtil.replaceAll(html, "\r\n", "\n");
     html = StringUtil.replaceAll(html, "\r", "");
     Vector vt = StringUtil.toStringVector(html, "\n");
     HTMLEditorKit kit = (HTMLEditorKit) editor.getEditorKit();
     HTMLDocument doc = (HTMLDocument) editor.getDocument();
     for (int iIndex = 0; iIndex < vt.size(); iIndex++)
       kit.insertHTML(doc, doc.getLength(), (String) vt.elementAt(iIndex), 0, 0, null);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public void saveDocumentAs() {
   try {
     view.selectHtmlTab();
     JFileChooser jFileChooser = new JFileChooser();
     jFileChooser.setFileFilter(new HTMLFileFilter());
     jFileChooser.setDialogTitle("Save File");
     int n = jFileChooser.showSaveDialog(view);
     if (n == JFileChooser.APPROVE_OPTION) {
       currentFile = jFileChooser.getSelectedFile();
       view.setTitle(currentFile.getName());
       try (FileWriter writer = new FileWriter(currentFile)) {
         new HTMLEditorKit().write(writer, document, 0, document.getLength());
       }
     }
   } catch (Exception e) {
     ExceptionHandler.log(e);
   }
 }
  /**
   * Calculates the preferred height of the editor pane with the given fixed width.
   *
   * @param width the width of the pane
   * @return the preferred height given the current editor pane content or {@code -1} if there was a
   *     problem. Value will never exceed {@link WorkflowAnnotation#MAX_HEIGHT}
   */
  private int getContentHeightOfEditor(final int width) {
    HTMLDocument document = (HTMLDocument) editPane.getDocument();
    StringWriter writer = new StringWriter();
    try {
      editPane.getEditorKit().write(writer, document, 0, document.getLength());
    } catch (IndexOutOfBoundsException | IOException | BadLocationException e1) {
      // should not happen
      return -1;
    }
    String comment = writer.toString();
    comment = AnnotationDrawUtils.removeStyleFromComment(comment);

    int maxHeight =
        model.getSelected() instanceof ProcessAnnotation
            ? ProcessAnnotation.MAX_HEIGHT
            : OperatorAnnotation.MAX_HEIGHT;
    return Math.min(
        AnnotationDrawUtils.getContentHeight(
            AnnotationDrawUtils.createStyledCommentString(comment, model.getSelected().getStyle()),
            width),
        maxHeight);
  }
  /**
   * Saves the content of the comment editor as the new comment for the given {@link
   * WorkflowAnnotation}.
   *
   * @param selected the annotation for which the content of the editor pane should be saved as new
   *     comment
   */
  private void saveEdit(final WorkflowAnnotation selected) {
    if (editPane == null) {
      return;
    }
    HTMLDocument document = (HTMLDocument) editPane.getDocument();
    StringWriter writer = new StringWriter();
    try {
      editPane.getEditorKit().write(writer, document, 0, document.getLength());
    } catch (IndexOutOfBoundsException | IOException | BadLocationException e1) {
      // should not happen
      LogService.getRoot()
          .log(
              Level.WARNING,
              "com.rapidminer.gui.flow.processrendering.annotations.AnnotationsDecorator.cannot_save");
    }
    String comment = writer.toString();
    comment = AnnotationDrawUtils.removeStyleFromComment(comment);
    Rectangle2D loc = selected.getLocation();
    Rectangle2D newLoc =
        new Rectangle2D.Double(
            loc.getX(),
            loc.getY(),
            editPane.getBounds().getWidth(),
            editPane.getBounds().getHeight());
    selected.setLocation(newLoc);

    boolean overflowing = false;
    int prefHeight =
        AnnotationDrawUtils.getContentHeight(
            AnnotationDrawUtils.createStyledCommentString(comment, selected.getStyle()),
            (int) newLoc.getWidth());
    if (prefHeight > newLoc.getHeight()) {
      overflowing = true;
    }
    selected.setOverflowing(overflowing);

    model.setAnnotationComment(selected, comment);
  }
    /**
     * Sets the HTML content to be displayed.
     *
     * @param content an HTML document
     */
    private void setDocumentContent(String content) {

      HTMLDocument doc = new HTMLDocument();
      try {
        doc.remove(0, doc.getLength());
      } catch (BadLocationException e) {
        e.printStackTrace();
      }
      doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);

      try {
        htmlPane.read(new ByteArrayInputStream(content.getBytes()), doc);
      } catch (IOException e) {
        e.printStackTrace();
      }

      htmlPane.setDocument(doc);
      htmlPane.setCaretPosition(0);

      taTextResponse.setText(content);
      taTextResponse.setCaretPosition(0);
      taTextResponse.requestFocus();
    }
Exemple #18
0
  /** Initializes the graphical components */
  public void init() {
    username = getParameter("username");
    if (username == null) {
      username =
          JOptionPane.showInputDialog(
              this, "Please enter a username", "Login", JOptionPane.QUESTION_MESSAGE);
    }
    try {
      PORT = Integer.valueOf(getParameter("port")).intValue();
    } catch (NumberFormatException e) {
      PORT = 42412;
    }

    URL url = getDocumentBase();
    site = url.getHost();
    locationURL = "http://" + site + ":" + url.getPort() + "/" + url.getPath();

    setSize(615, 362);
    c = getContentPane();

    c.setBackground(new Color(224, 224, 224));

    if (site == null || locationURL == null) {
      c.add(new JLabel("ERROR: did not recieve needed data from page"));
    }

    myAction = new MyAction();
    myKeyListener = new MyKeyListener();
    myMouseListener = new MyMouseListener();
    myHyperlinkListener = new MyHyperlinkListener();

    c.setLayout(null);

    cboChannels = new JComboBox();
    cboChannels.setBounds(5, 5, 150, 24);

    butChannel = new JButton("Join");
    butChannel.setToolTipText("Join channel");
    butChannel.addActionListener(myAction);
    butChannel.setBounds(160, 5, 60, 24);

    butCreate = new JButton("Create");
    butCreate.setToolTipText("Create new channel");
    butCreate.addActionListener(myAction);
    butCreate.setBounds(230, 5, 100, 24);
    butCreate.setEnabled(false);

    butInvite = new JButton("Invite");
    butInvite.setToolTipText("Invite Friend");
    butInvite.addActionListener(myAction);
    butInvite.setBounds(340, 5, 80, 24);

    mainChat = new ChatPane(this);
    textScroller =
        new JScrollPane(
            mainChat,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    textScroller.setBounds(5, 34, 500, 270);

    userList = new JList();
    userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    userList.setCellRenderer(new MyCellRenderer());
    userList.setBackground(new Color(249, 249, 250));
    JScrollPane userScroller = new JScrollPane(userList);
    userScroller.setBounds(510, 34, 100, 297);

    messageText = new JTextField();
    messageText.setBounds(5, 309, 500, 22);
    messageText.setColumns(10);
    messageText.setBackground(new Color(249, 249, 250));

    JMenuItem item;
    popup = new JPopupMenu("test");
    popup.add("whisper").addActionListener(myAction);
    popup.add("private message").addActionListener(myAction);
    popup.add("ignore").addActionListener(myAction);
    popup.add("clear ignore list").addActionListener(myAction);

    conNo = new ImageIcon(getURL("images/connect_no.gif"));
    conYes = new ImageIcon(getURL("images/connect_established.gif"));
    secNo = new ImageIcon(getURL("images/decrypted.gif"));
    secYes = new ImageIcon(getURL("images/encrypted.gif"));

    conIcon = new JLabel(conNo);
    conIcon.setBorder(new EtchedBorder());
    secIcon = new JLabel(secNo);
    secIcon.setBorder(new EtchedBorder());

    conIcon.setBounds(563, 334, 22, 22);
    secIcon.setBounds(588, 334, 22, 22);

    bottomText =
        new JLabel(
            "<html><body><font color=#445577><b>"
                + "LlamaChat "
                + VERSION
                + "</b></font> &nbsp;&copy; "
                + "<a href=\""
                + linkURL
                + "\">Joseph Monti</a> 2002-2003"
                + "</body></html>");
    bottomText.setBounds(5, 336, 500, 20);

    c.add(cboChannels);
    c.add(butChannel);
    c.add(butCreate);
    c.add(butInvite);
    c.add(textScroller);
    c.add(userScroller);
    c.add(messageText);
    c.add(conIcon);
    c.add(secIcon);
    c.add(bottomText);

    userList.addMouseListener(myMouseListener);
    messageText.addKeyListener(myKeyListener);
    bottomText.addMouseListener(myMouseListener);

    users = new ArrayList();
    ignores = new ArrayList(5);
    afks = new ArrayList(5);
    admins = new ArrayList(5);
    history = new CommandHistory(10);
    admin = false;
    channels = new Hashtable();
    privates = new PrivateMsg(this);
    showUserStatus = false;

    myColors[0] = new Color(200, 0, 0);
    myColors[1] = new Color(0, 150, 0);
    myColors[2] = new Color(0, 0, 200);

    rect = new Rectangle(0, 0, 1, 1);

    String opening =
        "<font color=#333333>"
            + "==================================<br>"
            + "Welcome to LlamaChat "
            + VERSION
            + "<br>"
            + "If you need assistance, type \\help<br>"
            + "Enjoy your stay!<br>"
            + "Maestria Aplicada en Redes<br>"
            + "==================================<br></font>";
    HTMLDocument doc = (HTMLDocument) mainChat.getDocument();
    HTMLEditorKit kit = (HTMLEditorKit) mainChat.getEditorKit();
    try {
      kit.insertHTML(doc, doc.getLength(), opening, 0, 0, HTML.Tag.FONT);
    } catch (Throwable t) {
      t.printStackTrace(System.out);
    }

    // validate the name
    if (!username.matches("[\\w_-]+?")) {
      error(
          "username contains invalid characters, changing to "
              + "'invalid' for now. "
              + "Type \\rename to chose a new name");
      username = "******";
    }
    if (username.length() > 10) {
      username = username.substring(0, 10);
      error("username too long, changed to " + username);
    }

    connect();
  }
  About() {
    window = new JWindow();
    this.setPreferredSize(new Dimension(650, 550));
    this.setVisible(true);
    this.setLayout(null);

    JTextPane text = new JTextPane();
    text.setBounds(5, 150, 625, 525);
    text.setVisible(true);
    text.setEditable(false);
    text.setOpaque(false);
    HTMLEditorKit htmlKit =
        new HTMLEditorKit() {
          public Parser getParser() {
            return super.getParser();
          }
        };
    HTMLDocument htmlDoc = new HTMLDocument();
    text.addHyperlinkListener(
        new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              if (Desktop.isDesktopSupported()) {
                try {
                  Desktop.getDesktop().browse(e.getURL().toURI());
                  return;
                } catch (IOException e1) {
                } catch (URISyntaxException e1) {
                }
              }
              try {
                Runtime.getRuntime().exec("xdg-open ".concat(e.getURL().toString()));
              } catch (IOException ioex) {
                ControlRoom.log(
                    Level.WARNING,
                    "Failed to show file: '"
                        + e.getURL().toString()
                        + "'. Possible unsupported File Manager...",
                    null);
              }
            }
          }
        });
    text.setEditorKit(htmlKit);
    text.setDocument(htmlDoc);
    try {
      BufferedReader reader =
          new BufferedReader(
              new InputStreamReader(
                  this.getClass().getResourceAsStream("/resources/about.html"), "UTF-8"));
      htmlKit.read(reader, htmlDoc, htmlDoc.getLength());
    } catch (IOException ioex) {
      ControlRoom.log(Level.SEVERE, "Failed to read about.html", ioex);
    } catch (BadLocationException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }

    text.addMouseListener(this);
    window.getContentPane().add(text);
    window.getContentPane().add(this);
    window.addMouseListener(this);
    window.pack();
    ControlRoom.setWindowRelativeToCentral(window);
    window.setVisible(true);
    window.setAlwaysOnTop(true);
  }