public NodeDisplay() { super(new BorderLayout()); // setPreferredSize(new Dimension(300, 300)); editorPane = new JEditorPane(); editorPane.setEditorKit(new HTMLEditorKit()); add(new JScrollPane(editorPane), BorderLayout.CENTER); }
/** * Creates component. * * @param collection collection to show. * @param treeMode <code>TRUE</code> to set tree mode by default. * @param readingLists <code>TRUE</code> if showing reading lists. */ public CListTree(Collection collection, boolean treeMode, boolean readingLists) { this.collection = collection; this.readingLists = readingLists; itemListener = new CItemListener(); setLayout(new BorderLayout()); setTreeMode(treeMode); BBFormBuilder builder = new BBFormBuilder("p, 2dlu, p, 0:grow"); JComboBox cbViewMode = new JComboBox( new Object[] { Strings.message("collections.viewmode.tree"), Strings.message("collections.viewmode.list") }); cbViewMode.setSelectedIndex(treeMode ? 0 : 1); cbViewMode.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { JComboBox box = (JComboBox) e.getSource(); boolean isTree = box.getSelectedIndex() == 0; setTreeMode(isTree); } }); builder.append(Strings.message("collections.viewmode"), cbViewMode); builder.appendRelatedComponentsGapRow(2); add(builder.getPanel(), BorderLayout.NORTH); // Description area taDescription = new JEditorPane(); Color back = taDescription.getBackground(); taDescription.setEditable(false); taDescription.setBackground(back); taDescription.setEditorKit(new CustomHTMLEditorKit()); HTMLDocument doc = (HTMLDocument) taDescription.getDocument(); Style def = doc.getStyle("default"); Font font = UIManager.getFont("TextArea.font"); if (SystemUtils.IS_OS_MAC) font = UifUtilities.applyFontBias(font, -2); UifUtilities.setFontAttributes(doc.addStyle(TEXT_STYLE, def), font); builder = new BBFormBuilder("0:grow"); builder.appendUnrelatedComponentsGapRow(2); builder.appendRow("p"); builder.append(Strings.message("collections.description"), 1); builder.appendRelatedComponentsGapRow(2); builder.appendRow("50px"); builder.append(taDescription, 1, CellConstraints.FILL, CellConstraints.FILL); add(builder.getPanel(), BorderLayout.SOUTH); }
private void initComponents() { setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); messagePane.setBackground(contentPane.getBackground()); messagePane.setEditorKit(new HTMLEditorKit()); messagePane.setForeground(contentPane.getForeground()); setSize(450, 360); // center the window int x = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() - getWidth()) / 2; int y = (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() - getHeight()) / 2; setLocation(x, y); okButton.addActionListener(this); }
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 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; }
/** Constructor - creates layout. */ public HelpFrame() { setTitle("Web-Harvest Help"); setIconImage(((ImageIcon) ResourceManager.HELP32_ICON).getImage()); this.topNode = new DefaultMutableTreeNode(); this.treeModel = new DefaultTreeModel(this.topNode); try { String helpContent = CommonUtil.readStringFromUrl(ResourceManager.getHelpContentUrl()); XmlNode xmlNode = XmlParser.parse(new InputSource(new StringReader(helpContent))); createNodes(topNode, xmlNode); } catch (Exception e) { e.printStackTrace(); GuiUtils.showErrorMessage("Error reading help content!"); } tree = new JTree(topNode); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.setBorder(new EmptyBorder(5, 5, 5, 5)); tree.setCellRenderer( new DefaultTreeCellRenderer() { public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus); if (value instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) value; Object userObject = defaultMutableTreeNode.getUserObject(); if (userObject instanceof TopicInfo) { TopicInfo topicInfo = (TopicInfo) userObject; renderer.setIcon( topicInfo.subtopicCount == 0 ? ResourceManager.HELPTOPIC_ICON : ResourceManager.HELPDIR_ICON); } } return renderer; } }); tree.addTreeSelectionListener(this); htmlPane = new JEditorPane(); htmlPane.setEditable(false); htmlPane.setContentType("text/html"); htmlPane.setEditorKit(new HTMLEditorKit()); htmlPane.setBorder(new EmptyBorder(5, 5, 5, 5)); JSplitPane splitPane = new ProportionalSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.setResizeWeight(0.0d); splitPane.setBorder(null); JScrollPane treeScrollPane = new WHScrollPane(tree); treeScrollPane.getViewport().setBackground(Color.white); treeScrollPane.setBackground(Color.white); splitPane.setLeftComponent(treeScrollPane); splitPane.setRightComponent(new WHScrollPane(htmlPane)); splitPane.setDividerLocation(0.3d); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(splitPane, BorderLayout.CENTER); pack(); }
public NcmlEditor(JPanel buttPanel, PreferencesExt prefs) { this.prefs = prefs; fileChooser = new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager")); AbstractAction coordAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { addCoords = (Boolean) getValue(BAMutil.STATE); String tooltip = addCoords ? "add Coordinates is ON" : "add Coordinates is OFF"; coordButt.setToolTipText(tooltip); } }; addCoords = prefs.getBoolean("coordState", false); String tooltip2 = addCoords ? "add Coordinates is ON" : "add Coordinates is OFF"; BAMutil.setActionProperties(coordAction, "addCoords", tooltip2, true, 'C', -1); coordAction.putValue(BAMutil.STATE, Boolean.valueOf(addCoords)); coordButt = BAMutil.addActionToContainer(buttPanel, coordAction); protoChooser = new ComboBox((PreferencesExt) prefs.node("protoChooser")); addProtoChoices(); buttPanel.add(protoChooser); protoChooser.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String ptype = (String) protoChooser.getSelectedItem(); String proto = protoMap.get(ptype); if (proto != null) { editor.setText(proto); } } }); editor = new JEditorPane(); // Instantiate a XMLEditorKit with wrapping enabled. XMLEditorKit kit = new XMLEditorKit(false); // Set the wrapping style. kit.setWrapStyleWord(true); editor.setEditorKit(kit); // Set the font style. editor.setFont(new Font("Monospaced", Font.PLAIN, 12)); // Set the tab size editor.getDocument().putProperty(PlainDocument.tabSizeAttribute, 2); // Enable auto indentation. editor.getDocument().putProperty(XMLDocument.AUTO_INDENTATION_ATTRIBUTE, true); // Enable tag completion. editor.getDocument().putProperty(XMLDocument.TAG_COMPLETION_ATTRIBUTE, true); // Initialise the folding kit.setFolding(true); // Set a style kit.setStyle(XMLStyleConstants.ATTRIBUTE_NAME, Color.RED, Font.BOLD); // Put the editor in a panel that will force it to resize, when a different view is choosen. ScrollableEditorPanel editorPanel = new ScrollableEditorPanel(editor); JScrollPane scroller = new JScrollPane(editorPanel); // Add the number margin as a Row Header View scroller.setRowHeaderView(new LineNumberMargin(editor)); AbstractAction wrapAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { XMLEditorKit kit = (XMLEditorKit) editor.getEditorKit(); kit.setLineWrappingEnabled(!kit.isLineWrapping()); editor.updateUI(); } }; BAMutil.setActionProperties(wrapAction, "Wrap", "Toggle Wrapping", false, 'W', -1); BAMutil.addActionToContainer(buttPanel, wrapAction); AbstractAction saveAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { String location = (ds == null) ? ncmlLocation : ds.getLocation(); if (location == null) location = "test"; int pos = location.lastIndexOf("."); if (pos > 0) location = location.substring(0, pos); String filename = fileChooser.chooseFilenameToSave(location + ".ncml"); if (filename == null) return; if (doSaveNcml(editor.getText(), filename)) ncmlLocation = filename; } }; BAMutil.setActionProperties(saveAction, "Save", "Save NcML", false, 'S', -1); BAMutil.addActionToContainer(buttPanel, saveAction); AbstractAction netcdfAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (outChooser == null) { outChooser = new NetcdfOutputChooser((Frame) null); outChooser.addPropertyChangeListener( "OK", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { writeNetcdf((NetcdfOutputChooser.Data) evt.getNewValue()); } }); } String location = (ds == null) ? ncmlLocation : ds.getLocation(); if (location == null) location = "test"; int pos = location.lastIndexOf("."); if (pos > 0) location = location.substring(0, pos); outChooser.setOutputFilename(location); outChooser.setVisible(true); } }; BAMutil.setActionProperties(netcdfAction, "netcdf", "Write netCDF file", false, 'N', -1); BAMutil.addActionToContainer(buttPanel, netcdfAction); AbstractAction transAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { doTransform(editor.getText()); } }; BAMutil.setActionProperties( transAction, "Import", "read textArea through NcMLReader\n write NcML back out via resulting dataset", false, 'T', -1); BAMutil.addActionToContainer(buttPanel, transAction); AbstractButton compareButton = BAMutil.makeButtcon("Select", "Check NcML", false); compareButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Formatter f = new Formatter(); checkNcml(f); infoTA.setText(f.toString()); infoTA.gotoTop(); infoWindow.show(); } }); buttPanel.add(compareButton); setLayout(new BorderLayout()); add(scroller, BorderLayout.CENTER); // the info window infoTA = new TextHistoryPane(); infoWindow = new IndependentWindow("Extra Information", BAMutil.getImage("netcdfUI"), infoTA); infoWindow.setBounds( (Rectangle) prefs.getBean("InfoWindowBounds", new Rectangle(300, 300, 500, 300))); }