branding & internationalization with the netbeans platform

30
NetBeans Rich Client Platform Branding & Internationalisation NetBeans Rich Client Platform Branding & Internationalisation Anton Epple Eppleton IT Consulting

Upload: toni-epple

Post on 12-Jun-2015

10.047 views

Category:

Technology


5 download

DESCRIPTION

How to brand and localize your NetBeans Platform application, including some tipps on how to change language on the fly and how to make your application accessible.

TRANSCRIPT

Page 1: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

NetBeans Rich Client PlatformBranding & Internationalisation

Anton EppleEppleton IT Consulting

Page 2: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Agenda

InternationalisationBranding

Accessibility

Page 3: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

Internationalisable Resources:

String values in source files

String values in manifest

Help pages

Graphics

Files

Layer.xml ( e.g. Folders)

Page 4: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

NbBundle:

Similar to java.util.PropertyResourceBundle

Extends the functionality of the default Java resource support

Better Integration with Module System (multiple classloaders)

nbresloc protocol for localized files

Page 5: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

Text constants in Source Files:

Special ResourceBundle: NbBundle

Bundle.properties File in package:

Call from Java:

CTL_MyTopComponent = My WindowNachricht_Parameter = This is my {0}. Window

ResourceBundle bundle = NbBundle.getBundle(MyTopComponent.class);String msg = bundle.getString(„CTL_MyTopComponent“);// oderString msg = NbBundle.getMessage(MyTopComponent.class, „CTL_MyTopComponent“);// bis zu 3 Einzel ParameterString msg = NbBundle.getMessage(MyTopComponent.class, „Nachricht_Parameter“, New Integer(3));

Page 6: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

Externalize String Constants to .properties Files

Tools → Internationalization → Internationalization Wizard

Page 7: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

String values in manifests

Manifest file:

Bundle.properties:

Bundle_de.properties Datei:

Manifest-Version: 1.0OpenIDE-Module: de.eppleton.languageOpenIDE-Module-Localizing-Bundle: de/eppleton/language/Bundle.properties

OpenIDE-Module-Name=Language Switch

OpenIDE-Module-Name=Sprach Wechsel

Page 8: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

Search order:

Locale US:

1. Bundle_en_US.properties

2. Bundle_en.properties

3. Bundle.properties

Page 9: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

Other Resources:

Help Pages: Attach locale-extension ( _de ) to resources (html files, etc.)

Load graphics via localised String, or use extension (icon.gif, icon_de.gif):

System FileSystem (Menu):

Folder Attribute SystemFileSystem.localizingBundle

Image img = Utilities.loadImage(„resources/icon.gif“, true);

Page 10: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

nbresloc Protocol

Load localized Version of File:

Can load resources from all Modules:

also be used to reduce redundancy e.g. central repository for icons

URL u = new URL(„nbresloc:/de/eppleton/netbeans/modules/icon.png“);ImageIcon icon = newImageIcon(u);

Page 11: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

Bundling localization resources in Folder „locale“:

Example NetBeans platform9 Modules:

Page 12: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

Simplify Localization by externalizing defaults:

Translator sees only localizable resources:

Page 13: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

Localisation Bundles as Modules:

Localization can also be packaged as installable Plugin

User can install Language pack for his Locale:

http://www.sepix.de/blogs/blogrittner/blog/archive/2008/august/07/beandev_platform_uebersetzung_als_plugin/index.html

http://blogs.kiyut.com/tonny/2008/08/06/netbeans-platform-localization-as-plugins/

Page 14: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

OmegaT Translation Tool:

http://sf.net/projects/omegat/http://translatedfiles.netbeans.org/docs/HOWTOs/How-to-translate-NetBeans-using-OmegaT.html

Page 15: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

Change language on-the-fly (1): MenuItems

Not officially supported (but useful for Support → zh_CN)

but most MenuItems react to changing Locale:

Some don't (SaveAsAction):

public String getName() { return NbBundle.getMessage(SaveAction.class, "Save"); }

AbstractAction instance = Lookups.forPath("Actions/System").lookup(AbstractAction.class);instance.putValue(Action.NAME, NbBundle.getMessage(DataObject.class, "CTL_SaveAsAction"));

Page 16: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

Change language on-the-fly (2): Menus

1. Possibility: MenuBarFrame main = WindowManager.getDefault().getMainWindow();assert main != null;if (main instanceof JFrame) { Component [] c = ((Jframe)main).getJMenuBar().getComponents(); [....](Jmenu)c[i].setText(„internationalisiert...“); } // Error-prone...

Page 17: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding & Internationalisation

2. Possibility: Force Refresh

Demo

FileSystem sfs = Repository.getDefault().getDefaultFileSystem();FileObject menus = sfs.findResource("Menu"); FileObject[] children = menus.getChildren(); for (int i = 0; i < children.length; i++) { FileObject fileObject = children[i]; FileLock lock = null; try { lock = fileObject.lock(); String oldname= fileObject.getName(); fileObject.rename(lock, File.createTempFile("bla", "bla").getName(), null); fileObject.rename(lock, oldname, null); } catch (FileAlreadyLockedException es) { } lock.releaseLock();}

Page 18: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Agenda

InternationalisationBranding

Accessibility

Page 19: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Einfaches Branding einer Anwendung

Properties Dialog:

Page 20: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Basic Branding

Properties Dialog:

Page 21: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Basic Branding

Properties Dialog:

Page 22: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Replacing Icons

Find Resources:

Use „This layer in context“ to find module of an Action

Identify Icon Path in Source Files

Put in Suite's branding Folder

in a folder named like the module

JAR, under the same package:

Page 23: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Replacing Icons

Even Icons that don't exist in the original can be „replaced“ for a better Look & Feel

Example add rollover or disabled icons:

Page 24: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Replacing Icons

Picture Formats

What to do when your Icon collection has different Picture Format (e.g. gif instead png required)?

Rename your image.png to image.gif

No conversion needed

Page 25: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding von Texten

Branding token:

Page 26: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Branding Strings

Branding token is used in addition to locale

Resources stored in „locale“ folder

Search order example, Locale US:

1. Bundle_token_en_US.properties

2. Bundle_token_en.properties

3. Bundle_token.properties

4. Bundle_en_US.properties

5. Bundle_en.properties

6. Bundle.properties

Page 27: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Look & Feel

Dynamically changing Swing L&F at Runtime

Need to get Hold of Application Frame:UIManager.setLookAndFeel(new MetalLookAndFeel());

Frame frame = WindowManager.getDefault().getMainWindow();

SwingUtilities.updateComponentTreeUI(frame);

frame.pack();

UIDelegates need (e.g. Tabs) to be available or created for Third-party L&F (e.g. Synthetica, Substance)

Page 28: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Agenda

InternationalisationBranding

Accessibility

Page 29: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Accessibility

Resources:

http://a11y.netbeans.org/

a11y Checker Module:

This module checks designed forms online, in design time.

Provides sortable error list

Highlights affected components

Assists with fixes

Cooperates with i18n

Page 30: Branding & Internationalization with the NetBeans Platform

NetBeans Rich Client Platform

Accessibility