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();
    }
  }
Ejemplo n.º 2
0
  /**
   * Set the current selection to this row.
   *
   * @param rowno index into rowList
   */
  public void setSelectedRow(int rowno) {
    if ((rowno < 0) || (rowno >= model.getRowCount())) return;
    if (debugSetPath) System.out.println("TreeTableSorted setSelected " + rowno);

    selectedRow = model.getRow(rowno);
    TreePath path = model.getPath(selectedRow);
    if (path != null) table.setSelectionPath(path);

    // for mysterious reasons, gotta do it again later
    invokeSetPath();
    ensureRowIsVisible(rowno);
  }
Ejemplo n.º 3
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.º 4
0
  /**
   * Get the currently selected rows.
   *
   * @return an Iterator whose objects are TableRow
   */
  public Iterator getSelectedRows() {
    TreePath[] paths = table.getSelectionPaths();
    if ((paths == null) || (paths.length < 1)) return null;

    HashSet set = new HashSet(2 * paths.length);
    for (int i = 0; i < paths.length; i++) {
      model.addRowsToSetFromPath(table.getTree(), paths[i], set);
    }

    return set.iterator();
  }
Ejemplo n.º 5
0
  /**
   * Replace the rowList with this one.
   *
   * @param rows list of rows
   */
  public void setRows(ArrayList rows) {
    model.setRows(rows);

    /*    if (rowList.size() > 0)
      table.setRowSelectionInterval(0, 0);
    else
      table.clearSelection(); */

    // table.clearSelection();
    table.fireDataChanged();
  }
Ejemplo n.º 6
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.º 7
0
 /**
  * Get the currently selected row.
  *
  * @return selected TableRow
  */
 public TableRow getSelectedRow() {
   return model.getRow(table.getSelectionPath());
 }
Ejemplo n.º 8
0
 public ArrayList getRows() {
   return model.getRows();
 }
Ejemplo n.º 9
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.º 10
0
 public TableRow getRow(int row) {
   return model.getRow(table.getPathForRow(row));
 }