Search in sources :

Example 51 with TableColumn

use of javax.swing.table.TableColumn in project jmeter by apache.

the class RequestViewHTTP method createRequestPane.

/**
     * Create a pane with three tables (request, params, headers)
     * 
     * @return Pane to display request data
     */
private Component createRequestPane() {
    // Set up the 1st table Result with empty headers
    tableRequest = new JTable(requestModel);
    JMeterUtils.applyHiDPI(tableRequest);
    // $NON-NLS-1$
    tableRequest.setToolTipText(JMeterUtils.getResString("textbox_tooltip_cell"));
    tableRequest.addMouseListener(new TextBoxDoubleClick(tableRequest));
    setFirstColumnPreferredAndMaxWidth(tableRequest);
    RendererUtils.applyRenderers(tableRequest, RENDERERS_REQUEST);
    // Set up the 2nd table 
    tableParams = new JTable(paramsModel);
    JMeterUtils.applyHiDPI(tableParams);
    // $NON-NLS-1$
    tableParams.setToolTipText(JMeterUtils.getResString("textbox_tooltip_cell"));
    tableParams.addMouseListener(new TextBoxDoubleClick(tableParams));
    TableColumn column = tableParams.getColumnModel().getColumn(0);
    column.setPreferredWidth(160);
    tableParams.getTableHeader().setDefaultRenderer(new HeaderAsPropertyRenderer());
    RendererUtils.applyRenderers(tableParams, RENDERERS_PARAMS);
    // Set up the 3rd table 
    tableHeaders = new JTable(headersModel);
    JMeterUtils.applyHiDPI(tableHeaders);
    // $NON-NLS-1$
    tableHeaders.setToolTipText(JMeterUtils.getResString("textbox_tooltip_cell"));
    tableHeaders.addMouseListener(new TextBoxDoubleClick(tableHeaders));
    setFirstColumnPreferredAndMaxWidth(tableHeaders);
    tableHeaders.getTableHeader().setDefaultRenderer(new HeaderAsPropertyRenderer());
    RendererUtils.applyRenderers(tableHeaders, RENDERERS_HEADERS);
    // Create the split pane
    JSplitPane topSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, GuiUtils.makeScrollPane(tableParams), GuiUtils.makeScrollPane(tableHeaders));
    topSplit.setOneTouchExpandable(true);
    // set split ratio
    topSplit.setResizeWeight(0.50);
    // see bug jdk 4131528
    topSplit.setBorder(null);
    JSplitPane paneParsed = new JSplitPane(JSplitPane.VERTICAL_SPLIT, GuiUtils.makeScrollPane(tableRequest), topSplit);
    paneParsed.setOneTouchExpandable(true);
    // set split ratio (only 5 lines to display)
    paneParsed.setResizeWeight(0.25);
    // see bug jdk 4131528
    paneParsed.setBorder(null);
    // Hint to background color on bottom tabs (grey, not blue)
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(paneParsed);
    return panel;
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) HeaderAsPropertyRenderer(org.apache.jmeter.gui.util.HeaderAsPropertyRenderer) TextBoxDoubleClick(org.apache.jmeter.gui.util.TextBoxDialoger.TextBoxDoubleClick) JSplitPane(javax.swing.JSplitPane) TableColumn(javax.swing.table.TableColumn)

Example 52 with TableColumn

use of javax.swing.table.TableColumn in project jmeter by apache.

the class RequestViewHTTP method setFirstColumnPreferredAndMaxWidth.

private void setFirstColumnPreferredAndMaxWidth(JTable table) {
    TableColumn column = table.getColumnModel().getColumn(0);
    column.setMaxWidth(300);
    column.setPreferredWidth(160);
}
Also used : TableColumn(javax.swing.table.TableColumn)

Example 53 with TableColumn

use of javax.swing.table.TableColumn in project intellij-community by JetBrains.

the class ExtractedSettingsDialog method buildExtractedSettingsTree.

