private void setDataInternal( SmartPsiElementPointer element, String text, final Rectangle viewRect, boolean skip) { boolean justShown = false; myElement = element; if (!myIsShown && myHint != null) { myEditorPane.setText(text); applyFontSize(); myManager.showHint(myHint); myIsShown = justShown = true; } if (!justShown) { myEditorPane.setText(text); applyFontSize(); } if (!skip) { myText = text; } SwingUtilities.invokeLater( new Runnable() { @Override public void run() { myEditorPane.scrollRectToVisible(viewRect); } }); }
public int computeDocumentOffset(int line, int column) throws BadLocationException { if (line < 0 || column < 0) throw new BadLocationException("Negative line/col", -1); Element lineElement = editor.getDocument().getDefaultRootElement().getElement(line - 1); int beginLineOffset = lineElement.getStartOffset(); int endLineOffset = lineElement.getEndOffset(); String text = editor.getDocument().getText(beginLineOffset, endLineOffset - beginLineOffset); int parserChar = 1; int documentChar = 0; while (parserChar < column) { if (documentChar < text.length() && text.charAt(documentChar) == '\t') { parserChar += 8; documentChar += 1; } else { parserChar += 1; documentChar += 1; } } return beginLineOffset + documentChar; }
public static void main(String[] args) { StringBuffer result = new StringBuffer("<html><body><h1>Fibonacci Sequence</h1><ol>"); long f1 = 0; long f2 = 1; for (int i = 0; i < 50; i++) { result.append("<li>"); result.append(f1); long temp = f2; f2 = f1 + f2; f1 = temp; } result.append("</ol></body></html>"); JEditorPane jep = new JEditorPane("text/html", result.toString()); jep.setEditable(false); // new FibonocciRectangles().execute(); JScrollPane scrollPane = new JScrollPane(jep); JFrame f = new JFrame("Fibonacci Sequence"); f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); f.setContentPane(scrollPane); f.setSize(512, 342); EventQueue.invokeLater(new FrameShower(f)); }
public void delete() { try { editor .getDocument() .remove( editor.getSelectionStart(), editor.getSelectionEnd() - editor.getSelectionStart()); } catch (BadLocationException ex) { // GUIPrism.getGUI().getMultiLogger().logMessage(PrismLogLevel.PRISM_ERROR, ex.getMessage()); } }
/** * Loads the model editor with the text from the given stream reader, discards any previous * content in the editor. * * @param reader A character stream reader * @param object An object describing the stream; this might be a string, a File, a URL, etc. * @throws IOException Thrown if there was an IO error reading the input stream. */ public void read(Reader reader, Object object) throws IOException { editor.getDocument().removeUndoableEditListener(undoManager); editor.read(reader, object); // For some unknown reason the listeners have to be added both here // and in the constructor, if they're not added here the editor won't // be listening. editor.getDocument().addDocumentListener(this); editor.getDocument().addUndoableEditListener(undoManager); }
public HtmlPane() { try { URL url = getClass().getResource("/resources/HelpFiles/toc.html"); html = new JEditorPane(url); html.setEditable(false); html.addHyperlinkListener(this); html.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); JViewport vp = getViewport(); vp.add(html); } catch (MalformedURLException e) { System.out.println("Malformed URL: " + e); } catch (IOException e) { System.out.println("IOException: " + e); } }
/** * Called when the selection changed in the tree. Loads the selected certificate. * * @param e the event */ private void valueChangedPerformed(TreeSelectionEvent e) { Object o = e.getNewLeadSelectionPath().getLastPathComponent(); if (o instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) o; infoTextPane.setText(toString(node.getUserObject())); } }
public void jumpToError() { if (parseError != null && parseError.hasLineNumbers()) { try { int offset = computeDocumentOffset(parseError.getBeginLine(), parseError.getBeginColumn()); // scroll to center as much as possible. editor.setCaretPosition(offset); Rectangle r1 = editor.modelToView(offset); int dy = (editor.getVisibleRect().height - r1.height) / 2; Rectangle r2 = new Rectangle(0, r1.y - dy, editor.getVisibleRect().width, r1.height + 2 * dy); editor.scrollRectToVisible(r2); } catch (BadLocationException e) { } } }
@Override public Object getData(@NonNls String dataId) { if (DocumentationManager.SELECTED_QUICK_DOC_TEXT.getName().equals(dataId)) { return myEditorPane.getSelectedText(); } return null; }
public HtmlPane(String helpFileName) { try { File f = new File(helpFileName); String s = f.getAbsolutePath(); s = "file:" + s; URL url = new URL(s); html = new JEditorPane(s); html.setEditable(false); html.addHyperlinkListener(this); JViewport vp = getViewport(); vp.add(html); } catch (MalformedURLException e) { System.out.println("Malformed URL: " + e); } catch (IOException e) { System.out.println("IOException: " + e); } }
public void refreshErrorDisplay() { if (parseErrorHighlightKey != null) editor.getHighlighter().removeHighlight(parseErrorHighlightKey); /* Mapping for gutter */ Map<Integer, String> errorLines = new HashMap<Integer, String>(); if (parseError != null && parseError.hasLineNumbers()) { String error = parseError.getMessage(); // Just the first line. errorLines.put(parseError.getBeginLine(), error); // If error spans multiple lines, this code will put // an error in every line of the gutter. /*for (int line = parseError.getBeginLine(); line <= parseError.getEndLine(); line++) { errorLines.put(line, error); }*/ } gutter.setParseErrors(errorLines); /* Highlighting errors in editor */ if (parseError != null && parseError.hasLineNumbers()) { /* Remove existing highlight */ try { parseErrorHighlightKey = editor .getHighlighter() .addHighlight( computeDocumentOffset(parseError.getBeginLine(), parseError.getBeginColumn()), computeDocumentOffset(parseError.getEndLine(), parseError.getEndColumn()) + 1, errorHighlightPainter); } catch (BadLocationException e) { } } }
@Override public Object getData(@NonNls String dataId) { if (DocumentationManager.SELECTED_QUICK_DOC_TEXT.getName().equals(dataId)) { // Javadocs often contain symbols (non-breakable white space). We don't want to copy // them as is and replace // with raw white spaces. See IDEA-86633 for more details. String selectedText = myEditorPane.getSelectedText(); return selectedText == null ? null : selectedText.replace((char) 160, ' '); } return null; }
public boolean canDoClipBoardAction(Action action) { if (action == GUIPrism.getClipboardPlugin().getPasteAction()) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); return (clipboard.getContents(null) != null); } else if (action == GUIPrism.getClipboardPlugin().getCutAction() || action == GUIPrism.getClipboardPlugin().getCopyAction() || action == GUIPrism.getClipboardPlugin().getDeleteAction()) { return (editor.getSelectedText() != null); } else if (action == GUIPrism.getClipboardPlugin().getSelectAllAction()) { return true; } return handler.canDoClipBoardAction(action); }
private void applyFontSize() { Document document = myEditorPane.getDocument(); if (!(document instanceof StyledDocument)) { return; } StyledDocument styledDocument = (StyledDocument) document; if (myFontSizeStyle == null) { myFontSizeStyle = styledDocument.addStyle("active", null); } EditorColorsManager colorsManager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = colorsManager.getGlobalScheme(); StyleConstants.setFontSize(myFontSizeStyle, scheme.getQuickDocFontSize().getSize()); if (Registry.is("documentation.component.editor.font")) { StyleConstants.setFontFamily(myFontSizeStyle, scheme.getEditorFontName()); } styledDocument.setCharacterAttributes(0, document.getLength(), myFontSizeStyle, false); }
/** * Helper method that initializes the items for the context menu. This menu will include cut, * copy, paste, undo/redo, and find/replace functionality. */ private void initContextMenu() { contextPopup = new JPopupMenu(); // Edit menu stuff contextPopup.add(GUIPrism.getClipboardPlugin().getUndoAction()); contextPopup.add(GUIPrism.getClipboardPlugin().getRedoAction()); contextPopup.add(new JSeparator()); contextPopup.add(GUIPrism.getClipboardPlugin().getCutAction()); contextPopup.add(GUIPrism.getClipboardPlugin().getCopyAction()); contextPopup.add(GUIPrism.getClipboardPlugin().getPasteAction()); contextPopup.add(GUIPrism.getClipboardPlugin().getDeleteAction()); contextPopup.add(new JSeparator()); contextPopup.add(GUIPrism.getClipboardPlugin().getSelectAllAction()); contextPopup.add(new JSeparator()); // Model menu stuff contextPopup.add(((GUIMultiModel) handler.getGUIPlugin()).getParseModel()); contextPopup.add(((GUIMultiModel) handler.getGUIPlugin()).getBuildModel()); contextPopup.add(new JSeparator()); contextPopup.add(((GUIMultiModel) handler.getGUIPlugin()).getExportMenu()); contextPopup.add(((GUIMultiModel) handler.getGUIPlugin()).getViewMenu()); contextPopup.add(((GUIMultiModel) handler.getGUIPlugin()).getComputeMenu()); // contextPopup.add(actionJumpToError); // contextPopup.add(actionSearch); if (editor.getContentType().equals("text/prism")) { JMenu insertMenu = new JMenu("Insert elements"); JMenu insertModelTypeMenu = new JMenu("Model type"); insertMenu.add(insertModelTypeMenu); JMenu insertModule = new JMenu("Module"); insertMenu.add(insertModule); JMenu insertVariable = new JMenu("Variable"); insertMenu.add(insertVariable); insertModelTypeMenu.add(insertDTMC); insertModelTypeMenu.add(insertCTMC); insertModelTypeMenu.add(insertMDP); // contextPopup.add(new JSeparator()); // contextPopup.add(insertMenu); } }
/** * @param baseURL may be <code>null</code> * @see PropertyPanel.PropertyField#setText */ void setText(String text, String baseURL, DocumentListener documentListener) { // textComponent.getDocument().removeDocumentListener(documentListener); // if (editorType == EDITOR_TYPE_STYLED) { // // --- set content type --- ((JEditorPane) textComponent).setContentType("text/html"); // // --- set base URL --- try { // Note: baseURL is null if no baseURL is set for the corresponding property // Note: baseURL is empty if corporate baseURL is used but not set if (baseURL != null && !baseURL.equals("")) { ((HTMLDocument) textComponent.getDocument()).setBase(new URL(baseURL)); } } catch (MalformedURLException mue) { System.out.println("*** TextEditorPanel.setText(): invalid base URL: " + mue); } // // --- set text --- try { if (text.length() <= 59) { // ### 59 <html><head></head><body></body></html> + whitespace text = "<html><body><p></p></body></html>"; } textComponent.setText(text); textComponent.setCaretPosition(0); } catch (Throwable e) { textComponent.setText( "<html><body><font color=#FF0000>Page can't be displayed</font></body></html>"); System.out.println("*** TextEditorPanel.setText(): error while HTML rendering: " + e); } } else { textComponent.setText(text); textComponent.setCaretPosition(0); } // textComponent.getDocument().addDocumentListener(documentListener); }
public OrderTrans2() { super(windowTitle); int i; int currentPanel; // Value to specify which is the current panel in the vector JPanel subPanel = new JPanel(); // value used when adding sliders to the frame Runtime program = Runtime.getRuntime(); Container content = getContentPane(); createSliderVector(); createPanelVector(); getCodeSwapString(); /** Set code-swap strings' value. */ /** Get current OS of the system. */ if (System.getProperty("os.name").startsWith("Windows")) isWindows = true; else isWindows = false; /** Add the radio buttons to the group */ radioGrp.add(firstBox); radioGrp.add(secondBox); /** Set interactive buttons for the user interface */ JButton exeButton = new JButton("Execute"); exeButton.setToolTipText("Re-execute the program"); JButton resetButton = new JButton("Reset"); resetButton.setToolTipText("Reset Value"); JButton exitButton = new JButton("Exit"); exitButton.setToolTipText("Exit the Program"); // Create the main panel that contains everything. JPanel mainPanel = new JPanel(); // Create the panel that contains the sliders JPanel subPanel1 = new JPanel(); // Create the panel that contains the checkboxes JPanel subPanel2 = new JPanel(); // Create the panel that contains the buttons JPanel subPanel3 = new JPanel(); // JScrollPane scrollPane = new JScrollPane(); // main text pane with scroll bars content.add(mainPanel, BorderLayout.SOUTH); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); content.add(scrollPane, BorderLayout.CENTER); scrollPane.setBorder(BorderFactory.createLoweredBevelBorder()); scrollPane.getViewport().add(textPane); mainPanel.add(subPanel1); mainPanel.add(subPanel2); mainPanel.add(subPanel3); subPanel1.setLayout(new GridLayout(0, 1)); /** Add subPanel elements to the subPanel1, each would be a row of sliders */ for (i = 0; i < ROWS; i++) subPanel1.add((JPanel) vSubPanel.elementAt(i)); /** Set the first element in the Panel Vector as the current subPanel. */ currentPanel = 0; subPanel = (JPanel) vSubPanel.elementAt(currentPanel); /** Allocate sliders to the sub-panels. */ for (i = 0; i < COMPONENTS; i++) { PSlider slider = (PSlider) vSlider.elementAt(i); if (slider.getResideValue() == 'n') { currentPanel += 1; subPanel = (JPanel) vSubPanel.elementAt(currentPanel); } subPanel.add((PSlider) vSlider.elementAt(i)); } /** Set and view the source code on the frame */ textPane.setEditable(false); textPane.setContentType("text/html; charset=EUC-JP"); subPanel2.setLayout(new GridLayout(0, 2)); subPanel2.add(firstBox); subPanel2.add(secondBox); subPanel3.setLayout(new GridLayout(0, 3)); subPanel3.add(exeButton); exeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExeCommand(); } }); subPanel3.add(resetButton); resetButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doResetCommand(); } }); subPanel3.add(exitButton); exitButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExitCommand(); } }); /** Run the illustrated program */ try { pid = program.exec(cmd); if (isWindows == false) { Process pid2 = null; pid2 = program.exec("getpid " + cmd.substring(4)); } } catch (IOException ie) { System.err.println("Couldn't run " + ie); // System.exit(-1);; } /** Set the initial status for the window */ addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { File fp = new File(dataFile); doResetCommand(); boolean delete = fp.delete(); pid.destroy(); } }); doExeCommand(); setSize(WIDTH, HEIGHT); setLocation(500, 0); setVisible(true); }
public void cut() { editor.cut(); }
public void paste() { editor.paste(); }
public DocumentationComponent( final DocumentationManager manager, final AnAction[] additionalActions) { myManager = manager; myIsEmpty = true; myIsShown = false; myEditorPane = new JEditorPane(UIUtil.HTML_MIME, "") { @Override public Dimension getPreferredScrollableViewportSize() { if (getWidth() == 0 || getHeight() == 0) { setSize(MAX_WIDTH, MAX_HEIGHT); } Insets ins = myEditorPane.getInsets(); View rootView = myEditorPane.getUI().getRootView(myEditorPane); rootView.setSize( MAX_WIDTH, MAX_HEIGHT); // Necessary! Without this line, size will not increase then you go // from small page to bigger one int prefHeight = (int) rootView.getPreferredSpan(View.Y_AXIS); prefHeight += ins.bottom + ins.top + myScrollPane.getHorizontalScrollBar().getMaximumSize().height; return new Dimension(MAX_WIDTH, Math.max(MIN_HEIGHT, Math.min(MAX_HEIGHT, prefHeight))); } { enableEvents(AWTEvent.KEY_EVENT_MASK); } @Override protected void processKeyEvent(KeyEvent e) { KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e); ActionListener listener = myKeyboardActions.get(keyStroke); if (listener != null) { listener.actionPerformed(new ActionEvent(DocumentationComponent.this, 0, "")); e.consume(); return; } super.processKeyEvent(e); } @Override protected void paintComponent(Graphics g) { GraphicsUtil.setupAntialiasing(g); super.paintComponent(g); } }; DataProvider helpDataProvider = new DataProvider() { @Override public Object getData(@NonNls String dataId) { return PlatformDataKeys.HELP_ID.is(dataId) ? DOCUMENTATION_TOPIC_ID : null; } }; myEditorPane.putClientProperty(DataManager.CLIENT_PROPERTY_DATA_PROVIDER, helpDataProvider); myText = ""; myEditorPane.setEditable(false); myEditorPane.setBackground(HintUtil.INFORMATION_COLOR); myEditorPane.setEditorKit(UIUtil.getHTMLEditorKit()); myScrollPane = new JBScrollPane(myEditorPane) { @Override protected void processMouseWheelEvent(MouseWheelEvent e) { if (!EditorSettingsExternalizable.getInstance().isWheelFontChangeEnabled() || !EditorUtil.isChangeFontSize(e)) { super.processMouseWheelEvent(e); return; } int change = Math.abs(e.getWheelRotation()); boolean increase = e.getWheelRotation() <= 0; EditorColorsManager colorsManager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = colorsManager.getGlobalScheme(); FontSize newFontSize = scheme.getQuickDocFontSize(); for (; change > 0; change--) { if (increase) { newFontSize = newFontSize.larger(); } else { newFontSize = newFontSize.smaller(); } } if (newFontSize == scheme.getQuickDocFontSize()) { return; } scheme.setQuickDocFontSize(newFontSize); applyFontSize(); setFontSizeSliderSize(newFontSize); } }; myScrollPane.setBorder(null); myScrollPane.putClientProperty(DataManager.CLIENT_PROPERTY_DATA_PROVIDER, helpDataProvider); final MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { myManager.requestFocus(); myShowSettingsButton.hideSettings(); } }; myEditorPane.addMouseListener(mouseAdapter); Disposer.register( this, new Disposable() { @Override public void dispose() { myEditorPane.removeMouseListener(mouseAdapter); } }); final FocusAdapter focusAdapter = new FocusAdapter() { @Override public void focusLost(FocusEvent e) { Component previouslyFocused = WindowManagerEx.getInstanceEx() .getFocusedComponent(manager.getProject(getElement())); if (!(previouslyFocused == myEditorPane)) { if (myHint != null && !myHint.isDisposed()) myHint.cancel(); } } }; myEditorPane.addFocusListener(focusAdapter); Disposer.register( this, new Disposable() { @Override public void dispose() { myEditorPane.removeFocusListener(focusAdapter); } }); setLayout(new BorderLayout()); JLayeredPane layeredPane = new JBLayeredPane() { @Override public void doLayout() { final Rectangle r = getBounds(); for (Component component : getComponents()) { if (component instanceof JScrollPane) { component.setBounds(0, 0, r.width, r.height); } else { int insets = 2; Dimension d = component.getPreferredSize(); component.setBounds(r.width - d.width - insets, insets, d.width, d.height); } } } @Override public Dimension getPreferredSize() { Dimension editorPaneSize = myEditorPane.getPreferredScrollableViewportSize(); Dimension controlPanelSize = myControlPanel.getPreferredSize(); return new Dimension( Math.max(editorPaneSize.width, controlPanelSize.width), editorPaneSize.height + controlPanelSize.height); } }; layeredPane.add(myScrollPane); layeredPane.setLayer(myScrollPane, 0); mySettingsPanel = createSettingsPanel(); layeredPane.add(mySettingsPanel); layeredPane.setLayer(mySettingsPanel, JLayeredPane.POPUP_LAYER); add(layeredPane, BorderLayout.CENTER); setOpaque(true); myScrollPane.setViewportBorder(JBScrollPane.createIndentBorder()); final DefaultActionGroup actions = new DefaultActionGroup(); final BackAction back = new BackAction(); final ForwardAction forward = new ForwardAction(); actions.add(back); actions.add(forward); actions.add(myExternalDocAction = new ExternalDocAction()); back.registerCustomShortcutSet(CustomShortcutSet.fromString("LEFT"), this); forward.registerCustomShortcutSet(CustomShortcutSet.fromString("RIGHT"), this); myExternalDocAction.registerCustomShortcutSet(CustomShortcutSet.fromString("UP"), this); if (additionalActions != null) { for (final AnAction action : additionalActions) { actions.add(action); } } myToolBar = ActionManager.getInstance() .createActionToolbar(ActionPlaces.JAVADOC_TOOLBAR, actions, true); myControlPanel = new JPanel(); myControlPanel.setLayout(new BorderLayout()); myControlPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM)); JPanel dummyPanel = new JPanel(); myElementLabel = new JLabel(); dummyPanel.setLayout(new BorderLayout()); dummyPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); dummyPanel.add(myElementLabel, BorderLayout.EAST); myControlPanel.add(myToolBar.getComponent(), BorderLayout.WEST); myControlPanel.add(dummyPanel, BorderLayout.CENTER); myControlPanel.add(myShowSettingsButton = new MyShowSettingsButton(), BorderLayout.EAST); myControlPanelVisible = false; final HyperlinkListener hyperlinkListener = new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { HyperlinkEvent.EventType type = e.getEventType(); if (type == HyperlinkEvent.EventType.ACTIVATED) { manager.navigateByLink(DocumentationComponent.this, e.getDescription()); } } }; myEditorPane.addHyperlinkListener(hyperlinkListener); Disposer.register( this, new Disposable() { @Override public void dispose() { myEditorPane.removeHyperlinkListener(hyperlinkListener); } }); registerActions(); updateControlState(); }
public void selectAll() { editor.selectAll(); }
// Here's where the font is set on the editor pane, and we also keep // track of the panes in use for future font updates. public void install(JEditorPane pane) { if (Settings.debug) System.err.println("Installing kit into pane"); delegate.install(pane); panes.add(pane); pane.setFont(Settings.font); }
public static JEditorPane initPane( @NonNls Html html, final HintHint hintHint, @Nullable final JLayeredPane layeredPane) { final Ref<Dimension> prefSize = new Ref<Dimension>(null); String htmlBody = UIUtil.getHtmlBody(html); @NonNls String text = "<html><head>" + UIUtil.getCssFontDeclaration( hintHint.getTextFont(), hintHint.getTextForeground(), hintHint.getLinkForeground(), hintHint.getUlImg()) + "</head><body>" + htmlBody + "</body></html>"; final boolean[] prefSizeWasComputed = {false}; final JEditorPane pane = new JEditorPane() { @Override public Dimension getPreferredSize() { if (!prefSizeWasComputed[0] && hintHint.isAwtTooltip()) { JLayeredPane lp = layeredPane; if (lp == null) { JRootPane rootPane = UIUtil.getRootPane(this); if (rootPane != null) { lp = rootPane.getLayeredPane(); } } Dimension size; if (lp != null) { size = lp.getSize(); prefSizeWasComputed[0] = true; } else { size = ScreenUtil.getScreenRectangle(0, 0).getSize(); } int fitWidth = (int) (size.width * 0.8); Dimension prefSizeOriginal = super.getPreferredSize(); if (prefSizeOriginal.width > fitWidth) { setSize(new Dimension(fitWidth, Integer.MAX_VALUE)); Dimension fixedWidthSize = super.getPreferredSize(); Dimension minSize = super.getMinimumSize(); prefSize.set( new Dimension( fitWidth > minSize.width ? fitWidth : minSize.width, fixedWidthSize.height)); } else { prefSize.set(new Dimension(prefSizeOriginal)); } } Dimension s = prefSize.get() != null ? new Dimension(prefSize.get()) : super.getPreferredSize(); Border b = getBorder(); if (b != null) { Insets insets = b.getBorderInsets(this); if (insets != null) { s.width += insets.left + insets.right; s.height += insets.top + insets.bottom; } } return s; } }; final HTMLEditorKit.HTMLFactory factory = new HTMLEditorKit.HTMLFactory() { @Override public View create(Element elem) { AttributeSet attrs = elem.getAttributes(); Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute); Object o = elementName != null ? null : attrs.getAttribute(StyleConstants.NameAttribute); if (o instanceof HTML.Tag) { HTML.Tag kind = (HTML.Tag) o; if (kind == HTML.Tag.HR) { return new CustomHrView(elem, hintHint.getTextForeground()); } } return super.create(elem); } }; HTMLEditorKit kit = new HTMLEditorKit() { @Override public ViewFactory getViewFactory() { return factory; } }; pane.setEditorKit(kit); pane.setText(text); pane.setCaretPosition(0); pane.setEditable(false); if (hintHint.isOwnBorderAllowed()) { setBorder(pane); setColors(pane); } else { pane.setBorder(null); } if (!hintHint.isAwtTooltip()) { prefSizeWasComputed[0] = true; } final boolean opaque = hintHint.isOpaqueAllowed(); pane.setOpaque(opaque); if (UIUtil.isUnderNimbusLookAndFeel() && !opaque) { pane.setBackground(UIUtil.TRANSPARENT_COLOR); } else { pane.setBackground(hintHint.getTextBackground()); } return pane; }
public boolean isEditable() { return editor.isEditable(); }
/** * Follows the reference in an link. The given url is the requested reference. By default this * calls <a href="#setPage">setPage</a>, and if an exception is thrown the original previous * document is restored and a beep sounded. If an attempt was made to follow a link, but it * represented a malformed url, this method will be called with a null argument. * * @param u the URL to follow */ protected void linkActivated(URL u) { Cursor c = html.getCursor(); Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); html.setCursor(waitCursor); SwingUtilities.invokeLater(new PageLoader(u, c)); }
public void setEditable(boolean b) { editor.setEditable(b); }
public void setEditorFont(Font f) { editor.setFont(f); }
/** * Constructs a X509 certificate panel. * * @param certificates <tt>X509Certificate</tt> objects */ public X509CertificatePanel(Certificate[] certificates) { setLayout(new BorderLayout(5, 5)); // Certificate chain list TransparentPanel topPanel = new TransparentPanel(new BorderLayout()); topPanel.add( new JLabel( "<html><body><b>" + R.getI18NString("service.gui.CERT_INFO_CHAIN") + "</b></body></html>"), BorderLayout.NORTH); DefaultMutableTreeNode top = new DefaultMutableTreeNode(); DefaultMutableTreeNode previous = top; for (int i = certificates.length - 1; i >= 0; i--) { Certificate cert = certificates[i]; DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert); previous.add(next); previous = next; } JTree tree = new JTree(top); tree.setBorder(new BevelBorder(BevelBorder.LOWERED)); tree.setRootVisible(false); tree.setExpandsSelectedPaths(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setCellRenderer( new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { JLabel component = (JLabel) super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus); if (value instanceof DefaultMutableTreeNode) { Object o = ((DefaultMutableTreeNode) value).getUserObject(); if (o instanceof X509Certificate) { component.setText(getSimplifiedName((X509Certificate) o)); } else { // We don't know how to represent this certificate type, // let's use the first 20 characters String text = o.toString(); if (text.length() > 20) { text = text.substring(0, 20); } component.setText(text); } } return component; } }); tree.getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { valueChangedPerformed(e); } }); tree.setSelectionPath( new TreePath((((DefaultTreeModel) tree.getModel()).getPathToRoot(previous)))); topPanel.add(tree, BorderLayout.CENTER); add(topPanel, BorderLayout.NORTH); // Certificate details pane Caret caret = infoTextPane.getCaret(); if (caret instanceof DefaultCaret) { ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE); } /* * Make JEditorPane respect our default font because we will be using it * to just display text. */ infoTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true); infoTextPane.setOpaque(false); infoTextPane.setEditable(false); infoTextPane.setContentType("text/html"); infoTextPane.setText(toString(certificates[0])); final JScrollPane certScroll = new JScrollPane(infoTextPane); certScroll.setPreferredSize(new Dimension(300, 500)); add(certScroll, BorderLayout.CENTER); }
public void setEditorBackground(Color c) { editor.setBackground(c); }
void doSourceFileUpdate() { BufferedReader bufferIn = null; String str1 = new String(); String strContent = new String(); String sliderValue = new String(); String newLine = System.getProperty("line.separator"); StringBuffer strBuf = new StringBuffer(); RandomAccessFile access = null; String tempFile = "temp" + round + ".html"; File fp = new File(tempFile); boolean firstChoice = true; int posFound = 0; int i = 0; PSlider slider; // round += 1; // Read the original source file to input buffer try { bufferIn = new BufferedReader(new FileReader(exampleSource)); } catch (FileNotFoundException fe) { System.err.println("Example Source File not found " + fe); // System.exit(-1);; } // get the first line of the buffer. try { str1 = bufferIn.readLine(); } catch (IOException ie) { System.err.println("Error reading line from the buffer " + ie); // System.exit(-1);; } // Transfer the whole content of the input buffer to the string try { do strContent += str1 + newLine; while ((str1 = bufferIn.readLine()) != null); } catch (IOException ie) { System.err.println("Error readding content of the input buffer " + ie); // System.exit(-1);; } // do the replacement. // First having to update the code part that is active in this section before // doing variables updated. Look at the current active radiobutton to make decision if (secondBox.isSelected() == true) firstChoice = false; if (firstChoice == true) { String tempStr = new String(); strBuf = new StringBuffer(strContent); posFound = strContent.indexOf(textStr2); tempStr = "<font color=blue>/***********" + newLine + textStr2 + newLine + "***********/</font>"; strBuf.replace(posFound, posFound + textStr2.length(), tempStr); strContent = new String(strBuf); } else { String tempStr = new String(); strBuf = new StringBuffer(strContent); posFound = strContent.indexOf(textStr1); tempStr = "<font color=blue>/***********" + newLine + textStr1 + newLine + "***********/</font>"; strBuf.replace(posFound, posFound + textStr1.length(), tempStr); strContent = new String(strBuf); } for (i = COMPONENTS; i > 0; i--) { // get the current value of slider slider = (PSlider) vSlider.elementAt(i - 1); sliderValue = slider.getValue(); // construct the search string str1 = "JPOT$" + i; // get the position of the search string in the content string. while ((posFound = strContent.indexOf(str1)) != -1) { strBuf = new StringBuffer(strContent); strBuf.replace(posFound, posFound + str1.length(), sliderValue); strContent = new String(strBuf); } } boolean delete = fp.delete(); try { fp.createNewFile(); } catch (IOException ie) { System.err.println("Couldn't create the new file " + ie); // System.exit(-1);; } try { access = new RandomAccessFile(fp, "rw"); } catch (IOException ie) { System.err.println("Error in accessing the file " + ie); // System.exit(-1);; } try { access.writeBytes(strContent); access.close(); } catch (IOException ie) { System.err.println("Error in writing to file " + ie); // System.exit(-1);; } try { textPane.getDocument().putProperty(Document.StreamDescriptionProperty, null); URL url = new URL("file:" + tempFile + "#gohere"); textPane.setPage(url); delete = fp.delete(); } catch (IOException ie) { System.err.println("Can not get the example html file " + ie); // System.exit(-1);; } }