/**
   * scrolls to selected line number
   *
   * @param lineNumber the line number to scroll to
   * @param toTop display on the top row
   * @return true if .. , false if
   */
  public boolean scrollToLine(final int lineNumber, final boolean toTop) {
    final int lineNumbers = m_sourceModel.getLineNumbers();

    if ((lineNumber >= 0) && (lineNumber < lineNumbers)) {
      int viewColumnIndex = 0;

      Rectangle rect = m_sourceCode.getCellRect(lineNumber, viewColumnIndex, true);

      JViewport viewport = (JViewport) m_sourceCode.getParent();

      if (toTop) {
        Rectangle lastRect = m_sourceCode.getCellRect(lineNumbers - 1, viewColumnIndex, true);
        viewport.scrollRectToVisible(lastRect);
      }

      Point pt = viewport.getViewPosition();
      rect.setLocation(rect.x - pt.x, rect.y - pt.y);

      // Scroll the area into view

      viewport.scrollRectToVisible(rect);

      m_sourceCode.repaint();

      return true;
    }
    return false;
  }
示例#2
0
 @Override
 public void mouseMoved(MouseEvent e) {
   Point pt = e.getPoint();
   int prevRow = row;
   int prevCol = col;
   row = table.rowAtPoint(pt);
   col = table.columnAtPoint(pt);
   if (row < 0 || col < 0) {
     row = -1;
     col = -1;
   }
   // >>>> HyperlinkCellRenderer.java
   // @see
   // http://java.net/projects/swingset3/sources/svn/content/trunk/SwingSet3/src/com/sun/swingset3/demos/table/HyperlinkCellRenderer.java
   if (row == prevRow && col == prevCol) {
     return;
   }
   Rectangle repaintRect;
   if (row >= 0 && col >= 0) {
     Rectangle r = table.getCellRect(row, col, false);
     if (prevRow >= 0 && prevCol >= 0) {
       repaintRect = r.union(table.getCellRect(prevRow, prevCol, false));
     } else {
       repaintRect = r;
     }
   } else {
     repaintRect = table.getCellRect(prevRow, prevCol, false);
   }
   table.repaint(repaintRect);
   // <<<<
   // table.repaint();
 }
示例#3
0
 /**
  * Method getRowBounds
  *
  * @param table JTable
  * @param first int
  * @param last int
  * @return Rectangle
  */
 private Rectangle getRowBounds(JTable table, int first, int last) {
   Rectangle result = table.getCellRect(first, -1, true);
   result = result.union(table.getCellRect(last, -1, true));
   final Insets insets = table.getInsets();
   result.x = insets.left;
   result.width = table.getWidth() - insets.left - insets.right;
   return result;
 }
