Search in sources :

Example 6 with JBScrollPane

use of com.intellij.ui.components.JBScrollPane in project intellij-community by JetBrains.

the class CustomizePluginsStepPanel method createScrollPane.

static JBScrollPane createScrollPane(JPanel gridPanel) {
    JBScrollPane scrollPane = new JBScrollPane(gridPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    // to disallow resetting border on LaF change
    scrollPane.setBorder(JBUI.Borders.empty());
    return scrollPane;
}
Also used : JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 7 with JBScrollPane

use of com.intellij.ui.components.JBScrollPane in project intellij-community by JetBrains.

the class AppUIUtil method showPrivacyPolicyAgreement.

/**
   * @param htmlText Updated version of Privacy Policy text if any.
   *                 If it's {@code null}, the standard text from bundled resources would be used.
   */
public static void showPrivacyPolicyAgreement(@NotNull String htmlText) {
    DialogWrapper dialog = new DialogWrapper(true) {

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            JPanel centerPanel = new JPanel(new BorderLayout(JBUI.scale(5), JBUI.scale(5)));
            JEditorPane viewer = SwingHelper.createHtmlViewer(true, null, JBColor.WHITE, JBColor.BLACK);
            viewer.setFocusable(true);
            viewer.addHyperlinkListener(new HyperlinkAdapter() {

                @Override
                protected void hyperlinkActivated(HyperlinkEvent e) {
                    URL url = e.getURL();
                    if (url != null) {
                        BrowserUtil.browse(url);
                    } else {
                        SwingHelper.scrollToReference(viewer, e.getDescription());
                    }
                }
            });
            viewer.setText(htmlText);
            StyleSheet styleSheet = ((HTMLDocument) viewer.getDocument()).getStyleSheet();
            styleSheet.addRule("body {font-family: \"Segoe UI\", Tahoma, sans-serif;}");
            styleSheet.addRule("body {margin-top:0;padding-top:0;}");
            styleSheet.addRule("body {font-size:" + JBUI.scaleFontSize(13) + "pt;}");
            styleSheet.addRule("h2, em {margin-top:" + JBUI.scaleFontSize(20) + "pt;}");
            styleSheet.addRule("h1, h2, h3, p, h4, em {margin-bottom:0;padding-bottom:0;}");
            styleSheet.addRule("p, h1 {margin-top:0;padding-top:" + JBUI.scaleFontSize(6) + "pt;}");
            styleSheet.addRule("li {margin-bottom:" + JBUI.scaleFontSize(6) + "pt;}");
            styleSheet.addRule("h2 {margin-top:0;padding-top:" + JBUI.scaleFontSize(13) + "pt;}");
            viewer.setCaretPosition(0);
            viewer.setBorder(JBUI.Borders.empty(0, 5, 5, 5));
            centerPanel.add(new JLabel("Please read and accept these terms and conditions:"), BorderLayout.NORTH);
            centerPanel.add(new JBScrollPane(viewer, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
            return centerPanel;
        }

        @Override
        protected void createDefaultActions() {
            super.createDefaultActions();
            init();
            setOKButtonText("Accept");
            setCancelButtonText("Reject and Exit");
            setAutoAdjustable(false);
        }

        @Override
        public void doCancelAction() {
            super.doCancelAction();
            ApplicationEx application = ApplicationManagerEx.getApplicationEx();
            if (application == null) {
                System.exit(Main.PRIVACY_POLICY_REJECTION);
            } else {
                ((ApplicationImpl) application).exit(true, true, false);
            }
        }
    };
    dialog.setModal(true);
    dialog.setTitle(ApplicationNamesInfo.getInstance().getFullProductName() + " Privacy Policy Agreement");
    dialog.setSize(JBUI.scale(509), JBUI.scale(395));
    dialog.show();
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HTMLDocument(javax.swing.text.html.HTMLDocument) ApplicationImpl(com.intellij.openapi.application.impl.ApplicationImpl) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) URL(java.net.URL) StyleSheet(javax.swing.text.html.StyleSheet) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 8 with JBScrollPane

use of com.intellij.ui.components.JBScrollPane in project intellij-community by JetBrains.

the class VcsStructureChooser method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myTree = new Tree();
    myTree.setBorder(BORDER);
    myTree.setShowsRootHandles(true);
    myTree.setRootVisible(false);
    myTree.setExpandableItemsEnabled(false);
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, true, false, true) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            if (!super.isFileVisible(file, showHiddenFiles))
                return false;
            if (myRoots.contains(file))
                return false;
            ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
            return !changeListManager.isIgnoredFile(file) && !changeListManager.isUnversioned(file);
        }
    };
    descriptor.withRoots(new ArrayList<>(myRoots)).withShowHiddenFiles(true).withHideIgnored(true);
    final MyCheckboxTreeCellRenderer cellRenderer = new MyCheckboxTreeCellRenderer(mySelectionManager, myModulesSet, myProject, myTree, myRoots);
    FileSystemTreeImpl fileSystemTree = new FileSystemTreeImpl(myProject, descriptor, myTree, cellRenderer, null, o -> {
        DefaultMutableTreeNode lastPathComponent = ((DefaultMutableTreeNode) o.getLastPathComponent());
        Object uo = lastPathComponent.getUserObject();
        if (uo instanceof FileNodeDescriptor) {
            VirtualFile file = ((FileNodeDescriptor) uo).getElement().getFile();
            String module = myModulesSet.get(file);
            if (module != null)
                return module;
            return file == null ? "" : file.getName();
        }
        return o.toString();
    });
    fileSystemTree.getTreeBuilder().getUi().setNodeDescriptorComparator((o1, o2) -> {
        if (o1 instanceof FileNodeDescriptor && o2 instanceof FileNodeDescriptor) {
            VirtualFile f1 = ((FileNodeDescriptor) o1).getElement().getFile();
            VirtualFile f2 = ((FileNodeDescriptor) o2).getElement().getFile();
            boolean isDir1 = f1.isDirectory();
            boolean isDir2 = f2.isDirectory();
            if (isDir1 != isDir2)
                return isDir1 ? -1 : 1;
            return f1.getPath().compareToIgnoreCase(f2.getPath());
        }
        return o1.getIndex() - o2.getIndex();
    });
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            int row = myTree.getRowForLocation(e.getX(), e.getY());
            if (row < 0)
                return false;
            Object o = myTree.getPathForRow(row).getLastPathComponent();
            if (getTreeRoot() == o || getFile(o) == null)
                return false;
            Rectangle rowBounds = myTree.getRowBounds(row);
            cellRenderer.setBounds(rowBounds);
            Rectangle checkBounds = cellRenderer.myCheckbox.getBounds();
            checkBounds.setLocation(rowBounds.getLocation());
            if (checkBounds.height == 0)
                checkBounds.height = rowBounds.height;
            if (checkBounds.contains(e.getPoint())) {
                mySelectionManager.toggleSelection((DefaultMutableTreeNode) o);
                myTree.revalidate();
                myTree.repaint();
            }
            return true;
        }
    }.installOn(myTree);
    myTree.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                TreePath[] paths = myTree.getSelectionPaths();
                if (paths == null)
                    return;
                for (TreePath path : paths) {
                    if (path == null)
                        continue;
                    Object o = path.getLastPathComponent();
                    if (getTreeRoot() == o || getFile(o) == null)
                        return;
                    mySelectionManager.toggleSelection((DefaultMutableTreeNode) o);
                }
                myTree.revalidate();
                myTree.repaint();
                e.consume();
            }
        }
    });
    JBPanel panel = new JBPanel(new BorderLayout());
    panel.add(new JBScrollPane(fileSystemTree.getTree()), BorderLayout.CENTER);
    final JLabel selectedLabel = new JLabel("");
    selectedLabel.setBorder(JBUI.Borders.empty(2, 0));
    panel.add(selectedLabel, BorderLayout.SOUTH);
    mySelectionManager.setSelectionChangeListener(new PlusMinus<VirtualFile>() {

        @Override
        public void plus(VirtualFile virtualFile) {
            mySelectedFiles.add(virtualFile);
            recalculateErrorText();
        }

        private void recalculateErrorText() {
            checkEmpty();
            if (mySelectionManager.canAddSelection()) {
                selectedLabel.setText("");
            } else {
                selectedLabel.setText(CAN_NOT_ADD_TEXT);
            }
            selectedLabel.revalidate();
        }

        @Override
        public void minus(VirtualFile virtualFile) {
            mySelectedFiles.remove(virtualFile);
            recalculateErrorText();
        }
    });
    panel.setPreferredSize(JBUI.size(400, 300));
    return panel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) Tree(com.intellij.ui.treeStructure.Tree) MouseEvent(java.awt.event.MouseEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileSystemTreeImpl(com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl) FileNodeDescriptor(com.intellij.openapi.fileChooser.ex.FileNodeDescriptor) JBPanel(com.intellij.ui.components.JBPanel) TreePath(javax.swing.tree.TreePath) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 9 with JBScrollPane

use of com.intellij.ui.components.JBScrollPane in project intellij-community by JetBrains.

the class FileDocumentManagerImpl method handleErrorsOnSave.

private void handleErrorsOnSave(@NotNull Map<Document, IOException> failures) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        IOException ioException = ContainerUtil.getFirstItem(failures.values());
        if (ioException != null) {
            throw new RuntimeException(ioException);
        }
        return;
    }
    for (IOException exception : failures.values()) {
        LOG.warn(exception);
    }
    final String text = StringUtil.join(failures.values(), Throwable::getMessage, "\n");
    final DialogWrapper dialog = new DialogWrapper(null) {

        {
            init();
            setTitle(UIBundle.message("cannot.save.files.dialog.title"));
        }

        @Override
        protected void createDefaultActions() {
            super.createDefaultActions();
            myOKAction.putValue(Action.NAME, UIBundle.message(myOnClose ? "cannot.save.files.dialog.ignore.changes" : "cannot.save.files.dialog.revert.changes"));
            myOKAction.putValue(DEFAULT_ACTION, null);
            if (!myOnClose) {
                myCancelAction.putValue(Action.NAME, CommonBundle.getCloseButtonText());
            }
        }

        @Override
        protected JComponent createCenterPanel() {
            final JPanel panel = new JPanel(new BorderLayout(0, 5));
            panel.add(new JLabel(UIBundle.message("cannot.save.files.dialog.message")), BorderLayout.NORTH);
            final JTextPane area = new JTextPane();
            area.setText(text);
            area.setEditable(false);
            area.setMinimumSize(new Dimension(area.getMinimumSize().width, 50));
            panel.add(new JBScrollPane(area, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
            return panel;
        }
    };
    if (dialog.showAndGet()) {
        for (Document document : failures.keySet()) {
            reloadFromDisk(document);
        }
    }
}
Also used : IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 10 with JBScrollPane

use of com.intellij.ui.components.JBScrollPane in project intellij-community by JetBrains.

the class FocusTracesDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    JBSplitter splitter = new JBSplitter(true, .5F, .2F, .8F);
    splitter.setFirstComponent(new JBScrollPane(myRequestsTable, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
    JComponent consoleComponent = new JPanel(new BorderLayout());
    consoleComponent.add(consoleView.getComponent(), BorderLayout.CENTER);
    int row = myRequestsTable.getSelectedRow();
    if (row >= 0) {
        consoleView.print(ExceptionUtil.getThrowableText(myRequests.get(row).trace), ConsoleViewContentType.NORMAL_OUTPUT);
    }
    splitter.setSecondComponent(new JBScrollPane(consoleComponent, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
    panel.add(splitter, BorderLayout.CENTER);
    return panel;
}
Also used : JBSplitter(com.intellij.ui.JBSplitter) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Aggregations

JBScrollPane (com.intellij.ui.components.JBScrollPane)51 ActionEvent (java.awt.event.ActionEvent)7 Nullable (org.jetbrains.annotations.Nullable)7 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 JBList (com.intellij.ui.components.JBList)6 ListSelectionEvent (javax.swing.event.ListSelectionEvent)6 ListSelectionListener (javax.swing.event.ListSelectionListener)5 JBTable (com.intellij.ui.table.JBTable)4 Tree (com.intellij.ui.treeStructure.Tree)4 java.awt (java.awt)4 MouseEvent (java.awt.event.MouseEvent)4 List (java.util.List)4 javax.swing (javax.swing)4 TreePath (javax.swing.tree.TreePath)4 NotNull (org.jetbrains.annotations.NotNull)4 Module (com.intellij.openapi.module.Module)3 Project (com.intellij.openapi.project.Project)3 VerticalFlowLayout (com.intellij.openapi.ui.VerticalFlowLayout)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3