Move keywords files out of jar into \Magarena\translations\keywords folder. (closes #1140)
parent
06b9329a10
commit
30707191fc
|
@ -1,15 +1,19 @@
|
|||
package magic.ui.screen.keywords;
|
||||
|
||||
import java.io.IOException;
|
||||
import magic.ui.FontsAndBorders;
|
||||
import magic.ui.widget.TexturedPanel;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class ContentPanelA extends TexturedPanel {
|
||||
|
||||
ContentPanelA() {
|
||||
setLayout(new MigLayout("insets 0, gap 0, fill"));
|
||||
add(new KeywordsScrollPane(), "grow");
|
||||
class ContentPanelA extends ScreenContentPanel {
|
||||
|
||||
ContentPanelA() {
|
||||
try {
|
||||
setLayout(new MigLayout("insets 0, gap 0, fill"));
|
||||
add(new KeywordsScrollPane(), "grow");
|
||||
} catch (IOException ex) {
|
||||
showKeywordsFileError(ex);
|
||||
}
|
||||
setBackground(FontsAndBorders.TRANSLUCENT_WHITE_STRONG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package magic.ui.screen.keywords;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import magic.ui.theme.Theme;
|
||||
import magic.ui.utility.MagicStyle;
|
||||
import magic.ui.widget.TexturedPanel;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class ContentPanelB extends TexturedPanel {
|
||||
class ContentPanelB extends ScreenContentPanel {
|
||||
|
||||
ContentPanelB() {
|
||||
|
||||
|
@ -18,16 +18,17 @@ class ContentPanelB extends TexturedPanel {
|
|||
// since we already have the card name.
|
||||
// CardDefinitions.getMissingCards();
|
||||
|
||||
KeywordPanelB keywordPanel = new KeywordPanelB();
|
||||
try {
|
||||
KeywordPanelB keywordPanel = new KeywordPanelB();
|
||||
setLayout(new MigLayout("", "[grow, fill][500!, grow, fill]", "[grow, fill]"));
|
||||
add(new KeywordsListPane(keywordPanel));
|
||||
add(keywordPanel);
|
||||
} catch (IOException ex) {
|
||||
showKeywordsFileError(ex);
|
||||
}
|
||||
|
||||
setLayout(new MigLayout("", "[grow, fill][500!, grow, fill]", "[grow, fill]"));
|
||||
add(new KeywordsListPane(keywordPanel));
|
||||
add(keywordPanel);
|
||||
|
||||
// setBackground(ActionBar.getBackgroundColor().darker());
|
||||
final Color refBG = MagicStyle.getTheme().getColor(Theme.COLOR_TITLE_BACKGROUND);
|
||||
final Color thisBG = MagicStyle.getTranslucentColor(refBG, 220);
|
||||
setBackground(thisBG.darker());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,29 @@
|
|||
package magic.ui.screen.keywords;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import magic.utility.MagicResources;
|
||||
import magic.data.GeneralConfig;
|
||||
import magic.translate.MText;
|
||||
import magic.utility.MagicFileSystem;
|
||||
|
||||
final class KeywordsHelper {
|
||||
|
||||
private static final String _S1 = "Invalid keywords file.";
|
||||
|
||||
private KeywordsHelper() { }
|
||||
|
||||
static Keyword[] loadKeywordsFileToSortedArray() {
|
||||
|
||||
final List<Keyword> keywords = new ArrayList<>();
|
||||
final String content = MagicResources.getKeywordsFileContent();
|
||||
|
||||
Keyword keyword = null;
|
||||
private static Keyword[] loadKeywordsFileToSortedArray(File keywordsFile) throws FileNotFoundException {
|
||||
|
||||
final List<Keyword> keywords = new ArrayList<>();
|
||||
|
||||
Keyword keyword = new Keyword("");
|
||||
|
||||
try (final Scanner sc = new Scanner(keywordsFile, "UTF-8")) {
|
||||
|
||||
try (final Scanner sc = new Scanner(content)) {
|
||||
while (sc.hasNextLine()) {
|
||||
|
||||
final String line = sc.nextLine().trim();
|
||||
|
@ -40,8 +48,49 @@ final class KeywordsHelper {
|
|||
}
|
||||
|
||||
return keywords.stream()
|
||||
.sorted()
|
||||
.toArray(sz -> new Keyword[sz]);
|
||||
.sorted()
|
||||
.toArray(sz -> new Keyword[sz]);
|
||||
}
|
||||
|
||||
private static File getKeywordsFile(String lang) {
|
||||
return MagicFileSystem
|
||||
.getDataPath(MagicFileSystem.DataPath.TRANSLATIONS)
|
||||
.resolve("keywords")
|
||||
.resolve((lang.isEmpty() ? "English" : lang) + ".txt")
|
||||
.toFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default English keywords file.
|
||||
*/
|
||||
private static File getKeywordsFile() throws FileNotFoundException {
|
||||
return getKeywordsFile("");
|
||||
}
|
||||
|
||||
static Keyword[] getKeywords() throws IOException {
|
||||
|
||||
Keyword[] keywords = null;
|
||||
File keywordsFile = null;
|
||||
String lang = GeneralConfig.getInstance().getTranslation();
|
||||
|
||||
try {
|
||||
keywordsFile = getKeywordsFile(lang);
|
||||
keywords = loadKeywordsFileToSortedArray(keywordsFile);
|
||||
} catch (FileNotFoundException ex) {
|
||||
if (!lang.isEmpty()) {
|
||||
// no keywords file exists for current translation so load English file instead.
|
||||
keywordsFile = getKeywordsFile();
|
||||
keywords = loadKeywordsFileToSortedArray(keywordsFile);
|
||||
} else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
if (keywords == null || keywords.length == 0) {
|
||||
throw new IOException(MText.get(_S1) + "\n" + keywordsFile);
|
||||
}
|
||||
|
||||
return keywords;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
package magic.ui.screen.keywords;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class KeywordsListPane extends JScrollPane {
|
||||
|
||||
KeywordsListPane(final KeywordPanelB keywordPanel) {
|
||||
KeywordsListPane(final KeywordPanelB keywordPanel) throws IOException {
|
||||
|
||||
JList<Keyword> list = new JList<>(KeywordsHelper.loadKeywordsFileToSortedArray());
|
||||
JList<Keyword> list = new JList<>(KeywordsHelper.getKeywords());
|
||||
|
||||
list.setLayoutOrientation(JList.VERTICAL_WRAP);
|
||||
list.setVisibleRowCount(-1);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package magic.ui.screen.keywords;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
@ -11,7 +12,7 @@ import javax.swing.SwingUtilities;
|
|||
@SuppressWarnings("serial")
|
||||
class KeywordsScrollPane extends JScrollPane {
|
||||
|
||||
KeywordsScrollPane() {
|
||||
KeywordsScrollPane() throws IOException {
|
||||
setDefaultProperties();
|
||||
getViewport().add(new KeywordsScrollablePanel());
|
||||
setScrollbarToTop();
|
||||
|
|
|
@ -2,6 +2,7 @@ package magic.ui.screen.keywords;
|
|||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Rectangle;
|
||||
import java.io.IOException;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.Scrollable;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
@ -15,14 +16,14 @@ import net.miginfocom.swing.MigLayout;
|
|||
@SuppressWarnings("serial")
|
||||
class KeywordsScrollablePanel extends JPanel implements Scrollable {
|
||||
|
||||
KeywordsScrollablePanel() {
|
||||
KeywordsScrollablePanel() throws IOException {
|
||||
setLayout(new MigLayout("insets 10, gap 6 8, wrap 2"));
|
||||
setOpaque(false);
|
||||
refreshKeywords();
|
||||
}
|
||||
|
||||
private void refreshKeywords() {
|
||||
for (final Keyword keywordDefinition : KeywordsHelper.loadKeywordsFileToSortedArray()) {
|
||||
private void refreshKeywords() throws IOException {
|
||||
for (final Keyword keywordDefinition : KeywordsHelper.getKeywords()) {
|
||||
add(new KeywordPanelA(keywordDefinition), "w 10:100%, top");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package magic.ui.screen.keywords;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import magic.ui.widget.TexturedPanel;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
abstract class ScreenContentPanel extends TexturedPanel {
|
||||
|
||||
protected final void showKeywordsFileError(Exception ex) {
|
||||
JLabel lbl = new JLabel(String.format(
|
||||
"<html><h2><font color=\"red\"><b>%s</b></font></h1></html>",
|
||||
ex.toString().replaceAll("\n", "<br>"))
|
||||
);
|
||||
setLayout(new MigLayout());
|
||||
add(lbl);
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import magic.data.GeneralConfig;
|
||||
import magic.data.MagicIcon;
|
||||
import magic.data.MagicPredefinedFormat;
|
||||
import magic.data.MagicSets;
|
||||
|
@ -15,16 +14,6 @@ public final class MagicResources {
|
|||
// Used as reference class for accessing JAR resources.
|
||||
private static final MagicResources instance = new MagicResources();
|
||||
|
||||
public static String getKeywordsFileContent() {
|
||||
final String content = getResourceFileContent(
|
||||
String.format("/magic/data/keywords/%s.txt",
|
||||
GeneralConfig.getInstance().getTranslation())
|
||||
);
|
||||
return content.isEmpty()
|
||||
? getResourceFileContent("/magic/data/keywords/English.txt")
|
||||
: content;
|
||||
}
|
||||
|
||||
public static String getFileContent(final MagicSets magicSet) {
|
||||
return getResourceFileContent("/magic/data/sets/" + magicSet.toString().replace("_", "") + ".txt");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue