Return-Path: Delivered-To: apmail-pivot-user-archive@www.apache.org Received: (qmail 79232 invoked from network); 28 Jan 2011 12:17:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Jan 2011 12:17:10 -0000 Received: (qmail 17096 invoked by uid 500); 28 Jan 2011 12:17:10 -0000 Delivered-To: apmail-pivot-user-archive@pivot.apache.org Received: (qmail 16906 invoked by uid 500); 28 Jan 2011 12:17:07 -0000 Mailing-List: contact user-help@pivot.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@pivot.apache.org Delivered-To: mailing list user@pivot.apache.org Received: (qmail 16898 invoked by uid 99); 28 Jan 2011 12:17:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Jan 2011 12:17:07 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of schatela@gmail.com designates 209.85.210.182 as permitted sender) Received: from [209.85.210.182] (HELO mail-iy0-f182.google.com) (209.85.210.182) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Jan 2011 12:16:58 +0000 Received: by iyb26 with SMTP id 26so2552923iyb.13 for ; Fri, 28 Jan 2011 04:16:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=SJOa0UXl/4oj5zwNoe5vSfZpKtQJfY/qu7WwJ3oyuqA=; b=A5qIcky63ODHjdU2/AII/iXwrK2JR+B6aYTi9NiEumVunpLp7liM2yBlDvQrncXfI1 yg93EbW218G2sv7WZHySQFeWNzd+n3+RvppE0FqBo755Zk09w2HK9EoC5gHw2phpiJvB bgmuQHc0pdF8sFIqR2HyGhckULwYNYQfRmRoI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=ZfHgPRXB22WfeprmWqcBcZtdj+U/PsrvLPHvlmcyQpKKHlGwBooW6X7USmpBFdLJCl sFmCAUHnW0EtWai2ZMCjq8AvOcjL+oNNJj5jOj3pCuLYxHOW21D+LLbatprxQ3CQPjW0 UQxJfpTYRIBGla/mlmwO8bOaN/1HWBS7jVTDM= MIME-Version: 1.0 Received: by 10.42.172.198 with SMTP id o6mr2112942icz.132.1296216997007; Fri, 28 Jan 2011 04:16:37 -0800 (PST) Received: by 10.42.226.196 with HTTP; Fri, 28 Jan 2011 04:16:36 -0800 (PST) In-Reply-To: References: <6EF92659-6D7A-427A-A1DA-DCB7D7AAB88F@verizon.net> <975FFF6E-20E9-40D8-BE3D-2E48F6ACCA2F@verizon.net> Date: Fri, 28 Jan 2011 13:16:36 +0100 Message-ID: Subject: Re: Change application locale after startup From: Simon Chatelain To: user@pivot.apache.org Content-Type: multipart/alternative; boundary=90e6ba6e837ca88f80049ae70944 X-Virus-Checked: Checked by ClamAV on apache.org --90e6ba6e837ca88f80049ae70944 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Ah ok, I see. I was thinking that maybe there was a more subtle way of doing that. Something like: private Window window =3D null; private BXMLSerializer bxmlSerializer =3D null; public void startup() { Resources resources =3D new Resources(getClass().getName(), Locale.getDefault()); bxmlSerializer =3D new BXMLSerializer(); window =3D (Window)bxmlSerializer.readObject(Localization.class.getResource("my_window= .bxml"), resources); window.open(display); } private void setLocale(String lang) { Locale.setDefault(new Locale(lang)); Resources resources =3D new Resources(getClass().getName(), Locale.getDefault()); bxmlSerializer.Update/Reload(resources); } In fact the current state of my test application looks like : public class Main implements Application { Window myWindow =3D new Window(); public static void main(String[] args) { DesktopApplicationContext.main(Main.class, args); } private void setLanguage(String lang) { Locale locale =3D new Locale(lang); Locale.setDefault(locale); loadUI(); } private void loadUI() { try { Resources resources =3D new Resources(getClass().getName(), Locale.getDefault()); BXMLSerializer bxmlSerializer =3D new BXMLSerializer(); TabPane l_TabPane =3D (TabPane) bxmlSerializer.readObject( Main.class.getResource("ContainerView.bxml"), resources); myWindow.setContent(l_TabPane); } catch (Exception _Ex) { _Ex.printStackTrace(); } } @Override public void startup(Display _Display, Map _Properties) throws Exception { loadUI(); myWindow.setMaximized(true); myWindow.open(_Display); } } It works to update localized strings but even if it is easy to reload all data displayed in the UI by using data binding after reloading the bxml file, I will loose the state of the UI (split ratio of splitters, selected tab in a tab pane, etc.). Anyway, thank you for your answer. Simon On Thu, Jan 27, 2011 at 4:05 PM, Greg Brown wrote: > I need to implement a dynamic localization in my application, meaning the > user must be able to click on a button in some kind of toolbar and the UI > must change directly to display all texts in the chosen language without > restarting the application. > > ... > > So I go back to the localization feature and found on the mailing list th= e > question of Joao Neves, and the answer of Greg Brown saying > >If you define your UI in BXML, you can just reload it after you change t= he > locale. > That seems interesting but I do not understand how to =93reload the UI=94= ; if > someone could post a little code snippet showing how to do that, that wou= ld > be great. > > > I don't think there is an example that demonstrates how to do this, but t= he > idea is pretty simple. Let's say you have a main Window defined in > my_window.bxml. Your application loads this window in startup() and store= s a > reference to it. When you want to apply a locale change, you can reload > my_window.bxml using the Resources loaded from the new locale. > > You might be able to do this by calling shutdown() and startup() on the > application yourself. I haven't tried it but it might be worth a shot. > > G > > > --90e6ba6e837ca88f80049ae70944 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Ah ok, I see.

