Ejemplo n.º 1
0
  /** Save state to the PreferencesExt. */
  public void saveState(PreferencesExt store) {
    if (store == null) return;

    int ncols = table.getColumnCount();
    int[] size = new int[ncols];
    int[] modelIndex = new int[ncols];

    TableColumnModel tcm = table.getColumnModel();
    for (int i = 0; i < ncols; i++) {
      TableColumn tc = tcm.getColumn(i);
      size[i] = tc.getWidth();
      modelIndex[i] = tc.getModelIndex();
    }
    store.putBeanObject("ColumnWidths", size);
    store.putBeanObject("ColumnOrder", modelIndex);

    store.putInt("SortOnCol", model.getSortCol());
    store.putBoolean("SortReverse", model.getReverse());
    store.putBoolean("isThreadsOn", model.isThreadsOn());

    if (debug) {
      System.out.println(" store widths = ");
      for (int i = 0; i < size.length; i++) System.out.print(" " + size[i]);
      System.out.println();
    }
  }
    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();
      }
    }
Ejemplo n.º 3
0
  private int getHeaderHeight() {
    if ((header == null) || (header.getTable() == null)) {
      return 0;
    }
    int height = 0;
    boolean accomodatedDefault = false;
    TableColumnModel columnModel = header.getColumnModel();
    for (int column = 0; column < columnModel.getColumnCount(); column++) {
      TableColumn aColumn = columnModel.getColumn(column);
      boolean isDefault = (aColumn.getHeaderRenderer() == null);

      if (!isDefault || !accomodatedDefault) {
        Component comp = getHeaderRenderer(column);
        int rendererHeight = comp.getPreferredSize().height;
        height = Math.max(height, rendererHeight);

        // Configuring the header renderer to calculate its preferred size
        // is expensive. Optimise this by assuming the default renderer
        // always has the same height as the first non-zero height that
        // it returns for a non-null/non-empty value.
        if (isDefault && rendererHeight > 0) {
          Object headerValue = aColumn.getHeaderValue();
          if (headerValue != null) {
            headerValue = headerValue.toString();

            if (headerValue != null && !headerValue.equals("")) {
              accomodatedDefault = true;
            }
          }
        }
      }
    }
    return height + 2;
  }
  public void adjustColumns() {
    TableColumnModel tcm = table.getColumnModel();

    for (int i = 0; i < tcm.getColumnCount(); i++) {
      adjustColumn(i);
    }
  }
Ejemplo n.º 5
0
 public void setSortCol(int sortCol, boolean reverse) {
   TableColumnModel tcm = table.getColumnModel();
   for (int i = 0; i < table.getColumnCount(); i++) {
     TableColumn tc = tcm.getColumn(i);
     SortedHeaderRenderer shr = (SortedHeaderRenderer) tc.getHeaderRenderer();
     shr.setSortCol(sortCol, reverse);
   }
 }
 private int viewIndexForColumn(TableColumn aColumn) {
   TableColumnModel cm = header.getColumnModel();
   for (int column = 0; column < cm.getColumnCount(); column++) {
     if (cm.getColumn(column) == aColumn) {
       return column;
     }
   }
   return -1;
 }
Ejemplo n.º 7
0
 private void setColumnWidths(int[] sizes) {
   TableColumnModel tcm = table.getColumnModel();
   for (int i = 0; i < table.getColumnCount(); i++) {
     TableColumn tc = tcm.getColumn(i);
     int maxw = ((sizes == null) || (i >= sizes.length)) ? 10 : sizes[i];
     //     model.getPreferredWidthForColumn(tc) : sizes[i];
     tc.setPreferredWidth(maxw);
   }
   // table.sizeColumnsToFit(0);     //  must be called due to a JTable bug
 }
Ejemplo n.º 8
0
    public void actionPerformed(ActionEvent e) {
      boolean state = ((Boolean) getValue(BAMutil.STATE)).booleanValue();
      TableColumnModel tcm = table.getColumnModel();

      if (state) {
        if (tc != null) tcm.addColumn(tc);
      } else hideColumn();

      JTreeTableSorted.this.revalidate();
      // System.out.println(id+" "+state);
    }
Ejemplo n.º 9
0
 public void hideColumn() {
   // System.out.println("hideColumn "+id);
   TableColumnModel tcm = table.getColumnModel();
   try {
     int idx = tcm.getColumnIndex(id);
     tc = tcm.getColumn(idx);
     tcm.removeColumn(tc);
   } catch (Exception e) {
     // System.out.println("hideColumn didnt find"+id);
   }
 }
Ejemplo n.º 10
0
    public void addAtPos(int pos) {
      if (tc == null) return;

      TableColumnModel tcm = table.getColumnModel();

      // make sure it doesnt already exist
      try {
        tcm.addColumn(tc);
        int idx = tcm.getColumnIndex(id);
        tcm.moveColumn(idx, 0);
      } catch (Exception e) {
        System.out.println("addAtPos failed" + e);
      }
    }
Ejemplo n.º 11
0
  /** this array translates the column index to the model index */
  public int[] getModelIndex() {
    int[] modelIndex = new int[model.getColumnCount()];

    try {
      TableColumnModel tcm = table.getColumnModel();
      for (int i = 0; i < model.getColumnCount(); i++) {
        TableColumn tc = tcm.getColumn(i);
        modelIndex[i] = tc.getModelIndex();
      }
    } catch (java.lang.ArrayIndexOutOfBoundsException e) {
      // can happen when model size increases
    }

    return modelIndex;
  }
Ejemplo n.º 12
0
 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);
   }
 }
Ejemplo n.º 13
0
    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();
    }
Ejemplo n.º 14
0
  GroupableHeaderExample() {
    super("Groupable Header Example");

    DefaultTableModel dm = new DefaultTableModel();
    dm.setDataVector(
        new Object[][] {
          {"119", "foo", "bar", "ja", "ko", "zh"},
          {"911", "bar", "foo", "en", "fr", "pt"}
        },
        new Object[] {"SNo.", "1", "2", "Native", "2", "3"});

    JTable table =
        new JTable(dm) {
          protected JTableHeader createDefaultTableHeader() {
            return new GroupableTableHeader(columnModel);
          }
        };

    TableColumnModel cm = table.getColumnModel();
    ColumnGroup g_name = new ColumnGroup("Name");
    g_name.add(cm.getColumn(1));
    g_name.add(cm.getColumn(2));
    ColumnGroup g_lang = new ColumnGroup("Language");
    g_lang.add(cm.getColumn(3));
    ColumnGroup g_other = new ColumnGroup("Others");
    g_other.add(cm.getColumn(4));
    g_other.add(cm.getColumn(5));
    g_lang.add(g_other);

    GroupableTableHeader header = (GroupableTableHeader) table.getTableHeader();
    header.addColumnGroup(g_name);
    header.addColumnGroup(g_lang);
    JScrollPane scroll = new JScrollPane(table);
    getContentPane().add(scroll);
    setSize(400, 120);
  }
Ejemplo n.º 15
0
  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);
    }
  }
Ejemplo n.º 16
0
  public void paint(Graphics g, JComponent c) {
    if ((header == null)
        || (header.getTable() == null)
        || header.getColumnModel().getColumnCount() <= 0) {
      return;
    }

    boolean ltr = header.getComponentOrientation().isLeftToRight();
    Rectangle clip = g.getClipBounds();
    Point left = clip.getLocation();
    Point right = new Point(clip.x + clip.width - 1, clip.y);
    TableColumnModel cm = header.getColumnModel();
    int cMin = header.columnAtPoint(ltr ? left : right);
    int cMax = header.columnAtPoint(ltr ? right : left);
    // This should never happen.
    if (cMin == -1) {
      cMin = 0;
    }
    // If the table does not have enough columns to fill the view we'll get -1.
    // Replace this with the index of the last column.
    if (cMax == -1) {
      cMax = cm.getColumnCount() - 1;
    }

    TableColumn draggedColumn = header.getDraggedColumn();
    Rectangle cellRect = header.getHeaderRect(ltr ? cMin : cMax);
    int columnWidth;
    TableColumn aColumn;
    if (ltr) {
      for (int column = cMin; column <= cMax; column++) {
        aColumn = cm.getColumn(column);
        columnWidth = aColumn.getWidth();
        cellRect.width = columnWidth;
        if (aColumn != draggedColumn) {
          paintCell(g, cellRect, column);
        }
        cellRect.x += columnWidth;
      }
    } else {
      for (int column = cMax; column >= cMin; column--) {
        aColumn = cm.getColumn(column);
        columnWidth = aColumn.getWidth();
        cellRect.width = columnWidth;
        if (aColumn != draggedColumn) {
          paintCell(g, cellRect, column);
        }
        cellRect.x += columnWidth;
      }
    }

    // Paint the dragged column if we are dragging.
    if (draggedColumn != null) {
      int draggedColumnIndex = viewIndexForColumn(draggedColumn);
      Rectangle draggedCellRect = header.getHeaderRect(draggedColumnIndex);
      // Draw a gray well in place of the moving column.
      g.setColor(header.getParent().getBackground());
      g.fillRect(
          draggedCellRect.x, draggedCellRect.y, draggedCellRect.width, draggedCellRect.height);
      draggedCellRect.x += header.getDraggedDistance();

      // Fill the background.
      g.setColor(header.getBackground());
      g.fillRect(
          draggedCellRect.x, draggedCellRect.y, draggedCellRect.width, draggedCellRect.height);
      paintCell(g, draggedCellRect, draggedColumnIndex);
    }

    // Remove all components in the rendererPane.
    rendererPane.removeAll();
  }
Ejemplo n.º 17
0
  /**
   * Set the state from the last saved in the PreferencesExt.
   *
   * @param store ok if null or empty
   */
  public void restoreState(PreferencesExt store) {
    if (store == null) return;

    int ncols = table.getColumnCount();

    // stored column order
    int[] modelIndex = (int[]) store.getBean("ColumnOrder", null);

    if ((modelIndex != null) && (modelIndex.length == ncols)) { // what about invisible ??

      // make invisible any not stored
      boolean[] visible = new boolean[ncols];
      for (int i = 0; i < modelIndex.length; i++)
        if (modelIndex[i] < ncols) visible[modelIndex[i]] = true;

      // modify popup menu
      for (int i = 0; i < ncols; i++)
        if (!visible[i]) {
          // System.out.println( colName[i]+" hide "+i);
          acts[i].hideColumn();
          acts[i].putValue(BAMutil.STATE, new Boolean(false));
        }

      // now set the header order
      TableColumnModel tcm = table.getColumnModel();
      int n = Math.min(modelIndex.length, table.getColumnCount());
      for (int i = 0; i < n; i++) {
        TableColumn tc = tcm.getColumn(i);
        tc.setModelIndex(modelIndex[i]);
        String name = model.getColumnName(modelIndex[i]);
        tc.setHeaderValue(name);
        tc.setIdentifier(name);
        if (useThreads && (modelIndex[i] == threadCol)) {
          threadHeaderRenderer = new ThreadHeaderRenderer(threadCol);
          tc.setHeaderRenderer(threadHeaderRenderer);
        } else tc.setHeaderRenderer(new SortedHeaderRenderer(name, modelIndex[i]));
      }
    }

    // set the column widths
    Object colWidths = store.getBean("ColumnWidths", null);
    if (colWidths == null) return;
    int[] size = (int[]) colWidths;

    if (size != null) setColumnWidths(size);
    if (debug) {
      System.out.println(" read widths = ");
      for (int i = 0; i < size.length; i++) System.out.print(" " + size[i]);
      System.out.println();
    }

    boolean isThreadsOn = store.getBoolean("isThreadsOn", false);
    if (useThreads) {
      model.setThreadsOn(isThreadsOn);
      threadHeaderRenderer.setOn(isThreadsOn);
    }

    int colNo = store.getInt("SortOnCol", 0);
    boolean reverse = store.getBoolean("SortReverse", false);
    model.setSortCol(colNo);
    model.setReverse(reverse);
    setSortCol(colNo, reverse);

    model.sort();
    table.fireDataChanged();
  }
