Skip to content

Commit

Permalink
Initial i18n system
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhocodes committed Apr 14, 2021
1 parent bb50980 commit 4b22da3
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 23 deletions.
33 changes: 18 additions & 15 deletions ui/src/main/java/org/adoptopenjdk/jitwatch/ui/main/JITWatchUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

import org.adoptopenjdk.jitwatch.compilation.codecache.CodeCacheEventWalker;
import org.adoptopenjdk.jitwatch.compilation.codecache.CodeCacheWalkerResult;
Expand Down Expand Up @@ -474,7 +476,7 @@ private void stopParsing()

comboParser.getSelectionModel().select(ParserType.fromString(parserProperty));

Button btnChooseWatchFile = new Button("Open Log");
Button btnChooseWatchFile = UserInterfaceUtil.createButton("OPEN_LOG");
btnChooseWatchFile.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -484,7 +486,8 @@ private void stopParsing()
}
});

btnStart = new Button("Start");
btnStart = UserInterfaceUtil.createButton("START");

btnStart.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand Down Expand Up @@ -514,7 +517,7 @@ private void stopParsing()
}
});

btnStop = new Button("Stop");
btnStop = UserInterfaceUtil.createButton("STOP");
btnStop.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -523,7 +526,7 @@ private void stopParsing()
}
});

btnConfigure = new Button("Config");
btnConfigure = UserInterfaceUtil.createButton("CONFIG");
btnConfigure.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -532,7 +535,7 @@ private void stopParsing()
}
});

btnTimeLine = new Button("Timeline");
btnTimeLine = UserInterfaceUtil.createButton("TIMELINE");
btnTimeLine.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -545,7 +548,7 @@ private void stopParsing()
}
});

btnHisto = new Button("Histo");
btnHisto = UserInterfaceUtil.createButton("HISTO");
btnHisto.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -558,7 +561,7 @@ private void stopParsing()
}
});

btnTopList = new Button("TopList");
btnTopList = UserInterfaceUtil.createButton("TOPLIST");
btnTopList.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -571,7 +574,7 @@ private void stopParsing()
}
});

btnCodeCacheTimeline = new Button("Cache");
btnCodeCacheTimeline = UserInterfaceUtil.createButton("CACHE");
btnCodeCacheTimeline.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -584,7 +587,7 @@ private void stopParsing()
}
});

btnNMethods = new Button("NMethods");
btnNMethods = UserInterfaceUtil.createButton("NMETHODS");
btnNMethods.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -600,7 +603,7 @@ private void stopParsing()
}
});

btnCompilerThreads = new Button("Threads");
btnCompilerThreads = UserInterfaceUtil.createButton("THREADS");
btnCompilerThreads.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -616,7 +619,7 @@ private void stopParsing()
}
});

btnTriView = new Button("TriView");
btnTriView = UserInterfaceUtil.createButton("TRIVIEW");
btnTriView.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -630,7 +633,7 @@ private void stopParsing()
}
});

btnReportSuggestions = new Button("Suggest");
btnReportSuggestions = UserInterfaceUtil.createButton("SUGGEST");
btnReportSuggestions.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -644,7 +647,7 @@ private void stopParsing()
}
});

btnReportEliminatedAllocations = new Button("-Allocs");
btnReportEliminatedAllocations = UserInterfaceUtil.createButton("ELIM_ALLOCS");
btnReportEliminatedAllocations.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -658,7 +661,7 @@ private void stopParsing()
}
});

btnReportOptimisedLocks = new Button("-Locks");
btnReportOptimisedLocks = UserInterfaceUtil.createButton("ELIM_LOCKS");
btnReportOptimisedLocks.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand All @@ -672,7 +675,7 @@ private void stopParsing()
}
});

btnSandbox = new Button("Sandbox");
btnSandbox = UserInterfaceUtil.createButton("SANDBOX");
btnSandbox.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.ResourceBundle;

