mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
GUI: added custom tooltip support on mouse move over table's cell (related to #11438);
This commit is contained in:
parent
7629e4bf7c
commit
a4073a83c6
4 changed files with 49 additions and 8 deletions
|
|
@ -6,9 +6,12 @@ import org.apache.log4j.Logger;
|
|||
import javax.swing.*;
|
||||
import javax.swing.table.JTableHeader;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableModel;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/**
|
||||
* GUI: basic mage table for any data like game tables list, players list, etc
|
||||
*
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class MageTable extends JTable {
|
||||
|
|
@ -38,7 +41,12 @@ public class MageTable extends JTable {
|
|||
int modelCol = this.convertColumnIndexToModel(viewCol);
|
||||
String tip = null;
|
||||
if (modelRow != -1 && modelCol != -1) {
|
||||
tip = this.getModel().getValueAt(modelRow, modelCol).toString();
|
||||
TableModel model = this.getModel();
|
||||
if (model instanceof TableModelWithTooltip) {
|
||||
tip = ((TableModelWithTooltip) model).getTooltipAt(modelRow, modelCol);
|
||||
} else {
|
||||
tip = model.getValueAt(modelRow, modelCol).toString();
|
||||
}
|
||||
}
|
||||
return GUISizeHelper.textToHtmlWithSize(tip, GUISizeHelper.tableFont);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package mage.client.table;
|
||||
|
||||
/**
|
||||
* GUI: add support of tooltip/hint for table's cells on mouse move (used by MageTable)
|
||||
*
|
||||
* @author JayDi85
|
||||
*/
|
||||
public interface TableModelWithTooltip {
|
||||
|
||||
String getTooltipAt(int rowIndex, int columnIndex);
|
||||
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ import javax.swing.table.AbstractTableModel;
|
|||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
||||
public class TablesTableModel extends AbstractTableModel {
|
||||
public class TablesTableModel extends AbstractTableModel implements TableModelWithTooltip {
|
||||
|
||||
// icons with tostring for tables hints
|
||||
final ImageIcon tourneyIcon = new ImageIcon(getClass().getResource("/tables/tourney_icon.png")) {
|
||||
|
|
@ -132,7 +132,7 @@ public class TablesTableModel extends AbstractTableModel {
|
|||
case 5:
|
||||
return tables[rowIndex].getGameType();
|
||||
case 6:
|
||||
return tables[rowIndex].getAdditionalInfo();
|
||||
return tables[rowIndex].getAdditionalInfoShort();
|
||||
case 7:
|
||||
return tables[rowIndex].getTableStateText();
|
||||
case 8:
|
||||
|
|
@ -190,6 +190,20 @@ public class TablesTableModel extends AbstractTableModel {
|
|||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltipAt(int rowIndex, int columnIndex) {
|
||||
Object res;
|
||||
switch (columnIndex) {
|
||||
case COLUMN_INFO:
|
||||
res = tables[rowIndex].getAdditionalInfoFull();
|
||||
break;
|
||||
default:
|
||||
res = this.getValueAt(rowIndex, columnIndex);
|
||||
break;
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int columnIndex) {
|
||||
String colName = "";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue