Exemple #1
0
 private static JTable createUITable(
     boolean keyColumnResizable, int typeWidth, Type type, List<String> lst, Actions editAction) {
   String[] keys = lst.toArray(new String[lst.size()]);
   Arrays.sort(keys);
   TableModel mdl = type == null ? new UITableModel(keys) : new UITypeTableModel(keys, type, true);
   JTable table = new UITable(mdl, null);
   table.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);
   table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
   table.setRowHeight(25);
   TableColumnModel columns = table.getColumnModel();
   int keyWidth = TABLE_WIDTH - typeWidth - VALUE_WIDTH - DEFAULT_WIDTH;
   columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setMinWidth(keyWidth);
   columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setPreferredWidth(keyWidth);
   columns.getColumn(UITableModel.KEY_COLUMN_INDEX).setResizable(keyColumnResizable);
   Creator.setWidth(columns.getColumn(UITableModel.TYPE_COLUMN_INDEX), typeWidth);
   TableColumn column = columns.getColumn(UITableModel.VALUE_COLUMN_INDEX);
   Creator.setWidth(column, VALUE_WIDTH);
   column.setCellRenderer(new UIDefaultsRenderer());
   column.setCellEditor(new UIDefaultsEditor());
   Creator.setWidth(columns.getColumn(UITableModel.DEFAULT_COLUMN_INDEX), DEFAULT_WIDTH);
   table.setAutoCreateRowSorter(true);
   DefaultRowSorter<?, ?> sorter = (DefaultRowSorter<?, ?>) table.getRowSorter();
   sorter.setSortable(UITableModel.VALUE_COLUMN_INDEX, false);
   table
       .getInputMap(JComponent.WHEN_FOCUSED)
       .put(KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0), editAction);
   table.getActionMap().put(editAction, editAction);
   return table;
 }
Exemple #2
0
 private void updateFilter() {
   DefaultRowSorter<TableModel, Object> sorter =
       (DefaultRowSorter<TableModel, Object>) otherTable.getRowSorter();
   String key = keyFilter.getSelectedItem().toString();
   RowFilter<TableModel, Object> filter = null;
   if (!key.isEmpty()) {
     Object method = keyFilterMethod.getSelectedItem();
     if (method == STARTS_WITH) {
       filter = RowFilter.regexFilter('^' + Pattern.quote(key), UITableModel.KEY_COLUMN_INDEX);
     } else if (method == ENDS_WITH) {
       filter = RowFilter.regexFilter(Pattern.quote(key) + '$', UITableModel.KEY_COLUMN_INDEX);
     } else if (method == CONTAINS) {
       filter = RowFilter.regexFilter(Pattern.quote(key), UITableModel.KEY_COLUMN_INDEX);
     } else {
       filter = RowFilter.regexFilter(key, UITableModel.KEY_COLUMN_INDEX);
     }
   }
   String type = typeFilter.getSelectedItem().toString();
   if (!type.isEmpty()) {
     RowFilter<TableModel, Object> typeFilter =
         RowFilter.regexFilter('^' + type + '$', UITableModel.TYPE_COLUMN_INDEX);
     filter =
         filter == null
             ? typeFilter
             : RowFilter.<TableModel, Object>andFilter(Arrays.asList(filter, typeFilter));
   }
   sorter.setRowFilter(filter);
 }
  /**
   * Expects a VisualNode with a proper {@link HostVisualNode#getData() } return value.
   *
   * @param n Node to show all connections for.
   */
  public ConnectionDialog(HostVisualNode n) {
    if (n == null || !n.isHost()) {
      this.treeViewNode = null;
      return;
    }

    initComponents();
    setTitle(String.format("%s Connections", n.getName()));
    this.iconLabel.setIcon(n.getDetails().image.getIcon());
    this.model = getNewModel();
    this.model.setColumnIdentifiers(ConnectionDialog.COLUMNS);
    this.table.setModel(this.model);
    this.table.setAutoCreateRowSorter(true);
    DefaultRowSorter sorter = (DefaultRowSorter) this.table.getRowSorter();
    Comparator comp =
        (o1, o2) -> {
          int compare;
          try {
            compare =
                Integer.compare(Integer.valueOf(o1.toString()), Integer.valueOf(o2.toString()));
          } catch (Exception ex) {
            compare = o1.toString().compareTo(o2.toString());
          }
          return compare;
        };
    sorter.setComparator(1, comp);
    sorter.setComparator(3, comp);
    sorter.setComparator(8, comp);
    sorter.setComparator(9, comp);
    this.table.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
              int row = table.rowAtPoint(e.getPoint());
              Object obj = table.getValueAt(row, PACKET);
              try {
                Integer frame = Integer.valueOf(obj.toString());
                String path = table.getValueAt(row, FILE).toString();
                ConnectionDialog.this.openPopup(e.getPoint(), frame, path);
              } catch (Exception ex) {
                Logger.getLogger(getClass().getName())
                    .log(Level.SEVERE, "Failed to get pcap frame number.", ex);
              }
            }
          }
        });
    this.treeViewNode = n;
    pack();
  }
 /**
  * {@inheritDoc}
  *
  * <p>
  */
 @Override
 public void setSortable(int column, boolean sortable) {
   super.setSortable(column, sortable);
 }