Some fixes for the sort setting of deck editor.

This commit is contained in:
LevelX2 2014-01-21 17:18:02 +01:00
parent 9dc1120500
commit 00b03c91b6
5 changed files with 24 additions and 59 deletions

View file

@ -28,11 +28,6 @@
package mage.client.deckeditor; package mage.client.deckeditor;
import mage.client.constants.Constants.SortBy; import mage.client.constants.Constants.SortBy;
import static mage.client.constants.Constants.SortBy.CASTING_COST;
import static mage.client.constants.Constants.SortBy.COLOR;
import static mage.client.constants.Constants.SortBy.COLOR_DETAILED;
import static mage.client.constants.Constants.SortBy.NAME;
import static mage.client.constants.Constants.SortBy.RARITY;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
/** /**
@ -45,19 +40,32 @@ public abstract class SortSetting {
int sortIndex; int sortIndex;
boolean ascending; boolean ascending;
String prefSortBy;
String prefSortIndex;
String prefSortAscending;
public SortSetting(String prefSortBy, String prefSortIndex, String prefSortAscending) {
this.prefSortBy = prefSortBy;
this.prefSortIndex = prefSortIndex;
this.prefSortAscending = prefSortAscending;
this.sortBy = SortBy.getByString(PreferencesDialog.getCachedValue(this.prefSortBy, "Color"));
this.sortIndex = Integer.parseInt(PreferencesDialog.getCachedValue(this.prefSortIndex, "1"));
this.ascending = PreferencesDialog.getCachedValue(this.prefSortAscending, "1").equals("1");
}
public void setSortBy(SortBy sortBy) { public void setSortBy(SortBy sortBy) {
this.sortBy = sortBy; this.sortBy = sortBy;
PreferencesDialog.saveValue(PreferencesDialog.KEY_DRAFT_SORT_BY, sortBy.toString()); PreferencesDialog.saveValue(prefSortBy, sortBy.toString());
} }
public void setSortIndex(int sortIndex) { public void setSortIndex(int sortIndex) {
this.sortIndex = sortIndex; this.sortIndex = sortIndex;
PreferencesDialog.saveValue(PreferencesDialog.KEY_DRAFT_SORT_INDEX, Integer.toString(sortIndex)); PreferencesDialog.saveValue(this.prefSortIndex, Integer.toString(sortIndex));
} }
public void setAscending(boolean ascending) { public void setAscending(boolean ascending) {
this.ascending = ascending; this.ascending = ascending;
PreferencesDialog.saveValue(PreferencesDialog.KEY_DRAFT_SORT_ASCENDING, this.ascending ? "1":"0"); PreferencesDialog.saveValue(this.prefSortAscending, this.ascending ? "1":"0");
} }
public SortBy getSortBy() { public SortBy getSortBy() {
@ -71,35 +79,4 @@ public abstract class SortSetting {
public boolean isAscending() { public boolean isAscending() {
return ascending; return ascending;
} }
public int convertSortByToIndex(SortBy sortBy) {
switch(sortBy) {
case NAME:
return 1;
case CASTING_COST:
return 2;
case COLOR:
case COLOR_DETAILED:
return 3;
case RARITY:
return 5;
default:
return 0;
}
}
public SortBy convertIndexToSortBy(int index) {
switch (index) {
case 1:
return SortBy.NAME;
case 2:
return SortBy.CASTING_COST;
case 3:
return SortBy.COLOR;
case 5:
return SortBy.RARITY;
default:
return SortBy.UNSORTED;
}
}
} }

View file

@ -27,7 +27,6 @@
*/ */
package mage.client.deckeditor; package mage.client.deckeditor;
import mage.client.constants.Constants.SortBy;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
/** /**
@ -37,15 +36,13 @@ import mage.client.dialog.PreferencesDialog;
public class SortSettingBase extends SortSetting { public class SortSettingBase extends SortSetting {
private static SortSettingBase fInstance = new SortSettingBase(); private final static SortSettingBase fInstance = new SortSettingBase();
public static SortSettingBase getInstance() { public static SortSettingBase getInstance() {
return fInstance; return fInstance;
} }
private SortSettingBase() { private SortSettingBase() {
this.sortBy = SortBy.getByString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BASE_SORT_BY, "Color")); super(PreferencesDialog.KEY_BASE_SORT_BY, PreferencesDialog.KEY_BASE_SORT_INDEX, PreferencesDialog.KEY_BASE_SORT_ASCENDING);
this.sortIndex = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BASE_SORT_INDEX, "1"));
this.ascending = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BASE_SORT_INDEX, "1").equals("1");
} }
} }

View file

@ -27,7 +27,6 @@
*/ */
package mage.client.deckeditor; package mage.client.deckeditor;
import mage.client.constants.Constants.SortBy;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
/** /**
@ -37,15 +36,13 @@ import mage.client.dialog.PreferencesDialog;
public class SortSettingDeck extends SortSetting { public class SortSettingDeck extends SortSetting {
private static SortSettingDeck fInstance = new SortSettingDeck(); private final static SortSettingDeck fInstance = new SortSettingDeck();
public static SortSettingDeck getInstance() { public static SortSettingDeck getInstance() {
return fInstance; return fInstance;
} }
private SortSettingDeck() { private SortSettingDeck() {
this.sortBy = SortBy.getByString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DECK_SORT_BY, "Color")); super(PreferencesDialog.KEY_DECK_SORT_BY, PreferencesDialog.KEY_DECK_SORT_INDEX, PreferencesDialog.KEY_DECK_SORT_ASCENDING);
this.sortIndex = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DECK_SORT_INDEX, "1"));
this.ascending = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DECK_SORT_INDEX, "1").equals("1");
} }
} }

View file

@ -28,7 +28,6 @@
package mage.client.deckeditor; package mage.client.deckeditor;
import mage.client.constants.Constants.SortBy;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
/** /**
@ -37,15 +36,13 @@ import mage.client.dialog.PreferencesDialog;
*/ */
public class SortSettingDraft extends SortSetting { public class SortSettingDraft extends SortSetting {
private static SortSettingDraft fInstance = new SortSettingDraft(); private final static SortSettingDraft fInstance = new SortSettingDraft();
public static SortSettingDraft getInstance() { public static SortSettingDraft getInstance() {
return fInstance; return fInstance;
} }
private SortSettingDraft() { private SortSettingDraft() {
this.sortBy = SortBy.getByString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DRAFT_SORT_BY, "Color")); super(PreferencesDialog.KEY_DRAFT_SORT_BY, PreferencesDialog.KEY_DRAFT_SORT_INDEX,PreferencesDialog.KEY_DRAFT_SORT_INDEX );
this.sortIndex = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DRAFT_SORT_INDEX, "1"));
this.ascending = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DRAFT_SORT_INDEX, "1").equals("1");
} }
} }

View file

@ -27,7 +27,6 @@
*/ */
package mage.client.deckeditor; package mage.client.deckeditor;
import mage.client.constants.Constants.SortBy;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
/** /**
@ -44,8 +43,6 @@ public class SortSettingSideboard extends SortSetting {
} }
private SortSettingSideboard() { private SortSettingSideboard() {
this.sortBy = SortBy.getByString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SIDEBOARD_SORT_BY, "Color")); super(PreferencesDialog.KEY_SIDEBOARD_SORT_BY, PreferencesDialog.KEY_SIDEBOARD_SORT_INDEX, PreferencesDialog.KEY_SIDEBOARD_SORT_INDEX);
this.sortIndex = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SIDEBOARD_SORT_INDEX, "1"));
this.ascending = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SIDEBOARD_SORT_INDEX, "1").equals("1");
} }
} }