private void addHTML(String text) { HTMLDocument hdoc = (HTMLDocument) doc; try { hdoc.insertAfterEnd(hdoc.getCharacterElement(hdoc.getLength()), text); } catch (BadLocationException | IOException ex) { ex.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()); } }
public void appendToEnd(String text) { Element root = document.getDefaultRootElement(); try { document.insertAfterEnd(root.getElement(root.getElementCount() - 1), text); } catch (BadLocationException e) { logger.error("Insert in the HTMLDocument failed.", e); } catch (IOException e) { logger.error("Insert in the HTMLDocument failed.", e); } }
public void hyperlinkUpdate(HyperlinkEvent event) { HTMLDocument documentHTML = null; if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { m_sPageCourante = event.getURL().toString(); if (event instanceof HTMLFrameHyperlinkEvent) { documentHTML = (HTMLDocument) jEditorPaneHTML.getDocument(); documentHTML.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) event); } else ChargerPageActive(); } }
public StyledHTMLEditorPane() { this.setContentType("text/html"); this.document = (HTMLDocument) this.getDocument(); this.setDocument(document); Constants.loadSimpleStyle(document.getStyleSheet()); }
protected StyleSheet getStyleSheet() { HTMLDocument doc = (HTMLDocument) getDocument(); return doc.getStyleSheet(); }
/** 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> © " + "<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(); }
/** * Creates a new HTMLWriter. * * @param w a Writer * @param doc an HTMLDocument * @param pos the document location from which to fetch the content * @param len the amount to write out */ public HTMLWriter(Writer w, HTMLDocument doc, int pos, int len) { super(w, doc, pos, len); completeDoc = (pos == 0 && len == doc.getLength()); setLineLength(80); }
/** * Creates a new HTMLWriter. * * @param w a Writer * @param doc an HTMLDocument */ public HTMLWriter(Writer w, HTMLDocument doc) { this(w, doc, 0, doc.getLength()); }
/** * Writes out a start tag for the element. Ignores all synthesized elements. * * @param elem an Element * @exception IOException on any I/O error */ protected void startTag(Element elem) throws IOException, BadLocationException { if (synthesizedElement(elem)) { return; } // Determine the name, as an HTML.Tag. AttributeSet attr = elem.getAttributes(); Object nameAttribute = attr.getAttribute(StyleConstants.NameAttribute); HTML.Tag name; if (nameAttribute instanceof HTML.Tag) { name = (HTML.Tag) nameAttribute; } else { name = null; } if (name == HTML.Tag.PRE) { inPre = true; preEndOffset = elem.getEndOffset(); } // write out end tags for item on stack closeOutUnwantedEmbeddedTags(attr); if (inContent) { writeLineSeparator(); inContent = false; newlineOutputed = false; } if (completeDoc && name == HTML.Tag.BODY && !wroteHead) { // If the head has not been output, output it and the styles. wroteHead = true; indent(); write("<head>"); writeLineSeparator(); incrIndent(); writeStyles(((HTMLDocument) getDocument()).getStyleSheet()); decrIndent(); writeLineSeparator(); indent(); write("</head>"); writeLineSeparator(); } indent(); write('<'); write(elem.getName()); writeAttributes(attr); write('>'); if (name != HTML.Tag.PRE) { writeLineSeparator(); } if (name == HTML.Tag.TEXTAREA) { textAreaContent(elem.getAttributes()); } else if (name == HTML.Tag.SELECT) { selectContent(elem.getAttributes()); } else if (completeDoc && name == HTML.Tag.BODY) { // Write out the maps, which is not stored as Elements in // the Document. writeMaps(((HTMLDocument) getDocument()).getMaps()); } else if (name == HTML.Tag.HEAD) { wroteHead = true; incrIndent(); writeStyles(((HTMLDocument) getDocument()).getStyleSheet()); decrIndent(); } HTMLDocument document = null; if (name == HTML.Tag.BODY && (document = (HTMLDocument) getDocument()).hasBaseTag()) { incrIndent(); indent(); write("<base href = \"" + document.getBase() + "\">"); writeLineSeparator(); decrIndent(); } }