|
|
@ -25,248 +25,249 @@ import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_M |
|
|
|
|
|
|
|
|
|
|
|
public class DataTableConfigPane extends JComponent implements PropertyChangeListener { |
|
|
|
public class DataTableConfigPane extends JComponent implements PropertyChangeListener { |
|
|
|
|
|
|
|
|
|
|
|
private DataEditingTable table; |
|
|
|
private DataEditingTable table; |
|
|
|
|
|
|
|
|
|
|
|
public DataTableConfigPane() { |
|
|
|
public DataTableConfigPane() { |
|
|
|
table = new DataEditingTable(); |
|
|
|
table = new DataEditingTable(); |
|
|
|
JScrollPane scrollPane = new JScrollPane(table); |
|
|
|
JScrollPane scrollPane = new JScrollPane(table); |
|
|
|
this.setLayout(new DataTableLayout()); |
|
|
|
this.setLayout(new DataTableLayout()); |
|
|
|
this.add(scrollPane, BorderLayout.CENTER); |
|
|
|
this.add(scrollPane, BorderLayout.CENTER); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void populate(DataTableConfig config) { |
|
|
|
public void populate(DataTableConfig config) { |
|
|
|
table.populate(config); |
|
|
|
table.populate(config); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public DataTableConfig update() { |
|
|
|
public DataTableConfig update() { |
|
|
|
return table.update(); |
|
|
|
return table.update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class DataTableLayout extends BorderLayout { |
|
|
|
class DataTableLayout extends BorderLayout { |
|
|
|
public void layoutContainer(Container target) { |
|
|
|
public void layoutContainer(Container target) { |
|
|
|
super.layoutContainer(target); |
|
|
|
super.layoutContainer(target); |
|
|
|
table.doLayout(); |
|
|
|
table.doLayout(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class DataEditingTable extends JTable { |
|
|
|
class DataEditingTable extends JTable { |
|
|
|
|
|
|
|
|
|
|
|
private DataTableConfig config; |
|
|
|
private DataTableConfig config; |
|
|
|
private BeanTableModel model; |
|
|
|
private BeanTableModel model; |
|
|
|
private TableColumnModelListener modeListener; |
|
|
|
private TableColumnModelListener modeListener; |
|
|
|
|
|
|
|
|
|
|
|
public DataEditingTable() { |
|
|
|
public DataEditingTable() { |
|
|
|
this.setBorder(BorderFactory.createLineBorder(new Color(210, 210, 210), 1)); |
|
|
|
this.setBorder(BorderFactory.createLineBorder(new Color(210, 210, 210), 1)); |
|
|
|
this.setColumnSelectionAllowed(true); |
|
|
|
this.setColumnSelectionAllowed(true); |
|
|
|
this.setRowSelectionAllowed(true); |
|
|
|
this.setRowSelectionAllowed(true); |
|
|
|
MouseAdapterListener l = new MouseAdapterListener(this); |
|
|
|
MouseAdapterListener l = new MouseAdapterListener(this); |
|
|
|
this.addMouseListener(l); |
|
|
|
this.addMouseListener(l); |
|
|
|
this.addMouseMotionListener(l); |
|
|
|
this.addMouseMotionListener(l); |
|
|
|
model = new BeanTableModel(); |
|
|
|
model = new BeanTableModel(); |
|
|
|
modeListener = new TableColumnModelListener() { |
|
|
|
modeListener = new TableColumnModelListener() { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void columnAdded(TableColumnModelEvent e) { |
|
|
|
public void columnAdded(TableColumnModelEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void columnMarginChanged(ChangeEvent e) { |
|
|
|
public void columnMarginChanged(ChangeEvent e) { |
|
|
|
DataTableConfigPane.this.propertyChange(); |
|
|
|
DataTableConfigPane.this.propertyChange(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void columnMoved(TableColumnModelEvent e) { |
|
|
|
public void columnMoved(TableColumnModelEvent e) { |
|
|
|
DataTableConfigPane.this.propertyChange(); |
|
|
|
DataTableConfigPane.this.propertyChange(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void columnRemoved(TableColumnModelEvent e) { |
|
|
|
public void columnRemoved(TableColumnModelEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void columnSelectionChanged(ListSelectionEvent e) { |
|
|
|
public void columnSelectionChanged(ListSelectionEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public TableCellRenderer getCellRenderer(int row, int column) { |
|
|
|
public TableCellRenderer getCellRenderer(int row, int column) { |
|
|
|
TableCellRenderer renderer = super.getCellRenderer(row, column); |
|
|
|
TableCellRenderer renderer = super.getCellRenderer(row, column); |
|
|
|
if (renderer instanceof UILabel) { |
|
|
|
if (renderer instanceof UILabel) { |
|
|
|
((UILabel) renderer).setHorizontalAlignment(UILabel.CENTER); |
|
|
|
((UILabel) renderer).setHorizontalAlignment(UILabel.CENTER); |
|
|
|
} |
|
|
|
} |
|
|
|
return renderer; |
|
|
|
return renderer; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void populate(DataTableConfig config) { |
|
|
|
public void populate(DataTableConfig config) { |
|
|
|
this.getTableHeader().getColumnModel().removeColumnModelListener(modeListener); |
|
|
|
this.getTableHeader().getColumnModel().removeColumnModelListener(modeListener); |
|
|
|
if (config == null) { |
|
|
|
if (config == null) { |
|
|
|
config = DataTableConfig.DEFAULT_TABLE_DATA_CONFIG; |
|
|
|
config = DataTableConfig.DEFAULT_TABLE_DATA_CONFIG; |
|
|
|
} |
|
|
|
} |
|
|
|
this.config = config; |
|
|
|
this.config = config; |
|
|
|
|
|
|
|
|
|
|
|
model = new BeanTableModel(); |
|
|
|
model = new BeanTableModel(); |
|
|
|
this.setModel(model); |
|
|
|
this.setModel(model); |
|
|
|
this.setRowHeight(0, config.getRowHeight()); |
|
|
|
this.setRowHeight(0, config.getRowHeight()); |
|
|
|
for (int i = 0; i < config.getColumnCount(); i++) { |
|
|
|
for (int i = 0; i < config.getColumnCount(); i++) { |
|
|
|
this.getColumn(this.getColumnName(i)).setPreferredWidth(config.getColumnWidth(i)); |
|
|
|
this.getColumn(this.getColumnName(i)).setPreferredWidth(config.getColumnWidth(i)); |
|
|
|
} |
|
|
|
} |
|
|
|
this.getTableHeader().getColumnModel().addColumnModelListener(modeListener); |
|
|
|
this.getTableHeader().getColumnModel().addColumnModelListener(modeListener); |
|
|
|
this.doLayout(); |
|
|
|
this.doLayout(); |
|
|
|
this.repaint(); |
|
|
|
this.repaint(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public DataTableConfig update() { |
|
|
|
public DataTableConfig update() { |
|
|
|
config.setRowHeight(this.getRowHeight(0)); |
|
|
|
config.setRowHeight(this.getRowHeight(0)); |
|
|
|
model = new BeanTableModel(); |
|
|
|
model = new BeanTableModel(); |
|
|
|
String[] columns = new String[this.getColumnCount()]; |
|
|
|
String[] columns = new String[this.getColumnCount()]; |
|
|
|
for (int i = 0; i < this.getColumnCount(); i++) { |
|
|
|
for (int i = 0; i < this.getColumnCount(); i++) { |
|
|
|
config.setColumnWidth(i, this.getColumn(this.getColumnName(i)).getWidth()); |
|
|
|
config.setColumnWidth(i, this.getColumn(this.getColumnName(i)).getWidth()); |
|
|
|
columns[i] = this.getColumnName(i); |
|
|
|
columns[i] = this.getColumnName(i); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
config.setColumns(columns); |
|
|
|
config.setColumns(columns); |
|
|
|
return config; |
|
|
|
return config; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class BeanTableModel extends AbstractTableModel { |
|
|
|
public class BeanTableModel extends AbstractTableModel { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int getColumnCount() { |
|
|
|
public int getColumnCount() { |
|
|
|
return config.getColumnCount(); |
|
|
|
return config.getColumnCount(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int getRowCount() { |
|
|
|
public int getRowCount() { |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String getColumnName(int column) { |
|
|
|
public String getColumnName(int column) { |
|
|
|
return config.getColumnName(column); |
|
|
|
return config.getColumnName(column); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Object getValueAt(int rowIndex, int columnIndex) { |
|
|
|
public Object getValueAt(int rowIndex, int columnIndex) { |
|
|
|
return config.getTableDataName() + "." + config.getColumnName(columnIndex); |
|
|
|
return config.getTableDataName() + "." + config.getColumnName(columnIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class MouseAdapterListener extends MouseAdapter { |
|
|
|
class MouseAdapterListener extends MouseAdapter { |
|
|
|
private JTable table; |
|
|
|
private JTable table; |
|
|
|
int oldY = 0; |
|
|
|
int oldY = 0; |
|
|
|
int newY = 0; |
|
|
|
int newY = 0; |
|
|
|
int row = 0; |
|
|
|
int row = 0; |
|
|
|
int oldHeight = 0; |
|
|
|
int oldHeight = 0; |
|
|
|
boolean drag = false; |
|
|
|
boolean drag = false; |
|
|
|
int increase = 0; |
|
|
|
int increase = 0; |
|
|
|
JPopupMenu popupMenu; |
|
|
|
JPopupMenu popupMenu; |
|
|
|
|
|
|
|
|
|
|
|
public MouseAdapterListener(JTable table) { |
|
|
|
public MouseAdapterListener(JTable table) { |
|
|
|
this.table = table; |
|
|
|
this.table = table; |
|
|
|
popupMenu = new JPopupMenu(); |
|
|
|
popupMenu = new JPopupMenu(); |
|
|
|
|
|
|
|
|
|
|
|
popupMenu.add(new CutAction()); |
|
|
|
popupMenu.add(new CutAction()); |
|
|
|
popupMenu.add(new CutAction()); |
|
|
|
popupMenu.add(new CutAction()); |
|
|
|
popupMenu.add(new CutAction()); |
|
|
|
popupMenu.add(new CutAction()); |
|
|
|
popupMenu.add(new CutAction()); |
|
|
|
popupMenu.add(new CutAction()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class CutAction extends UpdateAction { |
|
|
|
class CutAction extends UpdateAction { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Constructor |
|
|
|
* Constructor |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public CutAction() { |
|
|
|
public CutAction() { |
|
|
|
this.setName(Inter.getLocText("M_Edit-Cut")); |
|
|
|
this.setName(Inter.getLocText("M_Edit-Cut")); |
|
|
|
this.setMnemonic('T'); |
|
|
|
this.setMnemonic('T'); |
|
|
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/cut.png")); |
|
|
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/cut.png")); |
|
|
|
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER)); |
|
|
|
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
int row = table.getSelectedRow(); |
|
|
|
int row = table.getSelectedRow(); |
|
|
|
int column = table.getSelectedColumn(); |
|
|
|
int column = table.getSelectedColumn(); |
|
|
|
table.getColumnModel().removeColumn(table.getColumn(table.getColumnName(column))); |
|
|
|
table.getColumnModel().removeColumn(table.getColumn(table.getColumnName(column))); |
|
|
|
DataTableConfigPane.this.propertyChange(); |
|
|
|
DataTableConfigPane.this.propertyChange(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void mouseMoved(MouseEvent e) { |
|
|
|
public void mouseMoved(MouseEvent e) { |
|
|
|
int onRow = table.rowAtPoint(e.getPoint()); |
|
|
|
int onRow = table.rowAtPoint(e.getPoint()); |
|
|
|
|
|
|
|
|
|
|
|
int height = 0; |
|
|
|
int height = 0; |
|
|
|
for (int i = 0; i <= onRow; i++) { |
|
|
|
for (int i = 0; i <= onRow; i++) { |
|
|
|
height = height + table.getRowHeight(i); |
|
|
|
height = height + table.getRowHeight(i); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (height - e.getY() < 3) { |
|
|
|
if (height - e.getY() < 3) { |
|
|
|
drag = true; |
|
|
|
drag = true; |
|
|
|
table.setCursor(new Cursor(Cursor.N_RESIZE_CURSOR)); |
|
|
|
table.setCursor(new Cursor(Cursor.N_RESIZE_CURSOR)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
drag = false; |
|
|
|
drag = false; |
|
|
|
table.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
|
|
|
table.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void trigger_popup(MouseEvent e) { |
|
|
|
private void trigger_popup(MouseEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
popupMenu.show(table, e.getX(), e.getY()); |
|
|
|
popupMenu.show(table, e.getX(), e.getY()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void mouseDragged(MouseEvent e) { |
|
|
|
public void mouseDragged(MouseEvent e) { |
|
|
|
if (drag) { |
|
|
|
if (drag) { |
|
|
|
int value = oldHeight + e.getY() - oldY; |
|
|
|
int value = oldHeight + e.getY() - oldY; |
|
|
|
if (value < 30) |
|
|
|
if (value < 30) { |
|
|
|
table.setRowHeight(row, 30); |
|
|
|
table.setRowHeight(row, 30); |
|
|
|
else |
|
|
|
} else { |
|
|
|
table.setRowHeight(row, oldHeight + e.getY() - oldY); |
|
|
|
table.setRowHeight(row, oldHeight + e.getY() - oldY); |
|
|
|
DataTableConfigPane.this.propertyChange(); |
|
|
|
} |
|
|
|
} |
|
|
|
DataTableConfigPane.this.propertyChange(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
|
|
|
|
oldY = e.getY(); |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
row = table.rowAtPoint(e.getPoint()); |
|
|
|
oldY = e.getY(); |
|
|
|
oldHeight = table.getRowHeight(row); |
|
|
|
row = table.rowAtPoint(e.getPoint()); |
|
|
|
if (e.getButton() == MouseEvent.BUTTON3) { |
|
|
|
oldHeight = table.getRowHeight(row); |
|
|
|
trigger_popup(e); |
|
|
|
if (e.getButton() == MouseEvent.BUTTON3) { |
|
|
|
} |
|
|
|
trigger_popup(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
|
|
|
|
newY = e.getY(); |
|
|
|
public void mouseReleased(MouseEvent e) { |
|
|
|
table.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
|
|
|
newY = e.getY(); |
|
|
|
} |
|
|
|
table.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
private ArrayList<PropertyChangeListener> changetList = new ArrayList<PropertyChangeListener>(); |
|
|
|
|
|
|
|
|
|
|
|
private ArrayList<PropertyChangeListener> changetList = new ArrayList<PropertyChangeListener>(); |
|
|
|
public void addpropertyChangeListener(PropertyChangeListener l) { |
|
|
|
|
|
|
|
changetList.add(l); |
|
|
|
public void addpropertyChangeListener(PropertyChangeListener l) { |
|
|
|
} |
|
|
|
changetList.add(l); |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
|
|
|
|
public void propertyChange() { |
|
|
|
@Override |
|
|
|
for (PropertyChangeListener l : changetList) { |
|
|
|
public void propertyChange() { |
|
|
|
l.propertyChange(); |
|
|
|
for (PropertyChangeListener l : changetList) { |
|
|
|
} |
|
|
|
l.propertyChange(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void propertyChange(Object mark) { |
|
|
|
public void propertyChange(Object mark) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void propertyChange(Object[] marks) { |
|
|
|
public void propertyChange(Object[] marks) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |