List of usage examples for javax.swing.text SimpleAttributeSet SimpleAttributeSet
public SimpleAttributeSet()
From source file:tufts.vue.RichTextBox.java
/*********** *******NOTES FROM FONT EDITOR PANEL TO HELP WITH COPY/PASTE OF STYLES. globalSizeListener = new ActionListener(){ //from w ww . j av a2 s.c o m public void actionPerformed(ActionEvent fe) { if (suspendItemListeners) return; if (lwtext == null) return; lwtext.richLabelBox.selectAll(); final String textSize = mSizeField.getSelectedItem().toString(); SHTMLDocument doc = (SHTMLDocument)lwtext.richLabelBox.getDocument(); SimpleAttributeSet set = new SimpleAttributeSet(); Util.styleSheet().addCSSAttribute(set, CSS.Attribute.FONT_SIZE, textSize); set.addAttribute(HTML.Attribute.SIZE, textSize); lwtext.richLabelBox.applyAttributes(set, false); lwtext.richLabelBox.select(0,0); //lwtext.setLabel0(lwtext.richLabelBox.getRichText(), false); lwtext.richLabelBox.setSize(lwtext.richLabelBox.getPreferredSize()); if (lwtext.getParent() !=null) lwtext.getParent().layout(); lwtext.notify(lwtext.richLabelBox, LWKey.Repaint); } }; globalFaceListener = new ActionListener(){ public void actionPerformed(ActionEvent fe) { if (suspendItemListeners) return; if (lwtext == null) return; lwtext.richLabelBox.selectAll(); SHTMLDocument doc = (SHTMLDocument)lwtext.richLabelBox.getDocument(); SimpleAttributeSet set = new SimpleAttributeSet(); Util.styleSheet().addCSSAttribute(set, CSS.Attribute.FONT_FAMILY, mFontCombo.getSelectedItem().toString()); set.addAttribute(HTML.Attribute.FACE, mFontCombo.getSelectedItem().toString()); lwtext.richLabelBox.applyAttributes(set, false); lwtext.richLabelBox.select(0,0); lwtext.richLabelBox.setSize(lwtext.richLabelBox.getPreferredSize()); if (lwtext.getParent() !=null) lwtext.getParent().layout(); lwtext.notify(lwtext.richLabelBox, LWKey.Repaint); } }; private final PropertyChangeListener RichTextColorChangeListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if (e instanceof LWPropertyChangeEvent == false) return; final RichTextBox activeRTB = (RichTextBox) VUE.getActive(RichTextBox.class); if (activeRTB == null && lwtext == null) { // no problem: just ignore if there's no active edit //tufts.Util.printStackTrace("FEP propertyChange: no active RichTextBox: " + e); return; } if (lwtext !=null) lwtext.richLabelBox.selectAll(); final Color color = (Color) e.getNewValue(); final SimpleAttributeSet set = new SimpleAttributeSet(); final String colorString = "#" + Integer.toHexString(color.getRGB()).substring(2); toggleBulletsAction.setColor(colorString); toggleNumbersAction.setColor(colorString); Util.styleSheet().addCSSAttribute(set, CSS.Attribute.COLOR, colorString); set.addAttribute(HTML.Attribute.COLOR, colorString); if (activeRTB != null) activeRTB.applyAttributes(set, false); else lwtext.richLabelBox.applyAttributes(set, false); if (lwtext !=null) { lwtext.richLabelBox.select(0,0); lwtext.richLabelBox.select(0,0); //lwtext.setLabel0(lwtext.richLabelBox.getRichText(), false); lwtext.richLabelBox.setSize(lwtext.richLabelBox.getPreferredSize()); if (lwtext.getParent() !=null) lwtext.getParent().layout(); lwtext.notify(lwtext.richLabelBox, LWKey.Repaint); } } }; ************/ // this called every time setText is called to ensure we get // the font style encoded in our owning LWComponent void copyStyle(LWComponent c) { if (DEBUG.TEXT) out("copyStyle " + c); //Basic Setup LWText srcText = (LWText) c; RichTextBox srcBox = srcText.getRichLabelBox(); selectAll(); SHTMLDocument srcDoc = (SHTMLDocument) srcBox.getDocument(); SHTMLDocument doc = (SHTMLDocument) getDocument(); SimpleAttributeSet set = new SimpleAttributeSet(); SimpleAttributeSet alignSet = new SimpleAttributeSet(); //Gather source information Element paragraphElement = srcDoc.getParagraphElement(1); if (paragraphElement.getName().equals("p-implied")) //we're in a list item paragraphElement = paragraphElement.getParentElement(); AttributeSet paragraphAttributeSet = paragraphElement.getAttributes(); Element charElem = srcDoc.getCharacterElement(1); AttributeSet charSet = charElem.getAttributes(); Enumeration characterAttributeEnum = charSet.getAttributeNames(); Enumeration elementEnum = paragraphAttributeSet.getAttributeNames(); //Apply some attributes // System.out.println(paragraphElement.toString()); while (elementEnum.hasMoreElements()) { Object o = elementEnum.nextElement(); boolean isAlignSet = false; //System.out.println("P :: " +o.toString()); if (o.toString().equals("text-align") && paragraphAttributeSet.getAttribute(o).toString().equals("left") && !isAlignSet) { //Left Align Util.styleSheet().addCSSAttribute(alignSet, CSS.Attribute.TEXT_ALIGN, paragraphAttributeSet.getAttribute(o).toString()); alignSet.addAttribute(HTML.Attribute.ALIGN, paragraphAttributeSet.getAttribute(o).toString()); } else if (o.toString().equals("text-align") && paragraphAttributeSet.getAttribute(o).toString().equals("center") && !isAlignSet) { //Center Align Util.styleSheet().addCSSAttribute(alignSet, CSS.Attribute.TEXT_ALIGN, paragraphAttributeSet.getAttribute(o).toString()); alignSet.addAttribute(HTML.Attribute.ALIGN, paragraphAttributeSet.getAttribute(o).toString()); } else if (o.toString().equals("text-align") && paragraphAttributeSet.getAttribute(o).toString().equals("right") && !isAlignSet) { //Right Align Util.styleSheet().addCSSAttribute(alignSet, CSS.Attribute.TEXT_ALIGN, paragraphAttributeSet.getAttribute(o).toString()); alignSet.addAttribute(HTML.Attribute.ALIGN, paragraphAttributeSet.getAttribute(o).toString()); } if ((o.toString().equals("font-size")) || (o.toString().equals("size"))) { //Font Size Util.styleSheet().addCSSAttribute(set, CSS.Attribute.FONT_SIZE, paragraphAttributeSet.getAttribute(o).toString()); set.addAttribute(HTML.Attribute.SIZE, paragraphAttributeSet.getAttribute(o).toString()); } else if ((o.toString().equals("font-family")) || (o.toString().equals("font-face")) || (o.toString().equals("face"))) { //Font Face Util.styleSheet().addCSSAttribute(set, CSS.Attribute.FONT_FAMILY, paragraphAttributeSet.getAttribute(o).toString()); set.addAttribute(HTML.Attribute.FACE, paragraphAttributeSet.getAttribute(o).toString()); } } boolean isBold = false; boolean isItalic = false; boolean isUnderline = false; while (characterAttributeEnum.hasMoreElements()) { Object o = characterAttributeEnum.nextElement(); //System.out.println("C :: " +o.toString() + "XXX " + charSet.getAttribute(o).toString()); //System.out.println("Character element : " + o.toString() + " , " + charSet.getAttribute(o)); if ((o.toString().equals("color"))) { //Color Util.styleSheet().addCSSAttribute(set, CSS.Attribute.COLOR, charSet.getAttribute(o).toString()); set.addAttribute(HTML.Attribute.COLOR, charSet.getAttribute(o).toString()); } if ((o.toString().equals("font-size")) || (o.toString().equals("size"))) { //Font Size Util.styleSheet().addCSSAttribute(set, CSS.Attribute.FONT_SIZE, charSet.getAttribute(o).toString()); set.addAttribute(HTML.Attribute.SIZE, charSet.getAttribute(o).toString()); } if ((o.toString().equals("font-family")) || (o.toString().equals("font-face")) || (o.toString().equals("face"))) { //Font Face Util.styleSheet().addCSSAttribute(set, CSS.Attribute.FONT_FAMILY, charSet.getAttribute(o).toString()); set.addAttribute(HTML.Attribute.FACE, charSet.getAttribute(o).toString()); } if ((o.toString().equals("font-weight") && charSet.getAttribute(o).toString().equals("bold")) || o.toString().equals("b")) { Util.styleSheet().addCSSAttribute(set, CSS.Attribute.FONT_WEIGHT, charSet.getAttribute(o).toString()); } if ((o.toString().equals("font-style") && charSet.getAttribute(o).toString().equals("italic")) || o.toString().equals("i")) { Util.styleSheet().addCSSAttribute(set, CSS.Attribute.FONT_STYLE, charSet.getAttribute(o).toString()); } if ((o.toString().equals("text-decoration") && charSet.getAttribute(o).toString().equals("underline")) || o.toString().equals("u")) { Util.styleSheet().addCSSAttribute(set, CSS.Attribute.TEXT_DECORATION, charSet.getAttribute(o).toString()); } } //done looking at character attributes applyAttributes(set, false); lwc.notify(this, LWKey.Repaint); applyAttributes(alignSet, true); lwc.notify(this, LWKey.Repaint); clearSelection(); try { setSize(getPreferredSize()); } catch (NullPointerException npe) { } /* set = new SimpleAttributeSet(); final String colorString = "#" + Integer.toHexString(color.getRGB()).substring(2); toggleBulletsAction.setColor(colorString); toggleNumbersAction.setColor(colorString); Util.styleSheet().addCSSAttribute(set, CSS.Attribute.COLOR, colorString); set.addAttribute(HTML.Attribute.COLOR, colorString); if (activeRTB != null) activeRTB.applyAttributes(set, false); else lwtext.richLabelBox.applyAttributes(set, false); if (lwtext !=null) { lwtext.richLabelBox.select(0,0); lwtext.richLabelBox.select(0,0); //lwtext.setLabel0(lwtext.richLabelBox.getRichText(), false); lwtext.richLabelBox.setSize(lwtext.richLabelBox.getPreferredSize()); if (lwtext.getParent() !=null) lwtext.getParent().layout(); lwtext.notify(lwtext.richLabelBox, LWKey.Repaint); }*/ }
From source file:tufts.vue.RichTextBox.java
public void overrideTextColor(Color c) { //System.out.println("OVERRIDE TEXT COLOR : " + c.toString()); SimpleAttributeSet set = new SimpleAttributeSet(); String colorString = "#" + Integer.toHexString(c.getRGB()).substring(2); com.lightdev.app.shtm.Util.styleSheet().addCSSAttribute(set, CSS.Attribute.COLOR, colorString); set.addAttribute(HTML.Attribute.COLOR, colorString); this.applyAttributesGlobally(set, true, false); }
From source file:uk.ac.kcl.texthunter.core.AnnotationEditor.java
private void updateProjectSummary() { try {// w ww. j av a 2s . c om projectXML.updateProjectSummary(con, targetTableName); } catch (java.sql.SQLException ex) { updateProjectStatus("Annotation table not ready"); } StyledDocument doc; doc = projectSummaryTextPane.getStyledDocument(); SimpleAttributeSet newString = new SimpleAttributeSet(); StyleConstants.setForeground(newString, Color.BLACK); StyleConstants.setBold(newString, true); StringBuilder newText = new StringBuilder("\n"); DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); Date date = new Date(); newText.append("------ results updated on ").append(dateFormat.format(date)).append(" ------\n\n"); newText.append("current project annotations:\n"); newText = newText.append("Gold Standard Positive Annotations = ").append(projectXML.getGsPos()) .append("\n"); newText = newText.append("Gold Standard Negative Annotations = ").append(projectXML.getGsneg()) .append("\n"); newText = newText.append("Gold Standard Unknown Annotations = ").append(projectXML.getGsunk()).append("\n"); newText = newText.append("Gold Standard Form Annotations = ").append(projectXML.getGsform()).append("\n"); newText = newText.append("Seed positive Annotations = ").append(projectXML.getSeedpos()).append("\n"); newText = newText.append("Seed Negative Annotations = ").append(projectXML.getSeedneg()).append("\n"); newText = newText.append("Seed Unknown Annotations = ").append(projectXML.getSeedunk()).append("\n"); newText = newText.append("Seed Form Annotations = ").append(projectXML.getSeedform()).append("\n"); newText = newText.append("AL Positive Annotations = ").append(projectXML.getAlpos()).append("\n"); newText = newText.append("AL Negative Annotations = ").append(projectXML.getAlneg()).append("\n"); newText = newText.append("AL Form Annotations = ").append(projectXML.getAlform()).append("\n"); newText = newText.append("AL Unknown Annotations = ").append(projectXML.getAlunk()).append("\n\n"); newText = newText.append("Last Pipeline run results:\n"); newText = newText.append("P = ").append(projectXML.getPrecision()).append("\n"); newText = newText.append("R = ").append(projectXML.getRecall()).append("\n"); newText = newText.append("F1 = ").append(projectXML.getF1()).append("\n"); try { doc.insertString(doc.getLength(), "\n" + newText, newString); } catch (Exception e) { System.out.println(e); } }
From source file:uk.ac.kcl.texthunter.core.AnnotationEditor.java
private void updateInfoTextPane(String newText) { StyledDocument doc;//w w w.jav a 2s .com doc = infoTextPane.getStyledDocument(); // Define a keyword attribute SimpleAttributeSet newString = new SimpleAttributeSet(); StyleConstants.setForeground(newString, Color.RED); StyleConstants.setBold(newString, true); SimpleAttributeSet oldString = new SimpleAttributeSet(); StyleConstants.setForeground(oldString, Color.BLACK); StyleConstants.setBold(oldString, false); // Add some text try { doc.setCharacterAttributes(0, doc.getLength(), oldString, true); doc.insertString(doc.getLength(), "\n" + newText, newString); } catch (Exception e) { System.out.println(e); } }