示例#4
0
  /**
   * Runs search within table
   *
   * @return Returns true if found
   */
  private boolean runSearch() {

    ListSelectionModel lsm = table.getSelectionModel();
    foundRowIndices = new Vector();
    boolean selectAll = this.selectAllButton.isSelected();
    boolean found = false;

    searchStr = (String) this.jComboBox1.getSelectedItem();
    if (searchStr == null || numSearchCols == 0 || searchStr.equals("")) return found;

    table.clearSelection();
    this.jComboBox1.insertItemAt(searchStr, 0);

    if (this.matchCaseChkBox.isSelected()) {
      for (int row = 0; row < numRows; row++) {

        for (int col = (numClasses + 2); col < numCols; col++) {
          if (((String) table.getValueAt(row, col)).indexOf(searchStr) != -1) {
            // select row;
            if (selectAll || !found) {
              table.addRowSelectionInterval(row, row);
              // first occurance
              if (!found) {
                table.scrollRectToVisible(table.getCellRect(row, 0, true));
                found = true;
              }
            } else foundRowIndices.add(new Integer(row));
            break;
          }
        }
      }
    } else {

      String upperCaseStr = searchStr.toUpperCase();

      for (int row = 0; row < numRows; row++) {

        for (int col = (numClasses + 2); col < numCols; col++) {
          if ((((String) table.getValueAt(row, col)).toUpperCase()).indexOf(upperCaseStr) != -1) {
            // select row;
            if (selectAll || !found) {
              table.addRowSelectionInterval(row, row);
              // first occurance
              if (!found) {
                table.scrollRectToVisible(table.getCellRect(row, 0, true));
                found = true;
              }
            } else foundRowIndices.add(new Integer(row));
            break;
          }
        }
      }
    }

    return found;
  }
    protected void customizeCellRenderer(
        final JTable table,
        final Object value,
        final boolean selected,
        final boolean hasFocus,
        final int row,
        final int column) {
      if (myListener == null) {
        myListener = new MergeSourceDetailsLinkListener(MERGE_SOURCE_DETAILS_TAG, myFile);
        myListener.install(table);
      }
      if (!(value instanceof SvnFileRevision)) {
        append("", SimpleTextAttributes.REGULAR_ATTRIBUTES);
        return;
      }
      final SvnFileRevision revision = (SvnFileRevision) value;
      final String text = getText(revision);
      if (text.length() == 0) {
        append("", SimpleTextAttributes.REGULAR_ATTRIBUTES);
        return;
      }

      append(
          cutString(text, table.getCellRect(row, column, false).getWidth()),
          SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
示例#6
0
  public void setSelectedCell(int row, int col) {
    if (row == -1 || col == -1) return;

    data.setRowSelectionInterval(row, row);
    data.setColumnSelectionInterval(col, col);
    data.scrollRectToVisible(data.getCellRect(row, col, true));
  }
    /**
     * {@inheritDoc}
     *
     * <p>Overridden to place the textfield in the node content boundaries, leaving the icon to the
     * renderer.
     *
     * <p>PENDING JW: insets?
     */
    @SuppressWarnings("deprecation")
    @Override
    public void reshape(int x, int y, int width, int height) {
      // Allows precise positioning of text field in the tree cell.
      // following three lines didn't work out
      // Border border = this.getBorder(); // get this text field's border
      // Insets insets = border == null ? null : border.getBorderInsets(this);
      // int newOffset = offset - (insets == null ? 0 : insets.left);

      Rectangle cellRect = table.getCellRect(0, column, false);
      Rectangle nodeRect = tree.getRowBounds(row);
      nodeRect.width -= iconWidth;
      if (table.getComponentOrientation().isLeftToRight()) {
        int nodeStart = cellRect.x + nodeRect.x + iconWidth;
        int nodeEnd = cellRect.x + cellRect.width;
        super.reshape(nodeStart, y, nodeEnd - nodeStart, height);
        //                int newOffset = nodeLeftX - getInsets().left;
        //                super.reshape(x + newOffset, y, width - newOffset, height);
      } else {
        int nodeRightX = nodeRect.x + nodeRect.width;
        nodeRect.x = 0; // Math.max(0, nodeRect.x);
        // ignore the parameter
        width = nodeRightX - nodeRect.x;
        super.reshape(cellRect.x + nodeRect.x, y, width, height);
      }
    }
示例#8
0
  private void selectInAllMethods(JipMethod selectedMethod) {

    if (selectedMethod == null) {
      mMethods.clearSelection();
      return;
    }

    // which row should we select?
    boolean foundIt = false;
    int nRow = mAllMethodsModel.getRowCount();
    int iRow;
    for (iRow = 0; iRow < nRow; iRow++) {
      MethodRow scan = mAllMethodsModel.getRow(iRow);
      if (scan.getMethod().equals(selectedMethod)) {
        foundIt = true;
        break;
      }
    }
    if (!foundIt) {
      System.out.println("couldn't find " + selectedMethod.getName());
      return;
    }

    // update the listSelectionModel
    int iRowInView = mAllMethodsSorterModel.viewIndex(iRow);
    mMethods.getSelectionModel().setSelectionInterval(iRowInView, iRowInView);

    // scroll to contain the new selection
    Rectangle selectionRect = mMethods.getCellRect(iRowInView, 0, true);
    mMethods.scrollRectToVisible(selectionRect);
  }
示例#9
0
 /**
  * tests if there should be an empty row appended
  *
  * @param inserting is set: the selected cell will be filled but is not yet
  */
 public void addRow(boolean inserting) {
   int row = replaceTable.getSelectedRow();
   int col = replaceTable.getSelectedColumn();
   if (row + 1 == replaceTable.getRowCount() && col >= 0) {
     boolean[] colSet = new boolean[2];
     colSet[0] = !data.lastElement().firstElement().equals("");
     colSet[1] = !data.lastElement().lastElement().equals("");
     colSet[col] = colSet[col] || inserting;
     if (colSet[0] && colSet[1]) {
       TableCellEditor editor = replaceTable.getCellEditor();
       if (editor != null) {
         row = replaceTable.getEditingRow();
         col = replaceTable.getEditingColumn();
         data.get(row).set(col, editor.getCellEditorValue().toString());
       }
       data.add(new Vector<String>(Arrays.asList(new String[] {"", ""})));
       replaceTable.revalidate();
       CASSubDialog.this.pack();
       Rectangle r = replaceTable.getCellRect(replaceTable.getRowCount() - 1, col, false);
       scrollPane.getViewport().scrollRectToVisible(r);
       if (editor != null) {
         replaceTable.editCellAt(row, col);
       }
     }
   }
 }
示例#10
0
 @Override
 public void mouseExited(MouseEvent e) {
   if (row >= 0 && col >= 0) {
     table.repaint(table.getCellRect(row, col, false));
   }
   row = -1;
   col = -1;
 }
示例#11
0
  protected Rectangle getCellRect(JTable table, Point location) {
    int row = table.rowAtPoint(location);
    int column = table.columnAtPoint(location);

    if (row < 0 || column < 0) return null;

    return table.getCellRect(row, column, true);
  }
示例#12
0
  /** Sets the call stack with the given vector of method names. */
  public void setContents(Vector newMethodNames) {
    methodNames = (Vector) newMethodNames.clone();
    callStackTable.revalidate();

    Rectangle r = callStackTable.getCellRect(newMethodNames.size() - 1, 0, true);
    callStackTable.scrollRectToVisible(r);
    repaint();
  }
 /** Returns the coordinates of the top left corner of the value at the given index. */
 public Point getCoordinates(int index) {
   JScrollBar bar = scrollPane.getVerticalScrollBar();
   Rectangle r = segmentTable.getCellRect(index, 1, true);
   segmentTable.scrollRectToVisible(r);
   setTopLevelLocation();
   return new Point(
       (int) (r.getX() + topLevelLocation.getX()), (int) (r.getY() + topLevelLocation.getY()));
 }
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   setFont(font);
   setBackground(isSelected ? selBackground : background);
   setForeground(isSelected ? selForeground : foreground);
   Rectangle rect = table.getCellRect(row, column, true);
   setSize(rect.width, rect.height);
   setText(value != null ? value.toString() : "");
   return this;
 }
示例#15
0
 private void appendMergeSourceText(JTable table, int row, int column, @Nullable String text) {
   if (StringUtil.isEmpty(text)) {
     append("", SimpleTextAttributes.REGULAR_ATTRIBUTES);
   } else {
     append(
         cutString(text, table.getCellRect(row, column, false).getWidth()),
         SimpleTextAttributes.REGULAR_ATTRIBUTES,
         MERGE_SOURCE_DETAILS_TAG);
   }
 }
示例#16
0
 //////////////////////// END OF CONSTRUCTOR/////////////////////////////
 public static boolean isCellVisible(JTable table, int rowIndex, int vColIndex) {
   if (!(table.getParent() instanceof JViewport)) {
     return false;
   }
   JViewport viewport = (JViewport) table.getParent();
   Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);
   Point pt = viewport.getViewPosition();
   rect.setLocation(rect.x - pt.x, rect.y - pt.y);
   return new Rectangle(viewport.getExtentSize()).contains(rect);
 }
