public void mouseClicked(MouseEvent e) { JTableHeader h = (JTableHeader) e.getSource(); TableColumnModel columnModel = h.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = columnModel.getColumn(viewColumn).getModelIndex(); if (column != -1) { sorting_column = column; // 0 == priority icon column // 4 == priority text column if (column == 0) sorting_column = 4; if (e.isControlDown()) sorting_column = -1; else opposite = !opposite; TaskTable treetable = ((TaskTable) h.getTable()); // java.util.Collection expanded = treetable.getExpandedTreeNodes(); treetable.tableChanged(); // treetable.setExpandedTreeNodes(expanded); // h.updateUI(); h.resizeAndRepaint(); } }
public void setMetricsResults(MetricDisplaySpecification displaySpecification, MetricsRun run) { final MetricCategory[] categories = MetricCategory.values(); for (final MetricCategory category : categories) { final JTable table = tables.get(category); final String type = MetricsCategoryNameUtil.getShortNameForCategory(category); final MetricTableSpecification tableSpecification = displaySpecification.getSpecification(category); final MetricsResult results = run.getResultsForCategory(category); final MetricTableModel model = new MetricTableModel(results, type, tableSpecification); table.setModel(model); final Container tab = table.getParent().getParent(); if (model.getRowCount() == 0) { tabbedPane.remove(tab); continue; } final String longName = MetricsCategoryNameUtil.getLongNameForCategory(category); tabbedPane.add(tab, longName); final MyColumnListener columnListener = new MyColumnListener(tableSpecification, table); final TableColumnModel columnModel = table.getColumnModel(); columnModel.addColumnModelListener(columnListener); final int columnCount = columnModel.getColumnCount(); for (int i = 0; i < columnCount; i++) { final TableColumn column = columnModel.getColumn(i); column.addPropertyChangeListener(columnListener); } setRenderers(table, type); setColumnWidths(table, tableSpecification); } }
public void adjustColumns() { TableColumnModel tcm = table.getColumnModel(); for (int i = 0; i < tcm.getColumnCount(); i++) { adjustColumn(i); } }
private void saveColumnSpecification() { final TableColumnModel columnModel = table.getColumnModel(); final int numColumns = table.getColumnCount(); final List<String> columns = new ArrayList<String>(numColumns); final List<Integer> columnWidths = new ArrayList<Integer>(numColumns); for (int i = 0; i < numColumns; i++) { final String columnName = table.getColumnName(i); columns.add(columnName); final TableColumn column = columnModel.getColumn(i); final int columnWidth = column.getWidth(); columnWidths.add(Integer.valueOf(columnWidth)); } tableSpecification.setColumnOrder(columns); tableSpecification.setColumnWidths(columnWidths); MetricsProfileRepository.getInstance().persistCurrentProfile(); }
public void mouseClicked(MouseEvent e) { JTableHeader h = (JTableHeader) e.getSource(); TableColumnModel columnModel = h.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = columnModel.getColumn(viewColumn).getModelIndex(); if (column != -1) { int status = getSortingStatus(column); if (!e.isControlDown()) { cancelSorting(); } // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed. status = status + (e.isShiftDown() ? -1 : 1); status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1} setSortingStatus(column, status); } }
public void mouseClicked(MouseEvent e) { TableColumnModel colModel = table.getColumnModel(); int columnModelIndex = colModel.getColumnIndexAtX(e.getX()); int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex(); if (modelIndex < 0) return; if (sortCol == modelIndex) isSortAsc = !isSortAsc; else sortCol = modelIndex; for (int i = 0; i < colNames.length; i++) { TableColumn column = colModel.getColumn(i); column.setHeaderValue(getColumnName(column.getModelIndex())); } table.getTableHeader().repaint(); Collections.sort(rowData, new MyComparator(isSortAsc)); table.tableChanged(new TableModelEvent(MyTableModel.this)); table.repaint(); }
private static void setColumnWidths(JTable table, MetricTableSpecification tableSpecification) { final TableModel model = table.getModel(); final TableColumnModel columnModel = table.getColumnModel(); final List<Integer> columnWidths = tableSpecification.getColumnWidths(); final List<String> columnOrder = tableSpecification.getColumnOrder(); if (columnWidths != null && !columnWidths.isEmpty()) { final int columnCount = model.getColumnCount(); for (int i = 0; i < columnCount; i++) { final String columnName = model.getColumnName(i); final int index = columnOrder.indexOf(columnName); if (index != -1) { final Integer width = columnWidths.get(index); final TableColumn column = columnModel.getColumn(i); column.setPreferredWidth(width.intValue()); } } } else { final Graphics graphics = table.getGraphics(); final Font font = table.getFont(); final FontMetrics fontMetrics = table.getFontMetrics(font); final int rowCount = model.getRowCount(); int maxFirstColumnWidth = 100; for (int i = 0; i < rowCount; i++) { final String name = (String) model.getValueAt(i, 0); if (name != null) { final Rectangle2D stringBounds = fontMetrics.getStringBounds(name, graphics); final double stringWidth = stringBounds.getWidth(); if (stringWidth > maxFirstColumnWidth) { maxFirstColumnWidth = (int) stringWidth; } } } final int allocatedFirstColumnWidth = Math.min(300, maxFirstColumnWidth + 5); final TableColumn column = columnModel.getColumn(0); column.setPreferredWidth(allocatedFirstColumnWidth); } }
private static void setRenderers(JTable table, String type) { final MetricTableModel model = (MetricTableModel) table.getModel(); final MetricInstance[] metrics = model.getMetricsInstances(); Arrays.sort(metrics, new MetricInstanceAbbreviationComparator()); final TableColumnModel columnModel = table.getColumnModel(); for (int i = 0; i < model.getColumnCount(); i++) { final String columnName = model.getColumnName(i); final TableColumn column = columnModel.getColumn(i); if (columnName.equals(type)) { column.setCellRenderer(new MetricCellRenderer(null)); column.setHeaderRenderer(new HeaderRenderer(null, model, SwingConstants.LEFT)); } else { final MetricInstance metricInstance = model.getMetricForColumn(i); final TableCellRenderer renderer = new MetricCellRenderer(metricInstance); column.setCellRenderer(renderer); final Metric metric = metricInstance.getMetric(); final String displayName = metric.getDisplayName(); column.setHeaderRenderer(new HeaderRenderer(displayName, model, SwingConstants.RIGHT)); } } }
public ProcessedModulesTable(final Project project) { super(new BorderLayout()); myTableModel = new MyTableModel(project); myTable = new JBTable(myTableModel); myTable.getEmptyText().setText("No modules configured"); // myTable.setShowGrid(false); myTable.setIntercellSpacing(JBUI.emptySize()); myTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); myTable.setColumnSelectionAllowed(false); final TableColumnModel columnModel = myTable.getColumnModel(); final TableColumn dirNameColumn = columnModel.getColumn(myTableModel.DIRNAME_COLUMN_INDEX); final String title = "Generated Sources Directory Name"; dirNameColumn.setHeaderValue(title); final JTableHeader tableHeader = myTable.getTableHeader(); final FontMetrics metrics = tableHeader.getFontMetrics(tableHeader.getFont()); final int preferredWidth = metrics.stringWidth(title) + 12; dirNameColumn.setPreferredWidth(preferredWidth); dirNameColumn.setMaxWidth(preferredWidth + 20); dirNameColumn.setCellRenderer(new MyElementColumnCellRenderer()); final TableColumn moduleColumn = columnModel.getColumn(myTableModel.ELEMENT_COLUMN_INDEX); moduleColumn.setHeaderValue("Module"); moduleColumn.setCellRenderer(new MyElementColumnCellRenderer()); final JPanel panel = ToolbarDecorator.createDecorator(myTable) .disableUpDownActions() .setPreferredSize(JBUI.size(100, 155)) .createPanel(); add(panel, BorderLayout.CENTER); final SpeedSearchBase<JBTable> speedSearch = new SpeedSearchBase<JBTable>(myTable) { public int getSelectedIndex() { return myTable.getSelectedRow(); } @Override protected int convertIndexToModel(int viewIndex) { return myTable.convertRowIndexToModel(viewIndex); } public Object[] getAllElements() { final int count = myTableModel.getRowCount(); Object[] elements = new Object[count]; for (int idx = 0; idx < count; idx++) { elements[idx] = myTableModel.getModuleAt(idx); } return elements; } public String getElementText(Object element) { return ((Module) element).getName() + " (" + FileUtil.toSystemDependentName(((Module) element).getModuleFilePath()) + ")"; } public void selectElement(Object element, String selectedText) { final int count = myTableModel.getRowCount(); for (int row = 0; row < count; row++) { if (element.equals(myTableModel.getModuleAt(row))) { final int viewRow = myTable.convertRowIndexToView(row); myTable.getSelectionModel().setSelectionInterval(viewRow, viewRow); TableUtil.scrollSelectionToVisible(myTable); break; } } } }; speedSearch.setComparator(new SpeedSearchComparator(false)); }
private TableColumnModel getTableColumnModel() { TableColumnModel tcm = new DefaultTableColumnModel(); tcm.addColumn(genColumn(0, 100, "Word")); tcm.addColumn(genColumn(1, 400, "Clue")); return tcm; }
private ElementsChooser(@Nullable List<T> elements, boolean marked, boolean elementsCanBeMarked) { super(new BorderLayout()); myTableModel = new MyTableModel(elementsCanBeMarked); myTable = new Table(myTableModel); myTable.setShowGrid(false); myTable.setIntercellSpacing(new Dimension(0, 0)); myTable.setTableHeader(null); myTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); myTable.setColumnSelectionAllowed(false); JScrollPane pane = ScrollPaneFactory.createScrollPane(myTable); pane.setPreferredSize(new Dimension(100, 155)); int width = new JCheckBox().getPreferredSize().width; TableColumnModel columnModel = myTable.getColumnModel(); if (elementsCanBeMarked) { TableColumn checkMarkColumn = columnModel.getColumn(myTableModel.CHECK_MARK_COLUM_INDEX); checkMarkColumn.setPreferredWidth(width); checkMarkColumn.setMaxWidth(width); checkMarkColumn.setCellRenderer( new CheckMarkColumnCellRenderer(myTable.getDefaultRenderer(Boolean.class))); } columnModel .getColumn(myTableModel.ELEMENT_COLUMN_INDEX) .setCellRenderer(new MyElementColumnCellRenderer()); add(pane, BorderLayout.CENTER); myTable.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { final int[] selectedRows = myTable.getSelectedRows(); boolean currentlyMarked = true; for (int selectedRow : selectedRows) { currentlyMarked = myTableModel.isElementMarked(selectedRow); if (!currentlyMarked) { break; } } myTableModel.setMarked(selectedRows, !currentlyMarked); } }, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_FOCUSED); final SpeedSearchBase<JBTable> speedSearch = new SpeedSearchBase<JBTable>(myTable) { public int getSelectedIndex() { return myTable.getSelectedRow(); } @Override protected int convertIndexToModel(int viewIndex) { return myTable.convertRowIndexToModel(viewIndex); } public Object[] getAllElements() { final int count = myTableModel.getRowCount(); Object[] elements = new Object[count]; for (int idx = 0; idx < count; idx++) { elements[idx] = myTableModel.getElementAt(idx); } return elements; } public String getElementText(Object element) { return getItemText((T) element); } public void selectElement(Object element, String selectedText) { final int count = myTableModel.getRowCount(); for (int row = 0; row < count; row++) { if (element.equals(myTableModel.getElementAt(row))) { final int viewRow = myTable.convertRowIndexToView(row); myTable.getSelectionModel().setSelectionInterval(viewRow, viewRow); TableUtil.scrollSelectionToVisible(myTable); break; } } } }; speedSearch.setComparator(new SpeedSearchBase.SpeedSearchComparator(false)); setElements(elements, marked); installActions(myTable); }
private void initComponents() { setLayout(new BorderLayout()); final JPanel mainPanel = new TransparentPanel(); add(mainPanel, BorderLayout.NORTH); mainPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.anchor = GridBagConstraints.LINE_START; c.fill = GridBagConstraints.HORIZONTAL; // general encryption option enableDefaultEncryption = new SIPCommCheckBox( UtilActivator.getResources() .getI18NString("plugin.sipaccregwizz.ENABLE_DEFAULT_ENCRYPTION"), regform.isDefaultEncryption()); enableDefaultEncryption.addActionListener(this); mainPanel.add(enableDefaultEncryption, c); // warning message and button to show advanced options JLabel lblWarning = new JLabel(); lblWarning.setBorder(new EmptyBorder(10, 5, 10, 0)); lblWarning.setText( UtilActivator.getResources() .getI18NString( "plugin.sipaccregwizz.SECURITY_WARNING", new String[] { UtilActivator.getResources().getSettingsString("service.gui.APPLICATION_NAME") })); c.gridy++; mainPanel.add(lblWarning, c); cmdExpandAdvancedSettings = new JLabel(); cmdExpandAdvancedSettings.setBorder(new EmptyBorder(0, 5, 0, 0)); cmdExpandAdvancedSettings.setIcon( UtilActivator.getResources().getImage("service.gui.icons.RIGHT_ARROW_ICON")); cmdExpandAdvancedSettings.setText( UtilActivator.getResources().getI18NString("plugin.sipaccregwizz.SHOW_ADVANCED")); cmdExpandAdvancedSettings.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { cmdExpandAdvancedSettings.setIcon( UtilActivator.getResources() .getImage( pnlAdvancedSettings.isVisible() ? "service.gui.icons.RIGHT_ARROW_ICON" : "service.gui.icons.DOWN_ARROW_ICON")); pnlAdvancedSettings.setVisible(!pnlAdvancedSettings.isVisible()); pnlAdvancedSettings.revalidate(); } }); c.gridy++; mainPanel.add(cmdExpandAdvancedSettings, c); pnlAdvancedSettings = new TransparentPanel(); pnlAdvancedSettings.setLayout(new GridBagLayout()); pnlAdvancedSettings.setVisible(false); c.gridy++; mainPanel.add(pnlAdvancedSettings, c); c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.gridheight = 1; c.anchor = GridBagConstraints.LINE_START; c.fill = GridBagConstraints.HORIZONTAL; pnlAdvancedSettings.add(new JSeparator(), c); // Encryption protcol preferences. JLabel lblEncryptionProtocolPreferences = new JLabel(); lblEncryptionProtocolPreferences.setText( UtilActivator.getResources() .getI18NString("plugin.sipaccregwizz.ENCRYPTION_PROTOCOL_PREFERENCES")); c.gridy++; pnlAdvancedSettings.add(lblEncryptionProtocolPreferences, c); int nbEncryptionProtocols = ENCRYPTION_PROTOCOLS.length; String[] encryptions = new String[nbEncryptionProtocols]; boolean[] selectedEncryptions = new boolean[nbEncryptionProtocols]; this.encryptionConfigurationTableModel = new EncryptionConfigurationTableModel(encryptions, selectedEncryptions); loadEncryptionProtocols(new HashMap<String, Integer>(), new HashMap<String, Boolean>()); this.encryptionProtocolPreferences = new PriorityTable(this.encryptionConfigurationTableModel, 60); this.encryptionConfigurationTableModel.addTableModelListener(this); c.gridy++; pnlAdvancedSettings.add(this.encryptionProtocolPreferences, c); // ZRTP JLabel lblZrtpOption = new JLabel(); lblZrtpOption.setBorder(new EmptyBorder(5, 5, 5, 0)); lblZrtpOption.setText( UtilActivator.getResources().getI18NString("plugin.sipaccregwizz.ZRTP_OPTION")); c.gridx = 0; c.gridy++; c.gridwidth = 1; pnlAdvancedSettings.add(lblZrtpOption, c); c.gridx = 1; pnlAdvancedSettings.add(new JSeparator(), c); enableSipZrtpAttribute = new SIPCommCheckBox( UtilActivator.getResources() .getI18NString("plugin.sipaccregwizz.ENABLE_SIPZRTP_ATTRIBUTE"), regform.isSipZrtpAttribute()); c.gridx = 0; c.gridy++; c.gridwidth = 2; pnlAdvancedSettings.add(enableSipZrtpAttribute, c); // SDES JLabel lblSDesOption = new JLabel(); lblSDesOption.setBorder(new EmptyBorder(5, 5, 5, 0)); lblSDesOption.setText( UtilActivator.getResources().getI18NString("plugin.sipaccregwizz.SDES_OPTION")); c.gridx = 0; c.gridy++; c.gridwidth = 1; pnlAdvancedSettings.add(lblSDesOption, c); c.gridx = 1; pnlAdvancedSettings.add(new JSeparator(), c); JLabel lblCipherInfo = new JLabel(); lblCipherInfo.setText( UtilActivator.getResources().getI18NString("plugin.sipaccregwizz.CIPHER_SUITES")); c.gridx = 0; c.gridy++; c.gridwidth = 2; pnlAdvancedSettings.add(lblCipherInfo, c); cipherModel = new CipherTableModel(regform.getSDesCipherSuites()); tabCiphers = new JTable(cipherModel); tabCiphers.setShowGrid(false); tabCiphers.setTableHeader(null); TableColumnModel tableColumnModel = tabCiphers.getColumnModel(); TableColumn tableColumn = tableColumnModel.getColumn(0); tableColumn.setMaxWidth(tableColumn.getMinWidth()); JScrollPane scrollPane = new JScrollPane(tabCiphers); scrollPane.setPreferredSize(new Dimension(tabCiphers.getWidth(), 100)); c.gridy++; pnlAdvancedSettings.add(scrollPane, c); // SAVP selection c.gridx = 0; c.gridwidth = 1; JLabel lblSavpOption = new JLabel(); lblSavpOption.setBorder(new EmptyBorder(5, 5, 5, 0)); lblSavpOption.setText( UtilActivator.getResources().getI18NString("plugin.sipaccregwizz.SAVP_OPTION")); if (this.displaySavpOtions) { c.gridy++; pnlAdvancedSettings.add(lblSavpOption, c); } c.gridx = 1; if (this.displaySavpOtions) { pnlAdvancedSettings.add(new JSeparator(), c); } cboSavpOption = new JComboBox(new SavpOption[] {new SavpOption(0), new SavpOption(1), new SavpOption(2)}); c.gridx = 0; c.gridwidth = 2; c.insets = new Insets(0, 20, 0, 0); if (this.displaySavpOtions) { c.gridy++; pnlAdvancedSettings.add(cboSavpOption, c); } }