List of usage examples for javax.swing.text Document TitleProperty
String TitleProperty
To view the source code for javax.swing.text Document TitleProperty.
Click Source Link
From source file:EditorPaneExample16.java
public TreeNode buildHeadingTree(Document doc) { String title = (String) doc.getProperty(Document.TitleProperty); if (title == null) { title = "[No title]"; }//from ww w. jav a2s. c o m Heading rootHeading = new Heading(title, 0, 0); DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(rootHeading); DefaultMutableTreeNode lastNode[] = new DefaultMutableTreeNode[7]; int lastLevel = 0; lastNode[lastLevel] = rootNode; if (doc instanceof HTMLDocument) { Element elem = doc.getDefaultRootElement(); ElementIterator iterator = new ElementIterator(elem); Heading heading; while ((heading = getNextHeading(doc, iterator)) != null) { // Add the node to the tree DefaultMutableTreeNode hNode = new DefaultMutableTreeNode(heading); int level = heading.getLevel(); if (level > lastLevel) { for (int i = lastLevel + 1; i < level; i++) { lastNode[i] = null; } lastNode[lastLevel].add(hNode); } else { int prevLevel = level - 1; while (prevLevel >= 0) { if (lastNode[prevLevel] != null) { break; } lastNode[prevLevel] = null; prevLevel--; } lastNode[prevLevel].add(hNode); } lastNode[level] = hNode; lastLevel = level; } } return rootNode; }
From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java
private void saveContent() { try {/*from w ww . j ava 2 s.c om*/ JTextComponent ed = EditorRegistry.lastFocusedComponent(); Document document = ed.getDocument(); String content = document.getText(0, document.getLength()); String path = (String) document.getProperty(Document.TitleProperty); String[] temp = path.split(File.separator); String name = temp[temp.length - 1]; String templateType = temp[temp.length - 2]; temp = name.split("\\."); String format = temp[1]; String key = temp[0]; if (templateType.equals("Mail")) { if (format.equals("txt")) { mailTemplateManagerService.setFormat(key, MailTemplateFormat.TEXT, IOUtils.toInputStream(content, encodingPattern)); } else { mailTemplateManagerService.setFormat(key, MailTemplateFormat.HTML, IOUtils.toInputStream(content, encodingPattern)); } } else if (format.equals("html")) { reportTemplateManagerService.setFormat(key, ReportTemplateFormat.HTML, IOUtils.toInputStream(content, encodingPattern)); } else if (format.equals("fo")) { reportTemplateManagerService.setFormat(key, ReportTemplateFormat.FO, IOUtils.toInputStream(content, encodingPattern)); } else { reportTemplateManagerService.setFormat(key, ReportTemplateFormat.CSV, IOUtils.toInputStream(content, encodingPattern)); } } catch (BadLocationException e) { Exceptions.printStackTrace(e); } }
From source file:org.fit.cssbox.swingbox.SwingBoxEditorKit.java
private void readImpl(InputStream in, SwingBoxDocument doc, int pos) throws IOException, BadLocationException { if (component == null) throw new IllegalStateException( "Component is null, editor kit is probably deinstalled from a JEditorPane."); if (pos > doc.getLength() || pos < 0) { BadLocationException e = new BadLocationException("Invalid location", pos); readError(null, e);/*from www . j a v a 2 s. c o m*/ throw e; } ContentReader rdr = new ContentReader(); URL url = (URL) doc.getProperty(Document.StreamDescriptionProperty); CSSBoxAnalyzer analyzer = getCSSBoxAnalyzer(); Container parent = component.getParent(); Dimension dim; if (parent != null && parent instanceof JViewport) { dim = ((JViewport) parent).getExtentSize(); } else { dim = component.getBounds().getSize(); } if (dim.width <= 10) { // component might not be initialized, use screen size :) Dimension tmp = Toolkit.getDefaultToolkit().getScreenSize(); dim.setSize(tmp.width / 2.5, tmp.height / 2.5); } // long time = System.currentTimeMillis(); List<ElementSpec> elements; try { String ctype = null; Object ct = doc.getProperty("Content-Type"); if (ct != null) { if (ct instanceof List) ctype = (String) ((List<?>) ct).get(0); else ctype = ct.toString(); } DocumentSource docSource = new StreamDocumentSource(in, url, ctype); elements = rdr.read(docSource, analyzer, dim); String title = analyzer.getDocumentTitle(); if (title == null) title = "No title"; doc.putProperty(Document.TitleProperty, title); } catch (IOException e) { readError(url, e); throw e; } // System.out.println(System.currentTimeMillis() - time + " ms"); ElementSpec elementsArray[] = elements.toArray(new ElementSpec[0]); doc.create(elementsArray); // component.revalidate(); // component.repaint(); // System.out.println(System.currentTimeMillis() - time + " ms"); // Dictionary<Object, Object> dic = doc.getDocumentProperties(); // Enumeration<Object> en = dic.keys(); // while( en.hasMoreElements()) { // Object k = en.nextElement(); // System.out.println(k + " " + dic.get(k)); // } readFinish(url); }
From source file:ru.gelin.fictionbook.reader.models.FBSimpleDocument.java
public FBSimpleDocument(FBDocument fb) { super(); this.fb = fb; putProperty(Document.TitleProperty, fb.getBookTitle()); traverseDocument(); }