mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
UI changed:
+ added default sorting for tables on open (last created on the top); + added "time ago" format for created date column;
This commit is contained in:
parent
e60d9c2257
commit
f706f9351d
2 changed files with 51 additions and 1 deletions
|
@ -148,6 +148,11 @@
|
||||||
<version>1.6-1</version>
|
<version>1.6-1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- svg support end -->
|
<!-- svg support end -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.ocpsoft.prettytime</groupId>
|
||||||
|
<artifactId>prettytime</artifactId>
|
||||||
|
<version>3.2.7.Final</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<!-- to get the reference to local repository with com\googlecode\jspf\jspf-core\0.9.1\ -->
|
<!-- to get the reference to local repository with com\googlecode\jspf\jspf-core\0.9.1\ -->
|
||||||
|
|
|
@ -46,6 +46,9 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
import javax.swing.table.DefaultTableCellRenderer;
|
||||||
|
import javax.swing.table.TableCellRenderer;
|
||||||
|
|
||||||
import mage.cards.decks.importer.DeckImporterUtil;
|
import mage.cards.decks.importer.DeckImporterUtil;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.client.SessionHandler;
|
import mage.client.SessionHandler;
|
||||||
|
@ -70,6 +73,8 @@ import mage.view.RoomUsersView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import mage.view.UserRequestMessage;
|
import mage.view.UserRequestMessage;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.ocpsoft.prettytime.PrettyTime;
|
||||||
|
import org.ocpsoft.prettytime.units.JustNow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -100,6 +105,18 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
final JToggleButton[] filterButtons;
|
final JToggleButton[] filterButtons;
|
||||||
|
|
||||||
|
// time ago date time renderer
|
||||||
|
private PrettyTime timeAgoFormater = new PrettyTime();
|
||||||
|
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(timeAgoFormater.format(d));
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new form TablesPanel
|
* Creates new form TablesPanel
|
||||||
*/
|
*/
|
||||||
|
@ -117,6 +134,28 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
activeTablesSorter = new MageTableRowSorter(tableModel);
|
activeTablesSorter = new MageTableRowSorter(tableModel);
|
||||||
tableTables.setRowSorter(activeTablesSorter);
|
tableTables.setRowSorter(activeTablesSorter);
|
||||||
|
|
||||||
|
|
||||||
|
// time ago column settings
|
||||||
|
// formater
|
||||||
|
timeAgoFormater.setLocale(Locale.ENGLISH);
|
||||||
|
JustNow jn = timeAgoFormater.getUnit(JustNow.class);
|
||||||
|
jn.setMaxQuantity(1000L * 30L); // 30 seconds gap (show "just now" from 0 to 30 secs)
|
||||||
|
// renderer
|
||||||
|
tableTables.getColumnModel().getColumn(TableTableModel.COLUMN_CREATED).setCellRenderer(timeAgoCellRenderer);
|
||||||
|
/* date sorter (not need, default is good - see getColumnClass)
|
||||||
|
activeTablesSorter.setComparator(TableTableModel.COLUMN_CREATED, new Comparator<Date>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Date v1, Date v2) {
|
||||||
|
return v1.compareTo(v2);
|
||||||
|
}
|
||||||
|
|
||||||
|
});*/
|
||||||
|
// default sort by created date (last games from above)
|
||||||
|
ArrayList list = new ArrayList();
|
||||||
|
list.add(new RowSorter.SortKey(TableTableModel.COLUMN_CREATED, SortOrder.DESCENDING));
|
||||||
|
activeTablesSorter.setSortKeys(list);
|
||||||
|
|
||||||
|
|
||||||
TableUtil.setColumnWidthAndOrder(tableTables, DEFAULT_COLUMNS_WIDTH,
|
TableUtil.setColumnWidthAndOrder(tableTables, DEFAULT_COLUMNS_WIDTH,
|
||||||
PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, PreferencesDialog.KEY_TABLES_COLUMNS_ORDER);
|
PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, PreferencesDialog.KEY_TABLES_COLUMNS_ORDER);
|
||||||
|
|
||||||
|
@ -1286,11 +1325,15 @@ class TableTableModel extends AbstractTableModel {
|
||||||
private TableView[] tables = new TableView[0];
|
private TableView[] tables = new TableView[0];
|
||||||
private static final DateFormat timeFormatter = new SimpleDateFormat("HH:mm:ss");
|
private static final DateFormat timeFormatter = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
|
||||||
|
public void TableModel() {
|
||||||
|
}
|
||||||
|
|
||||||
public void loadData(Collection<TableView> tables) throws MageRemoteException {
|
public void loadData(Collection<TableView> tables) throws MageRemoteException {
|
||||||
this.tables = tables.toArray(new TableView[0]);
|
this.tables = tables.toArray(new TableView[0]);
|
||||||
this.fireTableDataChanged();
|
this.fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRowCount() {
|
public int getRowCount() {
|
||||||
return tables.length;
|
return tables.length;
|
||||||
|
@ -1319,7 +1362,7 @@ class TableTableModel extends AbstractTableModel {
|
||||||
case 6:
|
case 6:
|
||||||
return tables[arg0].isPassworded() ? PASSWORDED : "";
|
return tables[arg0].isPassworded() ? PASSWORDED : "";
|
||||||
case 7:
|
case 7:
|
||||||
return timeFormatter.format(tables[arg0].getCreateTime());
|
return tables[arg0].getCreateTime(); // use cell render, not format here
|
||||||
case 8:
|
case 8:
|
||||||
return tables[arg0].getSkillLevel();
|
return tables[arg0].getSkillLevel();
|
||||||
case 9:
|
case 9:
|
||||||
|
@ -1384,6 +1427,8 @@ class TableTableModel extends AbstractTableModel {
|
||||||
return Icon.class;
|
return Icon.class;
|
||||||
case COLUMN_SKILL:
|
case COLUMN_SKILL:
|
||||||
return SkillLevel.class;
|
return SkillLevel.class;
|
||||||
|
case COLUMN_CREATED:
|
||||||
|
return Date.class;
|
||||||
default:
|
default:
|
||||||
return String.class;
|
return String.class;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue