mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
admin tools improves (#5388):
* added game ids and created time to tables list; * added popup hints support to tables list; * fixed wrong sorting and columns resizing in tables list; * refactored some modules to share table related code between client and admin console;
This commit is contained in:
parent
50c75f05bd
commit
fef37cdc73
14 changed files with 170 additions and 84 deletions
|
|
@ -1,41 +0,0 @@
|
|||
package mage.client.table;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class ColumnInfo {
|
||||
private final Integer index;
|
||||
private final Integer width;
|
||||
private final String headerName;
|
||||
private final String headerHint;
|
||||
private final Class colClass;
|
||||
|
||||
public ColumnInfo(Integer index, Integer width, Class colClass, String headerName, String headerHint) {
|
||||
this.index = index;
|
||||
this.width = width;
|
||||
this.colClass = colClass;
|
||||
this.headerName = headerName;
|
||||
this.headerHint = headerHint;
|
||||
}
|
||||
|
||||
|
||||
public Integer getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public Integer getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public String getHeaderName() {
|
||||
return headerName;
|
||||
}
|
||||
|
||||
public String getHeaderHint() {
|
||||
return headerHint;
|
||||
}
|
||||
|
||||
public Class getColClass() {
|
||||
return colClass;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
package mage.client.table;
|
||||
|
||||
import mage.client.util.GUISizeHelper;
|
||||
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 {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(MageTable.class);
|
||||
private TableInfo tableInfo;
|
||||
|
||||
public MageTable() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public MageTable(TableInfo tableInfo) {
|
||||
this.tableInfo = tableInfo;
|
||||
}
|
||||
|
||||
public void setTableInfo(TableInfo tableInfo) {
|
||||
this.tableInfo = tableInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolTipText(MouseEvent e) {
|
||||
// default tooltip for cells
|
||||
java.awt.Point p = e.getPoint();
|
||||
int viewRow = rowAtPoint(p);
|
||||
int viewCol = columnAtPoint(p);
|
||||
int modelRow = TablesUtil.getModelRowFromView(this, viewRow);
|
||||
int modelCol = this.convertColumnIndexToModel(viewCol);
|
||||
String tip = null;
|
||||
if (modelRow != -1 && modelCol != -1) {
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JTableHeader createDefaultTableHeader() {
|
||||
// default tooltip for headers
|
||||
return new JTableHeader(columnModel) {
|
||||
@Override
|
||||
public String getToolTipText(MouseEvent e) {
|
||||
// html tooltip
|
||||
java.awt.Point p = e.getPoint();
|
||||
int colIndex = columnModel.getColumnIndexAtX(p.x);
|
||||
TableColumn col = columnModel.getColumn(colIndex);
|
||||
if (colIndex < 0) {
|
||||
return "";
|
||||
}
|
||||
int realIndex = col.getModelIndex();
|
||||
|
||||
String tip;
|
||||
if (tableInfo != null) {
|
||||
// custom hint from table info
|
||||
tip = tableInfo.getColumnByIndex(realIndex).getHeaderHint();
|
||||
if (tip == null) {
|
||||
tip = tableInfo.getColumnByIndex(realIndex).getHeaderName();
|
||||
}
|
||||
} else {
|
||||
// default hint from header
|
||||
tip = col.getHeaderValue().toString();
|
||||
}
|
||||
|
||||
return GUISizeHelper.textToHtmlWithSize(tip, GUISizeHelper.tableFont);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,8 @@ import mage.client.util.GUISizeHelper;
|
|||
import mage.client.util.MageTableRowSorter;
|
||||
import mage.client.util.gui.TableUtil;
|
||||
import mage.client.util.gui.countryBox.CountryCellRenderer;
|
||||
import mage.components.table.MageTable;
|
||||
import mage.components.table.TableInfo;
|
||||
import mage.remote.MageRemoteException;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.UsersView;
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
package mage.client.table;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class TableInfo {
|
||||
|
||||
private final List<ColumnInfo> columns = new ArrayList<>();
|
||||
|
||||
|
||||
public TableInfo addColumn(Integer index, Integer width, Class colClass, String headerName, String headerHint) {
|
||||
this.columns.add(new ColumnInfo(index, width, colClass, headerName, headerHint));
|
||||
return this;
|
||||
}
|
||||
|
||||
public int[] getColumnsWidth() {
|
||||
return this.columns.stream().mapToInt(ColumnInfo::getIndex).toArray();
|
||||
}
|
||||
|
||||
public List<ColumnInfo> getColumns() {
|
||||
return this.columns;
|
||||
}
|
||||
|
||||
public ColumnInfo getColumnByIndex(int index) {
|
||||
for (ColumnInfo col : this.columns) {
|
||||
if (col.getIndex().equals(index)) {
|
||||
return col;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ColumnInfo getColumnByName(String name) {
|
||||
for (ColumnInfo col : this.columns) {
|
||||
if (col.getHeaderName().equals(name)) {
|
||||
return col;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
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);
|
||||
|
||||
}
|
||||
|
|
@ -13,6 +13,9 @@ import mage.client.util.MageTableRowSorter;
|
|||
import mage.client.util.URLHandler;
|
||||
import mage.client.util.gui.GuiDisplayUtil;
|
||||
import mage.client.util.gui.TableUtil;
|
||||
import mage.components.table.MageTable;
|
||||
import mage.components.table.TableInfo;
|
||||
import mage.components.table.TimeAgoTableCellRenderer;
|
||||
import mage.constants.*;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.players.PlayerType;
|
||||
|
|
@ -155,19 +158,8 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
|
||||
final JToggleButton[] filterButtons;
|
||||
|
||||
// time formater
|
||||
private final PrettyTime timeFormater = new PrettyTime(Locale.ENGLISH);
|
||||
|
||||
// time ago renderer
|
||||
TableCellRenderer timeAgoCellRenderer = new DefaultTableCellRenderer() {
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
Date d = (Date) value;
|
||||
label.setText(timeFormater.format(d));
|
||||
return label;
|
||||
}
|
||||
};
|
||||
// time formatter
|
||||
private final PrettyTime timeFormatter = new PrettyTime(Locale.ENGLISH);
|
||||
|
||||
// duration renderer
|
||||
TableCellRenderer durationCellRenderer = new DefaultTableCellRenderer() {
|
||||
|
|
@ -177,8 +169,8 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
Long ms = (Long) value;
|
||||
|
||||
if (ms != 0) {
|
||||
Duration dur = timeFormater.approximateDuration(new Date(ms));
|
||||
label.setText((timeFormater.formatDuration(dur)));
|
||||
Duration dur = timeFormatter.approximateDuration(new Date(ms));
|
||||
label.setText((timeFormatter.formatDuration(dur)));
|
||||
} else {
|
||||
label.setText("");
|
||||
}
|
||||
|
|
@ -298,13 +290,8 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
initComponents();
|
||||
// tableModel.setSession(session);
|
||||
|
||||
// formater
|
||||
// change default just now from 60 to 30 secs
|
||||
// see workaround for 4.0 versions: https://github.com/ocpsoft/prettytime/issues/152
|
||||
TimeFormat timeFormat = timeFormater.removeUnit(JustNow.class);
|
||||
JustNow newJustNow = new JustNow();
|
||||
newJustNow.setMaxQuantity(1000L * 30L); // 30 seconds gap (show "just now" from 0 to 30 secs)
|
||||
timeFormater.registerUnit(newJustNow, timeFormat);
|
||||
// formatter
|
||||
MageTable.fixTimeFormatter(this.timeFormatter);
|
||||
|
||||
// 1. TABLE CURRENT
|
||||
tableTables.createDefaultColumnsFromModel();
|
||||
|
|
@ -334,7 +321,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
tableTables.setRowSorter(activeTablesSorter);
|
||||
|
||||
// time ago
|
||||
tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_CREATED).setCellRenderer(timeAgoCellRenderer);
|
||||
tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_CREATED).setCellRenderer(TimeAgoTableCellRenderer.getInstance());
|
||||
// skill level
|
||||
tableTables.getColumnModel().getColumn(TablesTableModel.COLUMN_SKILL).setCellRenderer(skillCellRenderer);
|
||||
// seats
|
||||
|
|
@ -545,7 +532,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
int modelRow = TablesUtil.getSelectedModelRow(table);
|
||||
int modelRow = MageTable.getSelectedModelRow(table);
|
||||
if (modelRow != -1) {
|
||||
// needs only selected
|
||||
String rowId = TablesUtil.getSearchIdFromTable(table, modelRow);
|
||||
|
|
@ -563,7 +550,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
public void run() {
|
||||
String lastRowID = tablesLastSelection.get(table);
|
||||
int needModelRow = TablesUtil.findTableRowFromSearchId(table.getModel(), lastRowID);
|
||||
int needViewRow = TablesUtil.getViewRowFromModel(table, needModelRow);
|
||||
int needViewRow = MageTable.getViewRowFromModel(table, needModelRow);
|
||||
if (needViewRow != -1) {
|
||||
table.clearSelection();
|
||||
table.addRowSelectionInterval(needViewRow, needViewRow);
|
||||
|
|
@ -581,7 +568,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
if (!SwingUtilities.isLeftMouseButton(e)) {
|
||||
return;
|
||||
}
|
||||
int modelRow = TablesUtil.getSelectedModelRow(table);
|
||||
int modelRow = MageTable.getSelectedModelRow(table);
|
||||
if (e.getClickCount() == 2 && modelRow != -1) {
|
||||
action.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_PERFORMED, TablesUtil.getSearchIdFromTable(table, modelRow)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package mage.client.table;
|
||||
|
||||
import mage.client.SessionHandler;
|
||||
import mage.components.table.TableModelWithTooltip;
|
||||
import mage.constants.SkillLevel;
|
||||
import mage.remote.MageRemoteException;
|
||||
import mage.view.TableView;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import org.apache.log4j.Logger;
|
|||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* GUI related
|
||||
*
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class TablesUtil {
|
||||
|
|
@ -42,22 +44,4 @@ public class TablesUtil {
|
|||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,13 +186,6 @@ public final class GUISizeHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static String textToHtmlWithSize(String text, Font font) {
|
||||
if (text != null && !text.toLowerCase(Locale.ENGLISH).startsWith("<html>")) {
|
||||
return "<html><p style=\"font-size: " + font.getSize() + ";\">" + text + "</p>";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return scrollbar settings, so user can scroll it more faster for bigger cards
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue