Skip to content

Commit

Permalink
Fix issue #7
Browse files Browse the repository at this point in the history
* Use sun.misc.Unsafe instead of reflection to replace final field
  • Loading branch information
maripo committed Sep 4, 2021
1 parent f9630ef commit 681419e
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 10 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<property name="commit.message" value="Commit message"/>
<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
<property name="plugin.main.version" value="14153"/>
<property name="version.entry.commit.revision" value="18"/>
<property name="version.entry.commit.revision" value="23"/>

<!-- Configure these properties (replace "..." accordingly).
See https://josm.openstreetmap.de/wiki/DevelopersGuide/DevelopingPlugins
Expand All @@ -22,7 +22,7 @@

<target name="additional-manifest">
<manifest file="MANIFEST" mode="update">
<attribute name="14153_Plugin-Url" value="22;https://github.com/maripo/JOSM_quicklabel/releases/download/22/QuickLabel.jar" />
<attribute name="14153_Plugin-Url" value="23;https://github.com/maripo/JOSM_quicklabel/releases/download/23/QuickLabel.jar" />
<attribute name="13661_Plugin-Url" value="21;https://github.com/maripo/JOSM_quicklabel/releases/download/21/QuickLabel.jar" />
<attribute name="12545_Plugin-Url" value="v1.0.1;https://github.com/maripo/JOSM_quicklabel/releases/download/v1.0.1/QuickLabel.jar" />
</manifest>
Expand Down
78 changes: 78 additions & 0 deletions i18n/en.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:48
#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:50
#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:55
msgid "Show specified tag values next to objects"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:92
msgid "Your QuickLabel config is applied."
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:126
msgid "Restore default"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:190
msgid "Move up"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:191
msgid "Move down"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:244
msgid "Main"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:245
msgid "Sub"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:257
msgid ""
"<html>Tags to show next to objects.<br>You can specify multiple tags by "
"writing into multiple lines<br>in the order of descending priorities.</html>"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:259
msgid ""
"<html>Label format will be \"<b><i>Main</i>(<i>Sub</i>)</b>\" or "
"\"<b><i>Sub</i></b>\" if main tag is empty.</html>"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:280
msgid "Show key-value pairs"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:281
msgid "Always show sub tag with parentheses"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:282
msgid "Apply on startup"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:284
msgid "Apply"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:285
msgid "Apply change and show customized labels"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:293
msgctxt "quicklabel"
msgid "Reset"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:294
msgid "Reset QuickLabel config and show default labels"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:302
msgid "Cancel"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:303
msgid "Close this window without saving"
msgstr ""
104 changes: 104 additions & 0 deletions i18n/ja.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Japanese translations for PACKAGE package.
# Copyright (C) 2017 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# Mariko GODA <EMAIL@ADDRESS>, 2017.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-07-15 21:41+0900\n"
"PO-Revision-Date: 2017-09-18 21:19+0900\n"
"Last-Translator: Mariko GODA <EMAIL@ADDRESS>\n"
"Language-Team: Japanese\n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"

#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:48
#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:50
#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:55
msgid "Show specified tag values next to objects"
msgstr "指定したタグの値をオブジェクトの隣に表示します"

#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:92
msgid "Your QuickLabel config is applied."
msgstr "QuickLabelの設定が適用されました"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:126
msgid "Restore default"
msgstr "デフォルトに戻す"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:190
msgid "Move up"
msgstr "1つ上に"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:191
msgid "Move down"
msgstr "1つ下に"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:244
msgid "Main"
msgstr "メイン"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:245
msgid "Sub"
msgstr "サブ"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:257
msgid ""
"<html>Tags to show next to objects.<br>You can specify multiple tags by "
"writing into multiple lines<br>in the order of descending priorities.</html>"
msgstr ""
"<html>オブジェクトの隣に表示するタグを指定します。<br>複数のタグを指定するこ"
"ともできます。優先順位順に1行ずつ記入してください。</html>"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:259
msgid ""
"<html>Label format will be \"<b><i>Main</i>(<i>Sub</i>)</b>\" or "
"\"<b><i>Sub</i></b>\" if main tag is empty.</html>"
msgstr ""
"<html>ラベルのフォーマットは \"<b><i>メイン</i>(<i>サブ</i>)</b>\" になりま"
"す。<br>メインのタグがない場合は \"<b><i>サブ</i></b>\" になります。</html>"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:280
msgid "Show key-value pairs"
msgstr "キーと値を両方表示する"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:281
msgid "Always show sub tag with parentheses"
msgstr "サブのタグを必ず括弧に入れて表示する"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:282
msgid "Apply on startup"
msgstr "起動時に適用する"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:284
msgid "Apply"
msgstr "適用"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:285
msgid "Apply change and show customized labels"
msgstr "内容を適用し、カスタマイズしたラベルを表示する"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:293
msgctxt "quicklabel"
msgid "Reset"
msgstr "通常表示に戻す"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:294
msgid "Reset QuickLabel config and show default labels"
msgstr "QuickLabelで設定した内容をリセットし、通常の表示に戻す"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:302
msgid "Cancel"
msgstr "キャンセル"

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:303
msgid "Close this window without saving"
msgstr "セーブせずにこのウィンドウを閉じる"