示例#17
0
  /** Selects next row in table */
  public void findNext() {

    if (foundRowIndices.isEmpty()) return;

    int row = ((Integer) foundRowIndices.remove(0)).intValue(); // take off first element
    table.clearSelection();
    table.addRowSelectionInterval(row, row);
    table.scrollRectToVisible(table.getCellRect(row, 0, true));
    if (foundRowIndices.size() == 0) findNextButton.setEnabled(false);
  }
示例#18
0
  public void valueChanged(ListSelectionEvent e) {

    JTable table = statTable.getTable();

    int[] selRow = table.getSelectedRows();

    // exit if initing or nothing selected
    if (isIniting() || selRow.length == 0) return;

    if (getProbCalc().getProbMode() == ProbabilityCalculatorViewD.PROB_INTERVAL) {
      // System.out.println(Arrays.toString(selectedRow));
      String lowStr = (String) table.getModel().getValueAt(selRow[0], 0);
      String highStr = (String) table.getModel().getValueAt(selRow[selRow.length - 1], 0);
      int low = Integer.parseInt(lowStr);
      int high = Integer.parseInt(highStr);
      // System.out.println(low + " , " + high);
      ((ProbabilityCalculatorViewD) getProbCalc()).setInterval(low, high);
    } else if (getProbCalc().getProbMode() == ProbabilityCalculatorViewD.PROB_LEFT) {
      String lowStr = (String) statTable.getTable().getModel().getValueAt(0, 0);
      String highStr =
          (String) statTable.getTable().getModel().getValueAt(selRow[selRow.length - 1], 0);
      int low = Integer.parseInt(lowStr);
      int high = Integer.parseInt(highStr);
      // System.out.println(low + " , " + high);
      ((ProbabilityCalculatorViewD) getProbCalc()).setInterval(low, high);

      // adjust the selection
      table.getSelectionModel().removeListSelectionListener(this);
      if (isCumulative()) {
        // single row selected
        table.changeSelection(selRow[selRow.length - 1], 0, false, false);
      } else {
        // select multiple rows: first up to selected
        table.changeSelection(0, 0, false, false);
        table.changeSelection(selRow[selRow.length - 1], 0, false, true);
        table.scrollRectToVisible(table.getCellRect(selRow[selRow.length - 1], 0, true));
      }
      table.getSelectionModel().addListSelectionListener(this);
    } else if (getProbCalc().getProbMode() == ProbabilityCalculatorView.PROB_RIGHT) {
      String lowStr = (String) statTable.getTable().getModel().getValueAt(selRow[0], 0);
      int maxRow = statTable.getTable().getRowCount() - 1;
      String highStr = (String) statTable.getTable().getModel().getValueAt(maxRow, 0);
      int low = Integer.parseInt(lowStr);
      int high = Integer.parseInt(highStr);
      // System.out.println(low + " , " + high);
      ((ProbabilityCalculatorViewD) getProbCalc()).setInterval(low, high);

      table.getSelectionModel().removeListSelectionListener(this);
      table.changeSelection(maxRow, 0, false, false);
      table.changeSelection(selRow[0], 0, false, true);
      // table.scrollRectToVisible(table.getCellRect(selRow[0], 0, true));
      table.getSelectionModel().addListSelectionListener(this);
    }
  }
