forked from External/mage
refactor divider setting and saving into utility functions
refactor setting and saving filters into utility functions
This commit is contained in:
parent
d0c30e11bf
commit
5822a7d94d
3 changed files with 84 additions and 62 deletions
|
|
@ -7,6 +7,7 @@ package mage.client.util.gui;
|
|||
|
||||
import java.util.Arrays;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.table.TableColumn;
|
||||
import org.apache.log4j.Logger;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
|
|
@ -27,7 +28,29 @@ public final class TableUtil {
|
|||
|
||||
private static final Logger LOGGER = Logger.getLogger(TableUtil.class);
|
||||
|
||||
static public void setColumnWidthAndOrder(JTable table, int[] defaultColumnsWidth, String widthPrefKey, String orderPrefKey) {
|
||||
public static void saveActiveFiltersToPrefs(String filterPrefKey, JToggleButton[] buttons) {
|
||||
StringBuilder currentFilters = new StringBuilder();
|
||||
for (JToggleButton component : buttons) {
|
||||
currentFilters.append(component.isSelected() ? "x" : "-");
|
||||
}
|
||||
|
||||
PreferencesDialog.saveValue(filterPrefKey, currentFilters.toString());
|
||||
}
|
||||
|
||||
public static void setActiveFilters(String filterPrefKey, JToggleButton[] buttons) {
|
||||
String formatSettings = PreferencesDialog.getCachedValue(filterPrefKey, "");
|
||||
int i = 0;
|
||||
for (JToggleButton component : buttons) {
|
||||
if (formatSettings.length() > i) {
|
||||
component.setSelected(formatSettings.substring(i, i + 1).equals("x"));
|
||||
} else {
|
||||
component.setSelected(true);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setColumnWidthAndOrder(JTable table, int[] defaultColumnsWidth, String widthPrefKey, String orderPrefKey) {
|
||||
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
|
||||
// set the column width from saved value or defaults
|
||||
|
|
@ -58,11 +81,11 @@ public final class TableUtil {
|
|||
|
||||
}
|
||||
|
||||
static public void saveColumnWidthAndOrderToPrefs(JTable table, String widthPrefKey, String orderPrefKey) {
|
||||
// Column width
|
||||
public static void saveColumnWidthAndOrderToPrefs(JTable table, String widthPrefKey, String orderPrefKey) {
|
||||
StringBuilder columnWidthSettings = new StringBuilder();
|
||||
StringBuilder columnOrderSettings = new StringBuilder();
|
||||
boolean firstValue = true;
|
||||
|
||||
for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
|
||||
TableColumn column = table.getColumnModel().getColumn(table.convertColumnIndexToView(i));
|
||||
if (!firstValue) {
|
||||
|
|
@ -74,14 +97,14 @@ public final class TableUtil {
|
|||
columnWidthSettings.append(column.getWidth());
|
||||
columnOrderSettings.append(table.convertColumnIndexToModel(i));
|
||||
}
|
||||
|
||||
PreferencesDialog.saveValue(widthPrefKey, columnWidthSettings.toString());
|
||||
PreferencesDialog.saveValue(orderPrefKey, columnOrderSettings.toString());
|
||||
|
||||
LOGGER.info("saving column widths: " + columnWidthSettings.toString());
|
||||
LOGGER.info("saving column order: " + columnOrderSettings.toString());
|
||||
}
|
||||
|
||||
public static int[] getIntArrayFromString(String stringData) {
|
||||
private static int[] getIntArrayFromString(String stringData) {
|
||||
int[] intArray = null;
|
||||
if (stringData != null && !stringData.isEmpty()) {
|
||||
String[] items = stringData.split(",");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue