private boolean expandOrCollapseRoots(@NotNull MouseEvent e) {
   TableColumn column = getRootColumnOrNull(e);
   if (column != null) {
     myUI.setShowRootNames(!myUI.isShowRootNames());
     return true;
   }
   return false;
 }
Example #2
0
 private void setColumnPreferredSize() {
   for (int i = 0; i < getColumnCount(); i++) {
     TableColumn column = getColumnModel().getColumn(i);
     if (i == AbstractVcsLogTableModel.ROOT_COLUMN) { // thin stripe or nothing
       int rootWidth = myUI.getColorManager().isMultipleRoots() ? ROOT_INDICATOR_WIDTH : 0;
       // NB: all further instructions and their order are important, otherwise the minimum size
       // which is less than 15 won't be applied
       column.setMinWidth(rootWidth);
       column.setMaxWidth(rootWidth);
       column.setPreferredWidth(rootWidth);
     } else if (i
         == AbstractVcsLogTableModel
             .COMMIT_COLUMN) { // let commit message occupy as much as possible
       column.setPreferredWidth(Short.MAX_VALUE);
     } else if (i
         == AbstractVcsLogTableModel.AUTHOR_COLUMN) { // detect author with the longest name
       // to avoid querying the last row (it would lead to full graph loading)
       int maxRowsToCheck =
           Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount() - MAX_ROWS_TO_CALC_OFFSET);
       if (maxRowsToCheck < 0) { // but if the log is small, check all of them
         maxRowsToCheck = getRowCount();
       }
       int contentWidth = calcMaxContentColumnWidth(i, maxRowsToCheck);
       column.setMinWidth(Math.min(contentWidth, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH));
       column.setWidth(column.getMinWidth());
     } else if (i == AbstractVcsLogTableModel.DATE_COLUMN) { // all dates have nearly equal sizes
       Font tableFont = UIManager.getFont("Table.font");
       column.setMinWidth(
           getFontMetrics(tableFont)
               .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date())));
       column.setWidth(column.getMinWidth());
     }
   }
 }
  private void setRootColumnSize(TableColumn column) {
    int rootWidth;
    if (!myUI.isMultipleRoots()) {
      rootWidth = 0;
    } else if (!myUI.isShowRootNames()) {
      rootWidth = ROOT_INDICATOR_WIDTH;
    } else {
      rootWidth = Math.min(calculateMaxRootWidth(), ROOT_NAME_MAX_WIDTH);
    }

    // NB: all further instructions and their order are important, otherwise the minimum size which
    // is less than 15 won't be applied
    column.setMinWidth(rootWidth);
    column.setMaxWidth(rootWidth);
    column.setPreferredWidth(rootWidth);
  }
    @Override
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      String text;
      Color color;

      if (value instanceof VirtualFile) {
        VirtualFile root = (VirtualFile) value;
        int readableRow =
            ScrollingUtil.getReadableRow(table, Math.round(myUi.getTable().getRowHeight() * 0.5f));
        if (row < readableRow) {
          text = "";
        } else if (row == 0
            || !value.equals(table.getModel().getValueAt(row - 1, column))
            || readableRow == row) {
          text = root.getName();
        } else {
          text = "";
        }
        color = getRootBackgroundColor(root, myUi.getColorManager());
      } else {
        text = null;
        color = UIUtil.getTableBackground(isSelected);
      }

      myColor = color;
      Color background =
          ((VcsLogGraphTable) table)
              .getStyle(row, column, text, hasFocus, isSelected)
              .getBackground();
      assert background != null;
      myBorderColor = background;
      setForeground(UIUtil.getTableForeground(false));

      if (myUi.isShowRootNames()) {
        setText(text);
        isNarrow = false;
      } else {
        setText("");
        isNarrow = true;
      }

      return this;
    }
 @Override
 public void setFilter(@NotNull VcsLogFilter filter) {
   ApplicationManager.getApplication().assertIsDispatchThread();
   if (filter instanceof VcsLogBranchFilter) {
     myBranchFilterModel.setFilter((VcsLogBranchFilter) filter);
     JComponent toolbar = myUi.getMainFrame().getToolbar();
     toolbar.revalidate();
     toolbar.repaint();
   }
 }
Example #6
0
 @Override
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   if (value instanceof VirtualFile) {
     myColor = myUi.getColorManager().getRootColor((VirtualFile) value);
   } else {
     myColor = UIUtil.getTableBackground(isSelected);
   }
   return this;
 }
    @Override
    protected void paintComponent(Graphics g) {
      setFont(UIManager.getFont("Table.font"));
      g.setColor(myColor);

      int width = getWidth();

      if (isNarrow) {
        g.fillRect(0, 0, width - ROOT_INDICATOR_WHITE_WIDTH, myUi.getTable().getRowHeight());
        g.setColor(myBorderColor);
        g.fillRect(
            width - ROOT_INDICATOR_WHITE_WIDTH,
            0,
            ROOT_INDICATOR_WHITE_WIDTH,
            myUi.getTable().getRowHeight());
      } else {
        g.fillRect(0, 0, width, myUi.getTable().getRowHeight());
      }

      super.paintComponent(g);
    }