示例#19
0
  /**
   * This is a public function called append message. To append message.
   *
   * @param pRound round of the game.
   * @param pActor actor of the game.
   * @param pMsg message to append.
   */
  public void appendMessage(int pRound, String pActor, String pMsg) {

    _model.addRow(new Object[] {pRound, pActor, pMsg});
    try {
      _table.scrollRectToVisible(_table.getCellRect(_table.getRowCount() - 1, 0, false));
    } catch (Exception e) {
    }
    // _model.insertRow(0,new Object[] {pRound, pActor, pMsg});
    // _model.fireTableRowsInserted(ERROR, ERROR);
    // JScrollBar vertical = _scrollPane.getVerticalScrollBar();
    // vertical.setValue( vertical.getMaximum() );
  }
 /**
  * Returns the bounds of the specified range of items in JList coordinates. Returns null if index
  * isn't valid.
  *
  * @param index0 the index of the first JList cell in the range
  * @param index1 the index of the last JList cell in the range
  * @return the bounds of the indexed cells in pixels
  */
 public Rectangle getCellBounds(int index0, int index1) {
   Rectangle rect0 = table.getCellRect(index0, 0, true);
   Rectangle rect1 = table.getCellRect(index1, 0, true);
   int y, height;
   if (rect0.y < rect1.y) {
     y = rect0.y;
     height = rect1.y + rect1.height - y;
   } else {
     y = rect1.y;
     height = rect0.y + rect0.height - y;
   }
   return new Rectangle(0, y, getFixedCellWidth(), height);
 }
