From 83e8c95ea7d257166d350a59bfd81e9833ec14fd Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 5 Nov 2009 19:05:14 +0000 Subject: [#484] European Language support git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@535 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 27 ++++-- .../src/main/java/at/gv/egiz/bku/gui/BKUIcons.java | 57 ++++++++++++ .../at/gv/egiz/bku/gui/SecureViewerDialog.java | 98 ++++++++++++--------- .../at/gv/egiz/bku/gui/viewer/FontProvider.java | 40 +++++++++ .../egiz/bku/gui/viewer/FontProviderException.java | 29 ++++++ .../at/gv/egiz/bku/gui/Messages.properties | 2 +- .../at/gv/egiz/bku/gui/Messages_en.properties | 2 +- .../main/resources/at/gv/egiz/bku/gui/chip128.png | Bin 0 -> 7775 bytes .../main/resources/at/gv/egiz/bku/gui/chip16.png | Bin 0 -> 787 bytes .../main/resources/at/gv/egiz/bku/gui/chip24.png | Bin 0 -> 1227 bytes .../main/resources/at/gv/egiz/bku/gui/chip48.png | Bin 0 -> 2771 bytes 11 files changed, 205 insertions(+), 50 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUIcons.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProvider.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProviderException.java create mode 100644 BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip128.png create mode 100644 BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip16.png create mode 100644 BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip24.png create mode 100644 BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip48.png (limited to 'BKUCommonGUI/src/main') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java index e83502a8..8df4bd72 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java @@ -17,6 +17,8 @@ package at.gv.egiz.bku.gui; +import at.gv.egiz.bku.gui.viewer.FontProviderException; +import at.gv.egiz.bku.gui.viewer.FontProvider; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; import java.awt.Color; @@ -73,6 +75,7 @@ public class BKUGUIImpl implements BKUGUIFacade { protected HelpKeyListener helpKeyListener; protected SwitchFocusFocusListener switchFocusKeyListener; protected SecureViewerDialog secureViewer; + protected FontProvider fontProvider; protected Container contentPane; protected ResourceBundle messages; @@ -115,8 +118,9 @@ public class BKUGUIImpl implements BKUGUIFacade { */ public BKUGUIImpl(Container contentPane, Locale locale, - Style guiStyle, + Style guiStyle, URL background, + FontProvider fontProvider, ActionListener helpListener, SwitchFocusListener switchFocusListener) { this.contentPane = contentPane; @@ -139,7 +143,8 @@ public class BKUGUIImpl implements BKUGUIFacade { registerHelpListener(helpListener); registerSwitchFocusListener(switchFocusListener); - + + this.fontProvider = fontProvider; createGUI(background); } @@ -1386,7 +1391,12 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - showSecureViewer(dataToBeSigned.get(0)); + try { + showSecureViewer(dataToBeSigned.get(0)); + } catch (FontProviderException ex) { + log.error("failed to display secure viewer", ex); + showErrorDialog(ERR_VIEWER, new Object[] {ex.getMessage()}, backListener, backCommand); + } } }); @@ -1407,12 +1417,12 @@ public class BKUGUIImpl implements BKUGUIFacade { * @param saveListener * @param saveCommand */ - private void showSecureViewer(HashDataInput dataToBeSigned) { + private void showSecureViewer(HashDataInput dataToBeSigned) throws FontProviderException { log.debug("show secure viewer [" + Thread.currentThread().getName() + "]"); if (secureViewer == null) { secureViewer = new SecureViewerDialog(null, messages, - helpMouseListener.getActionListener()); + fontProvider, helpMouseListener.getActionListener()); // workaround for [#439] // avoid AlwaysOnTop at least in applet, otherwise make secureViewer AlwaysOnTop since MOCCA Dialog (JFrame created in LocalSTALFactory) is always on top. @@ -1485,7 +1495,12 @@ public class BKUGUIImpl implements BKUGUIFacade { int selectionIdx = lsm.getMinSelectionIndex(); if (selectionIdx >= 0) { final HashDataInput selection = signedReferences.get(selectionIdx); - showSecureViewer(selection); + try { + showSecureViewer(selection); + } catch (FontProviderException ex) { + log.error("failed to display secure viewer", ex); + showErrorDialog(ERR_VIEWER, new Object[] {ex.getMessage()}, backListener, backCommand); + } } } }); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUIcons.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUIcons.java new file mode 100644 index 00000000..92d6897b --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUIcons.java @@ -0,0 +1,57 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.gui; + +import java.awt.Image; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import javax.imageio.ImageIO; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class BKUIcons { + + protected static final Log log = LogFactory.getLog(BKUIcons.class); + + /** 16x16, 24x24, 32x32, 48x48, 128x128 pixels */ + public static final ArrayList icons = new ArrayList(); + + static { + String[] iconResources = new String[] { + "/at/gv/egiz/bku/gui/chip16.png", + "/at/gv/egiz/bku/gui/chip24.png", + "/at/gv/egiz/bku/gui/chip32.png", + "/at/gv/egiz/bku/gui/chip48.png", + "/at/gv/egiz/bku/gui/chip128.png" }; + for (String ir : iconResources) { + URL resource = BKUIcons.class.getResource(ir); + if (ir != null) { + try { + icons.add(ImageIO.read(resource)); + } catch (IOException ex) { + log.warn("failed to load mocca icon " + ir, ex); + } + } + } + } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java index ef70f94b..1883fce5 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.gui; +import at.gv.egiz.bku.gui.viewer.FontProvider; import at.gv.egiz.stal.HashDataInput; import java.awt.Container; import java.awt.Cursor; @@ -53,9 +54,12 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.LayoutStyle; import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.text.DefaultEditorKit; import javax.swing.text.Document; import javax.swing.text.EditorKit; import javax.swing.text.StyledEditorKit; +import javax.swing.text.html.HTMLEditorKit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -65,16 +69,20 @@ import org.apache.commons.logging.LogFactory; */ public class SecureViewerDialog extends JDialog implements ActionListener { - public static final String PLAINTEXT_FONT = "Monospaced"; + /** don't import BKUFonts in order not to load BKUFonts.jar + * BKUApplet includes BKUFonts as runtime dependency only, the jar is copied to the applet dir in BKUOnline with dependency-plugin + * BKUViewer has compile dependency BKUFonts, transitive in BKUOnline and BKULocal + */ + public static final String PLAINTEXT_FONT_RESOURCE = "DejaVuSansMono.ttf"; public static final Dimension VIEWER_DIMENSION = new Dimension(600, 400); protected static final Log log = LogFactory.getLog(SecureViewerDialog.class); - // private static SecureViewerDialog dialog; protected ResourceBundle messages; protected JEditorPane viewer; protected JLabel viewerLabel; protected JScrollPane scrollPane; protected HashDataInput content; //remember for save dialog + protected FontProvider fontProvider; /** * Create and display a modal SecureViewer dialog. @@ -97,10 +105,12 @@ public class SecureViewerDialog extends JDialog implements ActionListener { // dialog.setVisible(true); // } public SecureViewerDialog(Frame owner, ResourceBundle messages, -// ActionListener saveListener, String saveCommand, - ActionListener helpListener) { + // ActionListener saveListener, String saveCommand, + FontProvider fontProvider, ActionListener helpListener) { super(owner, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); + this.setIconImages(BKUIcons.icons); this.messages = messages; + this.fontProvider = fontProvider; initContentPane(VIEWER_DIMENSION, createViewerPanel(helpListener), @@ -135,7 +145,8 @@ public class SecureViewerDialog extends JDialog implements ActionListener { private JPanel createViewerPanel(final ActionListener helpListener) { viewer = new JEditorPane(); viewer.setEditable(false); - + viewer.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); + scrollPane = new JScrollPane(); JPanel viewerPanel = new JPanel(); @@ -167,31 +178,29 @@ public class SecureViewerDialog extends JDialog implements ActionListener { }); helpLabel.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent arg0) { - - if(arg0.getKeyCode() == KeyEvent.VK_ENTER) { - ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, BKUGUIFacade.HELP_HASHDATAVIEWER); - helpListener.actionPerformed(e); - } + @Override + public void keyPressed(KeyEvent arg0) { + + if (arg0.getKeyCode() == KeyEvent.VK_ENTER) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, BKUGUIFacade.HELP_HASHDATAVIEWER); + helpListener.actionPerformed(e); } - }); - + } + }); + helpLabel.addFocusListener(new FocusAdapter() { - - @Override - public void focusGained(FocusEvent e) { - - helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG_FOCUS))); - } - - @Override - public void focusLost(FocusEvent e) { - - helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); - } - - + + @Override + public void focusGained(FocusEvent e) { + + helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG_FOCUS))); + } + + @Override + public void focusLost(FocusEvent e) { + + helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); + } }); helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); @@ -216,9 +225,10 @@ public class SecureViewerDialog extends JDialog implements ActionListener { * @param hashDataInput */ - public void setContent(HashDataInput hashDataInput) { + public void setContent(HashDataInput hashDataInput) { //throws FontProviderException { this.content = null; + viewer.setText(null); String mimeType = hashDataInput.getMimeType(); if (mimeType == null) { @@ -228,20 +238,21 @@ public class SecureViewerDialog extends JDialog implements ActionListener { // loads editorkit for text/plain if unrecognized viewer.setContentType(mimeType); - if ("text/plain".equals(mimeType)) { - viewer.setEditorKit(new StyledEditorKit()); - viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); -// } else if ("text/html".equals(mimeType)) { -// viewer.setEditorKit(new RestrictedHTMLEditorKit()); - } else if ("application/xhtml+xml".equals(mimeType)) { - viewer.setContentType("text/html"); - } + try { + + if ("text/plain".equals(mimeType)) { + viewer.setEditorKit(new StyledEditorKit()); + viewer.setFont(fontProvider.getFont().deriveFont(Font.PLAIN, viewer.getFont().getSize())); + } else if ("application/xhtml+xml".equals(mimeType)) { + viewer.setEditorKit(new HTMLEditorKit()); + //reset font if fontprovider font was set before (TODO also html font from fontprovider) + viewer.setFont(new Font("Dialog", Font.PLAIN, viewer.getFont().getSize())); //UIManager.getFont("Label.font")); + } - EditorKit editorKit = viewer.getEditorKit(); - Document document = editorKit.createDefaultDocument(); -// document.putProperty("IgnoreCharsetDirective", new Boolean(true)); + EditorKit editorKit = viewer.getEditorKit(); + Document document = editorKit.createDefaultDocument(); + // document.putProperty("IgnoreCharsetDirective", new Boolean(true)); - try { Charset cs = (hashDataInput.getEncoding() == null) ? Charset.forName("UTF-8") : Charset.forName(hashDataInput.getEncoding()); log.debug("secure viewer encoding: " + cs.toString()); @@ -252,11 +263,14 @@ public class SecureViewerDialog extends JDialog implements ActionListener { this.content = hashDataInput; +// } catch (Exception ex) // fontProvider // } catch (IllegalCharsetNameException ex) { // } catch (UnsupportedCharsetException ex) { +// } catch (FontProviderException ex) { } catch (Exception ex) { log.error(ex.getMessage(), ex); String p = messages.getString(BKUGUIFacade.ERR_VIEWER); + viewer.setContentType("text/plain"); viewer.setText(MessageFormat.format(p, ex.getMessage())); } viewer.setCaretPosition(0); @@ -280,7 +294,7 @@ public class SecureViewerDialog extends JDialog implements ActionListener { closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); closeButton.setActionCommand("close"); closeButton.addActionListener(this); - + JButton saveButton = new JButton(); saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); saveButton.setActionCommand("save"); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProvider.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProvider.java new file mode 100644 index 00000000..8fb815b0 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProvider.java @@ -0,0 +1,40 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.gui.viewer; + +import java.awt.Font; + +/** + * + * @author Clemens Orthacker + */ +public interface FontProvider { + + /** will be replaced by more sophisticated font selection mechanism + * (see java.awt.Font int/String constants) */ + String SANSMONO_FONT_RESOURCE = "DejaVuLGCSansMono.ttf"; + + /** + * + * @return + * @throws InterruptedException + * @throws FileNotFoundException if remote font file cannot be retrieved + */ + Font getFont() throws FontProviderException; + +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProviderException.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProviderException.java new file mode 100644 index 00000000..5a6a277e --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProviderException.java @@ -0,0 +1,29 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.gui.viewer; + +/** + * Encapsulates the reason why a font could not be loaded. + * @author Clemens Orthacker + */ +public class FontProviderException extends Exception { + + public FontProviderException(String msg, Throwable cause) { + super(msg, cause); + } +} diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties index a96b835f..b458a214 100644 --- a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties +++ b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties @@ -86,7 +86,7 @@ error.test=Fehler1 {0} - Fehler2 {1} error.card.locked=B\u00FCrgerkarte ist gesperrt error.card.notactivated=Die B\u00FCrgerkarte ist nicht aktiviert error.pin.timeout=Zeit\u00FCberschreitung bei Eingabe der PIN -error.viewer=Der Inhalt kann nicht dargestellt werden: {0} +error.viewer=Der Inhalt kann nicht dargestellt werden: {0} error.external.link=Externer Link {0} wird nicht ge\u00F6ffnet error.config=Fehlerhafte Konfiguration des Systems: {0} diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties index c795b3fa..22b9095c 100644 --- a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties +++ b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties @@ -84,7 +84,7 @@ error.test=Error1 {0} - Error2 {1} error.card.locked=Citizen card is locked error.card.notactivated=Citizen card not activated error.pin.timeout=Timeout during PIN entry -error.viewer=Failed to display contents: {0} +error.viewer=Failed to display contents: {0} error.external.link=Cannot open external link {0} error.config=Incorrect system configuration: {0} diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip128.png b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip128.png new file mode 100644 index 00000000..c36d8079 Binary files /dev/null and b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip128.png differ diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip16.png b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip16.png new file mode 100644 index 00000000..96b580e9 Binary files /dev/null and b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip16.png differ diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip24.png b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip24.png new file mode 100644 index 00000000..efd6dbeb Binary files /dev/null and b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip24.png differ diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip48.png b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip48.png new file mode 100644 index 00000000..491fbcac Binary files /dev/null and b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip48.png differ -- cgit v1.2.3