Ejemplo n.º 18
0
  private <T extends Enum<T>> void createControls(JPanel panel, ZrtpConfigureTableModel<T> model) {
    ResourceManagementService resources = NeomediaActivator.getResources();

    final JButton upButton = new JButton(resources.getI18NString("impl.media.configform.UP"));
    upButton.setOpaque(false);

    final JButton downButton = new JButton(resources.getI18NString("impl.media.configform.DOWN"));
    downButton.setOpaque(false);

    Container buttonBar = new TransparentPanel(new GridLayout(0, 1));
    buttonBar.add(upButton);
    buttonBar.add(downButton);

    panel.setBorder(BorderFactory.createEmptyBorder(MARGIN, MARGIN, MARGIN, MARGIN));
    panel.setLayout(new GridBagLayout());

    final JTable table = new JTable(model.getRowCount(), 2);
    table.setShowGrid(false);
    table.setTableHeader(null);
    table.setModel(model);
    // table.setFillsViewportHeight(true); // Since 1.6 only - nicer view

    /*
     * The first column contains the check boxes which enable/disable their
     * associated encodings and it doesn't make sense to make it wider than
     * the check boxes.
     */
    TableColumnModel tableColumnModel = table.getColumnModel();
    TableColumn tableColumn = tableColumnModel.getColumn(0);
    tableColumn.setMaxWidth(tableColumn.getMinWidth() + 5);
    table.doLayout();

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridwidth = 1;
    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.weightx = 1;
    constraints.weighty = 1;
    panel.add(new JScrollPane(table), constraints);

    constraints.anchor = GridBagConstraints.NORTHEAST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridwidth = 1;
    constraints.gridx = 1;
    constraints.gridy = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    panel.add(buttonBar, constraints);

    ListSelectionListener tableSelectionListener =
        new ListSelectionListener() {
          @SuppressWarnings("unchecked")
          public void valueChanged(ListSelectionEvent event) {
            if (table.getSelectedRowCount() == 1) {
              int selectedRow = table.getSelectedRow();
              if (selectedRow > -1) {
                ZrtpConfigureTableModel<T> model = (ZrtpConfigureTableModel<T>) table.getModel();
                upButton.setEnabled(selectedRow > 0 && model.checkEnableUp(selectedRow));
                downButton.setEnabled(
                    selectedRow < (table.getRowCount() - 1) && model.checkEnableDown(selectedRow));
                return;
              }
            }
            upButton.setEnabled(false);
            downButton.setEnabled(false);
          }
        };
    table.getSelectionModel().addListSelectionListener(tableSelectionListener);

    TableModelListener tableListener =
        new TableModelListener() {
          @SuppressWarnings("unchecked")
          public void tableChanged(TableModelEvent e) {
            if (table.getSelectedRowCount() == 1) {
              int selectedRow = table.getSelectedRow();
              if (selectedRow > -1) {
                ZrtpConfigureTableModel<T> model = (ZrtpConfigureTableModel<T>) table.getModel();
                upButton.setEnabled(selectedRow > 0 && model.checkEnableUp(selectedRow));
                downButton.setEnabled(
                    selectedRow < (table.getRowCount() - 1) && model.checkEnableDown(selectedRow));
                return;
              }
            }
            upButton.setEnabled(false);
            downButton.setEnabled(false);
          }
        };
    table.getModel().addTableModelListener(tableListener);

    tableSelectionListener.valueChanged(null);

    ActionListener buttonListener =
        new ActionListener() {
          @SuppressWarnings("unchecked")
          public void actionPerformed(ActionEvent event) {
            Object source = event.getSource();
            boolean up;
            if (source == upButton) up = true;
            else if (source == downButton) up = false;
            else return;

            int index =
                ((ZrtpConfigureTableModel<T>) table.getModel())
                    .move(table.getSelectedRow(), up, up);
            table.getSelectionModel().setSelectionInterval(index, index);
          }
        };
    upButton.addActionListener(buttonListener);
    downButton.addActionListener(buttonListener);
  }