import javafx.scene.control.Tooltip;
import org.adoptopenjdk.jitwatch.model.bytecode.BCAnnotationType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -32,6 +35,8 @@ public final class UserInterfaceUtil
{
private static final Logger logger = LoggerFactory.getLogger(UserInterfaceUtil.class);

public static final ResourceBundle LANG = ResourceBundle.getBundle("i18n.lang", Locale.getDefault());

// https://www.iconfinder.com/icons/173960/tick_icon#size=16
public static final Image IMAGE_TICK;

Expand All @@ -40,7 +45,7 @@ public final class UserInterfaceUtil
public static final String FONT_MONOSPACE_FAMILY;
public static final String FONT_MONOSPACE_SIZE;
public static final boolean ADD_CLOSE_DECORATION; // for fullscreen JavaFX
// systems
// systems

private UserInterfaceUtil()
{
Expand All @@ -56,6 +61,21 @@ private UserInterfaceUtil()
ADD_CLOSE_DECORATION = Boolean.getBoolean("addCloseDecoration");
}

public static Button createButton(String langKey)
{
Button button = new Button(LANG.getString(langKey));

String tooltipKey = langKey + "_tt";

if (LANG.containsKey(tooltipKey))
{
String toolTip = LANG.getString(tooltipKey);
button.setTooltip(new Tooltip(toolTip));
}

return button;
}

private static Image loadResource(String path)
{
InputStream inputStream = UserInterfaceUtil.class.getResourceAsStream(path);
Expand Down Expand Up @@ -86,8 +106,7 @@ public static Button getSnapshotButton(final Scene scene, final String filenameP

buttonSnapShot.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
@Override public void handle(ActionEvent e)
{
takeSnapShot(scene, filenamePrefix);
}
Expand Down Expand Up @@ -118,11 +137,8 @@ private static void takeSnapShot(Scene scene, String filenamePrefix)
Method methodFromFXImage = classSwingFXUtils.getMethod("fromFXImage",
new Class[] { javafx.scene.image.Image.class, java.awt.image.BufferedImage.class });

methodWrite.invoke(null,
new Object[] {
methodFromFXImage.invoke(null, new Object[] { imageSnap, null }),
"png",
new File(snapshotFilename) });
methodWrite.invoke(null, new Object[] { methodFromFXImage.invoke(null, new Object[] { imageSnap, null }), "png",
new File(snapshotFilename) });
}
catch (Throwable t)
{
Expand Down
30 changes: 30 additions & 0 deletions ui/src/main/resources/i18n/lang.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
SANDBOX=Sandbox
SANDBOX_tt=Experiment with JIT behaviour
OPEN_LOG=Open Log
OPEN_LOG_tt=Select LogCompilation file
START=Start
START_tt=Start Processing
STOP=Stop
STOP_tt=Stop Processing
CONFIG=Config
CONFIG_tt=Configure JITWatch
TIMELINE=Timeline
TIMELINE_tt=Timeline of compilation events
HISTO=Histo
HISTO_tt=Histogram of events
CACHE=Cache
CACHE_tt=Code cache usage
NMETHODS=NMethods
NMETHODS_tt=NMethod layout in the code cache
TOPLIST=Toplist
TOPLIST_tt=Compilation activity toplists
THREADS=Threads
THREADS_tt=Compiler thread activity
TRIVIEW=TriView
TRIVIEW_tt=Show source, bytecode, and assembly
SUGGEST=Suggest
SUGGEST_tt=JITWatch suggestions
ELIM_ALLOCS=-Allocs
ELIM_ALLOCS_tt=Eliminated heap allocations
ELIM_LOCKS=-Locks
ELIM_LOCKS_tt=Eliminated Locks
1 change: 1 addition & 0 deletions ui/src/main/resources/i18n/lang_cn.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
START=开始
1 change: 1 addition & 0 deletions ui/src/main/resources/i18n/lang_de.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
START=Start
1 change: 1 addition & 0 deletions ui/src/main/resources/i18n/lang_pl.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
START=Początek

0 comments on commit 4b22da3

Please sign in to comment.