[vcs-log] fix links in table
authorJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Sat, 5 Nov 2016 15:14:44 +0000 (18:14 +0300)
committerJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Sat, 5 Nov 2016 15:14:44 +0000 (18:14 +0300)
platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/GraphTableController.java
platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java

index 8660219195bad50494650078ed54970cfdd724c3..e3abf6b6e2d59ab11af344de04afffb70ac008c6 100644 (file)
@@ -230,7 +230,7 @@ public class GraphTableController {
   }
 
   private class MyMouseAdapter extends MouseAdapter {
-    @NotNull private final TableLinkMouseListener myLinkListener = new TableLinkMouseListener();
+    @NotNull private final TableLinkMouseListener myLinkListener = myCommitRenderer.createLinkListener();
 
     @Override
     public void mouseClicked(MouseEvent e) {
index daa74873ddac584c1d0d1dac27ba391ad36a462f..e70fed0d498a146347e173327fc1592e34080aa1 100644 (file)
@@ -2,6 +2,8 @@ package com.intellij.vcs.log.ui.render;
 
 import com.intellij.openapi.util.registry.Registry;
 import com.intellij.openapi.vcs.changes.issueLinks.IssueLinkRenderer;
+import com.intellij.openapi.vcs.changes.issueLinks.TableLinkMouseListener;
+import com.intellij.ui.SimpleColoredComponent;
 import com.intellij.ui.SimpleColoredRenderer;
 import com.intellij.ui.SimpleTextAttributes;
 import com.intellij.util.ObjectUtils;
@@ -20,6 +22,7 @@ import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.awt.*;
+import java.awt.event.MouseEvent;
 import java.awt.image.BufferedImage;
 import java.util.Collection;
 
@@ -46,12 +49,12 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
   }
 
   @Override
-  protected Component getTableCellRendererComponentImpl(@NotNull JTable table,
-                                                        @NotNull GraphCommitCell value,
-                                                        boolean isSelected,
-                                                        boolean hasFocus,
-                                                        int row,
-                                                        int column) {
+  protected SimpleColoredComponent getTableCellRendererComponentImpl(@NotNull JTable table,
+                                                                     @NotNull GraphCommitCell value,
+                                                                     boolean isSelected,
+                                                                     boolean hasFocus,
+                                                                     int row,
+                                                                     int column) {
     myComponent.customize(value, isSelected, hasFocus, row, column);
     return myComponent;
   }
@@ -104,6 +107,10 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
     return myGraphTable.getColumnModel().getColumn(GraphTableModel.COMMIT_COLUMN).getWidth();
   }
 
+  public TableLinkMouseListener createLinkListener() {
+    return new MyTableLinkMouseListener();
+  }
+
   private static class MyComponent extends SimpleColoredRenderer {
     @NotNull private final VcsLogData myLogData;
     @NotNull private final VcsLogGraphTable myGraphTable;
@@ -252,4 +259,14 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
       return myWidth;
     }
   }
+
+  public class MyTableLinkMouseListener extends TableLinkMouseListener {
+    @Override
+    protected Object tryGetTag(@NotNull MouseEvent e, @NotNull JTable table, int row, int column) {
+      SimpleColoredComponent component =
+        getTableCellRendererComponentImpl(table, getValue(table.getValueAt(row, column)), false, false, row, column);
+      Rectangle rc = table.getCellRect(row, column, false);
+      return component.getFragmentTagAt(e.getX() - rc.x);
+    }
+  }
 }