Ejemplo n.º 19
0
  /**
   * Constructor.
   *
   * @param m TreeTableModelSorted m
   */
  public JTreeTableSorted(TreeTableModelSorted m, boolean allowSortColChange) {

    this.model = m;
    this.useThreads = model.useThreads();
    this.treeSort = model.isTreeSort();

    // create the ui
    table = new JTreeTable(model);
    setLayout(new BorderLayout());
    scrollPane = new JScrollPane(table);
    add(scrollPane, BorderLayout.CENTER);

    // table.setSelectionMode( ListSelectionModel.SINGLE_SELECTION);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
    // table.setFont( table.getFont().deriveFont( Font.BOLD));

    // now set the header renderers
    TableColumnModel tcm = table.getColumnModel();
    int ncolwt = useThreads ? table.getColumnCount() - 1 : table.getColumnCount();
    for (int i = 0; i < ncolwt; i++) {
      TableColumn tc = tcm.getColumn(i);
      tc.setHeaderRenderer(new SortedHeaderRenderer(model.getColumnName(i), i));
    }
    if (useThreads) {
      threadCol = ncolwt;
      threadHeaderRenderer = new ThreadHeaderRenderer(threadCol);
      tcm.getColumn(threadCol).setHeaderRenderer(threadHeaderRenderer);
    }

    // popupMenu
    popupMenu = new ucar.nc2.ui.widget.PopupMenu(table.getTableHeader(), "Visible");
    int ncols = model.getColumnCount();
    acts = new PopupAction[ncols];
    for (int i = 0; i < ncols; i++) {
      acts[i] = new PopupAction(model.getColumnName(i));
      popupMenu.addActionCheckBox(model.getColumnName(i), acts[i], true);
    }

    // listen for list selection
    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting() && lm.hasListeners() && (listSelectionEvent == null)) {
                  listSelectionEvent = e;
                  if (debugEvent) System.out.println(" JTreeTableSorted message selected = " + e);
                  SwingUtilities.invokeLater(
                      new Runnable() { // gotta do this after the dust settles

                        public void run() {
                          lm.sendEvent(listSelectionEvent);
                          listSelectionEvent = null; // dont like this
                        }
                      }); // new Runnable
                }
              }
            }); // new ListSelectionListener

    // listen for mouse clicks on the column header
    allowSortColChangeMouseListener =
        new MyMouseAdapter() {
          public void click(MouseEvent e) {
            TableColumnModel tcm2 = table.getColumnModel();
            int colIdx = tcm2.getColumnIndexAtX(e.getX());
            int colNo = table.convertColumnIndexToModel(colIdx);

            // keep track of selection
            selectedRow = getSelectedRow();
            if (debug) System.out.println("----selectedRow = " + selectedRow);

            if (colNo == threadCol) { // toggle threads
              threadHeaderRenderer.setOn(!threadHeaderRenderer.isOn);
              model.setThreadsOn(threadHeaderRenderer.isOn);
              model.sort();
            } else {
              boolean reverse = model.sort(colNo);
              setSortCol(colNo, reverse);
            }

            table.fireDataChanged();
            invokeSetPath();
          }
        };
    allowSortColChange(allowSortColChange);

    // event manager for ListSelection
    lm =
        new ListenerManager(
            "javax.swing.event.ListSelectionListener",
            "javax.swing.event.ListSelectionEvent",
            "valueChanged");

    // default sort
    setSortCol(model.getSortCol(), model.getReverse());
  }
Ejemplo n.º 20
0
 private TableColumnModel getTableColumnModel() {
   TableColumnModel tcm = new DefaultTableColumnModel();
   tcm.addColumn(genColumn(0, 100, "Word"));
   tcm.addColumn(genColumn(1, 400, "Clue"));
   return tcm;
 }