From 616e06910051528674165319a1d6d161dff5859c Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 27 Mar 2009 17:33:11 +0000 Subject: 1.1-RC6 (pinpad, pinmgmt, secureviewer) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@323 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/gui/SecureViewerDialog.java | 371 +++++++++++++++++++++ 1 file changed, 371 insertions(+) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java') 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 new file mode 100644 index 00000000..6a16306b --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java @@ -0,0 +1,371 @@ +/* + * 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 at.gv.egiz.stal.HashDataInput; +import java.awt.Container; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.Charset; +import java.text.MessageFormat; +import java.util.ResourceBundle; +import javax.swing.GroupLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JEditorPane; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.LayoutStyle; +import javax.swing.SwingUtilities; +import javax.swing.text.Document; +import javax.swing.text.EditorKit; +import javax.swing.text.StyledEditorKit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class SecureViewerDialog extends JDialog implements ActionListener { + + public static final String PLAINTEXT_FONT = "Monospaced"; + 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 + + /** + * Create and display a modal SecureViewer dialog. + * This method blocks until the dialog's close button is pressed. + * + * @param owner, dialog is positioned relative to its owner + * (if null, at default location of native windowing system) + */ +// public static void showDataToBeSigned(HashDataInput dataToBeSigned, +// ResourceBundle messages, +// ActionListener saveListener, String saveCommand, +// ActionListener helpListener) { +// +//// Frame ownerFrame = (owner != null) ? +//// JOptionPane.getFrameForComponent(owner) : +//// null; +// dialog = new SecureViewerDialog(null, messages, +// saveListener, saveCommand, helpListener); +// dialog.setContent(dataToBeSigned); +// dialog.setVisible(true); +// } + public SecureViewerDialog(Frame owner, ResourceBundle messages, +// ActionListener saveListener, String saveCommand, + ActionListener helpListener) { + super(owner, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); + this.messages = messages; + + initContentPane(VIEWER_DIMENSION, + createViewerPanel(helpListener), + createButtonPanel()); //saveListener, saveCommand)); + + pack(); + if (owner != null) { + setLocationRelativeTo(owner); + } else { + setLocationByPlatform(true); + } + } + + private void initContentPane(Dimension preferredSize, + JPanel viewerPanel, JPanel buttonPanel) { + Container contentPane = getContentPane(); + contentPane.setPreferredSize(preferredSize); + + GroupLayout mainLayout = new GroupLayout(contentPane); + contentPane.setLayout(mainLayout); + + mainLayout.setHorizontalGroup( + mainLayout.createSequentialGroup().addContainerGap().addGroup( + mainLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(viewerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()); + mainLayout.setVerticalGroup( + mainLayout.createSequentialGroup().addContainerGap().addComponent(viewerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addContainerGap()); + } + + /** + * @param helpListener may be null + */ + private JPanel createViewerPanel(final ActionListener helpListener) { + viewer = new JEditorPane(); + viewer.setEditable(false); + + scrollPane = new JScrollPane(); + + JPanel viewerPanel = new JPanel(); + GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); + viewerPanel.setLayout(viewerPanelLayout); + + GroupLayout.SequentialGroup infoHorizontal = viewerPanelLayout.createSequentialGroup(); + GroupLayout.ParallelGroup infoVertical = viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + + viewerLabel = new JLabel(); + viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); +// viewerLabel.setLabelFor(viewer); + + infoHorizontal.addComponent(viewerLabel); + infoVertical.addComponent(viewerLabel); + + if (helpListener != null) { + JLabel helpLabel = new JLabel(); + helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); + helpLabel.getAccessibleContext().setAccessibleName(messages.getString(BKUGUIFacade.ALT_HELP)); + helpLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent arg0) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, BKUGUIFacade.HELP_HASHDATAVIEWER); + helpListener.actionPerformed(e); + } + }); + helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + infoHorizontal.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE).addComponent(helpLabel); + infoVertical.addComponent(helpLabel); + } + + viewerPanelLayout.setHorizontalGroup( + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(infoHorizontal).addComponent(scrollPane)); + viewerPanelLayout.setVerticalGroup( + viewerPanelLayout.createSequentialGroup().addGroup(infoVertical).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(scrollPane)); + + return viewerPanel; + } + + /** + * Sets the hashdataInput to be displayed and makes the dialog visible. + * This method blocks until the dialog's close button is pressed. + * + * @param mimeType defaults to text/plain if null + * @param encoding must be null if document contains charset declaration (e.g. HTML page), otherwise the parser crashes + + * @param hashDataInput + */ + public void setContent(HashDataInput hashDataInput) { + + this.content = null; + + String mimeType = hashDataInput.getMimeType(); + if (mimeType == null) { + mimeType = "text/plain"; + } + log.debug("secure viewer mime type: " + mimeType); + // 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"); + } + + 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()); + + InputStreamReader isr = new InputStreamReader(hashDataInput.getHashDataInput(), cs); + Reader contentReader = new BufferedReader(isr); + viewer.read(contentReader, document); + contentReader.close(); + + this.content = hashDataInput; + +// } catch (IllegalCharsetNameException ex) { +// } catch (UnsupportedCharsetException ex) { + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + String p = messages.getString(BKUGUIFacade.ERR_VIEWER); + viewer.setText(MessageFormat.format(p, ex.getMessage())); + } + viewer.setCaretPosition(0); + + scrollPane.setViewportView(viewer); + scrollPane.setPreferredSize(viewer.getPreferredSize()); + scrollPane.setAlignmentX(LEFT_ALIGNMENT); + + if ("application/xhtml+xml".equals(mimeType)) { + viewerLabel.setText(messages.getString(BKUGUIFacade.WARNING_XHTML)); + } else { + viewerLabel.setText(""); + } + + setVisible(true); + } + + private JPanel createButtonPanel() { //ActionListener saveListener, String saveCommand) { + JButton closeButton = new JButton(); + 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"); + saveButton.addActionListener(this); + + int buttonSize = closeButton.getPreferredSize().width; + if (saveButton.getPreferredSize().width > buttonSize) { + buttonSize = saveButton.getPreferredSize().width; + } + + JPanel buttonPanel = new JPanel(); + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(saveButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(closeButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(closeButton)); + + return buttonPanel; + } + + @Override + public void actionPerformed(ActionEvent e) { + if ("close".equals(e.getActionCommand())) { +// SecureViewerDialog.dialog.setVisible(false); + log.trace("closing secure viewer"); + setVisible(false); + log.trace("secure viewer closed"); + } else if ("save".equals(e.getActionCommand())) { + log.trace("display secure viewer save dialog"); + showSaveDialog(content, null, null); + log.trace("done secure viewer save"); + } else { + log.warn("unknown action command " + e.getActionCommand()); + } + } + + private void showSaveDialog(final HashDataInput hashDataInput, + final ActionListener okListener, final String okCommand) { + + log.debug("scheduling save dialog [" + Thread.currentThread().getName() + "]"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show save dialog [" + Thread.currentThread().getName() + "]"); + + String userHome = System.getProperty("user.home"); + + JFileChooser fileDialog = new JFileChooser(userHome); + fileDialog.setMultiSelectionEnabled(false); + fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); + fileDialog.setFileHidingEnabled(true); + fileDialog.setDialogTitle(messages.getString(BKUGUIFacade.WINDOWTITLE_SAVE)); + fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); + String mimeType = hashDataInput.getMimeType(); + MimeFilter mimeFilter = new MimeFilter(mimeType, messages); + fileDialog.setFileFilter(mimeFilter); + String filename = messages.getString(BKUGUIFacade.SAVE_HASHDATAINPUT_PREFIX) + + MimeFilter.getExtension(mimeType); + fileDialog.setSelectedFile(new File(userHome, filename)); + + //parent contentPane -> placed over applet + switch (fileDialog.showSaveDialog(fileDialog)) { + case JFileChooser.APPROVE_OPTION: + File file = fileDialog.getSelectedFile(); + String id = hashDataInput.getReferenceId(); + if (file.exists()) { + String msgPattern = messages.getString(BKUGUIFacade.MESSAGE_OVERWRITE); + int overwrite = JOptionPane.showConfirmDialog(fileDialog, + MessageFormat.format(msgPattern, file), + messages.getString(BKUGUIFacade.WINDOWTITLE_OVERWRITE), + JOptionPane.OK_CANCEL_OPTION); + if (overwrite != JOptionPane.OK_OPTION) { + return; + } + } + if (log.isDebugEnabled()) { + log.debug("writing hashdata input " + id + " (" + mimeType + ") to file " + file); + } + FileOutputStream fos = null; + try { + fos = new FileOutputStream(file); + BufferedOutputStream bos = new BufferedOutputStream(fos); + InputStream hdi = hashDataInput.getHashDataInput(); + int b; + while ((b = hdi.read()) != -1) { + bos.write(b); + } + bos.flush(); + bos.close(); + } catch (IOException ex) { + log.error("Failed to write " + file + ": " + ex.getMessage()); + log.debug(ex); + String errPattern = messages.getString(BKUGUIFacade.ERR_WRITE_HASHDATA); + JOptionPane.showMessageDialog(fileDialog, + MessageFormat.format(errPattern, ex.getMessage()), + messages.getString(BKUGUIFacade.WINDOWTITLE_ERROR), + JOptionPane.ERROR_MESSAGE); + } finally { + try { + if (fos != null) { + fos.close(); + } + } catch (IOException ex) { + } + } + break; + case JFileChooser.CANCEL_OPTION: + log.debug("cancelled save dialog"); + break; + } + if (okListener != null) { + okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); + } + } + }); + } +} -- cgit v1.2.3 From 3b59e8f40dbddf0a752d39bb7d5c8bab86546205 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 2 Oct 2009 17:48:37 +0000 Subject: [#439], [#478] MOCCA Dialog is AlwaysOnTop (follow up for [#439]) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@518 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java | 1 + 1 file changed, 1 insertion(+) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java') 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 6a16306b..84c2a5ff 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 @@ -239,6 +239,7 @@ public class SecureViewerDialog extends JDialog implements ActionListener { } setVisible(true); + toFront(); } private JPanel createButtonPanel() { //ActionListener saveListener, String saveCommand) { -- cgit v1.2.3 From 4b8b858ddcab0bfbde80304a0f631233388a13d1 Mon Sep 17 00:00:00 2001 From: tzefferer Date: Fri, 16 Oct 2009 09:54:37 +0000 Subject: Keyboard accessibility for Online-BKU git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@528 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/gui/SecureViewerDialog.java | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java') 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 84c2a5ff..ef70f94b 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 @@ -24,6 +24,10 @@ import java.awt.Font; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.BufferedOutputStream; @@ -149,7 +153,8 @@ public class SecureViewerDialog extends JDialog implements ActionListener { infoVertical.addComponent(viewerLabel); if (helpListener != null) { - JLabel helpLabel = new JLabel(); + final JLabel helpLabel = new JLabel(); + helpLabel.setFocusable(true); helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); helpLabel.getAccessibleContext().setAccessibleName(messages.getString(BKUGUIFacade.ALT_HELP)); helpLabel.addMouseListener(new MouseAdapter() { @@ -159,6 +164,34 @@ public class SecureViewerDialog extends JDialog implements ActionListener { ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, BKUGUIFacade.HELP_HASHDATAVIEWER); helpListener.actionPerformed(e); } + }); + 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); + } + } + }); + + 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))); + } + + }); helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); -- cgit v1.2.3 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 --- .../at/gv/egiz/bku/gui/SecureViewerDialog.java | 98 ++++++++++++---------- 1 file changed, 56 insertions(+), 42 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java') 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"); -- cgit v1.2.3 From 5bb4d11327fcfe0fdc4234eeb02f4b09d108109e Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 9 Nov 2009 17:05:57 +0000 Subject: applet version BKUFonts .project git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@536 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java') 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 1883fce5..c0b14a85 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 @@ -321,11 +321,11 @@ public class SecureViewerDialog extends JDialog implements ActionListener { public void actionPerformed(ActionEvent e) { if ("close".equals(e.getActionCommand())) { // SecureViewerDialog.dialog.setVisible(false); - log.trace("closing secure viewer"); + log.trace(Thread.currentThread() + " closing secure viewer"); setVisible(false); log.trace("secure viewer closed"); } else if ("save".equals(e.getActionCommand())) { - log.trace("display secure viewer save dialog"); + log.trace(Thread.currentThread() + " display secure viewer save dialog"); showSaveDialog(content, null, null); log.trace("done secure viewer save"); } else { -- cgit v1.2.3 From caca721368d8c24559b1cd5ea2018884b4874f6b Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 10 Nov 2009 15:30:16 +0000 Subject: Removed switchFocusListener due to problem with viewer/help dialogs on Firefox/Mac git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@539 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java') 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 c0b14a85..878a998b 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 @@ -54,8 +54,6 @@ 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; @@ -73,7 +71,6 @@ public class SecureViewerDialog extends JDialog implements ActionListener { * 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; @@ -227,6 +224,8 @@ public class SecureViewerDialog extends JDialog implements ActionListener { */ public void setContent(HashDataInput hashDataInput) { //throws FontProviderException { + log.debug("[" + Thread.currentThread().getName() + "] set viewer content"); + this.content = null; viewer.setText(null); @@ -285,6 +284,7 @@ public class SecureViewerDialog extends JDialog implements ActionListener { viewerLabel.setText(""); } + log.debug("VIEWER FONT: " + viewer.getFont()); setVisible(true); toFront(); } @@ -320,12 +320,11 @@ public class SecureViewerDialog extends JDialog implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if ("close".equals(e.getActionCommand())) { -// SecureViewerDialog.dialog.setVisible(false); - log.trace(Thread.currentThread() + " closing secure viewer"); + log.trace("[" + Thread.currentThread().getName() + "] closing secure viewer"); setVisible(false); log.trace("secure viewer closed"); } else if ("save".equals(e.getActionCommand())) { - log.trace(Thread.currentThread() + " display secure viewer save dialog"); + log.trace("[" + Thread.currentThread().getName() + "] display secure viewer save dialog"); showSaveDialog(content, null, null); log.trace("done secure viewer save"); } else { @@ -336,14 +335,14 @@ public class SecureViewerDialog extends JDialog implements ActionListener { private void showSaveDialog(final HashDataInput hashDataInput, final ActionListener okListener, final String okCommand) { - log.debug("scheduling save dialog [" + Thread.currentThread().getName() + "]"); + log.debug("[" + Thread.currentThread().getName() + "] scheduling save dialog"); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - log.debug("show save dialog [" + Thread.currentThread().getName() + "]"); + log.debug("[" + Thread.currentThread().getName() + "] show save dialog"); String userHome = System.getProperty("user.home"); -- cgit v1.2.3 From b7dd29046e232e4d42623655efc28965cce942b8 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 13 Nov 2009 15:13:21 +0000 Subject: git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@546 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/gui/SecureViewerDialog.java | 146 +++++++-------------- 1 file changed, 51 insertions(+), 95 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java') 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 878a998b..7bae4673 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 @@ -17,12 +17,15 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.bku.gui.viewer.FontProvider; +import at.gv.egiz.bku.gui.viewer.FontProviderException; +import at.gv.egiz.bku.gui.viewer.SecureViewerSaveDialog; import at.gv.egiz.stal.HashDataInput; import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; +import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; @@ -41,6 +44,9 @@ import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.Charset; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; import java.util.ResourceBundle; import javax.swing.GroupLayout; import javax.swing.ImageIcon; @@ -72,6 +78,12 @@ public class SecureViewerDialog extends JDialog implements ActionListener { * BKUViewer has compile dependency BKUFonts, transitive in BKUOnline and BKULocal */ public static final Dimension VIEWER_DIMENSION = new Dimension(600, 400); + + public static final List SUPPORTED_MIME_TYPES = new ArrayList(); + static { + SUPPORTED_MIME_TYPES.add("text/plain"); + SUPPORTED_MIME_TYPES.add("application/xhtml+xml"); + } protected static final Log log = LogFactory.getLog(SecureViewerDialog.class); // private static SecureViewerDialog dialog; protected ResourceBundle messages; @@ -102,7 +114,7 @@ public class SecureViewerDialog extends JDialog implements ActionListener { // dialog.setVisible(true); // } public SecureViewerDialog(Frame owner, ResourceBundle messages, - // ActionListener saveListener, String saveCommand, + ActionListener closeListener, String closeCommand, FontProvider fontProvider, ActionListener helpListener) { super(owner, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); this.setIconImages(BKUIcons.icons); @@ -111,7 +123,7 @@ public class SecureViewerDialog extends JDialog implements ActionListener { initContentPane(VIEWER_DIMENSION, createViewerPanel(helpListener), - createButtonPanel()); //saveListener, saveCommand)); + createButtonPanel(closeListener, closeCommand)); pack(); if (owner != null) { @@ -289,15 +301,22 @@ public class SecureViewerDialog extends JDialog implements ActionListener { toFront(); } - private JPanel createButtonPanel() { //ActionListener saveListener, String saveCommand) { + private JPanel createButtonPanel(ActionListener closeListener, String closeCommand) { JButton closeButton = new JButton(); closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); - closeButton.setActionCommand("close"); - closeButton.addActionListener(this); + closeButton.setActionCommand(closeCommand); + closeButton.addActionListener(closeListener); + closeButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + log.trace("[" + Thread.currentThread().getName() + "] closing secure viewer"); + setVisible(false); + } + }); JButton saveButton = new JButton(); saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); - saveButton.setActionCommand("save"); + saveButton.setActionCommand("save"); //TODO ensure unequal to closeCommand saveButton.addActionListener(this); int buttonSize = closeButton.getPreferredSize().width; @@ -319,100 +338,37 @@ public class SecureViewerDialog extends JDialog implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - if ("close".equals(e.getActionCommand())) { - log.trace("[" + Thread.currentThread().getName() + "] closing secure viewer"); - setVisible(false); - log.trace("secure viewer closed"); - } else if ("save".equals(e.getActionCommand())) { + if ("save".equals(e.getActionCommand())) { log.trace("[" + Thread.currentThread().getName() + "] display secure viewer save dialog"); - showSaveDialog(content, null, null); + SecureViewerSaveDialog.showSaveDialog(content, messages, null, null); log.trace("done secure viewer save"); } else { log.warn("unknown action command " + e.getActionCommand()); } } + + +// //TEST +// private static SecureViewerDialog secureViewer; +// public static void showSecureViewerXXX(HashDataInput dataToBeSigned, ResourceBundle messages, FontProvider fontProvider, ActionListener helpListener, boolean alwaysOnTop) throws FontProviderException { +// +//// ResourceBundle messages = ResourceBundle.getBundle(BKUGUIFacade.MESSAGES_BUNDLE, locale); +// +// log.debug("[" + Thread.currentThread().getName() + "] show secure viewer"); +// if (secureViewer == null) { +// secureViewer = new SecureViewerDialog(null, messages, +// fontProvider, helpListener); +// +// // workaround for [#439] +// // avoid AlwaysOnTop at least in applet, otherwise make secureViewer AlwaysOnTop since MOCCA Dialog (JFrame created in LocalSTALFactory) is always on top. +//// Window window = SwingUtilities.getWindowAncestor(contentPane); +//// if (window != null && window.isAlwaysOnTop()) { +//// log.debug("make secureViewer alwaysOnTop"); +// secureViewer.setAlwaysOnTop(alwaysOnTop); +//// } +// } +// secureViewer.setContent(dataToBeSigned); +// log.trace("show secure viewer returned"); +// } - private void showSaveDialog(final HashDataInput hashDataInput, - final ActionListener okListener, final String okCommand) { - - log.debug("[" + Thread.currentThread().getName() + "] scheduling save dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("[" + Thread.currentThread().getName() + "] show save dialog"); - - String userHome = System.getProperty("user.home"); - - JFileChooser fileDialog = new JFileChooser(userHome); - fileDialog.setMultiSelectionEnabled(false); - fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); - fileDialog.setFileHidingEnabled(true); - fileDialog.setDialogTitle(messages.getString(BKUGUIFacade.WINDOWTITLE_SAVE)); - fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); - String mimeType = hashDataInput.getMimeType(); - MimeFilter mimeFilter = new MimeFilter(mimeType, messages); - fileDialog.setFileFilter(mimeFilter); - String filename = messages.getString(BKUGUIFacade.SAVE_HASHDATAINPUT_PREFIX) + - MimeFilter.getExtension(mimeType); - fileDialog.setSelectedFile(new File(userHome, filename)); - - //parent contentPane -> placed over applet - switch (fileDialog.showSaveDialog(fileDialog)) { - case JFileChooser.APPROVE_OPTION: - File file = fileDialog.getSelectedFile(); - String id = hashDataInput.getReferenceId(); - if (file.exists()) { - String msgPattern = messages.getString(BKUGUIFacade.MESSAGE_OVERWRITE); - int overwrite = JOptionPane.showConfirmDialog(fileDialog, - MessageFormat.format(msgPattern, file), - messages.getString(BKUGUIFacade.WINDOWTITLE_OVERWRITE), - JOptionPane.OK_CANCEL_OPTION); - if (overwrite != JOptionPane.OK_OPTION) { - return; - } - } - if (log.isDebugEnabled()) { - log.debug("writing hashdata input " + id + " (" + mimeType + ") to file " + file); - } - FileOutputStream fos = null; - try { - fos = new FileOutputStream(file); - BufferedOutputStream bos = new BufferedOutputStream(fos); - InputStream hdi = hashDataInput.getHashDataInput(); - int b; - while ((b = hdi.read()) != -1) { - bos.write(b); - } - bos.flush(); - bos.close(); - } catch (IOException ex) { - log.error("Failed to write " + file + ": " + ex.getMessage()); - log.debug(ex); - String errPattern = messages.getString(BKUGUIFacade.ERR_WRITE_HASHDATA); - JOptionPane.showMessageDialog(fileDialog, - MessageFormat.format(errPattern, ex.getMessage()), - messages.getString(BKUGUIFacade.WINDOWTITLE_ERROR), - JOptionPane.ERROR_MESSAGE); - } finally { - try { - if (fos != null) { - fos.close(); - } - } catch (IOException ex) { - } - } - break; - case JFileChooser.CANCEL_OPTION: - log.debug("cancelled save dialog"); - break; - } - if (okListener != null) { - okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); - } - } - }); - } } -- cgit v1.2.3 From 3da4655d011dfc2f04f9e4ac28b38aee42d01bc0 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 5 Jan 2010 10:06:47 +0000 Subject: Features [#437] Handle pinpad [64:03] response apdu correctly [#445] pin entry feedback for VERIFY_PIN_START/FINISH [#471] Provide SecureViewer Link before Pinpad PinEntry timeout starts Bugs [#479] PIN Managment Applet allows unmatching new pin and pin confirmation [#480] PIN Management displays blocked PINs as ACTIVE [#486] Not possible to select 3 times in series the same item from signedReferencesList for display in secureViewer [#506] change pin dialog (gui) issues [#508] e-card G3 PIN activation (with TransportPIN) not supported [#509] closing secure viewer window (WINDOW_CLOSING) leaves "signature data is displayed in viewer" dialog in applet git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@565 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/gui/SecureViewerDialog.java | 118 +++++++++------------ 1 file changed, 52 insertions(+), 66 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java') 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 7bae4673..7db70c46 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 @@ -17,7 +17,6 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.bku.gui.viewer.FontProvider; -import at.gv.egiz.bku.gui.viewer.FontProviderException; import at.gv.egiz.bku.gui.viewer.SecureViewerSaveDialog; import at.gv.egiz.stal.HashDataInput; import java.awt.Container; @@ -25,7 +24,6 @@ import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; -import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; @@ -34,32 +32,26 @@ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.io.BufferedOutputStream; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.Charset; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; -import java.util.Locale; import java.util.ResourceBundle; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JEditorPane; -import javax.swing.JFileChooser; import javax.swing.JLabel; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.LayoutStyle; -import javax.swing.SwingUtilities; +import javax.swing.WindowConstants; import javax.swing.text.Document; import javax.swing.text.EditorKit; import javax.swing.text.StyledEditorKit; @@ -71,7 +63,7 @@ import org.apache.commons.logging.LogFactory; * * @author Clemens Orthacker */ -public class SecureViewerDialog extends JDialog implements ActionListener { +public class SecureViewerDialog extends JDialog { /** 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 @@ -100,19 +92,6 @@ public class SecureViewerDialog extends JDialog implements ActionListener { * @param owner, dialog is positioned relative to its owner * (if null, at default location of native windowing system) */ -// public static void showDataToBeSigned(HashDataInput dataToBeSigned, -// ResourceBundle messages, -// ActionListener saveListener, String saveCommand, -// ActionListener helpListener) { -// -//// Frame ownerFrame = (owner != null) ? -//// JOptionPane.getFrameForComponent(owner) : -//// null; -// dialog = new SecureViewerDialog(null, messages, -// saveListener, saveCommand, helpListener); -// dialog.setContent(dataToBeSigned); -// dialog.setVisible(true); -// } public SecureViewerDialog(Frame owner, ResourceBundle messages, ActionListener closeListener, String closeCommand, FontProvider fontProvider, ActionListener helpListener) { @@ -125,6 +104,10 @@ public class SecureViewerDialog extends JDialog implements ActionListener { createViewerPanel(helpListener), createButtonPanel(closeListener, closeCommand)); + // also leave defaultWindowClosing HIDE_ON_CLOSE + this.addWindowListener(new WindowCloseListener(closeListener, closeCommand)); + this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + pack(); if (owner != null) { setLocationRelativeTo(owner); @@ -305,19 +288,11 @@ public class SecureViewerDialog extends JDialog implements ActionListener { JButton closeButton = new JButton(); closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); closeButton.setActionCommand(closeCommand); - closeButton.addActionListener(closeListener); - closeButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - log.trace("[" + Thread.currentThread().getName() + "] closing secure viewer"); - setVisible(false); - } - }); + closeButton.addActionListener(new CloseButtonListener(closeListener)); JButton saveButton = new JButton(); saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); - saveButton.setActionCommand("save"); //TODO ensure unequal to closeCommand - saveButton.addActionListener(this); + saveButton.addActionListener(new SaveButtonListener()); int buttonSize = closeButton.getPreferredSize().width; if (saveButton.getPreferredSize().width > buttonSize) { @@ -336,39 +311,50 @@ public class SecureViewerDialog extends JDialog implements ActionListener { return buttonPanel; } - @Override - public void actionPerformed(ActionEvent e) { - if ("save".equals(e.getActionCommand())) { + public class WindowCloseListener extends WindowAdapter { + + ActionListener closeListener; + String closeCommand; + + public WindowCloseListener(ActionListener closeListener, String closeCommand) { + this.closeListener = closeListener; + this.closeCommand = closeCommand; + } + + @Override + public void windowClosing(WindowEvent e) { + log.trace("[" + Thread.currentThread().getName() + "] closing secure viewer"); + setVisible(false); + if (closeListener != null) { + closeListener.actionPerformed(new ActionEvent(e.getSource(), e.getID(), closeCommand)); + } + } + } + + public class CloseButtonListener implements ActionListener { + + ActionListener closeListener; + + public CloseButtonListener(ActionListener closeListener) { + this.closeListener = closeListener; + } + + @Override + public void actionPerformed(ActionEvent e) { + log.trace("[" + Thread.currentThread().getName() + "] closing secure viewer"); + setVisible(false); + if (closeListener != null) { + closeListener.actionPerformed(e); + } + } + } + + public class SaveButtonListener implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { log.trace("[" + Thread.currentThread().getName() + "] display secure viewer save dialog"); SecureViewerSaveDialog.showSaveDialog(content, messages, null, null); - log.trace("done secure viewer save"); - } else { - log.warn("unknown action command " + e.getActionCommand()); } } - - -// //TEST -// private static SecureViewerDialog secureViewer; -// public static void showSecureViewerXXX(HashDataInput dataToBeSigned, ResourceBundle messages, FontProvider fontProvider, ActionListener helpListener, boolean alwaysOnTop) throws FontProviderException { -// -//// ResourceBundle messages = ResourceBundle.getBundle(BKUGUIFacade.MESSAGES_BUNDLE, locale); -// -// log.debug("[" + Thread.currentThread().getName() + "] show secure viewer"); -// if (secureViewer == null) { -// secureViewer = new SecureViewerDialog(null, messages, -// fontProvider, helpListener); -// -// // workaround for [#439] -// // avoid AlwaysOnTop at least in applet, otherwise make secureViewer AlwaysOnTop since MOCCA Dialog (JFrame created in LocalSTALFactory) is always on top. -//// Window window = SwingUtilities.getWindowAncestor(contentPane); -//// if (window != null && window.isAlwaysOnTop()) { -//// log.debug("make secureViewer alwaysOnTop"); -// secureViewer.setAlwaysOnTop(alwaysOnTop); -//// } -// } -// secureViewer.setContent(dataToBeSigned); -// log.trace("show secure viewer returned"); -// } - } -- cgit v1.2.3