List of usage examples for javax.swing.text SimpleAttributeSet SimpleAttributeSet
public SimpleAttributeSet()
From source file:org.apache.maven.doxia.module.fo.FoConfiguration.java
/** * (Re-)initialize the AttributeSet. */ private void reset() { this.attributeSet = new SimpleAttributeSet(); }
From source file:org.docx4all.swing.text.WordMLEditorKit.java
/** * Constructs an WordMLEditorKit, creates a StyleContext, and loads the * style sheet./*from w w w .j a v a 2s.c o m*/ */ public WordMLEditorKit() { caretListener = new CaretListener(); mouseListener = new MouseListener(); contentControlTracker = new ContentControlTracker(); inContentControlEdit = false; inputAttributes = new SimpleAttributeSet() { public AttributeSet getResolveParent() { return (currentRunE != null) ? currentRunE.getAttributes() : null; } public Object clone() { return new SimpleAttributeSet(this); } }; }
From source file:org.docx4all.ui.main.WordMLEditor.java
private JEditorPane createSourceView(WordMLTextPane editorView) { //Create the Source View JEditorPane sourceView = new JEditorPane(); MutableAttributeSet attrs = new SimpleAttributeSet(); StyleConstants.setFontFamily(attrs, FontManager.getInstance().getSourceViewFontFamilyName()); StyleConstants.setFontSize(attrs, FontManager.getInstance().getSourceViewFontSize()); // TODO - only do this if the font is available. Font font = new Font("Arial Unicode MS", Font.PLAIN, 12); System.out.println(font.getFamily()); System.out.println(font.getFontName()); System.out.println(font.getPSName()); sourceView.setFont(font);//from w ww. j a va2s.c o m //sourceView.setFont(FontManager.getInstance().getFontInAction(attrs)); sourceView.setContentType("text/xml; charset=UTF-16"); // Instantiate a XMLEditorKit with wrapping enabled. XMLEditorKit kit = new XMLEditorKit(true); // Set the wrapping style. kit.setWrapStyleWord(true); sourceView.setEditorKit(kit); WordMLDocument editorViewDoc = (WordMLDocument) editorView.getDocument(); try { editorViewDoc.readLock(); editorView.getWordMLEditorKit().saveCaretText(); DocumentElement elem = (DocumentElement) editorViewDoc.getDefaultRootElement(); WordprocessingMLPackage wmlPackage = ((DocumentML) elem.getElementML()).getWordprocessingMLPackage(); String filePath = (String) editorView.getDocument().getProperty(WordMLDocument.FILE_PATH_PROPERTY); //Do not include the last paragraph which is an extra paragraph. elem = (DocumentElement) elem.getElement(elem.getElementCount() - 1); ElementML paraML = elem.getElementML(); ElementML bodyML = paraML.getParent(); paraML.delete(); Document doc = DocUtil.read(sourceView, wmlPackage); doc.putProperty(WordMLDocument.FILE_PATH_PROPERTY, filePath); doc.putProperty(WordMLDocument.WML_PACKAGE_PROPERTY, wmlPackage); doc.addDocumentListener(getToolbarStates()); //Below are the properties used by bounce.jar library //See http://www.edankert.com/bounce/xmleditorkit.html doc.putProperty(PlainDocument.tabSizeAttribute, new Integer(4)); doc.putProperty(XMLDocument.AUTO_INDENTATION_ATTRIBUTE, Boolean.TRUE); doc.putProperty(XMLDocument.TAG_COMPLETION_ATTRIBUTE, Boolean.TRUE); //Remember to put 'paraML' as last paragraph bodyML.addChild(paraML); } finally { editorViewDoc.readUnlock(); } kit.setStyle(XMLStyleConstants.ATTRIBUTE_NAME, new Color(255, 0, 0), Font.PLAIN); sourceView.addFocusListener(getToolbarStates()); //sourceView.setDocument(doc); sourceView.putClientProperty(Constants.LOCAL_VIEWS_SYNCHRONIZED_FLAG, Boolean.TRUE); return sourceView; }
From source file:org.docx4all.xml.HyperlinkML.java
private RunPropertiesML createRunPropertiesML() { SimpleAttributeSet attrs = new SimpleAttributeSet(); attrs.addAttribute(WordMLStyleConstants.RStyleAttribute, "Hyperlink"); return ElementMLFactory.createRunPropertiesML(attrs); }
From source file:org.geopublishing.atlasViewer.GpCoreUtil.java
public static void setTabs(final JTextPane textPane, final int charactersPerTab) { final FontMetrics fm = textPane.getFontMetrics(textPane.getFont()); final int charWidth = fm.charWidth('w'); final int tabWidth = charWidth * charactersPerTab; final TabStop[] tabs = new TabStop[10]; for (int j = 0; j < tabs.length; j++) { final int tab = j + 1; tabs[j] = new TabStop(tab * tabWidth); }//w w w . ja v a 2s. co m final TabSet tabSet = new TabSet(tabs); final SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setTabSet(attributes, tabSet); final int length = textPane.getDocument().getLength(); textPane.getStyledDocument().setParagraphAttributes(0, length, attributes, false); }
From source file:org.nuxeo.launcher.gui.ColoredTextPane.java
public ColoredTextPane() { style = new SimpleAttributeSet(); setContentType("text/rtf"); setEditorKit(new RTFEditorKit()); doc = getDocument();/* w w w.j a v a 2s . c o m*/ }
From source file:org.optaplanner.benchmark.impl.aggregator.swingui.BenchmarkAggregatorFrame.java
private JComponent createNoPlannerFoundTextField() { String infoMessage = "No planner benchmarks have been found in the benchmarkDirectory (" + benchmarkAggregator.getBenchmarkDirectory() + ")."; JTextPane textPane = new JTextPane(); textPane.setEditable(false);/* w ww. jav a 2 s. co m*/ textPane.setText(infoMessage); // center info message StyledDocument styledDocument = textPane.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); StyleConstants.setBold(center, true); styledDocument.setParagraphAttributes(0, styledDocument.getLength(), center, false); return textPane; }
From source file:org.pmedv.core.components.RelativeImageView.java
/** * Change the size of this image. This alters the HEIGHT and WIDTH * attributes of the Element and causes a re-layout. *//*ww w .j av a2s. co m*/ protected void resize(int width, int height) { if ((width == fWidth) && (height == fHeight)) { return; } fWidth = width; fHeight = height; // Replace attributes in document MutableAttributeSet myAttr = new SimpleAttributeSet(); myAttr.addAttribute(HTML.Attribute.WIDTH, Integer.toString(width)); myAttr.addAttribute(HTML.Attribute.HEIGHT, Integer.toString(height)); ((StyledDocument) getDocument()).setCharacterAttributes(fElement.getStartOffset(), fElement.getEndOffset(), myAttr, false); }
From source file:org.spoutcraft.launcher.skin.ConsoleFrame.java
/** * Construct the frame./*from w ww .j av a 2 s.c o m*/ * * @param numLines number of lines to show at a time * @param colorEnabled true to enable a colored console * @param trackProc process to track * @param killProcess true to kill the process on console close */ public ConsoleFrame(int numLines, boolean colorEnabled, final Process trackProc, final boolean killProcess) { super("Console"); this.numLines = numLines; this.colorEnabled = colorEnabled; this.trackProc = trackProc; this.highlightedAttributes = new SimpleAttributeSet(); StyleConstants.setForeground(highlightedAttributes, Color.BLACK); StyleConstants.setBackground(highlightedAttributes, Color.YELLOW); this.errorAttributes = new SimpleAttributeSet(); StyleConstants.setForeground(errorAttributes, new Color(200, 0, 0)); this.infoAttributes = new SimpleAttributeSet(); StyleConstants.setForeground(infoAttributes, new Color(200, 0, 0)); this.debugAttributes = new SimpleAttributeSet(); StyleConstants.setForeground(debugAttributes, Color.DARK_GRAY); setSize(new Dimension(650, 400)); buildUI(); Compatibility.setIconImage(this, Toolkit.getDefaultToolkit().getImage(LoginFrame.spoutcraftIcon)); if (trackProc != null) { track(trackProc); } addMouseListener(this); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent event) { if (trackProc != null && killProcess) { trackProc.destroy(); if (loggerHandler != null) { rootLogger.removeHandler(loggerHandler); } event.getWindow().dispose(); } } }); }
From source file:org.thdl.tib.input.TibetanConverter.java
/** Reads from in, closes in, converts (or finds some/all non-TM/TMW), writes the result to out, does not close out. The action taken depends on ct, which must be one of a set number of strings -- see the code. Uses short error and warning messages if shortMessages is true; gives no warnings or many warnings depending on warningLevel. Returns an appropriate return code so that TibetanConverter's usage message is honored. *//*from w w w. j av a 2 s .c o m*/ static int reallyConvert(InputStream in, PrintStream out, String ct, String warningLevel, boolean shortMessages, boolean colors) { if (UNI_TO_WYLIE_TEXT == ct || WYLIE_TO_ACIP_TEXT == ct || ACIP_TO_WYLIE_TEXT == ct) { try { /*String uniText; { // TODO(dchandler): use, here and elsewhere in the // codebase, // org.apache.commons.io.IOUtils.toString(InputStream, // encoding) StringBuffer s = new StringBuffer(); char ch[] = new char[8192]; BufferedReader bin = new BufferedReader(new InputStreamReader(in, "UTF-8")); int amt; while (-1 != (amt = bin.read(ch))) { s.append(ch, 0, amt); } bin.close(); uniText = s.toString(); } StringBuffer errors = new StringBuffer(); // TODO(dchandler): DLC: use human-friendly EWTS, not // computer-friendly! String ewtsText = Converter.convertToEwtsForComputers(uniText, errors); // TODO(dchandler): is 51 the right choice? return (errors.length() > 0) ? 51 : 0;*/ BasicTibetanTranscriptionConverter bc = null; if (UNI_TO_WYLIE_TEXT == ct) bc = new BasicTibetanTranscriptionConverter( new BufferedReader(new InputStreamReader(in, "UTF16")), new PrintWriter(out)); else bc = new BasicTibetanTranscriptionConverter(new BufferedReader(new InputStreamReader(in)), new PrintWriter(out)); bc.run(ct); return 0; } catch (IOException e) { // TODO(dchandler): print it? where to? return 48; } } else if (ACIP_TO_UNI_TEXT == ct || ACIP_TO_TMW == ct || WYLIE_TO_UNI_TEXT == ct || WYLIE_TO_TMW == ct) { try { ArrayList al = ((ACIP_TO_UNI_TEXT == ct || ACIP_TO_TMW == ct) ? (TTraits) ACIPTraits.instance() : (TTraits) EWTSTraits.instance()).scanner().scanStream( in, null, ThdlOptions.getIntegerOption((ACIP_TO_UNI_TEXT == ct || ACIP_TO_TMW == ct) ? "thdl.most.errors.a.tibetan.acip.document.can.have" : "thdl.most.errors.a.tibetan.ewts.document.can.have", 1000 - 1), shortMessages, warningLevel); if (null == al) return 47; boolean embeddedWarnings = (warningLevel != "None"); boolean hasWarnings[] = new boolean[] { false }; if (ACIP_TO_UNI_TEXT == ct || WYLIE_TO_UNI_TEXT == ct) { if (!TConverter.convertToUnicodeText( (WYLIE_TO_UNI_TEXT == ct) ? (TTraits) EWTSTraits.instance() : (TTraits) ACIPTraits.instance(), al, out, null, null, hasWarnings, embeddedWarnings, warningLevel, shortMessages)) return 46; } else { if (!TConverter.convertToTMW( (WYLIE_TO_TMW == ct) ? (TTraits) EWTSTraits.instance() : (TTraits) ACIPTraits.instance(), al, out, null, null, hasWarnings, embeddedWarnings, warningLevel, shortMessages, colors)) return 46; } if (embeddedWarnings && hasWarnings[0]) return 45; else return 0; } catch (IOException e) { // TODO(dchandler): print it? where to? return 48; } } else { TibetanDocument tdoc = new TibetanDocument(); { SimpleAttributeSet ras = new SimpleAttributeSet(); StyleConstants.setFontFamily(ras, ThdlOptions.getStringOption("thdl.default.roman.font.face", "Serif")); StyleConstants.setFontSize(ras, ThdlOptions.getIntegerOption("thdl.default.roman.font.size", 14)); tdoc.setRomanAttributeSet(ras); } try { // Read in the rtf file. if (debug) System.err.println("Start: reading in old RTF file"); if (!ThdlOptions.getBooleanOption("thdl.do.not.fix.rtf.hex.escapes")) in = new RTFFixerInputStream(in); (new RTFEditorKit()).read(in, tdoc, 0); if (debug) System.err.println("End : reading in old RTF file"); } catch (Exception e) { out.println("TibetanConverter:\n" + rtfErrorMessage); return 3; } try { in.close(); } catch (IOException e) { // silently ignore; we don't care about the input so much... ThdlDebug.noteIffyCode(); } if (FIND_ALL_NON_TMW == ct) { // 0, -1 is the entire document. int exitCode = tdoc.findAllNonTMWCharacters(0, -1, out); if (out.checkError()) exitCode = 41; return exitCode; } else if (FIND_SOME_NON_TMW == ct) { // 0, -1 is the entire document. int exitCode = tdoc.findSomeNonTMWCharacters(0, -1, out); if (out.checkError()) exitCode = 41; return exitCode; } else if (FIND_SOME_NON_TM == ct) { // 0, -1 is the entire document. int exitCode = tdoc.findSomeNonTMCharacters(0, -1, out); if (out.checkError()) exitCode = 41; return exitCode; } else if (FIND_ALL_NON_TM == ct) { // 0, -1 is the entire document. int exitCode = tdoc.findAllNonTMCharacters(0, -1, out); if (out.checkError()) exitCode = 41; return exitCode; } else { // conversion {to Wylie or TM} mode // Fix curly braces in the entire document if the input is TMW: if (TM_TO_TMW != ct) { // DLC make me optional if (debug) System.err.println("Start: solving curly brace problem"); tdoc.replaceTahomaCurlyBracesAndBackslashes(0, -1); if (debug) System.err.println("End : solving curly brace problem"); } int exitCode = 0; ThdlDebug.verify(((TMW_TO_TM == ct) ? 1 : 0) + ((TMW_TO_SAME_TMW == ct) ? 1 : 0) + ((TMW_TO_UNI == ct) ? 1 : 0) + ((TM_TO_TMW == ct) ? 1 : 0) + ((TMW_TO_ACIP == ct) ? 1 : 0) + ((TMW_TO_ACIP_TEXT == ct) ? 1 : 0) + ((TMW_TO_WYLIE == ct) ? 1 : 0) + ((TMW_TO_WYLIE_TEXT == ct) ? 1 : 0) == 1); long numAttemptedReplacements[] = new long[] { 0 }; if (TMW_TO_SAME_TMW == ct) { // Identity conversion for testing if (tdoc.identityTmwToTmwConversion(0, tdoc.getLength(), numAttemptedReplacements)) { exitCode = 50; } } else if (TMW_TO_WYLIE == ct || TMW_TO_WYLIE_TEXT == ct) { // Convert to THDL Wylie: if (!tdoc.toWylie(0, tdoc.getLength(), numAttemptedReplacements)) { exitCode = 44; } } else if (TMW_TO_ACIP == ct || TMW_TO_ACIP_TEXT == ct) { // Convert to ACIP: if (!tdoc.toACIP(0, tdoc.getLength(), numAttemptedReplacements)) { exitCode = 49; } } else if (TMW_TO_UNI == ct) { StringBuffer errors = new StringBuffer(); // Convert to Unicode: if (tdoc.convertToUnicode(0, tdoc.getLength(), errors, ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern(), numAttemptedReplacements)) { System.err.println(errors); exitCode = 42; } } else if (TM_TO_TMW == ct) { StringBuffer errors = new StringBuffer(); // Convert to TibetanMachineWeb: if (tdoc.convertToTMW(0, tdoc.getLength(), errors, numAttemptedReplacements)) { System.err.println(errors); exitCode = 42; } } else { ThdlDebug.verify(TMW_TO_TM == ct); StringBuffer errors = new StringBuffer(); // Convert to TibetanMachine: if (tdoc.convertToTM(0, tdoc.getLength(), errors, numAttemptedReplacements)) { System.err.println(errors); exitCode = 42; } } // Write to standard output the result: if (TMW_TO_WYLIE_TEXT == ct || TMW_TO_ACIP_TEXT == ct) { try { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, "UTF-8")); tdoc.writeTextOutput(bw); bw.flush(); } catch (IOException e) { exitCode = 40; } } else { try { tdoc.writeRTFOutputStream(out); } catch (IOException e) { exitCode = 40; } } if (out.checkError()) exitCode = 41; if (numAttemptedReplacements[0] < 1) exitCode = 43; return exitCode; } } }