mirror of
https://github.com/correl/mage.git
synced 2025-04-09 17:00:09 -09:00
UI: fixed row selecting in tables list
This commit is contained in:
parent
4349ec881e
commit
dd09de7a09
3 changed files with 38 additions and 17 deletions
Mage.Client/src/main/java/mage/client/table
|
@ -27,16 +27,15 @@ public class MageTable extends JTable {
|
||||||
@Override
|
@Override
|
||||||
public String getToolTipText(MouseEvent e) {
|
public String getToolTipText(MouseEvent e) {
|
||||||
// default tooltip for cells
|
// default tooltip for cells
|
||||||
String tip = null;
|
|
||||||
java.awt.Point p = e.getPoint();
|
java.awt.Point p = e.getPoint();
|
||||||
int rowIndex = rowAtPoint(p);
|
int viewRow = rowAtPoint(p);
|
||||||
int colIndex = columnAtPoint(p);
|
int viewCol = columnAtPoint(p);
|
||||||
try {
|
int modelRow = TablesUtil.getModelRowFromView(this, viewRow);
|
||||||
tip = this.getModel().getValueAt(this.convertRowIndexToModel(rowIndex), this.convertColumnIndexToModel(colIndex)).toString();
|
int modelCol = this.convertColumnIndexToModel(viewCol);
|
||||||
} catch (RuntimeException e1) {
|
String tip = null;
|
||||||
//catch null pointer exception if mouse is over an empty line
|
if (modelRow != -1 && modelCol != -1) {
|
||||||
|
tip = this.getModel().getValueAt(modelRow, modelCol).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return GUISizeHelper.textToHtmlWithSize(tip, GUISizeHelper.tableFont);
|
return GUISizeHelper.textToHtmlWithSize(tip, GUISizeHelper.tableFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -387,9 +387,12 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void valueChanged(ListSelectionEvent e) {
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
int row = e.getFirstIndex();
|
int modelRow = TablesUtil.getSelectedModelRow(table);
|
||||||
String rowId = TablesUtil.getSearchIdFromTable(table, row);
|
if (modelRow != -1) {
|
||||||
tablesLastSelection.put(table, rowId);
|
// needs only selected
|
||||||
|
String rowId = TablesUtil.getSearchIdFromTable(table, modelRow);
|
||||||
|
tablesLastSelection.put(table, rowId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -401,9 +404,11 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String lastRowID = tablesLastSelection.get(table);
|
String lastRowID = tablesLastSelection.get(table);
|
||||||
int needRow = TablesUtil.findTableRowFromSearchId(table.getModel(), lastRowID);
|
int needModelRow = TablesUtil.findTableRowFromSearchId(table.getModel(), lastRowID);
|
||||||
if (needRow != -1) {
|
int needViewRow = TablesUtil.getViewRowFromModel(table, needModelRow);
|
||||||
table.addRowSelectionInterval(needRow, needRow);
|
if (needViewRow != -1) {
|
||||||
|
table.clearSelection();
|
||||||
|
table.addRowSelectionInterval(needViewRow, needViewRow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -415,9 +420,9 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
table.addMouseListener(new MouseAdapter() {
|
table.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
int row = table.getSelectedRow();
|
int modelRow = TablesUtil.getSelectedModelRow(table);
|
||||||
if (e.getClickCount() == 2 && row != -1) {
|
if (e.getClickCount() == 2 && modelRow != -1) {
|
||||||
action.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_PERFORMED, TablesUtil.getSearchIdFromTable(table, row)));
|
action.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_PERFORMED, TablesUtil.getSearchIdFromTable(table, modelRow)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,4 +43,21 @@ public class TablesUtil {
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getSelectedModelRow(JTable table) {
|
||||||
|
return getModelRowFromView(table, table.getSelectedRow());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getModelRowFromView(JTable table, int viewRow) {
|
||||||
|
if (viewRow != -1 && viewRow < table.getModel().getRowCount()) {
|
||||||
|
return table.convertRowIndexToModel(viewRow);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getViewRowFromModel(JTable table, int modelRow) {
|
||||||
|
if (modelRow != -1 && modelRow < table.getModel().getRowCount()) {
|
||||||
|
return table.convertRowIndexToView(modelRow);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue