List of usage examples for javax.swing JEditorPane JEditorPane
public JEditorPane(String type, String text)
JEditorPane
that has been initialized to the given text. From source file:Main.java
public MyTreeCellRenderer() { editorPane = new JEditorPane("text/html", null); }
From source file:net.ontopia.topicmaps.viz.AboutFrame.java
private JEditorPane createAboutTextPanel() { JEditorPane about = new JEditorPane("text/html", "<html>" + "<body><center>" + "<h1>Vizigator™: VizDesktop™</h1>" + "<h3>Version: " + Ontopia.getInfo() + "</h3>" + "<p>Topic Map visualization and configuration tool based on the graphic visualization product, TouchGraph </p>" + "<p>Copyright © 2004-2007 Ontopia AS</p>" + "<p>The Ontopians wish you Happy Vizigating</p><br></center></body></html>"); about.setEditable(false);//www . java 2 s . co m return about; }
From source file:net.sf.jasperreports.engine.util.JEditorPaneHtmlMarkupProcessor.java
@Override public String convert(String srcText) { JEditorPane editorPane = new JEditorPane("text/html", srcText); editorPane.setEditable(false);//from w ww.ja v a2 s .c o m List<Element> elements = new ArrayList<Element>(); Document document = editorPane.getDocument(); Element root = document.getDefaultRootElement(); if (root != null) { addElements(elements, root); } int startOffset = 0; int endOffset = 0; int crtOffset = 0; String chunk = null; JRPrintHyperlink hyperlink = null; Element element = null; Element parent = null; boolean bodyOccurred = false; int[] orderedListIndex = new int[elements.size()]; String whitespace = " "; String[] whitespaces = new String[elements.size()]; for (int i = 0; i < elements.size(); i++) { whitespaces[i] = ""; } StringBuilder text = new StringBuilder(); List<JRStyledText.Run> styleRuns = new ArrayList<>(); for (int i = 0; i < elements.size(); i++) { if (bodyOccurred && chunk != null) { text.append(chunk); Map<Attribute, Object> styleAttributes = getAttributes(element.getAttributes()); if (hyperlink != null) { styleAttributes.put(JRTextAttribute.HYPERLINK, hyperlink); hyperlink = null; } if (!styleAttributes.isEmpty()) { styleRuns.add( new JRStyledText.Run(styleAttributes, startOffset + crtOffset, endOffset + crtOffset)); } } chunk = null; element = elements.get(i); parent = element.getParentElement(); startOffset = element.getStartOffset(); endOffset = element.getEndOffset(); AttributeSet attrs = element.getAttributes(); Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute); Object object = (elementName != null) ? null : attrs.getAttribute(StyleConstants.NameAttribute); if (object instanceof HTML.Tag) { HTML.Tag htmlTag = (HTML.Tag) object; if (htmlTag == Tag.BODY) { bodyOccurred = true; crtOffset = -startOffset; } else if (htmlTag == Tag.BR) { chunk = "\n"; } else if (htmlTag == Tag.OL) { orderedListIndex[i] = 0; String parentName = parent.getName().toLowerCase(); whitespaces[i] = whitespaces[elements.indexOf(parent)] + whitespace; if (parentName.equals("li")) { chunk = ""; } else { chunk = "\n"; ++crtOffset; } } else if (htmlTag == Tag.UL) { whitespaces[i] = whitespaces[elements.indexOf(parent)] + whitespace; String parentName = parent.getName().toLowerCase(); if (parentName.equals("li")) { chunk = ""; } else { chunk = "\n"; ++crtOffset; } } else if (htmlTag == Tag.LI) { whitespaces[i] = whitespaces[elements.indexOf(parent)]; if (element.getElement(0) != null && (element.getElement(0).getName().toLowerCase().equals("ol") || element.getElement(0).getName().toLowerCase().equals("ul"))) { chunk = ""; } else if (parent.getName().equals("ol")) { int index = elements.indexOf(parent); Object type = parent.getAttributes().getAttribute(HTML.Attribute.TYPE); Object startObject = parent.getAttributes().getAttribute(HTML.Attribute.START); int start = startObject == null ? 0 : Math.max(0, Integer.valueOf(startObject.toString()) - 1); String suffix = ""; ++orderedListIndex[index]; if (type != null) { switch (((String) type).charAt(0)) { case 'A': suffix = getOLBulletChars(orderedListIndex[index] + start, true); break; case 'a': suffix = getOLBulletChars(orderedListIndex[index] + start, false); break; case 'I': suffix = JRStringUtil.getRomanNumeral(orderedListIndex[index] + start, true); break; case 'i': suffix = JRStringUtil.getRomanNumeral(orderedListIndex[index] + start, false); break; case '1': default: suffix = String.valueOf(orderedListIndex[index] + start); break; } } else { suffix += orderedListIndex[index] + start; } chunk = whitespaces[index] + suffix + DEFAULT_BULLET_SEPARATOR + " "; } else { chunk = whitespaces[elements.indexOf(parent)] + DEFAULT_BULLET_CHARACTER + " "; } crtOffset += chunk.length(); } else if (element instanceof LeafElement) { if (element instanceof RunElement) { RunElement runElement = (RunElement) element; AttributeSet attrSet = (AttributeSet) runElement.getAttribute(Tag.A); if (attrSet != null) { hyperlink = new JRBasePrintHyperlink(); hyperlink.setHyperlinkType(HyperlinkTypeEnum.REFERENCE); hyperlink.setHyperlinkReference((String) attrSet.getAttribute(HTML.Attribute.HREF)); hyperlink.setLinkTarget((String) attrSet.getAttribute(HTML.Attribute.TARGET)); } } try { chunk = document.getText(startOffset, endOffset - startOffset); } catch (BadLocationException e) { if (log.isDebugEnabled()) { log.debug("Error converting markup.", e); } } } } } if (chunk != null) { if (!"\n".equals(chunk)) { text.append(chunk); Map<Attribute, Object> styleAttributes = getAttributes(element.getAttributes()); if (hyperlink != null) { styleAttributes.put(JRTextAttribute.HYPERLINK, hyperlink); hyperlink = null; } if (!styleAttributes.isEmpty()) { styleRuns.add( new JRStyledText.Run(styleAttributes, startOffset + crtOffset, endOffset + crtOffset)); } } else { //final newline, not appending //check if there's any style run that would have covered it, that can happen if there's a <li> tag with style int length = text.length(); for (ListIterator<JRStyledText.Run> it = styleRuns.listIterator(); it.hasNext();) { JRStyledText.Run run = it.next(); //only looking at runs that end at the position where the newline should have been //we don't want to hide bugs in which runs that span after the text length are created if (run.endIndex == length + 1) { if (run.startIndex < run.endIndex - 1) { it.set(new JRStyledText.Run(run.attributes, run.startIndex, run.endIndex - 1)); } else { it.remove(); } } } } } JRStyledText styledText = new JRStyledText(null, text.toString()); for (JRStyledText.Run run : styleRuns) { styledText.addRun(run); } styledText.setGlobalAttributes(new HashMap<Attribute, Object>()); return JRStyledTextParser.getInstance().write(styledText); }
From source file:edu.ku.brc.specify.config.SpecifyExceptionTracker.java
@Override protected FeedBackSenderItem getFeedBackSenderItem(final Class<?> cls, final Exception exception) { CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g", "p,8px,p,2px, p,4px,p,2px,f:p:g")); Vector<Taskable> taskItems = new Vector<Taskable>(TaskMgr.getInstance().getAllTasks()); Collections.sort(taskItems, new Comparator<Taskable>() { @Override/*from w ww .ja va 2 s. c om*/ public int compare(Taskable o1, Taskable o2) { return o1.getName().compareTo(o2.getName()); } }); final JTextArea commentsTA = createTextArea(3, 60); final JTextArea stackTraceTA = createTextArea(15, 60); final JCheckBox moreBtn; commentsTA.setWrapStyleWord(true); commentsTA.setLineWrap(true); //JLabel desc = createI18NLabel("UNHDL_EXCP", SwingConstants.LEFT); JEditorPane desc = new JEditorPane("text/html", getResourceString("UNHDL_EXCP")); desc.setEditable(false); desc.setOpaque(false); //desc.setFont(new Font(Font.SANS_SERIF, Font.BOLD, (new JLabel("X")).getFont().getSize())); JScrollPane sp = new JScrollPane(stackTraceTA, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); int y = 1; pb.add(desc, cc.xyw(1, y, 4)); y += 2; pb.add(createI18NFormLabel("UNHDL_EXCP_CMM"), cc.xy(1, y)); y += 2; pb.add(createScrollPane(commentsTA, true), cc.xyw(1, y, 4)); y += 2; forwardImgIcon = IconManager.getIcon("Forward"); //$NON-NLS-1$ downImgIcon = IconManager.getIcon("Down"); //$NON-NLS-1$ moreBtn = new JCheckBox(getResourceString("LOGIN_DLG_MORE"), forwardImgIcon); //$NON-NLS-1$ setControlSize(moreBtn); JButton copyBtn = createI18NButton("UNHDL_EXCP_COPY"); PanelBuilder innerPB = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,2px,p:g,2px,p")); innerPB.add(createI18NLabel("UNHDL_EXCP_STK"), cc.xy(1, 1)); innerPB.add(sp, cc.xyw(1, 3, 3)); innerPB.add(copyBtn, cc.xy(1, 5)); stackTracePanel = innerPB.getPanel(); stackTracePanel.setVisible(false); pb.add(moreBtn, cc.xyw(1, y, 4)); y += 2; pb.add(stackTracePanel, cc.xyw(1, y, 4)); y += 2; ByteArrayOutputStream baos = new ByteArrayOutputStream(); exception.printStackTrace(new PrintStream(baos)); stackTraceTA.setText(baos.toString()); moreBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (stackTracePanel.isVisible()) { stackTracePanel.setVisible(false); moreBtn.setIcon(forwardImgIcon); } else { stackTracePanel.setVisible(true); moreBtn.setIcon(downImgIcon); } if (dlg != null) { dlg.pack(); } } }); copyBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String taskName = getTaskName(); FeedBackSenderItem item = new FeedBackSenderItem(taskName, "", "", commentsTA.getText(), stackTraceTA.getText(), cls.getName()); NameValuePair[] pairs = createPostParameters(item); StringBuilder sb = new StringBuilder(); for (NameValuePair pair : pairs) { if (!pair.getName().equals("bug")) { sb.append(pair.getName()); sb.append(": "); if (pair.getName().equals("comments") || pair.getName().equals("stack_trace")) { sb.append("\n"); } sb.append(pair.getValue()); sb.append("\n"); } } // Copy to Clipboard UIHelper.setTextToClipboard(sb.toString()); } }); pb.setDefaultDialogBorder(); dlg = new CustomDialog((Frame) null, getResourceString("UnhandledExceptionTitle"), true, CustomDialog.OK_BTN, pb.getPanel()); dlg.setOkLabel(getResourceString("UNHDL_EXCP_SEND")); dlg.createUI(); stackTracePanel.setVisible(false); centerAndShow(dlg); String taskName = getTaskName(); FeedBackSenderItem item = new FeedBackSenderItem(taskName, "", "", commentsTA.getText(), stackTraceTA.getText(), cls.getName()); return item; }
From source file:edu.ku.brc.specify.plugins.ipadexporter.VerifyCollectionDlg.java
@SuppressWarnings({ "unchecked" }) @Override/*from w ww .j ava 2s . c o m*/ public void createUI() { loadAndPushResourceBundle(iPadDBExporterPlugin.RESOURCE_NAME); setTitle(getResourceString("VERIFY_TITLE")); try { htmlPane = new JEditorPane("text/html", ""); //$NON-NLS-1$ final JScrollPane scrollPane = UIHelper.createScrollPane(htmlPane); //this.add(scrollPane, BorderLayout.CENTER); htmlPane.setEditable(false); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:700px:g", "f:500px:g")); contentPanel = pb.getPanel(); pb.add(scrollPane, cc.xy(1, 1)); pb.setDefaultDialogBorder(); setOkLabel("Continue"); setCancelLabel("Close"); setHelpLabel("To Browser"); worker = new SwingWorker<Integer, Integer>() { @Override protected Integer doInBackground() throws Exception { processResults(); return 0; } @Override protected void done() { super.done(); popResourceBundle(); } }; //addProgressListener(worker); worker.execute(); } catch (Exception ex) { ex.printStackTrace(); } finally { popResourceBundle(); } setSize(800, 650); setBounds(0, 0, 650, 650); super.createUI(); okBtn.setEnabled(false); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // Must be called at the end 'createUI' }
From source file:com.microsoft.tfs.client.common.ui.controls.generic.CompatibleBrowser.java
public CompatibleBrowser(final Composite parent, final int style) { super(parent, style); Check.notNull(parent, "parent"); //$NON-NLS-1$ final GridLayout gridLayout = new GridLayout(1, true); gridLayout.marginHeight = 0;//from w ww .j av a2s . c o m gridLayout.marginWidth = 0; setLayout(gridLayout); if (isNativeBrowserAvailable()) { log.info(MessageFormat.format("{0} using SWT Browser", CompatibleBrowser.class.getName())); //$NON-NLS-1$ final GridData gd = new GridData(); gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment = SWT.FILL; gd.grabExcessVerticalSpace = true; gd.verticalAlignment = SWT.FILL; browser = new Browser(this, style); browser.setLayoutData(gd); editorPane = null; } else { log.info(MessageFormat.format("{0} using JEditorPane", CompatibleBrowser.class.getName())); //$NON-NLS-1$ browser = null; JEditorPane tempEditorPane = null; CompatibilityLinkControl tempErrorLabel = null; /* * Embedded AWT widgets must be in a Composite with SWT.EMBEDDED * set, so create one. */ final Composite embeddableComposite = new Composite(this, SWT.EMBEDDED); final GridData compositeGridData = new GridData(); compositeGridData.grabExcessHorizontalSpace = true; compositeGridData.horizontalAlignment = SWT.FILL; compositeGridData.grabExcessVerticalSpace = true; compositeGridData.verticalAlignment = SWT.FILL; embeddableComposite.setLayoutData(compositeGridData); /* * We have to skip trying AWT entirely some places. */ boolean loadedAWTBrowser = false; if (CompatibleBrowser.isAWTDangerousHere() == false) { try { /* * Create a Frame in the SWT Composite as the top-level * element. */ final Frame browserFrame = SWT_AWT.new_Frame(embeddableComposite); /* * Create a panel with a simple BorderLayout to hold * contents. */ final Panel panel = new Panel(new BorderLayout()); browserFrame.add(panel); /* * Create an JEditorPane with an HTML document. */ final String pageContents = "<html><body></body></html>"; //$NON-NLS-1$ tempEditorPane = new JEditorPane("text/html", pageContents); //$NON-NLS-1$ tempEditorPane.setEditable(false); /* * Put the HTML viewer in a scroll pane and parent the * scroll pane in the panel. */ final JScrollPane scrollPane = new JScrollPane(tempEditorPane); panel.add(scrollPane); loadedAWTBrowser = true; } catch (final Throwable t) { log.warn("Error embedding AWT frame for JEditorPane", t); //$NON-NLS-1$ } } if (loadedAWTBrowser == false) { /* * We don't need the embeddable composite because AWT embedding * failed, and we can't put normal (error label) things in it, * so hide it. */ compositeGridData.widthHint = 0; compositeGridData.heightHint = 0; tempErrorLabel = CompatibilityLinkFactory.createLink(this, SWT.NONE); tempErrorLabel.setText( MessageFormat.format(Messages.getString("CompatibleBrowser.CouldNotLoadSWTBrowserFormat"), //$NON-NLS-1$ AWT_TOOLKIT_ENV_VAR_NAME, XTOOLKIT_ENV_VAR_VALUE)); final GridData labelGridData = new GridData(); labelGridData.grabExcessHorizontalSpace = true; labelGridData.horizontalAlignment = SWT.FILL; labelGridData.grabExcessVerticalSpace = true; labelGridData.verticalAlignment = SWT.FILL; tempErrorLabel.getControl().setLayoutData(labelGridData); } editorPane = tempEditorPane; } }
From source file:com.rapidminer.gui.flow.processrendering.annotations.AnnotationDrawUtils.java
/** * Calculates the preferred height of an editor pane with the given fixed width for the * specified string.//from ww w. j a v a 2 s . com * * @param comment * the annotation comment string * @param width * the width of the content * @return the preferred height given the comment */ public static int getContentHeight(final String comment, final int width) { if (comment == null) { throw new IllegalArgumentException("comment must not be null!"); } JEditorPane dummyEditorPane = new JEditorPane("text/html", ""); dummyEditorPane.setText(comment); dummyEditorPane.setBorder(null); dummyEditorPane.setSize(width, Short.MAX_VALUE); // height is not exact. Multiply by magic number to get a more fitting value... if (SystemInfoUtilities.getOperatingSystem() == OperatingSystem.OSX || SystemInfoUtilities.getOperatingSystem() == OperatingSystem.UNIX || SystemInfoUtilities.getOperatingSystem() == OperatingSystem.SOLARIS) { return (int) (dummyEditorPane.getPreferredSize().getHeight() * 1.05f); } else { return (int) dummyEditorPane.getPreferredSize().getHeight(); } }
From source file:jamel.gui.JamelWindow.java
/** * Creates and returns the consol panel. * @return the consol panel./*from w w w . ja v a 2s . com*/ */ private JScrollPane getConsolePanel() { consolePane = new JEditorPane("text/html", "<h2>The console panel.</h2>"); consolePane.setEditable(false); JScrollPane scrollPane = new JScrollPane(consolePane); return scrollPane; }
From source file:jamel.gui.JamelWindow.java
/** * Returns the info panel.//w w w . j a v a 2 s . co m * @return the info panel. */ private Component getInfoPanel() { final JEditorPane editorPane = new JEditorPane("text/html", "<center>" + this.infoString + "</center>"); editorPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) try { java.awt.Desktop.getDesktop().browse(e.getURL().toURI()); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "<html>" + "Error.<br>" + "Cause: " + e.toString() + ".<br>" + "Please see server.log for more details.</html>", "Warning", JOptionPane.WARNING_MESSAGE); } } }); editorPane.setEditable(false); final JScrollPane scrollPane = new JScrollPane(editorPane); return scrollPane; }
From source file:jamel.gui.JamelWindow.java
/** * Returns the matrix panel.//from ww w. j av a 2s.c o m * @return the matrix panel. */ private JScrollPane getMatrixPanel() { matrixPane = new JEditorPane("text/html", "<H2>The balance sheet matrix panel.</H2>"); matrixPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(matrixPane); return scrollPane; }