Example #1
0
    @Override
    public void update(Observable o, Object arg) {

      Set<Integer> oldSelection = new HashSet<Integer>();
      oldSelection.addAll(selection);

      SortedSet<Feature> fs = model.selectionModel().getFeatureSelection();
      // System.out.println(fs);
      // int prevIndex = selectedIndex;
      if (fs.size() > 0) {
        for (Feature f : fs) {
          selection.add(listModel.getRow(f));
        }

      } else {
        selection.clear();
      }
      oldSelection.retainAll(selection);
      if (oldSelection.size() != selection.size()) {
        fireValueChanged(false);
      }

      // getSelectionModel().setSelectionInterval(row, row);

    }
Example #2
0
 public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex) {
   Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
   if (c instanceof JComponent) {
     JComponent jc = (JComponent) c;
     String longDisplay = model.getTrackList().get(rowIndex).config().displayName();
     jc.setToolTipText(longDisplay);
   }
   return c;
 }
Example #3
0
  @Override
  public void update(Observable o, Object arg) {
    SortedSet<Feature> fs = model.selectionModel().getFeatureSelection();

    if (fs.size() == 1) {

      if (fs.first().type() == listModel.getType()) {
        int row = listModel.getRow(fs.first());
        // getSelectionModel().setSelectionInterval(row, row);
        if (!(getParent() instanceof JViewport)) {
          return;
        }
        JViewport viewport = (JViewport) getParent();

        // This rectangle is relative to the table where the
        // northwest corner of cell (0,0) is always (0,0).
        Rectangle rect = getCellRect(row, 0, true);

        // The location of the view relative to the table
        Rectangle viewRect = viewport.getViewRect();

        int topVisible = viewport.getViewRect().y;
        int bottomVisible = viewport.getViewRect().height + topVisible;

        /* When the cell is visible, don't do anything */
        if (rect.y > topVisible && rect.y + rect.height < bottomVisible) {
          return;
        }
        // Translate the cell location so that it is relative
        // to the view, assuming the northwest corner of the
        // view is (0,0).
        rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y);

        // Calculate location of rect if it were at the center of view
        int centerX = (viewRect.width - rect.width) / 2;
        int centerY = (viewRect.height - rect.height) / 2;

        // Fake the location of the cell so that scrollRectToVisible
        // will move the cell to the center
        if (rect.x < centerX) {
          centerX = -centerX;
        }
        if (rect.y < centerY) {
          centerY = -centerY;
        }
        rect.translate(centerX, centerY);

        // Scroll the area into view.
        viewport.scrollRectToVisible(rect);
      }
    }
  }
Example #4
0
  public FeatureTable(final Model model) {
    super(new FeatureTableModel(model));
    FeatureTableSelectionModel ftsm = new FeatureTableSelectionModel(model);
    setSelectionModel(ftsm);
    setDefaultRenderer(String.class, new FeatureTableCellRenderer());
    model.addObserver(this);
    this.model = model;
    listModel = (FeatureTableModel) this.getModel();

    // setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    // getColumnModel().getColumn(0).setPreferredWidth(200);
    for (int i = 1; i < this.getColumnCount(); i++) {
      getColumnModel().getColumn(i).setPreferredWidth(30);
      getColumnModel().getColumn(i).setMaxWidth(50);
    }
    getTableHeader().addMouseMotionListener(new ColumnHeaderToolTips(listModel));
    getTableHeader().setReorderingAllowed(false);

    ToolTipManager.sharedInstance().setInitialDelay(0);

    addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 0) {

              Feature rf = listModel.getFeature(rowAtPoint(e.getPoint()));

              model.selectionModel().setLocationSelection(rf);

              if (e.getClickCount() > 1) {
                int min = rf.start();
                int max = rf.end();
                model.vlm.center((min + max) / 2);
              }
            }
          }
        });
  }
Example #5
0
  @Override
  public boolean dispatchKeyEvent(KeyEvent e) {

    if (!FocusManager.getCurrentManager()
        .getActiveWindow()
        .equals(model.getGUIManager().getParent())) return false;
    if (e.getID() == KeyEvent.KEY_PRESSED) {
      switch (e.getKeyCode()) {
        case KeyEvent.VK_HOME:
          start.actionPerformed(null);
          return true;
        case KeyEvent.VK_END:
          end.actionPerformed(null);
          return true;
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_NUMPAD4:
          left.actionPerformed(null);
          return true;
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_NUMPAD6:
          right.actionPerformed(null);
          return true;
        case KeyEvent.VK_ADD:
        case KeyEvent.VK_UP:
        case KeyEvent.VK_PLUS:
        case KeyEvent.VK_EQUALS:
          zoomin.actionPerformed(null);
          return true;
        case KeyEvent.VK_SUBTRACT:
        case KeyEvent.VK_DOWN:
        case KeyEvent.VK_MINUS:
          zoomout.actionPerformed(null);
          return true;
        case KeyEvent.VK_DELETE:
        case KeyEvent.VK_BACK_SPACE:
          remove.actionPerformed(null);
          return true;
        default:
          return false;
          // do nothing
      }
    }
    return false;

    // /* zoom in */
    // inputs.put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0),
    // "customZoomIn");
    // actions.put("customZoomIn", new AnnotationZoomInAction(model));
    // inputs.put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0),
    // "customZoomOut");
    // actions.put("customZoomOut", new AnnotationZoomOutAction(model));
    //
    // /* select first from selection */
    // inputs.put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD7, 0),
    // "customSelectFirst");
    // inputs.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0),
    // "customSelectFirst");
    // actions.put("customSelectFirst", new SelectFromSelectedFirst(model));
    //
    // /* select last from selection */
    // inputs.put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD1, 0),
    // "customSelectLast");
    // inputs.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0),
    // "customSelectLast");
    // actions.put("customSelectLast", new SelectFromSelectedLast(model));
    //
    // /* move selection one location forward */
    // inputs.put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD9, 0),
    // "customSelectForward");
    // inputs.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0),
    // "customSelectForward");
    // actions
    // .put("customSelectForward",
    // new SelectFromSelectedForward(model));
    //
    // /* move selection one location back */
    // inputs.put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD3, 0),
    // "customSelectBack");
    // inputs.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0),
    // "customSelectBack");
    // actions.put("customSelectBack", new SelectFromSelectedBack(model));

  }
Example #6
0
 public FeatureTableSelectionModel(Model model) {
   this.model = model;
   model.addObserver(this);
 }