protected JComponent buildExtractedSettingsTree() {
    Collection<Value> unusedValues = ContainerUtil.newHashSet(myValues);
    myRoot = new DefaultMutableTreeNode();
    for (Map.Entry<LanguageCodeStyleSettingsProvider.SettingsType, Map<CodeStyleSettingPresentation.SettingsGroup, List<CodeStyleSettingPresentation>>> typeEntry : myNameProvider.mySettings.entrySet()) {
        DefaultMutableTreeNode settingsNode = null;
        for (Map.Entry<CodeStyleSettingPresentation.SettingsGroup, List<CodeStyleSettingPresentation>> groupEntry : typeEntry.getValue().entrySet()) {
            CodeStyleSettingPresentation.SettingsGroup group = groupEntry.getKey();
            List<CodeStyleSettingPresentation> representations = groupEntry.getValue();
            List<CodeStyleSettingPresentation> children = ContainerUtil.emptyList();
            DefaultMutableTreeNode groupNode = null;
            if (group.name == null && !representations.isEmpty()) {
                //there is a setting with name coinciding with group name
                if (representations.size() > 1) {
                    children = representations.subList(1, representations.size());
                }
                CodeStyleSettingPresentation headRep = representations.get(0);
                Value myValue = CodeStyleSettingsNameProvider.getValue(headRep, myValues);
                if (myValue == null) {
                    //value was not found (was not selected)
                    groupNode = new SettingsTreeNode(headRep.getUiName());
                } else {
                    groupNode = new SettingsTreeNode(headRep.getUiName());
                    groupNode.add(new SettingsTreeNode(headRep.getValueUiName(myValue.value), headRep, true, myValue));
                    unusedValues.remove(myValue);
                }
            } else {
                children = representations;
            }
            for (CodeStyleSettingPresentation representation : children) {
                Value myValue = CodeStyleSettingsNameProvider.getValue(representation, myValues);
                if (myValue != null) {
                    if (groupNode == null) {
                        groupNode = new SettingsTreeNode(group.name);
                    }
                    groupNode.add(new SettingsTreeNode(representation.getValueUiName(myValue.value), representation, false, myValue));
                    unusedValues.remove(myValue);
                }
            }
            if (groupNode != null && !groupNode.isLeaf()) {
                if (settingsNode == null) {
                    settingsNode = new SettingsTreeNode(CodeStyleSettingsNameProvider.getSettingsTypeName(typeEntry.getKey()));
                }
                settingsNode.add(groupNode);
            }
        }
        if (settingsNode != null) {
            myRoot.add(settingsNode);
        }
    }
    //TODO: for now, settings without UI presentation are not displayed. Do something about it.
    //unusedValues = ContainerUtil.filter(unusedValues, new Condition<Value>(){
    //  @Override
    //  public boolean value(Value value) {
    //    return value.state == Value.STATE.SELECTED;
    //  }
    //});
    //
    //DefaultMutableTreeNode unnamedNode = null;
    //for (Value value: unusedValues) {
    //  if (unnamedNode == null) {
    //    unnamedNode = new SettingsTreeNode("Settings without UI representation");
    //  }
    //  unnamedNode.add(new SettingsTreeNode(value.value.toString(), null, false, value.name, value));
    //}
    //
    //if (unnamedNode != null) {
    //  myRoot.add(unnamedNode);
    //}
    final ColumnInfo[] COLUMNS = new ColumnInfo[] { getTitleColumnInfo(), getValueColumnInfo() };
    ListTreeTableModel model = new ListTreeTableModel(myRoot, COLUMNS);
    final TreeTable treeTable = new TreeTable(model) {

        @Override
        public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) {
            TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel);
            UIUtil.setLineStyleAngled(tableRenderer);
            tableRenderer.setRootVisible(false);
            tableRenderer.setShowsRootHandles(true);
            return tableRenderer;
        }

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            TreePath treePath = getTree().getPathForRow(row);
            if (treePath == null)
                return super.getCellRenderer(row, column);
            Object node = treePath.getLastPathComponent();
            TableCellRenderer renderer = COLUMNS[column].getRenderer(node);
            return renderer == null ? super.getCellRenderer(row, column) : renderer;
        }

        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            TreePath treePath = getTree().getPathForRow(row);
            if (treePath == null)
                return super.getCellEditor(row, column);
            Object node = treePath.getLastPathComponent();
            TableCellEditor editor = COLUMNS[column].getEditor(node);
            return editor == null ? super.getCellEditor(row, column) : editor;
        }
    };
    new TreeTableSpeedSearch(treeTable).setComparator(new SpeedSearchComparator(false));
    treeTable.setRootVisible(false);
    final JTree tree = treeTable.getTree();
    tree.setCellRenderer(myTitleRenderer);
    tree.setShowsRootHandles(true);
    treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    treeTable.setTableHeader(null);
    TreeUtil.expandAll(tree);
    treeTable.getColumnModel().getSelectionModel().setAnchorSelectionIndex(1);
    treeTable.getColumnModel().getSelectionModel().setLeadSelectionIndex(1);
    int maxWidth = tree.getPreferredScrollableViewportSize().width + 10;
    final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0);
    titleColumn.setPreferredWidth(maxWidth);
    titleColumn.setMinWidth(maxWidth);
    titleColumn.setMaxWidth(maxWidth);
    titleColumn.setResizable(false);
    final Dimension valueSize = new JLabel(ApplicationBundle.message("option.table.sizing.text")).getPreferredSize();
    treeTable.setPreferredScrollableViewportSize(new Dimension(maxWidth + valueSize.width + 10, 20));
    treeTable.setBackground(UIUtil.getPanelBackground());
    treeTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    final Dimension screenSize = treeTable.getToolkit().getScreenSize();
    JBScrollPane scroller = new JBScrollPane(treeTable) {

        @Override
        public Dimension getMinimumSize() {
            return super.getPreferredSize();
        }
    };
    final Dimension preferredSize = new Dimension(Math.min(screenSize.width / 2, treeTable.getPreferredSize().width), Math.min(screenSize.height / 2, treeTable.getPreferredSize().height));
    getRootPane().setPreferredSize(preferredSize);
    return scroller;
}
Also used : TreeTableSpeedSearch(com.intellij.ui.TreeTableSpeedSearch) ColumnInfo(com.intellij.util.ui.ColumnInfo) CodeStyleSettingPresentation(com.intellij.psi.codeStyle.presentation.CodeStyleSettingPresentation) List(java.util.List) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) TableCellEditor(javax.swing.table.TableCellEditor) TableCellRenderer(javax.swing.table.TableCellRenderer) TableColumn(javax.swing.table.TableColumn) Value(com.intellij.psi.codeStyle.extractor.values.Value) SpeedSearchComparator(com.intellij.ui.SpeedSearchComparator) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 54 with TableColumn

