X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTMessageBox.java;h=4c453790fbeff1f941b284e49903fe4bd2e59a2e;hb=615a0d99fd0aa4437116dd083147f9150d5e6527;hp=88acb8a4282c7d2e33d4fea1469de8581109df81;hpb=e16dda65585466c8987bd1efd718431450a96605;p=nikiroo-utils.git diff --git a/src/jexer/TMessageBox.java b/src/jexer/TMessageBox.java index 88acb8a..4c45379 100644 --- a/src/jexer/TMessageBox.java +++ b/src/jexer/TMessageBox.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2016 Kevin Lamonte + * Copyright (C) 2017 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -30,6 +30,7 @@ package jexer; import java.util.ArrayList; import java.util.List; +import java.util.ResourceBundle; import jexer.event.TKeypressEvent; import static jexer.TKeypress.*; @@ -38,7 +39,6 @@ import static jexer.TKeypress.*; * TMessageBox is a system-modal dialog with buttons for OK, Cancel, Yes, or * No. Call it like: * - *
*
* {@code * box = application.messageBox(title, caption, @@ -53,6 +53,15 @@ import static jexer.TKeypress.*; */ public class TMessageBox extends TWindow { + /** + * Translated strings. + */ + private static final ResourceBundle i18n = ResourceBundle.getBundle(TMessageBox.class.getName()); + + // ------------------------------------------------------------------------ + // Constants -------------------------------------------------------------- + // ------------------------------------------------------------------------ + /** * Message boxes have these supported types. */ @@ -78,16 +87,6 @@ public class TMessageBox extends TWindow { YESNOCANCEL }; - /** - * The type of this message box. - */ - private Type type; - - /** - * My buttons. - */ - private Listbuttons; - /** * Message boxes have these possible results. */ @@ -113,6 +112,20 @@ public class TMessageBox extends TWindow { NO }; + // ------------------------------------------------------------------------ + // Variables -------------------------------------------------------------- + // ------------------------------------------------------------------------ + + /** + * The type of this message box. + */ + private Type type; + + /** + * My buttons. + */ + private List buttons; + /** * Which button was clicked: OK, CANCEL, YES, or NO. */ @@ -127,6 +140,10 @@ public class TMessageBox extends TWindow { return result; } + // ------------------------------------------------------------------------ + // Constructors ----------------------------------------------------------- + // ------------------------------------------------------------------------ + /** * Public constructor. The message box will be centered on screen. * @@ -215,7 +232,7 @@ public class TMessageBox extends TWindow { setWidth(15); } buttonX = (getWidth() - 11) / 2; - buttons.add(addButton(" &OK ", buttonX, lineI, + buttons.add(addButton(i18n.getString("okButton"), buttonX, lineI, new TAction() { public void DO() { result = Result.OK; @@ -232,7 +249,7 @@ public class TMessageBox extends TWindow { setWidth(26); } buttonX = (getWidth() - 22) / 2; - buttons.add(addButton(" &OK ", buttonX, lineI, + buttons.add(addButton(i18n.getString("okButton"), buttonX, lineI, new TAction() { public void DO() { result = Result.OK; @@ -242,7 +259,7 @@ public class TMessageBox extends TWindow { ) ); buttonX += 8 + 4; - buttons.add(addButton("&Cancel", buttonX, lineI, + buttons.add(addButton(i18n.getString("cancelButton"), buttonX, lineI, new TAction() { public void DO() { result = Result.CANCEL; @@ -259,7 +276,7 @@ public class TMessageBox extends TWindow { setWidth(20); } buttonX = (getWidth() - 16) / 2; - buttons.add(addButton("&Yes", buttonX, lineI, + buttons.add(addButton(i18n.getString("yesButton"), buttonX, lineI, new TAction() { public void DO() { result = Result.YES; @@ -269,7 +286,7 @@ public class TMessageBox extends TWindow { ) ); buttonX += 5 + 4; - buttons.add(addButton("&No", buttonX, lineI, + buttons.add(addButton(i18n.getString("noButton"), buttonX, lineI, new TAction() { public void DO() { result = Result.NO; @@ -286,7 +303,7 @@ public class TMessageBox extends TWindow { setWidth(31); } buttonX = (getWidth() - 27) / 2; - buttons.add(addButton("&Yes", buttonX, lineI, + buttons.add(addButton(i18n.getString("yesButton"), buttonX, lineI, new TAction() { public void DO() { result = Result.YES; @@ -296,7 +313,7 @@ public class TMessageBox extends TWindow { ) ); buttonX += 5 + 4; - buttons.add(addButton("&No", buttonX, lineI, + buttons.add(addButton(i18n.getString("noButton"), buttonX, lineI, new TAction() { public void DO() { result = Result.NO; @@ -306,7 +323,8 @@ public class TMessageBox extends TWindow { ) ); buttonX += 4 + 4; - buttons.add(addButton("&Cancel", buttonX, lineI, + buttons.add(addButton(i18n.getString("cancelButton"), buttonX, + lineI, new TAction() { public void DO() { result = Result.CANCEL; @@ -331,6 +349,10 @@ public class TMessageBox extends TWindow { } } + // ------------------------------------------------------------------------ + // TWindow ---------------------------------------------------------------- + // ------------------------------------------------------------------------ + /** * Handle keystrokes. * @@ -389,7 +411,8 @@ public class TMessageBox extends TWindow { break; default: - throw new IllegalArgumentException("Invalid message box type: " + type); + throw new IllegalArgumentException("Invalid message box type: " + + type); } super.onKeypress(keypress);