From 05a3713694220edd440e1c3123494120f3085528 Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Sat, 14 Aug 2021 12:16:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-56595=20=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8F=AF=E5=A4=8D=E5=88=B6-?= =?UTF-8?q?=E8=A1=A8=E5=A4=B4=E5=A4=8D=E5=88=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datapane/preview/CopyableJTable.java | 116 ++++++++++++++++-- 1 file changed, 108 insertions(+), 8 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/CopyableJTable.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/CopyableJTable.java index 38b5a08e47..7baf51ddd6 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/CopyableJTable.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/CopyableJTable.java @@ -6,7 +6,11 @@ import com.fr.design.gui.itable.TableSorter; import com.fr.log.FineLoggerFactory; import com.fr.stable.os.OperatingSystem; +import javax.swing.*; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.JTableHeader; import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumnModel; import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; @@ -40,27 +44,104 @@ public class CopyableJTable extends SortableJTable { int commandKeyCode = 157; //选中单元格的背景色 Color selectBackGround = new Color(54, 133, 242, 63); + Color headerBackGround = new Color(229, 229, 229); + boolean mouseDrag = false; + boolean headerSelect = false; + + DefaultTableCellRenderer tableHeaderCellRenderer = new DefaultTableCellRenderer() { + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + if (isChoose(row, column)) { + comp.setBackground(selectBackGround); + } else { + comp.setBackground(headerBackGround); + } + return comp; + } + }; public CopyableJTable(TableSorter tableModel) { super(tableModel); initListener(); + this.getTableHeader().setDefaultRenderer(tableHeaderCellRenderer); } private void initListener() { CopyableJTable self = this; + this.getTableHeader().addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + if (mouseDrag) { + headerSelect = true; + int column = getColumn(e); + self.updateEndPoint(-1, column); + self.getTableHeader().repaint(); + } + } + + @Override + public void mouseExited(MouseEvent e) { + if (mouseDrag) { + headerSelect = false; + } + } + + @Override + public void mouseClicked(MouseEvent e) { + headerSelect = true; + int column = getColumn(e); + if (column != -1) { + self.clearPoint(); + self.addPoint(-1, column); + self.updateStartPoint(-1, column); + self.updateEndPoint(-1, column); + self.refreshTable(); + } + } + + private int getColumn(MouseEvent e) { + JTableHeader h = (JTableHeader) e.getSource(); + TableColumnModel columnModel = h.getColumnModel(); + int viewColumn = columnModel.getColumnIndexAtX(e.getX()); + return viewColumn; + } + }); + this.getTableHeader().addMouseMotionListener(new MouseAdapter() { + @Override + public void mouseMoved(MouseEvent e) { + mouseDrag = false; + } + + @Override + public void mouseDragged(MouseEvent e) { + self.clearPoint(); + self.updateStartPoint(-1, -1); + self.updateEndPoint(-1, -1); + self.refreshTable(); + } + + }); + + this.addMouseMotionListener(new java.awt.event.MouseAdapter() { @Override public void mouseDragged(MouseEvent evt) { + mouseDrag = true; int row = self.rowAtPoint(evt.getPoint()); int col = self.columnAtPoint(evt.getPoint()); if (self.updateEndPoint(row, col)) { - self.repaint(); + self.refreshTable(); } } + + public void mouseMoved(MouseEvent e) { + mouseDrag = false; + } }); this.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { + headerSelect = false; int row = self.rowAtPoint(e.getPoint()); int col = self.columnAtPoint(e.getPoint()); if (!self.isControlDown) { @@ -74,7 +155,7 @@ public class CopyableJTable extends SortableJTable { self.addPoint(row, col); self.updateEndPoint(row, col); - self.repaint(); + self.refreshTable(); } }); @@ -129,6 +210,8 @@ public class CopyableJTable extends SortableJTable { private boolean updateEndPoint(int row, int col) { + if (headerSelect && row != -1) + return false; if (endRow != row || endCol != col) { endRow = row; endCol = col; @@ -157,13 +240,12 @@ public class CopyableJTable extends SortableJTable { private void copy() { FineLoggerFactory.getLogger().info("copy cell value"); java.util.List> table = new ArrayList<>(); - if ((startRow != endRow || startCol != endCol) && - Math.min(startRow, endRow) > -1 && 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++) { table.add(new ArrayList<>()); for (int j = Math.min(startCol, endCol); j <= Math.max(startCol, endCol); j++) { - Object text = this.getValueAt(i, j); - table.get(i - Math.min(startRow, endRow)).add(text); + Object text = this.getTableValue(i, j); + table.get(table.size() - 1).add(text); } } } else if (pointList.size() > 0) { @@ -176,8 +258,8 @@ public class CopyableJTable extends SortableJTable { table.add(new ArrayList<>()); currentRow++; } - Object text = this.getValueAt(point.x, point.y); - table.get(currentRow - startRow).add(text); + Object text = this.getTableValue(point.x, point.y); + table.get(table.size() - 1).add(text); } } @@ -186,6 +268,24 @@ public class CopyableJTable extends SortableJTable { clip.setContents(tText, null); } + private Object getTableValue(int row, int col) { + Object value = null; + if (col > -1) { + if (row > -1) { + value = this.getValueAt(row, col); + } else if (row == -1) { + col = columnModel.getColumn(col).getModelIndex(); + value = this.getModel().getColumnName(col); + } + } + return value; + } + + private void refreshTable() { + this.repaint(); + this.getTableHeader().repaint(); + } + private boolean isChoose(int row, int col) { if (row >= Math.min(startRow, endRow) && row <= Math.max(startRow, endRow)) { if (col >= Math.min(startCol, endCol) && col <= Math.max(startCol, endCol)) { From bee3075e5f291f3436ad1d4e74ade0648b0dfa42 Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Sat, 14 Aug 2021 12:35:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-55481=20=E6=A8=A1=E6=9D=BFWeb?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E7=9A=84=E9=A1=B6=E9=83=A8=E5=92=8C=E5=BA=95?= =?UTF-8?q?=E9=83=A8=E5=B7=A5=E5=85=B7=E6=A0=8F=E5=9C=A8=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=97=B6=EF=BC=8C=E9=A1=B6=E9=83=A8=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=A0=8F=E8=A2=AB=E5=BA=95=E9=83=A8=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=A0=8F=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/mainframe/AuthorityToolBarPane.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/AuthorityToolBarPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/AuthorityToolBarPane.java index 1fc891c8b3..5eb1de3664 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/AuthorityToolBarPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/AuthorityToolBarPane.java @@ -185,7 +185,7 @@ public class AuthorityToolBarPane extends BasicBeanPane toolBarButtons = toolBarPane.getToolBarButtons(); - boolean isnotEnable = ComparatorUtils.equals(title.getText(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Server_Toolbar_Choose_Role"))&& !WorkContext.getCurrent().isRoot(); + boolean isnotEnable = ComparatorUtils.equals(title.getText(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Server_Toolbar_Choose_Role")) && !WorkContext.getCurrent().isRoot(); for (ToolBarButton button : toolBarButtons) { button.setEnabled(!isnotEnable); } @@ -296,9 +296,15 @@ public class AuthorityToolBarPane extends BasicBeanPane