mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -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.*;
|
||||||
import javax.swing.table.JTableHeader;
|
import javax.swing.table.JTableHeader;
|
||||||
import javax.swing.table.TableColumn;
|
import javax.swing.table.TableColumn;
|
||||||
|
import javax.swing.table.TableModel;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* GUI: basic mage table for any data like game tables list, players list, etc
|
||||||
|
*
|
||||||
* @author JayDi85
|
* @author JayDi85
|
||||||
*/
|
*/
|
||||||
public class MageTable extends JTable {
|
public class MageTable extends JTable {
|
||||||
|
|
@ -38,7 +41,12 @@ public class MageTable extends JTable {
|
||||||
int modelCol = this.convertColumnIndexToModel(viewCol);
|
int modelCol = this.convertColumnIndexToModel(viewCol);
|
||||||
String tip = null;
|
String tip = null;
|
||||||
if (modelRow != -1 && modelCol != -1) {
|
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);
|
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.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class TablesTableModel extends AbstractTableModel {
|
public class TablesTableModel extends AbstractTableModel implements TableModelWithTooltip {
|
||||||
|
|
||||||
// icons with tostring for tables hints
|
// icons with tostring for tables hints
|
||||||
final ImageIcon tourneyIcon = new ImageIcon(getClass().getResource("/tables/tourney_icon.png")) {
|
final ImageIcon tourneyIcon = new ImageIcon(getClass().getResource("/tables/tourney_icon.png")) {
|
||||||
|
|
@ -132,7 +132,7 @@ public class TablesTableModel extends AbstractTableModel {
|
||||||
case 5:
|
case 5:
|
||||||
return tables[rowIndex].getGameType();
|
return tables[rowIndex].getGameType();
|
||||||
case 6:
|
case 6:
|
||||||
return tables[rowIndex].getAdditionalInfo();
|
return tables[rowIndex].getAdditionalInfoShort();
|
||||||
case 7:
|
case 7:
|
||||||
return tables[rowIndex].getTableStateText();
|
return tables[rowIndex].getTableStateText();
|
||||||
case 8:
|
case 8:
|
||||||
|
|
@ -190,6 +190,20 @@ public class TablesTableModel extends AbstractTableModel {
|
||||||
return "";
|
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
|
@Override
|
||||||
public String getColumnName(int columnIndex) {
|
public String getColumnName(int columnIndex) {
|
||||||
String colName = "";
|
String colName = "";
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ public class TableView implements Serializable {
|
||||||
private final String deckType;
|
private final String deckType;
|
||||||
private String tableName;
|
private String tableName;
|
||||||
private String controllerName;
|
private String controllerName;
|
||||||
private final String additionalInfo;
|
private final String additionalInfoShort;
|
||||||
|
private final String additionalInfoFull;
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
private TableState tableState;
|
private TableState tableState;
|
||||||
private final SkillLevel skillLevel;
|
private final SkillLevel skillLevel;
|
||||||
|
|
@ -133,7 +134,8 @@ public class TableView implements Serializable {
|
||||||
if (table.getNumberOfSeats() > 3) {
|
if (table.getNumberOfSeats() > 3) {
|
||||||
addInfo.append(" Rng: ").append(table.getMatch().getOptions().getRange().toString());
|
addInfo.append(" Rng: ").append(table.getMatch().getOptions().getRange().toString());
|
||||||
}
|
}
|
||||||
this.additionalInfo = addInfo.toString();
|
this.additionalInfoShort = addInfo.toString();
|
||||||
|
this.additionalInfoFull = addInfo.toString(); // TODO: add tooltip details here
|
||||||
this.skillLevel = table.getMatch().getOptions().getSkillLevel();
|
this.skillLevel = table.getMatch().getOptions().getSkillLevel();
|
||||||
this.quitRatio = Integer.toString(table.getMatch().getOptions().getQuitRatio());
|
this.quitRatio = Integer.toString(table.getMatch().getOptions().getQuitRatio());
|
||||||
this.minimumRating = Integer.toString(table.getMatch().getOptions().getMinimumRating());
|
this.minimumRating = Integer.toString(table.getMatch().getOptions().getMinimumRating());
|
||||||
|
|
@ -213,7 +215,8 @@ public class TableView implements Serializable {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
this.additionalInfo = infoText.toString();
|
this.additionalInfoShort = infoText.toString();
|
||||||
|
this.additionalInfoFull = infoText.toString(); // TODO: add tooltip details here
|
||||||
this.tableStateText = stateText.toString();
|
this.tableStateText = stateText.toString();
|
||||||
this.deckType = table.getDeckType() + ' ' + table.getTournament().getBoosterInfo();
|
this.deckType = table.getDeckType() + ' ' + table.getTournament().getBoosterInfo();
|
||||||
this.skillLevel = table.getTournament().getOptions().getMatchOptions().getSkillLevel();
|
this.skillLevel = table.getTournament().getOptions().getMatchOptions().getSkillLevel();
|
||||||
|
|
@ -275,8 +278,12 @@ public class TableView implements Serializable {
|
||||||
return this.isTournament;
|
return this.isTournament;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAdditionalInfo() {
|
public String getAdditionalInfoShort() {
|
||||||
return this.additionalInfo;
|
return this.additionalInfoShort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAdditionalInfoFull() {
|
||||||
|
return this.additionalInfoFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTableStateText() {
|
public String getTableStateText() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue