Skip to content

Commit 4310739

Browse files
committed
minor reformating and cleanup
1 parent 3015798 commit 4310739

8 files changed

+51
-66
lines changed

src/main/java/org/openstreetmap/josm/plugins/scripting/ui/EditorPaneBuilder.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
import javax.swing.text.html.HTMLEditorKit;
55
import javax.swing.text.html.StyleSheet;
66
import java.awt.*;
7-
import java.text.MessageFormat;
87
import java.util.logging.Logger;
98

9+
import static java.text.MessageFormat.format;
10+
1011
public class EditorPaneBuilder {
1112
static private final String RESOURCE_NAME_STYLE_SHEET = "/css/default-editor-pane.css";
12-
static private final Logger logger =
13-
Logger.getLogger(EditorPaneBuilder.class.getName());
13+
static private final Logger logger = Logger.getLogger(EditorPaneBuilder.class.getName());
1414

1515
private static StyleSheet loadDefaultStyleSheet() {
16-
var styleSheet = new StyleSheet();
17-
final var styleSheetUri =
18-
EditorPaneBuilder.class.getResource(RESOURCE_NAME_STYLE_SHEET);
16+
final var styleSheet = new StyleSheet();
17+
final var styleSheetUri = EditorPaneBuilder.class.getResource(RESOURCE_NAME_STYLE_SHEET);
1918
if (styleSheetUri == null) {
20-
logger.warning(String.format(
21-
"failed to load default CSS style sheet from resource '%s'",
19+
logger.warning(format(
20+
"failed to load default CSS style sheet from resource ''{0}''",
2221
RESOURCE_NAME_STYLE_SHEET
2322
));
2423
return styleSheet;
@@ -34,8 +33,7 @@ private static StyleSheet loadDefaultStyleSheet() {
3433
* @return the info pane
3534
*/
3635
public static JEditorPane buildInfoEditorPane() {
37-
final JEditorPane jepInfo =
38-
new JEditorPane("text/html", null /* no text */);
36+
final JEditorPane jepInfo = new JEditorPane("text/html", null /* no text */);
3937
jepInfo.setOpaque(false);
4038
jepInfo.setEditable(false);
4139
final StyleSheet ss = loadDefaultStyleSheet();
@@ -44,15 +42,16 @@ public static JEditorPane buildInfoEditorPane() {
4442
// font used in labels
4543
final Font f = UIManager.getFont("Label.font");
4644
final String cssRuleFontFamily =
47-
"font-family: ''{0}'';font-size: {1,number}pt; font-weight: {2}; " +
48-
"font-style: {3};";
45+
"font-family: ''{0}'';font-size: {1,number}pt; font-weight: {2}; "
46+
+ "font-style: {3};";
4947
final String rule = "strong {" +
50-
MessageFormat.format(cssRuleFontFamily,
48+
format(cssRuleFontFamily,
5149
f.getName(),
5250
f.getSize(),
5351
"bold",
54-
f.isItalic() ? "italic" : "normal") +
55-
"}";
52+
f.isItalic() ? "italic" : "normal"
53+
)
54+
+ "}";
5655
ss.addRule(rule);
5756
final HTMLEditorKit kit = new HTMLEditorKit();
5857
kit.setStyleSheet(ss);

src/main/java/org/openstreetmap/josm/plugins/scripting/ui/LaunchRunScriptDialogAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public LaunchRunScriptDialogAction() {
2121
Shortcut.registerShortcut("scripting:runScript",
2222
tr("Scripting: Run a Script"), KeyEvent.VK_R,
2323
Shortcut.NONE // don't assign an action group, let
24-
// the user assign in the preferences
24+
// the user assign in the preferences
2525
), false, // don't register toolbar item
2626
"scripting:runScript", false // don't install adapters
2727
);

src/main/java/org/openstreetmap/josm/plugins/scripting/ui/RunScriptAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public List<ActionParameter<?>> getActionParameters() {
5050
@Override
5151
public void actionPerformed(ActionEvent evt, Map<String, Object> parameters) {
5252

53-
final String scriptFile = (String)parameters.getOrDefault(PARA_SCRIPTING_FILE_NAME, null);
53+
final String scriptFile = (String) parameters.getOrDefault(PARA_SCRIPTING_FILE_NAME, null);
5454
final String engineId = (String) parameters.getOrDefault(PARA_ENGINE_ID, null);
5555
if (scriptFile == null) {
5656
logger.warning(format("action doesn''t include parameter ''{0}''. Can''t execute script file.",

src/main/java/org/openstreetmap/josm/plugins/scripting/ui/RunScriptDialog.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ private JPanel buildInfoPanel() {
5656
JPanel pnl = new JPanel(new BorderLayout());
5757
HtmlPanel info = new HtmlPanel();
5858
info.setText(
59-
"<html>"
60-
+ tr("Select a script file and click on <strong>Run</strong>.")
61-
+ "</html>"
59+
"<html>"
60+
+ tr("Select a script file and click on <strong>Run</strong>.")
61+
+ "</html>"
6262
);
6363
pnl.add(info, BorderLayout.CENTER);
6464
return pnl;
@@ -74,7 +74,7 @@ private JPanel buildControlButtonPanel() {
7474
getRootPane().registerKeyboardAction(actRun,
7575
KeyStroke.getKeyStroke("ctrl ENTER"),
7676
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
77-
);
77+
);
7878
pnl.add(new JButton(new CancelAction()));
7979
final var helpAction = new ContextSensitiveHelpAction(HelpUtil.ht("/Plugin/Scripting#Run"));
8080
pnl.add(new JButton(helpAction));
@@ -86,7 +86,7 @@ private JPanel buildMacroFileInputPanel() {
8686

8787
JPanel filePnl = new JPanel(new GridBagLayout());
8888
GridBagConstraints gc = gbc().cell(0, 0).weight(0, 0).fillboth()
89-
.insets(3, 3, 3, 3).constraints();
89+
.insets(3, 3, 3, 3).constraints();
9090
filePnl.add(new JLabel(tr("File:")), gc);
9191

9292
cbScriptFile = new MostRecentlyRunScriptsComboBox(MostRecentlyRunScriptsModel.getInstance());
@@ -127,7 +127,7 @@ protected void build() {
127127
addWindowListener(new WindowAdapter() {
128128
@Override
129129
public void windowActivated(WindowEvent e) {
130-
cbScriptFile.requestFocusInWindow();
130+
cbScriptFile.requestFocusInWindow();
131131
}
132132
});
133133
}

src/main/java/org/openstreetmap/josm/plugins/scripting/ui/RunScriptService.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.util.Objects;
1818
import java.util.logging.Level;
1919
import java.util.logging.Logger;
20-
import java.util.stream.Collectors;
2120
import java.util.stream.Stream;
2221

2322
import static org.openstreetmap.josm.plugins.scripting.util.FileUtils.buildTextFileReader;
@@ -85,12 +84,11 @@ private Stream<ScriptEngineDescriptor> filterGraalVMEngines(
8584
final String mimeType) {
8685
return GraalVMFacadeFactory.isGraalVMPresent()
8786
? GraalVMFacadeFactory.getOrCreateGraalVMFacade()
88-
.getScriptEngineDescriptors()
89-
.stream()
90-
.filter(desc ->
91-
desc.getContentMimeTypes().contains(mimeType))
87+
.getScriptEngineDescriptors()
88+
.stream()
89+
.filter(desc -> desc.getContentMimeTypes().contains(mimeType))
9290
: Stream.empty();
93-
}
91+
}
9492

9593
/**
9694
* Determines the script engine to run the script in file <tt>file</tt>.
@@ -109,9 +107,9 @@ public ScriptEngineDescriptor deriveOrAskScriptEngineDescriptor(String fileName,
109107

110108
// the stream of suitable engines for a given mime type
111109
java.util.List<ScriptEngineDescriptor> engines = Stream.of(
112-
filterGraalVMEngines(mimeType),
113-
filterJSR223Engines(mimeType)
114-
).flatMap(desc -> desc).collect(Collectors.toList());
110+
filterGraalVMEngines(mimeType),
111+
filterJSR223Engines(mimeType)
112+
).flatMap(desc -> desc).toList();
115113

116114
// exactly one suitable engine found. Use it without prompting
117115
// the user.

src/main/java/org/openstreetmap/josm/plugins/scripting/ui/ScriptEngineCellRenderer.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
/**
1313
* Implements a list cell renderer for the list of scripting engines.
1414
*/
15-
public class ScriptEngineCellRenderer
16-
implements ListCellRenderer<ScriptEngineDescriptor> {
15+
public class ScriptEngineCellRenderer implements ListCellRenderer<ScriptEngineDescriptor> {
1716

1817
static public final String DISPLAYED_GRAAL_ENGINE_NAME = "GraalVM";
1918

@@ -23,13 +22,13 @@ static public String defaultEngineName(ScriptEngineDescriptor desc) {
2322
}
2423
return desc.getEngineName()
2524
.map(String::trim)
26-
.filter(s -> ! s.isEmpty())
25+
.filter(s -> !s.isEmpty())
2726
.orElse(tr("unknown"));
2827
}
2928

3029
private final JLabel lbl = new JLabel();
3130

32-
private String getDisplayName(ScriptEngineDescriptor descriptor){
31+
private String getDisplayName(ScriptEngineDescriptor descriptor) {
3332
if (descriptor == null) return tr("Select an engine");
3433
final String engineName = defaultEngineName(descriptor);
3534
final String languageName = descriptor.getLanguageName()
@@ -38,31 +37,25 @@ private String getDisplayName(ScriptEngineDescriptor descriptor){
3837
return tr("{1} (with engine {0})", engineName, languageName);
3938
}
4039

41-
private void addNameValuePairToToolTip(StringBuilder sb, String name,
42-
String value) {
43-
sb.append("<strong>").append(name).append("</strong> ")
44-
.append(value).append("<br>");
40+
private void addNameValuePairToToolTip(StringBuilder sb, String name, String value) {
41+
sb.append("<strong>").append(name).append("</strong> ").append(value).append("<br>");
4542
}
4643

4744
private String getTooltipText(ScriptEngineDescriptor descriptor) {
4845
if (descriptor == null) return "";
4946
final StringBuilder sb = new StringBuilder();
5047
sb.append("<html>");
5148
if (descriptor.getEngineName().isPresent()) {
52-
addNameValuePairToToolTip(sb, tr("Name:"),
53-
defaultEngineName(descriptor));
49+
addNameValuePairToToolTip(sb, tr("Name:"), defaultEngineName(descriptor));
5450
}
5551
if (descriptor.getEngineVersion().isPresent()) {
56-
addNameValuePairToToolTip(sb, tr("Version:"),
57-
descriptor.getEngineVersion().get());
52+
addNameValuePairToToolTip(sb, tr("Version:"), descriptor.getEngineVersion().get());
5853
}
5954
if (descriptor.getLanguageName().isPresent()) {
60-
addNameValuePairToToolTip(sb, tr("Language:"),
61-
descriptor.getLanguageName().get());
55+
addNameValuePairToToolTip(sb, tr("Language:"), descriptor.getLanguageName().get());
6256
}
6357
if (descriptor.getLanguageVersion().isPresent()) {
64-
addNameValuePairToToolTip(sb, tr("Language version:"),
65-
descriptor.getLanguageVersion().get());
58+
addNameValuePairToToolTip(sb, tr("Language version:"), descriptor.getLanguageVersion().get());
6659
}
6760
sb.append("<strong>").append(tr("MIME-Types:")).append("</strong> ");
6861
sb.append(String.join(", ", descriptor.getContentMimeTypes()));
@@ -71,8 +64,8 @@ private String getTooltipText(ScriptEngineDescriptor descriptor) {
7164
return sb.toString();
7265
}
7366

74-
private void renderColors(boolean selected, boolean enabled){
75-
if (!selected || !enabled){
67+
private void renderColors(boolean selected, boolean enabled) {
68+
if (!selected || !enabled) {
7669
lbl.setForeground(UIManager.getColor(enabled
7770
? "List.foreground"
7871
: "Label.disabledForeground"));
@@ -86,8 +79,7 @@ private void renderColors(boolean selected, boolean enabled){
8679
public ScriptEngineCellRenderer() {
8780
lbl.setOpaque(true);
8881
lbl.setBorder(BorderFactory.createEmptyBorder(1, 3, 1, 3));
89-
lbl.setIcon(ImageProvider.get("script-engine",
90-
ImageProvider.ImageSizes.SMALLICON));
82+
lbl.setIcon(ImageProvider.get("script-engine", ImageProvider.ImageSizes.SMALLICON));
9183
}
9284

9385
@Override

src/main/java/org/openstreetmap/josm/plugins/scripting/ui/ScriptErrorDialog.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ private JPanel buildTopPanel() {
1919
final JPanel pnl = new JPanel(new BorderLayout());
2020
final JEditorPane pane = EditorPaneBuilder.buildInfoEditorPane();
2121
final String infoTxt = "<html>" + tr(
22-
"An error occurred when executing a script. This is most likely " +
23-
"a bug in the script, and not in JOSM.<p>" +
24-
"Please get in touch with the script author before you file " +
25-
"a bug in JOSMs bug tracker."
22+
"An error occurred when executing a script. It is most likely "
23+
+ "caused by a bug in the script and not in JOSM.<p>"
24+
+ " Please get in touch with the script author before you file "
25+
+ "a bug in JOSM''s bug tracker."
2626
) + "</html>";
2727
pane.setText(infoTxt);
2828
pnl.add(pane, BorderLayout.CENTER);

src/main/java/org/openstreetmap/josm/plugins/scripting/ui/ScriptErrorViewer.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ protected JComponent buildViewerPanel() {
9393
final var fontSize = paneOutput.getFont().getSize();
9494
paneOutput.setFont(new Font(Font.MONOSPACED, Font.PLAIN, fontSize));
9595
final var editorScrollPane = new JScrollPane(paneOutput);
96-
editorScrollPane.setVerticalScrollBarPolicy(
97-
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
98-
editorScrollPane.setHorizontalScrollBarPolicy(
99-
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
96+
editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
97+
editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
10098
add(editorScrollPane, BorderLayout.CENTER);
10199
model.addPropertyChangeListener(new ErrorModelChangeListener());
102100
return editorScrollPane;
@@ -135,8 +133,7 @@ public void displayException(@Null Throwable exception) {
135133
return;
136134
}
137135
var builder = new StringBuilder();
138-
var scriptException =
139-
lookupCauseByExceptionType(exception, ScriptException.class);
136+
var scriptException = lookupCauseByExceptionType(exception, ScriptException.class);
140137

141138
if (scriptException != null) {
142139
builder.append(formatScriptException((ScriptException) scriptException));
@@ -148,7 +145,7 @@ public void displayException(@Null Throwable exception) {
148145
if (polyglotException != null) {
149146
builder.append(formatPolyglotException(polyglotException));
150147
}
151-
} catch(ClassNotFoundException e) {
148+
} catch (ClassNotFoundException e) {
152149
// ignore
153150
}
154151
} else {
@@ -175,9 +172,8 @@ private void refreshView() {
175172
}
176173

177174
protected @Null Throwable lookupCauseByExceptionType(Throwable t, Class<?> clazz) {
178-
while(t != null) {
175+
while (t != null) {
179176
if (clazz.isInstance(t)) {
180-
// if (clazz.getName().equals(t.getClass().getName())) {
181177
break;
182178
}
183179
t = t.getCause();
@@ -201,7 +197,7 @@ protected String formatPolyglotException(@NotNull final Throwable exception) {
201197
class ErrorModelChangeListener implements PropertyChangeListener {
202198
@Override
203199
public void propertyChange(PropertyChangeEvent event) {
204-
if (! ScriptErrorViewerModel.PROP_ERROR.equals(event.getPropertyName())) {
200+
if (!ScriptErrorViewerModel.PROP_ERROR.equals(event.getPropertyName())) {
205201
return;
206202
}
207203
if (event.getNewValue() == null) {

0 commit comments

Comments
 (0)