use of javax.swing.table.TableColumn in project intellij-community by JetBrains.

the class DetectedRootsChooserDialog method createTreeTable.

private static CheckboxTreeTable createTreeTable(Collection<SuggestedChildRootInfo> suggestedRoots) {
    final CheckedTreeNode root = createRoot(suggestedRoots);
    CheckboxTreeTable treeTable = new CheckboxTreeTable(root, new CheckboxTree.CheckboxTreeCellRenderer(true) {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (!(value instanceof VirtualFileCheckedTreeNode))
                return;
            VirtualFileCheckedTreeNode node = (VirtualFileCheckedTreeNode) value;
            VirtualFile file = node.getFile();
            String text;
            SimpleTextAttributes attributes;
            Icon icon;
            boolean isValid = true;
            if (leaf) {
                VirtualFile ancestor = ((VirtualFileCheckedTreeNode) node.getParent()).getFile();
                if (ancestor != null) {
                    text = VfsUtilCore.getRelativePath(file, ancestor, File.separatorChar);
                    if (StringUtil.isEmpty(text)) {
                        text = File.separator;
                    }
                } else {
                    text = file.getPresentableUrl();
                }
                if (text == null) {
                    isValid = false;
                    text = file.getPresentableUrl();
                }
                attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
                icon = PlatformIcons.DIRECTORY_CLOSED_ICON;
            } else {
                text = file.getPresentableUrl();
                attributes = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
                icon = PlatformIcons.DIRECTORY_CLOSED_ICON;
            }
            final ColoredTreeCellRenderer textRenderer = getTextRenderer();
            textRenderer.setIcon(icon);
            if (!isValid) {
                textRenderer.append("[INVALID] ", SimpleTextAttributes.ERROR_ATTRIBUTES);
            }
            textRenderer.append(text, attributes);
        }
    }, new ColumnInfo[] { ROOT_COLUMN, ROOT_TYPE_COLUMN });
    int max = 0;
    for (SuggestedChildRootInfo info : suggestedRoots) {
        for (String s : info.getRootTypeNames()) {
            max = Math.max(max, treeTable.getFontMetrics(treeTable.getFont()).stringWidth(s));
        }
    }
    final TableColumn column = treeTable.getColumnModel().getColumn(1);
    //add space for combobox button
    int width = max + 20;
    column.setPreferredWidth(width);
    column.setMaxWidth(width);
    treeTable.setRootVisible(false);
    new TreeTableSpeedSearch(treeTable, new Convertor<TreePath, String>() {

        @Override
        public String convert(TreePath o) {
            Object node = o.getLastPathComponent();
            if (!(node instanceof VirtualFileCheckedTreeNode))
                return "";
            return ((VirtualFileCheckedTreeNode) node).getFile().getPresentableUrl();
        }
    });
    TreeUtil.expandAll(treeTable.getTree());
    return treeTable;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TableColumn(javax.swing.table.TableColumn) TreePath(javax.swing.tree.TreePath)

