Search in sources :

Example 11 with JBScrollPane

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

the class MultilineTreeCellRenderer method installRenderer.

public static JScrollPane installRenderer(final JTree tree, final MultilineTreeCellRenderer renderer) {
    final TreeCellRenderer defaultRenderer = tree.getCellRenderer();
    JScrollPane scrollpane = new JBScrollPane(tree) {

        private int myAddRemoveCounter = 0;

        private boolean myShouldResetCaches = false;

        public void setSize(Dimension d) {
            boolean isChanged = getWidth() != d.width || myShouldResetCaches;
            super.setSize(d);
            if (isChanged)
                resetCaches();
        }

        public void reshape(int x, int y, int w, int h) {
            boolean isChanged = w != getWidth() || myShouldResetCaches;
            super.reshape(x, y, w, h);
            if (isChanged)
                resetCaches();
        }

        private void resetCaches() {
            resetHeightCache(tree, defaultRenderer, renderer);
            myShouldResetCaches = false;
        }

        public void addNotify() {
            //To change body of overriden methods use Options | File Templates.
            super.addNotify();
            if (myAddRemoveCounter == 0)
                myShouldResetCaches = true;
            myAddRemoveCounter++;
        }

        public void removeNotify() {
            //To change body of overriden methods use Options | File Templates.
            super.removeNotify();
            myAddRemoveCounter--;
        }
    };
    scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    tree.setCellRenderer(renderer);
    scrollpane.addComponentListener(new ComponentAdapter() {

        public void componentResized(ComponentEvent e) {
            resetHeightCache(tree, defaultRenderer, renderer);
        }

        public void componentShown(ComponentEvent e) {
            // componentResized not called when adding to opened tool window.
            // Seems to be BUG#4765299, however I failed to create same code to reproduce it.
            // To reproduce it with IDEA: 1. remove this method, 2. Start any Ant task, 3. Keep message window open 4. start Ant task again.
            resetHeightCache(tree, defaultRenderer, renderer);
        }
    });
    return scrollpane;
}
Also used : TreeCellRenderer(javax.swing.tree.TreeCellRenderer) ComponentEvent(java.awt.event.ComponentEvent) JBScrollPane(com.intellij.ui.components.JBScrollPane) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 12 with JBScrollPane

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

the class ShowUIDefaultsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final UIDefaults defaults = UIManager.getDefaults();
    Enumeration keys = defaults.keys();
    final Object[][] data = new Object[defaults.size()][2];
    int i = 0;
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        data[i][0] = key;
        data[i][1] = defaults.get(key);
        i++;
    }
    Arrays.sort(data, (o1, o2) -> StringUtil.naturalCompare(o1[0].toString(), o2[0].toString()));
    final Project project = getEventProject(e);
    new DialogWrapper(project) {

        {
            setTitle("Edit LaF Defaults");
            setModal(false);
            init();
        }

        public JBTable myTable;

        @Nullable
        @Override
        public JComponent getPreferredFocusedComponent() {
            return myTable;
        }

        @Nullable
        @Override
        protected String getDimensionServiceKey() {
            return project == null ? null : "UI.Defaults.Dialog";
        }

        @Override
        protected JComponent createCenterPanel() {
            final JBTable table = new JBTable(new DefaultTableModel(data, new Object[] { "Name", "Value" }) {

                @Override
                public boolean isCellEditable(int row, int column) {
                    return column == 1 && getValueAt(row, column) instanceof Color;
                }
            }) {

                @Override
                public boolean editCellAt(int row, int column, EventObject e) {
                    if (isCellEditable(row, column) && e instanceof MouseEvent) {
                        final Object color = getValueAt(row, column);
                        final Color newColor = ColorPicker.showDialog(this, "Choose Color", (Color) color, true, null, true);
                        if (newColor != null) {
                            final ColorUIResource colorUIResource = new ColorUIResource(newColor);
                            final Object key = getValueAt(row, 0);
                            UIManager.put(key, colorUIResource);
                            setValueAt(colorUIResource, row, column);
                        }
                    }
                    return false;
                }
            };
            table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    final JPanel panel = new JPanel(new BorderLayout());
                    final JLabel label = new JLabel(value == null ? "" : value.toString());
                    panel.add(label, BorderLayout.CENTER);
                    if (value instanceof Color) {
                        final Color c = (Color) value;
                        label.setText(String.format("[r=%d,g=%d,b=%d] hex=0x%s", c.getRed(), c.getGreen(), c.getBlue(), ColorUtil.toHex(c)));
                        label.setForeground(ColorUtil.isDark(c) ? Color.white : Color.black);
                        panel.setBackground(c);
                        return panel;
                    } else if (value instanceof Icon) {
                        try {
                            final Icon icon = new IconWrap((Icon) value);
                            if (icon.getIconHeight() <= 20) {
                                label.setIcon(icon);
                            }
                            label.setText(String.format("(%dx%d) %s)", icon.getIconWidth(), icon.getIconHeight(), label.getText()));
                        } catch (Throwable e1) {
                        //
                        }
                        return panel;
                    } else if (value instanceof Border) {
                        try {
                            final Insets i = ((Border) value).getBorderInsets(null);
                            label.setText(String.format("[%d, %d, %d, %d] %s", i.top, i.left, i.bottom, i.right, label.getText()));
                            return panel;
                        } catch (Exception ignore) {
                        }
                    }
                    return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                }
            });
            final JBScrollPane pane = new JBScrollPane(table);
            new TableSpeedSearch(table, (o, cell) -> cell.column == 1 ? null : String.valueOf(o));
            table.setShowGrid(false);
            final JPanel panel = new JPanel(new BorderLayout());
            panel.add(pane, BorderLayout.CENTER);
            myTable = table;
            TableUtil.ensureSelectionExists(myTable);
            return panel;
        }
    }.show();
}
Also used : EmptyIcon(com.intellij.util.ui.EmptyIcon) Arrays(java.util.Arrays) DefaultTableModel(javax.swing.table.DefaultTableModel) Enumeration(java.util.Enumeration) StringUtil(com.intellij.openapi.util.text.StringUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) ColorUIResource(javax.swing.plaf.ColorUIResource) MouseEvent(java.awt.event.MouseEvent) JBScrollPane(com.intellij.ui.components.JBScrollPane) Border(javax.swing.border.Border) EventObject(java.util.EventObject) java.awt(java.awt) JBTable(com.intellij.ui.table.JBTable) Nullable(org.jetbrains.annotations.Nullable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) PairFunction(com.intellij.util.PairFunction) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Project(com.intellij.openapi.project.Project) DumbAware(com.intellij.openapi.project.DumbAware) Comparator(java.util.Comparator) javax.swing(javax.swing) DefaultTableModel(javax.swing.table.DefaultTableModel) JBTable(com.intellij.ui.table.JBTable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Enumeration(java.util.Enumeration) MouseEvent(java.awt.event.MouseEvent) ColorUIResource(javax.swing.plaf.ColorUIResource) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) EventObject(java.util.EventObject) Project(com.intellij.openapi.project.Project) EventObject(java.util.EventObject) EmptyIcon(com.intellij.util.ui.EmptyIcon) Border(javax.swing.border.Border) Nullable(org.jetbrains.annotations.Nullable) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 13 with JBScrollPane

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

the class MemoryInstanceView method instanceChanged.

private void instanceChanged() {
    if (mySplitter == null || myInstanceObject == myStage.getSelectedInstance()) {
        return;
    }
    myInstanceObject = myStage.getSelectedInstance();
    if (myInstanceObject == null) {
        mySplitter.setSecondComponent(null);
        return;
    }
    AllocationStack callStack = myInstanceObject.getCallStack();
    if (callStack == null || callStack.getStackFramesList().size() == 0) {
        return;
    }
    DefaultListModel<StackTraceElement> model = new DefaultListModel<>();
    callStack.getStackFramesList().forEach(frame -> model.addElement(new StackTraceElement(frame.getClassName(), frame.getMethodName(), frame.getFileName(), frame.getLineNumber())));
    mySplitter.setSecondComponent(new JBScrollPane(new JBList(model)));
}
Also used : JBList(com.intellij.ui.components.JBList) JBScrollPane(com.intellij.ui.components.JBScrollPane) AllocationStack(com.android.tools.profiler.proto.MemoryProfiler.AllocationStack)

Example 14 with JBScrollPane

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

the class ActivityGalleryStep method createGallery.

private JComponent createGallery() {
    myGallery = new ASGallery<>();
    Dimension thumbnailSize = DEFAULT_GALLERY_THUMBNAIL_SIZE;
    myGallery.setThumbnailSize(thumbnailSize);
    myGallery.setMinimumSize(new Dimension(thumbnailSize.width * 2 + 1, thumbnailSize.height));
    myGallery.setLabelProvider(new Function<Optional<TemplateEntry>, String>() {

        @Override
        public String apply(Optional<TemplateEntry> template) {
            if (template.isPresent()) {
                return template.get().getTitle();
            } else {
                return "Add No Activity";
            }
        }
    });
    myGallery.setDefaultAction(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            DynamicWizard wizard = getWizard();
            assert wizard != null;
            wizard.doNextAction();
        }
    });
    myGallery.setImageProvider(new Function<Optional<TemplateEntry>, Image>() {

        @Override
        public Image apply(Optional<TemplateEntry> input) {
            return input.isPresent() ? input.get().getImage() : null;
        }
    });
    myGallery.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            saveState(myGallery);
        }
    });
    myGallery.setName("Templates Gallery");
    AccessibleContext accessibleContext = myGallery.getAccessibleContext();
    if (accessibleContext != null) {
        accessibleContext.setAccessibleDescription(getStepTitle());
    }
    JPanel panel = new JPanel(new JBCardLayout());
    panel.add("only card", new JBScrollPane(myGallery));
    return panel;
}
Also used : Optional(java.util.Optional) AccessibleContext(javax.accessibility.AccessibleContext) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) DynamicWizard(com.android.tools.idea.wizard.dynamic.DynamicWizard) JBCardLayout(com.intellij.ui.JBCardLayout) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 15 with JBScrollPane

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

the class ChooseModuleTypeStep method createGallery.

@NotNull
private JComponent createGallery() {
    myFormFactorGallery = new ASGallery<ModuleGalleryEntry>(JBList.createDefaultListModel(), image -> image.getIcon() == null ? null : IconUtil.toImage(image.getIcon()), label -> label == null ? message("android.wizard.gallery.item.none") : label.getName(), DEFAULT_GALLERY_THUMBNAIL_SIZE, null) {

        @Override
        public Dimension getPreferredScrollableViewportSize() {
            // The default implementations assigns a height as tall as the screen.
            // When calling setVisibleRowCount(2), the underlying implementation is buggy, and  will have a gap on the right and when the user
            // resizes, it enters on an adjustment loop at some widths (can't decide to fit 3 or for elements, and loops between the two)
            Dimension cellSize = computeCellSize();
            int heightInsets = getInsets().top + getInsets().bottom;
            int widthInsets = getInsets().left + getInsets().right;
            // Don't want to show an exact number of rows, since then it's not obvious there's another row available.
            return new Dimension(cellSize.width * 5 + widthInsets, (int) (cellSize.height * 2.2) + heightInsets);
        }
    };
    myFormFactorGallery.setBorder(BorderFactory.createLineBorder(JBColor.border()));
    AccessibleContext accessibleContext = myFormFactorGallery.getAccessibleContext();
    if (accessibleContext != null) {
        accessibleContext.setAccessibleDescription(getTitle());
    }
    return new JBScrollPane(myFormFactorGallery);
}
Also used : JBList(com.intellij.ui.components.JBList) AndroidBundle.message(org.jetbrains.android.util.AndroidBundle.message) FormScalingUtil(com.android.tools.swing.util.FormScalingUtil) java.util(java.util) ATTR_INCLUDE_FORM_FACTOR(com.android.tools.idea.templates.TemplateMetadata.ATTR_INCLUDE_FORM_FACTOR) FormFactor(com.android.tools.idea.npw.FormFactor) StringUtil(com.intellij.openapi.util.text.StringUtil) HashMap(com.intellij.util.containers.HashMap) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard) AccessibleContext(javax.accessibility.AccessibleContext) ModelWizardStep(com.android.tools.idea.wizard.model.ModelWizardStep) ActionEvent(java.awt.event.ActionEvent) ASGallery(com.android.tools.idea.ui.ASGallery) JBScrollPane(com.intellij.ui.components.JBScrollPane) SkippableWizardStep(com.android.tools.idea.wizard.model.SkippableWizardStep) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Lists(com.google.common.collect.Lists) DEFAULT_GALLERY_THUMBNAIL_SIZE(com.android.tools.idea.wizard.WizardConstants.DEFAULT_GALLERY_THUMBNAIL_SIZE) NotNull(org.jetbrains.annotations.NotNull) JBColor(com.intellij.ui.JBColor) IconUtil(com.intellij.util.IconUtil) javax.swing(javax.swing) AccessibleContext(javax.accessibility.AccessibleContext) JBScrollPane(com.intellij.ui.components.JBScrollPane) NotNull(org.jetbrains.annotations.NotNull)

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