示例#21
0
  public void locateAndShowHost(long ip) {
    synchronized (alerts) {
      int size = model.getRowCount();
      for (int i = 0; i < size; i++) {
        AlertItem item = model.getAlert(i);
        if (item.getFlowId().getSourceIP() == ip) {
          table.setRowSelectionInterval(i, i);
          table.scrollRectToVisible(table.getCellRect(i, 0, true));
          break;
        }
      }
    }

    showInDetails(ip);
  }
示例#22
0
  private int getResizingRow(Point p, int row) {
    if (row == -1) {
      return -1;
    }
    int col = table.columnAtPoint(p);
    if (col == -1) return -1;
    Rectangle r = table.getCellRect(row, col, true);
    r.grow(0, -3);
    if (r.contains(p)) return -1;

    int midPoint = r.y + r.height / 2;
    int rowIndex = (p.y < midPoint) ? row - 1 : row;

    return rowIndex;
  }
示例#23
0
 protected void moveTableViewToSelected() {
   if (re == null) {
     return;
   }
   // Remove the listener as this change will re-activate it and we end up in a loop!
   dataTable.getSelectionModel().removeListSelectionListener(tableSelectionListener);
   dataTable.clearSelection();
   int entires = dataTable.getRowCount();
   for (int i = 0; i < entires; i++) {
     if (dataTable.getValueAt(i, RosterTableModel.IDCOL).equals(re.getId())) {
       dataTable.addRowSelectionInterval(i, i);
       dataTable.scrollRectToVisible(new Rectangle(dataTable.getCellRect(i, 0, true)));
     }
   }
   dataTable.getSelectionModel().addListSelectionListener(tableSelectionListener);
 }
示例#24
0
  @Override
  public Component getTableCellEditorComponent(
      JTable table, Object value, boolean isSelected, int row, int column) {
    JTextField txt1 =
        (JTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);
    if (value == null) value = "";
    txt1.setText(value.toString().trim());

    Rectangle rect = table.getCellRect(row, column, true);
    tblY = table.getLocationOnScreen().y + rect.getLocation().y;
    tblX = table.getLocationOnScreen().x + rect.getLocation().x;
    iRow = row;
    txt1.getCaret().setVisible(true);
    // txt1.setCaretPosition(0);
    txt1.requestFocus();
    return txt1;
  }
示例#25
0
  /**
   * Assumes table is contained in a JScrollPane. Scrolls the cell (rowIndex, vColIndex) so that it
   * is visible within the viewport.
   */
  public static void scrollToVisible(JTable table, int row, int col) {
    if (!(table.getParent() instanceof JViewport)) return;

    JViewport viewport = (JViewport) table.getParent();

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

    // The location of the viewport relative to the table
    Point pt = viewport.getViewPosition();

    // 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 - pt.x, rect.y - pt.y);

    // Scroll the area into view
    viewport.scrollRectToVisible(rect);
  }
示例#26
0
    private void paintStripedBackground(Graphics g) {
      // get the row index at the top of the clip bounds (the first row
      // to paint).
      int rowAtPoint = fTable.rowAtPoint(g.getClipBounds().getLocation());
      // get the y coordinate of the first row to paint. if there are no
      // rows in the table, start painting at the top of the supplied
      // clipping bounds.
      int topY = rowAtPoint < 0 ? g.getClipBounds().y : fTable.getCellRect(rowAtPoint, 0, true).y;

      // create a counter variable to hold the current row. if there are no
      // rows in the table, start the counter at 0.
      int currentRow = rowAtPoint < 0 ? 0 : rowAtPoint;
      while (topY < g.getClipBounds().y + g.getClipBounds().height) {
        int bottomY = topY + fTable.getRowHeight();
        g.setColor(getRowColor(currentRow));
        g.fillRect(g.getClipBounds().x, topY, g.getClipBounds().width, bottomY);
        topY = bottomY;
        currentRow++;
      }
    }
示例#27
0
文件: Moves.java 项目: Tha1n/ESIR2
  /**
   * Method of adding new moves to the table
   *
   * @param str String which in is saved player move
   */
  protected void addMove2Table(String str) {
    try {
      if (!this.enterBlack) {
        this.addRow();
        this.rowsNum = this.tableModel.getRowCount() - 1;
        this.tableModel.setValueAt(str, rowsNum, 0);
      } else {
        this.tableModel.setValueAt(str, rowsNum, 1);
        this.rowsNum = this.tableModel.getRowCount() - 1;
      }
      this.enterBlack = !this.enterBlack;
      this.table.scrollRectToVisible(
          table.getCellRect(table.getRowCount() - 1, 0, true)); // scroll to down

    } catch (ArrayIndexOutOfBoundsException exc) {
      if (this.rowsNum > 0) {
        this.rowsNum--;
        addMove2Table(str);
      }
    }
  }
示例#28
0
 private void initFields(int row, Operacao operacao) {
   this.operacao = operacao;
   if (operacao == Operacao.NENHUM) {
     // SALVAR, CANCELAR, EXCLUIR, ATUALIZAR
     int index = tbTipoContrato.getSelectedRow();
     tbTipoContrato.getSelectionModel().clearSelection();
     clearFields();
     if (index < 0) {
       index = 0;
     }
     this.tbTipoContrato.setRowSelectionInterval(index, index);
     this.TOTAL_RECORDS = dao.getCount();
     this.doPagination(PAGE);
     this.enableFields(false);
   } else {
     // INCLUIR E ALTERAR
     tbTipoContrato.setRowSelectionInterval(row, row);
     tbTipoContrato.scrollRectToVisible(tbTipoContrato.getCellRect(row, 0, true));
     this.enableFields(true);
   }
 }
  public void scrollToColumnLocation(int colIndex) {
    JTable scrollTable = transposedSpreadsheetSubform.getScrollTable();
    scrollTable.setColumnSelectionInterval(colIndex, colIndex);

    JViewport scrollPane = transposedSpreadsheetSubform.getFrozenTable().getViewport();
    Rectangle rect = scrollTable.getCellRect(1, colIndex, true);
    Point p = scrollPane.getViewPosition();
    rect.setLocation(rect.x - p.x, rect.y - p.y);

    scrollPane.scrollRectToVisible(rect);

    Map<Integer, Color> columnToColor = new HashMap<Integer, Color>();
    columnToColor.put(colIndex, new Color(28, 117, 188, 70));

    transposedSpreadsheetSubform.changeTableRenderer(
        transposedSpreadsheetSubform.getScrollTable(),
        new SubFormCellRenderer(
            UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, null, columnToColor));

    transposedSpreadsheetSubform.validate();
    transposedSpreadsheetSubform.repaint();
  }
示例#30
0
  public static void ScrollToLine(JScrollPane scrollPane, JTable table) {
    Rectangle vr = table.getVisibleRect();
    int first = table.rowAtPoint(vr.getLocation());
    Rectangle cellRect = table.getCellRect(first + 1, 0, true);
    JViewport viewport = scrollPane.getViewport();
    Rectangle rr = viewport.getViewRect();
    int shift = cellRect.y - rr.y;
    // String tt;
    // tt = String.format("%d %d %d",cellRect.y, rr.y, shift);
    for (int i = 0; i < shift; i++) {
      int cur = scrollPane.getVerticalScrollBar().getValue();
      scrollPane.getVerticalScrollBar().setValue(cur + 1);
      try {
        Thread.sleep(45);
      } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }
    // JOptionPane.showMessageDialog(null, tt);
    // viewport.setViewPosition(cellRect.getLocation());

  }