Example 55 with TableColumn

use of javax.swing.table.TableColumn in project intellij-community by JetBrains.

the class OptionTableWithPreviewPanel method createOptionsTree.

protected TreeTable createOptionsTree(CodeStyleSettings settings) {
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    Map<String, DefaultMutableTreeNode> groupsMap = new THashMap<>();
    List<Option> sorted = sortOptions(ContainerUtil.concat(myOptions, myCustomOptions));
    for (Option each : sorted) {
        if (!(myCustomOptions.contains(each) || myAllowedOptions.contains(each.field.getName()) || myShowAllStandardOptions))
            continue;
        String group = each.groupName;
        MyTreeNode newNode = new MyTreeNode(each, each.title, settings);
        DefaultMutableTreeNode groupNode = groupsMap.get(group);
        if (groupNode != null) {
            groupNode.add(newNode);
        } else {
            String groupName;
            if (group == null) {
                groupName = each.title;
                groupNode = newNode;
            } else {
                groupName = group;
                groupNode = new DefaultMutableTreeNode(groupName);
                groupNode.add(newNode);
            }
            groupsMap.put(groupName, groupNode);
            rootNode.add(groupNode);
        }
    }
    ListTreeTableModel model = new ListTreeTableModel(rootNode, COLUMNS);
    TreeTable treeTable = new TreeTable(model) {

        @Override
        public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) {
            TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel);
            UIUtil.setLineStyleAngled(tableRenderer);
            tableRenderer.setRootVisible(false);
            tableRenderer.setShowsRootHandles(true);
            return tableRenderer;
        }

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            TreePath treePath = getTree().getPathForRow(row);
            if (treePath == null)
                return super.getCellRenderer(row, column);
            Object node = treePath.getLastPathComponent();
            @SuppressWarnings("unchecked") TableCellRenderer renderer = COLUMNS[column].getRenderer(node);
            return renderer == null ? super.getCellRenderer(row, column) : renderer;
        }

        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            TreePath treePath = getTree().getPathForRow(row);
            if (treePath == null)
                return super.getCellEditor(row, column);
            Object node = treePath.getLastPathComponent();
            @SuppressWarnings("unchecked") TableCellEditor editor = COLUMNS[column].getEditor(node);
            return editor == null ? super.getCellEditor(row, column) : editor;
        }
    };
    new TreeTableSpeedSearch(treeTable).setComparator(new SpeedSearchComparator(false));
    treeTable.setRootVisible(false);
    final JTree tree = treeTable.getTree();
    tree.setCellRenderer(myTitleRenderer);
    tree.setShowsRootHandles(true);
    //myTreeTable.setRowHeight(new JComboBox(new String[]{"Sample Text"}).getPreferredSize().height);
    treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    treeTable.setTableHeader(null);
    TreeUtil.expandAll(tree);
    treeTable.getColumnModel().getSelectionModel().setAnchorSelectionIndex(1);
    treeTable.getColumnModel().getSelectionModel().setLeadSelectionIndex(1);
    int maxWidth = tree.getPreferredScrollableViewportSize().width + 10;
    final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0);
    titleColumn.setPreferredWidth(maxWidth);
    titleColumn.setMinWidth(maxWidth);
    titleColumn.setMaxWidth(maxWidth);
    titleColumn.setResizable(false);
    //final TableColumn levelColumn = treeTable.getColumnModel().getColumn(1);
    //TODO[max]: better preffered size...
    //TODO[kb]: Did I fixed it by making the last column floating?
    //levelColumn.setPreferredWidth(valueSize.width);
    //levelColumn.setMaxWidth(valueSize.width);
    //levelColumn.setMinWidth(valueSize.width);
    //levelColumn.setResizable(false);
    final Dimension valueSize = new JLabel(ApplicationBundle.message("option.table.sizing.text")).getPreferredSize();
    treeTable.setPreferredScrollableViewportSize(new Dimension(maxWidth + valueSize.width + 10, 20));
    return treeTable;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) TreeTableCellRenderer(com.intellij.ui.treeStructure.treetable.TreeTableCellRenderer) TreeTableSpeedSearch(com.intellij.ui.TreeTableSpeedSearch) TreeTable(com.intellij.ui.treeStructure.treetable.TreeTable) ListTreeTableModel(com.intellij.ui.treeStructure.treetable.ListTreeTableModel) TreeTableModel(com.intellij.ui.treeStructure.treetable.TreeTableModel) TableColumn(javax.swing.table.TableColumn) TreeTableCellRenderer(com.intellij.ui.treeStructure.treetable.TreeTableCellRenderer) THashMap(gnu.trove.THashMap) ListTreeTableModel(com.intellij.ui.treeStructure.treetable.ListTreeTableModel) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) TableCellEditor(javax.swing.table.TableCellEditor) SpeedSearchComparator(com.intellij.ui.SpeedSearchComparator)

Aggregations

TableColumn (javax.swing.table.TableColumn)272 TableColumnModel (javax.swing.table.TableColumnModel)75 JTable (javax.swing.JTable)51 TableCellRenderer (javax.swing.table.TableCellRenderer)50 JScrollPane (javax.swing.JScrollPane)44 JPanel (javax.swing.JPanel)33 Component (java.awt.Component)31 JLabel (javax.swing.JLabel)26 BoxLayout (javax.swing.BoxLayout)25 JComboBox (javax.swing.JComboBox)23 ActionEvent (java.awt.event.ActionEvent)21 Dimension (java.awt.Dimension)20 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)20 DefaultCellEditor (javax.swing.DefaultCellEditor)19 ActionListener (java.awt.event.ActionListener)17 JButton (javax.swing.JButton)17 FlowLayout (java.awt.FlowLayout)16 DefaultTableModel (javax.swing.table.DefaultTableModel)15 ArrayList (java.util.ArrayList)14 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)12