Skip to content

Commit

Permalink
Merge branch »locales«:
Browse files Browse the repository at this point in the history
* Multilanguage support (DE/EN)
* Improve FFM ghost detection
  • Loading branch information
killerbees19 committed Nov 18, 2017
1 parent f3cf4ca commit 7b5ac26
Show file tree
Hide file tree
Showing 21 changed files with 1,095 additions and 384 deletions.
6 changes: 4 additions & 2 deletions Makefile
Expand Up @@ -27,6 +27,8 @@ compile: $(classes)
echo Original version: $(version)
@echo git-$(commit) > $(VFILE)

cp -af ./src/*.properties ./classes/

%.class: %.java
$(JC) $(JFLAGS) $<

Expand All @@ -39,7 +41,7 @@ jar: compile
@echo "Permissions: all-permissions" >> $(MFFILE)

cd ./classes && \
$(JAR) -cmf ../$(MFFILE) ../$(JARFILE) ./*.class ../$(VFILE) && \
$(JAR) -cmf ../$(MFFILE) ../$(JARFILE) ./*.class ./*.properties ../$(VFILE) && \
chmod +x ../$(JARFILE) && $(RM) ../$(MFFILE)

zip: jar
Expand Down Expand Up @@ -70,4 +72,4 @@ sig: zip
clean:
$(RM) build/HTGT_*.*
$(RM) $(MFFILE) $(VFILE) $(LICENCEFILE)
$(RM) classes/*.class src/*.class
$(RM) classes/*.class classes/*.properties src/*.class
12 changes: 1 addition & 11 deletions src/DynamicMenuItem.java
Expand Up @@ -19,7 +19,6 @@

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Method;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

Expand Down Expand Up @@ -56,15 +55,6 @@ private void DynamicMenuItemWorker(String textLabel, String className, String me
@Override
public void actionPerformed(ActionEvent a)
{
try
{
Class<?> c = Class.forName(this.className);
Method m = c.getDeclaredMethod(this.methodName);
m.invoke(null);
}
catch(Exception e)
{
e.printStackTrace();
}
FNX.actionCallback(this.className, this.methodName);
}
}
59 changes: 59 additions & 0 deletions src/FNX.java
Expand Up @@ -27,6 +27,8 @@
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;

import java.lang.reflect.Method;

import java.net.URLEncoder;

import java.security.MessageDigest;
Expand All @@ -37,6 +39,7 @@

import java.util.Date;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.TimeZone;

import javax.swing.JEditorPane;
Expand Down Expand Up @@ -373,4 +376,60 @@ public static JEditorPane getHTMLPane(String html)

return e;
}

public static ResourceBundle getLangBundle(String bundle)
{
return ResourceBundle.getBundle(String.format("LangBundle_%s", bundle));
}

/*
public static String formatLangString(ResourceBundle lang, String key)
{
return String.format(getLangString(lang, key));
}
*/

public static String formatLangString(ResourceBundle lang, String key, Object... args)
{
return String.format(getLangString(lang, key), args);
}

public static String getLangString(ResourceBundle lang, String key)
{
try
{
return new String(lang.getString(key).getBytes("ISO-8859-1"), "UTF-8");
}
catch(UnsupportedEncodingException e)
{
e.printStackTrace();
return "{" + key + "}";
}
}

public static String[] getLangStrings(ResourceBundle lang, String[] keys)
{
String[] results = new String[keys.length];

for(int i = 0; i < keys.length; i++)
{
results[i] = getLangString(lang, keys[i]);
}

return results;
}

public static void actionCallback(String className, String methodName)
{
try
{
Class<?> c = Class.forName(className);
Method m = c.getDeclaredMethod(methodName);
m.invoke(null);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
14 changes: 9 additions & 5 deletions src/FNX_ContextMenu.java
Expand Up @@ -29,6 +29,8 @@

import javax.swing.text.JTextComponent;

import java.util.ResourceBundle;

public class FNX_ContextMenu extends JPopupMenu implements ActionListener
{
public static final FNX_ContextMenu INSTANCE = new FNX_ContextMenu();
Expand All @@ -41,12 +43,14 @@ public class FNX_ContextMenu extends JPopupMenu implements ActionListener

private FNX_ContextMenu()
{
itemCut = newItem("Ausschneiden", 'X');
itemCopy = newItem("Kopieren", 'C');
itemPaste = newItem("Einfügen", 'V');
itemDelete = newItem("Löschen");
ResourceBundle lang = FNX.getLangBundle("ContextMenu");

itemCut = newItem(FNX.getLangString(lang, "cut"), 'X');
itemCopy = newItem(FNX.getLangString(lang, "copy"), 'C');
itemPaste = newItem(FNX.getLangString(lang, "paste"), 'V');
itemDelete = newItem(FNX.getLangString(lang, "delete"));
addSeparator(); // ----------------------------
itemSelectAll = newItem("Alles markieren", 'A');
itemSelectAll = newItem(FNX.getLangString(lang, "markAll"), 'A');
}

private JMenuItem newItem(String t)
Expand Down
49 changes: 49 additions & 0 deletions src/FlexibleActionHandler.java
@@ -0,0 +1,49 @@
/**
* FlexibleActionHandler.java: Avoid anonymous inner classes
* Copyright (C) 2017 Christian Schrötter <cs@fnx.li>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;

public class FlexibleActionHandler extends JMenuItem implements ActionListener
{
String className;
String methodName;

public FlexibleActionHandler(String className, String methodName)
{
super();

this.className = className;
this.methodName = methodName;

addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent a)
{
FNX.actionCallback(this.className, this.methodName);
}
}

// TODO: Diese Klasse sollte nicht JMenuItem erweitern.
// Ich bin jetzt aber zu faul die passende zu suchen,
// bei der addActionListener() implementiert ist.
// ...

0 comments on commit 7b5ac26

Please sign in to comment.