|
|
@ -106,6 +106,7 @@ public class CopyableJTable extends SortableJTable { |
|
|
|
self.updateEndPoint(-1, column); |
|
|
|
self.updateEndPoint(-1, column); |
|
|
|
self.refreshTable(); |
|
|
|
self.refreshTable(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
self.requestFocusInWindow(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private int getColumn(MouseEvent e) { |
|
|
|
private int getColumn(MouseEvent e) { |
|
|
@ -249,26 +250,9 @@ public class CopyableJTable extends SortableJTable { |
|
|
|
FineLoggerFactory.getLogger().info("copy cell value"); |
|
|
|
FineLoggerFactory.getLogger().info("copy cell value"); |
|
|
|
java.util.List<java.util.List<Object>> table = new ArrayList<>(); |
|
|
|
java.util.List<java.util.List<Object>> table = new ArrayList<>(); |
|
|
|
if ((startRow != endRow || startCol != endCol) && Math.min(startCol, endCol) > -1) { |
|
|
|
if ((startRow != endRow || startCol != endCol) && Math.min(startCol, endCol) > -1) { |
|
|
|
for (int i = Math.min(startRow, endRow); i <= Math.max(startRow, endRow); i++) { |
|
|
|
copyAreaData(table); |
|
|
|
table.add(new ArrayList<>()); |
|
|
|
|
|
|
|
for (int j = Math.min(startCol, endCol); j <= Math.max(startCol, endCol); j++) { |
|
|
|
|
|
|
|
Object text = this.getTableValue(i, j); |
|
|
|
|
|
|
|
table.get(table.size() - 1).add(text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (pointList.size() > 0) { |
|
|
|
} else if (pointList.size() > 0) { |
|
|
|
Collections.sort(pointList, Comparator.comparing(Point::getX).thenComparing(Point::getY)); |
|
|
|
copyPointsData(table); |
|
|
|
int startRow = pointList.get(0).x; |
|
|
|
|
|
|
|
int currentRow = startRow; |
|
|
|
|
|
|
|
table.add(new ArrayList<>()); |
|
|
|
|
|
|
|
for (Point point : pointList) { |
|
|
|
|
|
|
|
while (currentRow < point.x) { |
|
|
|
|
|
|
|
table.add(new ArrayList<>()); |
|
|
|
|
|
|
|
currentRow++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Object text = this.getTableValue(point.x, point.y); |
|
|
|
|
|
|
|
table.get(table.size() - 1).add(text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); |
|
|
|
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); |
|
|
@ -276,6 +260,35 @@ public class CopyableJTable extends SortableJTable { |
|
|
|
clip.setContents(tText, null); |
|
|
|
clip.setContents(tText, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void copyAreaData(java.util.List<java.util.List<Object>> table) { |
|
|
|
|
|
|
|
for (int i = Math.min(startRow, endRow); i <= Math.max(startRow, endRow); i++) { |
|
|
|
|
|
|
|
table.add(new ArrayList<>()); |
|
|
|
|
|
|
|
for (int j = Math.min(startCol, endCol); j <= Math.max(startCol, endCol); j++) { |
|
|
|
|
|
|
|
Object text = this.getTableValue(i, j); |
|
|
|
|
|
|
|
if (text != null) { |
|
|
|
|
|
|
|
table.get(table.size() - 1).add(text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void copyPointsData(java.util.List<java.util.List<Object>> table) { |
|
|
|
|
|
|
|
Collections.sort(pointList, Comparator.comparing(Point::getX).thenComparing(Point::getY)); |
|
|
|
|
|
|
|
int startRow = pointList.get(0).x; |
|
|
|
|
|
|
|
int currentRow = startRow; |
|
|
|
|
|
|
|
table.add(new ArrayList<>()); |
|
|
|
|
|
|
|
for (Point point : pointList) { |
|
|
|
|
|
|
|
while (currentRow < point.x) { |
|
|
|
|
|
|
|
table.add(new ArrayList<>()); |
|
|
|
|
|
|
|
currentRow++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Object text = this.getTableValue(point.x, point.y); |
|
|
|
|
|
|
|
if (text != null) { |
|
|
|
|
|
|
|
table.get(table.size() - 1).add(text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Object getTableValue(int row, int col) { |
|
|
|
private Object getTableValue(int row, int col) { |
|
|
|
Object value = null; |
|
|
|
Object value = null; |
|
|
|
if (col > -1) { |
|
|
|
if (col > -1) { |
|
|
|