private void initComponents() { { DefaultTableColumnModel model = new DefaultTableColumnModel(); TableColumn column = new TableColumn(0); column.setResizable(true); model.addColumn(column); column = new TableColumn(1, 120, new ButtonCellRenderer(), null); column.setMaxWidth(120); column.setResizable(false); model.addColumn(column); companionsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); companionsTable.getTableHeader().setResizingAllowed(false); companionsTable.setAutoCreateColumnsFromModel(false); companionsTable.setColumnModel(model); } companionsTable.setIntercellSpacing(new Dimension(0, 0)); companionsTable.setFocusable(false); companionsTable.setRowHeight(23); companionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setLeftComponent(new JScrollPane(companionsTable)); JPanel rightPane = new JPanel(new BorderLayout()); infoPane.setOpaque(false); infoPane.setEditable(false); infoPane.setFocusable(true); infoPane.setContentType("text/html"); // $NON-NLS-1$ rightPane.add(new JScrollPane(infoPane), BorderLayout.CENTER); JPanel buttonPane = new JPanel(new FlowLayout()); buttonPane.add(loadButton); rightPane.add(buttonPane, BorderLayout.SOUTH); setRightComponent(rightPane); }
public void actionPerformed(final AnActionEvent e) { @NonNls final String delim = " -> "; final StringBuffer buf = new StringBuffer(); processDependencies( getSelectedScope(myLeftTree), getSelectedScope(myRightTree), new Processor<List<PsiFile>>() { public boolean process(final List<PsiFile> path) { if (buf.length() > 0) buf.append("<br>"); buf.append( StringUtil.join( path, new Function<PsiFile, String>() { public String fun(final PsiFile psiFile) { return psiFile.getName(); } }, delim)); return true; } }); final JEditorPane pane = new JEditorPane(UIUtil.HTML_MIME, "<html>" + buf.toString() + "</html>"); pane.setForeground(Color.black); pane.setBackground(HintUtil.INFORMATION_COLOR); pane.setOpaque(true); final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane); final Dimension dimension = pane.getPreferredSize(); scrollPane.setMinimumSize(new Dimension(dimension.width, dimension.height + 20)); scrollPane.setPreferredSize(new Dimension(dimension.width, dimension.height + 20)); JBPopupFactory.getInstance() .createComponentPopupBuilder(scrollPane, pane) .setTitle("Dependencies") .setMovable(true) .createPopup() .showInBestPositionFor(e.getDataContext()); }
/** * 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 EditorPaneHTMLHelp(String htmlFile) { if (GlobalValues.useSystemBrowserForHelp) { Desktop d = GlobalValues.desktop; try { // create a temp file GlobalValues.forHTMLHelptempFile = new File("tempHTMLHelpSynthetic.html"); FileWriter fw = new FileWriter(GlobalValues.forHTMLHelptempFile); java.util.List<String> list = readTextFromJar(htmlFile); Iterator<String> it = list.iterator(); while (it.hasNext()) { fw.write(it.next() + "\n"); } String canonicalPathOfFile = GlobalValues.forHTMLHelptempFile.getCanonicalPath(); URL urlFile = new URL("file://" + canonicalPathOfFile); URI uriOfFile = urlFile.toURI(); fw.close(); d.browse(uriOfFile); } catch (Exception e) { e.printStackTrace(); } } else { URL initialURL = getClass().getResource(htmlFile); font = GlobalValues.htmlfont; String title = "HTML Help"; setTitle(title); final Stack<String> urlStack = new Stack<String>(); final JEditorPane editorPane; editorPane = new JEditorPane(new HTMLEditorKit().getContentType(), " "); editorPane.setOpaque(false); editorPane.setBorder(null); editorPane.setEditable(false); JPanel magPanel = new JPanel(); magnificationFactor = GlobalValues.helpMagnificationFactor; magFactor = new JTextField(Double.toString(magnificationFactor)); JButton magButton = new JButton("Set Magnification: "); magButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { magnificationFactor = Double.parseDouble(magFactor.getText()); GlobalValues.helpMagnificationFactor = magnificationFactor; } }); magPanel.setLayout(new GridLayout(1, 2)); magPanel.add(magButton); magPanel.add(magFactor); final JTextField url = new JTextField(initialURL.toString()); // set up hyperlink listener editorPane.setEditable(false); try { // remember URL for back button urlStack.push(initialURL.toString()); // show URL in text field url.setText(initialURL.toString()); // add a CSS rule to force body tags to use the default label font // instead of the value in javax.swing.text.html.default.csss String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() * GlobalValues.helpMagnificationFactor + "pt; }"; ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); editorPane.setPage(initialURL); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } editorPane.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() * GlobalValues.helpMagnificationFactor + "pt; }"; ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); } }); editorPane.addHyperlinkListener( new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { // remember URL for back button urlStack.push(event.getURL().toString()); // show URL in text field url.setText(event.getURL().toString()); editorPane.setPage(event.getURL()); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } } } }); // set up checkbox for toggling edit mode final JCheckBox editable = new JCheckBox(); editable.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { editorPane.setEditable(editable.isSelected()); } }); // set up load button for loading URL ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { try { // remember URL for back button urlStack.push(url.getText()); editorPane.setPage(url.getText()); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }; JButton loadButton = new JButton("Load/Magnify"); loadButton.addActionListener(listener); url.addActionListener(listener); // set up back button and button action JButton backButton = new JButton("Back"); backButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (urlStack.size() <= 1) return; try { // get URL from back button urlStack.pop(); // show URL in text field String urlString = urlStack.peek(); url.setText(urlString); editorPane.setPage(urlString); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }); JPanel allPanel = new JPanel(new BorderLayout()); // put all control components in a panel JPanel ctrlPanel = new JPanel(new BorderLayout()); JPanel urlPanel = new JPanel(); urlPanel.add(new JLabel("URL")); urlPanel.add(url); JPanel buttonPanel = new JPanel(); buttonPanel.add(loadButton); buttonPanel.add(backButton); buttonPanel.add(new JLabel("Editable")); buttonPanel.add(magPanel); buttonPanel.add(editable); ctrlPanel.add(buttonPanel, BorderLayout.NORTH); ctrlPanel.add(urlPanel, BorderLayout.CENTER); allPanel.add(ctrlPanel, BorderLayout.NORTH); allPanel.add(new JScrollPane(editorPane), BorderLayout.CENTER); add(allPanel); } }
private void updateList( @NotNull final List<WCInfo> infoList, @NotNull final List<WorkingCopyFormat> supportedFormats) { myPanel.removeAll(); final Insets nullIndent = new Insets(1, 3, 1, 0); final GridBagConstraints gb = new GridBagConstraints( 0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2, 2, 0, 0), 0, 0); gb.insets.left = 4; myPanel.add(myRefreshLabel, gb); gb.insets.left = 1; final LocalFileSystem lfs = LocalFileSystem.getInstance(); final Insets topIndent = new Insets(10, 3, 0, 0); for (final WCInfo wcInfo : infoList) { final Collection<WorkingCopyFormat> upgradeFormats = getUpgradeFormats(wcInfo, supportedFormats); final VirtualFile vf = lfs.refreshAndFindFileByIoFile(new File(wcInfo.getPath())); final VirtualFile root = (vf == null) ? wcInfo.getVcsRoot() : vf; final JEditorPane editorPane = new JEditorPane(UIUtil.HTML_MIME, ""); editorPane.setEditable(false); editorPane.setFocusable(true); editorPane.setBackground(UIUtil.getPanelBackground()); editorPane.setOpaque(false); editorPane.addHyperlinkListener( new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (CONFIGURE_BRANCHES.equals(e.getDescription())) { if (!checkRoot(root, wcInfo.getPath(), " invoke Configure Branches")) return; BranchConfigurationDialog.configureBranches(myProject, root, true); } else if (FIX_DEPTH.equals(e.getDescription())) { final int result = Messages.showOkCancelDialog( myVcs.getProject(), "You are going to checkout into '" + wcInfo.getPath() + "' with 'infinity' depth.\n" + "This will update your working copy to HEAD revision as well.", "Set Working Copy Infinity Depth", Messages.getWarningIcon()); if (result == Messages.OK) { // update of view will be triggered by roots changed event SvnCheckoutProvider.checkout( myVcs.getProject(), new File(wcInfo.getPath()), wcInfo.getRootUrl(), SVNRevision.HEAD, Depth.INFINITY, false, null, wcInfo.getFormat()); } } else if (CHANGE_FORMAT.equals(e.getDescription())) { changeFormat(wcInfo, upgradeFormats); } else if (MERGE_FROM.equals(e.getDescription())) { if (!checkRoot(root, wcInfo.getPath(), " invoke Merge From")) return; mergeFrom(wcInfo, root, editorPane); } else if (CLEANUP.equals(e.getDescription())) { if (!checkRoot(root, wcInfo.getPath(), " invoke Cleanup")) return; new CleanupWorker( new VirtualFile[] {root}, myVcs.getProject(), "action.Subversion.cleanup.progress.title") .execute(); } } } private boolean checkRoot( VirtualFile root, final String path, final String actionName) { if (root == null) { Messages.showWarningDialog( myProject, "Invalid working copy root: " + path, "Can not " + actionName); return false; } return true; } }); editorPane.setBorder(null); editorPane.setText(formatWc(wcInfo, upgradeFormats)); final JPanel copyPanel = new JPanel(new GridBagLayout()); final GridBagConstraints gb1 = new GridBagConstraints( 0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, nullIndent, 0, 0); gb1.insets.top = 1; gb1.gridwidth = 3; gb.insets = topIndent; gb.fill = GridBagConstraints.HORIZONTAL; ++gb.gridy; final JPanel contForCopy = new JPanel(new BorderLayout()); contForCopy.add(copyPanel, BorderLayout.WEST); myPanel.add(contForCopy, gb); copyPanel.add(editorPane, gb1); gb1.insets = nullIndent; } myPanel.revalidate(); myPanel.repaint(); }