|
|
|
@ -16,6 +16,7 @@ import javax.swing.BorderFactory;
|
|
|
|
|
import javax.swing.JComponent; |
|
|
|
|
import javax.swing.JLabel; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.JScrollPane; |
|
|
|
|
import javax.swing.JTable; |
|
|
|
|
import javax.swing.SwingConstants; |
|
|
|
|
import javax.swing.UIManager; |
|
|
|
@ -29,6 +30,10 @@ import java.awt.GridLayout;
|
|
|
|
|
import java.awt.Insets; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.cell; |
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.column; |
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.row; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 表格编辑面板,一般是两列.键-值 用泛型实现,用的时候请定义T.model里面的T要一样 |
|
|
|
|
* |
|
|
|
@ -40,9 +45,9 @@ public class UITableEditorPane<T> extends BasicPane {
|
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
private static final long serialVersionUID = 6855793816972735815L; |
|
|
|
|
private JTable editTable; |
|
|
|
|
protected static JTable editTable; |
|
|
|
|
// 放置action 的按钮.
|
|
|
|
|
private UITableModelAdapter<T> tableModel; |
|
|
|
|
protected UITableModelAdapter<T> tableModel; |
|
|
|
|
private String leftLabelName; |
|
|
|
|
private JPanel buttonPane; |
|
|
|
|
|
|
|
|
@ -77,20 +82,37 @@ public class UITableEditorPane<T> extends BasicPane {
|
|
|
|
|
|
|
|
|
|
UIScrollPane scrollPane = new UIScrollPane(editTable); |
|
|
|
|
scrollPane.setBorder(new FineRoundBorder()); |
|
|
|
|
pane.add(scrollPane, BorderLayout.CENTER); |
|
|
|
|
initbuttonPane(action); |
|
|
|
|
JPanel controlPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
controlPane.add(buttonPane, BorderLayout.EAST); |
|
|
|
|
|
|
|
|
|
controlPane.add(content == null ? l : content, BorderLayout.WEST); |
|
|
|
|
|
|
|
|
|
pane.add(controlPane, BorderLayout.NORTH); |
|
|
|
|
pane.add(column(cell(controlPane), cell(buildScrollTablePane(scrollPane)).weight(1)).getComponent()); |
|
|
|
|
|
|
|
|
|
this.editTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer()); |
|
|
|
|
this.editTable.setDefaultRenderer(Object.class, new TableRenderer()); |
|
|
|
|
this.editTable.setRowHeight(FineUIScale.scale(24)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 组合 jtable 和垂直滚动条 |
|
|
|
|
* @param scrollPane |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
protected Component buildScrollTablePane(JScrollPane scrollPane) { |
|
|
|
|
return row( |
|
|
|
|
cell(scrollPane).weight(1), |
|
|
|
|
column( |
|
|
|
|
cell(new UILabel()).with(it -> { |
|
|
|
|
it.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 1, UIManager.getColor("defaultBorderColor"))); |
|
|
|
|
it.setPreferredSize(FineUIScale.scale(new Dimension(scrollPane.getVerticalScrollBar().getWidth(), (int) editTable.getTableHeader().getPreferredSize().getHeight()))); |
|
|
|
|
}), |
|
|
|
|
cell(scrollPane.getVerticalScrollBar()).weight(1).with(it -> { |
|
|
|
|
it.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 1, UIManager.getColor("defaultBorderColor"))); |
|
|
|
|
})) |
|
|
|
|
).getComponent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public UITableModelAdapter<T> getTableModel() { |
|
|
|
|
return tableModel; |
|
|
|
|
} |
|
|
|
@ -175,7 +197,10 @@ public class UITableEditorPane<T> extends BasicPane {
|
|
|
|
|
return buttonPane; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public JTable getEditTable() { |
|
|
|
|
/** |
|
|
|
|
* @return jTable |
|
|
|
|
*/ |
|
|
|
|
public static JTable getEditTable() { |
|
|
|
|
return editTable; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -210,7 +235,11 @@ public class UITableEditorPane<T> extends BasicPane {
|
|
|
|
|
@Override |
|
|
|
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
|
|
|
|
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
|
|
|
|
((JComponent) component).setBorder(UIManager.getBorder("TableHeader.cellBorder")); |
|
|
|
|
if (column == table.getColumnCount() - 1) { |
|
|
|
|
((JComponent) component).setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("defaultBorderColor"))); |
|
|
|
|
} else { |
|
|
|
|
((JComponent) component).setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, UIManager.getColor("defaultBorderColor"))); |
|
|
|
|
} |
|
|
|
|
return component; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -231,9 +260,15 @@ public class UITableEditorPane<T> extends BasicPane {
|
|
|
|
|
((JLabel) component).setToolTipText(toolTipText); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
((JComponent) component).setBorder(BorderFactory.createCompoundBorder( |
|
|
|
|
BorderFactory.createMatteBorder(0, 0, 1, 1, UIManager.getColor("defaultBorderColor")), |
|
|
|
|
new ScaledEmptyBorder(0,4,0,0))); |
|
|
|
|
if (column == table.getColumnCount() - 1) { |
|
|
|
|
((JComponent) component).setBorder(BorderFactory.createCompoundBorder( |
|
|
|
|
BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("defaultBorderColor")), |
|
|
|
|
new ScaledEmptyBorder(0,4,0,0))); |
|
|
|
|
} else { |
|
|
|
|
((JComponent) component).setBorder(BorderFactory.createCompoundBorder( |
|
|
|
|
BorderFactory.createMatteBorder(0, 0, 1, 1, UIManager.getColor("defaultBorderColor")), |
|
|
|
|
new ScaledEmptyBorder(0,4,0,0))); |
|
|
|
|
} |
|
|
|
|
component.setBackground(FlatUIUtils.getUIColor("background.normal", Color.WHITE)); |
|
|
|
|
return component; |
|
|
|
|
} |
|
|
|
|