#~ msgid "Sub labels"
#~ msgstr "サブ"
97 changes: 97 additions & 0 deletions i18n/messages.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-07-15 21:41+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:48
#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:50
#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:55
msgid "Show specified tag values next to objects"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelPlugin.java:92
msgid "Your QuickLabel config is applied."
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:126
msgid "Restore default"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:190
msgid "Move up"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:191
msgid "Move down"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:244
msgid "Main"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:245
msgid "Sub"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:257
msgid ""
"<html>Tags to show next to objects.<br>You can specify multiple tags by "
"writing into multiple lines<br>in the order of descending priorities.</html>"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:259
msgid ""
"<html>Label format will be \"<b><i>Main</i>(<i>Sub</i>)</b>\" or "
"\"<b><i>Sub</i></b>\" if main tag is empty.</html>"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:280
msgid "Show key-value pairs"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:281
msgid "Always show sub tag with parentheses"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:282
msgid "Apply on startup"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:284
msgid "Apply"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:285
msgid "Apply change and show customized labels"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:293
msgctxt "quicklabel"
msgid "Reset"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:294
msgid "Reset QuickLabel config and show default labels"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:302
msgid "Cancel"
msgstr ""

#: src/org/maripo/josm/quicklabel/QuickLabelDialog.java:303
msgid "Close this window without saving"
msgstr ""
2 changes: 2 additions & 0 deletions i18n_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
perl ../../i18n/i18n.pl --basedir=data --potfile=i18n/messages.po i18n/en.po i18n/ja.po
11 changes: 11 additions & 0 deletions i18n_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
find . -name '*.java' | xargs xgettext -k -ktrc:1c,2 -kmarktrc:1c,2 -ktr -kmarktr -ktrn:1,2 -ktrnc:1c,2,3
mv -f messages.po i18n
# Backup
cd i18n
mv -f ja.po ja.po.prev
mv -f en.po en.po.prev
msgmerge ja.po.prev messages.po -o ja.po
msgmerge en.po.prev messages.po -o en.po
cd -
echo 'Edit i18n/*.po and exec i18n_deploy.sh'
15 changes: 7 additions & 8 deletions src/org/maripo/josm/quicklabel/config/QuickLabelConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import sun.misc.Unsafe;

import org.maripo.josm.quicklabel.strategy.QuickLabelCompositionStrategy;
import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy;
Expand Down Expand Up @@ -89,16 +90,14 @@ private void setStrategy(LabelCompositionStrategy strategy) {
System.out.println("QuickLabelConfig.setStrategy " + strategy);
TextLabel.AUTO_LABEL_COMPOSITION_STRATEGY.toString();
try {

Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
Unsafe unsafe = (Unsafe) unsafeField.get(null);

Field field = TextLabel.class.getDeclaredField("AUTO_LABEL_COMPOSITION_STRATEGY");
field.setAccessible(true);
// Remove "final" modifier from AUTO_LABEL_COMPOSITION_STRATEGY
// TODO: java.lang.NoSuchFieldException: modifiers
Field modifierField = Field.class.getDeclaredField("modifiers");
modifierField.setAccessible(true);
modifierField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
// Replace!
field.set(null, strategy);
unsafe.putObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field), strategy);

} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
Expand Down

0 comments on commit 681419e

Please sign in to comment.