Example #8
0
 @Override
 protected void paintComponent(Graphics g) {
   g.setColor(myColor);
   g.fillRect(0, 0, ROOT_INDICATOR_WIDTH - 1, HEIGHT_CELL);
   UIUtil.drawLine(
       (Graphics2D) g,
       ROOT_INDICATOR_WIDTH - 1,
       0,
       ROOT_INDICATOR_WIDTH - 1,
       HEIGHT_CELL,
       null,
       myUi.getColorManager().getRootIndicatorBorder());
 }
 @Override
 public void performCopy(@NotNull DataContext dataContext) {
   List<VcsFullCommitDetails> details =
       VcsLogUtil.collectFirstPackOfLoadedSelectedDetails(myUI.getVcsLog());
   if (!details.isEmpty()) {
     CopyPasteManager.getInstance()
         .setContents(
             new StringSelection(
                 StringUtil.join(
                     details,
                     new Function<VcsFullCommitDetails, String>() {
                       @Override
                       public String fun(VcsFullCommitDetails details) {
                         return details.getSubject();
                       }
                     },
                     "\n")));
   }
 }
 @Override
 public String getToolTipText(@NotNull MouseEvent event) {
   int row = rowAtPoint(event.getPoint());
   int column = columnAtPoint(event.getPoint());
   if (column < 0 || row < 0) {
     return null;
   }
   if (column == GraphTableModel.ROOT_COLUMN) {
     Object at = getValueAt(row, column);
     if (at instanceof VirtualFile) {
       return "<html><b>"
           + ((VirtualFile) at).getPresentableUrl()
           + "</b><br/>Click to "
           + (myUI.isShowRootNames() ? "collapse" : "expand")
           + "</html>";
     }
   }
   return null;
 }
Example #11
0
  public VcsLogGraphTable(
      @NotNull VcsLogUiImpl UI,
      @NotNull final VcsLogDataHolder logDataHolder,
      @NotNull DataPack initialDataPack) {
    super();
    myUI = UI;
    myLogDataHolder = logDataHolder;
    myDataPack = initialDataPack;
    myGraphCommitCellRender =
        new GraphCommitCellRender(
            myUI.getColorManager(), logDataHolder, myDataPack.getGraphFacade(), this);

    setDefaultRenderer(
        VirtualFile.class, new RootCellRenderer(myUI, myLogDataHolder.isMultiRoot()));
    setDefaultRenderer(GraphCommitCell.class, myGraphCommitCellRender);
    setDefaultRenderer(String.class, new StringCellRenderer());

    setRowHeight(HEIGHT_CELL);
    setShowHorizontalLines(false);
    setIntercellSpacing(new Dimension(0, 0));

    getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                int selectedRow = getSelectedRow();
                if (selectedRow >= 0) {
                  myUI.click(selectedRow);
                }
              }
            });

    MouseAdapter mouseAdapter = new MyMouseAdapter();
    addMouseMotionListener(mouseAdapter);
    addMouseListener(mouseAdapter);

    PopupHandler.installPopupHandler(
        this, VcsLogUiImpl.POPUP_ACTION_GROUP, VcsLogUiImpl.VCS_LOG_TABLE_PLACE);
    TableScrollingUtil.installActions(this, false);
  }
  public void handleAnswer(
      @Nullable GraphAnswer<Integer> answer,
      boolean dataCouldChange,
      @Nullable Selection previousSelection) {
    if (dataCouldChange) {
      GraphTableModel graphTableModel = (GraphTableModel) getModel();

      graphTableModel.fireTableDataChanged();

      // since fireTableDataChanged clears selection we restore it here
      if (previousSelection != null) {
        previousSelection.restore(
            getVisibleGraph(), answer == null || answer.getCommitToJump() != null);
      }
    }

    myUI
        .repaintUI(); // in case of repaintUI doing something more than just repainting this table
                      // in some distant future

    if (answer == null) {
      return;
    }

    if (answer.getCursorToSet() != null) {
      setCursor(answer.getCursorToSet());
    }
    if (answer.getCommitToJump() != null) {
      Integer row =
          getGraphTableModel()
              .getVisiblePack()
              .getVisibleGraph()
              .getVisibleRowIndex(answer.getCommitToJump());
      if (row != null && row >= 0) {
        jumpToRow(row);
      }
      // TODO wait for the full log and then jump
    }
  }
 void applyFilters() {
   myUi.applyFiltersAndUpdateUi();
 }