I was thinking that maybe there was a more subtle way = of doing that.
Something like:

=A0=A0=A0 private Window window = =3D null;
=A0=A0=A0 private BXMLSerializer bxmlSerializer =3D null;
= =A0=A0=A0
=A0=A0=A0 public void startup()=A0 {
=A0=A0=A0=A0=A0=A0=A0 Resources resources =3D new Resources(getClass().getN= ame(), Locale.getDefault());
=A0
=A0=A0=A0=A0=A0=A0=A0 bxmlSerializer= =3D new BXMLSerializer();
=A0=A0=A0=A0=A0=A0=A0 window =3D (Window)bxml= Serializer.readObject(Localization.class.getResource("my_window.bxml&q= uot;), resources);
=A0=A0=A0=A0=A0=A0=A0 window.open(display);
=A0=A0=A0 }
=A0=A0=A0 pri= vate void setLocale(String lang) {
=A0=A0=A0 =A0=A0=A0 Locale.setDefault= (new Locale(lang));
=A0=A0=A0 =A0=A0=A0 Resources resources =3D new Reso= urces(getClass().getName(), Locale.getDefault());
=A0=A0=A0 =A0=A0=A0 bxmlSerializer.Update/Reload(resources);
=A0=A0=A0 }=

In fact the current state of my test application looks like :
public class Main implements Application {

=A0=A0=A0 Window myWind= ow =3D new Window();

=A0=A0=A0 public static void main(String[] args) {
=A0=A0=A0 =A0=A0= =A0 DesktopApplicationContext.main(Main.class, args);
=A0=A0=A0 }
=A0=A0=A0 private void setLanguage(String lang) {
=A0=A0=A0 =A0=A0=A0 L= ocale locale =3D new Locale(lang);
=A0=A0=A0 =A0=A0=A0 Locale.setDefault= (locale);
=A0=A0=A0 =A0=A0=A0 loadUI();
=A0=A0=A0 }

=A0=A0=A0 private void = loadUI() {
=A0=A0=A0 =A0=A0=A0 try {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Re= sources resources =3D new Resources(getClass().getName(),
=A0=A0=A0 =A0= =A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Locale.getDefault());
=A0=A0=A0 =A0= =A0=A0 =A0=A0=A0 BXMLSerializer bxmlSerializer =3D new BXMLSerializer(); =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 TabPane l_TabPane =3D (TabPane) bxmlSerialize= r.readObject(
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Main.cla= ss.getResource("ContainerView.bxml"), resources);
=A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 myWindow.setContent(l_TabPane);

=A0=A0=A0 =A0=A0= =A0 } catch (Exception _Ex) {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 _Ex.printStackTrace();
=A0=A0=A0 =A0=A0=A0= }
=A0=A0=A0 }

=A0=A0=A0 @Override
=A0=A0=A0 public void start= up(Display _Display, Map<String, String> _Properties)
=A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 throws Exception {

=A0=A0=A0 =A0=A0=A0 loadUI();=
=A0=A0=A0 =A0=A0=A0 myWindow.setMaximized(true);
=A0=A0=A0 =A0=A0=A0 myW= indow.open(_Display);
=A0=A0=A0 }
}

It works to update localiz= ed strings but even if it is easy to reload all data displayed in the UI by= using data binding after reloading the bxml file, I will loose the state o= f the UI (split ratio of splitters, selected tab in a tab pane, etc.).

Anyway, thank you for your answer.

Simon

On Thu, Jan 27, 2011 at 4:05 PM, Greg Brown &l= t;gk_brown@verizo= n.net> wrote:
I need to imp= lement a dynamic localization in my application, meaning the user must be a= ble to click on a button in some kind of toolbar and the UI must change dir= ectly to display all texts in the chosen language without restarting the ap= plication.
...
So I go back to the localization feature= and found on the mailing list the question of Joao Neves, and the answer o= f Greg Brown saying
>If you define your UI in BXML, you can just reload it after you change = the locale.
That seems interesting but I do not understand how to =93rel= oad the UI=94; if someone could post a little code snippet showing how to d= o that, that would be great.

I don't think there is an example tha= t demonstrates how to do this, but the idea is pretty simple. Let's say= you have a main Window defined in my_window.bxml. Your application loads t= his window in startup() and stores a reference to it. When you want to appl= y a locale change, you can reload my_window.bxml using the Resources loaded= from the new locale.

You might be able to do this by calling shutdown() and = startup() on the application yourself. I haven't tried it but it might = be worth a shot.

G



--90e6ba6e837ca88f80049ae70944--