mirror of
https://github.com/correl/mage.git
synced 2025-04-07 17:00:08 -09:00
Added save/restore of active table columns order.
This commit is contained in:
parent
9fb75d3877
commit
e662111ddd
3 changed files with 38 additions and 23 deletions
Mage.Client/src/main/java
|
@ -138,6 +138,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
||||||
// pref settings of table settings and filtering
|
// pref settings of table settings and filtering
|
||||||
public static final String KEY_TABLES_FILTER_SETTINGS = "tablePanelFilterSettings";
|
public static final String KEY_TABLES_FILTER_SETTINGS = "tablePanelFilterSettings";
|
||||||
public static final String KEY_TABLES_COLUMNS_WIDTH = "tablePanelColumnWidth";
|
public static final String KEY_TABLES_COLUMNS_WIDTH = "tablePanelColumnWidth";
|
||||||
|
public static final String KEY_TABLES_COLUMNS_ORDER = "tablePanelColumnSort";
|
||||||
|
|
||||||
// positions of divider bars
|
// positions of divider bars
|
||||||
public static final String KEY_TABLES_DIVIDER_LOCATION_1 = "tablePanelDividerLocation1";
|
public static final String KEY_TABLES_DIVIDER_LOCATION_1 = "tablePanelDividerLocation1";
|
||||||
|
|
|
@ -92,6 +92,7 @@ import mage.view.MatchView;
|
||||||
import mage.view.RoomUsersView;
|
import mage.view.RoomUsersView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.mage.card.arcane.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -133,7 +134,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
activeTablesSorter = new MageTableRowSorter(tableModel);
|
activeTablesSorter = new MageTableRowSorter(tableModel);
|
||||||
tableTables.setRowSorter(activeTablesSorter);
|
tableTables.setRowSorter(activeTablesSorter);
|
||||||
|
|
||||||
TableTableModel.setColumnWidth(tableTables);
|
TableTableModel.setColumnWidthAndOrder(tableTables);
|
||||||
|
|
||||||
tableCompleted.setRowSorter(new MageTableRowSorter(matchesModel));
|
tableCompleted.setRowSorter(new MageTableRowSorter(matchesModel));
|
||||||
|
|
||||||
|
@ -310,17 +311,21 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
// Column width
|
// Column width
|
||||||
StringBuilder columnWidthSettings = new StringBuilder();
|
StringBuilder columnWidthSettings = new StringBuilder();
|
||||||
|
StringBuilder columnOrderSettings = new StringBuilder();
|
||||||
boolean firstValue = true;
|
boolean firstValue = true;
|
||||||
for (int i = 0; i < tableTables.getColumnModel().getColumnCount(); i++) {
|
for (int i = 0; i < tableTables.getColumnModel().getColumnCount(); i++) {
|
||||||
TableColumn column = tableTables.getColumnModel().getColumn(tableTables.convertColumnIndexToView(i));
|
TableColumn column = tableTables.getColumnModel().getColumn(tableTables.convertColumnIndexToView(i));
|
||||||
if (!firstValue) {
|
if (!firstValue) {
|
||||||
columnWidthSettings.append(",");
|
columnWidthSettings.append(",");
|
||||||
|
columnOrderSettings.append(",");
|
||||||
} else {
|
} else {
|
||||||
firstValue = false;
|
firstValue = false;
|
||||||
}
|
}
|
||||||
columnWidthSettings.append(column.getWidth());
|
columnWidthSettings.append(column.getWidth());
|
||||||
|
columnOrderSettings.append(tableTables.convertColumnIndexToModel(i));
|
||||||
}
|
}
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, columnWidthSettings.toString());
|
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, columnWidthSettings.toString());
|
||||||
|
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_COLUMNS_ORDER, columnOrderSettings.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreDividerLocations() {
|
private void restoreDividerLocations() {
|
||||||
|
@ -1182,36 +1187,30 @@ class TableTableModel extends AbstractTableModel {
|
||||||
this.fireTableDataChanged();
|
this.fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void setColumnWidth(JTable table) {
|
static public void setColumnWidthAndOrder(JTable table) {
|
||||||
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||||
|
|
||||||
// read the saved column width
|
|
||||||
String widthsString = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, null);
|
|
||||||
int[] widths = null;
|
|
||||||
int length = 0;
|
|
||||||
if (widthsString != null && !widthsString.isEmpty()) {
|
|
||||||
String[] items = widthsString.split(",");
|
|
||||||
length = items.length;
|
|
||||||
widths = new int[length];
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
try {
|
|
||||||
widths[i] = Integer.parseInt(items[i]);
|
|
||||||
if (widths[i] > 500) {
|
|
||||||
widths[i] = 300;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException nfe) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// set the column width from saved value or defaults
|
// set the column width from saved value or defaults
|
||||||
|
int[] widths = Util.getIntArrayFromString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, null));
|
||||||
|
int lengthW = widths.length;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (int width : defaultColumnsWidth) {
|
for (int width : defaultColumnsWidth) {
|
||||||
if (length > i) {
|
if (lengthW > i) {
|
||||||
width = widths[i];
|
width = widths[i];
|
||||||
}
|
}
|
||||||
TableColumn column = table.getColumnModel().getColumn(i++);
|
TableColumn column = table.getColumnModel().getColumn(i++);
|
||||||
column.setWidth(width);
|
column.setWidth(width);
|
||||||
column.setPreferredWidth(width);
|
column.setPreferredWidth(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set the column order
|
||||||
|
int[] order = Util.getIntArrayFromString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_COLUMNS_ORDER, null));
|
||||||
|
if (order != null && order.length == table.getColumnCount()) {
|
||||||
|
for (int j = 0; j < table.getColumnCount(); j++) {
|
||||||
|
table.moveColumn(table.convertColumnIndexToView(order[j]), j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,8 +16,8 @@ import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
public class Util {
|
public class Util {
|
||||||
public static final boolean isMac = System.getProperty("os.name").toLowerCase().indexOf("mac") != -1;
|
public static final boolean isMac = System.getProperty("os.name").toLowerCase().contains("mac");
|
||||||
public static final boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("windows") == -1;
|
public static final boolean isWindows = !System.getProperty("os.name").toLowerCase().contains("windows");
|
||||||
|
|
||||||
public static final ThreadPoolExecutor threadPool;
|
public static final ThreadPoolExecutor threadPool;
|
||||||
static private int threadCount;
|
static private int threadCount;
|
||||||
|
@ -89,4 +89,19 @@ public class Util {
|
||||||
throw new RuntimeException("Error invoking runnable in UI thread.", ex);
|
throw new RuntimeException("Error invoking runnable in UI thread.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int[] getIntArrayFromString(String stringData) {
|
||||||
|
int[] intArray = null;
|
||||||
|
if (stringData != null && !stringData.isEmpty()) {
|
||||||
|
String[] items = stringData.split(",");
|
||||||
|
int lengthW = items.length;
|
||||||
|
intArray = new int[lengthW];
|
||||||
|
for (int i = 0; i < lengthW; i++) {
|
||||||
|
try {
|
||||||
|
intArray[i] = Integer.parseInt(items[i]);
|
||||||
|
} catch (NumberFormatException nfe) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return intArray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue