From 32d17447a258188b2d534bcb0bf65a659ba7b7d0 Mon Sep 17 00:00:00 2001 From: mcentner Date: Fri, 29 Aug 2008 12:11:34 +0000 Subject: Initial import. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@1 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 909 +++++++++++++++++++++ .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 66 ++ .../java/at/gv/egiz/bku/gui/BKUGUIFactory.java | 32 + .../java/at/gv/egiz/bku/gui/HashDataInput.java | 36 + 4 files changed, 1043 insertions(+) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java new file mode 100644 index 00000000..87b4eab4 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -0,0 +1,909 @@ +/* +* 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. +*/ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package at.gv.egiz.bku.gui; + +import at.gv.egiz.smcc.PINSpec; +import java.awt.Color; +import java.awt.Container; +import java.awt.Cursor; +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.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.swing.GroupLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.LayoutStyle; +import javax.swing.SwingUtilities; +import javax.swing.filechooser.FileFilter; +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.PlainDocument; + +/** + * + * @author clemens + */ +public class BKUGUI implements BKUGUIFacade { + + public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; + public static final String LOGO_RESOURCE = "/images/logo.png"; + + public static final int MAIN_PANEL_WIDTH = 100; +// public static final int MAIN_PANEL_HEIGHT = 20; + public static final int PREF_SIZE_PINFIELD = 118; + public static final Color ERROR_COLOR = Color.RED; + public static final Color HYPERLINK_COLOR = Color.BLUE; + + private static final String TITLE_WELCOME = "title.welcome"; + private static final String TITLE_INSERTCARD = "title.insertcard"; + private static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; + private static final String TITLE_CARDPIN = "title.cardpin"; + private static final String TITLE_SIGN = "title.sign"; + private static final String TITLE_ERROR = "title.error"; + private static final String TITLE_RETRY = "title.retry"; + private static final String WINDOWTITLE_SAVE = "windowtitle.save"; + + private static final String MESSAGE_WAIT="message.wait"; + private static final String MESSAGE_INSERTCARD="message.insertcard"; + private static final String MESSAGE_HASHDATALINK="message.hashdatalink"; + private static final String MESSAGE_RETRIES="message.retries"; + private static final String LABEL_PIN="label.pin"; + private static final String LABEL_PINSIZE="label.pinsize"; +// private static final String LABEL_CARDPINSIZE="label.cardpinsize"; +// private static final String LABEL_SIGNPIN="label.signpin"; +// private static final String LABEL_SIGNPINSIZE="label.signpinsize"; + private static final String BUTTON_OK = "button.ok"; + private static final String BUTTON_CANCEL = "button.cancel"; + private static final String BUTTON_SIGN = "button.sign"; + + private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; + private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; + private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; + private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; + private static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; + + protected Container contentPane; + protected ResourceBundle messages; + + /** left and right side main panels */ + protected JPanel iconPanel; + protected JPanel contentPanel; + /** right side content panels and layouts */ + protected JPanel headerPanel; + protected JPanel mainPanel; + protected JPanel buttonPanel; + /** right side fixed labels */ + protected JLabel titleLabel; + /** remember the pinfield to return to worker */ + protected JPasswordField pinField; + + /** + * @param contentPane + * @param localeString may be null + */ + @Override + public void init(final Container contentPane, String localeString) { + + if (localeString != null) { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); + } else { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); + } + + this.contentPane = contentPane; + + try { + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + + initIconPanel(); + initContentPanel(); + + GroupLayout layout = new GroupLayout(contentPane); + contentPane.setLayout(layout); + layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); + layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + } + }); + } catch (Exception ex) { + throw new RuntimeException("Failed to init GUI: " + ex.getMessage()); + } + } + + protected void initIconPanel() { + iconPanel = new JPanel(); + JLabel iconLabel = new JLabel(); + iconLabel.setIcon(new ImageIcon(getClass().getResource(LOGO_RESOURCE))); // NOI18N + + GroupLayout iconPanelLayout = new GroupLayout(iconPanel); + iconPanel.setLayout(iconPanelLayout); + iconPanelLayout.setHorizontalGroup( + iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(iconPanelLayout.createSequentialGroup().addContainerGap().addComponent(iconLabel).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); + iconPanelLayout.setVerticalGroup( + iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(iconPanelLayout.createSequentialGroup().addContainerGap().addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE).addContainerGap(41, Short.MAX_VALUE))); + } + + protected void initContentPanel() { + + contentPanel = new JPanel(); + + headerPanel = new JPanel(); + mainPanel = new JPanel(); + buttonPanel = new JPanel(); + +// headerPanel.setBorder(new TitledBorder("header")); +// mainPanel.setBorder(new TitledBorder("main")); +// buttonPanel.setBorder(new TitledBorder("button")); + + titleLabel = new JLabel(); + titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | + java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); +// titleLabel.setForeground(defaultForground); + + GroupLayout headerPanelLayout = new GroupLayout(headerPanel); + headerPanel.setLayout(headerPanelLayout); + + headerPanelLayout.setHorizontalGroup( + headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(titleLabel, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)); + headerPanelLayout.setVerticalGroup( + headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(titleLabel)); + +// mainPanel.setPreferredSize(new Dimension(MAIN_PANEL_WIDTH, MAIN_PANEL_HEIGHT)); + + GroupLayout contentPanelLayout = new GroupLayout(contentPanel); + contentPanel.setLayout(contentPanelLayout); + contentPanelLayout.setHorizontalGroup( + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(contentPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(headerPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, MAIN_PANEL_WIDTH, Short.MAX_VALUE) + .addComponent(buttonPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))); + contentPanelLayout.setVerticalGroup( + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(contentPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(headerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(mainPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) //79, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap())); + } + + @Override + public void showLoginDialog(ActionListener loginListener, String actionCommand) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_ERROR)); +// titleLabel.setForeground(defaultForground); + + JLabel waitMsgLabel = new JLabel(); + waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + waitMsgLabel.setText("LoginDialog not supported yet."); + waitMsgLabel.setForeground(ERROR_COLOR); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); + + contentPanel.validate(); + } + }); + } + + @Override + public void showWelcomeDialog() { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_WELCOME)); +// titleLabel.setForeground(defaultForground); + + JLabel waitMsgLabel = new JLabel(); + waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); + + contentPanel.validate(); + + } + }); + } + + @Override + public void showInsertCardDialog(final ActionListener cancelListener, final String cancelCommand) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_INSERTCARD)); +// titleLabel.setForeground(defaultForground); + + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont()); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.addActionListener(cancelListener); + cancelButton.setActionCommand(cancelCommand); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton) + .addContainerGap())); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(cancelButton)); + + contentPanel.validate(); + } + }); + } + + @Override + public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); +// titleLabel.setForeground(defaultForground); + + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont()); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.addActionListener(cancelListener); + cancelButton.setActionCommand(cancelCommand); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); + + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton) + .addContainerGap())); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(cancelButton)); + + contentPanel.validate(); + } + }); + } + + private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (numRetries < 0) { + String cardpinTitle = messages.getString(TITLE_CARDPIN); + titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[] {pinSpec.getLocalizedName()})); + } else { + titleLabel.setText(messages.getString(TITLE_RETRY)); + } + + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont()); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + JButton okButton = new JButton(); + okButton.setEnabled(false); + okButton.setFont(okButton.getFont()); + okButton.setText(messages.getString(BUTTON_OK)); + okButton.setActionCommand(okCommand); + okButton.addActionListener(okListener); + + JLabel cardPinLabel = new JLabel(); + cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); + String pinLabel = messages.getString(LABEL_PIN); + cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[] {pinSpec.getLocalizedName()})); + +// JPasswordField cardPINField = new JPasswordField(); + pinField = new JPasswordField(); + pinField.setText(""); + pinField.setDocument(new PINDocument(pinSpec, okButton)); + pinField.setActionCommand(okCommand); + pinField.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (pinField.getPassword().length >= pinSpec.getMinLength()) { + okListener.actionPerformed(e); + } + } + }); + + JLabel infoLabel = new JLabel(); + if (numRetries < 0) { + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[] {pinSize})); + } else { + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[] {String.valueOf(numRetries)})); + infoLabel.setForeground(ERROR_COLOR); + } + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + +// GroupLayout.ParallelGroup mainGroup = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); +// mainGroup.addComponent(pinSizeLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) +// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup() // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addComponent(hashDataLabel) + // .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) //RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) //TRAILING) + .addComponent(infoLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) + .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) //)) + .addContainerGap())); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) //, false) + .addComponent(cardPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) + .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(infoLabel).addGap(cardPinLabel.getFont().getSize()))); //10, 10, 10))); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + .addContainerGap(15, Short.MAX_VALUE) + .addComponent(okButton) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(cancelButton))); + + pinField.requestFocusInWindow(); + contentPanel.validate(); + + } + }); + } + + @Override + public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { + showCardPINDialog(pinSpec, -1, okListener, okCommand, cancelListener, cancelCommand); + } + + @Override + public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { + showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); + } + + @Override + public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { + showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); + } + + @Override + public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { + showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); + } + + + + private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (numRetries < 0) { + titleLabel.setText(messages.getString(TITLE_SIGN)); + } else { + titleLabel.setText(messages.getString(TITLE_RETRY)); + } + + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont()); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + JButton signButton = new JButton(); + signButton.setEnabled(false); + signButton.setFont(signButton.getFont()); + signButton.setText(messages.getString(BUTTON_SIGN)); + signButton.setActionCommand(signCommand); + signButton.addActionListener(signListener); + + JLabel signPinLabel = new JLabel(); + signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); + String pinLabel = messages.getString(LABEL_PIN); + signPinLabel.setText(MessageFormat.format(pinLabel, new Object[] {pinSpec.getLocalizedName()})); + + pinField = new JPasswordField(); + pinField.setText(""); + pinField.setDocument(new PINDocument(pinSpec, signButton)); + pinField.setActionCommand(signCommand); + pinField.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (pinField.getPassword().length >= pinSpec.getMinLength()) { + signListener.actionPerformed(e); + } + } + }); + + //pinsize or error label + JLabel infoLabel = new JLabel(); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (numRetries < 0) { + String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[] {pinSize})); + } else { + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[] {String.valueOf(numRetries)})); + infoLabel.setForeground(ERROR_COLOR); + } + + JLabel hashDataLabel = new JLabel(); + hashDataLabel.setFont(hashDataLabel.getFont().deriveFont(hashDataLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + hashDataLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); + hashDataLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + hashDataLabel.setForeground(HYPERLINK_COLOR); + hashDataLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent me) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e); + } + }); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(hashDataLabel).addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup().addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING).addComponent(infoLabel) //, GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE) + .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)))).addContainerGap())); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(hashDataLabel).addGap(hashDataLabel.getFont().getSize()) //14, 14, 14) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE, false).addComponent(signPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) + .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(infoLabel).addGap(signPinLabel.getFont().getSize()))); //10, 10, 10))); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(signButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(signButton).addComponent(cancelButton))); + + pinField.requestFocusInWindow(); + contentPanel.validate(); + + } + +// private ParallelGroup createMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { +// ParallelGroup mainGroup = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); +// mainGroup.addComponent(hashDataLabel); +// if (errorLabel != null) { +// mainGroup.addComponent(errorLabel); +// } +// mainGroup.addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() +// .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) +// .addComponent(pinSizeLabel) +// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE))); +// return mainGroup; +// } + +// private GroupLayout.SequentialGroup createVerticalMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { +// GroupLayout.SequentialGroup mainGroup = mainPanelLayout.createSequentialGroup(); +// mainGroup.addComponent(hashDataLabel) +// .addGap(hashDataLabel.getFont().getSize()); //14, 14, 14) +// +// if (errorLabel != null) { +// mainGroup.addComponent(errorLabel) +// .addGap(errorLabel.getFont().getSize()); +// } +// mainGroup.addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE, false) +// .addComponent(signPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) +// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(pinSizeLabel) +// .addGap(signPinLabel.getFont().getSize()); +// +// return mainGroup; +//// mainPanelLayout.createSequentialGroup() +//// .addComponent(hashDataLabel) +//// .addGap(hashDataLabel.getFont().getSize()) //14, 14, 14) +//// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE, false) +//// .addComponent(signPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) +//// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) +//// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +//// .addComponent(pinSizeLabel) +//// .addGap(signPinLabel.getFont().getSize()) +//// +//// +// } + }); + } + + @Override + public void showErrorDialog(final String errorMsg, final ActionListener okListener, final String okCommand) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_ERROR)); +// titleLabel.setForeground(defaultForground); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText("" + errorMsg + ""); + errorMsgLabel.setForeground(ERROR_COLOR); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); + + JButton okButton = new JButton(); + okButton.setFont(okButton.getFont()); + okButton.setText(messages.getString(BUTTON_OK)); + okButton.setActionCommand(okCommand); + okButton.addActionListener(okListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton) + .addContainerGap())); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(okButton)); + + contentPanel.validate(); + } + }); + } + + @Override + public void showErrorDialog(final String errorMsg) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_ERROR)); +// titleLabel.setForeground(defaultForground); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText("" + errorMsg + ""); + errorMsgLabel.setForeground(ERROR_COLOR); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); + + contentPanel.validate(); + } + }); + } + + @Override + public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + + if (signedReferences != null && signedReferences.size() == 1) { + FileOutputStream fos = null; + try { + HashDataInput signedRef = signedReferences.get(0); + final String mimeType = signedRef.getMimeType(); + String dir = System.getProperty("user.home"); + JFileChooser fileDialog = new JFileChooser(dir); + fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); + fileDialog.setMultiSelectionEnabled(false); + fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); + fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); + fileDialog.setFileHidingEnabled(true); + MimeFilter mimeFilter = new MimeFilter(mimeType); + fileDialog.setFileFilter(mimeFilter); + String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + mimeFilter.getExtension(); + fileDialog.setSelectedFile(new File(dir, filename)); + switch (fileDialog.showSaveDialog(contentPane)) { + case JFileChooser.APPROVE_OPTION: + File f = fileDialog.getSelectedFile(); +// if (f.exists()) { +// //TODO +// } + + fos = new FileOutputStream(f); + BufferedOutputStream bos = new BufferedOutputStream(fos); + InputStream hdi = signedRef.getHashDataInput(); + int b; + while ((b = hdi.read()) != -1) { + bos.write(b); + } + bos.flush(); + bos.close(); + } + } catch (IOException ex) { + showErrorDialog("Failed to write signed reference to file: " + ex.getMessage(), null, null); + ex.printStackTrace(); + } finally { + try { + fos.close(); + } catch (IOException ex) {} + } + } else { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_ERROR)); + // titleLabel.setForeground(defaultForground); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText("HashDataInputDialog not supported yet."); + errorMsgLabel.setForeground(ERROR_COLOR); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); + + JButton okButton = new JButton(); + okButton.setFont(okButton.getFont()); + okButton.setText(messages.getString(BUTTON_OK)); + okButton.setActionCommand(okCommand); + okButton.addActionListener(okListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton) + .addContainerGap())); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(okButton)); + + contentPanel.validate(); + } + } + }); + } + + @Override + public char[] getPin() { + if (pinField != null) + return pinField.getPassword(); + return null; + } + + class PINDocument extends PlainDocument { + + private PINSpec pinSpec; + private Pattern pinPattern; + private JButton enterButton; + + public PINDocument(PINSpec pinSpec, JButton enterButton) { + this.pinSpec = pinSpec; + if (pinSpec.getRexepPattern() != null) { + pinPattern = Pattern.compile(pinSpec.getRexepPattern()); + } else { + pinPattern = Pattern.compile("."); + } + this.enterButton = enterButton; + } + + @Override + public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { + if (pinSpec.getMaxLength() >= (getLength() + str.length())) { + boolean matches = true; + for (int i = 0; i < str.length(); i++) { + Matcher m = pinPattern.matcher(str.substring(i, i+1)); + if (!m.matches()) { + matches = false; + } + } + if (matches) { + super.insertString(offs, str, a); + } + } + enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); + } + + @Override + public void remove(int offs, int len) throws BadLocationException { + super.remove(offs, len); + enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); + } + } + + class MimeFilter extends FileFilter { + + protected String mimeType; + + public MimeFilter(String mimeType) { + this.mimeType = mimeType; + } + + @Override + public boolean accept(File f) { + + if (f.isDirectory()) { + return true; + } else if ("text/xml".equals(mimeType)) { + return "xml".equals(getExtension(f)); + } else if ("text/plain".equals(mimeType)) { + return "txt".equals(getExtension(f)); + } else if ("application/pdf".equals(mimeType)) { + return "pdf".equals(getExtension(f)); + } else { + return "bin".equals(getExtension(f)); + } + } + + private String getExtension(File f) { + String ext = null; + String s = f.getName(); + int i = s.lastIndexOf('.'); + + if (i > 0 && i < s.length() - 1) { + ext = s.substring(i+1).toLowerCase(); + } + return ext; + } + + @Override + public String getDescription() { + if ("text/xml".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_XML); + } else if ("text/plain".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_TXT); + } else if ("application/pdf".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_PDF); + } else { + return messages.getString(MIMETYPE_DESC_BIN); + } + } + + public String getExtension() { + if ("text/xml".equals(mimeType)) { + return ".xml"; + } else if ("text/plain".equals(mimeType)) { + return ".txt"; + } else if ("application/pdf".equals(mimeType)) { + return ".pdf"; + } else { + return ".bin"; + } + } + } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java new file mode 100644 index 00000000..3766e905 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -0,0 +1,66 @@ +/* +* 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. +*/ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package at.gv.egiz.bku.gui; + +//import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.PINSpec; +import java.awt.Container; +import java.awt.event.ActionListener; +import java.util.List; +import javax.swing.JPasswordField; + +/** + * + * @author clemens + */ +public interface BKUGUIFacade { + + public void init(Container contentPane, String localeString); + + public void showWelcomeDialog(); + + /** + * MOA-ID only + * @param loginListener + */ + public void showLoginDialog(ActionListener loginListener, String actionCommand); + + public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); + + public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); + + public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); + + public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); + + public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); + + public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); + + public char[] getPin(); + + public void showHashDataInputDialog(List signedReferences, ActionListener okListener, String actionCommand); + + public void showErrorDialog(String errorMsg, ActionListener okListener, String actionCommand); + + public void showErrorDialog(String errorMsg); + +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java new file mode 100644 index 00000000..478b949b --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java @@ -0,0 +1,32 @@ +/* +* 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; + +public class BKUGUIFactory { + private static BKUGUIFactory instance = new BKUGUIFactory(); + + private BKUGUIFactory() { + } + + protected BKUGUIFacade createNewGUI() { + return new BKUGUI(); + } + + public static BKUGUIFacade createGUI() { + return instance.createNewGUI(); + } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java new file mode 100644 index 00000000..d916e81c --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java @@ -0,0 +1,36 @@ +/* +* 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. +*/ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.gui; + +import java.io.InputStream; + +/** + * + * @author clemens + */ +public interface HashDataInput { + + public InputStream getHashDataInput(); + + public String getMimeType(); + +} -- cgit v1.2.3 From 3808a5b4ec9d13c8cbb1b7fd95afa62c133342fd Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 5 Sep 2008 13:39:14 +0000 Subject: HashDataInput git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@21 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 432 +++++++++++---------- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 17 +- .../java/at/gv/egiz/bku/gui/HashDataInput.java | 36 -- 3 files changed, 228 insertions(+), 257 deletions(-) delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 87b4eab4..0ad09c70 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -1,19 +1,19 @@ /* -* 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. -*/ + * 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. + */ /* * To change this template, choose Tools | Templates * and open the template in the editor. @@ -21,6 +21,7 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.stal.HashDataInput; import java.awt.Color; import java.awt.Container; import java.awt.Cursor; @@ -30,7 +31,6 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -38,16 +38,14 @@ import java.text.MessageFormat; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; -import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.LayoutStyle; @@ -56,22 +54,23 @@ import javax.swing.filechooser.FileFilter; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.PlainDocument; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * * @author clemens */ public class BKUGUI implements BKUGUIFacade { - + + private static final Log log = LogFactory.getLog(BKUGUI.class); public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; public static final String LOGO_RESOURCE = "/images/logo.png"; - public static final int MAIN_PANEL_WIDTH = 100; // public static final int MAIN_PANEL_HEIGHT = 20; public static final int PREF_SIZE_PINFIELD = 118; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; - private static final String TITLE_WELCOME = "title.welcome"; private static final String TITLE_INSERTCARD = "title.insertcard"; private static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; @@ -79,30 +78,32 @@ public class BKUGUI implements BKUGUIFacade { private static final String TITLE_SIGN = "title.sign"; private static final String TITLE_ERROR = "title.error"; private static final String TITLE_RETRY = "title.retry"; + private static final String TITLE_WAIT = "title.wait"; + private static final String TITLE_HASHDATA = "title.hashdata"; private static final String WINDOWTITLE_SAVE = "windowtitle.save"; - - private static final String MESSAGE_WAIT="message.wait"; - private static final String MESSAGE_INSERTCARD="message.insertcard"; - private static final String MESSAGE_HASHDATALINK="message.hashdatalink"; - private static final String MESSAGE_RETRIES="message.retries"; - private static final String LABEL_PIN="label.pin"; - private static final String LABEL_PINSIZE="label.pinsize"; + private static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; + private static final String MESSAGE_WAIT = "message.wait"; + private static final String MESSAGE_INSERTCARD = "message.insertcard"; + private static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; + private static final String MESSAGE_HASHDATA = "message.hashdata"; + private static final String MESSAGE_RETRIES = "message.retries"; + private static final String MESSAGE_OVERWRITE = "message.overwrite"; + private static final String LABEL_PIN = "label.pin"; + private static final String LABEL_PINSIZE = "label.pinsize"; // private static final String LABEL_CARDPINSIZE="label.cardpinsize"; // private static final String LABEL_SIGNPIN="label.signpin"; // private static final String LABEL_SIGNPINSIZE="label.signpinsize"; private static final String BUTTON_OK = "button.ok"; private static final String BUTTON_CANCEL = "button.cancel"; private static final String BUTTON_SIGN = "button.sign"; - + private static final String BUTTON_SAVE = "button.save"; private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; private static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; - protected Container contentPane; protected ResourceBundle messages; - /** left and right side main panels */ protected JPanel iconPanel; protected JPanel contentPanel; @@ -121,7 +122,7 @@ public class BKUGUI implements BKUGUIFacade { */ @Override public void init(final Container contentPane, String localeString) { - + if (localeString != null) { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); } else { @@ -174,18 +175,17 @@ public class BKUGUI implements BKUGUIFacade { // headerPanel.setBorder(new TitledBorder("header")); // mainPanel.setBorder(new TitledBorder("main")); // buttonPanel.setBorder(new TitledBorder("button")); - + titleLabel = new JLabel(); - titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | - java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); + titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | + java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); // titleLabel.setForeground(defaultForground); - + GroupLayout headerPanelLayout = new GroupLayout(headerPanel); headerPanel.setLayout(headerPanelLayout); - + headerPanelLayout.setHorizontalGroup( - headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(titleLabel, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)); + headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(titleLabel, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)); headerPanelLayout.setVerticalGroup( headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(titleLabel)); @@ -194,25 +194,12 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout contentPanelLayout = new GroupLayout(contentPanel); contentPanel.setLayout(contentPanelLayout); contentPanelLayout.setHorizontalGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(contentPanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(headerPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, MAIN_PANEL_WIDTH, Short.MAX_VALUE) - .addComponent(buttonPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))); + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(contentPanelLayout.createSequentialGroup().addContainerGap().addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(headerPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, MAIN_PANEL_WIDTH, Short.MAX_VALUE).addComponent(buttonPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))); contentPanelLayout.setVerticalGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(contentPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(headerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(mainPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) //79, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap())); + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(contentPanelLayout.createSequentialGroup().addContainerGap().addComponent(headerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(mainPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) //79, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addContainerGap())); } - + @Override public void showLoginDialog(ActionListener loginListener, String actionCommand) { SwingUtilities.invokeLater(new Runnable() { @@ -220,13 +207,13 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - + titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); - + JLabel waitMsgLabel = new JLabel(); waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - waitMsgLabel.setText("LoginDialog not supported yet."); + waitMsgLabel.setText("LoginDialog not supported yet."); waitMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -236,12 +223,12 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); - + contentPanel.validate(); } }); } - + @Override public void showWelcomeDialog() { SwingUtilities.invokeLater(new Runnable() { @@ -249,13 +236,13 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_WELCOME)); + + titleLabel.setText(messages.getString(TITLE_WELCOME)); // titleLabel.setForeground(defaultForground); - + JLabel waitMsgLabel = new JLabel(); waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -264,9 +251,9 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); - + contentPanel.validate(); - + } }); } @@ -278,13 +265,13 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + + titleLabel.setText(messages.getString(TITLE_INSERTCARD)); // titleLabel.setForeground(defaultForground); - + JButton cancelButton = new JButton(); cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); @@ -292,15 +279,10 @@ public class BKUGUI implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton) - .addContainerGap())); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(cancelButton).addContainerGap())); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(cancelButton)); - + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(cancelButton)); + contentPanel.validate(); } }); @@ -313,19 +295,19 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - + titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); // titleLabel.setForeground(defaultForground); - + JButton cancelButton = new JButton(); cancelButton.setFont(cancelButton.getFont()); cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); - + JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + errorMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -334,21 +316,16 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); - - + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton) - .addContainerGap())); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(cancelButton).addContainerGap())); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(cancelButton)); - + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(cancelButton)); + contentPanel.validate(); } }); @@ -361,10 +338,10 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - + if (numRetries < 0) { String cardpinTitle = messages.getString(TITLE_CARDPIN); - titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[] {pinSpec.getLocalizedName()})); + titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); } else { titleLabel.setText(messages.getString(TITLE_RETRY)); } @@ -381,11 +358,11 @@ public class BKUGUI implements BKUGUIFacade { okButton.setText(messages.getString(BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); - + JLabel cardPinLabel = new JLabel(); cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); - String pinLabel = messages.getString(LABEL_PIN); - cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[] {pinSpec.getLocalizedName()})); + String pinLabel = messages.getString(LABEL_PIN); + cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); // JPasswordField cardPINField = new JPasswordField(); pinField = new JPasswordField(); @@ -410,9 +387,9 @@ public class BKUGUI implements BKUGUIFacade { if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { pinSize += "-" + pinSpec.getMaxLength(); } - infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[] {pinSize})); - } else { - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[] {String.valueOf(numRetries)})); + infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + } else { + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); } @@ -422,7 +399,7 @@ public class BKUGUI implements BKUGUIFacade { // GroupLayout.ParallelGroup mainGroup = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); // mainGroup.addComponent(pinSizeLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) // .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE); - + mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup() // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) // .addComponent(hashDataLabel) @@ -434,9 +411,7 @@ public class BKUGUI implements BKUGUIFacade { .addContainerGap())); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) //, false) .addComponent(cardPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) @@ -446,18 +421,13 @@ public class BKUGUI implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - .addContainerGap(15, Short.MAX_VALUE) - .addComponent(okButton) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(okButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(cancelButton))); - + pinField.requestFocusInWindow(); contentPanel.validate(); - + } }); } @@ -471,7 +441,7 @@ public class BKUGUI implements BKUGUIFacade { public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); } - + @Override public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); @@ -482,15 +452,13 @@ public class BKUGUI implements BKUGUIFacade { showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); } - - private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { SwingUtilities.invokeLater(new Runnable() { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - + if (numRetries < 0) { titleLabel.setText(messages.getString(TITLE_SIGN)); } else { @@ -512,8 +480,8 @@ public class BKUGUI implements BKUGUIFacade { JLabel signPinLabel = new JLabel(); signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); - String pinLabel = messages.getString(LABEL_PIN); - signPinLabel.setText(MessageFormat.format(pinLabel, new Object[] {pinSpec.getLocalizedName()})); + String pinLabel = messages.getString(LABEL_PIN); + signPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); pinField = new JPasswordField(); pinField.setText(""); @@ -538,25 +506,26 @@ public class BKUGUI implements BKUGUIFacade { if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { pinSize += "-" + pinSpec.getMaxLength(); } - infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[] {pinSize})); + infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); } else { - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[] {String.valueOf(numRetries)})); + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); } - + JLabel hashDataLabel = new JLabel(); hashDataLabel.setFont(hashDataLabel.getFont().deriveFont(hashDataLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); hashDataLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); hashDataLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); hashDataLabel.setForeground(HYPERLINK_COLOR); hashDataLabel.addMouseListener(new MouseAdapter() { + @Override - public void mouseClicked(MouseEvent me) { + public void mouseClicked(MouseEvent me) { ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); hashdataListener.actionPerformed(e); } }); - + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -580,10 +549,8 @@ public class BKUGUI implements BKUGUIFacade { pinField.requestFocusInWindow(); contentPanel.validate(); - - } -// private ParallelGroup createMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { + }// private ParallelGroup createMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { // ParallelGroup mainGroup = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); // mainGroup.addComponent(hashDataLabel); // if (errorLabel != null) { @@ -597,7 +564,6 @@ public class BKUGUI implements BKUGUIFacade { // .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE))); // return mainGroup; // } - // private GroupLayout.SequentialGroup createVerticalMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { // GroupLayout.SequentialGroup mainGroup = mainPanelLayout.createSequentialGroup(); // mainGroup.addComponent(hashDataLabel) @@ -637,8 +603,8 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_ERROR)); + + titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); JLabel errorMsgLabel = new JLabel(); @@ -653,7 +619,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); - + JButton okButton = new JButton(); okButton.setFont(okButton.getFont()); okButton.setText(messages.getString(BUTTON_OK)); @@ -664,15 +630,10 @@ public class BKUGUI implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton) - .addContainerGap())); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(okButton).addContainerGap())); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(okButton)); - + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(okButton)); + contentPanel.validate(); } }); @@ -685,13 +646,13 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_ERROR)); + + titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("" + errorMsg + ""); + errorMsgLabel.setText("" + errorMsg + ""); errorMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -701,69 +662,37 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); - + contentPanel.validate(); } }); } - + @Override public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { - + if (signedReferences != null && signedReferences.size() == 1) { - FileOutputStream fos = null; - try { - HashDataInput signedRef = signedReferences.get(0); - final String mimeType = signedRef.getMimeType(); - String dir = System.getProperty("user.home"); - JFileChooser fileDialog = new JFileChooser(dir); - fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileDialog.setMultiSelectionEnabled(false); - fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); - fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); - fileDialog.setFileHidingEnabled(true); - MimeFilter mimeFilter = new MimeFilter(mimeType); - fileDialog.setFileFilter(mimeFilter); - String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + mimeFilter.getExtension(); - fileDialog.setSelectedFile(new File(dir, filename)); - switch (fileDialog.showSaveDialog(contentPane)) { - case JFileChooser.APPROVE_OPTION: - File f = fileDialog.getSelectedFile(); -// if (f.exists()) { -// //TODO -// } - - fos = new FileOutputStream(f); - BufferedOutputStream bos = new BufferedOutputStream(fos); - InputStream hdi = signedRef.getHashDataInput(); - int b; - while ((b = hdi.read()) != -1) { - bos.write(b); - } - bos.flush(); - bos.close(); - } - } catch (IOException ex) { - showErrorDialog("Failed to write signed reference to file: " + ex.getMessage(), null, null); - ex.printStackTrace(); - } finally { - try { - fos.close(); - } catch (IOException ex) {} - } + + HashDataInput signedRef = signedReferences.get(0); +// if ("text/plain".equals(signedRef.getMimeType())) { +// } else { + showSaveHashDataInputDialog(signedRef, okListener, okCommand); +// } + } else { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_ERROR)); - // titleLabel.setForeground(defaultForground); + titleLabel.setText(messages.getString(TITLE_ERROR)); + // titleLabel.setForeground(defaultForground); JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("HashDataInputDialog not supported yet."); + errorMsgLabel.setText("HashDataInputDialog not supported yet."); errorMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -784,14 +713,9 @@ public class BKUGUI implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton) - .addContainerGap())); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(okButton).addContainerGap())); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(okButton)); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(okButton)); contentPanel.validate(); } @@ -799,13 +723,100 @@ public class BKUGUI implements BKUGUIFacade { }); } + + + private void showSaveHashDataInputDialog(HashDataInput signedRef, ActionListener okListener, String okCommand) { + String dir = System.getProperty("user.home"); + JFileChooser fileDialog = new JFileChooser(dir); + fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); + fileDialog.setMultiSelectionEnabled(false); + fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); + fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); + fileDialog.setFileHidingEnabled(true); + MimeFilter mimeFilter = new MimeFilter(signedRef.getMimeType()); + fileDialog.setFileFilter(mimeFilter); + String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + mimeFilter.getExtension(); + fileDialog.setSelectedFile(new File(dir, filename)); + switch (fileDialog.showSaveDialog(contentPane)) { + case JFileChooser.APPROVE_OPTION: + File f = fileDialog.getSelectedFile(); + if (f.exists()) { +// log.debug("hashDataInput file exists, overwrite?"); + String ovrwrt = messages.getString(MESSAGE_OVERWRITE); + int overwrite = JOptionPane.showConfirmDialog(contentPane, MessageFormat.format(ovrwrt, filename), messages.getString(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); + if (overwrite != JOptionPane.OK_OPTION) { +// log.debug("User canceled overwrite HashDataInput, returning to SignaturePin dialog"); + okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); + return; + } + } + if (log.isDebugEnabled()) { + log.debug("Writing HashDataInput " + signedRef.getReferenceId() + " (" + signedRef.getMimeType() + ") to file " + f); + } + FileOutputStream fos = null; + try { + fos = new FileOutputStream(f); + BufferedOutputStream bos = new BufferedOutputStream(fos); + InputStream hdi = signedRef.getHashDataInput(); + int b; + while ((b = hdi.read()) != -1) { + bos.write(b); + } + bos.flush(); + bos.close(); + } catch (IOException ex) { + log.error("Failed to write HashDataInput to file " + f + ": " + ex.getMessage()); + showErrorDialog("Failed to write signed reference to file: " + ex.getMessage(), null, null); + ex.printStackTrace(); + } finally { + try { + fos.close(); + } catch (IOException ex) { + } + } + } + okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); + } + + @Override + public void showWaitDialog(final String waitMessage) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_WAIT)); + + JLabel waitMsgLabel = new JLabel(); + waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (waitMessage != null) { + waitMsgLabel.setText("" + waitMessage + ""); + } else { + waitMsgLabel.setText("" + messages.getString(MESSAGE_WAIT) + ""); + } + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); + + contentPanel.validate(); + } + }); + } + @Override public char[] getPin() { - if (pinField != null) + if (pinField != null) { return pinField.getPassword(); + } return null; } - + class PINDocument extends PlainDocument { private PINSpec pinSpec; @@ -827,7 +838,7 @@ public class BKUGUI implements BKUGUIFacade { if (pinSpec.getMaxLength() >= (getLength() + str.length())) { boolean matches = true; for (int i = 0; i < str.length(); i++) { - Matcher m = pinPattern.matcher(str.substring(i, i+1)); + Matcher m = pinPattern.matcher(str.substring(i, i + 1)); if (!m.matches()) { matches = false; } @@ -845,7 +856,7 @@ public class BKUGUI implements BKUGUIFacade { enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); } } - + class MimeFilter extends FileFilter { protected String mimeType; @@ -853,20 +864,23 @@ public class BKUGUI implements BKUGUIFacade { public MimeFilter(String mimeType) { this.mimeType = mimeType; } - + @Override public boolean accept(File f) { if (f.isDirectory()) { return true; - } else if ("text/xml".equals(mimeType)) { - return "xml".equals(getExtension(f)); + } + + String ext = getExtension(f); + if ("text/xml".equals(mimeType)) { + return "xml".equals(ext); } else if ("text/plain".equals(mimeType)) { - return "txt".equals(getExtension(f)); + return "txt".equals(ext); } else if ("application/pdf".equals(mimeType)) { - return "pdf".equals(getExtension(f)); + return "pdf".equals(ext); } else { - return "bin".equals(getExtension(f)); + return "bin".equals(ext); } } @@ -875,8 +889,8 @@ public class BKUGUI implements BKUGUIFacade { String s = f.getName(); int i = s.lastIndexOf('.'); - if (i > 0 && i < s.length() - 1) { - ext = s.substring(i+1).toLowerCase(); + if (i > 0 && i < s.length() - 1) { + ext = s.substring(i + 1).toLowerCase(); } return ext; } @@ -893,7 +907,7 @@ public class BKUGUI implements BKUGUIFacade { return messages.getString(MIMETYPE_DESC_BIN); } } - + public String getExtension() { if ("text/xml".equals(mimeType)) { return ".xml"; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 3766e905..f8b80556 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -14,23 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package at.gv.egiz.bku.gui; -//import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.smcc.PINSpec; import java.awt.Container; import java.awt.event.ActionListener; import java.util.List; -import javax.swing.JPasswordField; -/** - * - * @author clemens - */ public interface BKUGUIFacade { public void init(Container contentPane, String localeString); @@ -42,7 +33,10 @@ public interface BKUGUIFacade { * @param loginListener */ public void showLoginDialog(ActionListener loginListener, String actionCommand); - + + /** optional wait message */ + public void showWaitDialog(String waitMessage); + public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); @@ -62,5 +56,4 @@ public interface BKUGUIFacade { public void showErrorDialog(String errorMsg, ActionListener okListener, String actionCommand); public void showErrorDialog(String errorMsg); - } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java deleted file mode 100644 index d916e81c..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java +++ /dev/null @@ -1,36 +0,0 @@ -/* -* 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. -*/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package at.gv.egiz.bku.gui; - -import java.io.InputStream; - -/** - * - * @author clemens - */ -public interface HashDataInput { - - public InputStream getHashDataInput(); - - public String getMimeType(); - -} -- cgit v1.2.3 From d3698ed2a4f129e5af970f072bc79bb8226d7765 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 5 Sep 2008 15:41:19 +0000 Subject: Text HashDataInput git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@24 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 111 ++++++++++++++++++++- 1 file changed, 106 insertions(+), 5 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 0ad09c70..5175b45f 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -29,15 +29,22 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.io.BufferedInputStream; import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; 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.text.MessageFormat; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.GroupLayout; @@ -48,6 +55,8 @@ import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.LayoutStyle; import javax.swing.SwingUtilities; import javax.swing.filechooser.FileFilter; @@ -677,11 +686,44 @@ public class BKUGUI implements BKUGUIFacade { if (signedReferences != null && signedReferences.size() == 1) { - HashDataInput signedRef = signedReferences.get(0); -// if ("text/plain".equals(signedRef.getMimeType())) { -// } else { + final HashDataInput signedRef = signedReferences.get(0); + if ("text/plain".equals(signedRef.getMimeType())) { + //TODO get encoding from mimetype + //read directly to byte[] since hashDataIS is backed by byte[] ? + ByteArrayOutputStream baos = null; + try { + String refId = signedRef.getReferenceId(); + InputStream hashDataIS = signedRef.getHashDataInput(); + if (hashDataIS == null) { + showErrorDialog("Failed to obtain HashDataInput for reference " + refId, okListener, okCommand); + } else { + baos = new ByteArrayOutputStream(hashDataIS.available()); + int c; + while ((c = hashDataIS.read()) != -1) { + baos.write(c); + } + String text = baos.toString("UTF-8"); + + ActionListener al = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(signedRef, okListener, okCommand); + } + }; + showPlainTextHashDataInputDialog(text, refId, okListener, okCommand, al, "save"); + } + } catch (IOException ex) { + showErrorDialog("Failed to read HashDataInput for reference " + signedRef.getReferenceId() + ": " + ex.getMessage(), okListener, okCommand); + } finally { + try { + baos.close(); + } catch (IOException ex) { + } + } + } else { showSaveHashDataInputDialog(signedRef, okListener, okCommand); -// } + } } else { mainPanel.removeAll(); @@ -723,7 +765,66 @@ public class BKUGUI implements BKUGUIFacade { }); } - + private void showPlainTextHashDataInputDialog(String text, String refId, ActionListener cancelListener, String cancelCommand, ActionListener saveListener, String saveCommand) { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_HASHDATA)); + + JLabel refIdLabel = new JLabel(); + refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String refIdLabelPattern = messages.getString(MESSAGE_HASHDATA); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[] {refId} )); + + JScrollPane hashDataScrollPane = new JScrollPane(); + JTextArea hashDataTextArea = new JTextArea(text); + hashDataTextArea.setEditable(false); + hashDataTextArea.setColumns(20); + hashDataTextArea.setRows(3); + hashDataScrollPane.setViewportView(hashDataTextArea); + + + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont()); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + JButton saveButton = new JButton(); + saveButton.setFont(saveButton.getFont()); + saveButton.setText(messages.getString(BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) + .addContainerGap())); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addGap(refIdLabel.getFont().getSize()) + .addComponent(hashDataScrollPane) + .addGap(refIdLabel.getFont().getSize()))); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); + + contentPanel.validate(); + } private void showSaveHashDataInputDialog(HashDataInput signedRef, ActionListener okListener, String okCommand) { String dir = System.getProperty("user.home"); -- cgit v1.2.3 From 84e214e4d708f13c8f09c68273541e535c560296 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 10 Sep 2008 16:54:04 +0000 Subject: gui final 0.1b git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@30 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 620 ++++++++++++++++----- 1 file changed, 467 insertions(+), 153 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 5175b45f..044e6927 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -23,43 +23,47 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; import java.awt.Color; +import java.awt.Component; import java.awt.Container; import java.awt.Cursor; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.io.BufferedInputStream; import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; 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.text.MessageFormat; +import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JScrollPane; +import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.LayoutStyle; import javax.swing.SwingUtilities; +import javax.swing.border.TitledBorder; import javax.swing.filechooser.FileFilter; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; +import javax.swing.table.TableModel; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.PlainDocument; @@ -75,9 +79,9 @@ public class BKUGUI implements BKUGUIFacade { private static final Log log = LogFactory.getLog(BKUGUI.class); public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; public static final String LOGO_RESOURCE = "/images/logo.png"; - public static final int MAIN_PANEL_WIDTH = 100; +// public static final int MAIN_PANEL_WIDTH = 100; // public static final int MAIN_PANEL_HEIGHT = 20; - public static final int PREF_SIZE_PINFIELD = 118; +// public static final int PREF_SIZE_PINFIELD = 118; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; private static final String TITLE_WELCOME = "title.welcome"; @@ -95,18 +99,21 @@ public class BKUGUI implements BKUGUIFacade { private static final String MESSAGE_INSERTCARD = "message.insertcard"; private static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; private static final String MESSAGE_HASHDATA = "message.hashdata"; + private static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; private static final String MESSAGE_RETRIES = "message.retries"; private static final String MESSAGE_OVERWRITE = "message.overwrite"; private static final String LABEL_PIN = "label.pin"; private static final String LABEL_PINSIZE = "label.pinsize"; -// private static final String LABEL_CARDPINSIZE="label.cardpinsize"; -// private static final String LABEL_SIGNPIN="label.signpin"; -// private static final String LABEL_SIGNPINSIZE="label.signpinsize"; + private static final String ERROR_HASHDATA = "error.hashdata"; + private static final String BUTTON_OK = "button.ok"; private static final String BUTTON_CANCEL = "button.cancel"; + private static final String BUTTON_BACK = "button.back"; private static final String BUTTON_SIGN = "button.sign"; private static final String BUTTON_SAVE = "button.save"; private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; + private static final String MIMETYPE_DESC_HTML = "mimetype.desc.html"; + private static final String MIMETYPE_DESC_XHTML = "mimetype.desc.xhtml"; private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; @@ -125,6 +132,15 @@ public class BKUGUI implements BKUGUIFacade { /** remember the pinfield to return to worker */ protected JPasswordField pinField; + protected JButton okButton; + protected JButton cancelButton; + protected JButton signButton; + protected JButton saveButton; + protected JButton backButton; + protected int buttonSize; + + private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; + /** * @param contentPane * @param localeString may be null @@ -168,9 +184,19 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout iconPanelLayout = new GroupLayout(iconPanel); iconPanel.setLayout(iconPanelLayout); iconPanelLayout.setHorizontalGroup( - iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(iconPanelLayout.createSequentialGroup().addContainerGap().addComponent(iconLabel).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); + iconPanelLayout.createSequentialGroup() +// iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(iconPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().width, GroupLayout.PREFERRED_SIZE) + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); iconPanelLayout.setVerticalGroup( - iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(iconPanelLayout.createSequentialGroup().addContainerGap().addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE).addContainerGap(41, Short.MAX_VALUE))); + iconPanelLayout.createSequentialGroup() +// iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(iconPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().height, GroupLayout.PREFERRED_SIZE) + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); } protected void initContentPanel() { @@ -190,23 +216,60 @@ public class BKUGUI implements BKUGUIFacade { java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); // titleLabel.setForeground(defaultForground); + okButton = new JButton(); + okButton.setText(messages.getString(BUTTON_OK)); + cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + signButton = new JButton(); + signButton.setText(messages.getString(BUTTON_SIGN)); + backButton = new JButton(); + backButton.setText(messages.getString(BUTTON_BACK)); + saveButton = new JButton(); + saveButton.setText(messages.getString(BUTTON_SAVE)); +// contentPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); + + if (okButton.getPreferredSize().width > buttonSize) + buttonSize = okButton.getPreferredSize().width; + if (cancelButton.getPreferredSize().width > buttonSize) + buttonSize = cancelButton.getPreferredSize().width; + if (signButton.getPreferredSize().width > buttonSize) + buttonSize = signButton.getPreferredSize().width; + if (backButton.getPreferredSize().width > buttonSize) + buttonSize = backButton.getPreferredSize().width; + if (saveButton.getPreferredSize().width > buttonSize) + buttonSize = saveButton.getPreferredSize().width; + + GroupLayout headerPanelLayout = new GroupLayout(headerPanel); headerPanel.setLayout(headerPanelLayout); headerPanelLayout.setHorizontalGroup( - headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(titleLabel, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)); + headerPanelLayout.createSequentialGroup() +// headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); headerPanelLayout.setVerticalGroup( - headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(titleLabel)); + headerPanelLayout.createSequentialGroup() +// headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); // mainPanel.setPreferredSize(new Dimension(MAIN_PANEL_WIDTH, MAIN_PANEL_HEIGHT)); GroupLayout contentPanelLayout = new GroupLayout(contentPanel); contentPanel.setLayout(contentPanelLayout); contentPanelLayout.setHorizontalGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(contentPanelLayout.createSequentialGroup().addContainerGap().addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(headerPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, MAIN_PANEL_WIDTH, Short.MAX_VALUE).addComponent(buttonPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))); + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //)); contentPanelLayout.setVerticalGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(contentPanelLayout.createSequentialGroup().addContainerGap().addComponent(headerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(mainPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) //79, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addContainerGap())); + contentPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); //); } @Override @@ -229,9 +292,13 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); contentPanel.validate(); } @@ -257,9 +324,14 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); contentPanel.validate(); @@ -276,21 +348,25 @@ public class BKUGUI implements BKUGUIFacade { buttonPanel.removeAll(); titleLabel.setText(messages.getString(TITLE_INSERTCARD)); -// titleLabel.setForeground(defaultForground); - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); //); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(cancelButton)); + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(cancelButton)); contentPanel.validate(); } @@ -308,12 +384,6 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); // titleLabel.setForeground(defaultForground); - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.addActionListener(cancelListener); - cancelButton.setActionCommand(cancelCommand); - JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); errorMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); @@ -322,19 +392,33 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); + cancelButton.addActionListener(cancelListener); + cancelButton.setActionCommand(cancelCommand); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); //); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(cancelButton)); - + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(cancelButton)); + contentPanel.validate(); } }); @@ -355,16 +439,10 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_RETRY)); } - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.setActionCommand(cancelCommand); cancelButton.addActionListener(cancelListener); - JButton okButton = new JButton(); okButton.setEnabled(false); - okButton.setFont(okButton.getFont()); - okButton.setText(messages.getString(BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -402,37 +480,77 @@ public class BKUGUI implements BKUGUIFacade { infoLabel.setForeground(ERROR_COLOR); } +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// mainPanelLayout.setHorizontalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(mainPanelLayout.createSequentialGroup() // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// // .addComponent(hashDataLabel) +// // .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() +// .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) //RELATED) +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) //TRAILING) +// .addComponent(infoLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) +// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)) //)) +// .addContainerGap())); +// +// mainPanelLayout.setVerticalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) //, false) +// .addComponent(cardPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) +// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(infoLabel).addGap(cardPinLabel.getFont().getSize()))); //10, 10, 10))); +// +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(okButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(cancelButton))); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); -// GroupLayout.ParallelGroup mainGroup = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); -// mainGroup.addComponent(pinSizeLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) -// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup() // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - // .addComponent(hashDataLabel) - // .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) //RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) //TRAILING) - .addComponent(infoLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) - .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) //)) - .addContainerGap())); + mainPanelLayout.createSequentialGroup() +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(hashDataLabel) +// .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) + .addComponent(infoLabel)) + .addContainerGap()); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) //, false) - .addComponent(cardPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) - .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(infoLabel).addGap(cardPinLabel.getFont().getSize()))); //10, 10, 10))); + mainPanelLayout.createSequentialGroup() +// .addComponent(hashDataLabel) +// .addGap(hashDataLabel.getFont().getSize()) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cardPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(infoLabel)); +// .addGap(signPinLabel.getFont().getSize())); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(okButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap());//); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(cancelButton))); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(okButton) + .addComponent(cancelButton)); pinField.requestFocusInWindow(); contentPanel.validate(); @@ -474,16 +592,10 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_RETRY)); } - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.setActionCommand(cancelCommand); cancelButton.addActionListener(cancelListener); - JButton signButton = new JButton(); signButton.setEnabled(false); - signButton.setFont(signButton.getFont()); - signButton.setText(messages.getString(BUTTON_SIGN)); signButton.setActionCommand(signCommand); signButton.addActionListener(signListener); @@ -539,22 +651,43 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(hashDataLabel).addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup().addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING).addComponent(infoLabel) //, GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE) - .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)))).addContainerGap())); + mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(hashDataLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(infoLabel)))) + .addContainerGap()); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(hashDataLabel).addGap(hashDataLabel.getFont().getSize()) //14, 14, 14) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE, false).addComponent(signPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) - .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(infoLabel).addGap(signPinLabel.getFont().getSize()))); //10, 10, 10))); + mainPanelLayout.createSequentialGroup() + .addComponent(hashDataLabel) + .addGap(hashDataLabel.getFont().getSize()) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(infoLabel)); +// .addGap(signPinLabel.getFont().getSize())); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(signButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap());//); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(signButton).addComponent(cancelButton))); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signButton) + .addComponent(cancelButton)); pinField.requestFocusInWindow(); contentPanel.validate(); @@ -625,23 +758,30 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); - JButton okButton = new JButton(); - okButton.setFont(okButton.getFont()); - okButton.setText(messages.getString(BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(okButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); //); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(okButton)); + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(okButton)); contentPanel.validate(); } @@ -668,9 +808,13 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); contentPanel.validate(); } @@ -725,41 +869,26 @@ public class BKUGUI implements BKUGUIFacade { showSaveHashDataInputDialog(signedRef, okListener, okCommand); } - } else { - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_ERROR)); - // titleLabel.setForeground(defaultForground); + } else if (signedReferences != null && signedReferences.size() > 1) { + final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("HashDataInputDialog not supported yet."); - errorMsgLabel.setForeground(ERROR_COLOR); + ActionListener al = new ActionListener() { - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); - - JButton okButton = new JButton(); - okButton.setFont(okButton.getFont()); - okButton.setText(messages.getString(BUTTON_OK)); - okButton.setActionCommand(okCommand); - okButton.addActionListener(okListener); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(okButton).addContainerGap())); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(okButton)); - - contentPanel.validate(); + @Override + public void actionPerformed(ActionEvent e) { + List selection = tableModel.getSelectedReferenceIds(); + StringBuilder sb = new StringBuilder("Not implemented yet. \n"); + for (String string : selection) { + sb.append(string); + sb.append('\n'); + } + showErrorDialog(sb.toString(), okListener, okCommand); +// showSaveHashDataInputDialog(signedRef, okListener, okCommand); + } + }; + showMultipleHashDataInputDialog(tableModel, okListener, okCommand, al, "save"); + } else { + showErrorDialog(messages.getString(ERROR_HASHDATA), okListener, okCommand); } } }); @@ -774,54 +903,193 @@ public class BKUGUI implements BKUGUIFacade { JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String refIdLabelPattern = messages.getString(MESSAGE_HASHDATA); - refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[] {refId} )); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{refId})); JScrollPane hashDataScrollPane = new JScrollPane(); JTextArea hashDataTextArea = new JTextArea(text); hashDataTextArea.setEditable(false); - hashDataTextArea.setColumns(20); - hashDataTextArea.setRows(3); + hashDataTextArea.setColumns(1); + hashDataTextArea.setRows(1); hashDataScrollPane.setViewportView(hashDataTextArea); + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTextArea.getPreferredSize().height+3)); + - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.setActionCommand(cancelCommand); - cancelButton.addActionListener(cancelListener); + +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// mainPanelLayout.setHorizontalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(refIdLabel).addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)).addContainerGap())); +// +// mainPanelLayout.setVerticalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(refIdLabel).addGap(refIdLabel.getFont().getSize()).addComponent(hashDataScrollPane).addGap(refIdLabel.getFont().getSize()))); + + backButton.setActionCommand(cancelCommand); + backButton.addActionListener(cancelListener); - JButton saveButton = new JButton(); - saveButton.setFont(saveButton.getFont()); - saveButton.setText(messages.getString(BUTTON_SAVE)); saveButton.setActionCommand(saveCommand); saveButton.addActionListener(saveListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); + 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(saveButton) + .addComponent(backButton)); + + +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); + + contentPanel.validate(); + } + + private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, ActionListener saveListener, String saveCommand) { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_HASHDATA)); + JLabel refIdLabel = new JLabel(); + refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); + + JTable hashDataTable = new JTable(); + hashDataTable.setModel(signedReferences); + hashDataTable.setTableHeader(null); +// hashDataTable.setShowVerticalLines(false); +// hashDataTable.setRowSelectionAllowed(false); + TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); + selectCol.setMinWidth(CHECKBOX_WIDTH); + selectCol.setMaxWidth(CHECKBOX_WIDTH); + + + hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); + + JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) - .addContainerGap())); - + mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); + mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addGap(refIdLabel.getFont().getSize()) - .addComponent(hashDataScrollPane) - .addGap(refIdLabel.getFont().getSize()))); - + mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTable.getPreferredSize().height+3)); +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)); + + + +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// mainPanelLayout.setHorizontalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(mainPanelLayout.createSequentialGroup() +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(refIdLabel) +// .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) +// .addContainerGap())); +// +// mainPanelLayout.setVerticalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(mainPanelLayout.createSequentialGroup() +// .addComponent(refIdLabel) +// .addGap(refIdLabel.getFont().getSize()) +// .addComponent(hashDataScrollPane) +// .addGap(refIdLabel.getFont().getSize()))); + + + + + + + + + + + + +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createSequentialGroup() +//// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +//// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(saveButton) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(cancelButton) +// .addContainerGap()); //); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() +// .addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) +// .addComponent(saveButton) +// .addComponent(cancelButton)) +// .addContainerGap())); + + + backButton.setActionCommand(cancelCommand); + backButton.addActionListener(cancelListener); + + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(saveButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap());//); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(saveButton) + .addComponent(backButton)); contentPanel.validate(); } @@ -901,9 +1169,13 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); contentPanel.validate(); } @@ -975,13 +1247,17 @@ public class BKUGUI implements BKUGUIFacade { String ext = getExtension(f); if ("text/xml".equals(mimeType)) { - return "xml".equals(ext); + return "xml".equalsIgnoreCase(ext); + } else if ("text/html".equals(mimeType)) { + return "html".equalsIgnoreCase(ext) || "htm".equalsIgnoreCase(ext); + } else if ("application/xhtml+xml".equals(mimeType)) { + return "xhtml".equalsIgnoreCase(ext); } else if ("text/plain".equals(mimeType)) { - return "txt".equals(ext); + return "txt".equalsIgnoreCase(ext); } else if ("application/pdf".equals(mimeType)) { - return "pdf".equals(ext); + return "pdf".equalsIgnoreCase(ext); } else { - return "bin".equals(ext); + return true; } } @@ -1000,6 +1276,10 @@ public class BKUGUI implements BKUGUIFacade { public String getDescription() { if ("text/xml".equals(mimeType)) { return messages.getString(MIMETYPE_DESC_XML); + } else if ("text/html".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_HTML); + } else if ("application/xhtml+xml".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_XHTML); } else if ("text/plain".equals(mimeType)) { return messages.getString(MIMETYPE_DESC_TXT); } else if ("application/pdf".equals(mimeType)) { @@ -1012,6 +1292,10 @@ public class BKUGUI implements BKUGUIFacade { public String getExtension() { if ("text/xml".equals(mimeType)) { return ".xml"; + } else if ("text/html".equals(mimeType)) { + return ".html"; + } else if ("application/xhtml+xml".equals(mimeType)) { + return ".xhtml"; } else if ("text/plain".equals(mimeType)) { return ".txt"; } else if ("application/pdf".equals(mimeType)) { @@ -1021,4 +1305,34 @@ public class BKUGUI implements BKUGUIFacade { } } } + + class HashDataTableModel extends DefaultTableModel { + + Class[] types = new Class[]{ + java.lang.String.class, java.lang.Boolean.class + }; + + public HashDataTableModel(List signedReferences) { + super(0, 2); + for (HashDataInput hashDataInput : signedReferences) { + addRow(new Object[]{hashDataInput.getReferenceId(), new Boolean(true)}); + } + } + + @Override + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + + public List getSelectedReferenceIds() { + ArrayList selection = new ArrayList(); + for (Object row : dataVector) { + if ((Boolean) ((Vector) row).elementAt(1)) { + selection.add((String) ((Vector) row).elementAt(0)); + } + } + return selection; + } + + } } -- cgit v1.2.3 From 3794536434fdbb06067eddcfd248898ce85f85a1 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 12 Sep 2008 13:06:34 +0000 Subject: gui 0.2 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@34 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 885 ++++++++++----------- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 2 + .../at/gv/egiz/bku/gui/HashDataTableModel.java | 71 ++ .../main/java/at/gv/egiz/bku/gui/MimeFilter.java | 98 +++ .../main/java/at/gv/egiz/bku/gui/PinDocument.java | 58 ++ 5 files changed, 634 insertions(+), 480 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 044e6927..584dba1a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -27,6 +27,7 @@ import java.awt.Component; import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; +import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -75,13 +76,11 @@ import org.apache.commons.logging.LogFactory; * @author clemens */ public class BKUGUI implements BKUGUIFacade { - + private static final Log log = LogFactory.getLog(BKUGUI.class); public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; public static final String LOGO_RESOURCE = "/images/logo.png"; -// public static final int MAIN_PANEL_WIDTH = 100; -// public static final int MAIN_PANEL_HEIGHT = 20; -// public static final int PREF_SIZE_PINFIELD = 118; + public static final String HASHDATA_FONT = "Monospaced"; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; private static final String TITLE_WELCOME = "title.welcome"; @@ -94,6 +93,7 @@ public class BKUGUI implements BKUGUIFacade { private static final String TITLE_WAIT = "title.wait"; private static final String TITLE_HASHDATA = "title.hashdata"; private static final String WINDOWTITLE_SAVE = "windowtitle.save"; + private static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; private static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; private static final String MESSAGE_WAIT = "message.wait"; private static final String MESSAGE_INSERTCARD = "message.insertcard"; @@ -104,19 +104,13 @@ public class BKUGUI implements BKUGUIFacade { private static final String MESSAGE_OVERWRITE = "message.overwrite"; private static final String LABEL_PIN = "label.pin"; private static final String LABEL_PINSIZE = "label.pinsize"; - private static final String ERROR_HASHDATA = "error.hashdata"; + private static final String ERROR_NO_HASHDATA = "error.no.hashdata"; private static final String BUTTON_OK = "button.ok"; private static final String BUTTON_CANCEL = "button.cancel"; private static final String BUTTON_BACK = "button.back"; private static final String BUTTON_SIGN = "button.sign"; private static final String BUTTON_SAVE = "button.save"; - private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; - private static final String MIMETYPE_DESC_HTML = "mimetype.desc.html"; - private static final String MIMETYPE_DESC_XHTML = "mimetype.desc.xhtml"; - private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; - private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; - private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; private static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; protected Container contentPane; protected ResourceBundle messages; @@ -132,11 +126,11 @@ public class BKUGUI implements BKUGUIFacade { /** remember the pinfield to return to worker */ protected JPasswordField pinField; - protected JButton okButton; - protected JButton cancelButton; - protected JButton signButton; - protected JButton saveButton; - protected JButton backButton; +// protected JButton okButton; +// protected JButton cancelButton; +// protected JButton signButton; +// protected JButton saveButton; +// protected JButton backButton; protected int buttonSize; private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; @@ -216,28 +210,43 @@ public class BKUGUI implements BKUGUIFacade { java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); // titleLabel.setForeground(defaultForground); - okButton = new JButton(); - okButton.setText(messages.getString(BUTTON_OK)); - cancelButton = new JButton(); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - signButton = new JButton(); - signButton.setText(messages.getString(BUTTON_SIGN)); - backButton = new JButton(); - backButton.setText(messages.getString(BUTTON_BACK)); - saveButton = new JButton(); - saveButton.setText(messages.getString(BUTTON_SAVE)); +// okButton = new JButton(); +// okButton.setText(messages.getString(BUTTON_OK)); +// cancelButton = new JButton(); +// cancelButton.setText(messages.getString(BUTTON_CANCEL)); +// signButton = new JButton(); +// signButton.setText(messages.getString(BUTTON_SIGN)); +// backButton = new JButton(); +// backButton.setText(messages.getString(BUTTON_BACK)); +// saveButton = new JButton(); +// saveButton.setText(messages.getString(BUTTON_SAVE)); // contentPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); - if (okButton.getPreferredSize().width > buttonSize) - buttonSize = okButton.getPreferredSize().width; - if (cancelButton.getPreferredSize().width > buttonSize) - buttonSize = cancelButton.getPreferredSize().width; - if (signButton.getPreferredSize().width > buttonSize) - buttonSize = signButton.getPreferredSize().width; - if (backButton.getPreferredSize().width > buttonSize) - buttonSize = backButton.getPreferredSize().width; - if (saveButton.getPreferredSize().width > buttonSize) - buttonSize = saveButton.getPreferredSize().width; + JButton b = new JButton(); + b.setText(messages.getString(BUTTON_CANCEL)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + b.setText(messages.getString(BUTTON_OK)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + b.setText(messages.getString(BUTTON_SIGN)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + b.setText(messages.getString(BUTTON_BACK)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + b.setText(messages.getString(BUTTON_SAVE)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + +// if (cancelButton.getPreferredSize().width > buttonSize) +// buttonSize = cancelButton.getPreferredSize().width; +// if (signButton.getPreferredSize().width > buttonSize) +// buttonSize = signButton.getPreferredSize().width; +// if (backButton.getPreferredSize().width > buttonSize) +// buttonSize = backButton.getPreferredSize().width; +// if (saveButton.getPreferredSize().width > buttonSize) +// buttonSize = saveButton.getPreferredSize().width; GroupLayout headerPanelLayout = new GroupLayout(headerPanel); @@ -349,6 +358,8 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); @@ -400,6 +411,8 @@ public class BKUGUI implements BKUGUIFacade { // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); @@ -439,9 +452,13 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_RETRY)); } + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.setActionCommand(cancelCommand); cancelButton.addActionListener(cancelListener); + JButton okButton = new JButton(); + okButton.setText(messages.getString(BUTTON_OK)); okButton.setEnabled(false); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -592,9 +609,13 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_RETRY)); } + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.setActionCommand(cancelCommand); cancelButton.addActionListener(cancelListener); + JButton signButton = new JButton(); + signButton.setText(messages.getString(BUTTON_SIGN)); signButton.setEnabled(false); signButton.setActionCommand(signCommand); signButton.addActionListener(signListener); @@ -764,6 +785,8 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); + JButton okButton = new JButton(); + okButton.setText(messages.getString(BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -790,343 +813,386 @@ public class BKUGUI implements BKUGUIFacade { @Override public void showErrorDialog(final String errorMsg) { - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeLater(new Runnable() { - public void run() { - mainPanel.removeAll(); - buttonPanel.removeAll(); + @Override + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_ERROR)); + titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("" + errorMsg + ""); - errorMsgLabel.setForeground(ERROR_COLOR); + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText("" + errorMsg + ""); + errorMsgLabel.setForeground(ERROR_COLOR); - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel)); + .addComponent(errorMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); - contentPanel.validate(); - } - }); + contentPanel.validate(); + } + }); } @Override public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { - SwingUtilities.invokeLater(new Runnable() { + + if (signedReferences == null) { + showErrorDialog(messages.getString(ERROR_NO_HASHDATA), okListener, okCommand); + } + + if (signedReferences.size() == 1) { + +// final HashDataInput signedRef = signedReferences.get(0); + + if ("text/plain".equals(signedReferences.get(0).getMimeType())) { + + ActionListener saveHashDataListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(signedReferences, okListener, okCommand); + } + }; + String hashDataText = getText(signedReferences.get(0)); + if (hashDataText != null) { + showPlainTextHashDataInputDialog(hashDataText, saveHashDataListener, "save", okListener, okCommand); + } else { + showErrorDialog(messages.getString(ERROR_NO_HASHDATA), okListener, okCommand); + } + + } else { + showSaveHashDataInputDialog(signedReferences, okListener, okCommand); + } + + } else { - @Override - public void run() { + final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - if (signedReferences != null && signedReferences.size() == 1) { - - final HashDataInput signedRef = signedReferences.get(0); - if ("text/plain".equals(signedRef.getMimeType())) { - //TODO get encoding from mimetype - //read directly to byte[] since hashDataIS is backed by byte[] ? - ByteArrayOutputStream baos = null; - try { - String refId = signedRef.getReferenceId(); - InputStream hashDataIS = signedRef.getHashDataInput(); - if (hashDataIS == null) { - showErrorDialog("Failed to obtain HashDataInput for reference " + refId, okListener, okCommand); - } else { - baos = new ByteArrayOutputStream(hashDataIS.available()); - int c; - while ((c = hashDataIS.read()) != -1) { - baos.write(c); - } - String text = baos.toString("UTF-8"); - - ActionListener al = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(signedRef, okListener, okCommand); - } - }; - showPlainTextHashDataInputDialog(text, refId, okListener, okCommand, al, "save"); - } - } catch (IOException ex) { - showErrorDialog("Failed to read HashDataInput for reference " + signedRef.getReferenceId() + ": " + ex.getMessage(), okListener, okCommand); - } finally { - try { - baos.close(); - } catch (IOException ex) { - } - } - } else { - showSaveHashDataInputDialog(signedRef, okListener, okCommand); - } + ActionListener saveHashDataListener = new ActionListener() { - } else if (signedReferences != null && signedReferences.size() > 1) { - final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - - ActionListener al = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - List selection = tableModel.getSelectedReferenceIds(); - StringBuilder sb = new StringBuilder("Not implemented yet. \n"); - for (String string : selection) { - sb.append(string); - sb.append('\n'); - } - showErrorDialog(sb.toString(), okListener, okCommand); -// showSaveHashDataInputDialog(signedRef, okListener, okCommand); - } - }; - showMultipleHashDataInputDialog(tableModel, okListener, okCommand, al, "save"); - } else { - showErrorDialog(messages.getString(ERROR_HASHDATA), okListener, okCommand); - } + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(tableModel.getSelectedHashData(), okListener, okCommand); } - }); + }; + showMultipleHashDataInputDialog(tableModel, okListener, okCommand, saveHashDataListener, "save"); + } + } + + private static String getText(HashDataInput hdi) { + ByteArrayOutputStream baos = null; + try { + InputStream hashDataIS = hdi.getHashDataInput(); + if (hashDataIS == null) { + log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); + return null; + } else { + baos = new ByteArrayOutputStream(hashDataIS.available()); + int c; + while ((c = hashDataIS.read()) != -1) { + baos.write(c); + } + return baos.toString("UTF-8"); + } + } catch (IOException ex) { + log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); + return null; + } finally { + try { + baos.close(); + } catch (IOException ex) { + } + } } - private void showPlainTextHashDataInputDialog(String text, String refId, ActionListener cancelListener, String cancelCommand, ActionListener saveListener, String saveCommand) { - mainPanel.removeAll(); - buttonPanel.removeAll(); + private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { + SwingUtilities.invokeLater(new Runnable() { - titleLabel.setText(messages.getString(TITLE_HASHDATA)); + @Override + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_HASHDATA)); + + JLabel refIdLabel = new JLabel(); + refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); + + JScrollPane hashDataScrollPane = new JScrollPane(); + JTextArea hashDataTextArea = new JTextArea(hashDataText); + hashDataTextArea.setEditable(false); + hashDataTextArea.setColumns(1); + hashDataTextArea.setRows(1); + hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); + hashDataScrollPane.setViewportView(hashDataTextArea); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTextArea.getPreferredSize().height+3)); + + + + // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + // mainPanel.setLayout(mainPanelLayout); + // + // mainPanelLayout.setHorizontalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(refIdLabel).addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)).addContainerGap())); + // + // mainPanelLayout.setVerticalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(refIdLabel).addGap(refIdLabel.getFont().getSize()).addComponent(hashDataScrollPane).addGap(refIdLabel.getFont().getSize()))); + + JButton backButton = new JButton(); + backButton.setText(messages.getString(BUTTON_BACK)); + backButton.setActionCommand(cancelCommand); + backButton.addActionListener(cancelListener); + + JButton saveButton = new JButton(); + saveButton.setText(messages.getString(BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + // buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); + 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(saveButton) + .addComponent(backButton)); + + + // GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + // buttonPanel.setLayout(buttonPanelLayout); + // + // buttonPanelLayout.setHorizontalGroup( + // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + // buttonPanelLayout.setVerticalGroup( + // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); + + contentPanel.validate(); + } + }); + } - JLabel refIdLabel = new JLabel(); - refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String refIdLabelPattern = messages.getString(MESSAGE_HASHDATA); - refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{refId})); + private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, final ActionListener saveListener, final String saveCommand) { + SwingUtilities.invokeLater(new Runnable() { - JScrollPane hashDataScrollPane = new JScrollPane(); - JTextArea hashDataTextArea = new JTextArea(text); - hashDataTextArea.setEditable(false); - hashDataTextArea.setColumns(1); - hashDataTextArea.setRows(1); - hashDataScrollPane.setViewportView(hashDataTextArea); + @Override + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); + titleLabel.setText(messages.getString(TITLE_HASHDATA)); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()); + JLabel refIdLabel = new JLabel(); + refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTextArea.getPreferredSize().height+3)); + JTable hashDataTable = new JTable(); + hashDataTable.setModel(signedReferences); + hashDataTable.setTableHeader(null); + // hashDataTable.setShowVerticalLines(false); + // hashDataTable.setRowSelectionAllowed(false); + TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); + selectCol.setMinWidth(CHECKBOX_WIDTH); + selectCol.setMaxWidth(CHECKBOX_WIDTH); + + + hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); - - -// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); -// mainPanel.setLayout(mainPanelLayout); -// -// mainPanelLayout.setHorizontalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(refIdLabel).addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)).addContainerGap())); -// -// mainPanelLayout.setVerticalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(refIdLabel).addGap(refIdLabel.getFont().getSize()).addComponent(hashDataScrollPane).addGap(refIdLabel.getFont().getSize()))); + JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); - backButton.setActionCommand(cancelCommand); - backButton.addActionListener(cancelListener); + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); - saveButton.setActionCommand(saveCommand); - saveButton.addActionListener(saveListener); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - -// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); - 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(saveButton) - .addComponent(backButton)); - - -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); - contentPanel.validate(); - } + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTable.getPreferredSize().height+3)); + // .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)); - private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, ActionListener saveListener, String saveCommand) { - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_HASHDATA)); - - JLabel refIdLabel = new JLabel(); - refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); - refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); - - JTable hashDataTable = new JTable(); - hashDataTable.setModel(signedReferences); - hashDataTable.setTableHeader(null); -// hashDataTable.setShowVerticalLines(false); -// hashDataTable.setRowSelectionAllowed(false); - TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); - selectCol.setMinWidth(CHECKBOX_WIDTH); - selectCol.setMaxWidth(CHECKBOX_WIDTH); - - - hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); - - JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTable.getPreferredSize().height+3)); -// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)); - - -// -// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); -// mainPanel.setLayout(mainPanelLayout); -// -// mainPanelLayout.setHorizontalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(mainPanelLayout.createSequentialGroup() -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(refIdLabel) -// .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) -// .addContainerGap())); -// -// mainPanelLayout.setVerticalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(mainPanelLayout.createSequentialGroup() -// .addComponent(refIdLabel) -// .addGap(refIdLabel.getFont().getSize()) -// .addComponent(hashDataScrollPane) -// .addGap(refIdLabel.getFont().getSize()))); - - - - - - - - - - - -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -//// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -//// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(saveButton) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(cancelButton) -// .addContainerGap()); //); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() -// .addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) -// .addComponent(saveButton) -// .addComponent(cancelButton)) -// .addContainerGap())); + // + // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + // mainPanel.setLayout(mainPanelLayout); + // + // mainPanelLayout.setHorizontalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addGroup(mainPanelLayout.createSequentialGroup() + // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addComponent(refIdLabel) + // .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) + // .addContainerGap())); + // + // mainPanelLayout.setVerticalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addGroup(mainPanelLayout.createSequentialGroup() + // .addComponent(refIdLabel) + // .addGap(refIdLabel.getFont().getSize()) + // .addComponent(hashDataScrollPane) + // .addGap(refIdLabel.getFont().getSize()))); - - backButton.setActionCommand(cancelCommand); - backButton.addActionListener(cancelListener); - saveButton.setActionCommand(saveCommand); - saveButton.addActionListener(saveListener); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - -// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); - 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap());//); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(saveButton) - .addComponent(backButton)); - - contentPanel.validate(); + + + + + + + + + + + // GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + // buttonPanel.setLayout(buttonPanelLayout); + // + // buttonPanelLayout.setHorizontalGroup( + // buttonPanelLayout.createSequentialGroup() + //// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + //// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + // .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + // .addComponent(saveButton) + // .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + // .addComponent(cancelButton) + // .addContainerGap()); //); + // buttonPanelLayout.setVerticalGroup( + // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + // .addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + // .addComponent(saveButton) + // .addComponent(cancelButton)) + // .addContainerGap())); + + + JButton backButton = new JButton(); + backButton.setText(messages.getString(BUTTON_BACK)); + backButton.setActionCommand(cancelCommand); + backButton.addActionListener(cancelListener); + + JButton saveButton = new JButton(); + saveButton.setText(messages.getString(BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + // buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); + 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap());//); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(saveButton) + .addComponent(backButton)); + + contentPanel.validate(); + } + }); } - private void showSaveHashDataInputDialog(HashDataInput signedRef, ActionListener okListener, String okCommand) { - String dir = System.getProperty("user.home"); - JFileChooser fileDialog = new JFileChooser(dir); - fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileDialog.setMultiSelectionEnabled(false); - fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); - fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); - fileDialog.setFileHidingEnabled(true); - MimeFilter mimeFilter = new MimeFilter(signedRef.getMimeType()); - fileDialog.setFileFilter(mimeFilter); - String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + mimeFilter.getExtension(); - fileDialog.setSelectedFile(new File(dir, filename)); - switch (fileDialog.showSaveDialog(contentPane)) { +// private DisposableFileChooser fileDialog; + + private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + String userHome = System.getProperty("user.home"); + + JFileChooser fileDialog = new JFileChooser(userHome); + fileDialog.setMultiSelectionEnabled(false); + fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); + fileDialog.setFileHidingEnabled(true); + if (signedRefs.size() == 1) { + fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); + fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); + String mimeType = signedRefs.get(0).getMimeType(); + MimeFilter mimeFilter = new MimeFilter(mimeType, messages); + fileDialog.setFileFilter(mimeFilter); + String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); + fileDialog.setSelectedFile(new File(userHome, filename)); + } else { + fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVEDIR)); + fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + } + + //parent contentPane -> placed over applet + switch (fileDialog.showSaveDialog(fileDialog)) { case JFileChooser.APPROVE_OPTION: - File f = fileDialog.getSelectedFile(); - if (f.exists()) { -// log.debug("hashDataInput file exists, overwrite?"); - String ovrwrt = messages.getString(MESSAGE_OVERWRITE); - int overwrite = JOptionPane.showConfirmDialog(contentPane, MessageFormat.format(ovrwrt, filename), messages.getString(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); - if (overwrite != JOptionPane.OK_OPTION) { -// log.debug("User canceled overwrite HashDataInput, returning to SignaturePin dialog"); - okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); - return; - } + File f = fileDialog.getSelectedFile(); + for (HashDataInput hashDataInput : signedRefs) { + String mimeType = hashDataInput.getMimeType(); + String id = hashDataInput.getReferenceId(); + File file; + if (f.isDirectory()) { + String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); + file = new File(f, filename); + } else { + file = f; + } + if (file.exists()) { + String ovrwrt = messages.getString(MESSAGE_OVERWRITE); + int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), messages.getString(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); + if (overwrite != JOptionPane.OK_OPTION) { + continue; + } } if (log.isDebugEnabled()) { - log.debug("Writing HashDataInput " + signedRef.getReferenceId() + " (" + signedRef.getMimeType() + ") to file " + f); + log.debug("Writing HashDataInput " + id + " (" + mimeType + ") to file " + file); } FileOutputStream fos = null; try { - fos = new FileOutputStream(f); + fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos); - InputStream hdi = signedRef.getHashDataInput(); + InputStream hdi = hashDataInput.getHashDataInput(); int b; while ((b = hdi.read()) != -1) { bos.write(b); @@ -1134,7 +1200,7 @@ public class BKUGUI implements BKUGUIFacade { bos.flush(); bos.close(); } catch (IOException ex) { - log.error("Failed to write HashDataInput to file " + f + ": " + ex.getMessage()); + log.error("Failed to write HashDataInput to file " + file + ": " + ex.getMessage()); showErrorDialog("Failed to write signed reference to file: " + ex.getMessage(), null, null); ex.printStackTrace(); } finally { @@ -1142,11 +1208,15 @@ public class BKUGUI implements BKUGUIFacade { fos.close(); } catch (IOException ex) { } - } + } + } + } + log.debug("done saving hashdatainput"); + okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); } - okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); + }); } - + @Override public void showWaitDialog(final String waitMessage) { SwingUtilities.invokeLater(new Runnable() { @@ -1190,149 +1260,4 @@ public class BKUGUI implements BKUGUIFacade { return null; } - class PINDocument extends PlainDocument { - - private PINSpec pinSpec; - private Pattern pinPattern; - private JButton enterButton; - - public PINDocument(PINSpec pinSpec, JButton enterButton) { - this.pinSpec = pinSpec; - if (pinSpec.getRexepPattern() != null) { - pinPattern = Pattern.compile(pinSpec.getRexepPattern()); - } else { - pinPattern = Pattern.compile("."); - } - this.enterButton = enterButton; - } - - @Override - public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { - if (pinSpec.getMaxLength() >= (getLength() + str.length())) { - boolean matches = true; - for (int i = 0; i < str.length(); i++) { - Matcher m = pinPattern.matcher(str.substring(i, i + 1)); - if (!m.matches()) { - matches = false; - } - } - if (matches) { - super.insertString(offs, str, a); - } - } - enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); - } - - @Override - public void remove(int offs, int len) throws BadLocationException { - super.remove(offs, len); - enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); - } - } - - class MimeFilter extends FileFilter { - - protected String mimeType; - - public MimeFilter(String mimeType) { - this.mimeType = mimeType; - } - - @Override - public boolean accept(File f) { - - if (f.isDirectory()) { - return true; - } - - String ext = getExtension(f); - if ("text/xml".equals(mimeType)) { - return "xml".equalsIgnoreCase(ext); - } else if ("text/html".equals(mimeType)) { - return "html".equalsIgnoreCase(ext) || "htm".equalsIgnoreCase(ext); - } else if ("application/xhtml+xml".equals(mimeType)) { - return "xhtml".equalsIgnoreCase(ext); - } else if ("text/plain".equals(mimeType)) { - return "txt".equalsIgnoreCase(ext); - } else if ("application/pdf".equals(mimeType)) { - return "pdf".equalsIgnoreCase(ext); - } else { - return true; - } - } - - private String getExtension(File f) { - String ext = null; - String s = f.getName(); - int i = s.lastIndexOf('.'); - - if (i > 0 && i < s.length() - 1) { - ext = s.substring(i + 1).toLowerCase(); - } - return ext; - } - - @Override - public String getDescription() { - if ("text/xml".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_XML); - } else if ("text/html".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_HTML); - } else if ("application/xhtml+xml".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_XHTML); - } else if ("text/plain".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_TXT); - } else if ("application/pdf".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_PDF); - } else { - return messages.getString(MIMETYPE_DESC_BIN); - } - } - - public String getExtension() { - if ("text/xml".equals(mimeType)) { - return ".xml"; - } else if ("text/html".equals(mimeType)) { - return ".html"; - } else if ("application/xhtml+xml".equals(mimeType)) { - return ".xhtml"; - } else if ("text/plain".equals(mimeType)) { - return ".txt"; - } else if ("application/pdf".equals(mimeType)) { - return ".pdf"; - } else { - return ".bin"; - } - } - } - - class HashDataTableModel extends DefaultTableModel { - - Class[] types = new Class[]{ - java.lang.String.class, java.lang.Boolean.class - }; - - public HashDataTableModel(List signedReferences) { - super(0, 2); - for (HashDataInput hashDataInput : signedReferences) { - addRow(new Object[]{hashDataInput.getReferenceId(), new Boolean(true)}); - } - } - - @Override - public Class getColumnClass(int columnIndex) { - return types [columnIndex]; - } - - public List getSelectedReferenceIds() { - ArrayList selection = new ArrayList(); - for (Object row : dataVector) { - if ((Boolean) ((Vector) row).elementAt(1)) { - selection.add((String) ((Vector) row).elementAt(0)); - } - } - return selection; - } - - } } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index f8b80556..f4b6325d 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -53,6 +53,8 @@ public interface BKUGUIFacade { public void showHashDataInputDialog(List signedReferences, ActionListener okListener, String actionCommand); +// public void showPlainTextHashDataInputDialog(String text, ActionListener saveListener, String saveCommand, ActionListener cancelListener, String cancelCommand); + public void showErrorDialog(String errorMsg, ActionListener okListener, String actionCommand); public void showErrorDialog(String errorMsg); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java new file mode 100644 index 00000000..061a2849 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java @@ -0,0 +1,71 @@ +/* +* 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.util.ArrayList; +import java.util.List; +import java.util.Vector; +import javax.swing.table.DefaultTableModel; + +/** + * + * @author clemens + */ +class HashDataTableModel extends DefaultTableModel { + + protected List signedReferences; + + Class[] types = new Class[]{ + java.lang.String.class, java.lang.Boolean.class + }; + + public HashDataTableModel(List signedReferences) { + super(0, 2); + this.signedReferences = signedReferences; + for (HashDataInput hashDataInput : signedReferences) { + String desc = hashDataInput.getReferenceId() + " (" + hashDataInput.getMimeType() + ")"; + addRow(new Object[]{desc, new Boolean(true)}); + } + } + + @Override + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + + public List getSelectedHashData() { + ArrayList selection = new ArrayList(); + for (int i = 0; i < dataVector.size(); i++) { + if ((Boolean) ((Vector) dataVector.get(i)).elementAt(1)) { + selection.add(signedReferences.get(i)); + } + } + return selection; + } + +// public List getSelectedReferenceIds() { +// ArrayList selection = new ArrayList(); +// for (Object row : dataVector) { +// if ((Boolean) ((Vector) row).elementAt(1)) { +// selection.add((String) ((Vector) row).elementAt(0)); +// } +// } +// return selection; +// } + + } \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java new file mode 100644 index 00000000..6ee61a82 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java @@ -0,0 +1,98 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package at.gv.egiz.bku.gui; + +import java.io.File; +import java.util.ResourceBundle; +import javax.swing.filechooser.FileFilter; + +/** + * + * @author clemens + */ +class MimeFilter extends FileFilter { + + private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; + private static final String MIMETYPE_DESC_HTML = "mimetype.desc.html"; + private static final String MIMETYPE_DESC_XHTML = "mimetype.desc.xhtml"; + private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; + private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; + private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; + + protected String mimeType; + protected ResourceBundle messages; + + public MimeFilter(String mimeType, ResourceBundle messages) { + this.mimeType = mimeType; + this.messages = messages; + } + + @Override + public boolean accept(File f) { + + if (f.isDirectory()) { + return true; + } + + String ext = getExtension(f); + if ("text/xml".equals(mimeType)) { + return "xml".equalsIgnoreCase(ext); + } else if ("text/html".equals(mimeType)) { + return "html".equalsIgnoreCase(ext) || "htm".equalsIgnoreCase(ext); + } else if ("application/xhtml+xml".equals(mimeType)) { + return "xhtml".equalsIgnoreCase(ext); + } else if ("text/plain".equals(mimeType)) { + return "txt".equalsIgnoreCase(ext); + } else if ("application/pdf".equals(mimeType)) { + return "pdf".equalsIgnoreCase(ext); + } else { + return true; + } + } + + private String getExtension(File f) { + String ext = null; + String s = f.getName(); + int i = s.lastIndexOf('.'); + + if (i > 0 && i < s.length() - 1) { + ext = s.substring(i + 1).toLowerCase(); + } + return ext; + } + + @Override + public String getDescription() { + if ("text/xml".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_XML); + } else if ("text/html".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_HTML); + } else if ("application/xhtml+xml".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_XHTML); + } else if ("text/plain".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_TXT); + } else if ("application/pdf".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_PDF); + } else { + return messages.getString(MIMETYPE_DESC_BIN); + } + } + + public static String getExtension(String mimeType) { + if ("text/xml".equals(mimeType)) { + return ".xml"; + } else if ("text/html".equals(mimeType)) { + return ".html"; + } else if ("application/xhtml+xml".equals(mimeType)) { + return ".xhtml"; + } else if ("text/plain".equals(mimeType)) { + return ".txt"; + } else if ("application/pdf".equals(mimeType)) { + return ".pdf"; + } else { + return ".bin"; + } + } +} \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java new file mode 100644 index 00000000..e8572742 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java @@ -0,0 +1,58 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.gui; + +import at.gv.egiz.smcc.PINSpec; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.swing.JButton; +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.PlainDocument; + +/** + * + * @author clemens + */ +class PINDocument extends PlainDocument { + + private PINSpec pinSpec; + private Pattern pinPattern; + private JButton enterButton; + + public PINDocument(PINSpec pinSpec, JButton enterButton) { + this.pinSpec = pinSpec; + if (pinSpec.getRexepPattern() != null) { + pinPattern = Pattern.compile(pinSpec.getRexepPattern()); + } else { + pinPattern = Pattern.compile("."); + } + this.enterButton = enterButton; + } + + @Override + public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { + if (pinSpec.getMaxLength() >= (getLength() + str.length())) { + boolean matches = true; + for (int i = 0; i < str.length(); i++) { + Matcher m = pinPattern.matcher(str.substring(i, i + 1)); + if (!m.matches()) { + matches = false; + } + } + if (matches) { + super.insertString(offs, str, a); + } + } + enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); + } + + @Override + public void remove(int offs, int len) throws BadLocationException { + super.remove(offs, len); + enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); + } + } \ No newline at end of file -- cgit v1.2.3 From a288c99fa6955a2c9055b28dc1c805dacbe5fc93 Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 15 Sep 2008 18:02:18 +0000 Subject: encoding git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@40 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 262 ++++++++++++++------- .../at/gv/egiz/bku/gui/HashDataTableModel.java | 94 ++++---- .../main/java/at/gv/egiz/bku/gui/MimeFilter.java | 18 +- .../main/java/at/gv/egiz/bku/gui/PinDocument.java | 19 +- 4 files changed, 251 insertions(+), 142 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 584dba1a..5fb67982 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -23,10 +23,8 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; import java.awt.Color; -import java.awt.Component; import java.awt.Container; import java.awt.Cursor; -import java.awt.Dimension; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -39,13 +37,10 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.text.MessageFormat; -import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; -import java.util.Vector; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.StringTokenizer; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -59,15 +54,10 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.LayoutStyle; +import javax.swing.ScrollPaneConstants; import javax.swing.SwingUtilities; -import javax.swing.border.TitledBorder; -import javax.swing.filechooser.FileFilter; -import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.PlainDocument; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -154,6 +144,7 @@ public class BKUGUI implements BKUGUIFacade { SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { initIconPanel(); @@ -285,6 +276,7 @@ public class BKUGUI implements BKUGUIFacade { public void showLoginDialog(ActionListener loginListener, String actionCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -318,6 +310,7 @@ public class BKUGUI implements BKUGUIFacade { public void showWelcomeDialog() { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -352,6 +345,7 @@ public class BKUGUI implements BKUGUIFacade { public void showInsertCardDialog(final ActionListener cancelListener, final String cancelCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -388,6 +382,7 @@ public class BKUGUI implements BKUGUIFacade { public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -440,6 +435,7 @@ public class BKUGUI implements BKUGUIFacade { private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); @@ -599,6 +595,7 @@ public class BKUGUI implements BKUGUIFacade { private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -763,6 +760,7 @@ public class BKUGUI implements BKUGUIFacade { public void showErrorDialog(final String errorMsg, final ActionListener okListener, final String okCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -845,6 +843,50 @@ public class BKUGUI implements BKUGUIFacade { }); } + @Override + public void showWaitDialog(final String waitMessage) { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_WAIT)); + + JLabel waitMsgLabel = new JLabel(); + waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (waitMessage != null) { + waitMsgLabel.setText("" + waitMessage + ""); + } else { + waitMsgLabel.setText("" + messages.getString(MESSAGE_WAIT) + ""); + } + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); + + contentPanel.validate(); + } + }); + } + + @Override + public char[] getPin() { + if (pinField != null) { + return pinField.getPassword(); + } + return null; + } + @Override public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { @@ -891,32 +933,6 @@ public class BKUGUI implements BKUGUIFacade { } } - private static String getText(HashDataInput hdi) { - ByteArrayOutputStream baos = null; - try { - InputStream hashDataIS = hdi.getHashDataInput(); - if (hashDataIS == null) { - log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); - return null; - } else { - baos = new ByteArrayOutputStream(hashDataIS.available()); - int c; - while ((c = hashDataIS.read()) != -1) { - baos.write(c); - } - return baos.toString("UTF-8"); - } - } catch (IOException ex) { - log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); - return null; - } finally { - try { - baos.close(); - } catch (IOException ex) { - } - } - } - private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { SwingUtilities.invokeLater(new Runnable() { @@ -931,13 +947,16 @@ public class BKUGUI implements BKUGUIFacade { refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); - JScrollPane hashDataScrollPane = new JScrollPane(); JTextArea hashDataTextArea = new JTextArea(hashDataText); hashDataTextArea.setEditable(false); - hashDataTextArea.setColumns(1); - hashDataTextArea.setRows(1); +// hashDataTextArea.setColumns(1); +// hashDataTextArea.setRows(1); hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); - hashDataScrollPane.setViewportView(hashDataTextArea); +// hashDataScrollPane.setViewportView(hashDataTextArea); +// hashDataScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //HORIZONTAL_SCROLLBAR_NEVER); + + + JScrollPane hashDataScrollPane = new JScrollPane(hashDataTextArea); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -946,16 +965,14 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createSequentialGroup() .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)) .addContainerGap()); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() .addComponent(refIdLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTextArea.getPreferredSize().height+3)); - - + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); // mainPanel.setLayout(mainPanelLayout); @@ -1031,7 +1048,7 @@ public class BKUGUI implements BKUGUIFacade { selectCol.setMaxWidth(CHECKBOX_WIDTH); - hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); +// hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); @@ -1042,14 +1059,14 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createSequentialGroup() .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)) // GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() .addComponent(refIdLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTable.getPreferredSize().height+3)); + .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); // .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)); @@ -1217,47 +1234,112 @@ public class BKUGUI implements BKUGUIFacade { }); } - @Override - public void showWaitDialog(final String waitMessage) { - SwingUtilities.invokeLater(new Runnable() { - - public void run() { - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_WAIT)); - - JLabel waitMsgLabel = new JLabel(); - waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - if (waitMessage != null) { - waitMsgLabel.setText("" + waitMessage + ""); - } else { - waitMsgLabel.setText("" + messages.getString(MESSAGE_WAIT) + ""); - } - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel)); - - contentPanel.validate(); - } - }); - } - - @Override - public char[] getPin() { - if (pinField != null) { - return pinField.getPassword(); + private static String getText(HashDataInput hdi) { + ByteArrayOutputStream baos = null; + try { + InputStream hashDataIS = hdi.getHashDataInput(); + if (hashDataIS == null) { + log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); + return null; + } else { + baos = new ByteArrayOutputStream(hashDataIS.available()); + int c; + while ((c = hashDataIS.read()) != -1) { + baos.write(c); + } + String encoding = hdi.getEncoding(); + if (encoding == null) { + //default for URL-encoded + encoding = "UTF-8"; + } + return baos.toString(encoding); } - return null; + } catch (IOException ex) { + log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); + return null; + } finally { + try { + baos.close(); + } catch (IOException ex) { + } + } } - + +// private String parseToken(final char[] terminators) { +// char ch; +// i1 = pos; +// i2 = pos; +// while (hasChar()) { +// ch = chars[pos]; +// if (isOneOf(ch, terminators)) { +// break; +// } +// i2++; +// pos++; +// } +// return getToken(false); +// } + +// private static String getCharset(String contentType) { +// +// StringTokenizer t = new StringTokenizer +// +// if (contentType == null) { +// return "UTF-8"; +// } +// +// int pos = 0; +// int len = contentType.length(); +// +// while (pos < len) { +// pos++; +// String paramName = parseToken(new char[] { +// '=', separator }); +// } +// +// HashMap params = new HashMap(); +// this.chars = chars; +// this.pos = offset; +// this.len = length; +// +// String paramName = null; +// String paramValue = null; +// while (hasChar()) { +// paramName = parseToken(new char[] { +// '=', separator }); +// paramValue = null; +// if (hasChar() && (chars[pos] == '=')) { +// pos++; // skip '=' +// paramValue = parseQuotedToken(new char[] { +// separator }); +// } +// if (hasChar() && (chars[pos] == separator)) { +// pos++; // skip separator +// } +// if ((paramName != null) && (paramName.length() > 0)) { +// if (this.lowerCaseNames) { +// paramName = paramName.toLowerCase(); +// } +// params.put(paramName, paramValue); +// } +// } +// return params; +// +// +// +// Parser +// ParameterParser pf = new ParameterParser(); +// pf.setLowerCaseNames(true); +// Map map = pf.parse(contentType, SEPERATOR); +// String retVal = (String) map.get(CHAR_SET); +// if ((retVal == null) && (replaceNullWithDefault)) { +// if (map.containsKey(APPLICATION_URL_ENCODED)) { +// // default charset for url encoded data +// return "UTF-8"; +// } +// retVal = getDefaultCharset(); +// } +// return retVal; +// } + } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java index 061a2849..1a833f48 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java @@ -1,19 +1,19 @@ /* -* 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. -*/ + * 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; @@ -28,37 +28,42 @@ import javax.swing.table.DefaultTableModel; */ class HashDataTableModel extends DefaultTableModel { - protected List signedReferences; - - Class[] types = new Class[]{ - java.lang.String.class, java.lang.Boolean.class - }; - - public HashDataTableModel(List signedReferences) { - super(0, 2); - this.signedReferences = signedReferences; - for (HashDataInput hashDataInput : signedReferences) { - String desc = hashDataInput.getReferenceId() + " (" + hashDataInput.getMimeType() + ")"; - addRow(new Object[]{desc, new Boolean(true)}); - } - } + protected List signedReferences; + + protected Class[] types = new Class[]{ + java.lang.String.class, java.lang.Boolean.class + }; - @Override - public Class getColumnClass(int columnIndex) { - return types [columnIndex]; - } + public HashDataTableModel(List signedReferences) { + super(0, 2); + this.signedReferences = signedReferences; + for (HashDataInput hashDataInput : signedReferences) { + String desc = hashDataInput.getReferenceId() + " (" + hashDataInput.getMimeType() + ")"; + addRow(new Object[]{desc, new Boolean(true)}); + } + } - public List getSelectedHashData() { - ArrayList selection = new ArrayList(); - for (int i = 0; i < dataVector.size(); i++) { - if ((Boolean) ((Vector) dataVector.get(i)).elementAt(1)) { - selection.add(signedReferences.get(i)); - } - } - return selection; - } + @Override + public Class getColumnClass(int columnIndex) { + return types[columnIndex]; + } -// public List getSelectedReferenceIds() { + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + if (columnIndex == 1) + return true; + return false; + } + + public List getSelectedHashData() { + ArrayList selection = new ArrayList(); + for (int i = 0; i < dataVector.size(); i++) { + if ((Boolean) ((Vector) dataVector.get(i)).elementAt(1)) { + selection.add(signedReferences.get(i)); + } + } + return selection; + }// public List getSelectedReferenceIds() { // ArrayList selection = new ArrayList(); // for (Object row : dataVector) { // if ((Boolean) ((Vector) row).elementAt(1)) { @@ -67,5 +72,4 @@ class HashDataTableModel extends DefaultTableModel { // } // return selection; // } - - } \ No newline at end of file +} \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java index 6ee61a82..4b48081a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java @@ -1,7 +1,19 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ +* 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.io.File; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java index e8572742..8ae9d7a3 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java @@ -1,8 +1,19 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - +* 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.smcc.PINSpec; -- cgit v1.2.3 From a20fb683943ce0893302b6dc25015c998cd9687f Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 18 Sep 2008 09:25:55 +0000 Subject: hashdatainput cached git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@46 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 5fb67982..be4aeded 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -871,8 +871,10 @@ public class BKUGUI implements BKUGUIFacade { .addComponent(waitMsgLabel) .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel) + .addContainerGap()); contentPanel.validate(); } -- cgit v1.2.3 From 12d4f22e52fba1f867571afbd539b532e2afe1b5 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 18 Sep 2008 09:48:56 +0000 Subject: wait message bug git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@47 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index be4aeded..449dfd61 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -835,7 +835,8 @@ public class BKUGUI implements BKUGUIFacade { .addComponent(errorMsgLabel) .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); contentPanel.validate(); @@ -859,7 +860,7 @@ public class BKUGUI implements BKUGUIFacade { if (waitMessage != null) { waitMsgLabel.setText("" + waitMessage + ""); } else { - waitMsgLabel.setText("" + messages.getString(MESSAGE_WAIT) + ""); + waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); } GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -873,8 +874,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addContainerGap()); + .addComponent(waitMsgLabel)); contentPanel.validate(); } -- cgit v1.2.3 From fe648888843f3c3695f252d887357ec63edfee97 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 18 Sep 2008 15:49:51 +0000 Subject: wordwrap git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@50 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 449dfd61..b94a58e8 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -956,7 +956,8 @@ public class BKUGUI implements BKUGUIFacade { hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); // hashDataScrollPane.setViewportView(hashDataTextArea); // hashDataScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //HORIZONTAL_SCROLLBAR_NEVER); - + hashDataTextArea.setLineWrap(true); + hashDataTextArea.setWrapStyleWord(true); JScrollPane hashDataScrollPane = new JScrollPane(hashDataTextArea); -- cgit v1.2.3 From 1c4df47223a6d655b9fb7f46f807171ceda07ba7 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 23 Sep 2008 12:09:10 +0000 Subject: bitte warten... git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@56 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index b94a58e8..0b68962c 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -400,7 +400,8 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel)); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(errorMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -777,10 +778,13 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel) //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addContainerGap()); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); JButton okButton = new JButton(); -- cgit v1.2.3 From 03f5ae9e9068168b294c042d68a58637e71a54ee Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 23 Sep 2008 14:09:02 +0000 Subject: bitte warten... git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@59 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 0b68962c..544b6eb3 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -246,7 +246,8 @@ public class BKUGUI implements BKUGUIFacade { headerPanelLayout.setHorizontalGroup( headerPanelLayout.createSequentialGroup() // headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + .addContainerGap()); headerPanelLayout.setVerticalGroup( headerPanelLayout.createSequentialGroup() // headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -- cgit v1.2.3 From ef04d747b03dc5159f7d284399dfcf637f4e97e3 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 24 Sep 2008 13:08:52 +0000 Subject: debugmessages git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@62 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 108 +++++++++++++++++---- 1 file changed, 91 insertions(+), 17 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 544b6eb3..749207ee 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -142,10 +142,14 @@ public class BKUGUI implements BKUGUIFacade { try { + log.debug("scheduling gui initialization"); + SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { + + log.debug("initializing gui"); initIconPanel(); initContentPanel(); @@ -275,10 +279,16 @@ public class BKUGUI implements BKUGUIFacade { @Override public void showLoginDialog(ActionListener loginListener, String actionCommand) { - SwingUtilities.invokeLater(new Runnable() { + + log.debug("scheduling login dialog"); + + SwingUtilities.invokeLater(new Runnable() { - @Override + @Override public void run() { + + log.debug("show login dialog"); + mainPanel.removeAll(); buttonPanel.removeAll(); @@ -309,10 +319,16 @@ public class BKUGUI implements BKUGUIFacade { @Override public void showWelcomeDialog() { + + log.debug("scheduling welcome dialog"); + SwingUtilities.invokeLater(new Runnable() { - @Override + @Override public void run() { + + log.debug("show welcome dialog"); + mainPanel.removeAll(); buttonPanel.removeAll(); @@ -344,10 +360,16 @@ public class BKUGUI implements BKUGUIFacade { @Override public void showInsertCardDialog(final ActionListener cancelListener, final String cancelCommand) { - SwingUtilities.invokeLater(new Runnable() { + + log.debug("scheduling insert card dialog"); + + SwingUtilities.invokeLater(new Runnable() { - @Override + @Override public void run() { + + log.debug("show insert card dialog"); + mainPanel.removeAll(); buttonPanel.removeAll(); @@ -381,12 +403,18 @@ public class BKUGUI implements BKUGUIFacade { @Override public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { - SwingUtilities.invokeLater(new Runnable() { + + log.debug("scheduling card not supported dialog"); + + SwingUtilities.invokeLater(new Runnable() { - @Override + @Override public void run() { - mainPanel.removeAll(); - buttonPanel.removeAll(); + + log.debug("show card not supported dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); // titleLabel.setForeground(defaultForground); @@ -435,11 +463,16 @@ public class BKUGUI implements BKUGUIFacade { } private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { - SwingUtilities.invokeLater(new Runnable() { + + log.debug("scheduling card-pin dialog"); + + SwingUtilities.invokeLater(new Runnable() { - @Override + @Override public void run() { + log.debug("show card-pin dialog"); + mainPanel.removeAll(); buttonPanel.removeAll(); @@ -595,10 +628,16 @@ public class BKUGUI implements BKUGUIFacade { } private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { - SwingUtilities.invokeLater(new Runnable() { - @Override + log.debug("scheduling signature-pin dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override public void run() { + + log.debug("show signature-pin dialog"); + mainPanel.removeAll(); buttonPanel.removeAll(); @@ -760,10 +799,16 @@ public class BKUGUI implements BKUGUIFacade { @Override public void showErrorDialog(final String errorMsg, final ActionListener okListener, final String okCommand) { - SwingUtilities.invokeLater(new Runnable() { + + log.debug("scheduling error dialog"); + + SwingUtilities.invokeLater(new Runnable() { - @Override + @Override public void run() { + + log.debug("show error dialog"); + mainPanel.removeAll(); buttonPanel.removeAll(); @@ -816,10 +861,16 @@ public class BKUGUI implements BKUGUIFacade { @Override public void showErrorDialog(final String errorMsg) { + + log.debug("scheduling error dialog"); + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { + + log.debug("show error dialog"); + mainPanel.removeAll(); buttonPanel.removeAll(); @@ -851,10 +902,16 @@ public class BKUGUI implements BKUGUIFacade { @Override public void showWaitDialog(final String waitMessage) { - SwingUtilities.invokeLater(new Runnable() { + + log.debug("scheduling wait dialog"); + + SwingUtilities.invokeLater(new Runnable() { - @Override + @Override public void run() { + + log.debug("show wait dialog"); + mainPanel.removeAll(); buttonPanel.removeAll(); @@ -941,10 +998,16 @@ public class BKUGUI implements BKUGUIFacade { } private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { + + log.debug("scheduling plaintext hashdatainput dialog"); + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { + + log.debug("show plaintext hashdatainput dialog"); + mainPanel.removeAll(); buttonPanel.removeAll(); @@ -1032,10 +1095,16 @@ public class BKUGUI implements BKUGUIFacade { } private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, final ActionListener saveListener, final String saveCommand) { + + log.debug("scheduling multiple hashdatainput dialog"); + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { + + log.debug("show multiple hashdatainput dialog"); + mainPanel.removeAll(); buttonPanel.removeAll(); @@ -1166,10 +1235,15 @@ public class BKUGUI implements BKUGUIFacade { private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { + log.debug("scheduling save hashdatainput dialog"); + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { + + log.debug("show save hashdatainput dialog"); + String userHome = System.getProperty("user.home"); JFileChooser fileDialog = new JFileChooser(userHome); -- cgit v1.2.3 From 8ccd9ab69dc74762567930f4c576a359502f1071 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 30 Sep 2008 16:37:59 +0000 Subject: showErrorDialog l10n git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@77 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 41 +++++++++++++--------- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 14 ++++++-- 2 files changed, 36 insertions(+), 19 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 749207ee..b09669b8 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -41,6 +41,8 @@ import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -94,7 +96,7 @@ public class BKUGUI implements BKUGUIFacade { private static final String MESSAGE_OVERWRITE = "message.overwrite"; private static final String LABEL_PIN = "label.pin"; private static final String LABEL_PINSIZE = "label.pinsize"; - private static final String ERROR_NO_HASHDATA = "error.no.hashdata"; +// private static final String ERROR_NO_HASHDATA = "error.no.hashdata"; private static final String BUTTON_OK = "button.ok"; private static final String BUTTON_CANCEL = "button.cancel"; @@ -798,7 +800,7 @@ public class BKUGUI implements BKUGUIFacade { } @Override - public void showErrorDialog(final String errorMsg, final ActionListener okListener, final String okCommand) { + public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams, final ActionListener okListener, final String okCommand) { log.debug("scheduling error dialog"); @@ -815,9 +817,12 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); + String errorMsgPattern = messages.getString(errorMsgKey); + String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); + JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("" + errorMsg + ""); + errorMsgLabel.setText(errorMsg); errorMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -860,7 +865,7 @@ public class BKUGUI implements BKUGUIFacade { } @Override - public void showErrorDialog(final String errorMsg) { + public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams) { log.debug("scheduling error dialog"); @@ -877,10 +882,13 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("" + errorMsg + ""); - errorMsgLabel.setForeground(ERROR_COLOR); + String errorMsgPattern = messages.getString(errorMsgKey); + String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText(errorMsg); + errorMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -955,7 +963,7 @@ public class BKUGUI implements BKUGUIFacade { public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { if (signedReferences == null) { - showErrorDialog(messages.getString(ERROR_NO_HASHDATA), okListener, okCommand); + showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); } if (signedReferences.size() == 1) { @@ -971,11 +979,12 @@ public class BKUGUI implements BKUGUIFacade { showSaveHashDataInputDialog(signedReferences, okListener, okCommand); } }; - String hashDataText = getText(signedReferences.get(0)); - if (hashDataText != null) { + + try { + String hashDataText = getText(signedReferences.get(0)); showPlainTextHashDataInputDialog(hashDataText, saveHashDataListener, "save", okListener, okCommand); - } else { - showErrorDialog(messages.getString(ERROR_NO_HASHDATA), okListener, okCommand); + } catch (IOException ex) { + showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {ex.getMessage()}, okListener, okCommand); } } else { @@ -1300,7 +1309,7 @@ public class BKUGUI implements BKUGUIFacade { bos.close(); } catch (IOException ex) { log.error("Failed to write HashDataInput to file " + file + ": " + ex.getMessage()); - showErrorDialog("Failed to write signed reference to file: " + ex.getMessage(), null, null); + showErrorDialog(ERR_WRITE_HASHDATA, new Object[] {ex.getMessage()}, null, null); ex.printStackTrace(); } finally { try { @@ -1316,7 +1325,7 @@ public class BKUGUI implements BKUGUIFacade { }); } - private static String getText(HashDataInput hdi) { + private static String getText(HashDataInput hdi) throws IOException { ByteArrayOutputStream baos = null; try { InputStream hashDataIS = hdi.getHashDataInput(); @@ -1338,7 +1347,7 @@ public class BKUGUI implements BKUGUIFacade { } } catch (IOException ex) { log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); - return null; + throw ex; } finally { try { baos.close(); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index f4b6325d..32eb4c3e 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -23,7 +23,15 @@ import java.awt.event.ActionListener; import java.util.List; public interface BKUGUIFacade { - + + public static final String ERR_UNKNOWN = "error.unknown"; + public static final String ERR_SERVICE_UNREACHABLE = "error.ws.unreachable"; + public static final String ERR_NO_PCSC = "error.pcsc"; + public static final String ERR_NO_CARDTERMINAL = "error.cardterminal"; + public static final String ERR_NO_HASHDATA = "error.no.hashdata"; + public static final String ERR_WRITE_HASHDATA = "error.write.hashdata"; + public static final String ERR_INVALID_HASH = "error.invalid.hash"; + public void init(Container contentPane, String localeString); public void showWelcomeDialog(); @@ -55,7 +63,7 @@ public interface BKUGUIFacade { // public void showPlainTextHashDataInputDialog(String text, ActionListener saveListener, String saveCommand, ActionListener cancelListener, String cancelCommand); - public void showErrorDialog(String errorMsg, ActionListener okListener, String actionCommand); + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String actionCommand); - public void showErrorDialog(String errorMsg); + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams); } -- cgit v1.2.3 From d7a3b8fdb62c881afb87838f2bb03b4c4b58e16d Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 8 Oct 2008 15:59:43 +0000 Subject: simpleGUI (header,chipperling removed) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@87 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 295 ++++++++++----------- 1 file changed, 141 insertions(+), 154 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index b09669b8..24cc2601 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -40,11 +40,7 @@ import java.text.MessageFormat; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; -import java.util.StringTokenizer; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.GroupLayout; -import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFileChooser; @@ -56,7 +52,6 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.LayoutStyle; -import javax.swing.ScrollPaneConstants; import javax.swing.SwingUtilities; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; @@ -107,14 +102,14 @@ public class BKUGUI implements BKUGUIFacade { protected Container contentPane; protected ResourceBundle messages; /** left and right side main panels */ - protected JPanel iconPanel; +// protected JPanel iconPanel; protected JPanel contentPanel; /** right side content panels and layouts */ - protected JPanel headerPanel; +// protected JPanel headerPanel; protected JPanel mainPanel; protected JPanel buttonPanel; /** right side fixed labels */ - protected JLabel titleLabel; +// protected JLabel titleLabel; /** remember the pinfield to return to worker */ protected JPasswordField pinField; @@ -153,13 +148,21 @@ public class BKUGUI implements BKUGUIFacade { log.debug("initializing gui"); - initIconPanel(); +// initIconPanel(); initContentPanel(); GroupLayout layout = new GroupLayout(contentPane); contentPane.setLayout(layout); - layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); - layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(contentPanel)); + layout.setVerticalGroup(layout.createSequentialGroup().addComponent(contentPanel)); +// layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(layout.createSequentialGroup() +// .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); +// layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); } }); } catch (Exception ex) { @@ -167,34 +170,30 @@ public class BKUGUI implements BKUGUIFacade { } } - protected void initIconPanel() { - iconPanel = new JPanel(); - JLabel iconLabel = new JLabel(); - iconLabel.setIcon(new ImageIcon(getClass().getResource(LOGO_RESOURCE))); // NOI18N - - GroupLayout iconPanelLayout = new GroupLayout(iconPanel); - iconPanel.setLayout(iconPanelLayout); - iconPanelLayout.setHorizontalGroup( - iconPanelLayout.createSequentialGroup() -// iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(iconPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().width, GroupLayout.PREFERRED_SIZE) - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); - iconPanelLayout.setVerticalGroup( - iconPanelLayout.createSequentialGroup() -// iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(iconPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().height, GroupLayout.PREFERRED_SIZE) - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); - } +// protected void initIconPanel() { +// iconPanel = new JPanel(); +// JLabel iconLabel = new JLabel(); +// iconLabel.setIcon(new ImageIcon(getClass().getResource(LOGO_RESOURCE))); // NOI18N +// +// GroupLayout iconPanelLayout = new GroupLayout(iconPanel); +// iconPanel.setLayout(iconPanelLayout); +// iconPanelLayout.setHorizontalGroup( +// iconPanelLayout.createSequentialGroup() +// .addContainerGap() +// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().width, GroupLayout.PREFERRED_SIZE) +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); +// iconPanelLayout.setVerticalGroup( +// iconPanelLayout.createSequentialGroup() +// .addContainerGap() +// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().height, GroupLayout.PREFERRED_SIZE) +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); +// } protected void initContentPanel() { contentPanel = new JPanel(); - headerPanel = new JPanel(); +// headerPanel = new JPanel(); mainPanel = new JPanel(); buttonPanel = new JPanel(); @@ -202,22 +201,9 @@ public class BKUGUI implements BKUGUIFacade { // mainPanel.setBorder(new TitledBorder("main")); // buttonPanel.setBorder(new TitledBorder("button")); - titleLabel = new JLabel(); - titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | - java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); -// titleLabel.setForeground(defaultForground); - -// okButton = new JButton(); -// okButton.setText(messages.getString(BUTTON_OK)); -// cancelButton = new JButton(); -// cancelButton.setText(messages.getString(BUTTON_CANCEL)); -// signButton = new JButton(); -// signButton.setText(messages.getString(BUTTON_SIGN)); -// backButton = new JButton(); -// backButton.setText(messages.getString(BUTTON_BACK)); -// saveButton = new JButton(); -// saveButton.setText(messages.getString(BUTTON_SAVE)); -// contentPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); +// titleLabel = new JLabel(); +// titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | +// java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); JButton b = new JButton(); b.setText(messages.getString(BUTTON_CANCEL)); @@ -246,33 +232,38 @@ public class BKUGUI implements BKUGUIFacade { // buttonSize = saveButton.getPreferredSize().width; - GroupLayout headerPanelLayout = new GroupLayout(headerPanel); - headerPanel.setLayout(headerPanelLayout); - - headerPanelLayout.setHorizontalGroup( - headerPanelLayout.createSequentialGroup() -// headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) - .addContainerGap()); - headerPanelLayout.setVerticalGroup( - headerPanelLayout.createSequentialGroup() -// headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); +// GroupLayout headerPanelLayout = new GroupLayout(headerPanel); +// headerPanel.setLayout(headerPanelLayout); +// +// headerPanelLayout.setHorizontalGroup( +// headerPanelLayout.createSequentialGroup() +// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) +// .addContainerGap()); +// headerPanelLayout.setVerticalGroup( +// headerPanelLayout.createSequentialGroup() +// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); -// mainPanel.setPreferredSize(new Dimension(MAIN_PANEL_WIDTH, MAIN_PANEL_HEIGHT)); GroupLayout contentPanelLayout = new GroupLayout(contentPanel); contentPanel.setLayout(contentPanelLayout); +// contentPanelLayout.setHorizontalGroup( +// contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //)); contentPanelLayout.setHorizontalGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //)); + contentPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup( + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); contentPanelLayout.setVerticalGroup( contentPanelLayout.createSequentialGroup() .addContainerGap() - .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) @@ -294,8 +285,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_ERROR)); -// titleLabel.setForeground(defaultForground); +// titleLabel.setText(messages.getString(TITLE_ERROR)); JLabel waitMsgLabel = new JLabel(); waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -308,8 +298,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(waitMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitMsgLabel)); @@ -334,12 +323,11 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_WELCOME)); -// titleLabel.setForeground(defaultForground); +// titleLabel.setText(messages.getString(TITLE_WELCOME)); - JLabel waitMsgLabel = new JLabel(); - waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + JLabel welcomeMsgLabel = new JLabel(); + welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); //MESSAGE_WAIT)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -347,12 +335,11 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(welcomeMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel)); + .addComponent(welcomeMsgLabel)); contentPanel.validate(); @@ -375,8 +362,24 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_INSERTCARD)); +// titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + JLabel insertCardMsgLabel = new JLabel(); + insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel)); + JButton cancelButton = new JButton(); cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); @@ -391,8 +394,7 @@ public class BKUGUI implements BKUGUIFacade { // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) // .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); //); + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -403,6 +405,11 @@ public class BKUGUI implements BKUGUIFacade { }); } + /** + * only difference to showInsertCard: title text: card not supported + * @param cancelListener + * @param cancelCommand + */ @Override public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { @@ -418,12 +425,11 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); -// titleLabel.setForeground(defaultForground); +// titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + JLabel insertCardMsgLabel = new JLabel(); + insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -431,12 +437,11 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(insertCardMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel)); + .addComponent(insertCardMsgLabel)); JButton cancelButton = new JButton(); cancelButton.setText(messages.getString(BUTTON_CANCEL)); @@ -452,8 +457,7 @@ public class BKUGUI implements BKUGUIFacade { // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) // .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); //); + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -478,12 +482,12 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - if (numRetries < 0) { - String cardpinTitle = messages.getString(TITLE_CARDPIN); - titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); - } else { - titleLabel.setText(messages.getString(TITLE_RETRY)); - } +// if (numRetries < 0) { +// String cardpinTitle = messages.getString(TITLE_CARDPIN); +// titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); +// } else { +// titleLabel.setText(messages.getString(TITLE_RETRY)); +// } JButton cancelButton = new JButton(); cancelButton.setText(messages.getString(BUTTON_CANCEL)); @@ -572,8 +576,7 @@ public class BKUGUI implements BKUGUIFacade { .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) - .addComponent(infoLabel)) - .addContainerGap()); + .addComponent(infoLabel))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() @@ -595,8 +598,7 @@ public class BKUGUI implements BKUGUIFacade { .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap());//); + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(okButton) @@ -643,11 +645,11 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - if (numRetries < 0) { - titleLabel.setText(messages.getString(TITLE_SIGN)); - } else { - titleLabel.setText(messages.getString(TITLE_RETRY)); - } +// if (numRetries < 0) { +// titleLabel.setText(messages.getString(TITLE_SIGN)); +// } else { +// titleLabel.setText(messages.getString(TITLE_RETRY)); +// } JButton cancelButton = new JButton(); cancelButton.setText(messages.getString(BUTTON_CANCEL)); @@ -712,16 +714,14 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(hashDataLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() - .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(infoLabel)))) - .addContainerGap()); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(hashDataLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(infoLabel)))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() @@ -743,8 +743,7 @@ public class BKUGUI implements BKUGUIFacade { .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap());//); + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(signButton) @@ -814,8 +813,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_ERROR)); -// titleLabel.setForeground(defaultForground); +// titleLabel.setText(messages.getString(TITLE_ERROR)); String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -831,8 +829,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel) //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); - .addContainerGap()); + .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -852,8 +849,7 @@ public class BKUGUI implements BKUGUIFacade { // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) // .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); //); + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -879,16 +875,15 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_ERROR)); -// titleLabel.setForeground(defaultForground); +// titleLabel.setText(messages.getString(TITLE_ERROR)); String errorMsgPattern = messages.getString(errorMsgKey); - String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); - - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(errorMsg); - errorMsgLabel.setForeground(ERROR_COLOR); + String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText(errorMsg); + errorMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -896,8 +891,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -923,7 +917,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_WAIT)); +// titleLabel.setText(messages.getString(TITLE_WAIT)); JLabel waitMsgLabel = new JLabel(); waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -939,8 +933,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(waitMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -1020,7 +1013,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_HASHDATA)); +// titleLabel.setText(messages.getString(TITLE_HASHDATA)); JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -1042,11 +1035,9 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)) - .addContainerGap()); + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() @@ -1082,8 +1073,7 @@ public class BKUGUI implements BKUGUIFacade { .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(saveButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(saveButton) @@ -1117,7 +1107,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_HASHDATA)); +// titleLabel.setText(messages.getString(TITLE_HASHDATA)); JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -1142,11 +1132,9 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)) // GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()); + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() @@ -1228,8 +1216,7 @@ public class BKUGUI implements BKUGUIFacade { .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(saveButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap());//); + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(saveButton) -- cgit v1.2.3 From a8d050168ad30c59087d9b8f7b399f0ffbb671d8 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 9 Oct 2008 07:54:29 +0000 Subject: SimpleGUI (one button) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@88 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 2 +- .../java/at/gv/egiz/bku/gui/BKUGUIFactory.java | 32 +- .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 1451 ++++++++++++++++++++ 3 files changed, 1468 insertions(+), 17 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 24cc2601..636a9fef 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -429,7 +429,7 @@ public class BKUGUI implements BKUGUIFacade { JLabel insertCardMsgLabel = new JLabel(); insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); //MESSAGE_INSERTCARD)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java index 478b949b..5124914a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java @@ -14,19 +14,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.gui; - -public class BKUGUIFactory { - private static BKUGUIFactory instance = new BKUGUIFactory(); - - private BKUGUIFactory() { - } - - protected BKUGUIFacade createNewGUI() { - return new BKUGUI(); - } - - public static BKUGUIFacade createGUI() { - return instance.createNewGUI(); - } -} +package at.gv.egiz.bku.gui; + +public class BKUGUIFactory { + private static BKUGUIFactory instance = new BKUGUIFactory(); + + private BKUGUIFactory() { + } + + protected BKUGUIFacade createNewGUI() { + return new SimpleGUI(); + } + + public static BKUGUIFacade createGUI() { + return instance.createNewGUI(); + } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java new file mode 100644 index 00000000..b7d86d05 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -0,0 +1,1451 @@ +/* + * 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. + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package at.gv.egiz.bku.gui; + +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.stal.HashDataInput; +import java.awt.Color; +import java.awt.Container; +import java.awt.Cursor; +import java.awt.Font; +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.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; +import javax.swing.GroupLayout; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.LayoutStyle; +import javax.swing.SwingUtilities; +import javax.swing.table.TableColumn; +import javax.swing.table.TableModel; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author clemens + */ +public class SimpleGUI implements BKUGUIFacade { + + private static final Log log = LogFactory.getLog(SimpleGUI.class); + public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; + public static final String LOGO_RESOURCE = "/images/logo.png"; + public static final String HASHDATA_FONT = "Monospaced"; + public static final Color ERROR_COLOR = Color.RED; + public static final Color HYPERLINK_COLOR = Color.BLUE; + private static final String TITLE_WELCOME = "title.welcome"; + private static final String TITLE_INSERTCARD = "title.insertcard"; + private static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; + private static final String TITLE_CARDPIN = "title.cardpin"; + private static final String TITLE_SIGN = "title.sign"; + private static final String TITLE_ERROR = "title.error"; + private static final String TITLE_RETRY = "title.retry"; + private static final String TITLE_WAIT = "title.wait"; + private static final String TITLE_HASHDATA = "title.hashdata"; + private static final String WINDOWTITLE_SAVE = "windowtitle.save"; + private static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; + private static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; + private static final String MESSAGE_WAIT = "message.wait"; + private static final String MESSAGE_INSERTCARD = "message.insertcard"; + private static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; + private static final String MESSAGE_HASHDATA = "message.hashdata"; + private static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; + private static final String MESSAGE_RETRIES = "message.retries"; + private static final String MESSAGE_OVERWRITE = "message.overwrite"; + private static final String LABEL_PIN = "label.pin"; + private static final String LABEL_PINSIZE = "label.pinsize"; +// private static final String ERROR_NO_HASHDATA = "error.no.hashdata"; + + private static final String BUTTON_OK = "button.ok"; + private static final String BUTTON_CANCEL = "button.cancel"; + private static final String BUTTON_BACK = "button.back"; + private static final String BUTTON_SIGN = "button.sign"; + private static final String BUTTON_SAVE = "button.save"; + private static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; + protected Container contentPane; + protected ResourceBundle messages; + /** left and right side main panels */ +// protected JPanel iconPanel; + protected JPanel contentPanel; + /** right side content panels and layouts */ +// protected JPanel headerPanel; + protected JPanel mainPanel; + protected JPanel buttonPanel; + /** right side fixed labels */ +// protected JLabel titleLabel; + /** remember the pinfield to return to worker */ + protected JPasswordField pinField; + +// protected JButton okButton; +// protected JButton cancelButton; +// protected JButton signButton; +// protected JButton saveButton; +// protected JButton backButton; + protected int buttonSize; + + private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; + + /** + * @param contentPane + * @param localeString may be null + */ + @Override + public void init(final Container contentPane, String localeString) { + + if (localeString != null) { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); + } else { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); + } + + this.contentPane = contentPane; + + try { + + log.debug("scheduling gui initialization"); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + + log.debug("initializing gui"); + +// initIconPanel(); + initContentPanel(); + + GroupLayout layout = new GroupLayout(contentPane); + contentPane.setLayout(layout); + layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(contentPanel)); + layout.setVerticalGroup(layout.createSequentialGroup().addComponent(contentPanel)); +// layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(layout.createSequentialGroup() +// .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); +// layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + } + }); + } catch (Exception ex) { + throw new RuntimeException("Failed to init GUI: " + ex.getMessage()); + } + } + +// protected void initIconPanel() { +// iconPanel = new JPanel(); +// JLabel iconLabel = new JLabel(); +// iconLabel.setIcon(new ImageIcon(getClass().getResource(LOGO_RESOURCE))); // NOI18N +// +// GroupLayout iconPanelLayout = new GroupLayout(iconPanel); +// iconPanel.setLayout(iconPanelLayout); +// iconPanelLayout.setHorizontalGroup( +// iconPanelLayout.createSequentialGroup() +// .addContainerGap() +// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().width, GroupLayout.PREFERRED_SIZE) +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); +// iconPanelLayout.setVerticalGroup( +// iconPanelLayout.createSequentialGroup() +// .addContainerGap() +// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().height, GroupLayout.PREFERRED_SIZE) +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); +// } + + protected void initContentPanel() { + + contentPanel = new JPanel(); + +// headerPanel = new JPanel(); + mainPanel = new JPanel(); + buttonPanel = new JPanel(); + +// headerPanel.setBorder(new TitledBorder("header")); +// mainPanel.setBorder(new TitledBorder("main")); +// buttonPanel.setBorder(new TitledBorder("button")); + +// titleLabel = new JLabel(); +// titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | +// java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); + + JButton b = new JButton(); +// b.setText(messages.getString(BUTTON_CANCEL)); +// if (b.getPreferredSize().width > buttonSize) +// buttonSize = b.getPreferredSize().width; + b.setText(messages.getString(BUTTON_OK)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + b.setText(messages.getString(BUTTON_SIGN)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + b.setText(messages.getString(BUTTON_BACK)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; +// b.setText(messages.getString(BUTTON_SAVE)); +// if (b.getPreferredSize().width > buttonSize) +// buttonSize = b.getPreferredSize().width; + +// if (cancelButton.getPreferredSize().width > buttonSize) +// buttonSize = cancelButton.getPreferredSize().width; +// if (signButton.getPreferredSize().width > buttonSize) +// buttonSize = signButton.getPreferredSize().width; +// if (backButton.getPreferredSize().width > buttonSize) +// buttonSize = backButton.getPreferredSize().width; +// if (saveButton.getPreferredSize().width > buttonSize) +// buttonSize = saveButton.getPreferredSize().width; + + +// GroupLayout headerPanelLayout = new GroupLayout(headerPanel); +// headerPanel.setLayout(headerPanelLayout); +// +// headerPanelLayout.setHorizontalGroup( +// headerPanelLayout.createSequentialGroup() +// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) +// .addContainerGap()); +// headerPanelLayout.setVerticalGroup( +// headerPanelLayout.createSequentialGroup() +// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + + + GroupLayout contentPanelLayout = new GroupLayout(contentPanel); + contentPanel.setLayout(contentPanelLayout); +// contentPanelLayout.setHorizontalGroup( +// contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //)); + contentPanelLayout.setHorizontalGroup( + contentPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup( + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); + contentPanelLayout.setVerticalGroup( + contentPanelLayout.createSequentialGroup() + .addContainerGap() +// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); //); + } + + @Override + public void showLoginDialog(ActionListener loginListener, String actionCommand) { + + log.debug("scheduling login dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show login dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + +// titleLabel.setText(messages.getString(TITLE_ERROR)); + + JLabel waitMsgLabel = new JLabel(); + waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + waitMsgLabel.setText("LoginDialog not supported yet."); + waitMsgLabel.setForeground(ERROR_COLOR); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); + + contentPanel.validate(); + } + }); + } + + @Override + public void showWelcomeDialog() { + + log.debug("scheduling welcome dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show welcome dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + +// titleLabel.setText(messages.getString(TITLE_WELCOME)); + + JLabel welcomeMsgLabel = new JLabel(); + welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); //MESSAGE_WAIT)); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(welcomeMsgLabel)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(welcomeMsgLabel)); + + contentPanel.validate(); + + } + }); + } + + @Override + public void showInsertCardDialog(final ActionListener cancelListener, final String cancelCommand) { + + log.debug("scheduling insert card dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show insert card dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + +// titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + + JLabel insertCardMsgLabel = new JLabel(); + insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel)); + +// JButton cancelButton = new JButton(); +// cancelButton.setText(messages.getString(BUTTON_CANCEL)); +// cancelButton.addActionListener(cancelListener); +// cancelButton.setActionCommand(cancelCommand); +// +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addComponent(cancelButton)); + + contentPanel.validate(); + } + }); + } + + /** + * only difference to showInsertCard: title text: card not supported + * @param cancelListener + * @param cancelCommand + */ + @Override + public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { + + log.debug("scheduling card not supported dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show card not supported dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + +// titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + + JLabel insertCardMsgLabel = new JLabel(); + insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); //MESSAGE_INSERTCARD)); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel)); + +// JButton cancelButton = new JButton(); +// cancelButton.setText(messages.getString(BUTTON_CANCEL)); +// cancelButton.addActionListener(cancelListener); +// cancelButton.setActionCommand(cancelCommand); +// +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addComponent(cancelButton)); + + contentPanel.validate(); + } + }); + } + + private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { + + log.debug("scheduling card-pin dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show card-pin dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + +// if (numRetries < 0) { +// String cardpinTitle = messages.getString(TITLE_CARDPIN); +// titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); +// } else { +// titleLabel.setText(messages.getString(TITLE_RETRY)); +// } + +// JButton cancelButton = new JButton(); +// cancelButton.setText(messages.getString(BUTTON_CANCEL)); +// cancelButton.setActionCommand(cancelCommand); +// cancelButton.addActionListener(cancelListener); + + JButton okButton = new JButton(); + okButton.setText(messages.getString(BUTTON_OK)); + okButton.setEnabled(false); + okButton.setActionCommand(okCommand); + okButton.addActionListener(okListener); + + JLabel cardPinLabel = new JLabel(); + cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); + String pinLabel = messages.getString(LABEL_PIN); + cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); + +// JPasswordField cardPINField = new JPasswordField(); + pinField = new JPasswordField(); + pinField.setText(""); + pinField.setDocument(new PINDocument(pinSpec, okButton)); + pinField.setActionCommand(okCommand); + pinField.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (pinField.getPassword().length >= pinSpec.getMinLength()) { + okListener.actionPerformed(e); + } + } + }); + + JLabel infoLabel = new JLabel(); + if (numRetries < 0) { + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + } else { + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); + infoLabel.setForeground(ERROR_COLOR); + } + +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// mainPanelLayout.setHorizontalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(mainPanelLayout.createSequentialGroup() // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// // .addComponent(hashDataLabel) +// // .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() +// .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) //RELATED) +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) //TRAILING) +// .addComponent(infoLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) +// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)) //)) +// .addContainerGap())); +// +// mainPanelLayout.setVerticalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) //, false) +// .addComponent(cardPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) +// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(infoLabel).addGap(cardPinLabel.getFont().getSize()))); //10, 10, 10))); +// +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(okButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(cancelButton))); + + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) //)) + .addComponent(infoLabel)); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() +// .addComponent(hashDataLabel) +// .addGap(hashDataLabel.getFont().getSize()) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cardPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(infoLabel)); +// .addGap(signPinLabel.getFont().getSize())); + + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(okButton)); + +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) +// .addComponent(okButton) +// .addComponent(cancelButton)); + + pinField.requestFocusInWindow(); + contentPanel.validate(); + + } + }); + } + + @Override + public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { + showCardPINDialog(pinSpec, -1, okListener, okCommand, cancelListener, cancelCommand); + } + + @Override + public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { + showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); + } + + @Override + public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { + showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); + } + + @Override + public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { + showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); + } + + private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { + + log.debug("scheduling signature-pin dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show signature-pin dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + +// if (numRetries < 0) { +// titleLabel.setText(messages.getString(TITLE_SIGN)); +// } else { +// titleLabel.setText(messages.getString(TITLE_RETRY)); +// } + +// JButton cancelButton = new JButton(); +// cancelButton.setText(messages.getString(BUTTON_CANCEL)); +// cancelButton.setActionCommand(cancelCommand); +// cancelButton.addActionListener(cancelListener); + + JButton signButton = new JButton(); + signButton.setText(messages.getString(BUTTON_SIGN)); + signButton.setEnabled(false); + signButton.setActionCommand(signCommand); + signButton.addActionListener(signListener); + + JLabel signPinLabel = new JLabel(); + signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); + String pinLabel = messages.getString(LABEL_PIN); + signPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); + + pinField = new JPasswordField(); + pinField.setText(""); + pinField.setDocument(new PINDocument(pinSpec, signButton)); + pinField.setActionCommand(signCommand); + pinField.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (pinField.getPassword().length >= pinSpec.getMinLength()) { + signListener.actionPerformed(e); + } + } + }); + + //pinsize or error label + JLabel infoLabel = new JLabel(); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (numRetries < 0) { + String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + } else { + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); + infoLabel.setForeground(ERROR_COLOR); + } + + JLabel hashDataLabel = new JLabel(); + hashDataLabel.setFont(hashDataLabel.getFont().deriveFont(hashDataLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + hashDataLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); + hashDataLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + hashDataLabel.setForeground(HYPERLINK_COLOR); + hashDataLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent me) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e); + } + }); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(hashDataLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(infoLabel)); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addComponent(hashDataLabel) + .addGap(hashDataLabel.getFont().getSize()) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(infoLabel)); +// .addGap(signPinLabel.getFont().getSize())); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(signButton)); + +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) +// .addComponent(signButton) +// .addComponent(cancelButton)); + + pinField.requestFocusInWindow(); + contentPanel.validate(); + + }// private ParallelGroup createMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { +// ParallelGroup mainGroup = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); +// mainGroup.addComponent(hashDataLabel); +// if (errorLabel != null) { +// mainGroup.addComponent(errorLabel); +// } +// mainGroup.addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() +// .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) +// .addComponent(pinSizeLabel) +// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE))); +// return mainGroup; +// } +// private GroupLayout.SequentialGroup createVerticalMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { +// GroupLayout.SequentialGroup mainGroup = mainPanelLayout.createSequentialGroup(); +// mainGroup.addComponent(hashDataLabel) +// .addGap(hashDataLabel.getFont().getSize()); //14, 14, 14) +// +// if (errorLabel != null) { +// mainGroup.addComponent(errorLabel) +// .addGap(errorLabel.getFont().getSize()); +// } +// mainGroup.addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE, false) +// .addComponent(signPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) +// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(pinSizeLabel) +// .addGap(signPinLabel.getFont().getSize()); +// +// return mainGroup; +//// mainPanelLayout.createSequentialGroup() +//// .addComponent(hashDataLabel) +//// .addGap(hashDataLabel.getFont().getSize()) //14, 14, 14) +//// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE, false) +//// .addComponent(signPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) +//// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) +//// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +//// .addComponent(pinSizeLabel) +//// .addGap(signPinLabel.getFont().getSize()) +//// +//// +// } + }); + } + + @Override + public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams, final ActionListener okListener, final String okCommand) { + + log.debug("scheduling error dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show error dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + +// titleLabel.setText(messages.getString(TITLE_ERROR)); + + String errorMsgPattern = messages.getString(errorMsgKey); + String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText(errorMsg); + errorMsgLabel.setForeground(ERROR_COLOR); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); + + JButton okButton = new JButton(); + okButton.setText(messages.getString(BUTTON_OK)); + okButton.setActionCommand(okCommand); + okButton.addActionListener(okListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(okButton)); + + contentPanel.validate(); + } + }); + } + + @Override + public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams) { + + log.debug("scheduling error dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show error dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + +// titleLabel.setText(messages.getString(TITLE_ERROR)); + + String errorMsgPattern = messages.getString(errorMsgKey); + String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText(errorMsg); + errorMsgLabel.setForeground(ERROR_COLOR); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); + + contentPanel.validate(); + } + }); + } + + @Override + public void showWaitDialog(final String waitMessage) { + + log.debug("scheduling wait dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show wait dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + +// titleLabel.setText(messages.getString(TITLE_WAIT)); + + JLabel waitMsgLabel = new JLabel(); + waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (waitMessage != null) { + waitMsgLabel.setText("" + waitMessage + ""); + } else { + waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + } + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); + + contentPanel.validate(); + } + }); + } + + @Override + public char[] getPin() { + if (pinField != null) { + return pinField.getPassword(); + } + return null; + } + + @Override + public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { + + if (signedReferences == null) { + showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); + } + + if (signedReferences.size() == 1) { + +// final HashDataInput signedRef = signedReferences.get(0); + + if ("text/plain".equals(signedReferences.get(0).getMimeType())) { + + ActionListener saveHashDataListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(signedReferences, okListener, okCommand); + } + }; + + try { + String hashDataText = getText(signedReferences.get(0)); + showPlainTextHashDataInputDialog(hashDataText, saveHashDataListener, "save", okListener, okCommand); + } catch (IOException ex) { + showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {ex.getMessage()}, okListener, okCommand); + } + + } else { + showSaveHashDataInputDialog(signedReferences, okListener, okCommand); + } + + } else { + + final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); + + ActionListener saveHashDataListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(tableModel.getSelectedHashData(), okListener, okCommand); + } + }; + showMultipleHashDataInputDialog(tableModel, okListener, okCommand, saveHashDataListener, "save"); + } + } + + private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { + + log.debug("scheduling plaintext hashdatainput dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show plaintext hashdatainput dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + +// titleLabel.setText(messages.getString(TITLE_HASHDATA)); + + JLabel refIdLabel = new JLabel(); + refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); + + JTextArea hashDataTextArea = new JTextArea(hashDataText); + hashDataTextArea.setEditable(false); +// hashDataTextArea.setColumns(1); +// hashDataTextArea.setRows(1); + hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); +// hashDataScrollPane.setViewportView(hashDataTextArea); +// hashDataScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //HORIZONTAL_SCROLLBAR_NEVER); + hashDataTextArea.setLineWrap(true); + hashDataTextArea.setWrapStyleWord(true); + + JScrollPane hashDataScrollPane = new JScrollPane(hashDataTextArea); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); + + // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + // mainPanel.setLayout(mainPanelLayout); + // + // mainPanelLayout.setHorizontalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(refIdLabel).addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)).addContainerGap())); + // + // mainPanelLayout.setVerticalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(refIdLabel).addGap(refIdLabel.getFont().getSize()).addComponent(hashDataScrollPane).addGap(refIdLabel.getFont().getSize()))); + + JButton backButton = new JButton(); + backButton.setText(messages.getString(BUTTON_BACK)); + backButton.setActionCommand(cancelCommand); + backButton.addActionListener(cancelListener); + +// JButton saveButton = new JButton(); +// saveButton.setText(messages.getString(BUTTON_SAVE)); +// saveButton.setActionCommand(saveCommand); +// saveButton.addActionListener(saveListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(backButton)); + +// 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) +// .addComponent(saveButton) +// .addComponent(backButton)); + + + // GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + // buttonPanel.setLayout(buttonPanelLayout); + // + // buttonPanelLayout.setHorizontalGroup( + // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + // buttonPanelLayout.setVerticalGroup( + // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); + + contentPanel.validate(); + } + }); + } + + private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, final ActionListener saveListener, final String saveCommand) { + + log.debug("scheduling multiple hashdatainput dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show multiple hashdatainput dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + +// titleLabel.setText(messages.getString(TITLE_HASHDATA)); + + JLabel refIdLabel = new JLabel(); + refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); + + JTable hashDataTable = new JTable(); + hashDataTable.setModel(signedReferences); + hashDataTable.setTableHeader(null); + // hashDataTable.setShowVerticalLines(false); + // hashDataTable.setRowSelectionAllowed(false); + TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); + selectCol.setMinWidth(CHECKBOX_WIDTH); + selectCol.setMaxWidth(CHECKBOX_WIDTH); + + +// hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); + + JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); + // .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)); + + + + // + // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + // mainPanel.setLayout(mainPanelLayout); + // + // mainPanelLayout.setHorizontalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addGroup(mainPanelLayout.createSequentialGroup() + // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addComponent(refIdLabel) + // .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) + // .addContainerGap())); + // + // mainPanelLayout.setVerticalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addGroup(mainPanelLayout.createSequentialGroup() + // .addComponent(refIdLabel) + // .addGap(refIdLabel.getFont().getSize()) + // .addComponent(hashDataScrollPane) + // .addGap(refIdLabel.getFont().getSize()))); + + + + + + + + + + + + + // GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + // buttonPanel.setLayout(buttonPanelLayout); + // + // buttonPanelLayout.setHorizontalGroup( + // buttonPanelLayout.createSequentialGroup() + //// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + //// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + // .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + // .addComponent(saveButton) + // .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + // .addComponent(cancelButton) + // .addContainerGap()); //); + // buttonPanelLayout.setVerticalGroup( + // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + // .addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + // .addComponent(saveButton) + // .addComponent(cancelButton)) + // .addContainerGap())); + + + JButton backButton = new JButton(); + backButton.setText(messages.getString(BUTTON_BACK)); + backButton.setActionCommand(cancelCommand); + backButton.addActionListener(cancelListener); + +// JButton saveButton = new JButton(); +// saveButton.setText(messages.getString(BUTTON_SAVE)); +// saveButton.setActionCommand(saveCommand); +// saveButton.addActionListener(saveListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(backButton)); + + +// 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) +// .addComponent(saveButton) +// .addComponent(backButton)); + + contentPanel.validate(); + } + }); + } + +// private DisposableFileChooser fileDialog; + + private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { + + log.debug("scheduling save hashdatainput dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show save hashdatainput dialog"); + + String userHome = System.getProperty("user.home"); + + JFileChooser fileDialog = new JFileChooser(userHome); + fileDialog.setMultiSelectionEnabled(false); + fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); + fileDialog.setFileHidingEnabled(true); + if (signedRefs.size() == 1) { + fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); + fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); + String mimeType = signedRefs.get(0).getMimeType(); + MimeFilter mimeFilter = new MimeFilter(mimeType, messages); + fileDialog.setFileFilter(mimeFilter); + String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); + fileDialog.setSelectedFile(new File(userHome, filename)); + } else { + fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVEDIR)); + fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + } + + //parent contentPane -> placed over applet + switch (fileDialog.showSaveDialog(fileDialog)) { + case JFileChooser.APPROVE_OPTION: + File f = fileDialog.getSelectedFile(); + for (HashDataInput hashDataInput : signedRefs) { + String mimeType = hashDataInput.getMimeType(); + String id = hashDataInput.getReferenceId(); + File file; + if (f.isDirectory()) { + String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); + file = new File(f, filename); + } else { + file = f; + } + if (file.exists()) { + String ovrwrt = messages.getString(MESSAGE_OVERWRITE); + int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), messages.getString(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); + if (overwrite != JOptionPane.OK_OPTION) { + continue; + } + } + if (log.isDebugEnabled()) { + log.debug("Writing HashDataInput " + 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 HashDataInput to file " + file + ": " + ex.getMessage()); + showErrorDialog(ERR_WRITE_HASHDATA, new Object[] {ex.getMessage()}, null, null); + ex.printStackTrace(); + } finally { + try { + fos.close(); + } catch (IOException ex) { + } + } + } + } + log.debug("done saving hashdatainput"); + okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); + } + }); + } + + private static String getText(HashDataInput hdi) throws IOException { + ByteArrayOutputStream baos = null; + try { + InputStream hashDataIS = hdi.getHashDataInput(); + if (hashDataIS == null) { + log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); + return null; + } else { + baos = new ByteArrayOutputStream(hashDataIS.available()); + int c; + while ((c = hashDataIS.read()) != -1) { + baos.write(c); + } + String encoding = hdi.getEncoding(); + if (encoding == null) { + //default for URL-encoded + encoding = "UTF-8"; + } + return baos.toString(encoding); + } + } catch (IOException ex) { + log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); + throw ex; + } finally { + try { + baos.close(); + } catch (IOException ex) { + } + } + } + +// private String parseToken(final char[] terminators) { +// char ch; +// i1 = pos; +// i2 = pos; +// while (hasChar()) { +// ch = chars[pos]; +// if (isOneOf(ch, terminators)) { +// break; +// } +// i2++; +// pos++; +// } +// return getToken(false); +// } + +// private static String getCharset(String contentType) { +// +// StringTokenizer t = new StringTokenizer +// +// if (contentType == null) { +// return "UTF-8"; +// } +// +// int pos = 0; +// int len = contentType.length(); +// +// while (pos < len) { +// pos++; +// String paramName = parseToken(new char[] { +// '=', separator }); +// } +// +// HashMap params = new HashMap(); +// this.chars = chars; +// this.pos = offset; +// this.len = length; +// +// String paramName = null; +// String paramValue = null; +// while (hasChar()) { +// paramName = parseToken(new char[] { +// '=', separator }); +// paramValue = null; +// if (hasChar() && (chars[pos] == '=')) { +// pos++; // skip '=' +// paramValue = parseQuotedToken(new char[] { +// separator }); +// } +// if (hasChar() && (chars[pos] == separator)) { +// pos++; // skip separator +// } +// if ((paramName != null) && (paramName.length() > 0)) { +// if (this.lowerCaseNames) { +// paramName = paramName.toLowerCase(); +// } +// params.put(paramName, paramValue); +// } +// } +// return params; +// +// +// +// Parser +// ParameterParser pf = new ParameterParser(); +// pf.setLowerCaseNames(true); +// Map map = pf.parse(contentType, SEPERATOR); +// String retVal = (String) map.get(CHAR_SET); +// if ((retVal == null) && (replaceNullWithDefault)) { +// if (map.containsKey(APPLICATION_URL_ENCODED)) { +// // default charset for url encoded data +// return "UTF-8"; +// } +// retVal = getDefaultCharset(); +// } +// return retVal; +// } + +} -- cgit v1.2.3 From f993d336e51b9f7898aeeff2e5ae6785066d1e5b Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 9 Oct 2008 16:23:52 +0000 Subject: demo integration beta1 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@94 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 7 ++-- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 3 +- .../main/java/at/gv/egiz/bku/gui/ImagePanel.java | 37 +++++++++++++++++++++ .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 38 +++++++++++++++------- 4 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 636a9fef..53ec1088 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -36,6 +36,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.text.MessageFormat; import java.util.List; import java.util.Locale; @@ -127,7 +128,7 @@ public class BKUGUI implements BKUGUIFacade { * @param localeString may be null */ @Override - public void init(final Container contentPane, String localeString) { + public void init(final Container contentPane, String localeString, final URL background) { if (localeString != null) { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); @@ -149,7 +150,7 @@ public class BKUGUI implements BKUGUIFacade { log.debug("initializing gui"); // initIconPanel(); - initContentPanel(); + initContentPanel(background); GroupLayout layout = new GroupLayout(contentPane); contentPane.setLayout(layout); @@ -189,7 +190,7 @@ public class BKUGUI implements BKUGUIFacade { // .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); // } - protected void initContentPanel() { + protected void initContentPanel(URL background) { contentPanel = new JPanel(); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 32eb4c3e..4925e7fa 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -20,6 +20,7 @@ import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.smcc.PINSpec; import java.awt.Container; import java.awt.event.ActionListener; +import java.net.URL; import java.util.List; public interface BKUGUIFacade { @@ -32,7 +33,7 @@ public interface BKUGUIFacade { public static final String ERR_WRITE_HASHDATA = "error.write.hashdata"; public static final String ERR_INVALID_HASH = "error.invalid.hash"; - public void init(Container contentPane, String localeString); + public void init(Container contentPane, String localeString, URL background); public void showWelcomeDialog(); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java new file mode 100644 index 00000000..e9c270ce --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java @@ -0,0 +1,37 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.gui; + +import java.awt.Graphics; +import java.awt.Image; +import java.net.URL; +import javax.swing.ImageIcon; +import javax.swing.JPanel; + +/** + * + * @author clemens + */ +public class ImagePanel extends JPanel { + + protected Image backgroundImg; + + public ImagePanel(URL background) { + this(new ImageIcon(background).getImage()); + } + + public ImagePanel(Image img) { + this.backgroundImg = img; + this.setOpaque(false); + } + + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + g.drawImage(backgroundImg, 0, this.getHeight() - backgroundImg.getHeight(null), null); + } + +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index b7d86d05..8e32d67e 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -36,6 +36,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.text.MessageFormat; import java.util.List; import java.util.Locale; @@ -53,6 +54,7 @@ import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.LayoutStyle; import javax.swing.SwingUtilities; +import javax.swing.border.TitledBorder; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import org.apache.commons.logging.Log; @@ -66,7 +68,7 @@ public class SimpleGUI implements BKUGUIFacade { private static final Log log = LogFactory.getLog(SimpleGUI.class); public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; - public static final String LOGO_RESOURCE = "/images/logo.png"; + public static final String DEFAULT_BACKGROUND = "/images/mocca_default.png"; //logo.png"; public static final String HASHDATA_FONT = "Monospaced"; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; @@ -121,13 +123,13 @@ public class SimpleGUI implements BKUGUIFacade { protected int buttonSize; private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; - + /** * @param contentPane * @param localeString may be null */ @Override - public void init(final Container contentPane, String localeString) { + public void init(final Container contentPane, String localeString, final URL background) { if (localeString != null) { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); @@ -149,7 +151,7 @@ public class SimpleGUI implements BKUGUIFacade { log.debug("initializing gui"); // initIconPanel(); - initContentPanel(); + initContentPanel(background); GroupLayout layout = new GroupLayout(contentPane); contentPane.setLayout(layout); @@ -189,13 +191,20 @@ public class SimpleGUI implements BKUGUIFacade { // .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); // } - protected void initContentPanel() { + protected void initContentPanel(URL background) { - contentPanel = new JPanel(); + if (background == null) { + background = this.getClass().getResource(DEFAULT_BACKGROUND); + } + contentPanel = new ImagePanel(background); +// contentPanel.setBorder(new TitledBorder("content")); + // headerPanel = new JPanel(); mainPanel = new JPanel(); - buttonPanel = new JPanel(); + mainPanel.setOpaque(false); + buttonPanel = new JPanel(); // new ImagePanel(LOGO_RESOURCE); //new JPanel(); + buttonPanel.setOpaque(false); // headerPanel.setBorder(new TitledBorder("header")); // mainPanel.setBorder(new TitledBorder("main")); @@ -487,13 +496,14 @@ public class SimpleGUI implements BKUGUIFacade { // cancelButton.addActionListener(cancelListener); JButton okButton = new JButton(); + okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); okButton.setText(messages.getString(BUTTON_OK)); okButton.setEnabled(false); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); JLabel cardPinLabel = new JLabel(); - cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); + cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String pinLabel = messages.getString(LABEL_PIN); cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); @@ -513,8 +523,8 @@ public class SimpleGUI implements BKUGUIFacade { }); JLabel infoLabel = new JLabel(); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD, infoLabel.getFont().getSize()-2)); if (numRetries < 0) { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String pinsizePattern = messages.getString(LABEL_PINSIZE); String pinSize = String.valueOf(pinSpec.getMinLength()); if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { @@ -658,13 +668,14 @@ public class SimpleGUI implements BKUGUIFacade { // cancelButton.addActionListener(cancelListener); JButton signButton = new JButton(); + signButton.setFont(signButton.getFont().deriveFont(signButton.getFont().getStyle() & ~java.awt.Font.BOLD)); signButton.setText(messages.getString(BUTTON_SIGN)); signButton.setEnabled(false); signButton.setActionCommand(signCommand); signButton.addActionListener(signListener); JLabel signPinLabel = new JLabel(); - signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); + signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String pinLabel = messages.getString(LABEL_PIN); signPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); @@ -684,7 +695,7 @@ public class SimpleGUI implements BKUGUIFacade { //pinsize or error label JLabel infoLabel = new JLabel(); - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD, infoLabel.getFont().getSize()-2)); if (numRetries < 0) { String pinsizePattern = messages.getString(LABEL_PINSIZE); String pinSize = String.valueOf(pinSpec.getMinLength()); @@ -721,7 +732,7 @@ public class SimpleGUI implements BKUGUIFacade { .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(infoLabel)); mainPanelLayout.setVerticalGroup( @@ -847,6 +858,7 @@ public class SimpleGUI implements BKUGUIFacade { .addComponent(errorMsgLabel)); JButton okButton = new JButton(); + okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); okButton.setText(messages.getString(BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -1062,6 +1074,7 @@ public class SimpleGUI implements BKUGUIFacade { // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(refIdLabel).addGap(refIdLabel.getFont().getSize()).addComponent(hashDataScrollPane).addGap(refIdLabel.getFont().getSize()))); JButton backButton = new JButton(); + backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); backButton.setText(messages.getString(BUTTON_BACK)); backButton.setActionCommand(cancelCommand); backButton.addActionListener(cancelListener); @@ -1215,6 +1228,7 @@ public class SimpleGUI implements BKUGUIFacade { JButton backButton = new JButton(); + backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); backButton.setText(messages.getString(BUTTON_BACK)); backButton.setActionCommand(cancelCommand); backButton.addActionListener(cancelListener); -- cgit v1.2.3 From 255269ab17404fa1249c257e88815cbbee6e0d0f Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 13 Oct 2008 12:53:57 +0000 Subject: ExternalDisplaySignRequestHandler git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@105 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 1 + 1 file changed, 1 insertion(+) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 4925e7fa..0b617271 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -30,6 +30,7 @@ public interface BKUGUIFacade { public static final String ERR_NO_PCSC = "error.pcsc"; public static final String ERR_NO_CARDTERMINAL = "error.cardterminal"; public static final String ERR_NO_HASHDATA = "error.no.hashdata"; + public static final String ERR_DISPLAY_HASHDATA = "error.display.hashdata"; public static final String ERR_WRITE_HASHDATA = "error.write.hashdata"; public static final String ERR_INVALID_HASH = "error.invalid.hash"; -- cgit v1.2.3 From aa099311111a1d53f999705762aceb4005ecc187 Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 13 Oct 2008 13:59:06 +0000 Subject: config guiStyle simple/advanced, hashdatadisplay internal/external git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@107 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java index 5124914a..4a338f23 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java @@ -17,16 +17,23 @@ package at.gv.egiz.bku.gui; public class BKUGUIFactory { + + public static final String SIMPLE_GUI = "simple"; + public static final String ADVANCED_GUI = "advanced"; + private static BKUGUIFactory instance = new BKUGUIFactory(); private BKUGUIFactory() { } - protected BKUGUIFacade createNewGUI() { + protected BKUGUIFacade createNewGUI(String style) { + if (ADVANCED_GUI.equals(style)) { + return new BKUGUI(); + } return new SimpleGUI(); } - public static BKUGUIFacade createGUI() { - return instance.createNewGUI(); + public static BKUGUIFacade createGUI(String style) { + return instance.createNewGUI(style); } } -- cgit v1.2.3 From de95f8219adf98710992b6716778b174bc2d2fcc Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 13 Oct 2008 16:43:46 +0000 Subject: BKUGUI / SimpleGUI aligned git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@109 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 112 +++------------------ .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 104 +++---------------- 2 files changed, 25 insertions(+), 191 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 53ec1088..64cd9f50 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -67,7 +67,7 @@ public class BKUGUI implements BKUGUIFacade { private static final Log log = LogFactory.getLog(BKUGUI.class); public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; - public static final String LOGO_RESOURCE = "/images/logo.png"; + public static final String DEFAULT_BACKGROUND = "/images/mocca_default.png"; //logo.png"; public static final String HASHDATA_FONT = "Monospaced"; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; @@ -192,11 +192,19 @@ public class BKUGUI implements BKUGUIFacade { protected void initContentPanel(URL background) { - contentPanel = new JPanel(); + if (background == null) { + background = this.getClass().getResource(DEFAULT_BACKGROUND); + } + contentPanel = new ImagePanel(background); +// contentPanel.setBorder(new TitledBorder("content")); + // headerPanel = new JPanel(); - mainPanel = new JPanel(); - buttonPanel = new JPanel(); +// headerPanel.setOpaque(false); +// mainPanel = new JPanel(); +// mainPanel.setOpaque(false); +// buttonPanel = new JPanel(); +// buttonPanel.setOpaque(false); // headerPanel.setBorder(new TitledBorder("header")); // mainPanel.setBorder(new TitledBorder("main")); @@ -389,16 +397,12 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); -// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( buttonPanelLayout.createSequentialGroup() -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(cancelButton)); contentPanel.validate(); @@ -452,16 +456,12 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); -// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( buttonPanelLayout.createSequentialGroup() -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(cancelButton)); contentPanel.validate(); @@ -522,8 +522,8 @@ public class BKUGUI implements BKUGUIFacade { }); JLabel infoLabel = new JLabel(); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); if (numRetries < 0) { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String pinsizePattern = messages.getString(LABEL_PINSIZE); String pinSize = String.valueOf(pinSpec.getMinLength()); if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { @@ -593,7 +593,6 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); -// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) @@ -738,7 +737,6 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); -// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) @@ -844,16 +842,12 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); -// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( buttonPanelLayout.createSequentialGroup() -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(okButton)); contentPanel.validate(); @@ -1068,7 +1062,6 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); - // buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) @@ -1211,7 +1204,6 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); - // buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) @@ -1343,82 +1335,4 @@ public class BKUGUI implements BKUGUIFacade { } } } - -// private String parseToken(final char[] terminators) { -// char ch; -// i1 = pos; -// i2 = pos; -// while (hasChar()) { -// ch = chars[pos]; -// if (isOneOf(ch, terminators)) { -// break; -// } -// i2++; -// pos++; -// } -// return getToken(false); -// } - -// private static String getCharset(String contentType) { -// -// StringTokenizer t = new StringTokenizer -// -// if (contentType == null) { -// return "UTF-8"; -// } -// -// int pos = 0; -// int len = contentType.length(); -// -// while (pos < len) { -// pos++; -// String paramName = parseToken(new char[] { -// '=', separator }); -// } -// -// HashMap params = new HashMap(); -// this.chars = chars; -// this.pos = offset; -// this.len = length; -// -// String paramName = null; -// String paramValue = null; -// while (hasChar()) { -// paramName = parseToken(new char[] { -// '=', separator }); -// paramValue = null; -// if (hasChar() && (chars[pos] == '=')) { -// pos++; // skip '=' -// paramValue = parseQuotedToken(new char[] { -// separator }); -// } -// if (hasChar() && (chars[pos] == separator)) { -// pos++; // skip separator -// } -// if ((paramName != null) && (paramName.length() > 0)) { -// if (this.lowerCaseNames) { -// paramName = paramName.toLowerCase(); -// } -// params.put(paramName, paramValue); -// } -// } -// return params; -// -// -// -// Parser -// ParameterParser pf = new ParameterParser(); -// pf.setLowerCaseNames(true); -// Map map = pf.parse(contentType, SEPERATOR); -// String retVal = (String) map.get(CHAR_SET); -// if ((retVal == null) && (replaceNullWithDefault)) { -// if (map.containsKey(APPLICATION_URL_ENCODED)) { -// // default charset for url encoded data -// return "UTF-8"; -// } -// retVal = getDefaultCharset(); -// } -// return retVal; -// } - } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index 8e32d67e..e323d195 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -54,7 +54,6 @@ import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.LayoutStyle; import javax.swing.SwingUtilities; -import javax.swing.border.TitledBorder; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import org.apache.commons.logging.Log; @@ -196,14 +195,15 @@ public class SimpleGUI implements BKUGUIFacade { if (background == null) { background = this.getClass().getResource(DEFAULT_BACKGROUND); } - contentPanel = new ImagePanel(background); + contentPanel = new ImagePanel(background); // contentPanel.setBorder(new TitledBorder("content")); // headerPanel = new JPanel(); +// headerPanel.setOpaque(false); mainPanel = new JPanel(); mainPanel.setOpaque(false); - buttonPanel = new JPanel(); // new ImagePanel(LOGO_RESOURCE); //new JPanel(); + buttonPanel = new JPanel(); buttonPanel.setOpaque(false); // headerPanel.setBorder(new TitledBorder("header")); @@ -570,13 +570,12 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) //)) - .addComponent(infoLabel)); + mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) + .addComponent(infoLabel))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() @@ -589,7 +588,6 @@ public class SimpleGUI implements BKUGUIFacade { .addComponent(infoLabel)); // .addGap(signPinLabel.getFont().getSize())); - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -731,9 +729,9 @@ public class SimpleGUI implements BKUGUIFacade { .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addComponent(infoLabel)); + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(infoLabel)))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() @@ -1384,82 +1382,4 @@ public class SimpleGUI implements BKUGUIFacade { } } } - -// private String parseToken(final char[] terminators) { -// char ch; -// i1 = pos; -// i2 = pos; -// while (hasChar()) { -// ch = chars[pos]; -// if (isOneOf(ch, terminators)) { -// break; -// } -// i2++; -// pos++; -// } -// return getToken(false); -// } - -// private static String getCharset(String contentType) { -// -// StringTokenizer t = new StringTokenizer -// -// if (contentType == null) { -// return "UTF-8"; -// } -// -// int pos = 0; -// int len = contentType.length(); -// -// while (pos < len) { -// pos++; -// String paramName = parseToken(new char[] { -// '=', separator }); -// } -// -// HashMap params = new HashMap(); -// this.chars = chars; -// this.pos = offset; -// this.len = length; -// -// String paramName = null; -// String paramValue = null; -// while (hasChar()) { -// paramName = parseToken(new char[] { -// '=', separator }); -// paramValue = null; -// if (hasChar() && (chars[pos] == '=')) { -// pos++; // skip '=' -// paramValue = parseQuotedToken(new char[] { -// separator }); -// } -// if (hasChar() && (chars[pos] == separator)) { -// pos++; // skip separator -// } -// if ((paramName != null) && (paramName.length() > 0)) { -// if (this.lowerCaseNames) { -// paramName = paramName.toLowerCase(); -// } -// params.put(paramName, paramValue); -// } -// } -// return params; -// -// -// -// Parser -// ParameterParser pf = new ParameterParser(); -// pf.setLowerCaseNames(true); -// Map map = pf.parse(contentType, SEPERATOR); -// String retVal = (String) map.get(CHAR_SET); -// if ((retVal == null) && (replaceNullWithDefault)) { -// if (map.containsKey(APPLICATION_URL_ENCODED)) { -// // default charset for url encoded data -// return "UTF-8"; -// } -// retVal = getDefaultCharset(); -// } -// return retVal; -// } - } -- cgit v1.2.3 From 43cb317a0eb230205e3c8ba58ae7ce67f9fc5613 Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 13 Oct 2008 16:45:33 +0000 Subject: BKUGUI / SimpleGUI aligned git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@110 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 64cd9f50..4988ff39 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -106,7 +106,7 @@ public class BKUGUI implements BKUGUIFacade { // protected JPanel iconPanel; protected JPanel contentPanel; /** right side content panels and layouts */ -// protected JPanel headerPanel; + protected JPanel headerPanel; protected JPanel mainPanel; protected JPanel buttonPanel; /** right side fixed labels */ @@ -199,12 +199,12 @@ public class BKUGUI implements BKUGUIFacade { // contentPanel.setBorder(new TitledBorder("content")); -// headerPanel = new JPanel(); -// headerPanel.setOpaque(false); -// mainPanel = new JPanel(); -// mainPanel.setOpaque(false); -// buttonPanel = new JPanel(); -// buttonPanel.setOpaque(false); + headerPanel = new JPanel(); + headerPanel.setOpaque(false); + mainPanel = new JPanel(); + mainPanel.setOpaque(false); + buttonPanel = new JPanel(); + buttonPanel.setOpaque(false); // headerPanel.setBorder(new TitledBorder("header")); // mainPanel.setBorder(new TitledBorder("main")); -- cgit v1.2.3 From 07e77c763ae69e690e9b714586dc45ccccc0e4da Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 13 Oct 2008 16:46:34 +0000 Subject: BKUGUI / SimpleGUI aligned git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@111 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 4988ff39..42f9e518 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -106,7 +106,7 @@ public class BKUGUI implements BKUGUIFacade { // protected JPanel iconPanel; protected JPanel contentPanel; /** right side content panels and layouts */ - protected JPanel headerPanel; +// protected JPanel headerPanel; protected JPanel mainPanel; protected JPanel buttonPanel; /** right side fixed labels */ @@ -199,8 +199,8 @@ public class BKUGUI implements BKUGUIFacade { // contentPanel.setBorder(new TitledBorder("content")); - headerPanel = new JPanel(); - headerPanel.setOpaque(false); +// headerPanel = new JPanel(); +// headerPanel.setOpaque(false); mainPanel = new JPanel(); mainPanel.setOpaque(false); buttonPanel = new JPanel(); -- cgit v1.2.3 From e19102048016591ba161453b43a3a47f3d4f180c Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 13 Oct 2008 17:31:43 +0000 Subject: GUI cleanup, BKUGUI HeaderPanel git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@112 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 257 ++++----------------- .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 183 +-------------- 2 files changed, 47 insertions(+), 393 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 42f9e518..9cba293a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -106,19 +106,14 @@ public class BKUGUI implements BKUGUIFacade { // protected JPanel iconPanel; protected JPanel contentPanel; /** right side content panels and layouts */ -// protected JPanel headerPanel; + protected JPanel headerPanel; protected JPanel mainPanel; protected JPanel buttonPanel; /** right side fixed labels */ -// protected JLabel titleLabel; + protected JLabel titleLabel; /** remember the pinfield to return to worker */ protected JPasswordField pinField; -// protected JButton okButton; -// protected JButton cancelButton; -// protected JButton signButton; -// protected JButton saveButton; -// protected JButton backButton; protected int buttonSize; private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; @@ -199,8 +194,8 @@ public class BKUGUI implements BKUGUIFacade { // contentPanel.setBorder(new TitledBorder("content")); -// headerPanel = new JPanel(); -// headerPanel.setOpaque(false); + headerPanel = new JPanel(); + headerPanel.setOpaque(false); mainPanel = new JPanel(); mainPanel.setOpaque(false); buttonPanel = new JPanel(); @@ -210,9 +205,9 @@ public class BKUGUI implements BKUGUIFacade { // mainPanel.setBorder(new TitledBorder("main")); // buttonPanel.setBorder(new TitledBorder("button")); -// titleLabel = new JLabel(); -// titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | -// java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); + titleLabel = new JLabel(); + titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | + java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); JButton b = new JButton(); b.setText(messages.getString(BUTTON_CANCEL)); @@ -241,38 +236,35 @@ public class BKUGUI implements BKUGUIFacade { // buttonSize = saveButton.getPreferredSize().width; -// GroupLayout headerPanelLayout = new GroupLayout(headerPanel); -// headerPanel.setLayout(headerPanelLayout); + GroupLayout headerPanelLayout = new GroupLayout(headerPanel); + headerPanel.setLayout(headerPanelLayout); // -// headerPanelLayout.setHorizontalGroup( -// headerPanelLayout.createSequentialGroup() -// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) -// .addContainerGap()); -// headerPanelLayout.setVerticalGroup( -// headerPanelLayout.createSequentialGroup() -// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + headerPanelLayout.setHorizontalGroup( + headerPanelLayout.createSequentialGroup() + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + .addContainerGap()); + headerPanelLayout.setVerticalGroup( + headerPanelLayout.createSequentialGroup() + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); GroupLayout contentPanelLayout = new GroupLayout(contentPanel); contentPanel.setLayout(contentPanelLayout); -// contentPanelLayout.setHorizontalGroup( -// contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //)); + contentPanelLayout.setHorizontalGroup( contentPanelLayout.createSequentialGroup() .addContainerGap() .addGroup( contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()); contentPanelLayout.setVerticalGroup( contentPanelLayout.createSequentialGroup() .addContainerGap() -// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) @@ -294,7 +286,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_ERROR)); + titleLabel.setText(messages.getString(TITLE_ERROR)); JLabel waitMsgLabel = new JLabel(); waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -306,7 +298,6 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -332,22 +323,20 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_WELCOME)); + titleLabel.setText(messages.getString(TITLE_WELCOME)); JLabel welcomeMsgLabel = new JLabel(); welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); //MESSAGE_WAIT)); + welcomeMsgLabel.setText(messages.getString(MESSAGE_WAIT)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(welcomeMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(welcomeMsgLabel)); contentPanel.validate(); @@ -371,7 +360,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + titleLabel.setText(messages.getString(TITLE_INSERTCARD)); JLabel insertCardMsgLabel = new JLabel(); insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -382,11 +371,9 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(insertCardMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(insertCardMsgLabel)); JButton cancelButton = new JButton(); @@ -430,22 +417,20 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); JLabel insertCardMsgLabel = new JLabel(); insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); //MESSAGE_INSERTCARD)); + insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(insertCardMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(insertCardMsgLabel)); JButton cancelButton = new JButton(); @@ -483,12 +468,12 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// if (numRetries < 0) { -// String cardpinTitle = messages.getString(TITLE_CARDPIN); -// titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); -// } else { -// titleLabel.setText(messages.getString(TITLE_RETRY)); -// } + if (numRetries < 0) { + String cardpinTitle = messages.getString(TITLE_CARDPIN); + titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); + } else { + titleLabel.setText(messages.getString(TITLE_RETRY)); + } JButton cancelButton = new JButton(); cancelButton.setText(messages.getString(BUTTON_CANCEL)); @@ -506,7 +491,6 @@ public class BKUGUI implements BKUGUIFacade { String pinLabel = messages.getString(LABEL_PIN); cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); -// JPasswordField cardPINField = new JPasswordField(); pinField = new JPasswordField(); pinField.setText(""); pinField.setDocument(new PINDocument(pinSpec, okButton)); @@ -534,36 +518,6 @@ public class BKUGUI implements BKUGUIFacade { infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); } - -// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); -// mainPanel.setLayout(mainPanelLayout); -// -// mainPanelLayout.setHorizontalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(mainPanelLayout.createSequentialGroup() // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// // .addComponent(hashDataLabel) -// // .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() -// .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) //RELATED) -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) //TRAILING) -// .addComponent(infoLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) -// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)) //)) -// .addContainerGap())); -// -// mainPanelLayout.setVerticalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) //, false) -// .addComponent(cardPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) -// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(infoLabel).addGap(cardPinLabel.getFont().getSize()))); //10, 10, 10))); -// -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(okButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(cancelButton))); - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -588,7 +542,6 @@ public class BKUGUI implements BKUGUIFacade { .addComponent(pinField)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(infoLabel)); -// .addGap(signPinLabel.getFont().getSize())); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -645,11 +598,11 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// if (numRetries < 0) { -// titleLabel.setText(messages.getString(TITLE_SIGN)); -// } else { -// titleLabel.setText(messages.getString(TITLE_RETRY)); -// } + if (numRetries < 0) { + titleLabel.setText(messages.getString(TITLE_SIGN)); + } else { + titleLabel.setText(messages.getString(TITLE_RETRY)); + } JButton cancelButton = new JButton(); cancelButton.setText(messages.getString(BUTTON_CANCEL)); @@ -732,7 +685,6 @@ public class BKUGUI implements BKUGUIFacade { .addComponent(pinField)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(infoLabel)); -// .addGap(signPinLabel.getFont().getSize())); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -751,49 +703,7 @@ public class BKUGUI implements BKUGUIFacade { pinField.requestFocusInWindow(); contentPanel.validate(); - }// private ParallelGroup createMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { -// ParallelGroup mainGroup = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); -// mainGroup.addComponent(hashDataLabel); -// if (errorLabel != null) { -// mainGroup.addComponent(errorLabel); -// } -// mainGroup.addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() -// .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) -// .addComponent(pinSizeLabel) -// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE))); -// return mainGroup; -// } -// private GroupLayout.SequentialGroup createVerticalMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { -// GroupLayout.SequentialGroup mainGroup = mainPanelLayout.createSequentialGroup(); -// mainGroup.addComponent(hashDataLabel) -// .addGap(hashDataLabel.getFont().getSize()); //14, 14, 14) -// -// if (errorLabel != null) { -// mainGroup.addComponent(errorLabel) -// .addGap(errorLabel.getFont().getSize()); -// } -// mainGroup.addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE, false) -// .addComponent(signPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) -// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(pinSizeLabel) -// .addGap(signPinLabel.getFont().getSize()); -// -// return mainGroup; -//// mainPanelLayout.createSequentialGroup() -//// .addComponent(hashDataLabel) -//// .addGap(hashDataLabel.getFont().getSize()) //14, 14, 14) -//// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE, false) -//// .addComponent(signPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) -//// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) -//// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -//// .addComponent(pinSizeLabel) -//// .addGap(signPinLabel.getFont().getSize()) -//// -//// -// } + } }); } @@ -812,7 +722,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_ERROR)); + titleLabel.setText(messages.getString(TITLE_ERROR)); String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -827,11 +737,9 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); JButton okButton = new JButton(); @@ -870,7 +778,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_ERROR)); + titleLabel.setText(messages.getString(TITLE_ERROR)); String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -885,11 +793,9 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); contentPanel.validate(); @@ -927,11 +833,9 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitMsgLabel)); contentPanel.validate(); @@ -956,8 +860,6 @@ public class BKUGUI implements BKUGUIFacade { if (signedReferences.size() == 1) { -// final HashDataInput signedRef = signedReferences.get(0); - if ("text/plain".equals(signedReferences.get(0).getMimeType())) { ActionListener saveHashDataListener = new ActionListener() { @@ -1008,7 +910,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_HASHDATA)); + titleLabel.setText(messages.getString(TITLE_HASHDATA)); JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -1040,15 +942,6 @@ public class BKUGUI implements BKUGUIFacade { .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); - // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - // mainPanel.setLayout(mainPanelLayout); - // - // mainPanelLayout.setHorizontalGroup( - // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(refIdLabel).addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)).addContainerGap())); - // - // mainPanelLayout.setVerticalGroup( - // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(refIdLabel).addGap(refIdLabel.getFont().getSize()).addComponent(hashDataScrollPane).addGap(refIdLabel.getFont().getSize()))); - JButton backButton = new JButton(); backButton.setText(messages.getString(BUTTON_BACK)); backButton.setActionCommand(cancelCommand); @@ -1073,15 +966,6 @@ public class BKUGUI implements BKUGUIFacade { .addComponent(saveButton) .addComponent(backButton)); - - // GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - // buttonPanel.setLayout(buttonPanelLayout); - // - // buttonPanelLayout.setHorizontalGroup( - // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); - // buttonPanelLayout.setVerticalGroup( - // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); - contentPanel.validate(); } }); @@ -1101,7 +985,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_HASHDATA)); + titleLabel.setText(messages.getString(TITLE_HASHDATA)); JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -1135,61 +1019,6 @@ public class BKUGUI implements BKUGUIFacade { .addComponent(refIdLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); - // .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)); - - - - // - // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - // mainPanel.setLayout(mainPanelLayout); - // - // mainPanelLayout.setHorizontalGroup( - // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - // .addGroup(mainPanelLayout.createSequentialGroup() - // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - // .addComponent(refIdLabel) - // .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) - // .addContainerGap())); - // - // mainPanelLayout.setVerticalGroup( - // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - // .addGroup(mainPanelLayout.createSequentialGroup() - // .addComponent(refIdLabel) - // .addGap(refIdLabel.getFont().getSize()) - // .addComponent(hashDataScrollPane) - // .addGap(refIdLabel.getFont().getSize()))); - - - - - - - - - - - - - // GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - // buttonPanel.setLayout(buttonPanelLayout); - // - // buttonPanelLayout.setHorizontalGroup( - // buttonPanelLayout.createSequentialGroup() - //// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - //// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - // .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - // .addComponent(saveButton) - // .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - // .addComponent(cancelButton) - // .addContainerGap()); //); - // buttonPanelLayout.setVerticalGroup( - // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - // .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - // .addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - // .addComponent(saveButton) - // .addComponent(cancelButton)) - // .addContainerGap())); - JButton backButton = new JButton(); backButton.setText(messages.getString(BUTTON_BACK)); @@ -1220,8 +1049,6 @@ public class BKUGUI implements BKUGUIFacade { }); } -// private DisposableFileChooser fileDialog; - private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { log.debug("scheduling save hashdatainput dialog"); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index e323d195..3d47e1cd 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -114,11 +114,6 @@ public class SimpleGUI implements BKUGUIFacade { /** remember the pinfield to return to worker */ protected JPasswordField pinField; -// protected JButton okButton; -// protected JButton cancelButton; -// protected JButton signButton; -// protected JButton saveButton; -// protected JButton backButton; protected int buttonSize; private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; @@ -255,16 +250,13 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout contentPanelLayout = new GroupLayout(contentPanel); contentPanel.setLayout(contentPanelLayout); -// contentPanelLayout.setHorizontalGroup( -// contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //)); + contentPanelLayout.setHorizontalGroup( contentPanelLayout.createSequentialGroup() .addContainerGap() .addGroup( contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()); @@ -306,7 +298,6 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -336,18 +327,16 @@ public class SimpleGUI implements BKUGUIFacade { JLabel welcomeMsgLabel = new JLabel(); welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); //MESSAGE_WAIT)); + welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(welcomeMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(welcomeMsgLabel)); contentPanel.validate(); @@ -382,11 +371,9 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(insertCardMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(insertCardMsgLabel)); // JButton cancelButton = new JButton(); @@ -434,18 +421,16 @@ public class SimpleGUI implements BKUGUIFacade { JLabel insertCardMsgLabel = new JLabel(); insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); //MESSAGE_INSERTCARD)); + insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(insertCardMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(insertCardMsgLabel)); // JButton cancelButton = new JButton(); @@ -507,7 +492,6 @@ public class SimpleGUI implements BKUGUIFacade { String pinLabel = messages.getString(LABEL_PIN); cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); -// JPasswordField cardPINField = new JPasswordField(); pinField = new JPasswordField(); pinField.setText(""); pinField.setDocument(new PINDocument(pinSpec, okButton)); @@ -535,36 +519,6 @@ public class SimpleGUI implements BKUGUIFacade { infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); } - -// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); -// mainPanel.setLayout(mainPanelLayout); -// -// mainPanelLayout.setHorizontalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(mainPanelLayout.createSequentialGroup() // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// // .addComponent(hashDataLabel) -// // .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() -// .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) //RELATED) -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) //TRAILING) -// .addComponent(infoLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) -// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)) //)) -// .addContainerGap())); -// -// mainPanelLayout.setVerticalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) //, false) -// .addComponent(cardPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) -// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(infoLabel).addGap(cardPinLabel.getFont().getSize()))); //10, 10, 10))); -// -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(okButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(cancelButton))); - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -586,7 +540,6 @@ public class SimpleGUI implements BKUGUIFacade { .addComponent(pinField)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(infoLabel)); -// .addGap(signPinLabel.getFont().getSize())); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -742,7 +695,6 @@ public class SimpleGUI implements BKUGUIFacade { .addComponent(pinField)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(infoLabel)); -// .addGap(signPinLabel.getFont().getSize())); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -772,49 +724,7 @@ public class SimpleGUI implements BKUGUIFacade { pinField.requestFocusInWindow(); contentPanel.validate(); - }// private ParallelGroup createMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { -// ParallelGroup mainGroup = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); -// mainGroup.addComponent(hashDataLabel); -// if (errorLabel != null) { -// mainGroup.addComponent(errorLabel); -// } -// mainGroup.addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() -// .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) -// .addComponent(pinSizeLabel) -// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE))); -// return mainGroup; -// } -// private GroupLayout.SequentialGroup createVerticalMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { -// GroupLayout.SequentialGroup mainGroup = mainPanelLayout.createSequentialGroup(); -// mainGroup.addComponent(hashDataLabel) -// .addGap(hashDataLabel.getFont().getSize()); //14, 14, 14) -// -// if (errorLabel != null) { -// mainGroup.addComponent(errorLabel) -// .addGap(errorLabel.getFont().getSize()); -// } -// mainGroup.addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE, false) -// .addComponent(signPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) -// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(pinSizeLabel) -// .addGap(signPinLabel.getFont().getSize()); -// -// return mainGroup; -//// mainPanelLayout.createSequentialGroup() -//// .addComponent(hashDataLabel) -//// .addGap(hashDataLabel.getFont().getSize()) //14, 14, 14) -//// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE, false) -//// .addComponent(signPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) -//// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) -//// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -//// .addComponent(pinSizeLabel) -//// .addGap(signPinLabel.getFont().getSize()) -//// -//// -// } + } }); } @@ -848,11 +758,9 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); JButton okButton = new JButton(); @@ -907,11 +815,9 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); contentPanel.validate(); @@ -949,11 +855,9 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitMsgLabel)); contentPanel.validate(); @@ -978,8 +882,6 @@ public class SimpleGUI implements BKUGUIFacade { if (signedReferences.size() == 1) { -// final HashDataInput signedRef = signedReferences.get(0); - if ("text/plain".equals(signedReferences.get(0).getMimeType())) { ActionListener saveHashDataListener = new ActionListener() { @@ -1062,15 +964,6 @@ public class SimpleGUI implements BKUGUIFacade { .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); - // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - // mainPanel.setLayout(mainPanelLayout); - // - // mainPanelLayout.setHorizontalGroup( - // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(refIdLabel).addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)).addContainerGap())); - // - // mainPanelLayout.setVerticalGroup( - // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(refIdLabel).addGap(refIdLabel.getFont().getSize()).addComponent(hashDataScrollPane).addGap(refIdLabel.getFont().getSize()))); - JButton backButton = new JButton(); backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); backButton.setText(messages.getString(BUTTON_BACK)); @@ -1107,15 +1000,6 @@ public class SimpleGUI implements BKUGUIFacade { // .addComponent(saveButton) // .addComponent(backButton)); - - // GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - // buttonPanel.setLayout(buttonPanelLayout); - // - // buttonPanelLayout.setHorizontalGroup( - // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); - // buttonPanelLayout.setVerticalGroup( - // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); - contentPanel.validate(); } }); @@ -1169,61 +1053,6 @@ public class SimpleGUI implements BKUGUIFacade { .addComponent(refIdLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); - // .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)); - - - - // - // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - // mainPanel.setLayout(mainPanelLayout); - // - // mainPanelLayout.setHorizontalGroup( - // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - // .addGroup(mainPanelLayout.createSequentialGroup() - // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - // .addComponent(refIdLabel) - // .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) - // .addContainerGap())); - // - // mainPanelLayout.setVerticalGroup( - // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - // .addGroup(mainPanelLayout.createSequentialGroup() - // .addComponent(refIdLabel) - // .addGap(refIdLabel.getFont().getSize()) - // .addComponent(hashDataScrollPane) - // .addGap(refIdLabel.getFont().getSize()))); - - - - - - - - - - - - - // GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - // buttonPanel.setLayout(buttonPanelLayout); - // - // buttonPanelLayout.setHorizontalGroup( - // buttonPanelLayout.createSequentialGroup() - //// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - //// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - // .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - // .addComponent(saveButton) - // .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - // .addComponent(cancelButton) - // .addContainerGap()); //); - // buttonPanelLayout.setVerticalGroup( - // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - // .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - // .addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - // .addComponent(saveButton) - // .addComponent(cancelButton)) - // .addContainerGap())); - JButton backButton = new JButton(); backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -1266,8 +1095,6 @@ public class SimpleGUI implements BKUGUIFacade { } }); } - -// private DisposableFileChooser fileDialog; private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { -- cgit v1.2.3 From 11411c3d236e10b237ec1c7a1904e64dc2508551 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 14 Oct 2008 14:47:06 +0000 Subject: GUI retry error msg git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@115 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 143 ++++++++------------- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 38 ++++++ .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 138 ++++++++------------ 3 files changed, 151 insertions(+), 168 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 9cba293a..7e0f0447 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -22,7 +22,6 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; -import java.awt.Color; import java.awt.Container; import java.awt.Cursor; import java.awt.Font; @@ -66,40 +65,7 @@ import org.apache.commons.logging.LogFactory; public class BKUGUI implements BKUGUIFacade { private static final Log log = LogFactory.getLog(BKUGUI.class); - public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; - public static final String DEFAULT_BACKGROUND = "/images/mocca_default.png"; //logo.png"; - public static final String HASHDATA_FONT = "Monospaced"; - public static final Color ERROR_COLOR = Color.RED; - public static final Color HYPERLINK_COLOR = Color.BLUE; - private static final String TITLE_WELCOME = "title.welcome"; - private static final String TITLE_INSERTCARD = "title.insertcard"; - private static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; - private static final String TITLE_CARDPIN = "title.cardpin"; - private static final String TITLE_SIGN = "title.sign"; - private static final String TITLE_ERROR = "title.error"; - private static final String TITLE_RETRY = "title.retry"; - private static final String TITLE_WAIT = "title.wait"; - private static final String TITLE_HASHDATA = "title.hashdata"; - private static final String WINDOWTITLE_SAVE = "windowtitle.save"; - private static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; - private static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; - private static final String MESSAGE_WAIT = "message.wait"; - private static final String MESSAGE_INSERTCARD = "message.insertcard"; - private static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; - private static final String MESSAGE_HASHDATA = "message.hashdata"; - private static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; - private static final String MESSAGE_RETRIES = "message.retries"; - private static final String MESSAGE_OVERWRITE = "message.overwrite"; - private static final String LABEL_PIN = "label.pin"; - private static final String LABEL_PINSIZE = "label.pinsize"; -// private static final String ERROR_NO_HASHDATA = "error.no.hashdata"; - private static final String BUTTON_OK = "button.ok"; - private static final String BUTTON_CANCEL = "button.cancel"; - private static final String BUTTON_BACK = "button.back"; - private static final String BUTTON_SIGN = "button.sign"; - private static final String BUTTON_SAVE = "button.save"; - private static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; protected Container contentPane; protected ResourceBundle messages; /** left and right side main panels */ @@ -506,42 +472,47 @@ public class BKUGUI implements BKUGUIFacade { }); JLabel infoLabel = new JLabel(); - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); if (numRetries < 0) { - String pinsizePattern = messages.getString(LABEL_PINSIZE); - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String infoPattern = messages.getString(MESSAGE_ENTERPIN); + infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); } else { - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); - infoLabel.setForeground(ERROR_COLOR); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); + infoLabel.setForeground(ERROR_COLOR); + } + + JLabel pinsizeLabel = new JLabel(); + pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); + String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); } + pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(hashDataLabel) -// .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) - .addComponent(infoLabel))); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) + .addComponent(pinsizeLabel)))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// .addComponent(hashDataLabel) -// .addGap(hashDataLabel.getFont().getSize()) + .addComponent(infoLabel) + .addGap(infoLabel.getFont().getSize()) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(cardPinLabel) .addComponent(pinField)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(infoLabel)); + .addComponent(pinsizeLabel)); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -634,57 +605,57 @@ public class BKUGUI implements BKUGUIFacade { } }); - //pinsize or error label + JLabel pinsizeLabel = new JLabel(); + pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); + String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + JLabel infoLabel = new JLabel(); - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); if (numRetries < 0) { - String pinsizePattern = messages.getString(LABEL_PINSIZE); - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); + infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + infoLabel.setForeground(HYPERLINK_COLOR); + infoLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent me) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e); + } + }); } else { - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); - infoLabel.setForeground(ERROR_COLOR); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); + infoLabel.setForeground(ERROR_COLOR); } - JLabel hashDataLabel = new JLabel(); - hashDataLabel.setFont(hashDataLabel.getFont().deriveFont(hashDataLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - hashDataLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); - hashDataLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - hashDataLabel.setForeground(HYPERLINK_COLOR); - hashDataLabel.addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent me) { - ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); - hashdataListener.actionPerformed(e); - } - }); - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(hashDataLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(infoLabel)))); + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(pinsizeLabel)))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(hashDataLabel) - .addGap(hashDataLabel.getFont().getSize()) + .addComponent(infoLabel) + .addGap(infoLabel.getFont().getSize()) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(signPinLabel) .addComponent(pinField)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(infoLabel)); + .addComponent(pinsizeLabel)); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 0b617271..a5b7d606 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -18,6 +18,7 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.smcc.PINSpec; +import java.awt.Color; import java.awt.Container; import java.awt.event.ActionListener; import java.net.URL; @@ -34,6 +35,43 @@ public interface BKUGUIFacade { public static final String ERR_WRITE_HASHDATA = "error.write.hashdata"; public static final String ERR_INVALID_HASH = "error.invalid.hash"; + public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; + public static final String DEFAULT_BACKGROUND = "/images/mocca_default.png"; //logo.png"; + public static final String HASHDATA_FONT = "Monospaced"; + public static final Color ERROR_COLOR = Color.RED; + public static final Color HYPERLINK_COLOR = Color.BLUE; + public static final String TITLE_WELCOME = "title.welcome"; + public static final String TITLE_INSERTCARD = "title.insertcard"; + public static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; + public static final String TITLE_CARDPIN = "title.cardpin"; + public static final String TITLE_SIGN = "title.sign"; + public static final String TITLE_ERROR = "title.error"; + public static final String TITLE_RETRY = "title.retry"; + public static final String TITLE_WAIT = "title.wait"; + public static final String TITLE_HASHDATA = "title.hashdata"; + public static final String WINDOWTITLE_SAVE = "windowtitle.save"; + public static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; + public static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; + public static final String MESSAGE_WAIT = "message.wait"; + public static final String MESSAGE_INSERTCARD = "message.insertcard"; + public static final String MESSAGE_ENTERPIN = "message.enterpin"; + public static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; + public static final String MESSAGE_HASHDATA = "message.hashdata"; + public static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; + public static final String MESSAGE_RETRIES = "message.retries"; + public static final String MESSAGE_OVERWRITE = "message.overwrite"; + public static final String LABEL_PIN = "label.pin"; + public static final String LABEL_PINSIZE = "label.pinsize"; +// public static final String ERROR_NO_HASHDATA = "error.no.hashdata"; + + public static final String BUTTON_OK = "button.ok"; + public static final String BUTTON_CANCEL = "button.cancel"; + public static final String BUTTON_BACK = "button.back"; + public static final String BUTTON_SIGN = "button.sign"; + public static final String BUTTON_SAVE = "button.save"; + public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; + + public void init(Container contentPane, String localeString, URL background); public void showWelcomeDialog(); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index 3d47e1cd..c37704e2 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -22,7 +22,6 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; -import java.awt.Color; import java.awt.Container; import java.awt.Cursor; import java.awt.Font; @@ -66,40 +65,7 @@ import org.apache.commons.logging.LogFactory; public class SimpleGUI implements BKUGUIFacade { private static final Log log = LogFactory.getLog(SimpleGUI.class); - public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; - public static final String DEFAULT_BACKGROUND = "/images/mocca_default.png"; //logo.png"; - public static final String HASHDATA_FONT = "Monospaced"; - public static final Color ERROR_COLOR = Color.RED; - public static final Color HYPERLINK_COLOR = Color.BLUE; - private static final String TITLE_WELCOME = "title.welcome"; - private static final String TITLE_INSERTCARD = "title.insertcard"; - private static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; - private static final String TITLE_CARDPIN = "title.cardpin"; - private static final String TITLE_SIGN = "title.sign"; - private static final String TITLE_ERROR = "title.error"; - private static final String TITLE_RETRY = "title.retry"; - private static final String TITLE_WAIT = "title.wait"; - private static final String TITLE_HASHDATA = "title.hashdata"; - private static final String WINDOWTITLE_SAVE = "windowtitle.save"; - private static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; - private static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; - private static final String MESSAGE_WAIT = "message.wait"; - private static final String MESSAGE_INSERTCARD = "message.insertcard"; - private static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; - private static final String MESSAGE_HASHDATA = "message.hashdata"; - private static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; - private static final String MESSAGE_RETRIES = "message.retries"; - private static final String MESSAGE_OVERWRITE = "message.overwrite"; - private static final String LABEL_PIN = "label.pin"; - private static final String LABEL_PINSIZE = "label.pinsize"; -// private static final String ERROR_NO_HASHDATA = "error.no.hashdata"; - private static final String BUTTON_OK = "button.ok"; - private static final String BUTTON_CANCEL = "button.cancel"; - private static final String BUTTON_BACK = "button.back"; - private static final String BUTTON_SIGN = "button.sign"; - private static final String BUTTON_SAVE = "button.save"; - private static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; protected Container contentPane; protected ResourceBundle messages; /** left and right side main panels */ @@ -507,39 +473,47 @@ public class SimpleGUI implements BKUGUIFacade { }); JLabel infoLabel = new JLabel(); - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD, infoLabel.getFont().getSize()-2)); if (numRetries < 0) { - String pinsizePattern = messages.getString(LABEL_PINSIZE); - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String infoPattern = messages.getString(MESSAGE_ENTERPIN); + infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); } else { - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); - infoLabel.setForeground(ERROR_COLOR); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); + infoLabel.setForeground(ERROR_COLOR); + } + + JLabel pinsizeLabel = new JLabel(); + pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); + String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); } + pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) - .addComponent(infoLabel))); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) + .addComponent(pinsizeLabel)))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() -// .addComponent(hashDataLabel) -// .addGap(hashDataLabel.getFont().getSize()) + .addComponent(infoLabel) + .addGap(infoLabel.getFont().getSize()) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(cardPinLabel) .addComponent(pinField)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(infoLabel)); + .addComponent(pinsizeLabel)); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -644,57 +618,57 @@ public class SimpleGUI implements BKUGUIFacade { } }); - //pinsize or error label + JLabel pinsizeLabel = new JLabel(); + pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); + String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + JLabel infoLabel = new JLabel(); - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD, infoLabel.getFont().getSize()-2)); if (numRetries < 0) { - String pinsizePattern = messages.getString(LABEL_PINSIZE); - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); + infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + infoLabel.setForeground(HYPERLINK_COLOR); + infoLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent me) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e); + } + }); } else { - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); - infoLabel.setForeground(ERROR_COLOR); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); + infoLabel.setForeground(ERROR_COLOR); } - JLabel hashDataLabel = new JLabel(); - hashDataLabel.setFont(hashDataLabel.getFont().deriveFont(hashDataLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - hashDataLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); - hashDataLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - hashDataLabel.setForeground(HYPERLINK_COLOR); - hashDataLabel.addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent me) { - ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); - hashdataListener.actionPerformed(e); - } - }); - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(hashDataLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(infoLabel)))); + .addComponent(pinsizeLabel)))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(hashDataLabel) - .addGap(hashDataLabel.getFont().getSize()) + .addComponent(infoLabel) + .addGap(infoLabel.getFont().getSize()) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(signPinLabel) .addComponent(pinField)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(infoLabel)); + .addComponent(pinsizeLabel)); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); -- cgit v1.2.3 From 73c8f359ff94b382324665ca981b0640cc9f058f Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 16 Oct 2008 13:11:22 +0000 Subject: Background Chipperling git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@123 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index a5b7d606..ced74834 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -36,7 +36,7 @@ public interface BKUGUIFacade { public static final String ERR_INVALID_HASH = "error.invalid.hash"; public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; - public static final String DEFAULT_BACKGROUND = "/images/mocca_default.png"; //logo.png"; + public static final String DEFAULT_BACKGROUND = "/images/BackgroundChipperling.png"; public static final String HASHDATA_FONT = "Monospaced"; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; -- cgit v1.2.3 From c2ae3db1bc6dcb8ba3eb3461c05e293917c004ca Mon Sep 17 00:00:00 2001 From: mcentner Date: Thu, 30 Oct 2008 10:33:29 +0000 Subject: Updated SMCC to use exclusive access and to throw exceptions upon locked or not activated cards. Improved locale support in the security layer request and response processing. Fixed issue in STAL which prevented the use of RSA-SHA1 signatures. Added additional parameters to the applet test pages. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@128 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java index 8ae9d7a3..2054ae86 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java @@ -46,7 +46,7 @@ class PINDocument extends PlainDocument { @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { - if (pinSpec.getMaxLength() >= (getLength() + str.length())) { + if (pinSpec.getMaxLength() < 0 || pinSpec.getMaxLength() >= (getLength() + str.length())) { boolean matches = true; for (int i = 0; i < str.length(); i++) { Matcher m = pinPattern.matcher(str.substring(i, i + 1)); -- cgit v1.2.3 From 036dd1a8054c5dc818d01e238eb9480d67da478d Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 30 Oct 2008 17:43:40 +0000 Subject: Help Icon git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@130 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 140 ++++++++++----- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 14 +- .../java/at/gv/egiz/bku/gui/HelpMouseListener.java | 33 ++++ .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 200 +++++++++++++++------ 4 files changed, 282 insertions(+), 105 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 7e0f0447..27841d1c 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -41,6 +41,7 @@ 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.JCheckBox; import javax.swing.JFileChooser; @@ -66,6 +67,8 @@ public class BKUGUI implements BKUGUIFacade { private static final Log log = LogFactory.getLog(BKUGUI.class); + protected HelpMouseListener helpListener; + protected Container contentPane; protected ResourceBundle messages; /** left and right side main panels */ @@ -89,7 +92,7 @@ public class BKUGUI implements BKUGUIFacade { * @param localeString may be null */ @Override - public void init(final Container contentPane, String localeString, final URL background) { + public void init(final Container contentPane, String localeString, final URL background, ActionListener helpListener) { if (localeString != null) { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); @@ -98,6 +101,7 @@ public class BKUGUI implements BKUGUIFacade { } this.contentPane = contentPane; + registerHelpListener(helpListener); try { @@ -175,6 +179,11 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); + JLabel helpLabel = new JLabel(); + helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); + helpLabel.addMouseListener(helpListener); + helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + JButton b = new JButton(); b.setText(messages.getString(BUTTON_CANCEL)); if (b.getPreferredSize().width > buttonSize) @@ -204,15 +213,17 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout headerPanelLayout = new GroupLayout(headerPanel); headerPanel.setLayout(headerPanelLayout); -// + headerPanelLayout.setHorizontalGroup( headerPanelLayout.createSequentialGroup() - .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) - .addContainerGap()); + .addComponent(titleLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)); headerPanelLayout.setVerticalGroup( - headerPanelLayout.createSequentialGroup() - .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); - + headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) //SequentialGroup() + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + .addComponent(helpLabel)); + GroupLayout contentPanelLayout = new GroupLayout(contentPanel); contentPanel.setLayout(contentPanelLayout); @@ -234,7 +245,7 @@ public class BKUGUI implements BKUGUIFacade { .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); //); + .addContainerGap()); } @Override @@ -291,6 +302,8 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_WELCOME)); + helpListener.setHelpTopic(HELP_WELCOME); + JLabel welcomeMsgLabel = new JLabel(); welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); welcomeMsgLabel.setText(messages.getString(MESSAGE_WAIT)); @@ -300,10 +313,10 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(welcomeMsgLabel)); + .addComponent(welcomeMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(welcomeMsgLabel)); + .addComponent(welcomeMsgLabel)); contentPanel.validate(); @@ -328,6 +341,8 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + helpListener.setHelpTopic(HELP_INSERTCARD); + JLabel insertCardMsgLabel = new JLabel(); insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); @@ -385,6 +400,8 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); + JLabel insertCardMsgLabel = new JLabel(); insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); @@ -476,10 +493,12 @@ public class BKUGUI implements BKUGUIFacade { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String infoPattern = messages.getString(MESSAGE_ENTERPIN); infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); + helpListener.setHelpTopic(HELP_CARDPIN); } else { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); + helpListener.setHelpTopic(HELP_RETRY); } JLabel pinsizeLabel = new JLabel(); @@ -496,7 +515,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) @@ -506,13 +525,13 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel) - .addGap(infoLabel.getFont().getSize()) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(cardPinLabel) - .addComponent(pinField)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); + .addComponent(infoLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cardPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel)); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -628,10 +647,12 @@ public class BKUGUI implements BKUGUIFacade { hashdataListener.actionPerformed(e); } }); + helpListener.setHelpTopic(HELP_SIGNPIN); } else { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); + helpListener.setHelpTopic(HELP_RETRY); } GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -640,22 +661,22 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pinsizeLabel)))); + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(pinsizeLabel)))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() .addComponent(infoLabel) - .addGap(infoLabel.getFont().getSize()) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(signPinLabel) - .addComponent(pinField)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel)); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -695,6 +716,8 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_ERROR)); + helpListener.setHelpTopic(errorMsgKey); + String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -708,10 +731,10 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); + .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); + .addComponent(errorMsgLabel)); JButton okButton = new JButton(); okButton.setText(messages.getString(BUTTON_OK)); @@ -751,6 +774,8 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_ERROR)); + helpListener.setHelpTopic(errorMsgKey); + String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -764,10 +789,10 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); + .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); + .addComponent(errorMsgLabel)); contentPanel.validate(); } @@ -791,6 +816,8 @@ public class BKUGUI implements BKUGUIFacade { // titleLabel.setText(messages.getString(TITLE_WAIT)); + helpListener.setHelpTopic(HELP_WAIT); + JLabel waitMsgLabel = new JLabel(); waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); if (waitMessage != null) { @@ -804,10 +831,10 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel)); + .addComponent(waitMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel)); + .addComponent(waitMsgLabel)); contentPanel.validate(); } @@ -883,6 +910,8 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_HASHDATA)); + helpListener.setHelpTopic(HELP_HASHDATA); + JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); @@ -904,14 +933,14 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); JButton backButton = new JButton(); backButton.setText(messages.getString(BUTTON_BACK)); @@ -958,6 +987,8 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_HASHDATA)); + helpListener.setHelpTopic(HELP_HASHDATALIST); + JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); @@ -982,15 +1013,15 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); - + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); + JButton backButton = new JButton(); backButton.setText(messages.getString(BUTTON_BACK)); backButton.setActionCommand(cancelCommand); @@ -1133,4 +1164,19 @@ public class BKUGUI implements BKUGUIFacade { } } } + + private void registerHelpListener(ActionListener helpListener) { + if (helpListener != null) { + this.helpListener = new HelpMouseListener(helpListener); + } else { + log.error("no help listener provided, will not be able to display help"); + this.helpListener = new HelpMouseListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + log.error("no help listener registered (requested help topic: " + e.getActionCommand() + ")"); + } + }); + } + } } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index ced74834..6c157e76 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -37,6 +37,7 @@ public interface BKUGUIFacade { public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; public static final String DEFAULT_BACKGROUND = "/images/BackgroundChipperling.png"; + public static final String HELP_IMG = "/images/help.png"; public static final String HASHDATA_FONT = "Monospaced"; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; @@ -63,6 +64,15 @@ public interface BKUGUIFacade { public static final String LABEL_PIN = "label.pin"; public static final String LABEL_PINSIZE = "label.pinsize"; // public static final String ERROR_NO_HASHDATA = "error.no.hashdata"; + public static final String HELP_WELCOME = "help.welcome"; + public static final String HELP_WAIT = "help.wait"; + public static final String HELP_CARDNOTSUPPORTED = "help.cardnotsupported"; + public static final String HELP_INSERTCARD = "help.insertcard"; + public static final String HELP_CARDPIN = "help.cardpin"; + public static final String HELP_SIGNPIN = "help.signpin"; + public static final String HELP_RETRY = "help.retry"; + public static final String HELP_HASHDATA = "help.hashdata"; + public static final String HELP_HASHDATALIST = "help.hashdatalist"; public static final String BUTTON_OK = "button.ok"; public static final String BUTTON_CANCEL = "button.cancel"; @@ -72,9 +82,9 @@ public interface BKUGUIFacade { public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; - public void init(Container contentPane, String localeString, URL background); + public void init(Container contentPane, String localeString, URL background, ActionListener helpListener); - public void showWelcomeDialog(); + public void showWelcomeDialog(); /** * MOA-ID only diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java new file mode 100644 index 00000000..6d814f01 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java @@ -0,0 +1,33 @@ +package at.gv.egiz.bku.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class HelpMouseListener extends MouseAdapter { + + protected static final Log log = LogFactory.getLog(HelpMouseListener.class); + + protected ActionListener externalHelpListener; + protected String locale; + protected String topic; + + public HelpMouseListener(ActionListener externalHelpListener) { + super(); + this.externalHelpListener = externalHelpListener; + } + + public void setHelpTopic(String topic) { + log.trace("setting help topic: " + topic); + this.topic = topic; + } + + @Override + public void mouseClicked(MouseEvent arg0) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, topic); + externalHelpListener.actionPerformed(e); + } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index c37704e2..29913d2a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -41,6 +41,7 @@ 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.JCheckBox; import javax.swing.JFileChooser; @@ -65,6 +66,8 @@ import org.apache.commons.logging.LogFactory; public class SimpleGUI implements BKUGUIFacade { private static final Log log = LogFactory.getLog(SimpleGUI.class); + + protected HelpMouseListener helpListener; protected Container contentPane; protected ResourceBundle messages; @@ -77,6 +80,7 @@ public class SimpleGUI implements BKUGUIFacade { protected JPanel buttonPanel; /** right side fixed labels */ // protected JLabel titleLabel; + protected JLabel helpLabel; /** remember the pinfield to return to worker */ protected JPasswordField pinField; @@ -89,7 +93,7 @@ public class SimpleGUI implements BKUGUIFacade { * @param localeString may be null */ @Override - public void init(final Container contentPane, String localeString, final URL background) { + public void init(final Container contentPane, String localeString, final URL background, ActionListener helpListener) { if (localeString != null) { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); @@ -98,7 +102,8 @@ public class SimpleGUI implements BKUGUIFacade { } this.contentPane = contentPane; - + registerHelpListener(helpListener); + try { log.debug("scheduling gui initialization"); @@ -131,7 +136,7 @@ public class SimpleGUI implements BKUGUIFacade { throw new RuntimeException("Failed to init GUI: " + ex.getMessage()); } } - + // protected void initIconPanel() { // iconPanel = new JPanel(); // JLabel iconLabel = new JLabel(); @@ -151,7 +156,7 @@ public class SimpleGUI implements BKUGUIFacade { // .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); // } - protected void initContentPanel(URL background) { + protected void initContentPanel(URL background) { if (background == null) { background = this.getClass().getResource(DEFAULT_BACKGROUND); @@ -175,6 +180,11 @@ public class SimpleGUI implements BKUGUIFacade { // titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | // java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); + helpLabel = new JLabel(); + helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); + helpLabel.addMouseListener(helpListener); + helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + JButton b = new JButton(); // b.setText(messages.getString(BUTTON_CANCEL)); // if (b.getPreferredSize().width > buttonSize) @@ -207,8 +217,7 @@ public class SimpleGUI implements BKUGUIFacade { // // headerPanelLayout.setHorizontalGroup( // headerPanelLayout.createSequentialGroup() -// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) -// .addContainerGap()); +// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); // headerPanelLayout.setVerticalGroup( // headerPanelLayout.createSequentialGroup() // .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); @@ -234,7 +243,7 @@ public class SimpleGUI implements BKUGUIFacade { .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); //); + .addContainerGap()); } @Override @@ -291,6 +300,8 @@ public class SimpleGUI implements BKUGUIFacade { // titleLabel.setText(messages.getString(TITLE_WELCOME)); + helpListener.setHelpTopic(HELP_WELCOME); + JLabel welcomeMsgLabel = new JLabel(); welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); @@ -299,12 +310,16 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(welcomeMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)) + .addComponent(welcomeMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(welcomeMsgLabel)); - + .addComponent(helpLabel) + .addComponent(welcomeMsgLabel)); + contentPanel.validate(); } @@ -328,6 +343,8 @@ public class SimpleGUI implements BKUGUIFacade { // titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + helpListener.setHelpTopic(HELP_INSERTCARD); + JLabel insertCardMsgLabel = new JLabel(); insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); @@ -336,10 +353,14 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)) .addComponent(insertCardMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() + .addComponent(helpLabel) .addComponent(insertCardMsgLabel)); // JButton cancelButton = new JButton(); @@ -385,6 +406,8 @@ public class SimpleGUI implements BKUGUIFacade { // titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); + JLabel insertCardMsgLabel = new JLabel(); insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); @@ -393,12 +416,16 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)) .addComponent(insertCardMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() + .addComponent(helpLabel) .addComponent(insertCardMsgLabel)); - + // JButton cancelButton = new JButton(); // cancelButton.setText(messages.getString(BUTTON_CANCEL)); // cancelButton.addActionListener(cancelListener); @@ -477,10 +504,12 @@ public class SimpleGUI implements BKUGUIFacade { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String infoPattern = messages.getString(MESSAGE_ENTERPIN); infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); + helpListener.setHelpTopic(HELP_CARDPIN); } else { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); + helpListener.setHelpTopic(HELP_RETRY); } JLabel pinsizeLabel = new JLabel(); @@ -497,7 +526,10 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) @@ -507,13 +539,15 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel) - .addGap(infoLabel.getFont().getSize()) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(cardPinLabel) - .addComponent(pinField)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel) + .addComponent(helpLabel)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cardPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel)); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -580,7 +614,7 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - + // if (numRetries < 0) { // titleLabel.setText(messages.getString(TITLE_SIGN)); // } else { @@ -626,7 +660,7 @@ public class SimpleGUI implements BKUGUIFacade { pinSize += "-" + pinSpec.getMaxLength(); } pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); - + JLabel infoLabel = new JLabel(); if (numRetries < 0) { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -641,10 +675,12 @@ public class SimpleGUI implements BKUGUIFacade { hashdataListener.actionPerformed(e); } }); + helpListener.setHelpTopic(HELP_SIGNPIN); } else { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); + helpListener.setHelpTopic(HELP_RETRY); } GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -652,23 +688,28 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pinsizeLabel)))); + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(pinsizeLabel)))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(infoLabel) - .addGap(infoLabel.getFont().getSize()) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(signPinLabel) - .addComponent(pinField)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); + .addComponent(helpLabel)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel)); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -719,6 +760,8 @@ public class SimpleGUI implements BKUGUIFacade { // titleLabel.setText(messages.getString(TITLE_ERROR)); + helpListener.setHelpTopic(errorMsgKey); + String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -731,12 +774,16 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)) + .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); - + .addComponent(helpLabel) + .addComponent(errorMsgLabel)); + JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); okButton.setText(messages.getString(BUTTON_OK)); @@ -776,6 +823,8 @@ public class SimpleGUI implements BKUGUIFacade { // titleLabel.setText(messages.getString(TITLE_ERROR)); + helpListener.setHelpTopic(errorMsgKey); + String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -788,11 +837,15 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)) + .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); + .addComponent(helpLabel) + .addComponent(errorMsgLabel)); contentPanel.validate(); } @@ -816,6 +869,8 @@ public class SimpleGUI implements BKUGUIFacade { // titleLabel.setText(messages.getString(TITLE_WAIT)); + helpListener.setHelpTopic(HELP_WAIT); + JLabel waitMsgLabel = new JLabel(); waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); if (waitMessage != null) { @@ -828,11 +883,15 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)) + .addComponent(waitMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel)); + .addComponent(helpLabel) + .addComponent(waitMsgLabel)); contentPanel.validate(); } @@ -907,6 +966,8 @@ public class SimpleGUI implements BKUGUIFacade { buttonPanel.removeAll(); // titleLabel.setText(messages.getString(TITLE_HASHDATA)); + + helpListener.setHelpTopic(HELP_HASHDATA); JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -929,14 +990,19 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(helpLabel)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); JButton backButton = new JButton(); backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -995,6 +1061,8 @@ public class SimpleGUI implements BKUGUIFacade { // titleLabel.setText(messages.getString(TITLE_HASHDATA)); + helpListener.setHelpTopic(HELP_HASHDATALIST); + JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); @@ -1019,14 +1087,19 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(helpLabel)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); JButton backButton = new JButton(); backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -1183,4 +1256,19 @@ public class SimpleGUI implements BKUGUIFacade { } } } + + private void registerHelpListener(ActionListener helpListener) { + if (helpListener != null) { + this.helpListener = new HelpMouseListener(helpListener); + } else { + log.error("no help listener provided, will not be able to display help"); + this.helpListener = new HelpMouseListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + log.error("no help listener registered (requested help topic: " + e.getActionCommand() + ")"); + } + }); + } + } } -- cgit v1.2.3 From 8479ef50c84e8998f7909074df6a23c2ff0aa5b0 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 31 Oct 2008 12:33:18 +0000 Subject: Help Icon git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@132 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 1 + .../src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java | 1 + .../java/at/gv/egiz/bku/gui/HashDataTableModel.java | 1 + .../main/java/at/gv/egiz/bku/gui/HelpMouseListener.java | 17 +++++++++++++++++ .../src/main/java/at/gv/egiz/bku/gui/ImagePanel.java | 16 ++++++++++++++-- .../src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 5 +---- 6 files changed, 35 insertions(+), 6 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 6c157e76..872f1874 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -14,6 +14,7 @@ * 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; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java index 4a338f23..87676026 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package at.gv.egiz.bku.gui; public class BKUGUIFactory { diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java index 1a833f48..aea85523 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java @@ -14,6 +14,7 @@ * 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; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java index 6d814f01..531884d1 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java @@ -1,3 +1,20 @@ +/* + * 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.event.ActionEvent; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java index e9c270ce..1185cf53 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * 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; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index 29913d2a..195db27a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -14,10 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ + package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; -- cgit v1.2.3 From 4032e46810c24dc3f013de296a2133f4651696b9 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 31 Oct 2008 15:30:34 +0000 Subject: local HelpListener card locked/not activated git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@137 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/gui/AbstractHelpListener.java | 84 ++++++++++++++++++++++ .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 2 + 2 files changed, 86 insertions(+) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java new file mode 100644 index 00000000..68d61bef --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -0,0 +1,84 @@ +/* + * 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.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.MalformedURLException; +import java.net.URL; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public abstract class AbstractHelpListener implements ActionListener { + + protected final static Log log = LogFactory.getLog(AbstractHelpListener.class); + protected String helpURLBase; + protected String locale; + + public AbstractHelpListener(URL baseURL, String locale) { + if (baseURL == null || "".equals(baseURL)) { + throw new RuntimeException("no help URL provided"); + } + this.helpURLBase = baseURL.toString(); + this.locale = locale; + } + + @Override + public void actionPerformed(ActionEvent e) { + log.debug("received help action: " + e.getActionCommand()); + URL helpURL; + try { + String urlString = helpURLBase; + if (locale != null) { + urlString = appendParameter(urlString, "locale", locale); + } + if (e.getActionCommand() != null && !"".equals(e.getActionCommand())) { + urlString = appendParameter(urlString, "topic", e.getActionCommand()); + } + helpURL = new URL(urlString); + } catch (MalformedURLException ex) { + try { + log.error("failed to create help URL: " + ex.getMessage()); + helpURL = new URL(helpURLBase); + } catch (MalformedURLException ex1) { + log.error("failed to create default help URL, requested help will not be displayed"); + return; + } + } + try { + showDocument(helpURL); + } catch (Exception ex) { + log.error("could not display help document " + helpURL + ": " + ex.getMessage()); + } + } + + private String appendParameter(String url, String paramName, String paramValue) { + if (url.indexOf('?') < 0) { + return url + "?" + paramName + "=" + paramValue; + } else { + return url + "&" + paramName + "=" + paramValue; + } + } + + public abstract void showDocument(URL helpDocument) throws Exception; + +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 872f1874..4ef1b7d9 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -35,6 +35,8 @@ public interface BKUGUIFacade { public static final String ERR_DISPLAY_HASHDATA = "error.display.hashdata"; public static final String ERR_WRITE_HASHDATA = "error.write.hashdata"; public static final String ERR_INVALID_HASH = "error.invalid.hash"; + public static final String ERR_CARD_LOCKED = "error.card.locked"; + public static final String ERR_CARD_NOTACTIVATED = "error.card.notactivated"; public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; public static final String DEFAULT_BACKGROUND = "/images/BackgroundChipperling.png"; -- cgit v1.2.3 From 9829de9c9b19dcca15676aaf9737195cc059a66c Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 3 Nov 2008 09:37:14 +0000 Subject: local HelpListener DesktopAPI git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@138 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java index 68d61bef..6e3167c1 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -21,6 +21,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.MalformedURLException; import java.net.URL; +import java.util.Locale; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -32,9 +33,9 @@ public abstract class AbstractHelpListener implements ActionListener { protected final static Log log = LogFactory.getLog(AbstractHelpListener.class); protected String helpURLBase; - protected String locale; + protected Locale locale; - public AbstractHelpListener(URL baseURL, String locale) { + public AbstractHelpListener(URL baseURL, Locale locale) { if (baseURL == null || "".equals(baseURL)) { throw new RuntimeException("no help URL provided"); } @@ -49,7 +50,7 @@ public abstract class AbstractHelpListener implements ActionListener { try { String urlString = helpURLBase; if (locale != null) { - urlString = appendParameter(urlString, "locale", locale); + urlString = appendParameter(urlString, "locale", locale.toString()); } if (e.getActionCommand() != null && !"".equals(e.getActionCommand())) { urlString = appendParameter(urlString, "topic", e.getActionCommand()); -- cgit v1.2.3 From 6211ed7f96c4ee6e1616a7c1e44477b9f3e8117f Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 3 Nov 2008 12:36:42 +0000 Subject: localization git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@140 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 11 ++++++++--- .../src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 9 ++++++++- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 11 ++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 27841d1c..9f733a14 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -92,10 +92,10 @@ public class BKUGUI implements BKUGUIFacade { * @param localeString may be null */ @Override - public void init(final Container contentPane, String localeString, final URL background, ActionListener helpListener) { + public void init(final Container contentPane, Locale locale, final URL background, ActionListener helpListener) { - if (localeString != null) { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); + if (locale != null) { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); } else { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); } @@ -248,6 +248,11 @@ public class BKUGUI implements BKUGUIFacade { .addContainerGap()); } + @Override + public Locale getLocale() { + return messages.getLocale(); + } + @Override public void showLoginDialog(ActionListener loginListener, String actionCommand) { diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 4ef1b7d9..6655cf64 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -24,6 +24,7 @@ import java.awt.Container; import java.awt.event.ActionListener; import java.net.URL; import java.util.List; +import java.util.Locale; public interface BKUGUIFacade { @@ -85,7 +86,13 @@ public interface BKUGUIFacade { public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; - public void init(Container contentPane, String localeString, URL background, ActionListener helpListener); + public void init(Container contentPane, Locale locale, URL background, ActionListener helpListener); + + /** + * + * @return the locale of the message bundle (what if no message bundle could be loaded for the requested locale?) + */ + public Locale getLocale(); public void showWelcomeDialog(); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index 195db27a..a005292e 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -90,10 +90,10 @@ public class SimpleGUI implements BKUGUIFacade { * @param localeString may be null */ @Override - public void init(final Container contentPane, String localeString, final URL background, ActionListener helpListener) { + public void init(final Container contentPane, Locale locale, final URL background, ActionListener helpListener) { - if (localeString != null) { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); + if (locale != null) { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); } else { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); } @@ -243,6 +243,11 @@ public class SimpleGUI implements BKUGUIFacade { .addContainerGap()); } + @Override + public Locale getLocale() { + return messages.getLocale(); + } + @Override public void showLoginDialog(ActionListener loginListener, String actionCommand) { -- cgit v1.2.3 From 9fcce6749092eb6c5d266dd1dd7099e88014fbd7 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 4 Nov 2008 12:03:15 +0000 Subject: simplegui messages on top git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@143 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 6 +- .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 93 ++++++++++++---------- 2 files changed, 53 insertions(+), 46 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 9f733a14..cb99a872 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; @@ -819,7 +815,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_WAIT)); + titleLabel.setText(messages.getString(TITLE_WAIT)); helpListener.setHelpTopic(HELP_WAIT); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index a005292e..6bf6df84 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -312,15 +312,14 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() + mainPanelLayout.createSequentialGroup() + .addComponent(welcomeMsgLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(welcomeMsgLabel)); + .addComponent(helpLabel)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(helpLabel) - .addComponent(welcomeMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(welcomeMsgLabel) + .addComponent(helpLabel)); contentPanel.validate(); @@ -355,15 +354,14 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() + mainPanelLayout.createSequentialGroup() + .addComponent(insertCardMsgLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(insertCardMsgLabel)); + .addComponent(helpLabel)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(helpLabel) - .addComponent(insertCardMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel) + .addComponent(helpLabel)); // JButton cancelButton = new JButton(); // cancelButton.setText(messages.getString(BUTTON_CANCEL)); @@ -418,15 +416,14 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() + mainPanelLayout.createSequentialGroup() + .addComponent(insertCardMsgLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(insertCardMsgLabel)); + .addComponent(helpLabel)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(helpLabel) - .addComponent(insertCardMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel) + .addComponent(helpLabel)); // JButton cancelButton = new JButton(); // cancelButton.setText(messages.getString(BUTTON_CANCEL)); @@ -764,6 +761,11 @@ public class SimpleGUI implements BKUGUIFacade { helpListener.setHelpTopic(errorMsgKey); + JLabel errorTitleLabel = new JLabel(); + errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); + errorTitleLabel.setText(messages.getString(TITLE_ERROR)); + errorTitleLabel.setForeground(ERROR_COLOR); + String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -778,12 +780,15 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(errorTitleLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) .addComponent(helpLabel)) .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addComponent(helpLabel) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorTitleLabel) + .addComponent(helpLabel)) .addComponent(errorMsgLabel)); JButton okButton = new JButton(); @@ -827,27 +832,34 @@ public class SimpleGUI implements BKUGUIFacade { helpListener.setHelpTopic(errorMsgKey); + JLabel errorTitleLabel = new JLabel(); + errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); + errorTitleLabel.setText(messages.getString(TITLE_ERROR)); + errorTitleLabel.setForeground(ERROR_COLOR); + String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); errorMsgLabel.setText(errorMsg); - errorMsgLabel.setForeground(ERROR_COLOR); - + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(errorMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(helpLabel) - .addComponent(errorMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(errorTitleLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)) + .addComponent(errorMsgLabel)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorTitleLabel) + .addComponent(helpLabel)) + .addComponent(errorMsgLabel)); contentPanel.validate(); } @@ -885,16 +897,15 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() + mainPanelLayout.createSequentialGroup() + .addComponent(waitMsgLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(waitMsgLabel)); + .addComponent(helpLabel)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(helpLabel) - .addComponent(waitMsgLabel)); - + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel) + .addComponent(helpLabel)); + contentPanel.validate(); } }); -- cgit v1.2.3 From 3049d65de7c8ca9c25756db5648b6f268d675df9 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 4 Nov 2008 12:24:39 +0000 Subject: error foreground color remove showLoginDialog() git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@145 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 37 --------------------- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 7 ++-- .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 38 ---------------------- 3 files changed, 2 insertions(+), 80 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index cb99a872..d96d22c8 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -249,43 +249,6 @@ public class BKUGUI implements BKUGUIFacade { return messages.getLocale(); } - @Override - public void showLoginDialog(ActionListener loginListener, String actionCommand) { - - log.debug("scheduling login dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show login dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_ERROR)); - - JLabel waitMsgLabel = new JLabel(); - waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - waitMsgLabel.setText("LoginDialog not supported yet."); - waitMsgLabel.setForeground(ERROR_COLOR); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel)); - - contentPanel.validate(); - } - }); - } - @Override public void showWelcomeDialog() { diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 6655cf64..ad489c2e 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -97,12 +97,9 @@ public interface BKUGUIFacade { public void showWelcomeDialog(); /** - * MOA-ID only - * @param loginListener + * + * @param waitMessage if null, a simple 'wait' text is displayed */ - public void showLoginDialog(ActionListener loginListener, String actionCommand); - - /** optional wait message */ public void showWaitDialog(String waitMessage); public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index 6bf6df84..f2a8466b 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -248,43 +248,6 @@ public class SimpleGUI implements BKUGUIFacade { return messages.getLocale(); } - @Override - public void showLoginDialog(ActionListener loginListener, String actionCommand) { - - log.debug("scheduling login dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show login dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - -// titleLabel.setText(messages.getString(TITLE_ERROR)); - - JLabel waitMsgLabel = new JLabel(); - waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - waitMsgLabel.setText("LoginDialog not supported yet."); - waitMsgLabel.setForeground(ERROR_COLOR); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel)); - - contentPanel.validate(); - } - }); - } - @Override public void showWelcomeDialog() { @@ -772,7 +735,6 @@ public class SimpleGUI implements BKUGUIFacade { JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); errorMsgLabel.setText(errorMsg); - errorMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); -- cgit v1.2.3 From 2cf6fcb31e85b0e3b367121219932ec86b205da8 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 5 Nov 2008 14:42:05 +0000 Subject: help jsp git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@151 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/gui/AbstractHelpListener.java | 45 +++++++++------------- 1 file changed, 19 insertions(+), 26 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java index 6e3167c1..a249a376 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -32,39 +32,22 @@ import org.apache.commons.logging.LogFactory; public abstract class AbstractHelpListener implements ActionListener { protected final static Log log = LogFactory.getLog(AbstractHelpListener.class); - protected String helpURLBase; +// protected String helpURLBase; + protected URL baseURL; protected Locale locale; public AbstractHelpListener(URL baseURL, Locale locale) { if (baseURL == null || "".equals(baseURL)) { throw new RuntimeException("no help URL provided"); } - this.helpURLBase = baseURL.toString(); + this.baseURL = baseURL; this.locale = locale; } @Override public void actionPerformed(ActionEvent e) { log.debug("received help action: " + e.getActionCommand()); - URL helpURL; - try { - String urlString = helpURLBase; - if (locale != null) { - urlString = appendParameter(urlString, "locale", locale.toString()); - } - if (e.getActionCommand() != null && !"".equals(e.getActionCommand())) { - urlString = appendParameter(urlString, "topic", e.getActionCommand()); - } - helpURL = new URL(urlString); - } catch (MalformedURLException ex) { - try { - log.error("failed to create help URL: " + ex.getMessage()); - helpURL = new URL(helpURLBase); - } catch (MalformedURLException ex1) { - log.error("failed to create default help URL, requested help will not be displayed"); - return; - } - } + URL helpURL = constructHelpURL(baseURL, e.getActionCommand()); try { showDocument(helpURL); } catch (Exception ex) { @@ -72,12 +55,22 @@ public abstract class AbstractHelpListener implements ActionListener { } } - private String appendParameter(String url, String paramName, String paramValue) { - if (url.indexOf('?') < 0) { - return url + "?" + paramName + "=" + paramValue; - } else { - return url + "&" + paramName + "=" + paramValue; + private URL constructHelpURL(URL baseURL, String helpItem) { + URL helpURL = baseURL; + log.trace("constructing help URL: " + helpURL); + try { + if (locale != null) { + helpURL = new URL(helpURL, locale.toString() + "/"); + log.trace("constructing help URL: " + helpURL); + } + if (helpItem != null && !"".equals(helpItem)) { + helpURL = new URL(helpURL, helpItem + ".html"); + log.trace("constructing help URL: " + helpURL); + } + } catch (MalformedURLException ex) { + log.error("Failed to construct help URL for help item " + helpItem + ": " + ex.getMessage()); } + return helpURL; } public abstract void showDocument(URL helpDocument) throws Exception; -- cgit v1.2.3 From 82c59c9d862d3ee9ad43fdc1509d0b5a61cc107c Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 11 Nov 2008 12:15:15 +0000 Subject: Frame HashData Display Interrupt in waitForAction (applet closed) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@161 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 2 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 5 +- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 260 +++++++++++++++++++++ .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 38 ++- 4 files changed, 300 insertions(+), 5 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index d96d22c8..d661c71a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -814,7 +814,7 @@ public class BKUGUI implements BKUGUIFacade { } @Override - public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { + public void showHashDataInputDialog(final List signedReferences, boolean standalone, final ActionListener okListener, final String okCommand) { if (signedReferences == null) { showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index ad489c2e..38638b5d 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -57,6 +57,7 @@ public interface BKUGUIFacade { public static final String WINDOWTITLE_SAVE = "windowtitle.save"; public static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; public static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; + public static final String WINDOWTITLE_VIEWER = "windowtitle.viewer"; public static final String MESSAGE_WAIT = "message.wait"; public static final String MESSAGE_INSERTCARD = "message.insertcard"; public static final String MESSAGE_ENTERPIN = "message.enterpin"; @@ -77,12 +78,14 @@ public interface BKUGUIFacade { public static final String HELP_RETRY = "help.retry"; public static final String HELP_HASHDATA = "help.hashdata"; public static final String HELP_HASHDATALIST = "help.hashdatalist"; + public static final String HELP_HASHDATAVIEWER = "help.hashdataviewer"; public static final String BUTTON_OK = "button.ok"; public static final String BUTTON_CANCEL = "button.cancel"; public static final String BUTTON_BACK = "button.back"; public static final String BUTTON_SIGN = "button.sign"; public static final String BUTTON_SAVE = "button.save"; + public static final String BUTTON_CLOSE = "button.close"; public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; @@ -116,7 +119,7 @@ public interface BKUGUIFacade { public char[] getPin(); - public void showHashDataInputDialog(List signedReferences, ActionListener okListener, String actionCommand); + public void showHashDataInputDialog(List signedReferences, boolean standalone, ActionListener okListener, String actionCommand); // public void showPlainTextHashDataInputDialog(String text, ActionListener saveListener, String saveCommand, ActionListener cancelListener, String cancelCommand); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java new file mode 100644 index 00000000..3db06e19 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java @@ -0,0 +1,260 @@ +/* + * 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.Component; +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.WindowEvent; +import java.awt.event.WindowListener; +import java.io.InputStreamReader; +import java.io.Reader; +import java.text.MessageFormat; +import java.util.List; +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.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.LayoutStyle; +import javax.swing.text.Document; +import javax.swing.text.EditorKit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class HashDataViewer extends JDialog + implements ActionListener, WindowListener { + + public static final String PLAINTEXT_FONT = "Monospaced"; + + protected static final Log log = LogFactory.getLog(HashDataViewer.class); + private static HashDataViewer dialog; + + public static void showDialog(Component frameComp, List signedReferences, ResourceBundle messages, ActionListener saveListener, String saveCommand, HelpMouseListener helpListener) { + + log.info("******************* SHOW HASHDATA DIALOG"); + + Frame frame = JOptionPane.getFrameForComponent(frameComp); + + dialog = new HashDataViewer(frame, signedReferences.get(0), messages, saveListener, saveCommand, helpListener); + dialog.addWindowListener(dialog); + dialog.setVisible(true); + + } + + private HashDataViewer(Frame frame, HashDataInput hashData, ResourceBundle messages, ActionListener saveListener, String saveCommand, HelpMouseListener helpListener) { + super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); + + JPanel viewerPanel = createViewerPanel(messages, hashData, helpListener); + JPanel buttonPanel = createButtonPanel(messages, saveListener, saveCommand); + + + Container contentPane = getContentPane(); + contentPane.setPreferredSize(new Dimension(400, 300)); + + 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, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); + + pack(); + setLocationRelativeTo(frame); + } + + private JPanel createViewerPanel(ResourceBundle messages, HashDataInput hashData, HelpMouseListener helpListener) { + String mimeType = hashData.getMimeType(); + String encoding = hashData.getEncoding(); + + log.debug("display hashdata: " + mimeType + ";" + encoding); + + if (mimeType == null) { + mimeType = "text/plain"; + } + if (encoding == null) { + encoding = "UTF-8"; + } + + JEditorPane viewer = new JEditorPane(); + viewer.setEditable(false); + viewer.setContentType(mimeType); + if ("text/plain".equals(mimeType)) { + viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); + } + + EditorKit editorKit = viewer.getEditorKit(); + Document document = editorKit.createDefaultDocument(); + + Reader reader; + try { + reader = new InputStreamReader(hashData.getHashDataInput(), encoding); + viewer.read(reader, document); + } catch (Exception ex) { + String p = messages.getString(BKUGUIFacade.ERR_DISPLAY_HASHDATA); + viewer.setText(MessageFormat.format(p, ex.getMessage())); + } + + JScrollPane scrollPane = new JScrollPane(viewer); +// scrollPane.setPreferredSize(new Dimension(400, 300)); + scrollPane.setPreferredSize(viewer.getPreferredSize()); + scrollPane.setAlignmentX(LEFT_ALIGNMENT); + + JLabel viewerTitle = new JLabel(); + viewerTitle.setText(messages.getString(BKUGUIFacade.TITLE_HASHDATA)); + viewerTitle.setFont(viewerTitle.getFont().deriveFont(viewerTitle.getFont().getStyle() | java.awt.Font.BOLD)); + viewerTitle.setLabelFor(viewer); + + JLabel helpLabel = new JLabel(); + helpListener.setHelpTopic(BKUGUIFacade.HELP_HASHDATAVIEWER); + helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); + helpLabel.addMouseListener(helpListener); + helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + JPanel viewerPanel = new JPanel(); + GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); + viewerPanel.setLayout(viewerPanelLayout); + + viewerPanelLayout.setHorizontalGroup( + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(viewerPanelLayout.createSequentialGroup() + .addComponent(viewerTitle) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)) + .addComponent(scrollPane)); //, 0, 0, Short.MAX_VALUE)); + + viewerPanelLayout.setVerticalGroup( + viewerPanelLayout.createSequentialGroup() + .addGroup(viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(viewerTitle) + .addComponent(helpLabel)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(scrollPane)); //, 0, 0, Short.MAX_VALUE)); + +// viewerPanel.setLayout(new BoxLayout(viewerPanel, BoxLayout.PAGE_AXIS)); +// JLabel title = new JLabel(messages.getString(BKUGUIFacade.TITLE_HASHDATA)); +// title.setLabelFor(viewer); +// viewerPanel.add(title); +// viewerPanel.add(Box.createRigidArea(new Dimension(0, 5))); +// viewerPanel.add(scrollPane); +// viewerPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + return viewerPanel; + } + + private JPanel createButtonPanel(ResourceBundle messages, ActionListener saveListener, String saveCommand) { + JButton closeButton = new JButton(); + closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); + closeButton.addActionListener(this); + + JButton saveButton = new JButton(); + saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + 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())) { + HashDataViewer.dialog.setVisible(false); +// HashDataViewer.dialog.dispose(); + } + + @Override + public void windowOpened(WindowEvent e) { + log.debug("WINDOW OPENED"); + } + + @Override + public void windowClosing(WindowEvent e) { + log.debug("WINDOW CLOSING"); + } + + @Override + public void windowClosed(WindowEvent e) { + log.debug("WINDOW CLOSED"); + } + + @Override + public void windowIconified(WindowEvent e) { + log.debug("WINDOW ICONIFIED"); + } + + @Override + public void windowDeiconified(WindowEvent e) { + } + + @Override + public void windowActivated(WindowEvent e) { + log.debug("WINDOW ACTIVATED"); + } + + @Override + public void windowDeactivated(WindowEvent e) { + log.debug("WINDOW DEACTIVATED"); + } + + + + + + + +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index f2a8466b..583dae0f 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -882,14 +882,25 @@ public class SimpleGUI implements BKUGUIFacade { } @Override - public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { + public void showHashDataInputDialog(final List signedReferences, boolean standalone, final ActionListener okListener, final String okCommand) { if (signedReferences == null) { showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); } if (signedReferences.size() == 1) { - + + if (standalone) { + ActionListener saveHashDataListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(signedReferences, okListener, okCommand); + } + }; + showHashDataViewer(signedReferences, saveHashDataListener, "save"); + + } else { if ("text/plain".equals(signedReferences.get(0).getMimeType())) { ActionListener saveHashDataListener = new ActionListener() { @@ -910,7 +921,7 @@ public class SimpleGUI implements BKUGUIFacade { } else { showSaveHashDataInputDialog(signedReferences, okListener, okCommand); } - + } } else { final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); @@ -926,6 +937,27 @@ public class SimpleGUI implements BKUGUIFacade { } } + /** + * TODO + * @param hashDataText + * @param saveListener + * @param saveCommand + */ + private void showHashDataViewer(final List signedReferences, final ActionListener saveListener, final String saveCommand) { + log.debug("scheduling plaintext hashdatainput dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show plaintext hashdatainput dialog"); + + HashDataViewer.showDialog(contentPane, signedReferences, messages, saveListener, saveCommand, helpListener); + } + }); + } + private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { log.debug("scheduling plaintext hashdatainput dialog"); -- cgit v1.2.3 From 9662ac90b6aa84bc54543d3c8670ba6c8e42bbac Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 13 Nov 2008 18:24:57 +0000 Subject: FRAME HashDataDisplay FRAME Help git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@165 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/gui/AbstractHelpListener.java | 41 ++- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 219 +++++++------ .../at/gv/egiz/bku/gui/HashDataTableModel.java | 10 +- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 260 --------------- .../java/at/gv/egiz/bku/gui/HyperLinkRenderer.java | 47 +++ .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 35 +- .../gv/egiz/bku/gui/SimpleHashDataTableModel.java | 60 ++++ .../main/java/at/gv/egiz/bku/gui/ViewerDialog.java | 354 +++++++++++++++++++++ 8 files changed, 626 insertions(+), 400 deletions(-) delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java index a249a376..f46f5227 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package at.gv.egiz.bku.gui; import java.awt.event.ActionEvent; @@ -22,19 +21,24 @@ import java.awt.event.ActionListener; import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; +import java.util.ResourceBundle; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** - * + * Implement the showDocument(URL) method to provide an actual HelpListener. + * This class does not keep a GUI reference and subclasses should not interfere with the GUI. + * Therefore, any errors occurring in showDocument() should be handled/displayed within + * showDocument() and exceptions thrown from showDocument() are logged, not displayed in the GUI. + * * @author Clemens Orthacker */ public abstract class AbstractHelpListener implements ActionListener { protected final static Log log = LogFactory.getLog(AbstractHelpListener.class); -// protected String helpURLBase; protected URL baseURL; protected Locale locale; + protected ResourceBundle messages; public AbstractHelpListener(URL baseURL, Locale locale) { if (baseURL == null || "".equals(baseURL)) { @@ -42,6 +46,11 @@ public abstract class AbstractHelpListener implements ActionListener { } this.baseURL = baseURL; this.locale = locale; + if (locale != null) { + messages = ResourceBundle.getBundle(BKUGUIFacade.MESSAGES_BUNDLE, locale); + } else { + messages = ResourceBundle.getBundle(BKUGUIFacade.MESSAGES_BUNDLE); + } } @Override @@ -49,30 +58,36 @@ public abstract class AbstractHelpListener implements ActionListener { log.debug("received help action: " + e.getActionCommand()); URL helpURL = constructHelpURL(baseURL, e.getActionCommand()); try { - showDocument(helpURL); + showDocument(helpURL, e.getActionCommand()); } catch (Exception ex) { log.error("could not display help document " + helpURL + ": " + ex.getMessage()); } } - - private URL constructHelpURL(URL baseURL, String helpItem) { + + private URL constructHelpURL(URL baseURL, String helpTopic) { URL helpURL = baseURL; log.trace("constructing help URL: " + helpURL); try { if (locale != null) { helpURL = new URL(helpURL, locale.toString() + "/"); log.trace("constructing help URL: " + helpURL); - } - if (helpItem != null && !"".equals(helpItem)) { - helpURL = new URL(helpURL, helpItem + ".html"); + } + if (helpTopic != null && !"".equals(helpTopic)) { + helpURL = new URL(helpURL, helpTopic + ".html"); log.trace("constructing help URL: " + helpURL); } } catch (MalformedURLException ex) { - log.error("Failed to construct help URL for help item " + helpItem + ": " + ex.getMessage()); + log.error("Failed to construct help URL for help item " + helpTopic + ": " + ex.getMessage()); } return helpURL; } - - public abstract void showDocument(URL helpDocument) throws Exception; - + + /** + * Errors from HelpListeners should not (are not) displayed in the applet, + * but should rather be in the HelpListener specific way. + * Therefore, implementations SHOULD NOT throw exceptions (these are only logged). + * @param helpDocument + * @throws java.lang.Exception + */ + public abstract void showDocument(URL helpDocument, String helpTopic) throws Exception; } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 38638b5d..2daf3300 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -1,20 +1,19 @@ /* -* 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. -*/ - + * 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; @@ -27,7 +26,7 @@ import java.util.List; import java.util.Locale; public interface BKUGUIFacade { - + public static final String ERR_UNKNOWN = "error.unknown"; public static final String ERR_SERVICE_UNREACHABLE = "error.ws.unreachable"; public static final String ERR_NO_PCSC = "error.pcsc"; @@ -38,92 +37,108 @@ public interface BKUGUIFacade { public static final String ERR_INVALID_HASH = "error.invalid.hash"; public static final String ERR_CARD_LOCKED = "error.card.locked"; public static final String ERR_CARD_NOTACTIVATED = "error.card.notactivated"; + public static final String ERR_VIEWER = "error.viewer"; - public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; - public static final String DEFAULT_BACKGROUND = "/images/BackgroundChipperling.png"; - public static final String HELP_IMG = "/images/help.png"; - public static final String HASHDATA_FONT = "Monospaced"; - public static final Color ERROR_COLOR = Color.RED; - public static final Color HYPERLINK_COLOR = Color.BLUE; - public static final String TITLE_WELCOME = "title.welcome"; - public static final String TITLE_INSERTCARD = "title.insertcard"; - public static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; - public static final String TITLE_CARDPIN = "title.cardpin"; - public static final String TITLE_SIGN = "title.sign"; - public static final String TITLE_ERROR = "title.error"; - public static final String TITLE_RETRY = "title.retry"; - public static final String TITLE_WAIT = "title.wait"; - public static final String TITLE_HASHDATA = "title.hashdata"; - public static final String WINDOWTITLE_SAVE = "windowtitle.save"; - public static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; - public static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; - public static final String WINDOWTITLE_VIEWER = "windowtitle.viewer"; - public static final String MESSAGE_WAIT = "message.wait"; - public static final String MESSAGE_INSERTCARD = "message.insertcard"; - public static final String MESSAGE_ENTERPIN = "message.enterpin"; - public static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; - public static final String MESSAGE_HASHDATA = "message.hashdata"; - public static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; - public static final String MESSAGE_RETRIES = "message.retries"; - public static final String MESSAGE_OVERWRITE = "message.overwrite"; - public static final String LABEL_PIN = "label.pin"; - public static final String LABEL_PINSIZE = "label.pinsize"; + public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; + public static final String DEFAULT_BACKGROUND = "/images/BackgroundChipperling.png"; + public static final String HELP_IMG = "/images/help.png"; + public static final String HASHDATA_FONT = "Monospaced"; + public static final Color ERROR_COLOR = Color.RED; + public static final Color HYPERLINK_COLOR = Color.BLUE; + public static final String TITLE_WELCOME = "title.welcome"; + public static final String TITLE_INSERTCARD = "title.insertcard"; + public static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; + public static final String TITLE_CARDPIN = "title.cardpin"; + public static final String TITLE_SIGN = "title.sign"; + public static final String TITLE_ERROR = "title.error"; + public static final String TITLE_RETRY = "title.retry"; + public static final String TITLE_WAIT = "title.wait"; + public static final String TITLE_HASHDATA = "title.hashdata"; + public static final String WINDOWTITLE_SAVE = "windowtitle.save"; + public static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; + public static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; + public static final String WINDOWTITLE_VIEWER = "windowtitle.viewer"; + public static final String WINDOWTITLE_HELP = "windowtitle.help"; + public static final String MESSAGE_WAIT = "message.wait"; + public static final String MESSAGE_INSERTCARD = "message.insertcard"; + public static final String MESSAGE_ENTERPIN = "message.enterpin"; + public static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; + public static final String MESSAGE_HASHDATA = "message.hashdata"; + public static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; + public static final String MESSAGE_RETRIES = "message.retries"; + public static final String MESSAGE_OVERWRITE = "message.overwrite"; + public static final String MESSAGE_HELP = "message.help"; + public static final String LABEL_PIN = "label.pin"; + public static final String LABEL_PINSIZE = "label.pinsize"; // public static final String ERROR_NO_HASHDATA = "error.no.hashdata"; - public static final String HELP_WELCOME = "help.welcome"; - public static final String HELP_WAIT = "help.wait"; - public static final String HELP_CARDNOTSUPPORTED = "help.cardnotsupported"; - public static final String HELP_INSERTCARD = "help.insertcard"; - public static final String HELP_CARDPIN = "help.cardpin"; - public static final String HELP_SIGNPIN = "help.signpin"; - public static final String HELP_RETRY = "help.retry"; - public static final String HELP_HASHDATA = "help.hashdata"; - public static final String HELP_HASHDATALIST = "help.hashdatalist"; - public static final String HELP_HASHDATAVIEWER = "help.hashdataviewer"; - - public static final String BUTTON_OK = "button.ok"; - public static final String BUTTON_CANCEL = "button.cancel"; - public static final String BUTTON_BACK = "button.back"; - public static final String BUTTON_SIGN = "button.sign"; - public static final String BUTTON_SAVE = "button.save"; - public static final String BUTTON_CLOSE = "button.close"; - public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; - - - public void init(Container contentPane, Locale locale, URL background, ActionListener helpListener); - - /** - * - * @return the locale of the message bundle (what if no message bundle could be loaded for the requested locale?) - */ - public Locale getLocale(); - - public void showWelcomeDialog(); - - /** - * - * @param waitMessage if null, a simple 'wait' text is displayed - */ - public void showWaitDialog(String waitMessage); - - public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); - - public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); - - public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); - - public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); - - public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); - - public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); - - public char[] getPin(); - - public void showHashDataInputDialog(List signedReferences, boolean standalone, ActionListener okListener, String actionCommand); - + public static final String HELP_WELCOME = "help.welcome"; + public static final String HELP_WAIT = "help.wait"; + public static final String HELP_CARDNOTSUPPORTED = "help.cardnotsupported"; + public static final String HELP_INSERTCARD = "help.insertcard"; + public static final String HELP_CARDPIN = "help.cardpin"; + public static final String HELP_SIGNPIN = "help.signpin"; + public static final String HELP_RETRY = "help.retry"; + public static final String HELP_HASHDATA = "help.hashdata"; + public static final String HELP_HASHDATALIST = "help.hashdatalist"; + public static final String HELP_HASHDATAVIEWER = "help.hashdataviewer"; + public static final String BUTTON_OK = "button.ok"; + public static final String BUTTON_CANCEL = "button.cancel"; + public static final String BUTTON_BACK = "button.back"; + public static final String BUTTON_SIGN = "button.sign"; + public static final String BUTTON_SAVE = "button.save"; + public static final String BUTTON_CLOSE = "button.close"; + public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; + + public void init(Container contentPane, Locale locale, URL background, ActionListener helpListener); + + /** + * + * @return the locale of the message bundle (what if no message bundle could be loaded for the requested locale?) + */ + public Locale getLocale(); + + public void showWelcomeDialog(); + + /** + * + * @param waitMessage if null, a simple 'wait' text is displayed + */ + public void showWaitDialog(String waitMessage); + + public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); + + public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); + + public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); + + public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); + + public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); + + public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); + + public char[] getPin(); + + /** + * TODO move to HashDataDisplay implementations + * @param signedReferences + * @param externalDisplay + * @param okListener + * @param okCommand + */ + public void showHashDataInputDialog(List signedReferences, boolean externalDisplay, ActionListener okListener, String okCommand); + + /** + * TODO pull out from BKUGUIFacade. (or make this strictly an applet internal version) + * Problem: if standalone flag is provided, we also need the actionlistener.. + * @param helpDocument + * @param mimeType + * @param encoding + */ +// public void showHelpDialog(InputStream helpDocument, String mimeType, String encoding); //, boolean standalone); //, ActionListener okListener, String okCommand); + // public void showPlainTextHashDataInputDialog(String text, ActionListener saveListener, String saveCommand, ActionListener cancelListener, String cancelCommand); - - public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String actionCommand); - - public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams); + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String actionCommand); + + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams); } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java index aea85523..e8566fa6 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java @@ -64,13 +64,5 @@ class HashDataTableModel extends DefaultTableModel { } } return selection; - }// public List getSelectedReferenceIds() { -// ArrayList selection = new ArrayList(); -// for (Object row : dataVector) { -// if ((Boolean) ((Vector) row).elementAt(1)) { -// selection.add((String) ((Vector) row).elementAt(0)); -// } -// } -// return selection; -// } + } } \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java deleted file mode 100644 index 3db06e19..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * 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.Component; -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.WindowEvent; -import java.awt.event.WindowListener; -import java.io.InputStreamReader; -import java.io.Reader; -import java.text.MessageFormat; -import java.util.List; -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.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.LayoutStyle; -import javax.swing.text.Document; -import javax.swing.text.EditorKit; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author Clemens Orthacker - */ -public class HashDataViewer extends JDialog - implements ActionListener, WindowListener { - - public static final String PLAINTEXT_FONT = "Monospaced"; - - protected static final Log log = LogFactory.getLog(HashDataViewer.class); - private static HashDataViewer dialog; - - public static void showDialog(Component frameComp, List signedReferences, ResourceBundle messages, ActionListener saveListener, String saveCommand, HelpMouseListener helpListener) { - - log.info("******************* SHOW HASHDATA DIALOG"); - - Frame frame = JOptionPane.getFrameForComponent(frameComp); - - dialog = new HashDataViewer(frame, signedReferences.get(0), messages, saveListener, saveCommand, helpListener); - dialog.addWindowListener(dialog); - dialog.setVisible(true); - - } - - private HashDataViewer(Frame frame, HashDataInput hashData, ResourceBundle messages, ActionListener saveListener, String saveCommand, HelpMouseListener helpListener) { - super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); - - JPanel viewerPanel = createViewerPanel(messages, hashData, helpListener); - JPanel buttonPanel = createButtonPanel(messages, saveListener, saveCommand); - - - Container contentPane = getContentPane(); - contentPane.setPreferredSize(new Dimension(400, 300)); - - 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, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); - - pack(); - setLocationRelativeTo(frame); - } - - private JPanel createViewerPanel(ResourceBundle messages, HashDataInput hashData, HelpMouseListener helpListener) { - String mimeType = hashData.getMimeType(); - String encoding = hashData.getEncoding(); - - log.debug("display hashdata: " + mimeType + ";" + encoding); - - if (mimeType == null) { - mimeType = "text/plain"; - } - if (encoding == null) { - encoding = "UTF-8"; - } - - JEditorPane viewer = new JEditorPane(); - viewer.setEditable(false); - viewer.setContentType(mimeType); - if ("text/plain".equals(mimeType)) { - viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); - } - - EditorKit editorKit = viewer.getEditorKit(); - Document document = editorKit.createDefaultDocument(); - - Reader reader; - try { - reader = new InputStreamReader(hashData.getHashDataInput(), encoding); - viewer.read(reader, document); - } catch (Exception ex) { - String p = messages.getString(BKUGUIFacade.ERR_DISPLAY_HASHDATA); - viewer.setText(MessageFormat.format(p, ex.getMessage())); - } - - JScrollPane scrollPane = new JScrollPane(viewer); -// scrollPane.setPreferredSize(new Dimension(400, 300)); - scrollPane.setPreferredSize(viewer.getPreferredSize()); - scrollPane.setAlignmentX(LEFT_ALIGNMENT); - - JLabel viewerTitle = new JLabel(); - viewerTitle.setText(messages.getString(BKUGUIFacade.TITLE_HASHDATA)); - viewerTitle.setFont(viewerTitle.getFont().deriveFont(viewerTitle.getFont().getStyle() | java.awt.Font.BOLD)); - viewerTitle.setLabelFor(viewer); - - JLabel helpLabel = new JLabel(); - helpListener.setHelpTopic(BKUGUIFacade.HELP_HASHDATAVIEWER); - helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); - helpLabel.addMouseListener(helpListener); - helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - - JPanel viewerPanel = new JPanel(); - GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); - viewerPanel.setLayout(viewerPanelLayout); - - viewerPanelLayout.setHorizontalGroup( - viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(viewerPanelLayout.createSequentialGroup() - .addComponent(viewerTitle) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(scrollPane)); //, 0, 0, Short.MAX_VALUE)); - - viewerPanelLayout.setVerticalGroup( - viewerPanelLayout.createSequentialGroup() - .addGroup(viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(viewerTitle) - .addComponent(helpLabel)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(scrollPane)); //, 0, 0, Short.MAX_VALUE)); - -// viewerPanel.setLayout(new BoxLayout(viewerPanel, BoxLayout.PAGE_AXIS)); -// JLabel title = new JLabel(messages.getString(BKUGUIFacade.TITLE_HASHDATA)); -// title.setLabelFor(viewer); -// viewerPanel.add(title); -// viewerPanel.add(Box.createRigidArea(new Dimension(0, 5))); -// viewerPanel.add(scrollPane); -// viewerPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - - return viewerPanel; - } - - private JPanel createButtonPanel(ResourceBundle messages, ActionListener saveListener, String saveCommand) { - JButton closeButton = new JButton(); - closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); - closeButton.addActionListener(this); - - JButton saveButton = new JButton(); - saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); - saveButton.setActionCommand(saveCommand); - saveButton.addActionListener(saveListener); - - 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())) { - HashDataViewer.dialog.setVisible(false); -// HashDataViewer.dialog.dispose(); - } - - @Override - public void windowOpened(WindowEvent e) { - log.debug("WINDOW OPENED"); - } - - @Override - public void windowClosing(WindowEvent e) { - log.debug("WINDOW CLOSING"); - } - - @Override - public void windowClosed(WindowEvent e) { - log.debug("WINDOW CLOSED"); - } - - @Override - public void windowIconified(WindowEvent e) { - log.debug("WINDOW ICONIFIED"); - } - - @Override - public void windowDeiconified(WindowEvent e) { - } - - @Override - public void windowActivated(WindowEvent e) { - log.debug("WINDOW ACTIVATED"); - } - - @Override - public void windowDeactivated(WindowEvent e) { - log.debug("WINDOW DEACTIVATED"); - } - - - - - - - -} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java new file mode 100644 index 00000000..d9606177 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java @@ -0,0 +1,47 @@ +/* + * 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.Color; +import java.awt.Component; +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.table.TableCellRenderer; + +/** + * + * @author Clemens Orthacker + */ +public class HyperLinkRenderer extends JLabel implements TableCellRenderer { + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + HashDataInput hdi = (HashDataInput) value; + setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); + setBackground(Color.CYAN); + return this; + } + +// extends DefaultTableCellRenderer { +// +// @Override +// public void setValue(Object value) { +// HashDataInput hdi = (HashDataInput) value; +// setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); +// } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index 583dae0f..6250dd0e 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -83,7 +83,7 @@ public class SimpleGUI implements BKUGUIFacade { protected int buttonSize; - private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; +// private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; /** * @param contentPane @@ -924,16 +924,17 @@ public class SimpleGUI implements BKUGUIFacade { } } else { - final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - - ActionListener saveHashDataListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(tableModel.getSelectedHashData(), okListener, okCommand); - } - }; - showMultipleHashDataInputDialog(tableModel, okListener, okCommand, saveHashDataListener, "save"); + SimpleHashDataTableModel tableModel = new SimpleHashDataTableModel(signedReferences); +// final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); +// +// ActionListener saveHashDataListener = new ActionListener() { +// +// @Override +// public void actionPerformed(ActionEvent e) { +// showSaveHashDataInputDialog(tableModel.getSelectedHashData(), okListener, okCommand); +// } +// }; + showMultipleHashDataInputDialog(tableModel, okListener, okCommand); } } @@ -953,7 +954,7 @@ public class SimpleGUI implements BKUGUIFacade { log.debug("show plaintext hashdatainput dialog"); - HashDataViewer.showDialog(contentPane, signedReferences, messages, saveListener, saveCommand, helpListener); + ViewerDialog.showHashDataInput(contentPane, signedReferences, messages, saveListener, saveCommand, helpListener); } }); } @@ -1052,7 +1053,8 @@ public class SimpleGUI implements BKUGUIFacade { }); } - private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, final ActionListener saveListener, final String saveCommand) { + private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand) { +// , final ActionListener saveListener, final String saveCommand log.debug("scheduling multiple hashdatainput dialog"); @@ -1076,13 +1078,14 @@ public class SimpleGUI implements BKUGUIFacade { refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); JTable hashDataTable = new JTable(); + hashDataTable.setDefaultRenderer(HashDataInput.class, new HyperLinkRenderer()); hashDataTable.setModel(signedReferences); hashDataTable.setTableHeader(null); // hashDataTable.setShowVerticalLines(false); // hashDataTable.setRowSelectionAllowed(false); - TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); - selectCol.setMinWidth(CHECKBOX_WIDTH); - selectCol.setMaxWidth(CHECKBOX_WIDTH); +// TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); +// selectCol.setMinWidth(CHECKBOX_WIDTH); +// selectCol.setMaxWidth(CHECKBOX_WIDTH); // hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java new file mode 100644 index 00000000..463dbe81 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java @@ -0,0 +1,60 @@ +/* + * 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.event.ActionListener; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; +import javax.swing.table.DefaultTableModel; + +/** + * + * @author clemens + */ +class SimpleHashDataTableModel extends DefaultTableModel { + + protected List signedReferences; + + protected Class[] types = new Class[]{ + java.lang.String.class + }; + + public SimpleHashDataTableModel(List signedReferences) { + super(0, 1); + this.signedReferences = signedReferences; + for (HashDataInput hashDataInput : signedReferences) { + +// String desc = hashDataInput.getReferenceId() + " (" + hashDataInput.getMimeType() + ")"; + addRow(new Object[]{hashDataInput}); + } + } + + @Override + public Class getColumnClass(int columnIndex) { + return types[columnIndex]; + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + if (columnIndex == 1) + return true; + return false; + } +} \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java new file mode 100644 index 00000000..cd04ad98 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java @@ -0,0 +1,354 @@ +/* + * 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.Component; +import java.awt.Container; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.Charset; +import java.text.MessageFormat; +import java.util.List; +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.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.LayoutStyle; +import javax.swing.text.Document; +import javax.swing.text.EditorKit; +import javax.swing.text.html.HTMLDocument; +import javax.swing.text.html.HTMLEditorKit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class ViewerDialog extends JDialog + implements ActionListener { + + public static final String PLAINTEXT_FONT = "Monospaced"; + protected static final Log log = LogFactory.getLog(ViewerDialog.class); +// private ViewerDialog dialog; + + protected ResourceBundle messages; + + /** + * + * @param frameComp + * @param signedReferences currently, only one hashdata input (the first in the list) is displayed + * @param messages + * @param saveListener + * @param saveCommand + * @param helpListener + */ + public static void showHashDataInput(Component frameComp, + List hashDataInputs, + ResourceBundle messages, + ActionListener saveListener, + String saveCommand, + HelpMouseListener helpListener) { + + Frame frame = null; + if (frameComp != null) { + JOptionPane.getFrameForComponent(frameComp); + } + ViewerDialog viewer = new ViewerDialog(frame, + messages, + hashDataInputs, + saveListener, + saveCommand, + helpListener); + viewer.setVisible(true); + } + + public static void showHelp(Component frameComp, + String helpTopic, +// Reader helpDocument, + InputStream helpDocument, + String mimeType, + ResourceBundle messages) { + + Frame frame = null; + if (frameComp != null) { + JOptionPane.getFrameForComponent(frameComp); + } + ViewerDialog viewer = new ViewerDialog(frame, messages, helpTopic, helpDocument, mimeType); + viewer.setVisible(true); + } + + /** + * TODO make encoding aware! + * @param frame + * @param title + * @param messages + * @param hashDataInputs + * @param saveListener + * @param saveCommand + * @param helpListener + */ + private ViewerDialog(Frame frame, + ResourceBundle messages, + List hashDataInputs, + ActionListener saveListener, + String saveCommand, + HelpMouseListener helpListener) { + super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); + this.messages = messages; + + HashDataInput hashData = hashDataInputs.get(0); + +// Charset cs; +// if (hashData.getEncoding() == null) { +// cs = Charset.forName("UTF-8"); +// } else { +// try { +// cs = Charset.forName(hashData.getEncoding()); +// } catch (Exception ex) { +// log.debug("charset " + hashData.getEncoding() + " not supported, assuming UTF-8: " + ex.getMessage()); +// cs = Charset.forName("UTF-8"); +// } +// } + +// InputStreamReader isr = new InputStreamReader(hashData.getHashDataInput(), cs); +// Reader content = new BufferedReader(isr); + InputStream content = hashData.getHashDataInput(); + String mimeType = hashData.getMimeType(); + String encoding = hashData.getEncoding(); + + JPanel hashDataPanel = createViewerPanel(messages.getString(BKUGUIFacade.MESSAGE_HASHDATA), content, mimeType, encoding, helpListener); + JPanel buttonPanel = createButtonPanel(saveListener, saveCommand); + initContentPane(new Dimension(600, 400), hashDataPanel, buttonPanel); + + pack(); + if (frame != null) { + setLocationRelativeTo(frame); + } else { + setLocationByPlatform(true); + } + } + + private ViewerDialog(Frame frame, + ResourceBundle messages, + String helpTopic, +// Reader helpDocument, + InputStream helpDocument, + String mimeType) { + super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_HELP), true); + this.messages = messages; + + String p = messages.getString(BKUGUIFacade.MESSAGE_HELP); + String helpItem = messages.getString(helpTopic); + String viewerLabel = MessageFormat.format(p, new Object[] {helpItem}); + + JPanel helpPanel = createViewerPanel(viewerLabel, helpDocument, mimeType, null, null); + JPanel buttonPanel = createButtonPanel(); + + initContentPane(new Dimension(600, 400), helpPanel, buttonPanel); + pack(); + if (frame != null) { + setLocationRelativeTo(frame); + } 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 messages + * @param content + * @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 helpListener may be null + * @return + */ + private JPanel createViewerPanel(String viewerLabelText, InputStream content, String mimeType, String encoding, HelpMouseListener helpListener) { + log.debug("viewer dialog: " + mimeType); + + if (mimeType == null) { + mimeType = "text/plain"; + } else if ("application/xhtml+xml".equals(mimeType)) { + mimeType = "text/html"; + } + + JEditorPane viewer = new JEditorPane(); + viewer.setEditable(false); + viewer.setContentType(mimeType); + if ("text/plain".equals(mimeType)) { + viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); + } + + EditorKit editorKit = viewer.getEditorKit(); + Document document = editorKit.createDefaultDocument(); +// document.putProperty("IgnoreCharsetDirective", new Boolean(true)); + + try { + if (encoding != null) { + BufferedReader contentReader = new BufferedReader(new InputStreamReader(content, encoding)); + viewer.read(contentReader, document); + contentReader.close(); + } else { + // charset declaration in content + viewer.read(content, document); + content.close(); + } + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + String p = messages.getString(BKUGUIFacade.ERR_VIEWER); + viewer.setText(MessageFormat.format(p, ex.getMessage())); + } + + JScrollPane scrollPane = new JScrollPane(viewer); + scrollPane.setPreferredSize(viewer.getPreferredSize()); + scrollPane.setAlignmentX(LEFT_ALIGNMENT); + viewer.setCaretPosition(0); + + JLabel viewerLabel = new JLabel(); + viewerLabel.setText(viewerLabelText); + viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); + viewerLabel.setLabelFor(viewer); + + JPanel viewerPanel = new JPanel(); + GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); + viewerPanel.setLayout(viewerPanelLayout); + + if (helpListener != null) { + JLabel helpLabel = new JLabel(); + helpListener.setHelpTopic(BKUGUIFacade.HELP_HASHDATAVIEWER); + helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); + helpLabel.addMouseListener(helpListener); + helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + viewerPanelLayout.setHorizontalGroup( + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(viewerPanelLayout.createSequentialGroup().addComponent(viewerLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE).addComponent(helpLabel)).addComponent(scrollPane)); //, 0, 0, Short.MAX_VALUE)); + viewerPanelLayout.setVerticalGroup( + viewerPanelLayout.createSequentialGroup() + .addGroup(viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(viewerLabel) + .addComponent(helpLabel)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(scrollPane)); + } else { + viewerPanelLayout.setHorizontalGroup( + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(viewerLabel) + .addComponent(scrollPane)); + viewerPanelLayout.setVerticalGroup( + viewerPanelLayout.createSequentialGroup() + .addComponent(viewerLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(scrollPane)); + + } + + return viewerPanel; + } + + private JPanel createButtonPanel() { + JButton closeButton = new JButton(); + closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); + closeButton.addActionListener(this); + + JPanel buttonPanel = new JPanel(); + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(closeButton)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(closeButton)); + return buttonPanel; + } + + private JPanel createButtonPanel(ActionListener saveListener, String saveCommand) { + JButton closeButton = new JButton(); + closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); + closeButton.addActionListener(this); + + JButton saveButton = new JButton(); + saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + 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())) { +// ViewerDialog.dialog.setVisible(false); +// HashDataViewer.dialog.dispose(); + this.setVisible(false); + } +} -- cgit v1.2.3 From 547d2ac46ea1feb323fd945de690b8ee0ca9c5f3 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 13 Nov 2008 18:33:03 +0000 Subject: FRAME HashDataDisplay FRAME Help git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@167 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java index cd04ad98..e643c876 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java @@ -151,6 +151,9 @@ public class ViewerDialog extends JDialog InputStream content = hashData.getHashDataInput(); String mimeType = hashData.getMimeType(); String encoding = hashData.getEncoding(); + if (encoding == null) { + encoding = "UTF-8"; + } JPanel hashDataPanel = createViewerPanel(messages.getString(BKUGUIFacade.MESSAGE_HASHDATA), content, mimeType, encoding, helpListener); JPanel buttonPanel = createButtonPanel(saveListener, saveCommand); -- cgit v1.2.3 From fef61ddc786960015c6fc416d4ad2d5d0f2048d1 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 13 Nov 2008 20:56:23 +0000 Subject: bugfix openwindow blocked bugfix helpTopic always hashdataviewer git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@168 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 1 + .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 288 +++++++++++++++++ .../java/at/gv/egiz/bku/gui/HelpMouseListener.java | 10 +- .../main/java/at/gv/egiz/bku/gui/HelpViewer.java | 211 ++++++++++++ .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 3 +- .../main/java/at/gv/egiz/bku/gui/ViewerDialog.java | 357 --------------------- 6 files changed, 509 insertions(+), 361 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 2daf3300..c7032f90 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -38,6 +38,7 @@ public interface BKUGUIFacade { public static final String ERR_CARD_LOCKED = "error.card.locked"; public static final String ERR_CARD_NOTACTIVATED = "error.card.notactivated"; public static final String ERR_VIEWER = "error.viewer"; + public static final String ERR_EXTERNAL_LINK = "error.external.link"; public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; public static final String DEFAULT_BACKGROUND = "/images/BackgroundChipperling.png"; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java new file mode 100644 index 00000000..8883098a --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java @@ -0,0 +1,288 @@ +/* + * 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.Component; +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.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.Charset; +import java.text.MessageFormat; +import java.util.List; +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.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.LayoutStyle; +import javax.swing.text.Document; +import javax.swing.text.EditorKit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class HashDataViewer extends JDialog + implements ActionListener { + + public static final String PLAINTEXT_FONT = "Monospaced"; + protected static final Log log = LogFactory.getLog(HashDataViewer.class); + + private static HashDataViewer dialog; + + protected ResourceBundle messages; + + /** + * + * @param signedReferences currently, only one hashdata input (the first in the list) is displayed + */ + public static void showHashDataInput(List hashDataInputs, + ResourceBundle messages, + ActionListener saveListener, + String saveCommand, + ActionListener helpListener) { + showHashDataInput(null, hashDataInputs, messages, saveListener, saveCommand, helpListener); + } + + /** + * + * @param frameComp owner + */ + public static void showHashDataInput(Component frameComp, + List hashDataInputs, + ResourceBundle messages, + ActionListener saveListener, + String saveCommand, + ActionListener helpListener) { + + Frame frame = null; + if (frameComp != null) { + JOptionPane.getFrameForComponent(frameComp); + } + dialog = new HashDataViewer(frame, + messages, + hashDataInputs, + saveListener, + saveCommand, + helpListener); + dialog.setVisible(true); + } + + private HashDataViewer(Frame frame, + ResourceBundle messages, + List hashDataInputs, + ActionListener saveListener, + String saveCommand, + ActionListener helpListener) { + super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); + this.messages = messages; + + HashDataInput hashData = hashDataInputs.get(0); + + Charset cs; + if (hashData.getEncoding() == null) { + cs = Charset.forName("UTF-8"); + } else { + try { + cs = Charset.forName(hashData.getEncoding()); + } catch (Exception ex) { + log.debug("charset " + hashData.getEncoding() + " not supported, assuming UTF-8: " + ex.getMessage()); + cs = Charset.forName("UTF-8"); + } + } + + + InputStreamReader isr = new InputStreamReader(hashData.getHashDataInput(), cs); + Reader content = new BufferedReader(isr); + + JPanel hashDataPanel = createViewerPanel( + messages.getString(BKUGUIFacade.MESSAGE_HASHDATA), + content, + hashData.getMimeType(), + helpListener); + JPanel buttonPanel = createButtonPanel(saveListener, saveCommand); + initContentPane(new Dimension(600, 400), hashDataPanel, buttonPanel); + + pack(); + if (frame != null) { + setLocationRelativeTo(frame); + } 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 messages + * @param content + * @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 helpListener may be null + * @return + */ + private JPanel createViewerPanel(String viewerLabelText, + Reader content, + String mimeType, + final ActionListener helpListener) { + log.debug("viewer dialog: " + mimeType); + + if (mimeType == null) { + mimeType = "text/plain"; + } else if ("application/xhtml+xml".equals(mimeType)) { + mimeType = "text/html"; + } + + JEditorPane viewer = new JEditorPane(); + viewer.setEditable(false); + viewer.setContentType(mimeType); + if ("text/plain".equals(mimeType)) { + viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); + } + + EditorKit editorKit = viewer.getEditorKit(); + Document document = editorKit.createDefaultDocument(); +// document.putProperty("IgnoreCharsetDirective", new Boolean(true)); + + try { + viewer.read(content, document); + content.close(); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + String p = messages.getString(BKUGUIFacade.ERR_VIEWER); + viewer.setText(MessageFormat.format(p, ex.getMessage())); + } + + JScrollPane scrollPane = new JScrollPane(viewer); + scrollPane.setPreferredSize(viewer.getPreferredSize()); + scrollPane.setAlignmentX(LEFT_ALIGNMENT); + viewer.setCaretPosition(0); + + JLabel viewerLabel = new JLabel(); + viewerLabel.setText(viewerLabelText); + viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); + viewerLabel.setLabelFor(viewer); + + JPanel viewerPanel = new JPanel(); + GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); + viewerPanel.setLayout(viewerPanelLayout); + + if (helpListener != null) { + JLabel helpLabel = new JLabel(); + helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); + 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)); + viewerPanelLayout.setHorizontalGroup( + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(viewerPanelLayout.createSequentialGroup().addComponent(viewerLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE).addComponent(helpLabel)).addComponent(scrollPane)); //, 0, 0, Short.MAX_VALUE)); + viewerPanelLayout.setVerticalGroup( + viewerPanelLayout.createSequentialGroup() + .addGroup(viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(viewerLabel) + .addComponent(helpLabel)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(scrollPane)); + } else { + viewerPanelLayout.setHorizontalGroup( + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(viewerLabel) + .addComponent(scrollPane)); + viewerPanelLayout.setVerticalGroup( + viewerPanelLayout.createSequentialGroup() + .addComponent(viewerLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(scrollPane)); + + } + + return viewerPanel; + } + + private JPanel createButtonPanel(ActionListener saveListener, String saveCommand) { + JButton closeButton = new JButton(); + closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); + closeButton.addActionListener(this); + + JButton saveButton = new JButton(); + saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + 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) { + HashDataViewer.dialog.setVisible(false); + } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java index 531884d1..b7bbe971 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java @@ -28,23 +28,27 @@ public class HelpMouseListener extends MouseAdapter { protected static final Log log = LogFactory.getLog(HelpMouseListener.class); - protected ActionListener externalHelpListener; + protected ActionListener helpListener; protected String locale; protected String topic; public HelpMouseListener(ActionListener externalHelpListener) { super(); - this.externalHelpListener = externalHelpListener; + this.helpListener = externalHelpListener; } public void setHelpTopic(String topic) { log.trace("setting help topic: " + topic); this.topic = topic; } + + public ActionListener getActionListener() { + return helpListener; + } @Override public void mouseClicked(MouseEvent arg0) { ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, topic); - externalHelpListener.actionPerformed(e); + helpListener.actionPerformed(e); } } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java new file mode 100644 index 00000000..42ca2090 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java @@ -0,0 +1,211 @@ +/* + * 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.bku.gui.*; +import java.applet.AppletContext; +import java.awt.Component; +import java.awt.Container; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.net.URL; +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.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.LayoutStyle; +import javax.swing.SwingUtilities; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class HelpViewer extends JDialog + implements ActionListener { + + protected static final Log log = LogFactory.getLog(HelpViewer.class); + private static HelpViewer dialog; + protected ResourceBundle messages; + protected AppletContext ctx; + + /** + * + * @param ctx external links are opened via ctx.showDocument() + * @param helpURL + * @param helpTopic + * @param messages + */ + public static void showHelpDialog(AppletContext ctx, + URL helpURL, + String helpTopic, + ResourceBundle messages) { + showHelpDialog(null, ctx, helpURL, helpTopic, messages); + } + + public static void showHelpDialog(URL helpURL, + String helpTopic, + ResourceBundle messages) { + showHelpDialog(null, null, helpURL, helpTopic, messages); + } + + public static void showHelpDialog(Component owner, + AppletContext ctx, + URL helpURL, + String helpTopic, + ResourceBundle messages) { + + Frame frame = null; + if (owner != null) { + JOptionPane.getFrameForComponent(owner); + } + dialog = new HelpViewer(frame, messages, ctx, helpURL, helpTopic); + dialog.setVisible(true); + } + + private HelpViewer(Frame frame, + ResourceBundle messages, + AppletContext ctx, + URL helpURL, + String helpTopic) { + super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_HELP), true); + this.messages = messages; + this.ctx = ctx; + + String p = messages.getString(BKUGUIFacade.MESSAGE_HELP); + String helpItem = messages.getString(helpTopic); + String viewerLabel = MessageFormat.format(p, new Object[]{helpItem}); + + JPanel helpPanel = createViewerPanel(viewerLabel, helpURL); + JPanel buttonPanel = createButtonPanel(); + + initContentPane(new Dimension(600, 400), helpPanel, buttonPanel); + pack(); + if (frame != null) { + setLocationRelativeTo(frame); + } 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()); + } + + private JPanel createViewerPanel(String viewerLabelText, URL helpURL) { + log.debug("viewer dialog: " + helpURL.toString()); + + final JEditorPane viewer = new JEditorPane(); + viewer.setEditable(false); + try { + viewer.setPage(helpURL); + viewer.addHyperlinkListener(new HyperlinkListener() { + + @Override + public void hyperlinkUpdate(HyperlinkEvent e) { + final URL url = e.getURL(); + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + if (ctx != null) { + log.debug("open external link in help viewer: " + url); + ctx.showDocument(url, "_blank"); + } else { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + String msgP = messages.getString(BKUGUIFacade.ERR_EXTERNAL_LINK); + String msg = MessageFormat.format(msgP, url); + String title = messages.getString(BKUGUIFacade.TITLE_ERROR); + JOptionPane.showMessageDialog(rootPane, msg, title, JOptionPane.ERROR_MESSAGE); + } + }); + } + } + } + }); + } catch (IOException ex) { + String p = messages.getString(BKUGUIFacade.ERR_VIEWER); + viewer.setText(MessageFormat.format(p, new Object[]{ex.getMessage()})); + } + + JScrollPane scrollPane = new JScrollPane(viewer); + scrollPane.setPreferredSize(viewer.getPreferredSize()); + scrollPane.setAlignmentX(LEFT_ALIGNMENT); + viewer.setCaretPosition(0); + + JLabel viewerLabel = new JLabel(); + viewerLabel.setText(viewerLabelText); + viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); + viewerLabel.setLabelFor(viewer); + + JPanel viewerPanel = new JPanel(); + GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); + viewerPanel.setLayout(viewerPanelLayout); + + viewerPanelLayout.setHorizontalGroup( + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(viewerLabel).addComponent(scrollPane)); + viewerPanelLayout.setVerticalGroup( + viewerPanelLayout.createSequentialGroup().addComponent(viewerLabel).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(scrollPane)); + + return viewerPanel; + } + + private JPanel createButtonPanel() { + JButton closeButton = new JButton(); + closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); + closeButton.addActionListener(this); + + JPanel buttonPanel = new JPanel(); + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(closeButton)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup().addComponent(closeButton)); + return buttonPanel; + } + + @Override + public void actionPerformed(ActionEvent e) { + HelpViewer.dialog.setVisible(false); + } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index 6250dd0e..a810d34c 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -954,7 +954,8 @@ public class SimpleGUI implements BKUGUIFacade { log.debug("show plaintext hashdatainput dialog"); - ViewerDialog.showHashDataInput(contentPane, signedReferences, messages, saveListener, saveCommand, helpListener); + ActionListener l = helpListener.getActionListener(); + HashDataViewer.showHashDataInput(contentPane, signedReferences, messages, saveListener, saveCommand, l); } }); } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java deleted file mode 100644 index e643c876..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * 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.Component; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Frame; -import java.awt.Point; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URL; -import java.net.URLConnection; -import java.nio.charset.Charset; -import java.text.MessageFormat; -import java.util.List; -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.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.LayoutStyle; -import javax.swing.text.Document; -import javax.swing.text.EditorKit; -import javax.swing.text.html.HTMLDocument; -import javax.swing.text.html.HTMLEditorKit; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author Clemens Orthacker - */ -public class ViewerDialog extends JDialog - implements ActionListener { - - public static final String PLAINTEXT_FONT = "Monospaced"; - protected static final Log log = LogFactory.getLog(ViewerDialog.class); -// private ViewerDialog dialog; - - protected ResourceBundle messages; - - /** - * - * @param frameComp - * @param signedReferences currently, only one hashdata input (the first in the list) is displayed - * @param messages - * @param saveListener - * @param saveCommand - * @param helpListener - */ - public static void showHashDataInput(Component frameComp, - List hashDataInputs, - ResourceBundle messages, - ActionListener saveListener, - String saveCommand, - HelpMouseListener helpListener) { - - Frame frame = null; - if (frameComp != null) { - JOptionPane.getFrameForComponent(frameComp); - } - ViewerDialog viewer = new ViewerDialog(frame, - messages, - hashDataInputs, - saveListener, - saveCommand, - helpListener); - viewer.setVisible(true); - } - - public static void showHelp(Component frameComp, - String helpTopic, -// Reader helpDocument, - InputStream helpDocument, - String mimeType, - ResourceBundle messages) { - - Frame frame = null; - if (frameComp != null) { - JOptionPane.getFrameForComponent(frameComp); - } - ViewerDialog viewer = new ViewerDialog(frame, messages, helpTopic, helpDocument, mimeType); - viewer.setVisible(true); - } - - /** - * TODO make encoding aware! - * @param frame - * @param title - * @param messages - * @param hashDataInputs - * @param saveListener - * @param saveCommand - * @param helpListener - */ - private ViewerDialog(Frame frame, - ResourceBundle messages, - List hashDataInputs, - ActionListener saveListener, - String saveCommand, - HelpMouseListener helpListener) { - super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); - this.messages = messages; - - HashDataInput hashData = hashDataInputs.get(0); - -// Charset cs; -// if (hashData.getEncoding() == null) { -// cs = Charset.forName("UTF-8"); -// } else { -// try { -// cs = Charset.forName(hashData.getEncoding()); -// } catch (Exception ex) { -// log.debug("charset " + hashData.getEncoding() + " not supported, assuming UTF-8: " + ex.getMessage()); -// cs = Charset.forName("UTF-8"); -// } -// } - -// InputStreamReader isr = new InputStreamReader(hashData.getHashDataInput(), cs); -// Reader content = new BufferedReader(isr); - InputStream content = hashData.getHashDataInput(); - String mimeType = hashData.getMimeType(); - String encoding = hashData.getEncoding(); - if (encoding == null) { - encoding = "UTF-8"; - } - - JPanel hashDataPanel = createViewerPanel(messages.getString(BKUGUIFacade.MESSAGE_HASHDATA), content, mimeType, encoding, helpListener); - JPanel buttonPanel = createButtonPanel(saveListener, saveCommand); - initContentPane(new Dimension(600, 400), hashDataPanel, buttonPanel); - - pack(); - if (frame != null) { - setLocationRelativeTo(frame); - } else { - setLocationByPlatform(true); - } - } - - private ViewerDialog(Frame frame, - ResourceBundle messages, - String helpTopic, -// Reader helpDocument, - InputStream helpDocument, - String mimeType) { - super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_HELP), true); - this.messages = messages; - - String p = messages.getString(BKUGUIFacade.MESSAGE_HELP); - String helpItem = messages.getString(helpTopic); - String viewerLabel = MessageFormat.format(p, new Object[] {helpItem}); - - JPanel helpPanel = createViewerPanel(viewerLabel, helpDocument, mimeType, null, null); - JPanel buttonPanel = createButtonPanel(); - - initContentPane(new Dimension(600, 400), helpPanel, buttonPanel); - pack(); - if (frame != null) { - setLocationRelativeTo(frame); - } 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 messages - * @param content - * @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 helpListener may be null - * @return - */ - private JPanel createViewerPanel(String viewerLabelText, InputStream content, String mimeType, String encoding, HelpMouseListener helpListener) { - log.debug("viewer dialog: " + mimeType); - - if (mimeType == null) { - mimeType = "text/plain"; - } else if ("application/xhtml+xml".equals(mimeType)) { - mimeType = "text/html"; - } - - JEditorPane viewer = new JEditorPane(); - viewer.setEditable(false); - viewer.setContentType(mimeType); - if ("text/plain".equals(mimeType)) { - viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); - } - - EditorKit editorKit = viewer.getEditorKit(); - Document document = editorKit.createDefaultDocument(); -// document.putProperty("IgnoreCharsetDirective", new Boolean(true)); - - try { - if (encoding != null) { - BufferedReader contentReader = new BufferedReader(new InputStreamReader(content, encoding)); - viewer.read(contentReader, document); - contentReader.close(); - } else { - // charset declaration in content - viewer.read(content, document); - content.close(); - } - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - String p = messages.getString(BKUGUIFacade.ERR_VIEWER); - viewer.setText(MessageFormat.format(p, ex.getMessage())); - } - - JScrollPane scrollPane = new JScrollPane(viewer); - scrollPane.setPreferredSize(viewer.getPreferredSize()); - scrollPane.setAlignmentX(LEFT_ALIGNMENT); - viewer.setCaretPosition(0); - - JLabel viewerLabel = new JLabel(); - viewerLabel.setText(viewerLabelText); - viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); - viewerLabel.setLabelFor(viewer); - - JPanel viewerPanel = new JPanel(); - GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); - viewerPanel.setLayout(viewerPanelLayout); - - if (helpListener != null) { - JLabel helpLabel = new JLabel(); - helpListener.setHelpTopic(BKUGUIFacade.HELP_HASHDATAVIEWER); - helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); - helpLabel.addMouseListener(helpListener); - helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - viewerPanelLayout.setHorizontalGroup( - viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(viewerPanelLayout.createSequentialGroup().addComponent(viewerLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE).addComponent(helpLabel)).addComponent(scrollPane)); //, 0, 0, Short.MAX_VALUE)); - viewerPanelLayout.setVerticalGroup( - viewerPanelLayout.createSequentialGroup() - .addGroup(viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(viewerLabel) - .addComponent(helpLabel)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(scrollPane)); - } else { - viewerPanelLayout.setHorizontalGroup( - viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(viewerLabel) - .addComponent(scrollPane)); - viewerPanelLayout.setVerticalGroup( - viewerPanelLayout.createSequentialGroup() - .addComponent(viewerLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(scrollPane)); - - } - - return viewerPanel; - } - - private JPanel createButtonPanel() { - JButton closeButton = new JButton(); - closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); - closeButton.addActionListener(this); - - JPanel buttonPanel = new JPanel(); - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(closeButton)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(closeButton)); - return buttonPanel; - } - - private JPanel createButtonPanel(ActionListener saveListener, String saveCommand) { - JButton closeButton = new JButton(); - closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); - closeButton.addActionListener(this); - - JButton saveButton = new JButton(); - saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); - saveButton.setActionCommand(saveCommand); - saveButton.addActionListener(saveListener); - - 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())) { -// ViewerDialog.dialog.setVisible(false); -// HashDataViewer.dialog.dispose(); - this.setVisible(false); - } -} -- cgit v1.2.3 From f09efb78459c7cd49ca4e28d92f170833e7ee32d Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 14 Nov 2008 16:30:28 +0000 Subject: git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@172 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 1 + .../at/gv/egiz/bku/gui/DefaultHelpListener.java | 62 ++++++++++++++++++++ .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 15 ++++- .../main/java/at/gv/egiz/bku/gui/HelpViewer.java | 5 +- .../main/java/at/gv/egiz/bku/gui/ImagePanel.java | 4 +- .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 6 ++ .../egiz/bku/gui/html/RestrictedHTMLEditorKit.java | 49 ++++++++++++++++ .../gv/egiz/bku/gui/html/RestrictedImageView.java | 67 ++++++++++++++++++++++ 8 files changed, 202 insertions(+), 7 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/html/RestrictedHTMLEditorKit.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/html/RestrictedImageView.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index c7032f90..87982c79 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -89,6 +89,7 @@ public interface BKUGUIFacade { public static final String BUTTON_SAVE = "button.save"; public static final String BUTTON_CLOSE = "button.close"; public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; + public static final String ALT_HELP = "alt.help"; public void init(Container contentPane, Locale locale, URL background, ActionListener helpListener); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java new file mode 100644 index 00000000..ba968a48 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java @@ -0,0 +1,62 @@ +/* + * 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.applet.AppletContext; +import java.net.URL; +import java.util.Locale; +import javax.swing.SwingUtilities; + +/** + * + * @author Clemens Orthacker + */ +public class DefaultHelpListener extends AbstractHelpListener { + + protected AppletContext ctx; + + public DefaultHelpListener(AppletContext ctx, URL helpURL, Locale locale) { + super(helpURL, locale); + this.ctx = ctx; + } + + public DefaultHelpListener(URL helpURL, Locale locale) { + super(helpURL, locale); + this.ctx = null; + } + + @Override + public void showDocument(final URL helpURL, final String helpTopic) throws Exception { + log.debug("schedule help dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show help dialog"); + + if (ctx == null) { + HelpViewer.showHelpDialog(helpURL, helpTopic, messages); + + } else { + HelpViewer.showHelpDialog(ctx, helpURL, helpTopic, messages); + } + } + }); + } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java index 8883098a..31887bde 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.gui; +import at.gv.egiz.bku.gui.html.RestrictedHTMLEditorKit; import at.gv.egiz.stal.HashDataInput; import java.awt.Component; import java.awt.Container; @@ -23,6 +24,7 @@ import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; +import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -47,6 +49,11 @@ import javax.swing.JScrollPane; import javax.swing.LayoutStyle; import javax.swing.text.Document; import javax.swing.text.EditorKit; +import javax.swing.text.Element; +import javax.swing.text.ViewFactory; +import javax.swing.text.html.HTML; +import javax.swing.text.html.HTMLEditorKit; +import javax.swing.text.html.ImageView; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -184,11 +191,14 @@ public class HashDataViewer extends JDialog } JEditorPane viewer = new JEditorPane(); - viewer.setEditable(false); - viewer.setContentType(mimeType); + if ("text/plain".equals(mimeType)) { viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); +// } else if ("text/html".equals(mimeType)) { +// viewer.setEditorKitForContentType("text/html", new RestrictedHTMLEditorKit()); } + viewer.setEditable(false); + viewer.setContentType(mimeType); EditorKit editorKit = viewer.getEditorKit(); Document document = editorKit.createDefaultDocument(); @@ -220,6 +230,7 @@ public class HashDataViewer extends JDialog 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 diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java index 42ca2090..173254e7 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java @@ -16,7 +16,6 @@ */ package at.gv.egiz.bku.gui; -import at.gv.egiz.bku.gui.*; import java.applet.AppletContext; import java.awt.Component; import java.awt.Container; @@ -30,7 +29,6 @@ import java.net.URL; 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; @@ -136,6 +134,7 @@ public class HelpViewer extends JDialog final JEditorPane viewer = new JEditorPane(); viewer.setEditable(false); try { + viewer.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); viewer.setPage(helpURL); viewer.addHyperlinkListener(new HyperlinkListener() { @@ -165,7 +164,7 @@ public class HelpViewer extends JDialog String p = messages.getString(BKUGUIFacade.ERR_VIEWER); viewer.setText(MessageFormat.format(p, new Object[]{ex.getMessage()})); } - + viewer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); JScrollPane scrollPane = new JScrollPane(viewer); scrollPane.setPreferredSize(viewer.getPreferredSize()); scrollPane.setAlignmentX(LEFT_ALIGNMENT); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java index 1185cf53..271c0b65 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java @@ -24,8 +24,8 @@ import javax.swing.ImageIcon; import javax.swing.JPanel; /** - * - * @author clemens + * + * @author Clemens Orthacker */ public class ImagePanel extends JPanel { diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index a810d34c..bb568b75 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -158,6 +158,11 @@ public class SimpleGUI implements BKUGUIFacade { if (background == null) { background = this.getClass().getResource(DEFAULT_BACKGROUND); } + if ("file".equals(background.getProtocol())) { + log.warn("local background image not allowed: " + background); + background = this.getClass().getResource(DEFAULT_BACKGROUND); + } + log.debug("loading background " + background); contentPanel = new ImagePanel(background); // contentPanel.setBorder(new TitledBorder("content")); @@ -179,6 +184,7 @@ public class SimpleGUI implements BKUGUIFacade { helpLabel = new JLabel(); helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); + helpLabel.getAccessibleContext().setAccessibleName(messages.getString(ALT_HELP)); helpLabel.addMouseListener(helpListener); helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/html/RestrictedHTMLEditorKit.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/html/RestrictedHTMLEditorKit.java new file mode 100644 index 00000000..680bf1a4 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/html/RestrictedHTMLEditorKit.java @@ -0,0 +1,49 @@ +/* + * 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.html; + +import javax.swing.text.Element; +import javax.swing.text.StyleConstants; +import javax.swing.text.View; +import javax.swing.text.html.HTML; +import javax.swing.text.html.HTMLEditorKit; + +/** + * + * @author Clemens Orthacker + */ +public class RestrictedHTMLEditorKit extends HTMLEditorKit { + + + public static class RestrictedHTMLFactory extends HTMLFactory { + + @Override + public View create(Element elem) { + Object o = + elem.getAttributes().getAttribute(StyleConstants.NameAttribute); + if (o instanceof HTML.Tag) { + HTML.Tag kind = (HTML.Tag) o; + if (kind == HTML.Tag.IMG) + return new RestrictedImageView(elem); + } + return super.create( elem ); + } + + } + +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/html/RestrictedImageView.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/html/RestrictedImageView.java new file mode 100644 index 00000000..b1aa35db --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/html/RestrictedImageView.java @@ -0,0 +1,67 @@ +/* + * 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.html; + +import javax.swing.text.Element; +import javax.swing.text.html.HTML; +import javax.swing.text.html.ImageView; + +/** + * + * @author Clemens Orthacker + */ +/** + * ImageViewer.refreshImage() (and loadImage()) is private :-( + */ + public class RestrictedImageView extends ImageView { + + public RestrictedImageView(Element elem) { + super(elem); + } + +// @Override +// public Image getImage() { +// int s = state; +// if ((s & RELOAD_IMAGE_FLAG) != 0) { +// refreshImage(); +// } +// s = state; +// if ((s & RELOAD_FLAG) != 0) { +// synchronized(this) { +// state = (state | RELOAD_FLAG) ^ RELOAD_FLAG; +// } +// setPropertiesFromAttributes(); +// } +// return super.getImage(); +// } + + /** + * check whether this URL corresponds to the data URI scheme + * (and the referenced content is directly included in the document). + * @return + */ + private boolean isDataURI() { + String src = (String)getElement().getAttributes(). + getAttribute(HTML.Attribute.SRC); + if (src == null) { + return false; + } + + return src.toLowerCase().startsWith("data"); + } + } \ No newline at end of file -- cgit v1.2.3 From 28e81afd92a6568ff78736b72c5257a86c0b9b91 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 18 Nov 2008 08:03:35 +0000 Subject: GUI refactoring 1 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@177 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 6 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 6 +- .../java/at/gv/egiz/bku/gui/BKUGUIFactory.java | 25 +- .../at/gv/egiz/bku/gui/DefaultHelpListener.java | 37 +- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 6 - .../main/java/at/gv/egiz/bku/gui/HelpViewer.java | 2 +- .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 1165 +++++++++++--------- 7 files changed, 695 insertions(+), 552 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index d661c71a..f68f2ece 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -87,8 +87,8 @@ public class BKUGUI implements BKUGUIFacade { * @param contentPane * @param localeString may be null */ - @Override - public void init(final Container contentPane, Locale locale, final URL background, ActionListener helpListener) { +// @Override + public void init(final Container contentPane, Locale locale, Style guiStyle, final URL background, ActionListener helpListener) { if (locale != null) { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); @@ -814,7 +814,7 @@ public class BKUGUI implements BKUGUIFacade { } @Override - public void showHashDataInputDialog(final List signedReferences, boolean standalone, final ActionListener okListener, final String okCommand) { + public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { if (signedReferences == null) { showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 87982c79..2dbba730 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -91,7 +91,9 @@ public interface BKUGUIFacade { public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; public static final String ALT_HELP = "alt.help"; - public void init(Container contentPane, Locale locale, URL background, ActionListener helpListener); + public enum Style { simple, advanced }; + +// public void init(Container contentPane, Locale locale, Style guiStyle, URL background, ActionListener helpListener); /** * @@ -128,7 +130,7 @@ public interface BKUGUIFacade { * @param okListener * @param okCommand */ - public void showHashDataInputDialog(List signedReferences, boolean externalDisplay, ActionListener okListener, String okCommand); + public void showHashDataInputDialog(List signedReferences, ActionListener okListener, String okCommand); /** * TODO pull out from BKUGUIFacade. (or make this strictly an applet internal version) diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java index 87676026..f4981614 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java @@ -17,24 +17,29 @@ package at.gv.egiz.bku.gui; +import java.awt.Container; +import java.awt.event.ActionListener; +import java.net.URL; +import java.util.Locale; + public class BKUGUIFactory { public static final String SIMPLE_GUI = "simple"; public static final String ADVANCED_GUI = "advanced"; - private static BKUGUIFactory instance = new BKUGUIFactory(); +// private static BKUGUIFactory instance = new BKUGUIFactory(); - private BKUGUIFactory() { - } +// private BKUGUIFactory() { +// } +// +// protected BKUGUIFacade createNewGUI(Container contentPane, Locale locale, String style, URL background, ActionListener helpListener) { +// +// } - protected BKUGUIFacade createNewGUI(String style) { + public static BKUGUIFacade createGUI(Container contentPane, Locale locale, String style, URL background, ActionListener helpListener) { if (ADVANCED_GUI.equals(style)) { - return new BKUGUI(); + return new SimpleGUI(contentPane, locale, BKUGUIFacade.Style.advanced, background, helpListener); } - return new SimpleGUI(); - } - - public static BKUGUIFacade createGUI(String style) { - return instance.createNewGUI(style); + return new SimpleGUI(contentPane, locale, BKUGUIFacade.Style.simple, background, helpListener); } } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java index ba968a48..f03bf158 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java @@ -17,6 +17,7 @@ package at.gv.egiz.bku.gui; import java.applet.AppletContext; +import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.util.Locale; import javax.swing.SwingUtilities; @@ -29,34 +30,56 @@ public class DefaultHelpListener extends AbstractHelpListener { protected AppletContext ctx; + /** + * + * @param ctx open external links via applet context + * @param helpURL + * @param locale + */ public DefaultHelpListener(AppletContext ctx, URL helpURL, Locale locale) { super(helpURL, locale); this.ctx = ctx; } + /** + * external links in help document are not opened + * @param helpURL + * @param locale + */ public DefaultHelpListener(URL helpURL, Locale locale) { super(helpURL, locale); this.ctx = null; } + /** + * blocks until help viewer returns (is closed) + * @param helpURL + * @param helpTopic + */ @Override - public void showDocument(final URL helpURL, final String helpTopic) throws Exception { - log.debug("schedule help dialog"); - - SwingUtilities.invokeLater(new Runnable() { + public void showDocument(final URL helpURL, final String helpTopic) { +// try { + log.debug("schedule help dialog"); + +// SwingUtilities.invokeAndWait(new Runnable() { + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - + log.debug("show help dialog"); - + if (ctx == null) { HelpViewer.showHelpDialog(helpURL, helpTopic, messages); - } else { HelpViewer.showHelpDialog(ctx, helpURL, helpTopic, messages); } } }); +// } catch (InterruptedException ex) { +// log.error("Failed to display HelpViewer: " + ex.getMessage(), ex); +// } catch (InvocationTargetException ex) { +// log.error("Failed to display HelpViewer: " + ex.getMessage(), ex); +// } } } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java index 31887bde..7b77faeb 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java @@ -16,7 +16,6 @@ */ package at.gv.egiz.bku.gui; -import at.gv.egiz.bku.gui.html.RestrictedHTMLEditorKit; import at.gv.egiz.stal.HashDataInput; import java.awt.Component; import java.awt.Container; @@ -49,11 +48,6 @@ import javax.swing.JScrollPane; import javax.swing.LayoutStyle; import javax.swing.text.Document; import javax.swing.text.EditorKit; -import javax.swing.text.Element; -import javax.swing.text.ViewFactory; -import javax.swing.text.html.HTML; -import javax.swing.text.html.HTMLEditorKit; -import javax.swing.text.html.ImageView; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java index 173254e7..0fef3f75 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java @@ -105,7 +105,7 @@ public class HelpViewer extends JDialog JPanel helpPanel = createViewerPanel(viewerLabel, helpURL); JPanel buttonPanel = createButtonPanel(); - initContentPane(new Dimension(600, 400), helpPanel, buttonPanel); + initContentPane(new Dimension(600, 600), helpPanel, buttonPanel); pack(); if (frame != null) { setLocationRelativeTo(frame); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index bb568b75..d4d6efef 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -32,6 +32,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.text.MessageFormat; import java.util.List; @@ -40,7 +41,6 @@ import java.util.ResourceBundle; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; -import javax.swing.JCheckBox; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -51,7 +51,6 @@ import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.LayoutStyle; import javax.swing.SwingUtilities; -import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -69,38 +68,60 @@ public class SimpleGUI implements BKUGUIFacade { protected Container contentPane; protected ResourceBundle messages; /** left and right side main panels */ -// protected JPanel iconPanel; + protected JPanel iconPanel; protected JPanel contentPanel; /** right side content panels and layouts */ -// protected JPanel headerPanel; + protected JPanel headerPanel; protected JPanel mainPanel; protected JPanel buttonPanel; /** right side fixed labels */ -// protected JLabel titleLabel; + protected JLabel titleLabel; protected JLabel helpLabel; /** remember the pinfield to return to worker */ protected JPasswordField pinField; protected int buttonSize; -// private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; + /** gui style config (default 'simple') */ + protected boolean renderHeaderPanel = false; + protected boolean renderIconPanel = false; + protected boolean renderCancelButton = false; /** + * set contentPane + * init message bundle + * configure the style + * register the help listener + * create GUI (on event-dispatching thread) + * * @param contentPane - * @param localeString may be null + * @param locale + * @param guiStyle + * @param background + * @param helpListener */ - @Override - public void init(final Container contentPane, Locale locale, final URL background, ActionListener helpListener) { + public SimpleGUI(Container contentPane, Locale locale, Style guiStyle, URL background, ActionListener helpListener) { + this.contentPane = contentPane; - if (locale != null) { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); - } else { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); - } + if (locale != null) { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); + } else { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); + } + + if (guiStyle == Style.advanced) { + renderHeaderPanel = true; + renderIconPanel = false; + renderCancelButton = true; + } + + registerHelpListener(helpListener); + + createGUI(background); + } + + private void createGUI(final URL background) { - this.contentPane = contentPane; - registerHelpListener(helpListener); - try { log.debug("scheduling gui initialization"); @@ -112,21 +133,28 @@ public class SimpleGUI implements BKUGUIFacade { log.debug("initializing gui"); -// initIconPanel(); + if (renderIconPanel) { + initIconPanel(background); + initContentPanel(null); + } else { initContentPanel(background); - - GroupLayout layout = new GroupLayout(contentPane); - contentPane.setLayout(layout); + } + + GroupLayout layout = new GroupLayout(contentPane); + contentPane.setLayout(layout); + + if (renderIconPanel) { + layout.setHorizontalGroup(layout.createSequentialGroup() + .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + } else { layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(contentPanel)); layout.setVerticalGroup(layout.createSequentialGroup().addComponent(contentPanel)); -// layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(layout.createSequentialGroup() -// .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); -// layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + } } }); } catch (Exception ex) { @@ -134,119 +162,113 @@ public class SimpleGUI implements BKUGUIFacade { } } -// protected void initIconPanel() { -// iconPanel = new JPanel(); -// JLabel iconLabel = new JLabel(); -// iconLabel.setIcon(new ImageIcon(getClass().getResource(LOGO_RESOURCE))); // NOI18N -// -// GroupLayout iconPanelLayout = new GroupLayout(iconPanel); -// iconPanel.setLayout(iconPanelLayout); -// iconPanelLayout.setHorizontalGroup( -// iconPanelLayout.createSequentialGroup() -// .addContainerGap() -// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().width, GroupLayout.PREFERRED_SIZE) -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); -// iconPanelLayout.setVerticalGroup( -// iconPanelLayout.createSequentialGroup() -// .addContainerGap() -// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().height, GroupLayout.PREFERRED_SIZE) -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); -// } + protected void initIconPanel(URL background) { + if (background == null) { + background = getClass().getResource(DEFAULT_BACKGROUND); + } + if ("file".equals(background.getProtocol())) { + log.warn("file:// background images not permitted: " + background); + background = getClass().getResource(DEFAULT_BACKGROUND); + } + log.debug("loading icon panel background " + background); + + iconPanel = new JPanel(); + JLabel iconLabel = new JLabel(); + iconLabel.setIcon(new ImageIcon(background)); + + GroupLayout iconPanelLayout = new GroupLayout(iconPanel); + iconPanel.setLayout(iconPanelLayout); + iconPanelLayout.setHorizontalGroup( + iconPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); + // no gap here (contentPanel has containerGap) + iconPanelLayout.setVerticalGroup( + iconPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + } protected void initContentPanel(URL background) { if (background == null) { - background = this.getClass().getResource(DEFAULT_BACKGROUND); + background = getClass().getResource(DEFAULT_BACKGROUND); } if ("file".equals(background.getProtocol())) { - log.warn("local background image not allowed: " + background); - background = this.getClass().getResource(DEFAULT_BACKGROUND); + log.warn("file:// background images not permitted: " + background); + background = getClass().getResource(DEFAULT_BACKGROUND); } log.debug("loading background " + background); contentPanel = new ImagePanel(background); -// contentPanel.setBorder(new TitledBorder("content")); - -// headerPanel = new JPanel(); -// headerPanel.setOpaque(false); - mainPanel = new JPanel(); - mainPanel.setOpaque(false); - buttonPanel = new JPanel(); - buttonPanel.setOpaque(false); - -// headerPanel.setBorder(new TitledBorder("header")); -// mainPanel.setBorder(new TitledBorder("main")); -// buttonPanel.setBorder(new TitledBorder("button")); - -// titleLabel = new JLabel(); -// titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | -// java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); - - helpLabel = new JLabel(); - helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); - helpLabel.getAccessibleContext().setAccessibleName(messages.getString(ALT_HELP)); - helpLabel.addMouseListener(helpListener); - helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - - JButton b = new JButton(); -// b.setText(messages.getString(BUTTON_CANCEL)); -// if (b.getPreferredSize().width > buttonSize) -// buttonSize = b.getPreferredSize().width; - b.setText(messages.getString(BUTTON_OK)); - if (b.getPreferredSize().width > buttonSize) - buttonSize = b.getPreferredSize().width; - b.setText(messages.getString(BUTTON_SIGN)); - if (b.getPreferredSize().width > buttonSize) - buttonSize = b.getPreferredSize().width; - b.setText(messages.getString(BUTTON_BACK)); - if (b.getPreferredSize().width > buttonSize) - buttonSize = b.getPreferredSize().width; -// b.setText(messages.getString(BUTTON_SAVE)); -// if (b.getPreferredSize().width > buttonSize) -// buttonSize = b.getPreferredSize().width; - -// if (cancelButton.getPreferredSize().width > buttonSize) -// buttonSize = cancelButton.getPreferredSize().width; -// if (signButton.getPreferredSize().width > buttonSize) -// buttonSize = signButton.getPreferredSize().width; -// if (backButton.getPreferredSize().width > buttonSize) -// buttonSize = backButton.getPreferredSize().width; -// if (saveButton.getPreferredSize().width > buttonSize) -// buttonSize = saveButton.getPreferredSize().width; + mainPanel = new JPanel(); + mainPanel.setOpaque(false); + buttonPanel = new JPanel(); + buttonPanel.setOpaque(false); + helpLabel = new JLabel(); + helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); + helpLabel.getAccessibleContext().setAccessibleName(messages.getString(ALT_HELP)); + helpLabel.addMouseListener(helpListener); + helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + buttonSize = initButtonSize(messages, renderCancelButton); -// GroupLayout headerPanelLayout = new GroupLayout(headerPanel); -// headerPanel.setLayout(headerPanelLayout); -// -// headerPanelLayout.setHorizontalGroup( -// headerPanelLayout.createSequentialGroup() -// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); -// headerPanelLayout.setVerticalGroup( -// headerPanelLayout.createSequentialGroup() -// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); - - - GroupLayout contentPanelLayout = new GroupLayout(contentPanel); - contentPanel.setLayout(contentPanelLayout); - - contentPanelLayout.setHorizontalGroup( - contentPanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()); - contentPanelLayout.setVerticalGroup( - contentPanelLayout.createSequentialGroup() - .addContainerGap() -// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); + if (renderHeaderPanel) { + headerPanel = new JPanel(); + headerPanel.setOpaque(false); + + titleLabel = new JLabel(); + titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | + java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); + + GroupLayout headerPanelLayout = new GroupLayout(headerPanel); + headerPanel.setLayout(headerPanelLayout); + + headerPanelLayout.setHorizontalGroup( + headerPanelLayout.createSequentialGroup() + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)); + headerPanelLayout.setVerticalGroup( + headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + .addComponent(helpLabel)); + } + + GroupLayout contentPanelLayout = new GroupLayout(contentPanel); + contentPanel.setLayout(contentPanelLayout); + + GroupLayout.ParallelGroup horizontalContentInner = contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + if (renderHeaderPanel) { + horizontalContentInner + .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); + } + horizontalContentInner + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); + GroupLayout.SequentialGroup horizontalContentOuter = contentPanelLayout.createSequentialGroup(); + if (!renderIconPanel) { + horizontalContentOuter + .addContainerGap(); + } + horizontalContentOuter + .addGroup(horizontalContentInner) + .addContainerGap(); + contentPanelLayout.setHorizontalGroup(horizontalContentOuter); + + GroupLayout.SequentialGroup verticalContent = contentPanelLayout.createSequentialGroup(); + verticalContent.addContainerGap(); + if (renderHeaderPanel) { + verticalContent.addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); + } + verticalContent.addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap(); + contentPanelLayout.setVerticalGroup(verticalContent); } @Override @@ -269,26 +291,35 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_WELCOME)); - helpListener.setHelpTopic(HELP_WELCOME); JLabel welcomeMsgLabel = new JLabel(); welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); - + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_WELCOME)); + welcomeMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + } else { + welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); + } + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(welcomeMsgLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(welcomeMsgLabel) - .addComponent(helpLabel)); + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(welcomeMsgLabel); + GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(welcomeMsgLabel); + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); contentPanel.validate(); @@ -311,8 +342,10 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_INSERTCARD)); - + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + } + helpListener.setHelpTopic(HELP_INSERTCARD); JLabel insertCardMsgLabel = new JLabel(); @@ -322,31 +355,39 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(insertCardMsgLabel) - .addComponent(helpLabel)); + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(insertCardMsgLabel); + GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup() + .addComponent(insertCardMsgLabel); -// JButton cancelButton = new JButton(); -// cancelButton.setText(messages.getString(BUTTON_CANCEL)); -// cancelButton.addActionListener(cancelListener); -// cancelButton.setActionCommand(cancelCommand); -// -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addComponent(cancelButton)); + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.addActionListener(cancelListener); + cancelButton.setActionCommand(cancelCommand); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(cancelButton)); + } contentPanel.validate(); } @@ -373,48 +414,89 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + JLabel insertCardMsgLabel = new JLabel(); + insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + } else { + insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + } helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); - JLabel insertCardMsgLabel = new JLabel(); - insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(insertCardMsgLabel); + GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel); + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.addActionListener(cancelListener); + cancelButton.setActionCommand(cancelCommand); - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(insertCardMsgLabel) - .addComponent(helpLabel)); - -// JButton cancelButton = new JButton(); -// cancelButton.setText(messages.getString(BUTTON_CANCEL)); -// cancelButton.addActionListener(cancelListener); -// cancelButton.setActionCommand(cancelCommand); -// -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addComponent(cancelButton)); - - contentPanel.validate(); + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(cancelButton)); + } + + contentPanel.validate(); } }); } + private static int initButtonSize(ResourceBundle messages, boolean renderCancelButton) { + + int buttonSize = 0; + + JButton b = new JButton(); + b.setText(messages.getString(BUTTON_OK)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + b.setText(messages.getString(BUTTON_SIGN)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + b.setText(messages.getString(BUTTON_BACK)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + b.setText(messages.getString(BUTTON_SAVE)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + if (renderCancelButton) { + b.setText(messages.getString(BUTTON_CANCEL)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + } + return buttonSize; + } + private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { log.debug("scheduling card-pin dialog"); @@ -429,17 +511,14 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// if (numRetries < 0) { -// String cardpinTitle = messages.getString(TITLE_CARDPIN); -// titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); -// } else { -// titleLabel.setText(messages.getString(TITLE_RETRY)); -// } - -// JButton cancelButton = new JButton(); -// cancelButton.setText(messages.getString(BUTTON_CANCEL)); -// cancelButton.setActionCommand(cancelCommand); -// cancelButton.addActionListener(cancelListener); + if (renderHeaderPanel) { + if (numRetries < 0) { + String cardpinTitle = messages.getString(TITLE_CARDPIN); + titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); + } else { + titleLabel.setText(messages.getString(TITLE_RETRY)); + } + } JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -492,55 +571,73 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGroup(mainPanelLayout.createSequentialGroup() + GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup pinHorizontal = mainPanelLayout.createSequentialGroup() .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) - .addComponent(pinsizeLabel)))); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel) - .addComponent(helpLabel)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(cardPinLabel) - .addComponent(pinField)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); + .addComponent(pinsizeLabel)); + + GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + + if (!renderHeaderPanel) { + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel) //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + mainHorizontal + .addGroup(infoHorizontal) + .addGroup(pinHorizontal); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel) + .addComponent(helpLabel); + mainVertical + .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); + } else { + mainHorizontal + .addGroup(pinHorizontal); + } + mainVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cardPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel); + + mainPanelLayout.setHorizontalGroup(mainHorizontal); + mainPanelLayout.setVerticalGroup(mainVertical); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(okButton)); - -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) -// .addComponent(okButton) -// .addComponent(cancelButton)); + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.Group buttonVertical; + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + buttonHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(okButton) + .addComponent(cancelButton); + } else { + buttonVertical = buttonPanelLayout.createSequentialGroup() + .addComponent(okButton); + } + + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); + buttonPanelLayout.setVerticalGroup(buttonVertical); pinField.requestFocusInWindow(); contentPanel.validate(); @@ -583,16 +680,13 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// if (numRetries < 0) { -// titleLabel.setText(messages.getString(TITLE_SIGN)); -// } else { -// titleLabel.setText(messages.getString(TITLE_RETRY)); -// } - -// JButton cancelButton = new JButton(); -// cancelButton.setText(messages.getString(BUTTON_CANCEL)); -// cancelButton.setActionCommand(cancelCommand); -// cancelButton.addActionListener(cancelListener); + if (renderHeaderPanel) { + if (numRetries < 0) { + titleLabel.setText(messages.getString(TITLE_SIGN)); + } else { + titleLabel.setText(messages.getString(TITLE_RETRY)); + } + } JButton signButton = new JButton(); signButton.setFont(signButton.getFont().deriveFont(signButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -653,13 +747,23 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel); + + if (!renderHeaderPanel) { + infoHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + infoVertical + .addComponent(helpLabel); + } mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGroup(infoHorizontal) .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) @@ -669,9 +773,7 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel) - .addComponent(helpLabel)) + .addGroup(infoVertical) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(signPinLabel) @@ -682,27 +784,31 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(signButton)); - -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) -// .addComponent(signButton) -// .addComponent(cancelButton)); + .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.Group buttonVertical; + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + buttonHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + + buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signButton) + .addComponent(cancelButton); + } else { + buttonVertical = buttonPanelLayout.createSequentialGroup() + .addComponent(signButton); + } + + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); + buttonPanelLayout.setVerticalGroup(buttonVertical); pinField.requestFocusInWindow(); contentPanel.validate(); @@ -726,15 +832,12 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_ERROR)); + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_ERROR)); + } helpListener.setHelpTopic(errorMsgKey); - JLabel errorTitleLabel = new JLabel(); - errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); - errorTitleLabel.setText(messages.getString(TITLE_ERROR)); - errorTitleLabel.setForeground(ERROR_COLOR); - String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -745,19 +848,30 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(errorTitleLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(errorMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorTitleLabel) - .addComponent(helpLabel)) - .addComponent(errorMsgLabel)); + GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + + if (!renderHeaderPanel) { + JLabel errorTitleLabel = new JLabel(); + errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); + errorTitleLabel.setText(messages.getString(TITLE_ERROR)); + errorTitleLabel.setForeground(ERROR_COLOR); + + mainHorizontal + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(errorTitleLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)); + mainVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorTitleLabel) + .addComponent(helpLabel)); + } + + mainPanelLayout.setHorizontalGroup(mainHorizontal + .addComponent(errorMsgLabel)); + mainPanelLayout.setVerticalGroup(mainVertical + .addComponent(errorMsgLabel)); JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -796,15 +910,12 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_ERROR)); + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_ERROR)); + } helpListener.setHelpTopic(errorMsgKey); - JLabel errorTitleLabel = new JLabel(); - errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); - errorTitleLabel.setText(messages.getString(TITLE_ERROR)); - errorTitleLabel.setForeground(ERROR_COLOR); - String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -815,20 +926,32 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + + GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + + if (!renderHeaderPanel) { + JLabel errorTitleLabel = new JLabel(); + errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); + errorTitleLabel.setText(messages.getString(TITLE_ERROR)); + errorTitleLabel.setForeground(ERROR_COLOR); + + mainHorizontal .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(errorTitleLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(errorMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() + .addComponent(helpLabel)); + mainVertical .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorTitleLabel) - .addComponent(helpLabel)) - .addComponent(errorMsgLabel)); + .addComponent(helpLabel)); + } + mainPanelLayout.setHorizontalGroup(mainHorizontal + .addComponent(errorMsgLabel)); + mainPanelLayout.setVerticalGroup(mainVertical + .addComponent(errorMsgLabel)); + contentPanel.validate(); } }); @@ -849,8 +972,10 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_WAIT)); - + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_WAIT)); + } + helpListener.setHelpTopic(HELP_WAIT); JLabel waitMsgLabel = new JLabel(); @@ -864,15 +989,20 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addComponent(helpLabel)); + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(waitMsgLabel); + GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel); + + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); contentPanel.validate(); } @@ -887,50 +1017,58 @@ public class SimpleGUI implements BKUGUIFacade { return null; } + /** + * TODO handle multiple references in HashDataViewer + * @param signedReferences + * @param okListener + * @param okCommand + */ @Override - public void showHashDataInputDialog(final List signedReferences, boolean standalone, final ActionListener okListener, final String okCommand) { + public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { if (signedReferences == null) { showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); + return; } + ActionListener saveHashDataListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(signedReferences, okListener, okCommand); + } + }; + if (signedReferences.size() == 1) { - if (standalone) { - ActionListener saveHashDataListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(signedReferences, okListener, okCommand); - } - }; - showHashDataViewer(signedReferences, saveHashDataListener, "save"); +// if (standalone) { - } else { - if ("text/plain".equals(signedReferences.get(0).getMimeType())) { - - ActionListener saveHashDataListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(signedReferences, okListener, okCommand); - } - }; - - try { - String hashDataText = getText(signedReferences.get(0)); - showPlainTextHashDataInputDialog(hashDataText, saveHashDataListener, "save", okListener, okCommand); - } catch (IOException ex) { - showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {ex.getMessage()}, okListener, okCommand); - } + showHashDataViewer(signedReferences, saveHashDataListener, "save"); - } else { - showSaveHashDataInputDialog(signedReferences, okListener, okCommand); - } - } +// } else { +// if ("text/plain".equals(signedReferences.get(0).getMimeType())) { +// +// ActionListener saveHashDataListener = new ActionListener() { +// +// @Override +// public void actionPerformed(ActionEvent e) { +// showSaveHashDataInputDialog(signedReferences, okListener, okCommand); +// } +// }; +// +// try { +// String hashDataText = getText(signedReferences.get(0)); +// showPlainTextHashDataInputDialog(hashDataText, saveHashDataListener, "save", okListener, okCommand); +// } catch (IOException ex) { +// showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {ex.getMessage()}, okListener, okCommand); +// } +// +// } else { +// showSaveHashDataInputDialog(signedReferences, okListener, okCommand); +// } +// } } else { - SimpleHashDataTableModel tableModel = new SimpleHashDataTableModel(signedReferences); // final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); // // ActionListener saveHashDataListener = new ActionListener() { @@ -940,128 +1078,112 @@ public class SimpleGUI implements BKUGUIFacade { // showSaveHashDataInputDialog(tableModel.getSelectedHashData(), okListener, okCommand); // } // }; - showMultipleHashDataInputDialog(tableModel, okListener, okCommand); + + SimpleHashDataTableModel tableModel = new SimpleHashDataTableModel(signedReferences); + showMultipleHashDataInputDialog(tableModel, okListener, okCommand, saveHashDataListener, "save"); } } /** - * TODO + * blocks until dialog returns (is closed) * @param hashDataText * @param saveListener * @param saveCommand */ private void showHashDataViewer(final List signedReferences, final ActionListener saveListener, final String saveCommand) { - log.debug("scheduling plaintext hashdatainput dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show plaintext hashdatainput dialog"); - - ActionListener l = helpListener.getActionListener(); - HashDataViewer.showHashDataInput(contentPane, signedReferences, messages, saveListener, saveCommand, l); - } - }); - } - - private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling plaintext hashdatainput dialog"); - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show plaintext hashdatainput dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - -// titleLabel.setText(messages.getString(TITLE_HASHDATA)); - - helpListener.setHelpTopic(HELP_HASHDATA); - - JLabel refIdLabel = new JLabel(); - refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); - - JTextArea hashDataTextArea = new JTextArea(hashDataText); - hashDataTextArea.setEditable(false); -// hashDataTextArea.setColumns(1); -// hashDataTextArea.setRows(1); - hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); -// hashDataScrollPane.setViewportView(hashDataTextArea); -// hashDataScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //HORIZONTAL_SCROLLBAR_NEVER); - hashDataTextArea.setLineWrap(true); - hashDataTextArea.setWrapStyleWord(true); - - JScrollPane hashDataScrollPane = new JScrollPane(hashDataTextArea); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(helpLabel)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); - - JButton backButton = new JButton(); - backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - backButton.setText(messages.getString(BUTTON_BACK)); - backButton.setActionCommand(cancelCommand); - backButton.addActionListener(cancelListener); + try { + log.debug("scheduling plaintext hashdatainput dialog"); -// JButton saveButton = new JButton(); -// saveButton.setText(messages.getString(BUTTON_SAVE)); -// saveButton.setActionCommand(saveCommand); -// saveButton.addActionListener(saveListener); + SwingUtilities.invokeAndWait(new Runnable() { - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); + @Override + public void run() { - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(backButton)); + log.debug("show plaintext hashdatainput dialog"); + ActionListener l = helpListener.getActionListener(); + HashDataViewer.showHashDataInput(contentPane, signedReferences, messages, saveListener, saveCommand, l); + } + }); + + } catch (InterruptedException ex) { + log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } catch (InvocationTargetException ex) { + log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } + } + +// private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { +// +// log.debug("scheduling plaintext hashdatainput dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("show plaintext hashdatainput dialog"); +// +// mainPanel.removeAll(); +// buttonPanel.removeAll(); +// +// helpListener.setHelpTopic(HELP_HASHDATA); +// +// JLabel refIdLabel = new JLabel(); +// refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); +// refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); +// +// JTextArea hashDataTextArea = new JTextArea(hashDataText); +// hashDataTextArea.setEditable(false); +// hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); +// hashDataTextArea.setLineWrap(true); +// hashDataTextArea.setWrapStyleWord(true); +// +// JScrollPane hashDataScrollPane = new JScrollPane(hashDataTextArea); +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// mainPanelLayout.setHorizontalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(mainPanelLayout.createSequentialGroup() +// .addComponent(refIdLabel) +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) +// .addComponent(helpLabel)) +// .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); +// +// mainPanelLayout.setVerticalGroup( +// mainPanelLayout.createSequentialGroup() +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(refIdLabel) +// .addComponent(helpLabel)) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); +// +// JButton backButton = new JButton(); +// backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); +// backButton.setText(messages.getString(BUTTON_BACK)); +// backButton.setActionCommand(cancelCommand); +// backButton.addActionListener(cancelListener); +// // 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); // buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) -// .addComponent(saveButton) -// .addComponent(backButton)); - - contentPanel.validate(); - } - }); - } +// buttonPanelLayout.createSequentialGroup() +// .addComponent(backButton)); +// +// contentPanel.validate(); +// } +// }); +// } - private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand) { -// , final ActionListener saveListener, final String saveCommand + private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, final ActionListener saveListener, final String saveCommand) { log.debug("scheduling multiple hashdatainput dialog"); @@ -1075,8 +1197,10 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_HASHDATA)); - + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_HASHDATA)); + } + helpListener.setHelpTopic(HELP_HASHDATALIST); JLabel refIdLabel = new JLabel(); @@ -1124,36 +1248,31 @@ public class SimpleGUI implements BKUGUIFacade { backButton.setActionCommand(cancelCommand); backButton.addActionListener(cancelListener); -// JButton saveButton = new JButton(); -// saveButton.setText(messages.getString(BUTTON_SAVE)); -// saveButton.setActionCommand(saveCommand); -// saveButton.addActionListener(saveListener); - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(backButton)); - - -// 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) -// .addComponent(saveButton) -// .addComponent(backButton)); + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.ParallelGroup buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(backButton); + + if (renderCancelButton) { + //render save button + JButton saveButton = new JButton(); + saveButton.setText(messages.getString(BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + buttonHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + buttonVertical + .addComponent(saveButton); + } + + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); + buttonPanelLayout.setVerticalGroup(buttonVertical); contentPanel.validate(); } @@ -1243,36 +1362,36 @@ public class SimpleGUI implements BKUGUIFacade { }); } - private static String getText(HashDataInput hdi) throws IOException { - ByteArrayOutputStream baos = null; - try { - InputStream hashDataIS = hdi.getHashDataInput(); - if (hashDataIS == null) { - log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); - return null; - } else { - baos = new ByteArrayOutputStream(hashDataIS.available()); - int c; - while ((c = hashDataIS.read()) != -1) { - baos.write(c); - } - String encoding = hdi.getEncoding(); - if (encoding == null) { - //default for URL-encoded - encoding = "UTF-8"; - } - return baos.toString(encoding); - } - } catch (IOException ex) { - log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); - throw ex; - } finally { - try { - baos.close(); - } catch (IOException ex) { - } - } - } +// private static String getText(HashDataInput hdi) throws IOException { +// ByteArrayOutputStream baos = null; +// try { +// InputStream hashDataIS = hdi.getHashDataInput(); +// if (hashDataIS == null) { +// log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); +// return null; +// } else { +// baos = new ByteArrayOutputStream(hashDataIS.available()); +// int c; +// while ((c = hashDataIS.read()) != -1) { +// baos.write(c); +// } +// String encoding = hdi.getEncoding(); +// if (encoding == null) { +// //default for URL-encoded +// encoding = "UTF-8"; +// } +// return baos.toString(encoding); +// } +// } catch (IOException ex) { +// log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); +// throw ex; +// } finally { +// try { +// baos.close(); +// } catch (IOException ex) { +// } +// } +// } private void registerHelpListener(ActionListener helpListener) { if (helpListener != null) { -- cgit v1.2.3 From 6d2cd68c8adff8c27a6a3a18711ea44a2e7bfe30 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 18 Nov 2008 18:00:44 +0000 Subject: GUI refactoring 2 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@178 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 1146 ---------------- .../java/at/gv/egiz/bku/gui/BKUGUIFactory.java | 23 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 1306 ++++++++++++++++++ .../at/gv/egiz/bku/gui/DefaultHelpListener.java | 7 - .../at/gv/egiz/bku/gui/HashDataTableModel.java | 93 +- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 25 +- .../java/at/gv/egiz/bku/gui/HyperLinkRenderer.java | 47 - .../main/java/at/gv/egiz/bku/gui/ImagePanel.java | 1 + .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 1410 -------------------- .../gv/egiz/bku/gui/SimpleHashDataTableModel.java | 60 - 10 files changed, 1391 insertions(+), 2727 deletions(-) delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java deleted file mode 100644 index f68f2ece..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ /dev/null @@ -1,1146 +0,0 @@ -/* - * 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.smcc.PINSpec; -import at.gv.egiz.stal.HashDataInput; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.Font; -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.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.text.MessageFormat; -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.JCheckBox; -import javax.swing.JFileChooser; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPasswordField; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextArea; -import javax.swing.LayoutStyle; -import javax.swing.SwingUtilities; -import javax.swing.table.TableColumn; -import javax.swing.table.TableModel; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author clemens - */ -public class BKUGUI implements BKUGUIFacade { - - private static final Log log = LogFactory.getLog(BKUGUI.class); - - protected HelpMouseListener helpListener; - - protected Container contentPane; - protected ResourceBundle messages; - /** left and right side main panels */ -// protected JPanel iconPanel; - protected JPanel contentPanel; - /** right side content panels and layouts */ - protected JPanel headerPanel; - protected JPanel mainPanel; - protected JPanel buttonPanel; - /** right side fixed labels */ - protected JLabel titleLabel; - /** remember the pinfield to return to worker */ - protected JPasswordField pinField; - - protected int buttonSize; - - private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; - - /** - * @param contentPane - * @param localeString may be null - */ -// @Override - public void init(final Container contentPane, Locale locale, Style guiStyle, final URL background, ActionListener helpListener) { - - if (locale != null) { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); - } else { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); - } - - this.contentPane = contentPane; - registerHelpListener(helpListener); - - try { - - log.debug("scheduling gui initialization"); - - SwingUtilities.invokeAndWait(new Runnable() { - - @Override - public void run() { - - log.debug("initializing gui"); - -// initIconPanel(); - initContentPanel(background); - - GroupLayout layout = new GroupLayout(contentPane); - contentPane.setLayout(layout); - layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(contentPanel)); - layout.setVerticalGroup(layout.createSequentialGroup().addComponent(contentPanel)); -// layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(layout.createSequentialGroup() -// .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); -// layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); - } - }); - } catch (Exception ex) { - throw new RuntimeException("Failed to init GUI: " + ex.getMessage()); - } - } - -// protected void initIconPanel() { -// iconPanel = new JPanel(); -// JLabel iconLabel = new JLabel(); -// iconLabel.setIcon(new ImageIcon(getClass().getResource(LOGO_RESOURCE))); // NOI18N -// -// GroupLayout iconPanelLayout = new GroupLayout(iconPanel); -// iconPanel.setLayout(iconPanelLayout); -// iconPanelLayout.setHorizontalGroup( -// iconPanelLayout.createSequentialGroup() -// .addContainerGap() -// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().width, GroupLayout.PREFERRED_SIZE) -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); -// iconPanelLayout.setVerticalGroup( -// iconPanelLayout.createSequentialGroup() -// .addContainerGap() -// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().height, GroupLayout.PREFERRED_SIZE) -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); -// } - - protected void initContentPanel(URL background) { - - if (background == null) { - background = this.getClass().getResource(DEFAULT_BACKGROUND); - } - contentPanel = new ImagePanel(background); - -// contentPanel.setBorder(new TitledBorder("content")); - - headerPanel = new JPanel(); - headerPanel.setOpaque(false); - mainPanel = new JPanel(); - mainPanel.setOpaque(false); - buttonPanel = new JPanel(); - buttonPanel.setOpaque(false); - -// headerPanel.setBorder(new TitledBorder("header")); -// mainPanel.setBorder(new TitledBorder("main")); -// buttonPanel.setBorder(new TitledBorder("button")); - - titleLabel = new JLabel(); - titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | - java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); - - JLabel helpLabel = new JLabel(); - helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); - helpLabel.addMouseListener(helpListener); - helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - - JButton b = new JButton(); - b.setText(messages.getString(BUTTON_CANCEL)); - if (b.getPreferredSize().width > buttonSize) - buttonSize = b.getPreferredSize().width; - b.setText(messages.getString(BUTTON_OK)); - if (b.getPreferredSize().width > buttonSize) - buttonSize = b.getPreferredSize().width; - b.setText(messages.getString(BUTTON_SIGN)); - if (b.getPreferredSize().width > buttonSize) - buttonSize = b.getPreferredSize().width; - b.setText(messages.getString(BUTTON_BACK)); - if (b.getPreferredSize().width > buttonSize) - buttonSize = b.getPreferredSize().width; - b.setText(messages.getString(BUTTON_SAVE)); - if (b.getPreferredSize().width > buttonSize) - buttonSize = b.getPreferredSize().width; - -// if (cancelButton.getPreferredSize().width > buttonSize) -// buttonSize = cancelButton.getPreferredSize().width; -// if (signButton.getPreferredSize().width > buttonSize) -// buttonSize = signButton.getPreferredSize().width; -// if (backButton.getPreferredSize().width > buttonSize) -// buttonSize = backButton.getPreferredSize().width; -// if (saveButton.getPreferredSize().width > buttonSize) -// buttonSize = saveButton.getPreferredSize().width; - - - GroupLayout headerPanelLayout = new GroupLayout(headerPanel); - headerPanel.setLayout(headerPanelLayout); - - headerPanelLayout.setHorizontalGroup( - headerPanelLayout.createSequentialGroup() - .addComponent(titleLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - headerPanelLayout.setVerticalGroup( - headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) //SequentialGroup() - .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) - .addComponent(helpLabel)); - - - GroupLayout contentPanelLayout = new GroupLayout(contentPanel); - contentPanel.setLayout(contentPanelLayout); - - contentPanelLayout.setHorizontalGroup( - contentPanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()); - contentPanelLayout.setVerticalGroup( - contentPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); - } - - @Override - public Locale getLocale() { - return messages.getLocale(); - } - - @Override - public void showWelcomeDialog() { - - log.debug("scheduling welcome dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show welcome dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_WELCOME)); - - helpListener.setHelpTopic(HELP_WELCOME); - - JLabel welcomeMsgLabel = new JLabel(); - welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - welcomeMsgLabel.setText(messages.getString(MESSAGE_WAIT)); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(welcomeMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(welcomeMsgLabel)); - - contentPanel.validate(); - - } - }); - } - - @Override - public void showInsertCardDialog(final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling insert card dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show insert card dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_INSERTCARD)); - - helpListener.setHelpTopic(HELP_INSERTCARD); - - JLabel insertCardMsgLabel = new JLabel(); - insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel)); - - JButton cancelButton = new JButton(); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.addActionListener(cancelListener); - cancelButton.setActionCommand(cancelCommand); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(cancelButton)); - - contentPanel.validate(); - } - }); - } - - /** - * only difference to showInsertCard: title text: card not supported - * @param cancelListener - * @param cancelCommand - */ - @Override - public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling card not supported dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show card not supported dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); - - helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); - - JLabel insertCardMsgLabel = new JLabel(); - insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel)); - - JButton cancelButton = new JButton(); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.addActionListener(cancelListener); - cancelButton.setActionCommand(cancelCommand); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(cancelButton)); - - contentPanel.validate(); - } - }); - } - - private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling card-pin dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show card-pin dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (numRetries < 0) { - String cardpinTitle = messages.getString(TITLE_CARDPIN); - titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); - } else { - titleLabel.setText(messages.getString(TITLE_RETRY)); - } - - JButton cancelButton = new JButton(); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.setActionCommand(cancelCommand); - cancelButton.addActionListener(cancelListener); - - JButton okButton = new JButton(); - okButton.setText(messages.getString(BUTTON_OK)); - okButton.setEnabled(false); - okButton.setActionCommand(okCommand); - okButton.addActionListener(okListener); - - JLabel cardPinLabel = new JLabel(); - cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); - String pinLabel = messages.getString(LABEL_PIN); - cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); - - pinField = new JPasswordField(); - pinField.setText(""); - pinField.setDocument(new PINDocument(pinSpec, okButton)); - pinField.setActionCommand(okCommand); - pinField.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - if (pinField.getPassword().length >= pinSpec.getMinLength()) { - okListener.actionPerformed(e); - } - } - }); - - JLabel infoLabel = new JLabel(); - if (numRetries < 0) { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String infoPattern = messages.getString(MESSAGE_ENTERPIN); - infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); - helpListener.setHelpTopic(HELP_CARDPIN); - } else { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); - infoLabel.setForeground(ERROR_COLOR); - helpListener.setHelpTopic(HELP_RETRY); - } - - JLabel pinsizeLabel = new JLabel(); - pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); - String pinsizePattern = messages.getString(LABEL_PINSIZE); - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) - .addComponent(pinsizeLabel)))); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(cardPinLabel) - .addComponent(pinField)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(okButton) - .addComponent(cancelButton)); - - pinField.requestFocusInWindow(); - contentPanel.validate(); - - } - }); - } - - @Override - public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { - showCardPINDialog(pinSpec, -1, okListener, okCommand, cancelListener, cancelCommand); - } - - @Override - public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { - showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); - } - - @Override - public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { - showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); - } - - @Override - public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { - showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); - } - - private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { - - log.debug("scheduling signature-pin dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show signature-pin dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (numRetries < 0) { - titleLabel.setText(messages.getString(TITLE_SIGN)); - } else { - titleLabel.setText(messages.getString(TITLE_RETRY)); - } - - JButton cancelButton = new JButton(); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.setActionCommand(cancelCommand); - cancelButton.addActionListener(cancelListener); - - JButton signButton = new JButton(); - signButton.setText(messages.getString(BUTTON_SIGN)); - signButton.setEnabled(false); - signButton.setActionCommand(signCommand); - signButton.addActionListener(signListener); - - JLabel signPinLabel = new JLabel(); - signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); - String pinLabel = messages.getString(LABEL_PIN); - signPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); - - pinField = new JPasswordField(); - pinField.setText(""); - pinField.setDocument(new PINDocument(pinSpec, signButton)); - pinField.setActionCommand(signCommand); - pinField.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - if (pinField.getPassword().length >= pinSpec.getMinLength()) { - signListener.actionPerformed(e); - } - } - }); - - JLabel pinsizeLabel = new JLabel(); - pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); - String pinsizePattern = messages.getString(LABEL_PINSIZE); - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); - - JLabel infoLabel = new JLabel(); - if (numRetries < 0) { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); - infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - infoLabel.setForeground(HYPERLINK_COLOR); - infoLabel.addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent me) { - ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); - hashdataListener.actionPerformed(e); - } - }); - helpListener.setHelpTopic(HELP_SIGNPIN); - } else { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); - infoLabel.setForeground(ERROR_COLOR); - helpListener.setHelpTopic(HELP_RETRY); - } - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pinsizeLabel)))); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(signPinLabel) - .addComponent(pinField)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(signButton) - .addComponent(cancelButton)); - - pinField.requestFocusInWindow(); - contentPanel.validate(); - - } - }); - } - - @Override - public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams, final ActionListener okListener, final String okCommand) { - - log.debug("scheduling error dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show error dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_ERROR)); - - helpListener.setHelpTopic(errorMsgKey); - - String errorMsgPattern = messages.getString(errorMsgKey); - String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); - - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(errorMsg); - errorMsgLabel.setForeground(ERROR_COLOR); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); - - JButton okButton = new JButton(); - okButton.setText(messages.getString(BUTTON_OK)); - okButton.setActionCommand(okCommand); - okButton.addActionListener(okListener); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(okButton)); - - contentPanel.validate(); - } - }); - } - - @Override - public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams) { - - log.debug("scheduling error dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show error dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_ERROR)); - - helpListener.setHelpTopic(errorMsgKey); - - String errorMsgPattern = messages.getString(errorMsgKey); - String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); - - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(errorMsg); - errorMsgLabel.setForeground(ERROR_COLOR); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(errorMsgLabel)); - - contentPanel.validate(); - } - }); - } - - @Override - public void showWaitDialog(final String waitMessage) { - - log.debug("scheduling wait dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show wait dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_WAIT)); - - helpListener.setHelpTopic(HELP_WAIT); - - JLabel waitMsgLabel = new JLabel(); - waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - if (waitMessage != null) { - waitMsgLabel.setText("" + waitMessage + ""); - } else { - waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); - } - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel)); - - contentPanel.validate(); - } - }); - } - - @Override - public char[] getPin() { - if (pinField != null) { - return pinField.getPassword(); - } - return null; - } - - @Override - public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { - - if (signedReferences == null) { - showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); - } - - if (signedReferences.size() == 1) { - - if ("text/plain".equals(signedReferences.get(0).getMimeType())) { - - ActionListener saveHashDataListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(signedReferences, okListener, okCommand); - } - }; - - try { - String hashDataText = getText(signedReferences.get(0)); - showPlainTextHashDataInputDialog(hashDataText, saveHashDataListener, "save", okListener, okCommand); - } catch (IOException ex) { - showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {ex.getMessage()}, okListener, okCommand); - } - - } else { - showSaveHashDataInputDialog(signedReferences, okListener, okCommand); - } - - } else { - - final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - - ActionListener saveHashDataListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(tableModel.getSelectedHashData(), okListener, okCommand); - } - }; - showMultipleHashDataInputDialog(tableModel, okListener, okCommand, saveHashDataListener, "save"); - } - } - - private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling plaintext hashdatainput dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show plaintext hashdatainput dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_HASHDATA)); - - helpListener.setHelpTopic(HELP_HASHDATA); - - JLabel refIdLabel = new JLabel(); - refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); - - JTextArea hashDataTextArea = new JTextArea(hashDataText); - hashDataTextArea.setEditable(false); -// hashDataTextArea.setColumns(1); -// hashDataTextArea.setRows(1); - hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); -// hashDataScrollPane.setViewportView(hashDataTextArea); -// hashDataScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //HORIZONTAL_SCROLLBAR_NEVER); - hashDataTextArea.setLineWrap(true); - hashDataTextArea.setWrapStyleWord(true); - - JScrollPane hashDataScrollPane = new JScrollPane(hashDataTextArea); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); - - JButton backButton = new JButton(); - backButton.setText(messages.getString(BUTTON_BACK)); - backButton.setActionCommand(cancelCommand); - backButton.addActionListener(cancelListener); - - JButton saveButton = new JButton(); - saveButton.setText(messages.getString(BUTTON_SAVE)); - saveButton.setActionCommand(saveCommand); - saveButton.addActionListener(saveListener); - - 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(saveButton) - .addComponent(backButton)); - - contentPanel.validate(); - } - }); - } - - private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, final ActionListener saveListener, final String saveCommand) { - - log.debug("scheduling multiple hashdatainput dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show multiple hashdatainput dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_HASHDATA)); - - helpListener.setHelpTopic(HELP_HASHDATALIST); - - JLabel refIdLabel = new JLabel(); - refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); - refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); - - JTable hashDataTable = new JTable(); - hashDataTable.setModel(signedReferences); - hashDataTable.setTableHeader(null); - // hashDataTable.setShowVerticalLines(false); - // hashDataTable.setRowSelectionAllowed(false); - TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); - selectCol.setMinWidth(CHECKBOX_WIDTH); - selectCol.setMaxWidth(CHECKBOX_WIDTH); - - -// hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); - - JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); - - JButton backButton = new JButton(); - backButton.setText(messages.getString(BUTTON_BACK)); - backButton.setActionCommand(cancelCommand); - backButton.addActionListener(cancelListener); - - JButton saveButton = new JButton(); - saveButton.setText(messages.getString(BUTTON_SAVE)); - saveButton.setActionCommand(saveCommand); - saveButton.addActionListener(saveListener); - - 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(saveButton) - .addComponent(backButton)); - - contentPanel.validate(); - } - }); - } - - private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { - - log.debug("scheduling save hashdatainput dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show save hashdatainput dialog"); - - String userHome = System.getProperty("user.home"); - - JFileChooser fileDialog = new JFileChooser(userHome); - fileDialog.setMultiSelectionEnabled(false); - fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); - fileDialog.setFileHidingEnabled(true); - if (signedRefs.size() == 1) { - fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); - fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); - String mimeType = signedRefs.get(0).getMimeType(); - MimeFilter mimeFilter = new MimeFilter(mimeType, messages); - fileDialog.setFileFilter(mimeFilter); - String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); - fileDialog.setSelectedFile(new File(userHome, filename)); - } else { - fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVEDIR)); - fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - } - - //parent contentPane -> placed over applet - switch (fileDialog.showSaveDialog(fileDialog)) { - case JFileChooser.APPROVE_OPTION: - File f = fileDialog.getSelectedFile(); - for (HashDataInput hashDataInput : signedRefs) { - String mimeType = hashDataInput.getMimeType(); - String id = hashDataInput.getReferenceId(); - File file; - if (f.isDirectory()) { - String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); - file = new File(f, filename); - } else { - file = f; - } - if (file.exists()) { - String ovrwrt = messages.getString(MESSAGE_OVERWRITE); - int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), messages.getString(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); - if (overwrite != JOptionPane.OK_OPTION) { - continue; - } - } - if (log.isDebugEnabled()) { - log.debug("Writing HashDataInput " + 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 HashDataInput to file " + file + ": " + ex.getMessage()); - showErrorDialog(ERR_WRITE_HASHDATA, new Object[] {ex.getMessage()}, null, null); - ex.printStackTrace(); - } finally { - try { - fos.close(); - } catch (IOException ex) { - } - } - } - } - log.debug("done saving hashdatainput"); - okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); - } - }); - } - - private static String getText(HashDataInput hdi) throws IOException { - ByteArrayOutputStream baos = null; - try { - InputStream hashDataIS = hdi.getHashDataInput(); - if (hashDataIS == null) { - log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); - return null; - } else { - baos = new ByteArrayOutputStream(hashDataIS.available()); - int c; - while ((c = hashDataIS.read()) != -1) { - baos.write(c); - } - String encoding = hdi.getEncoding(); - if (encoding == null) { - //default for URL-encoded - encoding = "UTF-8"; - } - return baos.toString(encoding); - } - } catch (IOException ex) { - log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); - throw ex; - } finally { - try { - baos.close(); - } catch (IOException ex) { - } - } - } - - private void registerHelpListener(ActionListener helpListener) { - if (helpListener != null) { - this.helpListener = new HelpMouseListener(helpListener); - } else { - log.error("no help listener provided, will not be able to display help"); - this.helpListener = new HelpMouseListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - log.error("no help listener registered (requested help topic: " + e.getActionCommand() + ")"); - } - }); - } - } -} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java index f4981614..998aaa86 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java @@ -24,22 +24,11 @@ import java.util.Locale; public class BKUGUIFactory { - public static final String SIMPLE_GUI = "simple"; - public static final String ADVANCED_GUI = "advanced"; - -// private static BKUGUIFactory instance = new BKUGUIFactory(); - -// private BKUGUIFactory() { -// } -// -// protected BKUGUIFacade createNewGUI(Container contentPane, Locale locale, String style, URL background, ActionListener helpListener) { -// -// } - - public static BKUGUIFacade createGUI(Container contentPane, Locale locale, String style, URL background, ActionListener helpListener) { - if (ADVANCED_GUI.equals(style)) { - return new SimpleGUI(contentPane, locale, BKUGUIFacade.Style.advanced, background, helpListener); - } - return new SimpleGUI(contentPane, locale, BKUGUIFacade.Style.simple, background, helpListener); + public static BKUGUIFacade createGUI(Container contentPane, + Locale locale, + BKUGUIFacade.Style style, + URL background, + ActionListener helpListener) { + return new BKUGUIImpl(contentPane, locale, style, background, helpListener); } } 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 new file mode 100644 index 00000000..9d23315c --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java @@ -0,0 +1,1306 @@ +/* + * 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.smcc.PINSpec; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import java.awt.Container; +import java.awt.Cursor; +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.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.text.MessageFormat; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; +import javax.swing.CellRendererPane; +import javax.swing.GroupLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.LayoutStyle; +import javax.swing.SwingUtilities; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableModel; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author clemens + */ +public class BKUGUIImpl implements BKUGUIFacade { + + private static final Log log = LogFactory.getLog(BKUGUIImpl.class); + + protected HelpMouseListener helpListener; + + protected Container contentPane; + protected ResourceBundle messages; + /** left and right side main panels */ + protected JPanel iconPanel; + protected JPanel contentPanel; + /** right side content panels and layouts */ + protected JPanel headerPanel; + protected JPanel mainPanel; + protected JPanel buttonPanel; + /** right side fixed labels */ + protected JLabel titleLabel; + protected JLabel helpLabel; + /** remember the pinfield to return to worker */ + protected JPasswordField pinField; + + protected int buttonSize; + + /** gui style config (default 'simple') */ + protected boolean renderHeaderPanel = false; + protected boolean renderIconPanel = false; + protected boolean renderCancelButton = false; + + /** + * set contentPane + * init message bundle + * configure the style + * register the help listener + * create GUI (on event-dispatching thread) + * + * @param contentPane + * @param locale + * @param guiStyle + * @param background + * @param helpListener + */ + public BKUGUIImpl(Container contentPane, + Locale locale, + Style guiStyle, + URL background, + ActionListener helpListener) { + this.contentPane = contentPane; + + if (locale != null) { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); + } else { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); + } + + if (guiStyle == Style.advanced) { + renderHeaderPanel = true; + renderIconPanel = false; + renderCancelButton = true; + } + + registerHelpListener(helpListener); + + createGUI(background); + } + + private void createGUI(final URL background) { + + try { + + log.debug("scheduling gui initialization"); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + + log.debug("initializing gui"); + + if (renderIconPanel) { + initIconPanel(background); + initContentPanel(null); + } else { + initContentPanel(background); + } + + GroupLayout layout = new GroupLayout(contentPane); + contentPane.setLayout(layout); + + if (renderIconPanel) { + layout.setHorizontalGroup(layout.createSequentialGroup() + .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + } else { + layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(contentPanel)); + layout.setVerticalGroup(layout.createSequentialGroup().addComponent(contentPanel)); + } + } + }); + } catch (Exception ex) { + throw new RuntimeException("Failed to init GUI: " + ex.getMessage()); + } + } + + protected void initIconPanel(URL background) { + if (background == null) { + background = getClass().getResource(DEFAULT_BACKGROUND); + } + if ("file".equals(background.getProtocol())) { + log.warn("file:// background images not permitted: " + background); + background = getClass().getResource(DEFAULT_BACKGROUND); + } + log.debug("loading icon panel background " + background); + + iconPanel = new JPanel(); + JLabel iconLabel = new JLabel(); + iconLabel.setIcon(new ImageIcon(background)); + + GroupLayout iconPanelLayout = new GroupLayout(iconPanel); + iconPanel.setLayout(iconPanelLayout); + iconPanelLayout.setHorizontalGroup( + iconPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); + // no gap here (contentPanel has containerGap) + iconPanelLayout.setVerticalGroup( + iconPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + } + + protected void initContentPanel(URL background) { + + if (background == null) { + background = getClass().getResource(DEFAULT_BACKGROUND); + } + if ("file".equals(background.getProtocol())) { + log.warn("file:// background images not permitted: " + background); + background = getClass().getResource(DEFAULT_BACKGROUND); + } + log.debug("loading background " + background); + contentPanel = new ImagePanel(background); + + mainPanel = new JPanel(); + mainPanel.setOpaque(false); + buttonPanel = new JPanel(); + buttonPanel.setOpaque(false); + + helpLabel = new JLabel(); + helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); + helpLabel.getAccessibleContext().setAccessibleName(messages.getString(ALT_HELP)); + helpLabel.addMouseListener(helpListener); + helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + buttonSize = initButtonSize(messages, renderCancelButton); + + if (renderHeaderPanel) { + headerPanel = new JPanel(); + headerPanel.setOpaque(false); + + titleLabel = new JLabel(); + titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | + java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); + + GroupLayout headerPanelLayout = new GroupLayout(headerPanel); + headerPanel.setLayout(headerPanelLayout); + + headerPanelLayout.setHorizontalGroup( + headerPanelLayout.createSequentialGroup() + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)); + headerPanelLayout.setVerticalGroup( + headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + .addComponent(helpLabel)); + } + + GroupLayout contentPanelLayout = new GroupLayout(contentPanel); + contentPanel.setLayout(contentPanelLayout); + + GroupLayout.ParallelGroup horizontalContentInner = contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + if (renderHeaderPanel) { + horizontalContentInner + .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); + } + horizontalContentInner + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); + GroupLayout.SequentialGroup horizontalContentOuter = contentPanelLayout.createSequentialGroup(); + if (!renderIconPanel) { + horizontalContentOuter + .addContainerGap(); + } + horizontalContentOuter + .addGroup(horizontalContentInner) + .addContainerGap(); + contentPanelLayout.setHorizontalGroup(horizontalContentOuter); + + GroupLayout.SequentialGroup verticalContent = contentPanelLayout.createSequentialGroup(); + verticalContent.addContainerGap(); + if (renderHeaderPanel) { + verticalContent.addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); + } + verticalContent.addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap(); + contentPanelLayout.setVerticalGroup(verticalContent); + } + + @Override + public Locale getLocale() { + return messages.getLocale(); + } + + @Override + public void showWelcomeDialog() { + + log.debug("scheduling welcome dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show welcome dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + helpListener.setHelpTopic(HELP_WELCOME); + + JLabel welcomeMsgLabel = new JLabel(); + welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_WELCOME)); + welcomeMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + } else { + welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); + } + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(welcomeMsgLabel); + GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(welcomeMsgLabel); + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); + + contentPanel.validate(); + + } + }); + } + + @Override + public void showInsertCardDialog(final ActionListener cancelListener, final String cancelCommand) { + + log.debug("scheduling insert card dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show insert card dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + } + + helpListener.setHelpTopic(HELP_INSERTCARD); + + JLabel insertCardMsgLabel = new JLabel(); + insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(insertCardMsgLabel); + GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup() + .addComponent(insertCardMsgLabel); + + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.addActionListener(cancelListener); + cancelButton.setActionCommand(cancelCommand); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(cancelButton)); + } + + contentPanel.validate(); + } + }); + } + + /** + * only difference to showInsertCard: title text: card not supported + * @param cancelListener + * @param cancelCommand + */ + @Override + public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { + + log.debug("scheduling card not supported dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show card not supported dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + JLabel insertCardMsgLabel = new JLabel(); + insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + } else { + insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + } + + helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(insertCardMsgLabel); + GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel); + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.addActionListener(cancelListener); + cancelButton.setActionCommand(cancelCommand); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(cancelButton)); + } + + contentPanel.validate(); + } + }); + } + + private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { + + log.debug("scheduling card-pin dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show card-pin dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (renderHeaderPanel) { + if (numRetries < 0) { + String cardpinTitle = messages.getString(TITLE_CARDPIN); + titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); + } else { + titleLabel.setText(messages.getString(TITLE_RETRY)); + } + } + + JButton okButton = new JButton(); + okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + okButton.setText(messages.getString(BUTTON_OK)); + okButton.setEnabled(false); + okButton.setActionCommand(okCommand); + okButton.addActionListener(okListener); + + JLabel cardPinLabel = new JLabel(); + cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String pinLabel = messages.getString(LABEL_PIN); + cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); + + pinField = new JPasswordField(); + pinField.setText(""); + pinField.setDocument(new PINDocument(pinSpec, okButton)); + pinField.setActionCommand(okCommand); + pinField.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (pinField.getPassword().length >= pinSpec.getMinLength()) { + okListener.actionPerformed(e); + } + } + }); + + JLabel infoLabel = new JLabel(); + if (numRetries < 0) { + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String infoPattern = messages.getString(MESSAGE_ENTERPIN); + infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); + helpListener.setHelpTopic(HELP_CARDPIN); + } else { + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); + infoLabel.setForeground(ERROR_COLOR); + helpListener.setHelpTopic(HELP_RETRY); + } + + JLabel pinsizeLabel = new JLabel(); + pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); + String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup pinHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) + .addComponent(pinsizeLabel)); + + GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + + if (!renderHeaderPanel) { + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel) //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + mainHorizontal + .addGroup(infoHorizontal) + .addGroup(pinHorizontal); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel) + .addComponent(helpLabel); + mainVertical + .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); + } else { + mainHorizontal + .addGroup(pinHorizontal); + } + + mainVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cardPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel); + + mainPanelLayout.setHorizontalGroup(mainHorizontal); + mainPanelLayout.setVerticalGroup(mainVertical); + + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.Group buttonVertical; + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + buttonHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(okButton) + .addComponent(cancelButton); + } else { + buttonVertical = buttonPanelLayout.createSequentialGroup() + .addComponent(okButton); + } + + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); + buttonPanelLayout.setVerticalGroup(buttonVertical); + + pinField.requestFocusInWindow(); + contentPanel.validate(); + + } + }); + } + + @Override + public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { + showCardPINDialog(pinSpec, -1, okListener, okCommand, cancelListener, cancelCommand); + } + + @Override + public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { + showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); + } + + @Override + public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { + showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); + } + + @Override + public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { + showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); + } + + private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { + + log.debug("scheduling signature-pin dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show signature-pin dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (renderHeaderPanel) { + if (numRetries < 0) { + titleLabel.setText(messages.getString(TITLE_SIGN)); + } else { + titleLabel.setText(messages.getString(TITLE_RETRY)); + } + } + + JButton signButton = new JButton(); + signButton.setFont(signButton.getFont().deriveFont(signButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + signButton.setText(messages.getString(BUTTON_SIGN)); + signButton.setEnabled(false); + signButton.setActionCommand(signCommand); + signButton.addActionListener(signListener); + + JLabel signPinLabel = new JLabel(); + signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String pinLabel = messages.getString(LABEL_PIN); + signPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); + + pinField = new JPasswordField(); + pinField.setText(""); + pinField.setDocument(new PINDocument(pinSpec, signButton)); + pinField.setActionCommand(signCommand); + pinField.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (pinField.getPassword().length >= pinSpec.getMinLength()) { + signListener.actionPerformed(e); + } + } + }); + + JLabel pinsizeLabel = new JLabel(); + pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); + String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + + JLabel infoLabel = new JLabel(); + if (numRetries < 0) { + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); + infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + infoLabel.setForeground(HYPERLINK_COLOR); + infoLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent me) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e); + } + }); + helpListener.setHelpTopic(HELP_SIGNPIN); + } else { + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); + infoLabel.setForeground(ERROR_COLOR); + helpListener.setHelpTopic(HELP_RETRY); + } + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel); + + if (!renderHeaderPanel) { + infoHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + infoVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(infoHorizontal) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(pinsizeLabel)))); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel)); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.Group buttonVertical; + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + buttonHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + + buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signButton) + .addComponent(cancelButton); + } else { + buttonVertical = buttonPanelLayout.createSequentialGroup() + .addComponent(signButton); + } + + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); + buttonPanelLayout.setVerticalGroup(buttonVertical); + + pinField.requestFocusInWindow(); + contentPanel.validate(); + + } + }); + } + + @Override + public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams, final ActionListener okListener, final String okCommand) { + + log.debug("scheduling error dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show error dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_ERROR)); + } + + helpListener.setHelpTopic(errorMsgKey); + + String errorMsgPattern = messages.getString(errorMsgKey); + String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText(errorMsg); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + + if (!renderHeaderPanel) { + JLabel errorTitleLabel = new JLabel(); + errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); + errorTitleLabel.setText(messages.getString(TITLE_ERROR)); + errorTitleLabel.setForeground(ERROR_COLOR); + + mainHorizontal + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(errorTitleLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)); + mainVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorTitleLabel) + .addComponent(helpLabel)); + } + + mainPanelLayout.setHorizontalGroup(mainHorizontal + .addComponent(errorMsgLabel)); + mainPanelLayout.setVerticalGroup(mainVertical + .addComponent(errorMsgLabel)); + + JButton okButton = new JButton(); + okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + okButton.setText(messages.getString(BUTTON_OK)); + okButton.setActionCommand(okCommand); + okButton.addActionListener(okListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(okButton)); + + contentPanel.validate(); + } + }); + } + + @Override + public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams) { + + log.debug("scheduling error dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show error dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_ERROR)); + } + + helpListener.setHelpTopic(errorMsgKey); + + String errorMsgPattern = messages.getString(errorMsgKey); + String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText(errorMsg); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + + GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + + if (!renderHeaderPanel) { + JLabel errorTitleLabel = new JLabel(); + errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); + errorTitleLabel.setText(messages.getString(TITLE_ERROR)); + errorTitleLabel.setForeground(ERROR_COLOR); + + mainHorizontal + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(errorTitleLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)); + mainVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorTitleLabel) + .addComponent(helpLabel)); + } + + mainPanelLayout.setHorizontalGroup(mainHorizontal + .addComponent(errorMsgLabel)); + mainPanelLayout.setVerticalGroup(mainVertical + .addComponent(errorMsgLabel)); + + contentPanel.validate(); + } + }); + } + + @Override + public void showWaitDialog(final String waitMessage) { + + log.debug("scheduling wait dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show wait dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_WAIT)); + } + + helpListener.setHelpTopic(HELP_WAIT); + + JLabel waitMsgLabel = new JLabel(); + waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (waitMessage != null) { + waitMsgLabel.setText("" + waitMessage + ""); + } else { + waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + } + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(waitMsgLabel); + GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel); + + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); + + contentPanel.validate(); + } + }); + } + + @Override + public char[] getPin() { + if (pinField != null) { + return pinField.getPassword(); + } + return null; + } + + /** + * TODO handle multiple references in HashDataViewer + * @param signedReferences + * @param okListener + * @param okCommand + */ + @Override + public void showHashDataInputDialog(final List signedReferences, + final ActionListener okListener, + final String okCommand) { + + if (signedReferences == null) { + showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); + return; + } + + if (signedReferences.size() == 1) { + ActionListener saveHashDataListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + HashDataInput hdi = signedReferences.get(0); + showSaveHashDataInputDialog(Collections.singletonList(hdi), okListener, okCommand); + } + }; + showHashDataViewer(signedReferences.get(0), saveHashDataListener, "save"); + } else { + HashDataTableModel tableModel = new HashDataTableModel(signedReferences); + showSignedReferencesListDialog(tableModel, okListener, okCommand); + } + } + + /** + * Opens HashDataViewer on mouse clicked event + */ + public class HashDataMouseListener extends MouseAdapter { + + private HashDataInput hashData; + + public void setHashData(HashDataInput hashData) { + this.hashData = hashData; + } + + @Override + public void mouseClicked(MouseEvent e) { + ActionListener saveListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(Collections.singletonList(hashData), null, null); + } + }; + showHashDataViewer(hashData, saveListener, "save"); + super.mouseClicked(e); + } + + + + } + + /** + * blocks until dialog returns (is closed) + * @param hashDataText + * @param saveListener + * @param saveCommand + */ + private void showHashDataViewer(final HashDataInput hashDataInput, final ActionListener saveListener, final String saveCommand) { + + try { + log.debug("scheduling plaintext hashdatainput dialog"); + + // avoid double-clicks on hashdata link + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + + log.debug("show plaintext hashdatainput dialog"); + + ActionListener l = helpListener.getActionListener(); + HashDataViewer.showHashDataInput(contentPane, hashDataInput, messages, saveListener, saveCommand, l); + } + }); + + } catch (InterruptedException ex) { + log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } catch (InvocationTargetException ex) { + log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } + } + + private void showSignedReferencesListDialog(final HashDataTableModel signedReferences, final ActionListener backListener, final String backCommand) { + + log.debug("scheduling signed references list dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show signed references list dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_HASHDATA)); + } + + helpListener.setHelpTopic(HELP_HASHDATALIST); + + JLabel refIdLabel = new JLabel(); + refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); + + JTable hashDataTable = new JTable(signedReferences); + hashDataTable.setDefaultRenderer(HashDataInput.class, signedReferences.getRenderer()); + + hashDataTable.setTableHeader(null); + // hashDataTable.setShowVerticalLines(false); + hashDataTable.setRowSelectionAllowed(true); +// TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); +// selectCol.setMinWidth(CHECKBOX_WIDTH); +// selectCol.setMaxWidth(CHECKBOX_WIDTH); + + +// hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); + + JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel); + + GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel); + + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(messageHorizontal) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(messageVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); + + JButton backButton = new JButton(); + backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + backButton.setText(messages.getString(BUTTON_BACK)); + backButton.setActionCommand(backCommand); + backButton.addActionListener(backListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup(buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(backButton)); + + contentPanel.validate(); + } + }); + } + + private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { + + log.debug("scheduling save hashdatainput dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show save hashdatainput dialog"); + + String userHome = System.getProperty("user.home"); + + JFileChooser fileDialog = new JFileChooser(userHome); + fileDialog.setMultiSelectionEnabled(false); + fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); + fileDialog.setFileHidingEnabled(true); + if (signedRefs.size() == 1) { + fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); + fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); + String mimeType = signedRefs.get(0).getMimeType(); + MimeFilter mimeFilter = new MimeFilter(mimeType, messages); + fileDialog.setFileFilter(mimeFilter); + String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); + fileDialog.setSelectedFile(new File(userHome, filename)); + } else { + fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVEDIR)); + fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + } + + //parent contentPane -> placed over applet + switch (fileDialog.showSaveDialog(fileDialog)) { + case JFileChooser.APPROVE_OPTION: + File f = fileDialog.getSelectedFile(); + for (HashDataInput hashDataInput : signedRefs) { + String mimeType = hashDataInput.getMimeType(); + String id = hashDataInput.getReferenceId(); + File file; + if (f.isDirectory()) { + String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); + file = new File(f, filename); + } else { + file = f; + } + if (file.exists()) { + String ovrwrt = messages.getString(MESSAGE_OVERWRITE); + int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), messages.getString(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); + if (overwrite != JOptionPane.OK_OPTION) { + continue; + } + } + if (log.isDebugEnabled()) { + log.debug("Writing HashDataInput " + 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 HashDataInput to file " + file + ": " + ex.getMessage()); + showErrorDialog(ERR_WRITE_HASHDATA, new Object[] {ex.getMessage()}, null, null); + ex.printStackTrace(); + } finally { + try { + fos.close(); + } catch (IOException ex) { + } + } + } + } + log.debug("done saving hashdatainput"); + if (okListener != null) { + okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); + } + } + }); + } + + private void registerHelpListener(ActionListener helpListener) { + if (helpListener != null) { + this.helpListener = new HelpMouseListener(helpListener); + } else { + log.error("no help listener provided, will not be able to display help"); + this.helpListener = new HelpMouseListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + log.error("no help listener registered (requested help topic: " + e.getActionCommand() + ")"); + } + }); + } + } + + private static int initButtonSize(ResourceBundle messages, boolean renderCancelButton) { + + int buttonSize = 0; + + JButton b = new JButton(); + b.setText(messages.getString(BUTTON_OK)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + b.setText(messages.getString(BUTTON_SIGN)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + b.setText(messages.getString(BUTTON_BACK)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + b.setText(messages.getString(BUTTON_SAVE)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + if (renderCancelButton) { + b.setText(messages.getString(BUTTON_CANCEL)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + } + return buttonSize; + } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java index f03bf158..502f93ec 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java @@ -17,7 +17,6 @@ package at.gv.egiz.bku.gui; import java.applet.AppletContext; -import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.util.Locale; import javax.swing.SwingUtilities; @@ -61,7 +60,6 @@ public class DefaultHelpListener extends AbstractHelpListener { // try { log.debug("schedule help dialog"); -// SwingUtilities.invokeAndWait(new Runnable() { SwingUtilities.invokeLater(new Runnable() { @Override @@ -76,10 +74,5 @@ public class DefaultHelpListener extends AbstractHelpListener { } } }); -// } catch (InterruptedException ex) { -// log.error("Failed to display HelpViewer: " + ex.getMessage(), ex); -// } catch (InvocationTargetException ex) { -// log.error("Failed to display HelpViewer: " + ex.getMessage(), ex); -// } } } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java index e8566fa6..a6709860 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java @@ -14,34 +14,46 @@ * 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.util.ArrayList; +import java.awt.Color; +import java.awt.Component; +import java.awt.Cursor; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.util.List; -import java.util.Vector; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JTable; import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableCellRenderer; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** - * - * @author clemens + * + * @author Clemens Orthacker */ class HashDataTableModel extends DefaultTableModel { - protected List signedReferences; + protected static final Log log = LogFactory.getLog(HashDataTableModel.class); - protected Class[] types = new Class[]{ - java.lang.String.class, java.lang.Boolean.class - }; - - public HashDataTableModel(List signedReferences) { - super(0, 2); - this.signedReferences = signedReferences; - for (HashDataInput hashDataInput : signedReferences) { - String desc = hashDataInput.getReferenceId() + " (" + hashDataInput.getMimeType() + ")"; - addRow(new Object[]{desc, new Boolean(true)}); + protected Class[] types = new Class[]{HashDataInput.class}; + protected List hashDataInputs; + private HashDataLinkRenderer renderer; + + public HashDataTableModel(List hashDataInputs) { + super(0, 1); + this.hashDataInputs = hashDataInputs; + for (HashDataInput hdi : hashDataInputs) { + addRow(new Object[]{hdi}); } + this.renderer = new HashDataLinkRenderer(); } @Override @@ -51,18 +63,49 @@ class HashDataTableModel extends DefaultTableModel { @Override public boolean isCellEditable(int rowIndex, int columnIndex) { - if (columnIndex == 1) - return true; return false; } - public List getSelectedHashData() { - ArrayList selection = new ArrayList(); - for (int i = 0; i < dataVector.size(); i++) { - if ((Boolean) ((Vector) dataVector.get(i)).elementAt(1)) { - selection.add(signedReferences.get(i)); - } + + + public HashDataLinkRenderer getRenderer() { + return renderer; + } + + public class HashDataLinkRenderer extends JLabel + implements TableCellRenderer { +// extends DefaultTableCellRenderer { + +// protected ActionListener saveHashDataListener; +// +// public HashDataLinkRenderer(ActionListener saveHashDataListener) { +// this.saveHashDataListener = saveHashDataListener; +// } + + @Override + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + final int row, + int column) { + final HashDataInput hdi = (HashDataInput) value; + log.debug("render hashdatainput " + hdi.getReferenceId() + " - (" + row + "," + column + ") " + isSelected + hasFocus); + setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD)); + setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); + addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + log.debug("received mouseclick on " + hdi.getReferenceId()); +// saveHashDataListener.actionPerformed(); + JOptionPane.showInputDialog(hashDataInputs.get(row).getReferenceId()); + } + + }); + + return this; } - return selection; } } \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java index 7b77faeb..db66bd52 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java @@ -23,18 +23,15 @@ import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; -import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.BufferedReader; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.Charset; import java.text.MessageFormat; -import java.util.List; import java.util.ResourceBundle; import javax.swing.GroupLayout; import javax.swing.ImageIcon; @@ -69,12 +66,12 @@ public class HashDataViewer extends JDialog * * @param signedReferences currently, only one hashdata input (the first in the list) is displayed */ - public static void showHashDataInput(List hashDataInputs, + public static void showHashDataInput(HashDataInput hashDataInput, ResourceBundle messages, ActionListener saveListener, String saveCommand, ActionListener helpListener) { - showHashDataInput(null, hashDataInputs, messages, saveListener, saveCommand, helpListener); + showHashDataInput(null, hashDataInput, messages, saveListener, saveCommand, helpListener); } /** @@ -82,7 +79,7 @@ public class HashDataViewer extends JDialog * @param frameComp owner */ public static void showHashDataInput(Component frameComp, - List hashDataInputs, + HashDataInput hashDataInput, ResourceBundle messages, ActionListener saveListener, String saveCommand, @@ -94,7 +91,7 @@ public class HashDataViewer extends JDialog } dialog = new HashDataViewer(frame, messages, - hashDataInputs, + hashDataInput, saveListener, saveCommand, helpListener); @@ -103,35 +100,33 @@ public class HashDataViewer extends JDialog private HashDataViewer(Frame frame, ResourceBundle messages, - List hashDataInputs, + HashDataInput hashDataInput, ActionListener saveListener, String saveCommand, ActionListener helpListener) { super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); this.messages = messages; - HashDataInput hashData = hashDataInputs.get(0); - Charset cs; - if (hashData.getEncoding() == null) { + if (hashDataInput.getEncoding() == null) { cs = Charset.forName("UTF-8"); } else { try { - cs = Charset.forName(hashData.getEncoding()); + cs = Charset.forName(hashDataInput.getEncoding()); } catch (Exception ex) { - log.debug("charset " + hashData.getEncoding() + " not supported, assuming UTF-8: " + ex.getMessage()); + log.debug("charset " + hashDataInput.getEncoding() + " not supported, assuming UTF-8: " + ex.getMessage()); cs = Charset.forName("UTF-8"); } } - InputStreamReader isr = new InputStreamReader(hashData.getHashDataInput(), cs); + InputStreamReader isr = new InputStreamReader(hashDataInput.getHashDataInput(), cs); Reader content = new BufferedReader(isr); JPanel hashDataPanel = createViewerPanel( messages.getString(BKUGUIFacade.MESSAGE_HASHDATA), content, - hashData.getMimeType(), + hashDataInput.getMimeType(), helpListener); JPanel buttonPanel = createButtonPanel(saveListener, saveCommand); initContentPane(new Dimension(600, 400), hashDataPanel, buttonPanel); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java deleted file mode 100644 index d9606177..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.Color; -import java.awt.Component; -import javax.swing.JLabel; -import javax.swing.JTable; -import javax.swing.table.TableCellRenderer; - -/** - * - * @author Clemens Orthacker - */ -public class HyperLinkRenderer extends JLabel implements TableCellRenderer { - - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - HashDataInput hdi = (HashDataInput) value; - setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); - setBackground(Color.CYAN); - return this; - } - -// extends DefaultTableCellRenderer { -// -// @Override -// public void setValue(Object value) { -// HashDataInput hdi = (HashDataInput) value; -// setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); -// } -} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java index 271c0b65..6a738acb 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java @@ -24,6 +24,7 @@ import javax.swing.ImageIcon; import javax.swing.JPanel; /** + * paints the background image in the lower left corner of the component * * @author Clemens Orthacker */ diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java deleted file mode 100644 index d4d6efef..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ /dev/null @@ -1,1410 +0,0 @@ -/* - * 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.smcc.PINSpec; -import at.gv.egiz.stal.HashDataInput; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.Font; -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.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.text.MessageFormat; -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.JFileChooser; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPasswordField; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextArea; -import javax.swing.LayoutStyle; -import javax.swing.SwingUtilities; -import javax.swing.table.TableModel; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author clemens - */ -public class SimpleGUI implements BKUGUIFacade { - - private static final Log log = LogFactory.getLog(SimpleGUI.class); - - protected HelpMouseListener helpListener; - - protected Container contentPane; - protected ResourceBundle messages; - /** left and right side main panels */ - protected JPanel iconPanel; - protected JPanel contentPanel; - /** right side content panels and layouts */ - protected JPanel headerPanel; - protected JPanel mainPanel; - protected JPanel buttonPanel; - /** right side fixed labels */ - protected JLabel titleLabel; - protected JLabel helpLabel; - /** remember the pinfield to return to worker */ - protected JPasswordField pinField; - - protected int buttonSize; - - /** gui style config (default 'simple') */ - protected boolean renderHeaderPanel = false; - protected boolean renderIconPanel = false; - protected boolean renderCancelButton = false; - - /** - * set contentPane - * init message bundle - * configure the style - * register the help listener - * create GUI (on event-dispatching thread) - * - * @param contentPane - * @param locale - * @param guiStyle - * @param background - * @param helpListener - */ - public SimpleGUI(Container contentPane, Locale locale, Style guiStyle, URL background, ActionListener helpListener) { - this.contentPane = contentPane; - - if (locale != null) { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); - } else { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); - } - - if (guiStyle == Style.advanced) { - renderHeaderPanel = true; - renderIconPanel = false; - renderCancelButton = true; - } - - registerHelpListener(helpListener); - - createGUI(background); - } - - private void createGUI(final URL background) { - - try { - - log.debug("scheduling gui initialization"); - - SwingUtilities.invokeAndWait(new Runnable() { - - @Override - public void run() { - - log.debug("initializing gui"); - - if (renderIconPanel) { - initIconPanel(background); - initContentPanel(null); - } else { - initContentPanel(background); - } - - GroupLayout layout = new GroupLayout(contentPane); - contentPane.setLayout(layout); - - if (renderIconPanel) { - layout.setHorizontalGroup(layout.createSequentialGroup() - .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); - layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); - } else { - layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(contentPanel)); - layout.setVerticalGroup(layout.createSequentialGroup().addComponent(contentPanel)); - } - } - }); - } catch (Exception ex) { - throw new RuntimeException("Failed to init GUI: " + ex.getMessage()); - } - } - - protected void initIconPanel(URL background) { - if (background == null) { - background = getClass().getResource(DEFAULT_BACKGROUND); - } - if ("file".equals(background.getProtocol())) { - log.warn("file:// background images not permitted: " + background); - background = getClass().getResource(DEFAULT_BACKGROUND); - } - log.debug("loading icon panel background " + background); - - iconPanel = new JPanel(); - JLabel iconLabel = new JLabel(); - iconLabel.setIcon(new ImageIcon(background)); - - GroupLayout iconPanelLayout = new GroupLayout(iconPanel); - iconPanel.setLayout(iconPanelLayout); - iconPanelLayout.setHorizontalGroup( - iconPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); - // no gap here (contentPanel has containerGap) - iconPanelLayout.setVerticalGroup( - iconPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); - } - - protected void initContentPanel(URL background) { - - if (background == null) { - background = getClass().getResource(DEFAULT_BACKGROUND); - } - if ("file".equals(background.getProtocol())) { - log.warn("file:// background images not permitted: " + background); - background = getClass().getResource(DEFAULT_BACKGROUND); - } - log.debug("loading background " + background); - contentPanel = new ImagePanel(background); - - mainPanel = new JPanel(); - mainPanel.setOpaque(false); - buttonPanel = new JPanel(); - buttonPanel.setOpaque(false); - - helpLabel = new JLabel(); - helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); - helpLabel.getAccessibleContext().setAccessibleName(messages.getString(ALT_HELP)); - helpLabel.addMouseListener(helpListener); - helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - - buttonSize = initButtonSize(messages, renderCancelButton); - - if (renderHeaderPanel) { - headerPanel = new JPanel(); - headerPanel.setOpaque(false); - - titleLabel = new JLabel(); - titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | - java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); - - GroupLayout headerPanelLayout = new GroupLayout(headerPanel); - headerPanel.setLayout(headerPanelLayout); - - headerPanelLayout.setHorizontalGroup( - headerPanelLayout.createSequentialGroup() - .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - headerPanelLayout.setVerticalGroup( - headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) - .addComponent(helpLabel)); - } - - GroupLayout contentPanelLayout = new GroupLayout(contentPanel); - contentPanel.setLayout(contentPanelLayout); - - GroupLayout.ParallelGroup horizontalContentInner = contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); - if (renderHeaderPanel) { - horizontalContentInner - .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); - } - horizontalContentInner - .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); - GroupLayout.SequentialGroup horizontalContentOuter = contentPanelLayout.createSequentialGroup(); - if (!renderIconPanel) { - horizontalContentOuter - .addContainerGap(); - } - horizontalContentOuter - .addGroup(horizontalContentInner) - .addContainerGap(); - contentPanelLayout.setHorizontalGroup(horizontalContentOuter); - - GroupLayout.SequentialGroup verticalContent = contentPanelLayout.createSequentialGroup(); - verticalContent.addContainerGap(); - if (renderHeaderPanel) { - verticalContent.addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); - } - verticalContent.addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap(); - contentPanelLayout.setVerticalGroup(verticalContent); - } - - @Override - public Locale getLocale() { - return messages.getLocale(); - } - - @Override - public void showWelcomeDialog() { - - log.debug("scheduling welcome dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show welcome dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - helpListener.setHelpTopic(HELP_WELCOME); - - JLabel welcomeMsgLabel = new JLabel(); - welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - - if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_WELCOME)); - welcomeMsgLabel.setText(messages.getString(MESSAGE_WAIT)); - } else { - welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); - } - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(welcomeMsgLabel); - GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(welcomeMsgLabel); - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - contentPanel.validate(); - - } - }); - } - - @Override - public void showInsertCardDialog(final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling insert card dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show insert card dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_INSERTCARD)); - } - - helpListener.setHelpTopic(HELP_INSERTCARD); - - JLabel insertCardMsgLabel = new JLabel(); - insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel); - GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup() - .addComponent(insertCardMsgLabel); - - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - if (renderCancelButton) { - JButton cancelButton = new JButton(); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.addActionListener(cancelListener); - cancelButton.setActionCommand(cancelCommand); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(cancelButton)); - } - - contentPanel.validate(); - } - }); - } - - /** - * only difference to showInsertCard: title text: card not supported - * @param cancelListener - * @param cancelCommand - */ - @Override - public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling card not supported dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show card not supported dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - JLabel insertCardMsgLabel = new JLabel(); - insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - - if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); - insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); - } else { - insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); - } - - helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel); - GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(insertCardMsgLabel); - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - if (renderCancelButton) { - JButton cancelButton = new JButton(); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.addActionListener(cancelListener); - cancelButton.setActionCommand(cancelCommand); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(cancelButton)); - } - - contentPanel.validate(); - } - }); - } - - private static int initButtonSize(ResourceBundle messages, boolean renderCancelButton) { - - int buttonSize = 0; - - JButton b = new JButton(); - b.setText(messages.getString(BUTTON_OK)); - if (b.getPreferredSize().width > buttonSize) { - buttonSize = b.getPreferredSize().width; - } - b.setText(messages.getString(BUTTON_SIGN)); - if (b.getPreferredSize().width > buttonSize) { - buttonSize = b.getPreferredSize().width; - } - b.setText(messages.getString(BUTTON_BACK)); - if (b.getPreferredSize().width > buttonSize) { - buttonSize = b.getPreferredSize().width; - } - b.setText(messages.getString(BUTTON_SAVE)); - if (b.getPreferredSize().width > buttonSize) { - buttonSize = b.getPreferredSize().width; - } - if (renderCancelButton) { - b.setText(messages.getString(BUTTON_CANCEL)); - if (b.getPreferredSize().width > buttonSize) { - buttonSize = b.getPreferredSize().width; - } - } - return buttonSize; - } - - private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling card-pin dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show card-pin dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - if (numRetries < 0) { - String cardpinTitle = messages.getString(TITLE_CARDPIN); - titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); - } else { - titleLabel.setText(messages.getString(TITLE_RETRY)); - } - } - - JButton okButton = new JButton(); - okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - okButton.setText(messages.getString(BUTTON_OK)); - okButton.setEnabled(false); - okButton.setActionCommand(okCommand); - okButton.addActionListener(okListener); - - JLabel cardPinLabel = new JLabel(); - cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String pinLabel = messages.getString(LABEL_PIN); - cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); - - pinField = new JPasswordField(); - pinField.setText(""); - pinField.setDocument(new PINDocument(pinSpec, okButton)); - pinField.setActionCommand(okCommand); - pinField.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - if (pinField.getPassword().length >= pinSpec.getMinLength()) { - okListener.actionPerformed(e); - } - } - }); - - JLabel infoLabel = new JLabel(); - if (numRetries < 0) { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String infoPattern = messages.getString(MESSAGE_ENTERPIN); - infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); - helpListener.setHelpTopic(HELP_CARDPIN); - } else { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); - infoLabel.setForeground(ERROR_COLOR); - helpListener.setHelpTopic(HELP_RETRY); - } - - JLabel pinsizeLabel = new JLabel(); - pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); - String pinsizePattern = messages.getString(LABEL_PINSIZE); - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); - GroupLayout.SequentialGroup pinHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) - .addComponent(pinsizeLabel)); - - GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); - - if (!renderHeaderPanel) { - GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel) //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - mainHorizontal - .addGroup(infoHorizontal) - .addGroup(pinHorizontal); - GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel) - .addComponent(helpLabel); - mainVertical - .addGroup(infoVertical) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); - } else { - mainHorizontal - .addGroup(pinHorizontal); - } - - mainVertical - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(cardPinLabel) - .addComponent(pinField)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel); - - mainPanelLayout.setHorizontalGroup(mainHorizontal); - mainPanelLayout.setVerticalGroup(mainVertical); - - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); - GroupLayout.Group buttonVertical; - - if (renderCancelButton) { - JButton cancelButton = new JButton(); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.setActionCommand(cancelCommand); - cancelButton.addActionListener(cancelListener); - - buttonHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); - buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(okButton) - .addComponent(cancelButton); - } else { - buttonVertical = buttonPanelLayout.createSequentialGroup() - .addComponent(okButton); - } - - buttonPanelLayout.setHorizontalGroup(buttonHorizontal); - buttonPanelLayout.setVerticalGroup(buttonVertical); - - pinField.requestFocusInWindow(); - contentPanel.validate(); - - } - }); - } - - @Override - public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { - showCardPINDialog(pinSpec, -1, okListener, okCommand, cancelListener, cancelCommand); - } - - @Override - public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { - showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); - } - - @Override - public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { - showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); - } - - @Override - public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { - showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); - } - - private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { - - log.debug("scheduling signature-pin dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show signature-pin dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - if (numRetries < 0) { - titleLabel.setText(messages.getString(TITLE_SIGN)); - } else { - titleLabel.setText(messages.getString(TITLE_RETRY)); - } - } - - JButton signButton = new JButton(); - signButton.setFont(signButton.getFont().deriveFont(signButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - signButton.setText(messages.getString(BUTTON_SIGN)); - signButton.setEnabled(false); - signButton.setActionCommand(signCommand); - signButton.addActionListener(signListener); - - JLabel signPinLabel = new JLabel(); - signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String pinLabel = messages.getString(LABEL_PIN); - signPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); - - pinField = new JPasswordField(); - pinField.setText(""); - pinField.setDocument(new PINDocument(pinSpec, signButton)); - pinField.setActionCommand(signCommand); - pinField.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - if (pinField.getPassword().length >= pinSpec.getMinLength()) { - signListener.actionPerformed(e); - } - } - }); - - JLabel pinsizeLabel = new JLabel(); - pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); - String pinsizePattern = messages.getString(LABEL_PINSIZE); - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); - - JLabel infoLabel = new JLabel(); - if (numRetries < 0) { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); - infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - infoLabel.setForeground(HYPERLINK_COLOR); - infoLabel.addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent me) { - ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); - hashdataListener.actionPerformed(e); - } - }); - helpListener.setHelpTopic(HELP_SIGNPIN); - } else { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); - infoLabel.setForeground(ERROR_COLOR); - helpListener.setHelpTopic(HELP_RETRY); - } - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel); - GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel); - - if (!renderHeaderPanel) { - infoHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); - infoVertical - .addComponent(helpLabel); - } - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(infoHorizontal) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pinsizeLabel)))); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(infoVertical) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(signPinLabel) - .addComponent(pinField)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); - GroupLayout.Group buttonVertical; - - if (renderCancelButton) { - JButton cancelButton = new JButton(); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.setActionCommand(cancelCommand); - cancelButton.addActionListener(cancelListener); - - buttonHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); - - buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(signButton) - .addComponent(cancelButton); - } else { - buttonVertical = buttonPanelLayout.createSequentialGroup() - .addComponent(signButton); - } - - buttonPanelLayout.setHorizontalGroup(buttonHorizontal); - buttonPanelLayout.setVerticalGroup(buttonVertical); - - pinField.requestFocusInWindow(); - contentPanel.validate(); - - } - }); - } - - @Override - public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams, final ActionListener okListener, final String okCommand) { - - log.debug("scheduling error dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show error dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_ERROR)); - } - - helpListener.setHelpTopic(errorMsgKey); - - String errorMsgPattern = messages.getString(errorMsgKey); - String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); - - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(errorMsg); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); - GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); - - if (!renderHeaderPanel) { - JLabel errorTitleLabel = new JLabel(); - errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); - errorTitleLabel.setText(messages.getString(TITLE_ERROR)); - errorTitleLabel.setForeground(ERROR_COLOR); - - mainHorizontal - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(errorTitleLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainVertical - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorTitleLabel) - .addComponent(helpLabel)); - } - - mainPanelLayout.setHorizontalGroup(mainHorizontal - .addComponent(errorMsgLabel)); - mainPanelLayout.setVerticalGroup(mainVertical - .addComponent(errorMsgLabel)); - - JButton okButton = new JButton(); - okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - okButton.setText(messages.getString(BUTTON_OK)); - okButton.setActionCommand(okCommand); - okButton.addActionListener(okListener); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(okButton)); - - contentPanel.validate(); - } - }); - } - - @Override - public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams) { - - log.debug("scheduling error dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show error dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_ERROR)); - } - - helpListener.setHelpTopic(errorMsgKey); - - String errorMsgPattern = messages.getString(errorMsgKey); - String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); - - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(errorMsg); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - - GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); - GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); - - if (!renderHeaderPanel) { - JLabel errorTitleLabel = new JLabel(); - errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); - errorTitleLabel.setText(messages.getString(TITLE_ERROR)); - errorTitleLabel.setForeground(ERROR_COLOR); - - mainHorizontal - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(errorTitleLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainVertical - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorTitleLabel) - .addComponent(helpLabel)); - } - - mainPanelLayout.setHorizontalGroup(mainHorizontal - .addComponent(errorMsgLabel)); - mainPanelLayout.setVerticalGroup(mainVertical - .addComponent(errorMsgLabel)); - - contentPanel.validate(); - } - }); - } - - @Override - public void showWaitDialog(final String waitMessage) { - - log.debug("scheduling wait dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show wait dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_WAIT)); - } - - helpListener.setHelpTopic(HELP_WAIT); - - JLabel waitMsgLabel = new JLabel(); - waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - if (waitMessage != null) { - waitMsgLabel.setText("" + waitMessage + ""); - } else { - waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); - } - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel); - GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel); - - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - contentPanel.validate(); - } - }); - } - - @Override - public char[] getPin() { - if (pinField != null) { - return pinField.getPassword(); - } - return null; - } - - /** - * TODO handle multiple references in HashDataViewer - * @param signedReferences - * @param okListener - * @param okCommand - */ - @Override - public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { - - if (signedReferences == null) { - showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); - return; - } - - ActionListener saveHashDataListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(signedReferences, okListener, okCommand); - } - }; - - if (signedReferences.size() == 1) { - -// if (standalone) { - - showHashDataViewer(signedReferences, saveHashDataListener, "save"); - -// } else { -// if ("text/plain".equals(signedReferences.get(0).getMimeType())) { -// -// ActionListener saveHashDataListener = new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// showSaveHashDataInputDialog(signedReferences, okListener, okCommand); -// } -// }; -// -// try { -// String hashDataText = getText(signedReferences.get(0)); -// showPlainTextHashDataInputDialog(hashDataText, saveHashDataListener, "save", okListener, okCommand); -// } catch (IOException ex) { -// showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {ex.getMessage()}, okListener, okCommand); -// } -// -// } else { -// showSaveHashDataInputDialog(signedReferences, okListener, okCommand); -// } -// } - } else { - -// final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); -// -// ActionListener saveHashDataListener = new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// showSaveHashDataInputDialog(tableModel.getSelectedHashData(), okListener, okCommand); -// } -// }; - - SimpleHashDataTableModel tableModel = new SimpleHashDataTableModel(signedReferences); - showMultipleHashDataInputDialog(tableModel, okListener, okCommand, saveHashDataListener, "save"); - } - } - - /** - * blocks until dialog returns (is closed) - * @param hashDataText - * @param saveListener - * @param saveCommand - */ - private void showHashDataViewer(final List signedReferences, final ActionListener saveListener, final String saveCommand) { - - try { - log.debug("scheduling plaintext hashdatainput dialog"); - - SwingUtilities.invokeAndWait(new Runnable() { - - @Override - public void run() { - - log.debug("show plaintext hashdatainput dialog"); - - ActionListener l = helpListener.getActionListener(); - HashDataViewer.showHashDataInput(contentPane, signedReferences, messages, saveListener, saveCommand, l); - } - }); - - } catch (InterruptedException ex) { - log.error("Failed to display HashDataViewer: " + ex.getMessage()); - } catch (InvocationTargetException ex) { - log.error("Failed to display HashDataViewer: " + ex.getMessage()); - } - } - -// private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { -// -// log.debug("scheduling plaintext hashdatainput dialog"); -// -// SwingUtilities.invokeLater(new Runnable() { -// -// @Override -// public void run() { -// -// log.debug("show plaintext hashdatainput dialog"); -// -// mainPanel.removeAll(); -// buttonPanel.removeAll(); -// -// helpListener.setHelpTopic(HELP_HASHDATA); -// -// JLabel refIdLabel = new JLabel(); -// refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); -// refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); -// -// JTextArea hashDataTextArea = new JTextArea(hashDataText); -// hashDataTextArea.setEditable(false); -// hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); -// hashDataTextArea.setLineWrap(true); -// hashDataTextArea.setWrapStyleWord(true); -// -// JScrollPane hashDataScrollPane = new JScrollPane(hashDataTextArea); -// -// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); -// mainPanel.setLayout(mainPanelLayout); -// -// mainPanelLayout.setHorizontalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(mainPanelLayout.createSequentialGroup() -// .addComponent(refIdLabel) -// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) -// .addComponent(helpLabel)) -// .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); -// -// mainPanelLayout.setVerticalGroup( -// mainPanelLayout.createSequentialGroup() -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(refIdLabel) -// .addComponent(helpLabel)) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); -// -// JButton backButton = new JButton(); -// backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); -// backButton.setText(messages.getString(BUTTON_BACK)); -// backButton.setActionCommand(cancelCommand); -// backButton.addActionListener(cancelListener); -// -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addComponent(backButton)); -// -// contentPanel.validate(); -// } -// }); -// } - - private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, final ActionListener saveListener, final String saveCommand) { - - log.debug("scheduling multiple hashdatainput dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show multiple hashdatainput dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_HASHDATA)); - } - - helpListener.setHelpTopic(HELP_HASHDATALIST); - - JLabel refIdLabel = new JLabel(); - refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); - refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); - - JTable hashDataTable = new JTable(); - hashDataTable.setDefaultRenderer(HashDataInput.class, new HyperLinkRenderer()); - hashDataTable.setModel(signedReferences); - hashDataTable.setTableHeader(null); - // hashDataTable.setShowVerticalLines(false); - // hashDataTable.setRowSelectionAllowed(false); -// TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); -// selectCol.setMinWidth(CHECKBOX_WIDTH); -// selectCol.setMaxWidth(CHECKBOX_WIDTH); - - -// hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); - - JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(helpLabel)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); - - JButton backButton = new JButton(); - backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - backButton.setText(messages.getString(BUTTON_BACK)); - backButton.setActionCommand(cancelCommand); - backButton.addActionListener(cancelListener); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); - GroupLayout.ParallelGroup buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(backButton); - - if (renderCancelButton) { - //render save button - JButton saveButton = new JButton(); - saveButton.setText(messages.getString(BUTTON_SAVE)); - saveButton.setActionCommand(saveCommand); - saveButton.addActionListener(saveListener); - - buttonHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); - buttonVertical - .addComponent(saveButton); - } - - buttonPanelLayout.setHorizontalGroup(buttonHorizontal); - buttonPanelLayout.setVerticalGroup(buttonVertical); - - contentPanel.validate(); - } - }); - } - - private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { - - log.debug("scheduling save hashdatainput dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show save hashdatainput dialog"); - - String userHome = System.getProperty("user.home"); - - JFileChooser fileDialog = new JFileChooser(userHome); - fileDialog.setMultiSelectionEnabled(false); - fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); - fileDialog.setFileHidingEnabled(true); - if (signedRefs.size() == 1) { - fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); - fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); - String mimeType = signedRefs.get(0).getMimeType(); - MimeFilter mimeFilter = new MimeFilter(mimeType, messages); - fileDialog.setFileFilter(mimeFilter); - String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); - fileDialog.setSelectedFile(new File(userHome, filename)); - } else { - fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVEDIR)); - fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - } - - //parent contentPane -> placed over applet - switch (fileDialog.showSaveDialog(fileDialog)) { - case JFileChooser.APPROVE_OPTION: - File f = fileDialog.getSelectedFile(); - for (HashDataInput hashDataInput : signedRefs) { - String mimeType = hashDataInput.getMimeType(); - String id = hashDataInput.getReferenceId(); - File file; - if (f.isDirectory()) { - String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); - file = new File(f, filename); - } else { - file = f; - } - if (file.exists()) { - String ovrwrt = messages.getString(MESSAGE_OVERWRITE); - int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), messages.getString(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); - if (overwrite != JOptionPane.OK_OPTION) { - continue; - } - } - if (log.isDebugEnabled()) { - log.debug("Writing HashDataInput " + 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 HashDataInput to file " + file + ": " + ex.getMessage()); - showErrorDialog(ERR_WRITE_HASHDATA, new Object[] {ex.getMessage()}, null, null); - ex.printStackTrace(); - } finally { - try { - fos.close(); - } catch (IOException ex) { - } - } - } - } - log.debug("done saving hashdatainput"); - okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); - } - }); - } - -// private static String getText(HashDataInput hdi) throws IOException { -// ByteArrayOutputStream baos = null; -// try { -// InputStream hashDataIS = hdi.getHashDataInput(); -// if (hashDataIS == null) { -// log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); -// return null; -// } else { -// baos = new ByteArrayOutputStream(hashDataIS.available()); -// int c; -// while ((c = hashDataIS.read()) != -1) { -// baos.write(c); -// } -// String encoding = hdi.getEncoding(); -// if (encoding == null) { -// //default for URL-encoded -// encoding = "UTF-8"; -// } -// return baos.toString(encoding); -// } -// } catch (IOException ex) { -// log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); -// throw ex; -// } finally { -// try { -// baos.close(); -// } catch (IOException ex) { -// } -// } -// } - - private void registerHelpListener(ActionListener helpListener) { - if (helpListener != null) { - this.helpListener = new HelpMouseListener(helpListener); - } else { - log.error("no help listener provided, will not be able to display help"); - this.helpListener = new HelpMouseListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - log.error("no help listener registered (requested help topic: " + e.getActionCommand() + ")"); - } - }); - } - } -} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java deleted file mode 100644 index 463dbe81..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.event.ActionListener; -import java.util.ArrayList; -import java.util.List; -import java.util.Vector; -import javax.swing.table.DefaultTableModel; - -/** - * - * @author clemens - */ -class SimpleHashDataTableModel extends DefaultTableModel { - - protected List signedReferences; - - protected Class[] types = new Class[]{ - java.lang.String.class - }; - - public SimpleHashDataTableModel(List signedReferences) { - super(0, 1); - this.signedReferences = signedReferences; - for (HashDataInput hashDataInput : signedReferences) { - -// String desc = hashDataInput.getReferenceId() + " (" + hashDataInput.getMimeType() + ")"; - addRow(new Object[]{hashDataInput}); - } - } - - @Override - public Class getColumnClass(int columnIndex) { - return types[columnIndex]; - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - if (columnIndex == 1) - return true; - return false; - } -} \ No newline at end of file -- cgit v1.2.3 From bc81c317e254fa617fc24c8129b743ac74aad470 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 19 Nov 2008 11:49:55 +0000 Subject: GUI feature complete git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@180 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 158 ++++++++++++--------- .../at/gv/egiz/bku/gui/HashDataTableModel.java | 98 ++++++------- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 6 +- 3 files changed, 138 insertions(+), 124 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 9d23315c..38247174 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 @@ -38,6 +38,8 @@ import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.CellRendererPane; import javax.swing.GroupLayout; import javax.swing.ImageIcon; @@ -50,8 +52,12 @@ import javax.swing.JPasswordField; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.LayoutStyle; +import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -1013,80 +1019,75 @@ public class BKUGUIImpl implements BKUGUIFacade { } if (signedReferences.size() == 1) { - ActionListener saveHashDataListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - HashDataInput hdi = signedReferences.get(0); - showSaveHashDataInputDialog(Collections.singletonList(hdi), okListener, okCommand); - } - }; - showHashDataViewer(signedReferences.get(0), saveHashDataListener, "save"); + try { + log.debug("scheduling hashdata viewer"); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + ActionListener saveHashDataListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + HashDataInput hdi = signedReferences.get(0); + showSaveHashDataInputDialog(Collections.singletonList(hdi), okListener, okCommand); + } + }; + showHashDataViewer(signedReferences.get(0), saveHashDataListener, "save"); + } + }); + + } catch (InterruptedException ex) { + log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } catch (InvocationTargetException ex) { + log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } } else { - HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - showSignedReferencesListDialog(tableModel, okListener, okCommand); + showSignedReferencesListDialog(signedReferences, okListener, okCommand); } } /** * Opens HashDataViewer on mouse clicked event */ - public class HashDataMouseListener extends MouseAdapter { - - private HashDataInput hashData; - - public void setHashData(HashDataInput hashData) { - this.hashData = hashData; - } - - @Override - public void mouseClicked(MouseEvent e) { - ActionListener saveListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(Collections.singletonList(hashData), null, null); - } - }; - showHashDataViewer(hashData, saveListener, "save"); - super.mouseClicked(e); - } - - - - } +// public class HashDataMouseListener extends MouseAdapter { +// +// private HashDataInput hashData; +// +// public void setHashData(HashDataInput hashData) { +// this.hashData = hashData; +// } +// +// @Override +// public void mouseClicked(MouseEvent e) { +// ActionListener saveListener = new ActionListener() { +// +// @Override +// public void actionPerformed(ActionEvent e) { +// showSaveHashDataInputDialog(Collections.singletonList(hashData), null, null); +// } +// }; +// showHashDataViewer(hashData, saveListener, "save"); +// super.mouseClicked(e); +// } +// } /** - * blocks until dialog returns (is closed) + * has to be called from event dispatcher thread * @param hashDataText * @param saveListener * @param saveCommand */ private void showHashDataViewer(final HashDataInput hashDataInput, final ActionListener saveListener, final String saveCommand) { - try { - log.debug("scheduling plaintext hashdatainput dialog"); - - // avoid double-clicks on hashdata link - SwingUtilities.invokeAndWait(new Runnable() { - - @Override - public void run() { - - log.debug("show plaintext hashdatainput dialog"); + log.debug("show hashdata viewer"); - ActionListener l = helpListener.getActionListener(); - HashDataViewer.showHashDataInput(contentPane, hashDataInput, messages, saveListener, saveCommand, l); - } - }); - - } catch (InterruptedException ex) { - log.error("Failed to display HashDataViewer: " + ex.getMessage()); - } catch (InvocationTargetException ex) { - log.error("Failed to display HashDataViewer: " + ex.getMessage()); - } + ActionListener l = helpListener.getActionListener(); + HashDataViewer.showHashDataInput(contentPane, hashDataInput, messages, saveListener, saveCommand, l); } - private void showSignedReferencesListDialog(final HashDataTableModel signedReferences, final ActionListener backListener, final String backCommand) { + private void showSignedReferencesListDialog(final List signedReferences, final ActionListener backListener, final String backCommand) { log.debug("scheduling signed references list dialog"); @@ -1109,21 +1110,40 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); - refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.size()})); - JTable hashDataTable = new JTable(signedReferences); - hashDataTable.setDefaultRenderer(HashDataInput.class, signedReferences.getRenderer()); - + HashDataTableModel tableModel = new HashDataTableModel(signedReferences); + JTable hashDataTable = new JTable(tableModel); +// hashDataTable.setDefaultRenderer(HashDataInput.class, signedReferences.getRenderer()); hashDataTable.setTableHeader(null); - // hashDataTable.setShowVerticalLines(false); - hashDataTable.setRowSelectionAllowed(true); -// TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); -// selectCol.setMinWidth(CHECKBOX_WIDTH); -// selectCol.setMaxWidth(CHECKBOX_WIDTH); + + hashDataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + hashDataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(final ListSelectionEvent e) { + //invoke later to allow thread to paint selection background + SwingUtilities.invokeLater(new Runnable() { -// hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); + @Override + public void run() { + ListSelectionModel lsm = (ListSelectionModel) e.getSource(); + int selectionIdx = lsm.getMinSelectionIndex(); + if (selectionIdx >= 0) { + final HashDataInput selection = signedReferences.get(selectionIdx); + showHashDataViewer(selection, new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(Collections.singletonList(selection), null, null); + } + }, "save"); + } + } + }); + } + }); + JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -1174,6 +1194,12 @@ public class BKUGUIImpl implements BKUGUIFacade { }); } + /** + * + * @param signedRefs + * @param okListener may be null + * @param okCommand + */ private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { log.debug("scheduling save hashdatainput dialog"); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java index a6709860..9a43e99d 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java @@ -17,21 +17,8 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.stal.HashDataInput; -import java.awt.Color; -import java.awt.Component; -import java.awt.Cursor; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.util.List; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JTable; import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableCellRenderer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -43,17 +30,15 @@ class HashDataTableModel extends DefaultTableModel { protected static final Log log = LogFactory.getLog(HashDataTableModel.class); - protected Class[] types = new Class[]{HashDataInput.class}; + protected Class[] types = new Class[]{ String.class, String.class }; protected List hashDataInputs; - private HashDataLinkRenderer renderer; public HashDataTableModel(List hashDataInputs) { - super(0, 1); + super(0, 2); this.hashDataInputs = hashDataInputs; for (HashDataInput hdi : hashDataInputs) { - addRow(new Object[]{hdi}); + addRow(new Object[]{hdi.getReferenceId(), hdi.getMimeType()}); } - this.renderer = new HashDataLinkRenderer(); } @Override @@ -66,46 +51,45 @@ class HashDataTableModel extends DefaultTableModel { return false; } - - - public HashDataLinkRenderer getRenderer() { - return renderer; - } +// public HashDataInput getValue(int rowIndex) { +// return hashDataInputs.get(rowIndex); +// } +// - public class HashDataLinkRenderer extends JLabel - implements TableCellRenderer { -// extends DefaultTableCellRenderer { - -// protected ActionListener saveHashDataListener; +// public class HashDataLinkRenderer extends JLabel +// implements TableCellRenderer { +//// extends DefaultTableCellRenderer { +// +//// protected ActionListener saveHashDataListener; +//// +//// public HashDataLinkRenderer(ActionListener saveHashDataListener) { +//// this.saveHashDataListener = saveHashDataListener; +//// } +// +// @Override +// public Component getTableCellRendererComponent(JTable table, +// Object value, +// boolean isSelected, +// boolean hasFocus, +// final int row, +// int column) { +// final HashDataInput hdi = (HashDataInput) value; +// log.debug("render hashdatainput " + hdi.getReferenceId() + " - (" + row + "," + column + ") " + isSelected + hasFocus); +// setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); +// setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD)); +// setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); +// addMouseListener(new MouseAdapter() { +// +// @Override +// public void mouseClicked(MouseEvent e) { +// log.debug("received mouseclick on " + hdi.getReferenceId()); +//// saveHashDataListener.actionPerformed(); +// JOptionPane.showInputDialog(hashDataInputs.get(row).getReferenceId()); +// } +// +// }); // -// public HashDataLinkRenderer(ActionListener saveHashDataListener) { -// this.saveHashDataListener = saveHashDataListener; +// return this; // } - - @Override - public Component getTableCellRendererComponent(JTable table, - Object value, - boolean isSelected, - boolean hasFocus, - final int row, - int column) { - final HashDataInput hdi = (HashDataInput) value; - log.debug("render hashdatainput " + hdi.getReferenceId() + " - (" + row + "," + column + ") " + isSelected + hasFocus); - setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD)); - setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); - addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent e) { - log.debug("received mouseclick on " + hdi.getReferenceId()); -// saveHashDataListener.actionPerformed(); - JOptionPane.showInputDialog(hashDataInputs.get(row).getReferenceId()); - } - - }); - - return this; - } - } +// } } \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java index db66bd52..263c3c04 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.gui; +import at.gv.egiz.bku.gui.html.RestrictedHTMLEditorKit; import at.gv.egiz.stal.HashDataInput; import java.awt.Component; import java.awt.Container; @@ -45,6 +46,7 @@ import javax.swing.JScrollPane; import javax.swing.LayoutStyle; 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; @@ -182,9 +184,11 @@ public class HashDataViewer extends JDialog JEditorPane viewer = new JEditorPane(); if ("text/plain".equals(mimeType)) { + //line wrapping, etc. + viewer.setEditorKit(new StyledEditorKit()); viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); // } else if ("text/html".equals(mimeType)) { -// viewer.setEditorKitForContentType("text/html", new RestrictedHTMLEditorKit()); +// viewer.setEditorKit(new RestrictedHTMLEditorKit()); } viewer.setEditable(false); viewer.setContentType(mimeType); -- cgit v1.2.3 From d8901c075f9deb663e0edd640672ed620ffb4610 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 19 Nov 2008 16:14:57 +0000 Subject: GUI bugfixes and cleanup git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@181 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 26 +----- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 103 +++++++++------------ .../at/gv/egiz/bku/gui/DefaultHelpListener.java | 4 + .../at/gv/egiz/bku/gui/HashDataTableModel.java | 47 +--------- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 1 - .../java/at/gv/egiz/bku/gui/HyperlinkRenderer.java | 38 ++++++++ 6 files changed, 89 insertions(+), 130 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 2dbba730..7d912f11 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -19,9 +19,7 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.smcc.PINSpec; import java.awt.Color; -import java.awt.Container; import java.awt.event.ActionListener; -import java.net.URL; import java.util.List; import java.util.Locale; @@ -71,7 +69,6 @@ public interface BKUGUIFacade { public static final String MESSAGE_HELP = "message.help"; public static final String LABEL_PIN = "label.pin"; public static final String LABEL_PINSIZE = "label.pinsize"; -// public static final String ERROR_NO_HASHDATA = "error.no.hashdata"; public static final String HELP_WELCOME = "help.welcome"; public static final String HELP_WAIT = "help.wait"; public static final String HELP_CARDNOTSUPPORTED = "help.cardnotsupported"; @@ -95,17 +92,13 @@ public interface BKUGUIFacade { // public void init(Container contentPane, Locale locale, Style guiStyle, URL background, ActionListener helpListener); - /** - * - * @return the locale of the message bundle (what if no message bundle could be loaded for the requested locale?) - */ public Locale getLocale(); public void showWelcomeDialog(); /** * - * @param waitMessage if null, a simple 'wait' text is displayed + * @param waitMessage if null, a simple 'please wait' text is displayed */ public void showWaitDialog(String waitMessage); @@ -123,25 +116,8 @@ public interface BKUGUIFacade { public char[] getPin(); - /** - * TODO move to HashDataDisplay implementations - * @param signedReferences - * @param externalDisplay - * @param okListener - * @param okCommand - */ public void showHashDataInputDialog(List signedReferences, ActionListener okListener, String okCommand); - /** - * TODO pull out from BKUGUIFacade. (or make this strictly an applet internal version) - * Problem: if standalone flag is provided, we also need the actionlistener.. - * @param helpDocument - * @param mimeType - * @param encoding - */ -// public void showHelpDialog(InputStream helpDocument, String mimeType, String encoding); //, boolean standalone); //, ActionListener okListener, String okCommand); - -// public void showPlainTextHashDataInputDialog(String text, ActionListener saveListener, String saveCommand, ActionListener cancelListener, String cancelCommand); public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String actionCommand); public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams); 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 38247174..a190b9c0 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 @@ -26,6 +26,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionAdapter; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -554,44 +556,37 @@ public class BKUGUIImpl implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); - GroupLayout.SequentialGroup pinHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) - .addComponent(pinsizeLabel)); - - GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel); if (!renderHeaderPanel) { - GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel) //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + infoHorizontal .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - mainHorizontal - .addGroup(infoHorizontal) - .addGroup(pinHorizontal); - GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel) .addComponent(helpLabel); - mainVertical - .addGroup(infoVertical) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); - } else { - mainHorizontal - .addGroup(pinHorizontal); - } - - mainVertical - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(cardPinLabel) - .addComponent(pinField)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel); + infoVertical + .addComponent(helpLabel); + } - mainPanelLayout.setHorizontalGroup(mainHorizontal); - mainPanelLayout.setVerticalGroup(mainVertical); + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(infoHorizontal) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) + .addComponent(pinsizeLabel)))); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cardPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel)); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); @@ -1048,31 +1043,6 @@ public class BKUGUIImpl implements BKUGUIFacade { } } - /** - * Opens HashDataViewer on mouse clicked event - */ -// public class HashDataMouseListener extends MouseAdapter { -// -// private HashDataInput hashData; -// -// public void setHashData(HashDataInput hashData) { -// this.hashData = hashData; -// } -// -// @Override -// public void mouseClicked(MouseEvent e) { -// ActionListener saveListener = new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// showSaveHashDataInputDialog(Collections.singletonList(hashData), null, null); -// } -// }; -// showHashDataViewer(hashData, saveListener, "save"); -// super.mouseClicked(e); -// } -// } - /** * has to be called from event dispatcher thread * @param hashDataText @@ -1113,10 +1083,23 @@ public class BKUGUIImpl implements BKUGUIFacade { refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.size()})); HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - JTable hashDataTable = new JTable(tableModel); -// hashDataTable.setDefaultRenderer(HashDataInput.class, signedReferences.getRenderer()); + final JTable hashDataTable = new JTable(tableModel); + hashDataTable.setDefaultRenderer(HashDataInput.class, new HyperlinkRenderer()); hashDataTable.setTableHeader(null); + // not possible to add mouse listener to TableCellRenderer + hashDataTable.addMouseMotionListener(new MouseMotionAdapter() { + + @Override + public void mouseMoved(MouseEvent e) { + if (hashDataTable.columnAtPoint(e.getPoint()) == 0) { + hashDataTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } else { + hashDataTable.setCursor(Cursor.getDefaultCursor()); + } + } + }); + hashDataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); hashDataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java index 502f93ec..3c8c7d6c 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java @@ -27,6 +27,10 @@ import javax.swing.SwingUtilities; */ public class DefaultHelpListener extends AbstractHelpListener { + /** + * applet context to open external links in help pages, + * if null, no external links will be opened + */ protected AppletContext ctx; /** diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java index 9a43e99d..b0f51a78 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java @@ -30,14 +30,15 @@ class HashDataTableModel extends DefaultTableModel { protected static final Log log = LogFactory.getLog(HashDataTableModel.class); - protected Class[] types = new Class[]{ String.class, String.class }; + /** HashDataInput in first column, register hyperlinkrenderer only here */ + protected Class[] types = new Class[]{ HashDataInput.class, String.class }; protected List hashDataInputs; public HashDataTableModel(List hashDataInputs) { super(0, 2); this.hashDataInputs = hashDataInputs; for (HashDataInput hdi : hashDataInputs) { - addRow(new Object[]{hdi.getReferenceId(), hdi.getMimeType()}); + addRow(new Object[]{ hdi, hdi.getMimeType()}); } } @@ -50,46 +51,4 @@ class HashDataTableModel extends DefaultTableModel { public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } - -// public HashDataInput getValue(int rowIndex) { -// return hashDataInputs.get(rowIndex); -// } -// - -// public class HashDataLinkRenderer extends JLabel -// implements TableCellRenderer { -//// extends DefaultTableCellRenderer { -// -//// protected ActionListener saveHashDataListener; -//// -//// public HashDataLinkRenderer(ActionListener saveHashDataListener) { -//// this.saveHashDataListener = saveHashDataListener; -//// } -// -// @Override -// public Component getTableCellRendererComponent(JTable table, -// Object value, -// boolean isSelected, -// boolean hasFocus, -// final int row, -// int column) { -// final HashDataInput hdi = (HashDataInput) value; -// log.debug("render hashdatainput " + hdi.getReferenceId() + " - (" + row + "," + column + ") " + isSelected + hasFocus); -// setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); -// setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD)); -// setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); -// addMouseListener(new MouseAdapter() { -// -// @Override -// public void mouseClicked(MouseEvent e) { -// log.debug("received mouseclick on " + hdi.getReferenceId()); -//// saveHashDataListener.actionPerformed(); -// JOptionPane.showInputDialog(hashDataInputs.get(row).getReferenceId()); -// } -// -// }); -// -// return this; -// } -// } } \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java index 263c3c04..777e8960 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java @@ -184,7 +184,6 @@ public class HashDataViewer extends JDialog JEditorPane viewer = new JEditorPane(); if ("text/plain".equals(mimeType)) { - //line wrapping, etc. viewer.setEditorKit(new StyledEditorKit()); viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); // } else if ("text/html".equals(mimeType)) { diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java new file mode 100644 index 00000000..f983706e --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java @@ -0,0 +1,38 @@ +/* + * 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 javax.swing.table.DefaultTableCellRenderer; + +/** + * + * @author Clemens Orthacker + */ +public class HyperlinkRenderer extends DefaultTableCellRenderer { + + /** + * cannot change mouse cursor here, do in jTable + * @param value + */ + @Override + protected void setValue(Object value) { + super.setText("" + ((HashDataInput) value).getReferenceId() + ""); + setForeground(BKUGUIFacade.HYPERLINK_COLOR); + } +} -- cgit v1.2.3 From b93f035e2c9df0ad430300c4f755b775a4aa1ed3 Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 24 Nov 2008 13:37:11 +0000 Subject: xhtml warning git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@192 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 3 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 15 +++-- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 72 +++++++++++----------- 3 files changed, 48 insertions(+), 42 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 7d912f11..d3cb76f2 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -62,11 +62,12 @@ public interface BKUGUIFacade { public static final String MESSAGE_INSERTCARD = "message.insertcard"; public static final String MESSAGE_ENTERPIN = "message.enterpin"; public static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; - public static final String MESSAGE_HASHDATA = "message.hashdata"; +// public static final String MESSAGE_HASHDATA = "message.hashdata"; public static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; public static final String MESSAGE_RETRIES = "message.retries"; public static final String MESSAGE_OVERWRITE = "message.overwrite"; public static final String MESSAGE_HELP = "message.help"; + public static final String WARNING_XHTML = "warning.xhtml"; public static final String LABEL_PIN = "label.pin"; public static final String LABEL_PINSIZE = "label.pinsize"; public static final String HELP_WELCOME = "help.welcome"; 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 a190b9c0..c786a291 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 @@ -208,13 +208,16 @@ public class BKUGUIImpl implements BKUGUIFacade { if (background == null) { background = getClass().getResource(DEFAULT_BACKGROUND); } - if ("file".equals(background.getProtocol())) { - log.warn("file:// background images not permitted: " + background); - background = getClass().getResource(DEFAULT_BACKGROUND); + if (background == null) { + contentPanel = new JPanel(); + } else { + if ("file".equals(background.getProtocol())) { + log.warn("file:// background images not permitted: " + background); + background = getClass().getResource(DEFAULT_BACKGROUND); + } + log.debug("loading background " + background); + contentPanel = new ImagePanel(background); } - log.debug("loading background " + background); - contentPanel = new ImagePanel(background); - mainPanel = new JPanel(); mainPanel.setOpaque(false); buttonPanel = new JPanel(); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java index 777e8960..6c097b2a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java @@ -125,9 +125,7 @@ public class HashDataViewer extends JDialog InputStreamReader isr = new InputStreamReader(hashDataInput.getHashDataInput(), cs); Reader content = new BufferedReader(isr); - JPanel hashDataPanel = createViewerPanel( - messages.getString(BKUGUIFacade.MESSAGE_HASHDATA), - content, + JPanel hashDataPanel = createViewerPanel(content, hashDataInput.getMimeType(), helpListener); JPanel buttonPanel = createButtonPanel(saveListener, saveCommand); @@ -169,29 +167,28 @@ public class HashDataViewer extends JDialog * @param helpListener may be null * @return */ - private JPanel createViewerPanel(String viewerLabelText, - Reader content, + private JPanel createViewerPanel(Reader content, String mimeType, final ActionListener helpListener) { - log.debug("viewer dialog: " + mimeType); if (mimeType == null) { mimeType = "text/plain"; - } else if ("application/xhtml+xml".equals(mimeType)) { - mimeType = "text/html"; } + log.debug("viewer dialog: " + mimeType); JEditorPane viewer = new JEditorPane(); + viewer.setEditable(false); + 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"); } - viewer.setEditable(false); - viewer.setContentType(mimeType); - + EditorKit editorKit = viewer.getEditorKit(); Document document = editorKit.createDefaultDocument(); // document.putProperty("IgnoreCharsetDirective", new Boolean(true)); @@ -210,15 +207,23 @@ public class HashDataViewer extends JDialog scrollPane.setAlignmentX(LEFT_ALIGNMENT); viewer.setCaretPosition(0); - JLabel viewerLabel = new JLabel(); - viewerLabel.setText(viewerLabelText); - viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); - viewerLabel.setLabelFor(viewer); - 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); + + if ("application/xhtml+xml".equals(mimeType)) { + JLabel viewerLabel = new JLabel(); + viewerLabel.setText(messages.getString(BKUGUIFacade.WARNING_XHTML)); + 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))); @@ -232,27 +237,24 @@ public class HashDataViewer extends JDialog } }); helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - viewerPanelLayout.setHorizontalGroup( - viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(viewerPanelLayout.createSequentialGroup().addComponent(viewerLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE).addComponent(helpLabel)).addComponent(scrollPane)); //, 0, 0, Short.MAX_VALUE)); - viewerPanelLayout.setVerticalGroup( - viewerPanelLayout.createSequentialGroup() - .addGroup(viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(viewerLabel) - .addComponent(helpLabel)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(scrollPane)); - } else { - viewerPanelLayout.setHorizontalGroup( - viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(viewerLabel) - .addComponent(scrollPane)); - viewerPanelLayout.setVerticalGroup( - viewerPanelLayout.createSequentialGroup() - .addComponent(viewerLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(scrollPane)); + 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; } -- cgit v1.2.3 From 959130f29903568c6b7fe3d6538b33887b3b1aaf Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 27 Nov 2008 15:22:32 +0000 Subject: help viewer label removed git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@221 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/gui/AbstractHelpListener.java | 5 ++- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 7 ++-- .../at/gv/egiz/bku/gui/DefaultHelpListener.java | 8 ++-- .../main/java/at/gv/egiz/bku/gui/HelpViewer.java | 43 ++++++++++++---------- 4 files changed, 34 insertions(+), 29 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java index f46f5227..b871263e 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -30,6 +30,9 @@ import org.apache.commons.logging.LogFactory; * This class does not keep a GUI reference and subclasses should not interfere with the GUI. * Therefore, any errors occurring in showDocument() should be handled/displayed within * showDocument() and exceptions thrown from showDocument() are logged, not displayed in the GUI. + *
+ * The help URL is build as [baseURL]/[locale]/[helpTopic].html + * (note that no session information is contained). * * @author Clemens Orthacker */ @@ -41,7 +44,7 @@ public abstract class AbstractHelpListener implements ActionListener { protected ResourceBundle messages; public AbstractHelpListener(URL baseURL, Locale locale) { - if (baseURL == null || "".equals(baseURL)) { + if (baseURL == null || "".equals(baseURL.toString())) { throw new RuntimeException("no help URL provided"); } this.baseURL = baseURL; 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 c786a291..d61c9a03 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 @@ -58,9 +58,6 @@ import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumn; -import javax.swing.table.TableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -117,7 +114,9 @@ public class BKUGUIImpl implements BKUGUIFacade { this.contentPane = contentPane; if (locale != null) { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); + Locale lang = new Locale(locale.getLanguage().substring(0,2)); + log.debug("loading applet resources for language: " + lang.toString()); + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, lang); } else { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java index 3c8c7d6c..c8594fe1 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java @@ -57,10 +57,10 @@ public class DefaultHelpListener extends AbstractHelpListener { /** * blocks until help viewer returns (is closed) * @param helpURL - * @param helpTopic + * @param helpTopic ignored */ @Override - public void showDocument(final URL helpURL, final String helpTopic) { + public void showDocument(final URL helpURL, final String helpTopic) { // try { log.debug("schedule help dialog"); @@ -72,9 +72,9 @@ public class DefaultHelpListener extends AbstractHelpListener { log.debug("show help dialog"); if (ctx == null) { - HelpViewer.showHelpDialog(helpURL, helpTopic, messages); + HelpViewer.showHelpDialog(helpURL, messages); // helpTopic, messages); } else { - HelpViewer.showHelpDialog(ctx, helpURL, helpTopic, messages); + HelpViewer.showHelpDialog(ctx, helpURL, messages); //helpTopic, messages); } } }); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java index 0fef3f75..364da6ec 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java @@ -32,7 +32,6 @@ import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JEditorPane; -import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -64,45 +63,44 @@ public class HelpViewer extends JDialog */ public static void showHelpDialog(AppletContext ctx, URL helpURL, - String helpTopic, +// String helpTopic, ResourceBundle messages) { - showHelpDialog(null, ctx, helpURL, helpTopic, messages); + showHelpDialog(null, ctx, helpURL, messages); //helpTopic, messages); } public static void showHelpDialog(URL helpURL, - String helpTopic, +// String helpTopic, ResourceBundle messages) { - showHelpDialog(null, null, helpURL, helpTopic, messages); + showHelpDialog(null, null, helpURL, messages); // helpTopic, messages); } public static void showHelpDialog(Component owner, AppletContext ctx, URL helpURL, - String helpTopic, +// String helpTopic, ResourceBundle messages) { Frame frame = null; if (owner != null) { JOptionPane.getFrameForComponent(owner); } - dialog = new HelpViewer(frame, messages, ctx, helpURL, helpTopic); + dialog = new HelpViewer(frame, messages, ctx, helpURL); //, helpTopic); dialog.setVisible(true); } private HelpViewer(Frame frame, ResourceBundle messages, AppletContext ctx, - URL helpURL, - String helpTopic) { + URL helpURL) { //, String helpTopic) { super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_HELP), true); this.messages = messages; this.ctx = ctx; - String p = messages.getString(BKUGUIFacade.MESSAGE_HELP); - String helpItem = messages.getString(helpTopic); - String viewerLabel = MessageFormat.format(p, new Object[]{helpItem}); +// String p = messages.getString(BKUGUIFacade.MESSAGE_HELP); +// String helpItem = messages.getString(helpTopic); +// String viewerLabel = MessageFormat.format(p, new Object[]{helpItem}); - JPanel helpPanel = createViewerPanel(viewerLabel, helpURL); + JPanel helpPanel = createViewerPanel(helpURL); //viewerLabel, helpURL); JPanel buttonPanel = createButtonPanel(); initContentPane(new Dimension(600, 600), helpPanel, buttonPanel); @@ -128,7 +126,7 @@ public class HelpViewer extends JDialog 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()); } - private JPanel createViewerPanel(String viewerLabelText, URL helpURL) { + private JPanel createViewerPanel(URL helpURL) { //String viewerLabelText, log.debug("viewer dialog: " + helpURL.toString()); final JEditorPane viewer = new JEditorPane(); @@ -170,19 +168,24 @@ public class HelpViewer extends JDialog scrollPane.setAlignmentX(LEFT_ALIGNMENT); viewer.setCaretPosition(0); - JLabel viewerLabel = new JLabel(); - viewerLabel.setText(viewerLabelText); - viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); - viewerLabel.setLabelFor(viewer); +// JLabel viewerLabel = new JLabel(); +// viewerLabel.setText(viewerLabelText); +// viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); +// viewerLabel.setLabelFor(viewer); JPanel viewerPanel = new JPanel(); GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); viewerPanel.setLayout(viewerPanelLayout); viewerPanelLayout.setHorizontalGroup( - viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(viewerLabel).addComponent(scrollPane)); + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(viewerLabel) + .addComponent(scrollPane)); viewerPanelLayout.setVerticalGroup( - viewerPanelLayout.createSequentialGroup().addComponent(viewerLabel).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(scrollPane)); + viewerPanelLayout.createSequentialGroup() +// .addComponent(viewerLabel) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(scrollPane)); return viewerPanel; } -- cgit v1.2.3 From 212bbffc24ccc1cd909cabdc9650491dd221cd60 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 22 Jan 2009 13:21:50 +0000 Subject: STALTranslator git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@283 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 1 + 1 file changed, 1 insertion(+) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index d3cb76f2..5ee0058f 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -37,6 +37,7 @@ public interface BKUGUIFacade { public static final String ERR_CARD_NOTACTIVATED = "error.card.notactivated"; public static final String ERR_VIEWER = "error.viewer"; public static final String ERR_EXTERNAL_LINK = "error.external.link"; + public static final String ERR_CONFIG = "error.config"; public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; public static final String DEFAULT_BACKGROUND = "/images/BackgroundChipperling.png"; -- cgit v1.2.3 From 9ef5d25ffec1c26ccf76ad46131e33a861335da1 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 23 Jan 2009 13:45:39 +0000 Subject: tiny applet git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@286 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 4 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 140 ++++++++++++++++----- .../at/gv/egiz/bku/gui/HashDataTableModel.java | 21 +++- .../java/at/gv/egiz/bku/gui/HyperlinkRenderer.java | 14 ++- 4 files changed, 137 insertions(+), 42 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 5ee0058f..51906616 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -63,9 +63,11 @@ public interface BKUGUIFacade { public static final String MESSAGE_INSERTCARD = "message.insertcard"; public static final String MESSAGE_ENTERPIN = "message.enterpin"; public static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; + public static final String MESSAGE_HASHDATALINK_TINY = "message.hashdatalink.tiny"; // public static final String MESSAGE_HASHDATA = "message.hashdata"; public static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; public static final String MESSAGE_RETRIES = "message.retries"; + public static final String MESSAGE_LAST_RETRY = "message.retries.last"; public static final String MESSAGE_OVERWRITE = "message.overwrite"; public static final String MESSAGE_HELP = "message.help"; public static final String WARNING_XHTML = "warning.xhtml"; @@ -90,7 +92,7 @@ public interface BKUGUIFacade { public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; public static final String ALT_HELP = "alt.help"; - public enum Style { simple, advanced }; + public enum Style { tiny, simple, advanced }; // public void init(Container contentPane, Locale locale, Style guiStyle, URL background, ActionListener helpListener); 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 d61c9a03..1e63c8d7 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 @@ -53,6 +53,7 @@ import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.JTextField; import javax.swing.LayoutStyle; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; @@ -69,6 +70,10 @@ public class BKUGUIImpl implements BKUGUIFacade { private static final Log log = LogFactory.getLog(BKUGUIImpl.class); + protected enum PinLabelPosition { + LEFT, ABOVE + } + protected HelpMouseListener helpListener; protected Container contentPane; @@ -92,6 +97,9 @@ public class BKUGUIImpl implements BKUGUIFacade { protected boolean renderHeaderPanel = false; protected boolean renderIconPanel = false; protected boolean renderCancelButton = false; + protected boolean shortText = false; + protected PinLabelPosition pinLabelPos = PinLabelPosition.LEFT; + protected boolean renderRefId = false; /** * set contentPane @@ -125,6 +133,10 @@ public class BKUGUIImpl implements BKUGUIFacade { renderHeaderPanel = true; renderIconPanel = false; renderCancelButton = true; + renderRefId = true; + } else if (guiStyle == Style.tiny) { + shortText = true; + pinLabelPos = PinLabelPosition.ABOVE; } registerHelpListener(helpListener); @@ -537,11 +549,21 @@ public class BKUGUIImpl implements BKUGUIFacade { if (numRetries < 0) { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String infoPattern = messages.getString(MESSAGE_ENTERPIN); - infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); + if (shortText) { + infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {"PIN"})); + } else { + infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); + } helpListener.setHelpTopic(HELP_CARDPIN); } else { + String retryPattern; + if (numRetries < 2) { + retryPattern = messages.getString(MESSAGE_LAST_RETRY); + } else { + retryPattern = messages.getString(MESSAGE_RETRIES); + } infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); + infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); helpListener.setHelpTopic(HELP_RETRY); } @@ -570,27 +592,47 @@ public class BKUGUIImpl implements BKUGUIFacade { infoVertical .addComponent(helpLabel); } - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(infoHorizontal) + + GroupLayout.Group pinHorizontal; + GroupLayout.Group pinVertical; + + if (pinLabelPos == PinLabelPosition.ABOVE) { + pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) - .addComponent(pinsizeLabel)))); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); + pinVertical = mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(cardPinLabel) - .addComponent(pinField)) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + } else { + pinHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); - - + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(pinsizeLabel)); + pinVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cardPinLabel) + .addComponent(pinField); + } + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(infoHorizontal) + .addGroup(pinHorizontal)); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(pinVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel)); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -707,7 +749,11 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel infoLabel = new JLabel(); if (numRetries < 0) { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); + if (shortText) { + infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK_TINY)); + } else { + infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); + } infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); infoLabel.setForeground(HYPERLINK_COLOR); infoLabel.addMouseListener(new MouseAdapter() { @@ -720,8 +766,14 @@ public class BKUGUIImpl implements BKUGUIFacade { }); helpListener.setHelpTopic(HELP_SIGNPIN); } else { + String retryPattern; + if (numRetries < 2) { + retryPattern = messages.getString(MESSAGE_LAST_RETRY); + } else { + retryPattern = messages.getString(MESSAGE_RETRIES); + } + infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); helpListener.setHelpTopic(HELP_RETRY); } @@ -737,28 +789,48 @@ public class BKUGUIImpl implements BKUGUIFacade { if (!renderHeaderPanel) { infoHorizontal .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + .addComponent(helpLabel); infoVertical .addComponent(helpLabel); } + GroupLayout.Group pinHorizontal; + GroupLayout.Group pinVertical; + + if (pinLabelPos == PinLabelPosition.ABOVE) { + pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(mainPanelLayout.createSequentialGroup() + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); + + pinVertical = mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + } else { + pinHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(pinsizeLabel)); + pinVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signPinLabel) + .addComponent(pinField); + } + mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(infoHorizontal) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pinsizeLabel)))); + .addGroup(pinHorizontal)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() .addGroup(infoVertical) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(signPinLabel) - .addComponent(pinField)) + .addGroup(pinVertical) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(pinsizeLabel)); @@ -1084,9 +1156,9 @@ public class BKUGUIImpl implements BKUGUIFacade { String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.size()})); - HashDataTableModel tableModel = new HashDataTableModel(signedReferences); + HashDataTableModel tableModel = new HashDataTableModel(signedReferences, renderRefId); final JTable hashDataTable = new JTable(tableModel); - hashDataTable.setDefaultRenderer(HashDataInput.class, new HyperlinkRenderer()); + hashDataTable.setDefaultRenderer(HashDataInput.class, new HyperlinkRenderer(renderRefId)); hashDataTable.setTableHeader(null); // not possible to add mouse listener to TableCellRenderer diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java index b0f51a78..70842102 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java @@ -31,14 +31,23 @@ class HashDataTableModel extends DefaultTableModel { protected static final Log log = LogFactory.getLog(HashDataTableModel.class); /** HashDataInput in first column, register hyperlinkrenderer only here */ - protected Class[] types = new Class[]{ HashDataInput.class, String.class }; + protected Class[] types; protected List hashDataInputs; - - public HashDataTableModel(List hashDataInputs) { - super(0, 2); + + public HashDataTableModel(List hashDataInputs, boolean twoColLayout) { + super(0, (twoColLayout) ? 2 : 1); this.hashDataInputs = hashDataInputs; - for (HashDataInput hdi : hashDataInputs) { - addRow(new Object[]{ hdi, hdi.getMimeType()}); + + if (twoColLayout) { + types = new Class[] { HashDataInput.class, String.class }; + for (HashDataInput hdi : hashDataInputs) { + addRow(new Object[] { hdi, hdi.getMimeType() }); + } + } else { + types = new Class[] { HashDataInput.class }; + for (HashDataInput hdi : hashDataInputs) { + addRow(new Object[] { hdi }); + } } } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java index f983706e..16024fcc 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java @@ -26,13 +26,25 @@ import javax.swing.table.DefaultTableCellRenderer; */ public class HyperlinkRenderer extends DefaultTableCellRenderer { + protected boolean renderReferenceId; + + public HyperlinkRenderer(boolean renderReferenceId) { + this.renderReferenceId = renderReferenceId; + } + /** * cannot change mouse cursor here, do in jTable * @param value */ @Override protected void setValue(Object value) { - super.setText("" + ((HashDataInput) value).getReferenceId() + ""); + String hrefText; + if (renderReferenceId) { + hrefText = ((HashDataInput) value).getReferenceId(); + } else { + hrefText = ((HashDataInput) value).getMimeType(); + } + super.setText("" + hrefText + ""); setForeground(BKUGUIFacade.HYPERLINK_COLOR); } } -- cgit v1.2.3 From ff9a71fe2a2beb94ad7aa52ba2c77a24dd39509e Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 11 Feb 2009 20:04:58 +0000 Subject: removed BKUGUIFactory git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@297 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 1 + .../java/at/gv/egiz/bku/gui/BKUGUIFactory.java | 34 ---------------------- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 4 +-- 3 files changed, 2 insertions(+), 37 deletions(-) delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 51906616..6fd29ba9 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -25,6 +25,7 @@ import java.util.Locale; public interface BKUGUIFacade { + public static final String ERR_UNKNOWN_WITH_PARAM = "error.unknown.param"; public static final String ERR_UNKNOWN = "error.unknown"; public static final String ERR_SERVICE_UNREACHABLE = "error.ws.unreachable"; public static final String ERR_NO_PCSC = "error.pcsc"; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java deleted file mode 100644 index 998aaa86..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* -* 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.Container; -import java.awt.event.ActionListener; -import java.net.URL; -import java.util.Locale; - -public class BKUGUIFactory { - - public static BKUGUIFacade createGUI(Container contentPane, - Locale locale, - BKUGUIFacade.Style style, - URL background, - ActionListener helpListener) { - return new BKUGUIImpl(contentPane, locale, style, background, helpListener); - } -} 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 1e63c8d7..f564c07a 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 @@ -19,14 +19,12 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; -import at.gv.egiz.stal.impl.ByteArrayHashDataInput; import java.awt.Container; import java.awt.Cursor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.awt.event.MouseMotionAdapter; import java.io.BufferedOutputStream; import java.io.File; @@ -68,7 +66,7 @@ import org.apache.commons.logging.LogFactory; */ public class BKUGUIImpl implements BKUGUIFacade { - private static final Log log = LogFactory.getLog(BKUGUIImpl.class); + protected static final Log log = LogFactory.getLog(BKUGUIImpl.class); protected enum PinLabelPosition { LEFT, ABOVE -- cgit v1.2.3 From 6576428966f1e3d688269a407b072fb01f9f7647 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 26 Feb 2009 19:39:00 +0000 Subject: 1.1 candidate (activation) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@309 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 8 +++---- .../main/java/at/gv/egiz/bku/gui/PinDocument.java | 28 ++++++++++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 f564c07a..1d5a2cf4 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 @@ -38,9 +38,6 @@ import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.CellRendererPane; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -51,7 +48,6 @@ import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JScrollPane; import javax.swing.JTable; -import javax.swing.JTextField; import javax.swing.LayoutStyle; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; @@ -1064,7 +1060,9 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public char[] getPin() { if (pinField != null) { - return pinField.getPassword(); + char[] pin = pinField.getPassword(); + pinField = null; + return pin; } return null; } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java index 2054ae86..87b636f0 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java @@ -22,6 +22,7 @@ import java.util.regex.Pattern; import javax.swing.JButton; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; +import javax.swing.text.Document; import javax.swing.text.PlainDocument; /** @@ -30,9 +31,10 @@ import javax.swing.text.PlainDocument; */ class PINDocument extends PlainDocument { - private PINSpec pinSpec; - private Pattern pinPattern; - private JButton enterButton; + protected PINSpec pinSpec; + protected Pattern pinPattern; + protected JButton enterButton; + protected Document compareTo; public PINDocument(PINSpec pinSpec, JButton enterButton) { this.pinSpec = pinSpec; @@ -44,6 +46,11 @@ class PINDocument extends PlainDocument { this.enterButton = enterButton; } + public PINDocument(PINSpec pinSpec, JButton enterButton, Document compareTo) { + this(pinSpec, enterButton); + this.compareTo = compareTo; + } + @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if (pinSpec.getMaxLength() < 0 || pinSpec.getMaxLength() >= (getLength() + str.length())) { @@ -58,12 +65,23 @@ class PINDocument extends PlainDocument { super.insertString(offs, str, a); } } - enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); + if (enterButton != null) { + enterButton.setEnabled(getLength() >= pinSpec.getMinLength() && compare()); + } } @Override public void remove(int offs, int len) throws BadLocationException { super.remove(offs, len); - enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); + if (enterButton != null) { + enterButton.setEnabled(getLength() >= pinSpec.getMinLength() && compare()); + } + } + + private boolean compare() throws BadLocationException { + if (compareTo == null) { + return true; + } + return compareTo.getText(0, compareTo.getLength()).equals(getText(0, getLength())); } } \ No newline at end of file -- cgit v1.2.3 From 4387153c6f65b55d576e1890c5b582237227369e Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 27 Feb 2009 18:10:57 +0000 Subject: 1.1-rc2 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@310 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 4 + .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 198 ++++++++++++--------- 2 files changed, 119 insertions(+), 83 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 6fd29ba9..ae91670a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -97,6 +97,10 @@ public interface BKUGUIFacade { // public void init(Container contentPane, Locale locale, Style guiStyle, URL background, ActionListener helpListener); + /** + * BKUWorker needs to init signature card with locale + * @return + */ public Locale getLocale(); public void showWelcomeDialog(); 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 1d5a2cf4..ca597701 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 @@ -115,13 +115,7 @@ public class BKUGUIImpl implements BKUGUIFacade { ActionListener helpListener) { this.contentPane = contentPane; - if (locale != null) { - Locale lang = new Locale(locale.getLanguage().substring(0,2)); - log.debug("loading applet resources for language: " + lang.toString()); - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, lang); - } else { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); - } + loadMessageBundle(locale); if (guiStyle == Style.advanced) { renderHeaderPanel = true; @@ -230,11 +224,11 @@ public class BKUGUIImpl implements BKUGUIFacade { helpLabel = new JLabel(); helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); - helpLabel.getAccessibleContext().setAccessibleName(messages.getString(ALT_HELP)); + helpLabel.getAccessibleContext().setAccessibleName(getMessage(ALT_HELP)); helpLabel.addMouseListener(helpListener); helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - buttonSize = initButtonSize(messages, renderCancelButton); + buttonSize = initButtonSize(); if (renderHeaderPanel) { headerPanel = new JPanel(); @@ -292,11 +286,33 @@ public class BKUGUIImpl implements BKUGUIFacade { contentPanelLayout.setVerticalGroup(verticalContent); } + /** + * BKUWorker inits signaturecard with locale + * @return + */ @Override public Locale getLocale() { return messages.getLocale(); } + /** + * to be overridden by subclasses providing additional resource messages + * @param key + * @return + */ + protected String getMessage(String key) { + return messages.getString(key); + } + + /** + * to be overridden by subclasses providing additional resource messages + * @param key + * @return + */ + protected boolean hasMessage(String key) { + return messages.containsKey(key); + } + @Override public void showWelcomeDialog() { @@ -318,10 +334,10 @@ public class BKUGUIImpl implements BKUGUIFacade { welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_WELCOME)); - welcomeMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + titleLabel.setText(getMessage(TITLE_WELCOME)); + welcomeMsgLabel.setText(getMessage(MESSAGE_WAIT)); } else { - welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); + welcomeMsgLabel.setText(getMessage(TITLE_WELCOME)); } GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -364,14 +380,14 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanel.removeAll(); if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + titleLabel.setText(getMessage(TITLE_INSERTCARD)); } helpListener.setHelpTopic(HELP_INSERTCARD); JLabel insertCardMsgLabel = new JLabel(); insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -395,7 +411,7 @@ public class BKUGUIImpl implements BKUGUIFacade { if (renderCancelButton) { JButton cancelButton = new JButton(); cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setText(getMessage(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); @@ -440,10 +456,10 @@ public class BKUGUIImpl implements BKUGUIFacade { insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); - insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + titleLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); + insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); } else { - insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + insertCardMsgLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); } helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); @@ -469,7 +485,7 @@ public class BKUGUIImpl implements BKUGUIFacade { if (renderCancelButton) { JButton cancelButton = new JButton(); cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setText(getMessage(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); @@ -506,23 +522,23 @@ public class BKUGUIImpl implements BKUGUIFacade { if (renderHeaderPanel) { if (numRetries < 0) { - String cardpinTitle = messages.getString(TITLE_CARDPIN); + String cardpinTitle = getMessage(TITLE_CARDPIN); titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); } else { - titleLabel.setText(messages.getString(TITLE_RETRY)); + titleLabel.setText(getMessage(TITLE_RETRY)); } } JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - okButton.setText(messages.getString(BUTTON_OK)); + okButton.setText(getMessage(BUTTON_OK)); okButton.setEnabled(false); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); JLabel cardPinLabel = new JLabel(); cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String pinLabel = messages.getString(LABEL_PIN); + String pinLabel = getMessage(LABEL_PIN); cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); pinField = new JPasswordField(); @@ -542,7 +558,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel infoLabel = new JLabel(); if (numRetries < 0) { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String infoPattern = messages.getString(MESSAGE_ENTERPIN); + String infoPattern = getMessage(MESSAGE_ENTERPIN); if (shortText) { infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {"PIN"})); } else { @@ -552,9 +568,9 @@ public class BKUGUIImpl implements BKUGUIFacade { } else { String retryPattern; if (numRetries < 2) { - retryPattern = messages.getString(MESSAGE_LAST_RETRY); + retryPattern = getMessage(MESSAGE_LAST_RETRY); } else { - retryPattern = messages.getString(MESSAGE_RETRIES); + retryPattern = getMessage(MESSAGE_RETRIES); } infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); @@ -564,7 +580,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel pinsizeLabel = new JLabel(); pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); - String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinsizePattern = getMessage(LABEL_PINSIZE); String pinSize = String.valueOf(pinSpec.getMinLength()); if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { pinSize += "-" + pinSpec.getMaxLength(); @@ -638,7 +654,7 @@ public class BKUGUIImpl implements BKUGUIFacade { if (renderCancelButton) { JButton cancelButton = new JButton(); cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setText(getMessage(BUTTON_CANCEL)); cancelButton.setActionCommand(cancelCommand); cancelButton.addActionListener(cancelListener); @@ -699,22 +715,22 @@ public class BKUGUIImpl implements BKUGUIFacade { if (renderHeaderPanel) { if (numRetries < 0) { - titleLabel.setText(messages.getString(TITLE_SIGN)); + titleLabel.setText(getMessage(TITLE_SIGN)); } else { - titleLabel.setText(messages.getString(TITLE_RETRY)); + titleLabel.setText(getMessage(TITLE_RETRY)); } } JButton signButton = new JButton(); signButton.setFont(signButton.getFont().deriveFont(signButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - signButton.setText(messages.getString(BUTTON_SIGN)); + signButton.setText(getMessage(BUTTON_SIGN)); signButton.setEnabled(false); signButton.setActionCommand(signCommand); signButton.addActionListener(signListener); JLabel signPinLabel = new JLabel(); signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String pinLabel = messages.getString(LABEL_PIN); + String pinLabel = getMessage(LABEL_PIN); signPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); pinField = new JPasswordField(); @@ -733,7 +749,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel pinsizeLabel = new JLabel(); pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); - String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinsizePattern = getMessage(LABEL_PINSIZE); String pinSize = String.valueOf(pinSpec.getMinLength()); if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { pinSize += "-" + pinSpec.getMaxLength(); @@ -744,9 +760,9 @@ public class BKUGUIImpl implements BKUGUIFacade { if (numRetries < 0) { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); if (shortText) { - infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK_TINY)); + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); } else { - infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); } infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); infoLabel.setForeground(HYPERLINK_COLOR); @@ -762,9 +778,9 @@ public class BKUGUIImpl implements BKUGUIFacade { } else { String retryPattern; if (numRetries < 2) { - retryPattern = messages.getString(MESSAGE_LAST_RETRY); + retryPattern = getMessage(MESSAGE_LAST_RETRY); } else { - retryPattern = messages.getString(MESSAGE_RETRIES); + retryPattern = getMessage(MESSAGE_RETRIES); } infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); @@ -839,7 +855,7 @@ public class BKUGUIImpl implements BKUGUIFacade { if (renderCancelButton) { JButton cancelButton = new JButton(); cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setText(getMessage(BUTTON_CANCEL)); cancelButton.setActionCommand(cancelCommand); cancelButton.addActionListener(cancelListener); @@ -881,12 +897,12 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanel.removeAll(); if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_ERROR)); + titleLabel.setText(getMessage(TITLE_ERROR)); } helpListener.setHelpTopic(errorMsgKey); - String errorMsgPattern = messages.getString(errorMsgKey); + String errorMsgPattern = getMessage(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); JLabel errorMsgLabel = new JLabel(); @@ -902,7 +918,7 @@ public class BKUGUIImpl implements BKUGUIFacade { if (!renderHeaderPanel) { JLabel errorTitleLabel = new JLabel(); errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); - errorTitleLabel.setText(messages.getString(TITLE_ERROR)); + errorTitleLabel.setText(getMessage(TITLE_ERROR)); errorTitleLabel.setForeground(ERROR_COLOR); mainHorizontal @@ -923,7 +939,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - okButton.setText(messages.getString(BUTTON_OK)); + okButton.setText(getMessage(BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -959,12 +975,12 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanel.removeAll(); if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_ERROR)); + titleLabel.setText(getMessage(TITLE_ERROR)); } helpListener.setHelpTopic(errorMsgKey); - String errorMsgPattern = messages.getString(errorMsgKey); + String errorMsgPattern = getMessage(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); JLabel errorMsgLabel = new JLabel(); @@ -981,7 +997,7 @@ public class BKUGUIImpl implements BKUGUIFacade { if (!renderHeaderPanel) { JLabel errorTitleLabel = new JLabel(); errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); - errorTitleLabel.setText(messages.getString(TITLE_ERROR)); + errorTitleLabel.setText(getMessage(TITLE_ERROR)); errorTitleLabel.setForeground(ERROR_COLOR); mainHorizontal @@ -1021,7 +1037,7 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanel.removeAll(); if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_WAIT)); + titleLabel.setText(getMessage(TITLE_WAIT)); } helpListener.setHelpTopic(HELP_WAIT); @@ -1031,7 +1047,7 @@ public class BKUGUIImpl implements BKUGUIFacade { if (waitMessage != null) { waitMsgLabel.setText("" + waitMessage + ""); } else { - waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + waitMsgLabel.setText(getMessage(MESSAGE_WAIT)); } GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -1079,7 +1095,7 @@ public class BKUGUIImpl implements BKUGUIFacade { final String okCommand) { if (signedReferences == null) { - showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); + showErrorDialog(getMessage(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); return; } @@ -1142,14 +1158,14 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanel.removeAll(); if (renderHeaderPanel) { - titleLabel.setText(messages.getString(TITLE_HASHDATA)); + titleLabel.setText(getMessage(TITLE_HASHDATA)); } helpListener.setHelpTopic(HELP_HASHDATALIST); JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); + String refIdLabelPattern = getMessage(MESSAGE_HASHDATALIST); refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.size()})); HashDataTableModel tableModel = new HashDataTableModel(signedReferences, renderRefId); @@ -1229,7 +1245,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JButton backButton = new JButton(); backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - backButton.setText(messages.getString(BUTTON_BACK)); + backButton.setText(getMessage(BUTTON_BACK)); backButton.setActionCommand(backCommand); backButton.addActionListener(backListener); @@ -1271,15 +1287,15 @@ public class BKUGUIImpl implements BKUGUIFacade { fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); fileDialog.setFileHidingEnabled(true); if (signedRefs.size() == 1) { - fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); + fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVE)); fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); String mimeType = signedRefs.get(0).getMimeType(); MimeFilter mimeFilter = new MimeFilter(mimeType, messages); fileDialog.setFileFilter(mimeFilter); - String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); + String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); fileDialog.setSelectedFile(new File(userHome, filename)); } else { - fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVEDIR)); + fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVEDIR)); fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } @@ -1292,14 +1308,14 @@ public class BKUGUIImpl implements BKUGUIFacade { String id = hashDataInput.getReferenceId(); File file; if (f.isDirectory()) { - String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); + String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); file = new File(f, filename); } else { file = f; } if (file.exists()) { - String ovrwrt = messages.getString(MESSAGE_OVERWRITE); - int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), messages.getString(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); + String ovrwrt = getMessage(MESSAGE_OVERWRITE); + int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), getMessage(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); if (overwrite != JOptionPane.OK_OPTION) { continue; } @@ -1352,34 +1368,50 @@ public class BKUGUIImpl implements BKUGUIFacade { }); } } - - private static int initButtonSize(ResourceBundle messages, boolean renderCancelButton) { - int buttonSize = 0; - - JButton b = new JButton(); - b.setText(messages.getString(BUTTON_OK)); - if (b.getPreferredSize().width > buttonSize) { - buttonSize = b.getPreferredSize().width; - } - b.setText(messages.getString(BUTTON_SIGN)); - if (b.getPreferredSize().width > buttonSize) { - buttonSize = b.getPreferredSize().width; - } - b.setText(messages.getString(BUTTON_BACK)); - if (b.getPreferredSize().width > buttonSize) { - buttonSize = b.getPreferredSize().width; - } - b.setText(messages.getString(BUTTON_SAVE)); - if (b.getPreferredSize().width > buttonSize) { - buttonSize = b.getPreferredSize().width; + /** + * Called from constructor. + * Subclasses may override this method to ensure the message bundle is loaded + * once initButtonSize (called from constructor as well) is called. + * (Only relevant if initButtonSize is overridden as well) + * @param locale + */ + protected void loadMessageBundle(Locale locale) { + if (locale != null) { + Locale lang = new Locale(locale.getLanguage().substring(0, 2)); + log.debug("loading applet resources for language: " + lang.toString()); + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, lang); + } else { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); + } } - if (renderCancelButton) { - b.setText(messages.getString(BUTTON_CANCEL)); - if (b.getPreferredSize().width > buttonSize) { - buttonSize = b.getPreferredSize().width; + + protected int initButtonSize() { + int bs = 0; + + JButton b = new JButton(); + b.setText(getMessage(BUTTON_OK)); + if (b.getPreferredSize().width > bs) { + bs = b.getPreferredSize().width; + } + b.setText(getMessage(BUTTON_SIGN)); + if (b.getPreferredSize().width > bs) { + bs = b.getPreferredSize().width; + } + b.setText(getMessage(BUTTON_BACK)); + if (b.getPreferredSize().width > bs) { + bs = b.getPreferredSize().width; + } + b.setText(getMessage(BUTTON_SAVE)); + if (b.getPreferredSize().width > bs) { + bs = b.getPreferredSize().width; + } + if (renderCancelButton) { + b.setText(getMessage(BUTTON_CANCEL)); + if (b.getPreferredSize().width > bs) { + bs = b.getPreferredSize().width; + } } + return bs; } - return buttonSize; - } } -- cgit v1.2.3 From a8690cc956924e1d83b0c45d21995ee2e10fbba2 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 4 Mar 2009 16:44:34 +0000 Subject: 1.1-rc3 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@311 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 4 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 177 +++++++++------------ 2 files changed, 78 insertions(+), 103 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index ae91670a..be5e3fc8 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -127,7 +127,9 @@ public interface BKUGUIFacade { public void showHashDataInputDialog(List signedReferences, ActionListener okListener, String okCommand); - public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String actionCommand); + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String okCommand); public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams); + + public void showMessageDialog(String titleKey, String msgKey, Object[] msgParams, ActionListener okListener, String okCommand); } 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 ca597701..d6c96627 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 @@ -19,8 +19,10 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; +import java.awt.Color; import java.awt.Container; import java.awt.Cursor; +import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -882,145 +884,116 @@ public class BKUGUIImpl implements BKUGUIFacade { } @Override - public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams, final ActionListener okListener, final String okCommand) { + public void showErrorDialog( + final String errorMsgKey, final Object[] errorMsgParams, + final ActionListener okListener, final String okCommand) { - log.debug("scheduling error dialog"); - + showMessageDialog(TITLE_ERROR, ERROR_COLOR, + errorMsgKey, errorMsgParams, okListener, okCommand); + } + + @Override + public void showErrorDialog( + final String errorMsgKey, final Object[] errorMsgParams) { + + showMessageDialog(TITLE_ERROR, ERROR_COLOR, + errorMsgKey, errorMsgParams, null, null); + } + + @Override + public void showMessageDialog( + final String titleKey, + final String msgKey, final Object[] msgParams, + final ActionListener okListener, final String okCommand) { + + showMessageDialog(titleKey, null, + msgKey, msgParams, okListener, okCommand); + } + + private void showMessageDialog( + final String titleKey, final Color titleColor, + final String msgKey, final Object[] msgParams, + final ActionListener okListener, final String okCommand) { + + log.debug("scheduling message dialog"); + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - log.debug("show error dialog"); - + log.debug("show message dialog"); + mainPanel.removeAll(); buttonPanel.removeAll(); if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_ERROR)); + titleLabel.setText(getMessage(titleKey)); } - helpListener.setHelpTopic(errorMsgKey); - - String errorMsgPattern = getMessage(errorMsgKey); - String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); - - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(errorMsg); + helpListener.setHelpTopic(msgKey); + + String msgPattern = getMessage(msgKey); + String msg = MessageFormat.format(msgPattern, msgParams); + + JLabel msgLabel = new JLabel(); + msgLabel.setFont(msgLabel.getFont().deriveFont(msgLabel.getFont().getStyle() & ~Font.BOLD)); + msgLabel.setText(msg); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); - + if (!renderHeaderPanel) { - JLabel errorTitleLabel = new JLabel(); - errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); - errorTitleLabel.setText(getMessage(TITLE_ERROR)); - errorTitleLabel.setForeground(ERROR_COLOR); - + JLabel titleLabel = new JLabel(); + titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | Font.BOLD)); + titleLabel.setText(getMessage(titleKey)); + if (titleColor != null) { + titleLabel.setForeground(titleColor); + } + mainHorizontal .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(errorTitleLabel) + .addComponent(titleLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) .addComponent(helpLabel)); mainVertical .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorTitleLabel) + .addComponent(titleLabel) .addComponent(helpLabel)); } - + mainPanelLayout.setHorizontalGroup(mainHorizontal - .addComponent(errorMsgLabel)); + .addComponent(msgLabel)); mainPanelLayout.setVerticalGroup(mainVertical - .addComponent(errorMsgLabel)); - - JButton okButton = new JButton(); - okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - okButton.setText(getMessage(BUTTON_OK)); - okButton.setActionCommand(okCommand); - okButton.addActionListener(okListener); + .addComponent(msgLabel)); - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); + if (okListener != null && okCommand != null) { + JButton okButton = new JButton(); + okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + okButton.setText(getMessage(BUTTON_OK)); + okButton.setActionCommand(okCommand); + okButton.addActionListener(okListener); - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(okButton)); + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(okButton)); + } contentPanel.validate(); } }); } - @Override - public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams) { - - log.debug("scheduling error dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show error dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_ERROR)); - } - - helpListener.setHelpTopic(errorMsgKey); - - String errorMsgPattern = getMessage(errorMsgKey); - String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); - - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(errorMsg); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - - GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); - GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); - - if (!renderHeaderPanel) { - JLabel errorTitleLabel = new JLabel(); - errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); - errorTitleLabel.setText(getMessage(TITLE_ERROR)); - errorTitleLabel.setForeground(ERROR_COLOR); - - mainHorizontal - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(errorTitleLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainVertical - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorTitleLabel) - .addComponent(helpLabel)); - } - - mainPanelLayout.setHorizontalGroup(mainHorizontal - .addComponent(errorMsgLabel)); - mainPanelLayout.setVerticalGroup(mainVertical - .addComponent(errorMsgLabel)); - - contentPanel.validate(); - } - }); - } - @Override public void showWaitDialog(final String waitMessage) { -- cgit v1.2.3 From d20bfd8b45e0a83773a12a649aa7ba0aaf58e649 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 10 Mar 2009 10:37:45 +0000 Subject: bug: showMessageDialog(key, param, listener, null) does not display OK button git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@315 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 d6c96627..6a1f2aad 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 @@ -970,7 +970,7 @@ public class BKUGUIImpl implements BKUGUIFacade { mainPanelLayout.setVerticalGroup(mainVertical .addComponent(msgLabel)); - if (okListener != null && okCommand != null) { + if (okListener != null) { JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); okButton.setText(getMessage(BUTTON_OK)); -- cgit v1.2.3 From b1c0b243cc7f24f4a2ede6d02bdead4032451f41 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 10 Mar 2009 11:10:27 +0000 Subject: pinfield and pinsize label aligned trailing git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@316 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 53 +++++++++++----------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 6a1f2aad..76b1d795 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 @@ -605,27 +605,27 @@ public class BKUGUIImpl implements BKUGUIFacade { .addComponent(helpLabel); } - GroupLayout.Group pinHorizontal; + // align pinfield and pinsize to the right + GroupLayout.ParallelGroup pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING); GroupLayout.Group pinVertical; if (pinLabelPos == PinLabelPosition.ABOVE) { - pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(mainPanelLayout.createSequentialGroup() - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); + pinHorizontal + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); pinVertical = mainPanelLayout.createSequentialGroup() .addComponent(cardPinLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); } else { - pinHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pinsizeLabel)); + pinHorizontal + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); pinVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(cardPinLabel) .addComponent(pinField); @@ -806,28 +806,27 @@ public class BKUGUIImpl implements BKUGUIFacade { .addComponent(helpLabel); } - GroupLayout.Group pinHorizontal; + // align pinfield and pinsize to the right + GroupLayout.ParallelGroup pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING); GroupLayout.Group pinVertical; if (pinLabelPos == PinLabelPosition.ABOVE) { - pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(mainPanelLayout.createSequentialGroup() - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); - + pinHorizontal + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); pinVertical = mainPanelLayout.createSequentialGroup() .addComponent(signPinLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); } else { - pinHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pinsizeLabel)); + pinHorizontal + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); pinVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(signPinLabel) .addComponent(pinField); -- cgit v1.2.3 From 2a1df5e58e44f8d77f34eb80df74e8c0d27caceb Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 18 Mar 2009 22:27:28 +0000 Subject: 1.1-rc5 (pinProviderFactories, gui refactoring, signatureCard, secureViewer) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@322 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 66 ++- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 560 +++++++++++---------- .../main/java/at/gv/egiz/bku/gui/PinDocument.java | 30 +- 3 files changed, 367 insertions(+), 289 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index be5e3fc8..1043b6a1 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -36,6 +36,7 @@ public interface BKUGUIFacade { public static final String ERR_INVALID_HASH = "error.invalid.hash"; public static final String ERR_CARD_LOCKED = "error.card.locked"; public static final String ERR_CARD_NOTACTIVATED = "error.card.notactivated"; + public static final String ERR_PIN_TIMEOUT = "error.pin.timeout"; public static final String ERR_VIEWER = "error.viewer"; public static final String ERR_EXTERNAL_LINK = "error.external.link"; public static final String ERR_CONFIG = "error.config"; @@ -52,6 +53,7 @@ public interface BKUGUIFacade { public static final String TITLE_CARDPIN = "title.cardpin"; public static final String TITLE_SIGN = "title.sign"; public static final String TITLE_ERROR = "title.error"; + public static final String TITLE_ENTRY_TIMEOUT = "title.entry.timeout"; public static final String TITLE_RETRY = "title.retry"; public static final String TITLE_WAIT = "title.wait"; public static final String TITLE_HASHDATA = "title.hashdata"; @@ -60,17 +62,22 @@ public interface BKUGUIFacade { public static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; public static final String WINDOWTITLE_VIEWER = "windowtitle.viewer"; public static final String WINDOWTITLE_HELP = "windowtitle.help"; - public static final String MESSAGE_WAIT = "message.wait"; - public static final String MESSAGE_INSERTCARD = "message.insertcard"; - public static final String MESSAGE_ENTERPIN = "message.enterpin"; - public static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; - public static final String MESSAGE_HASHDATALINK_TINY = "message.hashdatalink.tiny"; -// public static final String MESSAGE_HASHDATA = "message.hashdata"; - public static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; - public static final String MESSAGE_RETRIES = "message.retries"; - public static final String MESSAGE_LAST_RETRY = "message.retries.last"; - public static final String MESSAGE_OVERWRITE = "message.overwrite"; - public static final String MESSAGE_HELP = "message.help"; + + // removed message.* prefix to reuse keys as help keys + public static final String MESSAGE_WELCOME = "welcome"; + public static final String MESSAGE_WAIT = "wait"; + public static final String MESSAGE_INSERTCARD = "insertcard"; + public static final String MESSAGE_CARD_NOT_SUPPORTED = "cardnotsupported"; + public static final String MESSAGE_ENTERPIN = "enterpin"; + public static final String MESSAGE_ENTERPIN_PINPAD = "enterpin.pinpad"; + public static final String MESSAGE_HASHDATALINK = "hashdatalink"; + public static final String MESSAGE_HASHDATALINK_TINY = "hashdatalink.tiny"; + public static final String MESSAGE_HASHDATALIST = "hashdatalist"; + public static final String MESSAGE_RETRIES = "retries"; + public static final String MESSAGE_LAST_RETRY = "retries.last"; + public static final String MESSAGE_OVERWRITE = "overwrite"; + public static final String MESSAGE_HELP = "help"; + public static final String WARNING_XHTML = "warning.xhtml"; public static final String LABEL_PIN = "label.pin"; public static final String LABEL_PINSIZE = "label.pinsize"; @@ -103,33 +110,48 @@ public interface BKUGUIFacade { */ public Locale getLocale(); - public void showWelcomeDialog(); +// public void showWelcomeDialog(); /** * * @param waitMessage if null, a simple 'please wait' text is displayed */ - public void showWaitDialog(String waitMessage); +// public void showWaitDialog(String waitMessage); + +// public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); - public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); +// public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); - public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); + public void showCardPINDialog(PINSpec pinSpec, int numRetries, + ActionListener okListener, String okCommand, + ActionListener cancelListener, String cancelCommand); - public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); +// public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); - public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); + public void showSignaturePINDialog(PINSpec pinSpec, int numRetries, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); - public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); +// public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); - public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); +// public void showPinpadSignaturePINDialog(PINSpec pinSpec, int retries); public char[] getPin(); - public void showHashDataInputDialog(List signedReferences, ActionListener okListener, String okCommand); + public void showSecureViewer(List signedReferences, + ActionListener okListener, String okCommand); - public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String okCommand); + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, + ActionListener okListener, String okCommand); public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams); - public void showMessageDialog(String titleKey, String msgKey, Object[] msgParams, ActionListener okListener, String okCommand); + public void showMessageDialog(String titleKey, + String msgKey, Object[] msgParams, + String buttonKey, + ActionListener okListener, String okCommand); + + public void showMessageDialog(String titleKey, + String msgKey, Object[] msgParams); + + public void showMessageDialog(String titleKey, + String msgKey); } 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 76b1d795..928be249 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 @@ -315,200 +315,204 @@ public class BKUGUIImpl implements BKUGUIFacade { return messages.containsKey(key); } - @Override - public void showWelcomeDialog() { - - log.debug("scheduling welcome dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show welcome dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - helpListener.setHelpTopic(HELP_WELCOME); - - JLabel welcomeMsgLabel = new JLabel(); - welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - - if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_WELCOME)); - welcomeMsgLabel.setText(getMessage(MESSAGE_WAIT)); - } else { - welcomeMsgLabel.setText(getMessage(TITLE_WELCOME)); - } - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(welcomeMsgLabel); - GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(welcomeMsgLabel); - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - contentPanel.validate(); - - } - }); - } - - @Override - public void showInsertCardDialog(final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling insert card dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show insert card dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_INSERTCARD)); - } - - helpListener.setHelpTopic(HELP_INSERTCARD); - - JLabel insertCardMsgLabel = new JLabel(); - insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel); - GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup() - .addComponent(insertCardMsgLabel); - - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - if (renderCancelButton) { - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - cancelButton.setText(getMessage(BUTTON_CANCEL)); - cancelButton.addActionListener(cancelListener); - cancelButton.setActionCommand(cancelCommand); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(cancelButton)); - } - - contentPanel.validate(); - } - }); - } +// @Override +// public void showWelcomeDialog() { +// +// log.debug("scheduling welcome dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("show welcome dialog"); +// +// mainPanel.removeAll(); +// buttonPanel.removeAll(); +// +// helpListener.setHelpTopic(HELP_WELCOME); +// +// JLabel welcomeMsgLabel = new JLabel(); +// welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); +// +// if (renderHeaderPanel) { +// titleLabel.setText(getMessage(TITLE_WELCOME)); +// welcomeMsgLabel.setText(getMessage(MESSAGE_WAIT)); +// } else { +// welcomeMsgLabel.setText(getMessage(TITLE_WELCOME)); +// } +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() +// .addComponent(welcomeMsgLabel); +// GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(welcomeMsgLabel); +// if (!renderHeaderPanel) { +// messageHorizontal +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) +// .addComponent(helpLabel); +// messageVertical +// .addComponent(helpLabel); +// } +// +// mainPanelLayout.setHorizontalGroup(messageHorizontal); +// mainPanelLayout.setVerticalGroup(messageVertical); +// +// contentPanel.validate(); +// +// } +// }); +// } + +// @Override +// public void showInsertCardDialog( +// final ActionListener cancelListener, final String cancelCommand) { +// +// log.debug("scheduling insert card dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("show insert card dialog"); +// +// mainPanel.removeAll(); +// buttonPanel.removeAll(); +// +// if (renderHeaderPanel) { +// titleLabel.setText(getMessage(TITLE_INSERTCARD)); +// } +// +// helpListener.setHelpTopic(HELP_INSERTCARD); +// +// JLabel insertCardMsgLabel = new JLabel(); +// insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); +// insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() +// .addComponent(insertCardMsgLabel); +// GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup() +// .addComponent(insertCardMsgLabel); +// +// if (!renderHeaderPanel) { +// messageHorizontal +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) +// .addComponent(helpLabel); +// messageVertical +// .addComponent(helpLabel); +// } +// +// mainPanelLayout.setHorizontalGroup(messageHorizontal); +// mainPanelLayout.setVerticalGroup(messageVertical); +// +// if (renderCancelButton) { +// JButton cancelButton = new JButton(); +// cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); +// cancelButton.setText(getMessage(BUTTON_CANCEL)); +// cancelButton.addActionListener(cancelListener); +// cancelButton.setActionCommand(cancelCommand); +// +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addComponent(cancelButton)); +// } +// +// contentPanel.validate(); +// } +// }); +// } /** * only difference to showInsertCard: title text: card not supported * @param cancelListener * @param cancelCommand */ - @Override - public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling card not supported dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show card not supported dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - JLabel insertCardMsgLabel = new JLabel(); - insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - - if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); - insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); - } else { - insertCardMsgLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); - } - - helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel); - GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(insertCardMsgLabel); - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - if (renderCancelButton) { - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - cancelButton.setText(getMessage(BUTTON_CANCEL)); - cancelButton.addActionListener(cancelListener); - cancelButton.setActionCommand(cancelCommand); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(cancelButton)); - } - - contentPanel.validate(); - } - }); - } - - private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { +// @Override +// public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { +// +// log.debug("scheduling card not supported dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("show card not supported dialog"); +// +// mainPanel.removeAll(); +// buttonPanel.removeAll(); +// +// JLabel insertCardMsgLabel = new JLabel(); +// insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); +// +// if (renderHeaderPanel) { +// titleLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); +// insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); +// } else { +// insertCardMsgLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); +// } +// +// helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() +// .addComponent(insertCardMsgLabel); +// GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(insertCardMsgLabel); +// if (!renderHeaderPanel) { +// messageHorizontal +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) +// .addComponent(helpLabel); +// messageVertical +// .addComponent(helpLabel); +// } +// +// mainPanelLayout.setHorizontalGroup(messageHorizontal); +// mainPanelLayout.setVerticalGroup(messageVertical); +// +// if (renderCancelButton) { +// JButton cancelButton = new JButton(); +// cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); +// cancelButton.setText(getMessage(BUTTON_CANCEL)); +// cancelButton.addActionListener(cancelListener); +// cancelButton.setActionCommand(cancelCommand); +// +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addComponent(cancelButton)); +// } +// +// contentPanel.validate(); +// } +// }); +// } + + @Override + public void showCardPINDialog(final PINSpec pinSpec, final int numRetries, + final ActionListener okListener, final String okCommand, + final ActionListener cancelListener, final String cancelCommand) { log.debug("scheduling card-pin dialog"); @@ -534,7 +538,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); okButton.setText(getMessage(BUTTON_OK)); - okButton.setEnabled(false); + okButton.setEnabled(pinSpec.getMinLength() <= 0); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -681,27 +685,30 @@ public class BKUGUIImpl implements BKUGUIFacade { }); } - @Override - public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { - showCardPINDialog(pinSpec, -1, okListener, okCommand, cancelListener, cancelCommand); - } - - @Override - public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { - showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); - } - - @Override - public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { - showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); - } +// @Override +// public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { +// showCardPINDialog(pinSpec, -1, okListener, okCommand, cancelListener, cancelCommand); +// } +// +// @Override +// public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { +// showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); +// } + +// @Override +// public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { +// showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); +// } @Override - public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { - showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); - } - - private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { + public void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, + final ActionListener signListener, final String signCommand, + final ActionListener cancelListener, final String cancelCommand, + final ActionListener hashdataListener, final String hashdataCommand) { +// showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); +// } +// +// private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { log.debug("scheduling signature-pin dialog"); @@ -726,7 +733,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JButton signButton = new JButton(); signButton.setFont(signButton.getFont().deriveFont(signButton.getFont().getStyle() & ~java.awt.Font.BOLD)); signButton.setText(getMessage(BUTTON_SIGN)); - signButton.setEnabled(false); + signButton.setEnabled(pinSpec.getMinLength() <= 0); signButton.setActionCommand(signCommand); signButton.addActionListener(signListener); @@ -888,7 +895,7 @@ public class BKUGUIImpl implements BKUGUIFacade { final ActionListener okListener, final String okCommand) { showMessageDialog(TITLE_ERROR, ERROR_COLOR, - errorMsgKey, errorMsgParams, okListener, okCommand); + errorMsgKey, errorMsgParams, BUTTON_OK, okListener, okCommand); } @Override @@ -896,22 +903,45 @@ public class BKUGUIImpl implements BKUGUIFacade { final String errorMsgKey, final Object[] errorMsgParams) { showMessageDialog(TITLE_ERROR, ERROR_COLOR, - errorMsgKey, errorMsgParams, null, null); + errorMsgKey, errorMsgParams, null, null, null); } @Override public void showMessageDialog( final String titleKey, final String msgKey, final Object[] msgParams, + final String buttonKey, final ActionListener okListener, final String okCommand) { showMessageDialog(titleKey, null, - msgKey, msgParams, okListener, okCommand); + msgKey, msgParams, buttonKey, okListener, okCommand); + } + + @Override + public void showMessageDialog( + final String titleKey, + final String msgKey, final Object[] msgParams) { + + showMessageDialog(titleKey, null, + msgKey, msgParams, null, null, null); + } + + @Override + public void showMessageDialog( + final String titleKey, final String msgKey) { + + showMessageDialog(titleKey, null, + msgKey, null, null, null, null); } + /** + * + * @param buttonKey if null defaults to BUTTON_OK + */ private void showMessageDialog( final String titleKey, final Color titleColor, final String msgKey, final Object[] msgParams, + final String buttonKey, final ActionListener okListener, final String okCommand) { log.debug("scheduling message dialog"); @@ -972,7 +1002,7 @@ public class BKUGUIImpl implements BKUGUIFacade { if (okListener != null) { JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - okButton.setText(getMessage(BUTTON_OK)); + okButton.setText(getMessage((buttonKey != null) ? buttonKey : BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -993,57 +1023,57 @@ public class BKUGUIImpl implements BKUGUIFacade { }); } - @Override - public void showWaitDialog(final String waitMessage) { - - log.debug("scheduling wait dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show wait dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_WAIT)); - } - - helpListener.setHelpTopic(HELP_WAIT); - - JLabel waitMsgLabel = new JLabel(); - waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - if (waitMessage != null) { - waitMsgLabel.setText("" + waitMessage + ""); - } else { - waitMsgLabel.setText(getMessage(MESSAGE_WAIT)); - } - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel); - GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel); - - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - contentPanel.validate(); - } - }); - } +// @Override +// public void showWaitDialog(final String waitMessage) { +// +// log.debug("scheduling wait dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("show wait dialog"); +// +// mainPanel.removeAll(); +// buttonPanel.removeAll(); +// +// if (renderHeaderPanel) { +// titleLabel.setText(getMessage(TITLE_WAIT)); +// } +// +// helpListener.setHelpTopic(HELP_WAIT); +// +// JLabel waitMsgLabel = new JLabel(); +// waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); +// if (waitMessage != null) { +// waitMsgLabel.setText("" + waitMessage + ""); +// } else { +// waitMsgLabel.setText(getMessage(MESSAGE_WAIT)); +// } +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() +// .addComponent(waitMsgLabel); +// GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(waitMsgLabel); +// +// if (!renderHeaderPanel) { +// messageHorizontal +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) +// .addComponent(helpLabel); +// messageVertical +// .addComponent(helpLabel); +// } +// mainPanelLayout.setHorizontalGroup(messageHorizontal); +// mainPanelLayout.setVerticalGroup(messageVertical); +// +// contentPanel.validate(); +// } +// }); +// } @Override public char[] getPin() { @@ -1062,7 +1092,7 @@ public class BKUGUIImpl implements BKUGUIFacade { * @param okCommand */ @Override - public void showHashDataInputDialog(final List signedReferences, + public void showSecureViewer(final List signedReferences, final ActionListener okListener, final String okCommand) { diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java index 87b636f0..13aaf870 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java @@ -35,6 +35,7 @@ class PINDocument extends PlainDocument { protected Pattern pinPattern; protected JButton enterButton; protected Document compareTo; + protected Document oldPin; public PINDocument(PINSpec pinSpec, JButton enterButton) { this.pinSpec = pinSpec; @@ -46,11 +47,30 @@ class PINDocument extends PlainDocument { this.enterButton = enterButton; } + /** + * + * @param pinSpec + * @param enterButton + * @param compareTo enable enterButton iff this pinDocument's pin equals to compareTo's pin. may be null + */ public PINDocument(PINSpec pinSpec, JButton enterButton, Document compareTo) { this(pinSpec, enterButton); this.compareTo = compareTo; } + /** + * + * @param pinSpec + * @param enterButton may be null + * @param compareTo enable enterButton iff this pinDocument's pin equals to compareTo's pin. may be null + * @param oldPin enable enterButton iff oldPin meets the pinSpec pin length requirements, may be null + */ + public PINDocument(PINSpec pinSpec, JButton enterButton, Document compareTo, Document oldPin) { + this(pinSpec, enterButton); + this.compareTo = compareTo; + this.oldPin = oldPin; + } + @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if (pinSpec.getMaxLength() < 0 || pinSpec.getMaxLength() >= (getLength() + str.length())) { @@ -66,7 +86,10 @@ class PINDocument extends PlainDocument { } } if (enterButton != null) { - enterButton.setEnabled(getLength() >= pinSpec.getMinLength() && compare()); + enterButton.setEnabled( + (oldPin == null || oldPin.getLength() >= pinSpec.getMinLength()) && + getLength() >= pinSpec.getMinLength() && + compare()); } } @@ -74,7 +97,10 @@ class PINDocument extends PlainDocument { public void remove(int offs, int len) throws BadLocationException { super.remove(offs, len); if (enterButton != null) { - enterButton.setEnabled(getLength() >= pinSpec.getMinLength() && compare()); + enterButton.setEnabled( + (oldPin == null || oldPin.getLength() >= pinSpec.getMinLength()) && + getLength() >= pinSpec.getMinLength() && + compare()); } } -- cgit v1.2.3 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 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 40 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 603 +++++++++++++-------- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 293 ---------- .../at/gv/egiz/bku/gui/SecureViewerDialog.java | 371 +++++++++++++ 4 files changed, 759 insertions(+), 548 deletions(-) delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java 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') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 1043b6a1..4b079428 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -43,6 +43,7 @@ public interface BKUGUIFacade { public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; public static final String DEFAULT_BACKGROUND = "/images/BackgroundChipperling.png"; + public static final String DEFAULT_ICON = "/images/ChipperlingLogo.png"; public static final String HELP_IMG = "/images/help.png"; public static final String HASHDATA_FONT = "Monospaced"; public static final Color ERROR_COLOR = Color.RED; @@ -58,6 +59,7 @@ public interface BKUGUIFacade { public static final String TITLE_WAIT = "title.wait"; public static final String TITLE_HASHDATA = "title.hashdata"; public static final String WINDOWTITLE_SAVE = "windowtitle.save"; + public static final String WINDOWTITLE_ERROR = "windowtitle.error"; public static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; public static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; public static final String WINDOWTITLE_VIEWER = "windowtitle.viewer"; @@ -102,42 +104,36 @@ public interface BKUGUIFacade { public enum Style { tiny, simple, advanced }; -// public void init(Container contentPane, Locale locale, Style guiStyle, URL background, ActionListener helpListener); - /** * BKUWorker needs to init signature card with locale * @return */ public Locale getLocale(); -// public void showWelcomeDialog(); - - /** - * - * @param waitMessage if null, a simple 'please wait' text is displayed - */ -// public void showWaitDialog(String waitMessage); - -// public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); - -// public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); - public void showCardPINDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); -// public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); - - public void showSignaturePINDialog(PINSpec pinSpec, int numRetries, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); - -// public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); + public void showSignaturePINDialog(PINSpec pinSpec, int numRetries, + ActionListener signListener, String signCommand, + ActionListener cancelListener, String cancelCommand, + ActionListener viewerListener, String viewerCommand); -// public void showPinpadSignaturePINDialog(PINSpec pinSpec, int retries); + public void showPinpadSignaturePINDialog(PINSpec pinSpec, int numRetries, + ActionListener viewerListener, String viewerCommand); public char[] getPin(); - public void showSecureViewer(List signedReferences, - ActionListener okListener, String okCommand); + /** + * + * @param dataToBeSigned + * @param backListener if list of references hides pin dialog, backListener + * receives an action when user hits 'back' button (i.e. whenever the pin-dialog + * needs to be re-paint) + * @param backCommand + */ + public void showSecureViewer(List dataToBeSigned, + ActionListener backListener, String backCommand); public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String okCommand); 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 928be249..a7eebbfd 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 @@ -71,6 +71,7 @@ public class BKUGUIImpl implements BKUGUIFacade { } protected HelpMouseListener helpListener; + protected SecureViewerDialog secureViewer; protected Container contentPane; protected ResourceBundle messages; @@ -145,13 +146,16 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("initializing gui"); + log.debug("initializing gui [" + Thread.currentThread().getName() + "]"); if (renderIconPanel) { initIconPanel(background); initContentPanel(null); } else { - initContentPanel(background); + initContentPanel((background == null) ? + getClass().getResource(DEFAULT_BACKGROUND) : + background + ); } GroupLayout layout = new GroupLayout(contentPane); @@ -159,15 +163,27 @@ public class BKUGUIImpl implements BKUGUIFacade { if (renderIconPanel) { layout.setHorizontalGroup(layout.createSequentialGroup() - .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); - layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + .addContainerGap() + .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()); + layout.setVerticalGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); } else { - layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(contentPanel)); - layout.setVerticalGroup(layout.createSequentialGroup().addComponent(contentPanel)); + layout.setHorizontalGroup(layout.createSequentialGroup() + // left border + .addContainerGap() + .addComponent(contentPanel) + .addContainerGap()); + layout.setVerticalGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(contentPanel) + .addContainerGap()); } } }); @@ -178,11 +194,12 @@ public class BKUGUIImpl implements BKUGUIFacade { protected void initIconPanel(URL background) { if (background == null) { - background = getClass().getResource(DEFAULT_BACKGROUND); + background = getClass().getResource(DEFAULT_ICON); } if ("file".equals(background.getProtocol())) { - log.warn("file:// background images not permitted: " + background); - background = getClass().getResource(DEFAULT_BACKGROUND); + log.warn("file:// background images not permitted: " + background + + ", loading default background"); + background = getClass().getResource(DEFAULT_ICON); } log.debug("loading icon panel background " + background); @@ -194,26 +211,24 @@ public class BKUGUIImpl implements BKUGUIFacade { iconPanel.setLayout(iconPanelLayout); iconPanelLayout.setHorizontalGroup( iconPanelLayout.createSequentialGroup() - .addContainerGap() .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); - // no gap here (contentPanel has containerGap) iconPanelLayout.setVerticalGroup( iconPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); } protected void initContentPanel(URL background) { +// if (background == null) { +// background = getClass().getResource(DEFAULT_BACKGROUND); +// } if (background == null) { - background = getClass().getResource(DEFAULT_BACKGROUND); - } - if (background == null) { + log.debug("no background image set"); contentPanel = new JPanel(); } else { if ("file".equals(background.getProtocol())) { - log.warn("file:// background images not permitted: " + background); + log.warn("file:// background images not permitted: " + background + + ", loading default background"); background = getClass().getResource(DEFAULT_BACKGROUND); } log.debug("loading background " + background); @@ -257,34 +272,29 @@ public class BKUGUIImpl implements BKUGUIFacade { GroupLayout contentPanelLayout = new GroupLayout(contentPanel); contentPanel.setLayout(contentPanelLayout); - GroupLayout.ParallelGroup horizontalContentInner = contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + // align header, main and button to the right + GroupLayout.ParallelGroup horizontalContent = + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING); //LEADING); + GroupLayout.SequentialGroup verticalContent = + contentPanelLayout.createSequentialGroup(); + if (renderHeaderPanel) { - horizontalContentInner + horizontalContent .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); + verticalContent + .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); + } - horizontalContentInner + horizontalContent .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); - GroupLayout.SequentialGroup horizontalContentOuter = contentPanelLayout.createSequentialGroup(); - if (!renderIconPanel) { - horizontalContentOuter - .addContainerGap(); - } - horizontalContentOuter - .addGroup(horizontalContentInner) - .addContainerGap(); - contentPanelLayout.setHorizontalGroup(horizontalContentOuter); - - GroupLayout.SequentialGroup verticalContent = contentPanelLayout.createSequentialGroup(); - verticalContent.addContainerGap(); - if (renderHeaderPanel) { - verticalContent.addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); - } - verticalContent.addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap(); + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); //Short.MAX_VALUE); + verticalContent + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + + contentPanelLayout.setHorizontalGroup(horizontalContent); //Outer); contentPanelLayout.setVerticalGroup(verticalContent); } @@ -521,7 +531,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show card-pin dialog"); + log.debug("show card-pin dialog [" + Thread.currentThread().getName() + "]"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -653,7 +663,6 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); GroupLayout.Group buttonVertical; @@ -700,6 +709,128 @@ public class BKUGUIImpl implements BKUGUIFacade { // showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); // } + @Override + public void showPinpadSignaturePINDialog(final PINSpec pinSpec, final int numRetries, +// final ActionListener cancelListener, final String cancelCommand, + final ActionListener hashdataListener, final String hashdataCommand) { + + log.debug("scheduling pinpad signature-pin dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show pinpad signature-pin dialog [" + Thread.currentThread().getName() + "]"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (renderHeaderPanel) { + if (numRetries < 0) { + titleLabel.setText(getMessage(TITLE_SIGN)); + } else { + titleLabel.setText(getMessage(TITLE_RETRY)); + } + } + + JLabel infoLabel = new JLabel(); + if (numRetries < 0) { + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (shortText) { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); + } else { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); + } + infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + infoLabel.setForeground(HYPERLINK_COLOR); + infoLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent me) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e); + } + }); + helpListener.setHelpTopic(HELP_SIGNPIN); + } else { + String retryPattern; + if (numRetries < 2) { + retryPattern = getMessage(MESSAGE_LAST_RETRY); + } else { + retryPattern = getMessage(MESSAGE_RETRIES); + } + infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); + infoLabel.setForeground(ERROR_COLOR); + helpListener.setHelpTopic(HELP_RETRY); + } + + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + + String msgPattern = getMessage(MESSAGE_ENTERPIN_PINPAD); + String msg = MessageFormat.format(msgPattern, new Object[] { + pinSpec.getLocalizedName(), pinSize }); + + JLabel msgLabel = new JLabel(); + msgLabel.setFont(msgLabel.getFont().deriveFont(msgLabel.getFont().getStyle() & ~Font.BOLD)); + msgLabel.setText(msg); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel); + + if (!renderHeaderPanel) { + infoHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + infoVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(infoHorizontal) + .addComponent(msgLabel)); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(msgLabel)); + + //no cancel button (cancel via pinpad) +// if (renderCancelButton) { +// JButton cancelButton = new JButton(); +// cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); +// cancelButton.setText(getMessage(BUTTON_CANCEL)); +// cancelButton.setActionCommand(cancelCommand); +// cancelButton.addActionListener(cancelListener); +// +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() +// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); +// GroupLayout.SequentialGroup buttonVertical = buttonPanelLayout.createSequentialGroup() +// .addComponent(cancelButton); +// +// buttonPanelLayout.setHorizontalGroup(buttonHorizontal); +// buttonPanelLayout.setVerticalGroup(buttonVertical); +// } + + contentPanel.validate(); + } + }); + } + @Override public void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, @@ -717,7 +848,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show signature-pin dialog"); + log.debug("show signature-pin dialog [" + Thread.currentThread().getName() + "]"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -730,6 +861,38 @@ public class BKUGUIImpl implements BKUGUIFacade { } } + JLabel infoLabel = new JLabel(); + if (numRetries < 0) { + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (shortText) { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); + } else { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); + } + infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + infoLabel.setForeground(HYPERLINK_COLOR); + infoLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent me) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e); + } + }); + helpListener.setHelpTopic(HELP_SIGNPIN); + } else { + String retryPattern; + if (numRetries < 2) { + retryPattern = getMessage(MESSAGE_LAST_RETRY); + } else { + retryPattern = getMessage(MESSAGE_RETRIES); + } + infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); + infoLabel.setForeground(ERROR_COLOR); + helpListener.setHelpTopic(HELP_RETRY); + } + JButton signButton = new JButton(); signButton.setFont(signButton.getFont().deriveFont(signButton.getFont().getStyle() & ~java.awt.Font.BOLD)); signButton.setText(getMessage(BUTTON_SIGN)); @@ -765,46 +928,14 @@ public class BKUGUIImpl implements BKUGUIFacade { } pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); - JLabel infoLabel = new JLabel(); - if (numRetries < 0) { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - if (shortText) { - infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); - } else { - infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); - } - infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - infoLabel.setForeground(HYPERLINK_COLOR); - infoLabel.addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent me) { - ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); - hashdataListener.actionPerformed(e); - } - }); - helpListener.setHelpTopic(HELP_SIGNPIN); - } else { - String retryPattern; - if (numRetries < 2) { - retryPattern = getMessage(MESSAGE_LAST_RETRY); - } else { - retryPattern = getMessage(MESSAGE_RETRIES); - } - infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); - infoLabel.setForeground(ERROR_COLOR); - helpListener.setHelpTopic(HELP_RETRY); - } - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() .addComponent(infoLabel); GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(infoLabel); - + if (!renderHeaderPanel) { infoHorizontal .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) @@ -814,8 +945,8 @@ public class BKUGUIImpl implements BKUGUIFacade { } // align pinfield and pinsize to the right - GroupLayout.ParallelGroup pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING); - GroupLayout.Group pinVertical; + GroupLayout.Group pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING); + GroupLayout.SequentialGroup pinVertical = mainPanelLayout.createSequentialGroup(); if (pinLabelPos == PinLabelPosition.ABOVE) { pinHorizontal @@ -823,20 +954,25 @@ public class BKUGUIImpl implements BKUGUIFacade { .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); - pinVertical = mainPanelLayout.createSequentialGroup() + pinVertical .addComponent(signPinLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); - } else { + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel); + } else { // PinLabelPosition.LEFT pinHorizontal .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); - pinVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(signPinLabel) - .addComponent(pinField); + pinVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel); } mainPanelLayout.setHorizontalGroup( @@ -848,18 +984,14 @@ public class BKUGUIImpl implements BKUGUIFacade { mainPanelLayout.createSequentialGroup() .addGroup(infoVertical) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(pinVertical) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); + .addGroup(pinVertical)); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); - GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup(); GroupLayout.Group buttonVertical; - + if (renderCancelButton) { JButton cancelButton = new JButton(); cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -868,17 +1000,19 @@ public class BKUGUIImpl implements BKUGUIFacade { cancelButton.addActionListener(cancelListener); buttonHorizontal + .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); - buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(signButton) - .addComponent(cancelButton); + .addComponent(cancelButton); } else { + buttonHorizontal + .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); buttonVertical = buttonPanelLayout.createSequentialGroup() .addComponent(signButton); } - + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); buttonPanelLayout.setVerticalGroup(buttonVertical); @@ -951,7 +1085,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show message dialog"); + log.debug("show message dialog [" + Thread.currentThread().getName() + "]"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -1011,7 +1145,6 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanelLayout.setHorizontalGroup( buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() @@ -1084,68 +1217,69 @@ public class BKUGUIImpl implements BKUGUIFacade { } return null; } + + + //////////////////////////////////////////////////////////////////////////// + // SECURE VIEWER + //////////////////////////////////////////////////////////////////////////// + /** - * TODO handle multiple references in HashDataViewer * @param signedReferences - * @param okListener + * @param backListener gets notified if pin-dialog has to be redrawn + * (signedRefencesList returns via BACK button) * @param okCommand */ @Override - public void showSecureViewer(final List signedReferences, - final ActionListener okListener, - final String okCommand) { - - if (signedReferences == null) { - showErrorDialog(getMessage(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); - return; - } + public void showSecureViewer(final List dataToBeSigned, + final ActionListener backListener, final String backCommand) { - if (signedReferences.size() == 1) { + if (dataToBeSigned == null) { + showErrorDialog(getMessage(ERR_NO_HASHDATA), + new Object[] {"no signature data provided"}, + backListener, backCommand); + } else if (dataToBeSigned.size() == 1) { try { - log.debug("scheduling hashdata viewer"); + log.debug("scheduling secure viewer"); - SwingUtilities.invokeAndWait(new Runnable() { + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - ActionListener saveHashDataListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - HashDataInput hdi = signedReferences.get(0); - showSaveHashDataInputDialog(Collections.singletonList(hdi), okListener, okCommand); - } - }; - showHashDataViewer(signedReferences.get(0), saveHashDataListener, "save"); + showSecureViewer(dataToBeSigned.get(0)); } }); - } catch (InterruptedException ex) { - log.error("Failed to display HashDataViewer: " + ex.getMessage()); - } catch (InvocationTargetException ex) { - log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } catch (Exception ex) { //InterruptedException InvocationTargetException + log.error("Failed to display secure viewer: " + ex.getMessage()); + log.trace(ex); + showErrorDialog(ERR_UNKNOWN, null, backListener, backCommand); } } else { - showSignedReferencesListDialog(signedReferences, okListener, okCommand); + showSignedReferencesListDialog(dataToBeSigned, backListener, backCommand); } } /** * has to be called from event dispatcher thread + * This method blocks until the dialog's close button is pressed. * @param hashDataText * @param saveListener * @param saveCommand */ - private void showHashDataViewer(final HashDataInput hashDataInput, final ActionListener saveListener, final String saveCommand) { + private void showSecureViewer(HashDataInput dataToBeSigned) { - log.debug("show hashdata viewer"); - - ActionListener l = helpListener.getActionListener(); - HashDataViewer.showHashDataInput(contentPane, hashDataInput, messages, saveListener, saveCommand, l); + log.debug("show secure viewer [" + Thread.currentThread().getName() + "]"); + if (secureViewer == null) { + secureViewer = new SecureViewerDialog(null, messages, + helpListener.getActionListener()); + } + secureViewer.setContent(dataToBeSigned); + log.trace("show secure viewer returned"); } - private void showSignedReferencesListDialog(final List signedReferences, final ActionListener backListener, final String backCommand) { + private void showSignedReferencesListDialog(final List signedReferences, + final ActionListener backListener, final String backCommand) { log.debug("scheduling signed references list dialog"); @@ -1154,7 +1288,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show signed references list dialog"); + log.debug("show signed references list dialog [" + Thread.currentThread().getName() + "]"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -1202,13 +1336,7 @@ public class BKUGUIImpl implements BKUGUIFacade { int selectionIdx = lsm.getMinSelectionIndex(); if (selectionIdx >= 0) { final HashDataInput selection = signedReferences.get(selectionIdx); - showHashDataViewer(selection, new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(Collections.singletonList(selection), null, null); - } - }, "save"); + showSecureViewer(selection); } } }); @@ -1255,9 +1383,8 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup(buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + buttonPanelLayout.setVerticalGroup(buttonPanelLayout.createSequentialGroup() .addComponent(backButton)); contentPanel.validate(); @@ -1266,96 +1393,101 @@ public class BKUGUIImpl implements BKUGUIFacade { } /** - * - * @param signedRefs * @param okListener may be null - * @param okCommand */ - private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { - - log.debug("scheduling save hashdatainput dialog"); - - SwingUtilities.invokeLater(new Runnable() { +// private void showSaveDialog(final List signedRefs, +// final ActionListener okListener, final String okCommand) { +// +// log.debug("scheduling save dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("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); +// if (signedRefs.size() == 1) { +// fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVE)); +// fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); +// String mimeType = signedRefs.get(0).getMimeType(); +// MimeFilter mimeFilter = new MimeFilter(mimeType, messages); +// fileDialog.setFileFilter(mimeFilter); +// String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); +// fileDialog.setSelectedFile(new File(userHome, filename)); +// } else { +// fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVEDIR)); +// fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); +// } +// +// //parent contentPane -> placed over applet +// switch (fileDialog.showSaveDialog(fileDialog)) { +// case JFileChooser.APPROVE_OPTION: +// File f = fileDialog.getSelectedFile(); +// for (HashDataInput hashDataInput : signedRefs) { +// String mimeType = hashDataInput.getMimeType(); +// String id = hashDataInput.getReferenceId(); +// File file; +// if (f.isDirectory()) { +// String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); +// file = new File(f, filename); +// } else { +// file = f; +// } +// if (file.exists()) { +// String ovrwrt = getMessage(MESSAGE_OVERWRITE); +// int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), getMessage(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); +// if (overwrite != JOptionPane.OK_OPTION) { +// continue; +// } +// } +// 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()); +// showErrorDialog(ERR_WRITE_HASHDATA, new Object[] {ex.getMessage()}, null, null); +// ex.printStackTrace(); +// } finally { +// try { +// 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)); +// } +// } +// }); +// } + + //////////////////////////////////////////////////////////////////////////// + // UTILITY METHODS + //////////////////////////////////////////////////////////////////////////// - @Override - public void run() { - - log.debug("show save hashdatainput dialog"); - - String userHome = System.getProperty("user.home"); - - JFileChooser fileDialog = new JFileChooser(userHome); - fileDialog.setMultiSelectionEnabled(false); - fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); - fileDialog.setFileHidingEnabled(true); - if (signedRefs.size() == 1) { - fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVE)); - fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); - String mimeType = signedRefs.get(0).getMimeType(); - MimeFilter mimeFilter = new MimeFilter(mimeType, messages); - fileDialog.setFileFilter(mimeFilter); - String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); - fileDialog.setSelectedFile(new File(userHome, filename)); - } else { - fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVEDIR)); - fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - } - - //parent contentPane -> placed over applet - switch (fileDialog.showSaveDialog(fileDialog)) { - case JFileChooser.APPROVE_OPTION: - File f = fileDialog.getSelectedFile(); - for (HashDataInput hashDataInput : signedRefs) { - String mimeType = hashDataInput.getMimeType(); - String id = hashDataInput.getReferenceId(); - File file; - if (f.isDirectory()) { - String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); - file = new File(f, filename); - } else { - file = f; - } - if (file.exists()) { - String ovrwrt = getMessage(MESSAGE_OVERWRITE); - int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), getMessage(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); - if (overwrite != JOptionPane.OK_OPTION) { - continue; - } - } - if (log.isDebugEnabled()) { - log.debug("Writing HashDataInput " + 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 HashDataInput to file " + file + ": " + ex.getMessage()); - showErrorDialog(ERR_WRITE_HASHDATA, new Object[] {ex.getMessage()}, null, null); - ex.printStackTrace(); - } finally { - try { - fos.close(); - } catch (IOException ex) { - } - } - } - } - log.debug("done saving hashdatainput"); - if (okListener != null) { - okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); - } - } - }); - } - private void registerHelpListener(ActionListener helpListener) { if (helpListener != null) { this.helpListener = new HelpMouseListener(helpListener); @@ -1371,6 +1503,11 @@ public class BKUGUIImpl implements BKUGUIFacade { } } + + //////////////////////////////////////////////////////////////////////////// + // INITIALIZERS (MAY BE OVERRIDDEN BY SUBCLASSES) + //////////////////////////////////////////////////////////////////////////// + /** * Called from constructor. * Subclasses may override this method to ensure the message bundle is loaded diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java deleted file mode 100644 index 6c097b2a..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * 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.bku.gui.html.RestrictedHTMLEditorKit; -import at.gv.egiz.stal.HashDataInput; -import java.awt.Component; -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.BufferedReader; -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.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.LayoutStyle; -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 HashDataViewer extends JDialog - implements ActionListener { - - public static final String PLAINTEXT_FONT = "Monospaced"; - protected static final Log log = LogFactory.getLog(HashDataViewer.class); - - private static HashDataViewer dialog; - - protected ResourceBundle messages; - - /** - * - * @param signedReferences currently, only one hashdata input (the first in the list) is displayed - */ - public static void showHashDataInput(HashDataInput hashDataInput, - ResourceBundle messages, - ActionListener saveListener, - String saveCommand, - ActionListener helpListener) { - showHashDataInput(null, hashDataInput, messages, saveListener, saveCommand, helpListener); - } - - /** - * - * @param frameComp owner - */ - public static void showHashDataInput(Component frameComp, - HashDataInput hashDataInput, - ResourceBundle messages, - ActionListener saveListener, - String saveCommand, - ActionListener helpListener) { - - Frame frame = null; - if (frameComp != null) { - JOptionPane.getFrameForComponent(frameComp); - } - dialog = new HashDataViewer(frame, - messages, - hashDataInput, - saveListener, - saveCommand, - helpListener); - dialog.setVisible(true); - } - - private HashDataViewer(Frame frame, - ResourceBundle messages, - HashDataInput hashDataInput, - ActionListener saveListener, - String saveCommand, - ActionListener helpListener) { - super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); - this.messages = messages; - - Charset cs; - if (hashDataInput.getEncoding() == null) { - cs = Charset.forName("UTF-8"); - } else { - try { - cs = Charset.forName(hashDataInput.getEncoding()); - } catch (Exception ex) { - log.debug("charset " + hashDataInput.getEncoding() + " not supported, assuming UTF-8: " + ex.getMessage()); - cs = Charset.forName("UTF-8"); - } - } - - - InputStreamReader isr = new InputStreamReader(hashDataInput.getHashDataInput(), cs); - Reader content = new BufferedReader(isr); - - JPanel hashDataPanel = createViewerPanel(content, - hashDataInput.getMimeType(), - helpListener); - JPanel buttonPanel = createButtonPanel(saveListener, saveCommand); - initContentPane(new Dimension(600, 400), hashDataPanel, buttonPanel); - - pack(); - if (frame != null) { - setLocationRelativeTo(frame); - } 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 messages - * @param content - * @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 helpListener may be null - * @return - */ - private JPanel createViewerPanel(Reader content, - String mimeType, - final ActionListener helpListener) { - - if (mimeType == null) { - mimeType = "text/plain"; - } - log.debug("viewer dialog: " + mimeType); - - JEditorPane viewer = new JEditorPane(); - viewer.setEditable(false); - 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 { - viewer.read(content, document); - content.close(); - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - String p = messages.getString(BKUGUIFacade.ERR_VIEWER); - viewer.setText(MessageFormat.format(p, ex.getMessage())); - } - - JScrollPane scrollPane = new JScrollPane(viewer); - scrollPane.setPreferredSize(viewer.getPreferredSize()); - scrollPane.setAlignmentX(LEFT_ALIGNMENT); - viewer.setCaretPosition(0); - - 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); - - if ("application/xhtml+xml".equals(mimeType)) { - JLabel viewerLabel = new JLabel(); - viewerLabel.setText(messages.getString(BKUGUIFacade.WARNING_XHTML)); - 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; - } - - private JPanel createButtonPanel(ActionListener saveListener, String saveCommand) { - JButton closeButton = new JButton(); - closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); - closeButton.addActionListener(this); - - JButton saveButton = new JButton(); - saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); - saveButton.setActionCommand(saveCommand); - saveButton.addActionListener(saveListener); - - 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) { - HashDataViewer.dialog.setVisible(false); - } -} 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 78728a96af022bae87e4d0d11855f420736d87b7 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 3 Apr 2009 15:04:26 +0000 Subject: applet dispatcher (prevent applet caching) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@326 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 4b079428..79fbfd6c 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -77,6 +77,8 @@ public interface BKUGUIFacade { public static final String MESSAGE_HASHDATALIST = "hashdatalist"; public static final String MESSAGE_RETRIES = "retries"; public static final String MESSAGE_LAST_RETRY = "retries.last"; + public static final String MESSAGE_RETRIES_PINPAD = "retries.pinpad"; + public static final String MESSAGE_LAST_RETRY_PINPAD = "retries.pinpad.last"; public static final String MESSAGE_OVERWRITE = "overwrite"; public static final String MESSAGE_HELP = "help"; -- cgit v1.2.3 From 8a336c8343f86f69680817153334d0d37da56010 Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 20 Apr 2009 14:56:16 +0000 Subject: en localization of pinMgmt (verifyPin, cancelbutton) no java message (todo: localize) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@339 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 a7eebbfd..e5cac7b7 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 @@ -1533,6 +1533,12 @@ public class BKUGUIImpl implements BKUGUIFacade { if (b.getPreferredSize().width > bs) { bs = b.getPreferredSize().width; } + // need cancel button for message dialog, + // even if renderCancelButton == false + b.setText(getMessage(BUTTON_CANCEL)); + if (b.getPreferredSize().width > bs) { + bs = b.getPreferredSize().width; + } b.setText(getMessage(BUTTON_SIGN)); if (b.getPreferredSize().width > bs) { bs = b.getPreferredSize().width; @@ -1545,12 +1551,6 @@ public class BKUGUIImpl implements BKUGUIFacade { if (b.getPreferredSize().width > bs) { bs = b.getPreferredSize().width; } - if (renderCancelButton) { - b.setText(getMessage(BUTTON_CANCEL)); - if (b.getPreferredSize().width > bs) { - bs = b.getPreferredSize().width; - } - } return bs; } } -- cgit v1.2.3 From cb4496d82e8271102cda305e5490d6bc55e63fb6 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 9 Jul 2009 12:07:40 +0000 Subject: log locale git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@403 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 e5cac7b7..4cab29e0 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 @@ -39,6 +39,7 @@ import java.text.MessageFormat; import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.MissingResourceException; import java.util.ResourceBundle; import javax.swing.GroupLayout; import javax.swing.ImageIcon; @@ -1509,6 +1510,9 @@ public class BKUGUIImpl implements BKUGUIFacade { //////////////////////////////////////////////////////////////////////////// /** + * Load applet messages bundle. Note that getBundle looks for classes based + * on the default Locale before it selects the base class! + * * Called from constructor. * Subclasses may override this method to ensure the message bundle is loaded * once initButtonSize (called from constructor as well) is called. @@ -1517,12 +1521,16 @@ public class BKUGUIImpl implements BKUGUIFacade { */ protected void loadMessageBundle(Locale locale) { if (locale != null) { + // see [#378] Ignoring post parameter 'locale': bundle resolve-order not correct?! Locale lang = new Locale(locale.getLanguage().substring(0, 2)); log.debug("loading applet resources for language: " + lang.toString()); messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, lang); } else { + log.debug("loading default language applet resources"); messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); } + // how the f*** you know the default Messages.properties is de?! + log.debug("applet messages loaded: " + messages.getLocale()); } protected int initButtonSize() { -- cgit v1.2.3 From 5bff0a3288bd2b5e1f1030c6e47430735cd09463 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 9 Jul 2009 16:34:07 +0000 Subject: [#393] loading of default background fails git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@407 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 2 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 31 +++++----------------- 2 files changed, 8 insertions(+), 25 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 79fbfd6c..06aad45f 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -42,7 +42,7 @@ public interface BKUGUIFacade { public static final String ERR_CONFIG = "error.config"; public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; - public static final String DEFAULT_BACKGROUND = "/images/BackgroundChipperling.png"; + public static final String DEFAULT_BACKGROUND = "/images/ChipperlingCutoff.png"; public static final String DEFAULT_ICON = "/images/ChipperlingLogo.png"; public static final String HELP_IMG = "/images/help.png"; public static final String HASHDATA_FONT = "Monospaced"; 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 4cab29e0..16297218 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 @@ -28,25 +28,15 @@ import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.text.MessageFormat; -import java.util.Collections; import java.util.List; import java.util.Locale; -import java.util.MissingResourceException; import java.util.ResourceBundle; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; -import javax.swing.JFileChooser; import javax.swing.JLabel; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JScrollPane; @@ -153,10 +143,7 @@ public class BKUGUIImpl implements BKUGUIFacade { initIconPanel(background); initContentPanel(null); } else { - initContentPanel((background == null) ? - getClass().getResource(DEFAULT_BACKGROUND) : - background - ); + initContentPanel(background); } GroupLayout layout = new GroupLayout(contentPane); @@ -220,20 +207,16 @@ public class BKUGUIImpl implements BKUGUIFacade { protected void initContentPanel(URL background) { -// if (background == null) { -// background = getClass().getResource(DEFAULT_BACKGROUND); -// } if (background == null) { log.debug("no background image set"); +// contentPanel = new ImagePanel(getClass().getResource(DEFAULT_BACKGROUND)); + contentPanel = new JPanel(); + } else if ("file".equals(background.getProtocol())) { + log.warn("file:// background images not permitted: " + background); contentPanel = new JPanel(); } else { - if ("file".equals(background.getProtocol())) { - log.warn("file:// background images not permitted: " + background + - ", loading default background"); - background = getClass().getResource(DEFAULT_BACKGROUND); - } - log.debug("loading background " + background); - contentPanel = new ImagePanel(background); + log.debug("loading background " + background); + contentPanel = new ImagePanel(background); } mainPanel = new JPanel(); mainPanel.setOpaque(false); -- cgit v1.2.3 From 2429c7e98cb9e47e36dc5ff07fd10bd18cc999bc Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 13 Aug 2009 09:11:09 +0000 Subject: [#436] resolve "#PIN digits" message via message resource bundle git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@419 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 19 +++---------------- .../java/at/gv/egiz/bku/gui/DefaultHelpListener.java | 7 +++---- 2 files changed, 6 insertions(+), 20 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 16297218..4f3a8f1e 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 @@ -581,11 +581,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel pinsizeLabel = new JLabel(); pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); String pinsizePattern = getMessage(LABEL_PINSIZE); - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSpec.getLocalizedLength()})); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -750,14 +746,9 @@ public class BKUGUIImpl implements BKUGUIFacade { helpListener.setHelpTopic(HELP_RETRY); } - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - String msgPattern = getMessage(MESSAGE_ENTERPIN_PINPAD); String msg = MessageFormat.format(msgPattern, new Object[] { - pinSpec.getLocalizedName(), pinSize }); + pinSpec.getLocalizedName(), pinSpec.getLocalizedLength() }); JLabel msgLabel = new JLabel(); msgLabel.setFont(msgLabel.getFont().deriveFont(msgLabel.getFont().getStyle() & ~Font.BOLD)); @@ -906,11 +897,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel pinsizeLabel = new JLabel(); pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); String pinsizePattern = getMessage(LABEL_PINSIZE); - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } - pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSpec.getLocalizedLength()})); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java index c8594fe1..032c8fe5 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java @@ -60,8 +60,7 @@ public class DefaultHelpListener extends AbstractHelpListener { * @param helpTopic ignored */ @Override - public void showDocument(final URL helpURL, final String helpTopic) { -// try { + public void showDocument(final URL helpURL, final String helpTopic) { log.debug("schedule help dialog"); SwingUtilities.invokeLater(new Runnable() { @@ -72,9 +71,9 @@ public class DefaultHelpListener extends AbstractHelpListener { log.debug("show help dialog"); if (ctx == null) { - HelpViewer.showHelpDialog(helpURL, messages); // helpTopic, messages); + HelpViewer.showHelpDialog(helpURL, messages); } else { - HelpViewer.showHelpDialog(ctx, helpURL, messages); //helpTopic, messages); + HelpViewer.showHelpDialog(ctx, helpURL, messages); } } }); -- cgit v1.2.3 From d791931ac69b0a2a1201ef7cd2f7ca247e92ba8c Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 14 Aug 2009 10:46:26 +0000 Subject: [#436] resolve "#PIN digits" message via message resource bundle only for activation git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@431 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 4f3a8f1e..de9a91b9 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 @@ -581,7 +581,10 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel pinsizeLabel = new JLabel(); pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); String pinsizePattern = getMessage(LABEL_PINSIZE); - pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSpec.getLocalizedLength()})); + String pinSize = (pinSpec.getMaxLength() > pinSpec.getMinLength()) ? + pinSpec.getMinLength() + "-" + pinSpec.getMaxLength() : + String.valueOf(pinSpec.getMinLength()); + pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -747,8 +750,11 @@ public class BKUGUIImpl implements BKUGUIFacade { } String msgPattern = getMessage(MESSAGE_ENTERPIN_PINPAD); + String pinSize = (pinSpec.getMaxLength() > pinSpec.getMinLength()) ? + pinSpec.getMinLength() + "-" + pinSpec.getMaxLength() : + String.valueOf(pinSpec.getMinLength()); String msg = MessageFormat.format(msgPattern, new Object[] { - pinSpec.getLocalizedName(), pinSpec.getLocalizedLength() }); + pinSpec.getLocalizedName(), pinSize }); JLabel msgLabel = new JLabel(); msgLabel.setFont(msgLabel.getFont().deriveFont(msgLabel.getFont().getStyle() & ~Font.BOLD)); @@ -897,7 +903,10 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel pinsizeLabel = new JLabel(); pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); String pinsizePattern = getMessage(LABEL_PINSIZE); - pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSpec.getLocalizedLength()})); + String pinSize = (pinSpec.getMaxLength() > pinSpec.getMinLength()) ? + pinSpec.getMinLength() + "-" + pinSpec.getMaxLength() : + String.valueOf(pinSpec.getMinLength()); + pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); -- cgit v1.2.3 From 22001c93bca360d1b15c252cb22d2a4147ff350d Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 20 Aug 2009 16:24:55 +0000 Subject: [#430] Activation/PIN-management in MOCCA Web Start - new Modules: smccSTALExt, BKUGuiExt in order not to depend on BKUAppletExt in BKULocal - provide stal-request handler de-registration in abstractSMCCSTAL git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@448 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 de9a91b9..2663e8bf 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 @@ -132,7 +132,7 @@ public class BKUGUIImpl implements BKUGUIFacade { log.debug("scheduling gui initialization"); - SwingUtilities.invokeAndWait(new Runnable() { + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { -- cgit v1.2.3 From 06cd22f6acac2bd9edb373c7bb32c9a85cb34b21 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 21 Aug 2009 16:00:33 +0000 Subject: icons 2.0 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@462 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 06aad45f..6c27910a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -40,11 +40,12 @@ public interface BKUGUIFacade { public static final String ERR_VIEWER = "error.viewer"; public static final String ERR_EXTERNAL_LINK = "error.external.link"; public static final String ERR_CONFIG = "error.config"; - + + /** no leading slash for Messages resource, leading slash for images */ public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; - public static final String DEFAULT_BACKGROUND = "/images/ChipperlingCutoff.png"; - public static final String DEFAULT_ICON = "/images/ChipperlingLogo.png"; - public static final String HELP_IMG = "/images/help.png"; + public static final String DEFAULT_BACKGROUND = "/at/gv/egiz/bku/gui/chip32.png"; + public static final String DEFAULT_ICON = "/at/gv/egiz/bku/gui/chiperling105.png"; + public static final String HELP_IMG = "/at/gv/egiz/bku/gui/help.png"; public static final String HASHDATA_FONT = "Monospaced"; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; -- cgit v1.2.3 From 598f62c5b30d6e40f6983fc3eec17613d19cdc0e Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 25 Aug 2009 12:49:43 +0000 Subject: [#436] resolve "#pin digits" message via resource bundle (now, all dialogs - not only pinactivation - get pinLength from resource bundle) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@472 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 2663e8bf..5ea2499a 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 @@ -580,11 +580,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel pinsizeLabel = new JLabel(); pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); - String pinsizePattern = getMessage(LABEL_PINSIZE); - String pinSize = (pinSpec.getMaxLength() > pinSpec.getMinLength()) ? - pinSpec.getMinLength() + "-" + pinSpec.getMaxLength() : - String.valueOf(pinSpec.getMinLength()); - pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + pinsizeLabel.setText(MessageFormat.format(getMessage(LABEL_PINSIZE), pinSpec.getLocalizedLength())); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -750,11 +746,8 @@ public class BKUGUIImpl implements BKUGUIFacade { } String msgPattern = getMessage(MESSAGE_ENTERPIN_PINPAD); - String pinSize = (pinSpec.getMaxLength() > pinSpec.getMinLength()) ? - pinSpec.getMinLength() + "-" + pinSpec.getMaxLength() : - String.valueOf(pinSpec.getMinLength()); String msg = MessageFormat.format(msgPattern, new Object[] { - pinSpec.getLocalizedName(), pinSize }); + pinSpec.getLocalizedName(), pinSpec.getLocalizedLength() }); JLabel msgLabel = new JLabel(); msgLabel.setFont(msgLabel.getFont().deriveFont(msgLabel.getFont().getStyle() & ~Font.BOLD)); @@ -902,11 +895,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel pinsizeLabel = new JLabel(); pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); - String pinsizePattern = getMessage(LABEL_PINSIZE); - String pinSize = (pinSpec.getMaxLength() > pinSpec.getMinLength()) ? - pinSpec.getMinLength() + "-" + pinSpec.getMaxLength() : - String.valueOf(pinSpec.getMinLength()); - pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + pinsizeLabel.setText(MessageFormat.format(getMessage(LABEL_PINSIZE), pinSpec.getLocalizedLength())); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); -- cgit v1.2.3 From 145003155c05e915b900989a27cef1271398164b Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 26 Aug 2009 17:31:32 +0000 Subject: MOCCA TLS Server CA cert installation servlet removed help.jsp (and jsp dependencies in jetty) moved html pages to src/main/webapp (encoding problem?) switch to BASIC download protocol in BKUWebStart (no jnlpDownloadServlet required, see template.xml) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@474 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../java/at/gv/egiz/bku/gui/AbstractHelpListener.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java index b871263e..6fd1ffea 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -38,6 +38,11 @@ import org.apache.commons.logging.LogFactory; */ public abstract class AbstractHelpListener implements ActionListener { + /** + * any locale not in the list will be mapped to 'de' + */ + public static final String[] SUPPORTED_LANGUAGES = new String[] { "de" }; + protected final static Log log = LogFactory.getLog(AbstractHelpListener.class); protected URL baseURL; protected Locale locale; @@ -71,12 +76,14 @@ public abstract class AbstractHelpListener implements ActionListener { URL helpURL = baseURL; log.trace("constructing help URL: " + helpURL); try { - if (locale != null) { - helpURL = new URL(helpURL, locale.toString() + "/"); - log.trace("constructing help URL: " + helpURL); - } + // not localized for now + //check if locale.getLanguage() supported and add default if not +// if (locale != null) { +// helpURL = new URL(helpURL, locale.toString() + "/"); +// log.trace("constructing help URL: " + helpURL); +// } if (helpTopic != null && !"".equals(helpTopic)) { - helpURL = new URL(helpURL, helpTopic + ".html"); + helpURL = new URL(helpURL, "de/" + helpTopic + ".html"); log.trace("constructing help URL: " + helpURL); } } catch (MalformedURLException ex) { -- cgit v1.2.3 From 3ca1928f20603069058bf89dce1a47599d064091 Mon Sep 17 00:00:00 2001 From: mcentner Date: Tue, 8 Sep 2009 15:55:46 +0000 Subject: Fixed Bug [#467] Border between Background image and border. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@505 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 1 + 1 file changed, 1 insertion(+) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 5ea2499a..35a53ff7 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 @@ -218,6 +218,7 @@ public class BKUGUIImpl implements BKUGUIFacade { log.debug("loading background " + background); contentPanel = new ImagePanel(background); } + contentPanel.setOpaque(false); mainPanel = new JPanel(); mainPanel.setOpaque(false); buttonPanel = new JPanel(); -- 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/BKUGUIImpl.java | 9 +++++++++ BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java | 1 + .../src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java | 1 + 3 files changed, 11 insertions(+) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 35a53ff7..b84a2164 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 @@ -23,6 +23,7 @@ import java.awt.Color; import java.awt.Container; import java.awt.Cursor; import java.awt.Font; +import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -1243,6 +1244,14 @@ public class BKUGUIImpl implements BKUGUIFacade { if (secureViewer == null) { secureViewer = new SecureViewerDialog(null, messages, helpListener.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. + Window window = SwingUtilities.getWindowAncestor(contentPane); + if (window != null && window.isAlwaysOnTop()) { + log.debug("make secureViewer alwaysOnTop"); + secureViewer.setAlwaysOnTop(true); + } } secureViewer.setContent(dataToBeSigned); log.trace("show secure viewer returned"); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java index 364da6ec..48393101 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java @@ -86,6 +86,7 @@ public class HelpViewer extends JDialog } dialog = new HelpViewer(frame, messages, ctx, helpURL); //, helpTopic); dialog.setVisible(true); + dialog.toFront(); } private HelpViewer(Frame frame, 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 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 5 + .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 280 ++++++++++++++++++--- .../java/at/gv/egiz/bku/gui/HelpKeyListener.java | 46 ++++ .../at/gv/egiz/bku/gui/HelpLinkFocusManager.java | 138 ++++++++++ .../main/java/at/gv/egiz/bku/gui/HelpViewer.java | 4 + .../at/gv/egiz/bku/gui/SecureViewerDialog.java | 35 ++- .../gv/egiz/bku/gui/SwitchFocusFocusListener.java | 38 +++ .../at/gv/egiz/bku/gui/SwitchFocusListener.java | 44 ++++ 8 files changed, 552 insertions(+), 38 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpKeyListener.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpLinkFocusManager.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusFocusListener.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusListener.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 6c27910a..e4af6443 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -46,6 +46,7 @@ public interface BKUGUIFacade { public static final String DEFAULT_BACKGROUND = "/at/gv/egiz/bku/gui/chip32.png"; public static final String DEFAULT_ICON = "/at/gv/egiz/bku/gui/chiperling105.png"; public static final String HELP_IMG = "/at/gv/egiz/bku/gui/help.png"; + public static final String HELP_IMG_FOCUS = "/at/gv/egiz/bku/gui/help_focus.png"; public static final String HASHDATA_FONT = "Monospaced"; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; @@ -75,6 +76,8 @@ public interface BKUGUIFacade { public static final String MESSAGE_ENTERPIN_PINPAD = "enterpin.pinpad"; public static final String MESSAGE_HASHDATALINK = "hashdatalink"; public static final String MESSAGE_HASHDATALINK_TINY = "hashdatalink.tiny"; + public static final String MESSAGE_HASHDATALINK_FOCUS = "hashdatalink.focus"; + public static final String MESSAGE_HASHDATALINK_TINY_FOCUS = "hashdatalink.tiny.focus"; public static final String MESSAGE_HASHDATALIST = "hashdatalist"; public static final String MESSAGE_RETRIES = "retries"; public static final String MESSAGE_LAST_RETRY = "retries.last"; @@ -153,4 +156,6 @@ public interface BKUGUIFacade { public void showMessageDialog(String titleKey, String msgKey); + + public void getFocusFromBrowser(); } 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 b84a2164..e83502a8 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 @@ -26,6 +26,10 @@ import java.awt.Font; import java.awt.Window; 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.awt.event.MouseMotionAdapter; @@ -45,11 +49,14 @@ import javax.swing.JTable; import javax.swing.LayoutStyle; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; +import javax.swing.UIManager; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + + /** * * @author clemens @@ -62,7 +69,9 @@ public class BKUGUIImpl implements BKUGUIFacade { LEFT, ABOVE } - protected HelpMouseListener helpListener; + protected HelpMouseListener helpMouseListener; + protected HelpKeyListener helpKeyListener; + protected SwitchFocusFocusListener switchFocusKeyListener; protected SecureViewerDialog secureViewer; protected Container contentPane; @@ -77,6 +86,7 @@ public class BKUGUIImpl implements BKUGUIFacade { /** right side fixed labels */ protected JLabel titleLabel; protected JLabel helpLabel; + protected JLabel switchFocusDummyLabel; /** remember the pinfield to return to worker */ protected JPasswordField pinField; @@ -107,7 +117,8 @@ public class BKUGUIImpl implements BKUGUIFacade { Locale locale, Style guiStyle, URL background, - ActionListener helpListener) { + ActionListener helpListener, + SwitchFocusListener switchFocusListener) { this.contentPane = contentPane; loadMessageBundle(locale); @@ -122,8 +133,13 @@ public class BKUGUIImpl implements BKUGUIFacade { pinLabelPos = PinLabelPosition.ABOVE; } + // ensure that buttons can be fired with enter key too + UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE); + registerHelpListener(helpListener); + registerSwitchFocusListener(switchFocusListener); + createGUI(background); } @@ -224,12 +240,35 @@ public class BKUGUIImpl implements BKUGUIFacade { mainPanel.setOpaque(false); buttonPanel = new JPanel(); buttonPanel.setOpaque(false); - + helpLabel = new JLabel(); helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); helpLabel.getAccessibleContext().setAccessibleName(getMessage(ALT_HELP)); - helpLabel.addMouseListener(helpListener); + helpLabel.setFocusable(true); + helpLabel.addMouseListener(helpMouseListener); + helpLabel.addKeyListener(helpKeyListener); + helpLabel.addFocusListener(new FocusAdapter() { + + @Override + public void focusGained(FocusEvent e) { + + helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG_FOCUS))); + } + + @Override + public void focusLost(FocusEvent e) { + + helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); + } + + + }); helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + switchFocusDummyLabel = new JLabel(); + switchFocusDummyLabel.setText(""); + switchFocusDummyLabel.setFocusable(true); + switchFocusDummyLabel.addFocusListener(switchFocusKeyListener); buttonSize = initButtonSize(); @@ -248,11 +287,15 @@ public class BKUGUIImpl implements BKUGUIFacade { headerPanelLayout.createSequentialGroup() .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ); headerPanelLayout.setVerticalGroup( headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) - .addComponent(helpLabel)); + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ); } GroupLayout contentPanelLayout = new GroupLayout(contentPanel); @@ -566,7 +609,8 @@ public class BKUGUIImpl implements BKUGUIFacade { } else { infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); } - helpListener.setHelpTopic(HELP_CARDPIN); + helpMouseListener.setHelpTopic(HELP_CARDPIN); + helpKeyListener.setHelpTopic(HELP_CARDPIN); } else { String retryPattern; if (numRetries < 2) { @@ -577,7 +621,8 @@ public class BKUGUIImpl implements BKUGUIFacade { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); - helpListener.setHelpTopic(HELP_RETRY); + helpMouseListener.setHelpTopic(HELP_RETRY); + helpKeyListener.setHelpTopic(HELP_RETRY); } JLabel pinsizeLabel = new JLabel(); @@ -595,9 +640,13 @@ public class BKUGUIImpl implements BKUGUIFacade { if (!renderHeaderPanel) { infoHorizontal .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; infoVertical - .addComponent(helpLabel); + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; } // align pinfield and pinsize to the right @@ -668,7 +717,9 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanelLayout.setHorizontalGroup(buttonHorizontal); buttonPanelLayout.setVerticalGroup(buttonVertical); - pinField.requestFocusInWindow(); +// pinField.requestFocusInWindow(); +// helpLabel.requestFocus(); + pinField.requestFocus(); contentPanel.validate(); } @@ -715,7 +766,7 @@ public class BKUGUIImpl implements BKUGUIFacade { } } - JLabel infoLabel = new JLabel(); + final JLabel infoLabel = new JLabel(); if (numRetries < 0) { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); if (shortText) { @@ -723,6 +774,7 @@ public class BKUGUIImpl implements BKUGUIFacade { } else { infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); } + infoLabel.setFocusable(true); infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); infoLabel.setForeground(HYPERLINK_COLOR); infoLabel.addMouseListener(new MouseAdapter() { @@ -733,7 +785,47 @@ public class BKUGUIImpl implements BKUGUIFacade { hashdataListener.actionPerformed(e); } }); - helpListener.setHelpTopic(HELP_SIGNPIN); + + infoLabel.addKeyListener(new KeyAdapter() { + + @Override + public void keyPressed(KeyEvent e) { + + if(e.getKeyCode() == KeyEvent.VK_ENTER) { + ActionEvent e1 = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e1); + } + } + + }); + + infoLabel.addFocusListener(new FocusAdapter() { + + @Override + public void focusGained(FocusEvent e) { + + if (shortText) { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY_FOCUS)); + } else { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_FOCUS)); + } + } + + @Override + public void focusLost(FocusEvent e) { + + if (shortText) { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); + } else { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); + } + + } + + }); + + helpMouseListener.setHelpTopic(HELP_SIGNPIN); + helpKeyListener.setHelpTopic(HELP_SIGNPIN); } else { String retryPattern; if (numRetries < 2) { @@ -741,10 +833,12 @@ public class BKUGUIImpl implements BKUGUIFacade { } else { retryPattern = getMessage(MESSAGE_RETRIES); } + infoLabel.setFocusable(true); infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); infoLabel.setForeground(ERROR_COLOR); - helpListener.setHelpTopic(HELP_RETRY); + helpMouseListener.setHelpTopic(HELP_RETRY); + helpKeyListener.setHelpTopic(HELP_RETRY); } String msgPattern = getMessage(MESSAGE_ENTERPIN_PINPAD); @@ -766,9 +860,13 @@ public class BKUGUIImpl implements BKUGUIFacade { if (!renderHeaderPanel) { infoHorizontal .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; infoVertical - .addComponent(helpLabel); + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; } mainPanelLayout.setHorizontalGroup( @@ -837,7 +935,7 @@ public class BKUGUIImpl implements BKUGUIFacade { } } - JLabel infoLabel = new JLabel(); + final JLabel infoLabel = new JLabel(); if (numRetries < 0) { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); if (shortText) { @@ -845,6 +943,7 @@ public class BKUGUIImpl implements BKUGUIFacade { } else { infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); } + infoLabel.setFocusable(true); infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); infoLabel.setForeground(HYPERLINK_COLOR); infoLabel.addMouseListener(new MouseAdapter() { @@ -855,7 +954,49 @@ public class BKUGUIImpl implements BKUGUIFacade { hashdataListener.actionPerformed(e); } }); - helpListener.setHelpTopic(HELP_SIGNPIN); + + infoLabel.addKeyListener(new KeyAdapter() { + + @Override + public void keyPressed(KeyEvent e) { + + if(e.getKeyCode() == KeyEvent.VK_ENTER) { + ActionEvent e1 = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e1); + } + } + + }); + + infoLabel.addFocusListener(new FocusAdapter() { + + @Override + public void focusGained(FocusEvent e) { + + + if (shortText) { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY_FOCUS)); + } else { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_FOCUS)); + } + } + + @Override + public void focusLost(FocusEvent e) { + + + if (shortText) { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); + } else { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); + } + + } + + }); + + helpMouseListener.setHelpTopic(HELP_SIGNPIN); + helpKeyListener.setHelpTopic(HELP_SIGNPIN); } else { String retryPattern; if (numRetries < 2) { @@ -863,10 +1004,12 @@ public class BKUGUIImpl implements BKUGUIFacade { } else { retryPattern = getMessage(MESSAGE_RETRIES); } + infoLabel.setFocusable(true); infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); infoLabel.setForeground(ERROR_COLOR); - helpListener.setHelpTopic(HELP_RETRY); + helpMouseListener.setHelpTopic(HELP_RETRY); + helpKeyListener.setHelpTopic(HELP_RETRY); } JButton signButton = new JButton(); @@ -895,6 +1038,7 @@ public class BKUGUIImpl implements BKUGUIFacade { } }); + JLabel pinsizeLabel = new JLabel(); pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); pinsizeLabel.setText(MessageFormat.format(getMessage(LABEL_PINSIZE), pinSpec.getLocalizedLength())); @@ -910,9 +1054,13 @@ public class BKUGUIImpl implements BKUGUIFacade { if (!renderHeaderPanel) { infoHorizontal .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; infoVertical - .addComponent(helpLabel); + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; } // align pinfield and pinsize to the right @@ -973,21 +1121,27 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonHorizontal .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + ; buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(signButton) - .addComponent(cancelButton); + .addComponent(cancelButton) + ; } else { buttonHorizontal - .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + ; buttonVertical = buttonPanelLayout.createSequentialGroup() - .addComponent(signButton); + .addComponent(signButton) + ; } buttonPanelLayout.setHorizontalGroup(buttonHorizontal); buttonPanelLayout.setVerticalGroup(buttonVertical); - pinField.requestFocusInWindow(); +// pinField.requestFocusInWindow(); +// helpLabel.requestFocus(); + pinField.requestFocus(); contentPanel.validate(); } @@ -1065,7 +1219,8 @@ public class BKUGUIImpl implements BKUGUIFacade { titleLabel.setText(getMessage(titleKey)); } - helpListener.setHelpTopic(msgKey); + helpMouseListener.setHelpTopic(msgKey); + helpKeyListener.setHelpTopic(msgKey); String msgPattern = getMessage(msgKey); String msg = MessageFormat.format(msgPattern, msgParams); @@ -1080,6 +1235,9 @@ public class BKUGUIImpl implements BKUGUIFacade { GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + log.debug("focus to contentPanel"); + contentPanel.requestFocus(); + if (!renderHeaderPanel) { JLabel titleLabel = new JLabel(); titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | Font.BOLD)); @@ -1092,11 +1250,18 @@ public class BKUGUIImpl implements BKUGUIFacade { .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(titleLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ); mainVertical .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(titleLabel) - .addComponent(helpLabel)); + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ); + + log.debug("focus to helpLabel"); + helpLabel.requestFocus(); } mainPanelLayout.setHorizontalGroup(mainHorizontal @@ -1105,6 +1270,7 @@ public class BKUGUIImpl implements BKUGUIFacade { .addComponent(msgLabel)); if (okListener != null) { + JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); okButton.setText(getMessage((buttonKey != null) ? buttonKey : BUTTON_OK)); @@ -1120,6 +1286,9 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() .addComponent(okButton)); + + log.debug("focus to ok-button"); + okButton.requestFocus(); } contentPanel.validate(); @@ -1243,7 +1412,7 @@ public class BKUGUIImpl implements BKUGUIFacade { log.debug("show secure viewer [" + Thread.currentThread().getName() + "]"); if (secureViewer == null) { secureViewer = new SecureViewerDialog(null, messages, - helpListener.getActionListener()); + 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. @@ -1276,7 +1445,8 @@ public class BKUGUIImpl implements BKUGUIFacade { titleLabel.setText(getMessage(TITLE_HASHDATA)); } - helpListener.setHelpTopic(HELP_HASHDATALIST); + helpMouseListener.setHelpTopic(HELP_HASHDATALIST); + helpKeyListener.setHelpTopic(HELP_HASHDATALIST); JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -1335,10 +1505,14 @@ public class BKUGUIImpl implements BKUGUIFacade { if (!renderHeaderPanel) { messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; + messageVertical + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; } mainPanelLayout.setHorizontalGroup( @@ -1469,19 +1643,42 @@ public class BKUGUIImpl implements BKUGUIFacade { private void registerHelpListener(ActionListener helpListener) { if (helpListener != null) { - this.helpListener = new HelpMouseListener(helpListener); + this.helpMouseListener = new HelpMouseListener(helpListener); + this.helpKeyListener = new HelpKeyListener(helpListener); } else { log.error("no help listener provided, will not be able to display help"); - this.helpListener = new HelpMouseListener(new ActionListener() { + this.helpMouseListener = new HelpMouseListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { log.error("no help listener registered (requested help topic: " + e.getActionCommand() + ")"); } }); + this.helpKeyListener = new HelpKeyListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + log.error("no help listener registered (requested help topic: " + e.getActionCommand() + ")"); + } + }); } } + private void registerSwitchFocusListener(ActionListener switchFocusListener) { + if (switchFocusListener != null) { + this.switchFocusKeyListener = new SwitchFocusFocusListener(switchFocusListener); + + } else { + + this.switchFocusKeyListener = new SwitchFocusFocusListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + log.warn("no switch focus listener registered"); + } + }); + } + } //////////////////////////////////////////////////////////////////////////// // INITIALIZERS (MAY BE OVERRIDDEN BY SUBCLASSES) @@ -1539,4 +1736,13 @@ public class BKUGUIImpl implements BKUGUIFacade { } return bs; } + + @Override + public void getFocusFromBrowser() { + + // This method puts the focus to the helpLabel as this + // element is supposed to appear in each dialogue. + helpLabel.requestFocus(); + + } } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpKeyListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpKeyListener.java new file mode 100644 index 00000000..4ca20f7e --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpKeyListener.java @@ -0,0 +1,46 @@ +package at.gv.egiz.bku.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Thomas Zefferer + */ +public class HelpKeyListener extends KeyAdapter { + + protected static final Log log = LogFactory.getLog(HelpKeyListener.class); + + protected ActionListener helpListener; + protected String locale; + protected String topic; + + public HelpKeyListener(ActionListener externalHelpListener) { + super(); + this.helpListener = externalHelpListener; + } + + public void setHelpTopic(String topic) { + log.trace("setting help topic: " + topic); + this.topic = topic; + } + + public ActionListener getActionListener() { + return helpListener; + } + + @Override + public void keyPressed(KeyEvent arg0) { + + if(arg0.getKeyCode() == KeyEvent.VK_ENTER) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, topic); + helpListener.actionPerformed(e); + } + } + +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpLinkFocusManager.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpLinkFocusManager.java new file mode 100644 index 00000000..f5882b3d --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpLinkFocusManager.java @@ -0,0 +1,138 @@ +package at.gv.egiz.bku.gui; + +import java.awt.Color; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.net.URL; + +import javax.accessibility.AccessibleHyperlink; +import javax.accessibility.AccessibleHypertext; +import javax.swing.JEditorPane; +import javax.swing.event.HyperlinkEvent; +import javax.swing.text.DefaultStyledDocument; +import javax.swing.text.Element; +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; + +/** + * + * @author Thomas Zefferer + */ +public final class HelpLinkFocusManager extends KeyAdapter { + + private static final int FOCUS_UNDEFINED = -1; + + private int focusedHyperlinkIndex = FOCUS_UNDEFINED; + private JEditorPane displayPane; + + public HelpLinkFocusManager(JEditorPane displayPane) { + + super(); + this.displayPane = displayPane; + } + + public void keyPressed(KeyEvent e) { + + AccessibleHypertext accessibleHypertext = (AccessibleHypertext) this.displayPane + .getAccessibleContext().getAccessibleText(); + + if (accessibleHypertext.getLinkCount() > 0) { + switch (e.getKeyCode()) { + + case KeyEvent.VK_RIGHT: + if (this.focusedHyperlinkIndex != FOCUS_UNDEFINED) { + removeHyperlinkFocus(); + } + + this.focusedHyperlinkIndex++; + + if (this.focusedHyperlinkIndex >= accessibleHypertext + .getLinkCount()) { + + this.focusedHyperlinkIndex = 0; + } + + setHyperlinkFocus(); + break; + + case KeyEvent.VK_LEFT: + if (this.focusedHyperlinkIndex != FOCUS_UNDEFINED) { + removeHyperlinkFocus(); + } + + this.focusedHyperlinkIndex--; + + if (this.focusedHyperlinkIndex < 0) { + this.focusedHyperlinkIndex = accessibleHypertext + .getLinkCount() - 1; + } + + setHyperlinkFocus(); + break; + + case KeyEvent.VK_SPACE: + case KeyEvent.VK_ENTER: + + + AccessibleHyperlink link = accessibleHypertext + .getLink(this.focusedHyperlinkIndex); + if (link != null) { + URL url = (URL) link.getAccessibleActionObject(0); + Element element = ((DefaultStyledDocument) this.displayPane + .getDocument()).getCharacterElement(link + .getStartIndex()); + HyperlinkEvent linkEvent = new HyperlinkEvent( + this.displayPane, + HyperlinkEvent.EventType.ACTIVATED, url, null, + element); + this.displayPane.fireHyperlinkUpdate(linkEvent); + } + + removeHyperlinkFocus(); + this.focusedHyperlinkIndex = FOCUS_UNDEFINED; + break; + default: + // nothig to do + break; + } + } + } + + private void setHyperlinkFocus() { + + AccessibleHypertext accessibleHypertext = (AccessibleHypertext) this.displayPane + .getAccessibleContext().getAccessibleText(); + AccessibleHyperlink link = accessibleHypertext + .getLink(this.focusedHyperlinkIndex); + + if (link != null) { + + MutableAttributeSet style = new SimpleAttributeSet(); + StyleConstants.setForeground(style, Color.RED); + ((DefaultStyledDocument) this.displayPane.getDocument()) + .setCharacterAttributes(link.getStartIndex(), link + .getEndIndex() + - link.getStartIndex(), style, false); + } + } + + private void removeHyperlinkFocus() { + Color textColor = Color.BLUE; + AccessibleHypertext accessibleHypertext = (AccessibleHypertext) this.displayPane + .getAccessibleContext().getAccessibleText(); + AccessibleHyperlink link = accessibleHypertext + .getLink(this.focusedHyperlinkIndex); + + if (link != null) { + + MutableAttributeSet style = new SimpleAttributeSet(); + StyleConstants.setForeground(style, textColor); + ((DefaultStyledDocument) this.displayPane.getDocument()) + .setCharacterAttributes(link.getStartIndex(), link + .getEndIndex() + - link.getStartIndex(), style, false); + } + } + +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java index 48393101..0f887f78 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java @@ -135,6 +135,10 @@ public class HelpViewer extends JDialog try { viewer.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); viewer.setPage(helpURL); + + HelpLinkFocusManager editorFocusManager = new HelpLinkFocusManager (viewer); + viewer.addKeyListener(editorFocusManager ); + viewer.addHyperlinkListener(new HyperlinkListener() { @Override 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)); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusFocusListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusFocusListener.java new file mode 100644 index 00000000..06e37a89 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusFocusListener.java @@ -0,0 +1,38 @@ +package at.gv.egiz.bku.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Thomas Zefferer + */ +public class SwitchFocusFocusListener extends FocusAdapter { + + protected static final Log log = LogFactory.getLog(SwitchFocusFocusListener.class); + + protected ActionListener swichFocusListener; + + public SwitchFocusFocusListener(ActionListener externalSwitchFocusListener) { + super(); + this.swichFocusListener = externalSwitchFocusListener; + } + + public ActionListener getActionListener() { + return swichFocusListener; + } + + @Override + public void focusGained(FocusEvent arg0) { + + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null); + swichFocusListener.actionPerformed(e); + } + + +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusListener.java new file mode 100644 index 00000000..1e3fabbd --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusListener.java @@ -0,0 +1,44 @@ +package at.gv.egiz.bku.gui; + +import java.applet.AppletContext; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.MalformedURLException; +import java.net.URL; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Thomas Zefferer + */ +public class SwitchFocusListener implements ActionListener { + + protected final static Log log = LogFactory.getLog(SwitchFocusListener.class); + + protected AppletContext ctx; + protected String javascriptFunction; + + public SwitchFocusListener(AppletContext ctx, String javascriptFunction) { + + this.ctx = ctx; + this.javascriptFunction = javascriptFunction; + } + + @Override + public void actionPerformed(ActionEvent e) { + + try { + ctx.showDocument + (new URL("javascript:" + javascriptFunction)); + } + catch (MalformedURLException me) { + + log.warn("Unable to call external javascript function.", me); + } + + + } + +} -- 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 --- .../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 +++++++ 5 files changed, 203 insertions(+), 48 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 (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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); + } +} -- 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') 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 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 18 +++++++++--------- .../java/at/gv/egiz/bku/gui/SecureViewerDialog.java | 15 +++++++-------- .../java/at/gv/egiz/bku/gui/SwitchFocusListener.java | 4 ++-- 3 files changed, 18 insertions(+), 19 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 8df4bd72..34f278fb 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 @@ -159,7 +159,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("initializing gui [" + Thread.currentThread().getName() + "]"); + log.debug("[" + Thread.currentThread().getName() + "] initializing gui"); if (renderIconPanel) { initIconPanel(background); @@ -565,7 +565,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show card-pin dialog [" + Thread.currentThread().getName() + "]"); + log.debug("[" + Thread.currentThread().getName() + "] show card-pin dialog"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -758,7 +758,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show pinpad signature-pin dialog [" + Thread.currentThread().getName() + "]"); + log.debug("[" + Thread.currentThread().getName() + "] show pinpad signature-pin dialog"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -927,7 +927,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show signature-pin dialog [" + Thread.currentThread().getName() + "]"); + log.debug("[" + Thread.currentThread().getName() + "] show signature-pin dialog"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -1215,7 +1215,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show message dialog [" + Thread.currentThread().getName() + "]"); + log.debug("[" + Thread.currentThread().getName() + "] show message dialog"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -1385,7 +1385,7 @@ public class BKUGUIImpl implements BKUGUIFacade { backListener, backCommand); } else if (dataToBeSigned.size() == 1) { try { - log.debug("scheduling secure viewer"); + log.debug("[" + Thread.currentThread().getName() + "] scheduling secure viewer"); SwingUtilities.invokeLater(new Runnable() { @@ -1419,7 +1419,7 @@ public class BKUGUIImpl implements BKUGUIFacade { */ private void showSecureViewer(HashDataInput dataToBeSigned) throws FontProviderException { - log.debug("show secure viewer [" + Thread.currentThread().getName() + "]"); + log.debug("[" + Thread.currentThread().getName() + "] show secure viewer"); if (secureViewer == null) { secureViewer = new SecureViewerDialog(null, messages, fontProvider, helpMouseListener.getActionListener()); @@ -1439,14 +1439,14 @@ public class BKUGUIImpl implements BKUGUIFacade { private void showSignedReferencesListDialog(final List signedReferences, final ActionListener backListener, final String backCommand) { - log.debug("scheduling signed references list dialog"); + log.debug("[" + Thread.currentThread().getName() + "] scheduling signed references list dialog"); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - log.debug("show signed references list dialog [" + Thread.currentThread().getName() + "]"); + log.debug("[" + Thread.currentThread().getName() + "] show signed references list dialog"); mainPanel.removeAll(); buttonPanel.removeAll(); 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"); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusListener.java index 1e3fabbd..48b641e2 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SwitchFocusListener.java @@ -33,8 +33,8 @@ public class SwitchFocusListener implements ActionListener { ctx.showDocument (new URL("javascript:" + javascriptFunction)); } - catch (MalformedURLException me) { - + catch (MalformedURLException me) { + log.warn("Unable to call external javascript function.", me); } -- cgit v1.2.3 From 68651bf67987905980734f5c2199f337a232f427 Mon Sep 17 00:00:00 2001 From: mcentner Date: Thu, 12 Nov 2009 20:48:57 +0000 Subject: Added support for enforcing a PIN length in a CHANGE REFERENCE DATA to match the recommended PIN length via Applet parameter. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@541 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 4 +- .../main/java/at/gv/egiz/bku/gui/PinDocument.java | 94 ++++++++++++---------- 2 files changed, 54 insertions(+), 44 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 34f278fb..20fe4f56 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 @@ -593,7 +593,7 @@ public class BKUGUIImpl implements BKUGUIFacade { pinField = new JPasswordField(); pinField.setText(""); - pinField.setDocument(new PINDocument(pinSpec, okButton)); + pinField.setDocument(new PINDocument(pinSpec.getMinLength(), pinSpec.getMaxLength(), pinSpec.getRexepPattern(), okButton)); pinField.setActionCommand(okCommand); pinField.addActionListener(new ActionListener() { @@ -1031,7 +1031,7 @@ public class BKUGUIImpl implements BKUGUIFacade { pinField = new JPasswordField(); pinField.setText(""); - pinField.setDocument(new PINDocument(pinSpec, signButton)); + pinField.setDocument(new PINDocument(pinSpec.getMinLength(), pinSpec.getMaxLength(), pinSpec.getRexepPattern(), signButton)); pinField.setActionCommand(signCommand); pinField.addActionListener(new ActionListener() { diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java index 13aaf870..96032dc1 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java @@ -16,7 +16,6 @@ */ package at.gv.egiz.bku.gui; -import at.gv.egiz.smcc.PINSpec; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.JButton; @@ -31,49 +30,60 @@ import javax.swing.text.PlainDocument; */ class PINDocument extends PlainDocument { - protected PINSpec pinSpec; - protected Pattern pinPattern; - protected JButton enterButton; - protected Document compareTo; - protected Document oldPin; + private static final long serialVersionUID = 1L; + + protected Pattern pinPattern; + protected int minLength; + protected int maxLength; - public PINDocument(PINSpec pinSpec, JButton enterButton) { - this.pinSpec = pinSpec; - if (pinSpec.getRexepPattern() != null) { - pinPattern = Pattern.compile(pinSpec.getRexepPattern()); - } else { - pinPattern = Pattern.compile("."); - } - this.enterButton = enterButton; - } + protected JButton enterButton; + protected Document compareTo; + protected Document oldPin; - /** - * - * @param pinSpec - * @param enterButton - * @param compareTo enable enterButton iff this pinDocument's pin equals to compareTo's pin. may be null - */ - public PINDocument(PINSpec pinSpec, JButton enterButton, Document compareTo) { - this(pinSpec, enterButton); - this.compareTo = compareTo; - } + public PINDocument(int minLength, int maxLength, String pattern, JButton enterButton) { + if (pattern != null) { + pinPattern = Pattern.compile(pattern); + } else { + pinPattern = Pattern.compile("."); + } + this.minLength = minLength; + this.maxLength = maxLength; + this.enterButton = enterButton; + } - /** - * - * @param pinSpec - * @param enterButton may be null - * @param compareTo enable enterButton iff this pinDocument's pin equals to compareTo's pin. may be null - * @param oldPin enable enterButton iff oldPin meets the pinSpec pin length requirements, may be null - */ - public PINDocument(PINSpec pinSpec, JButton enterButton, Document compareTo, Document oldPin) { - this(pinSpec, enterButton); - this.compareTo = compareTo; - this.oldPin = oldPin; - } + /** + * @param pinSpec + * @param enterButton + * @param compareTo + * enable enterButton if this pinDocument's pin equals to + * compareTo's pin. may be null + */ + public PINDocument(int minLength, int maxLength, String pattern, JButton enterButton, Document compareTo) { + this(minLength, maxLength, pattern, enterButton); + this.compareTo = compareTo; + } + + /** + * @param pinSpec + * @param enterButton + * may be null + * @param compareTo + * enable enterButton if this pinDocument's pin equals to + * compareTo's pin. may be null + * @param oldPin + * enable enterButton if oldPin meets the pinSpec pin length + * requirements, may be null + */ + public PINDocument(int minLength, int maxLength, String pattern, + JButton enterButton, Document compareTo, Document oldPin) { + this(minLength, maxLength, pattern, enterButton); + this.compareTo = compareTo; + this.oldPin = oldPin; + } @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { - if (pinSpec.getMaxLength() < 0 || pinSpec.getMaxLength() >= (getLength() + str.length())) { + if (maxLength < 0 || maxLength >= (getLength() + str.length())) { boolean matches = true; for (int i = 0; i < str.length(); i++) { Matcher m = pinPattern.matcher(str.substring(i, i + 1)); @@ -87,8 +97,8 @@ class PINDocument extends PlainDocument { } if (enterButton != null) { enterButton.setEnabled( - (oldPin == null || oldPin.getLength() >= pinSpec.getMinLength()) && - getLength() >= pinSpec.getMinLength() && + (oldPin == null || oldPin.getLength() >= minLength) && + getLength() >= minLength && compare()); } } @@ -98,8 +108,8 @@ class PINDocument extends PlainDocument { super.remove(offs, len); if (enterButton != null) { enterButton.setEnabled( - (oldPin == null || oldPin.getLength() >= pinSpec.getMinLength()) && - getLength() >= pinSpec.getMinLength() && + (oldPin == null || oldPin.getLength() >= minLength) && + getLength() >= minLength && compare()); } } -- 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 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 5 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 318 +++++++++++---------- .../main/java/at/gv/egiz/bku/gui/MimeFilter.java | 110 ------- .../at/gv/egiz/bku/gui/SecureViewerDialog.java | 146 ++++------ .../java/at/gv/egiz/bku/gui/viewer/MimeFilter.java | 115 ++++++++ .../bku/gui/viewer/SecureViewerSaveDialog.java | 120 ++++++++ 6 files changed, 450 insertions(+), 364 deletions(-) delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index e4af6443..91c91dcb 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -46,7 +46,7 @@ public interface BKUGUIFacade { public static final String DEFAULT_BACKGROUND = "/at/gv/egiz/bku/gui/chip32.png"; public static final String DEFAULT_ICON = "/at/gv/egiz/bku/gui/chiperling105.png"; public static final String HELP_IMG = "/at/gv/egiz/bku/gui/help.png"; - public static final String HELP_IMG_FOCUS = "/at/gv/egiz/bku/gui/help_focus.png"; + public static final String HELP_IMG_FOCUS = "/at/gv/egiz/bku/gui/help.png"; //help_focus.png"; public static final String HASHDATA_FONT = "Monospaced"; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; @@ -56,6 +56,7 @@ public interface BKUGUIFacade { public static final String TITLE_CARDPIN = "title.cardpin"; public static final String TITLE_SIGN = "title.sign"; public static final String TITLE_ERROR = "title.error"; + public static final String TITLE_WARNING = "title.warning"; public static final String TITLE_ENTRY_TIMEOUT = "title.entry.timeout"; public static final String TITLE_RETRY = "title.retry"; public static final String TITLE_WAIT = "title.wait"; @@ -79,6 +80,8 @@ public interface BKUGUIFacade { public static final String MESSAGE_HASHDATALINK_FOCUS = "hashdatalink.focus"; public static final String MESSAGE_HASHDATALINK_TINY_FOCUS = "hashdatalink.tiny.focus"; public static final String MESSAGE_HASHDATALIST = "hashdatalist"; + public static final String MESSAGE_HASHDATA_VIEWER = "hashdata.viewer"; + public static final String MESSAGE_UNSUPPORTED_MIMETYPE = "unsupported.mimetype"; public static final String MESSAGE_RETRIES = "retries"; public static final String MESSAGE_LAST_RETRY = "retries.last"; public static final String MESSAGE_RETRIES_PINPAD = "retries.pinpad"; 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 20fe4f56..baffb3fd 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 @@ -19,6 +19,7 @@ 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.bku.gui.viewer.SecureViewerSaveDialog; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; import java.awt.Color; @@ -1384,26 +1385,34 @@ public class BKUGUIImpl implements BKUGUIFacade { new Object[] {"no signature data provided"}, backListener, backCommand); } else if (dataToBeSigned.size() == 1) { - try { - log.debug("[" + Thread.currentThread().getName() + "] scheduling secure viewer"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - 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); + //TODO pull out (see also SignedReferencesSelectionListener) + if (SecureViewerDialog.SUPPORTED_MIME_TYPES.contains(dataToBeSigned.get(0).getMimeType())) { + try { + log.debug("[" + Thread.currentThread().getName() + "] scheduling secure viewer"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + try { + showMessageDialog(TITLE_HASHDATA, MESSAGE_HASHDATA_VIEWER); + showSecureViewer(dataToBeSigned.get(0), backListener, backCommand); + } catch (FontProviderException ex) { + log.error("failed to display secure viewer", ex); + showErrorDialog(ERR_VIEWER, new Object[] {ex.getMessage()}, backListener, backCommand); + } } - } - }); - - } catch (Exception ex) { //InterruptedException InvocationTargetException - log.error("Failed to display secure viewer: " + ex.getMessage()); - log.trace(ex); - showErrorDialog(ERR_UNKNOWN, null, backListener, backCommand); + }); + + } catch (Exception ex) { //InterruptedException InvocationTargetException + log.error("Failed to display secure viewer: " + ex.getMessage()); + log.trace(ex); + showErrorDialog(ERR_UNKNOWN, null, backListener, backCommand); + } + } else { + log.debug("[" + Thread.currentThread().getName() + "] mime-type not supported by secure viewer, scheduling save dialog"); + showMessageDialog(TITLE_HASHDATA, MESSAGE_UNSUPPORTED_MIMETYPE); + SecureViewerSaveDialog.showSaveDialog(dataToBeSigned.get(0), messages, backListener, backCommand); } } else { showSignedReferencesListDialog(dataToBeSigned, backListener, backCommand); @@ -1412,30 +1421,48 @@ public class BKUGUIImpl implements BKUGUIFacade { /** * has to be called from event dispatcher thread - * This method blocks until the dialog's close button is pressed. * @param hashDataText * @param saveListener * @param saveCommand */ - private void showSecureViewer(HashDataInput dataToBeSigned) throws FontProviderException { +// private void showSecureViewer(HashDataInput dataToBeSigned) throws FontProviderException { +// +// log.debug("[" + Thread.currentThread().getName() + "] show secure viewer"); +// if (secureViewer == null) { +// secureViewer = new SecureViewerDialog(null, messages, +// 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. +// Window window = SwingUtilities.getWindowAncestor(contentPane); +// if (window != null && window.isAlwaysOnTop()) { +// log.debug("make secureViewer alwaysOnTop"); +// secureViewer.setAlwaysOnTop(true); +// } +// } +// secureViewer.setContent(dataToBeSigned); +// log.trace("show secure viewer returned"); +// } + private void showSecureViewer(HashDataInput dataToBeSigned, ActionListener closeListener, String closeCommand) throws FontProviderException { log.debug("[" + Thread.currentThread().getName() + "] show secure viewer"); - if (secureViewer == null) { - secureViewer = new SecureViewerDialog(null, messages, - 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. - Window window = SwingUtilities.getWindowAncestor(contentPane); - if (window != null && window.isAlwaysOnTop()) { - log.debug("make secureViewer alwaysOnTop"); - secureViewer.setAlwaysOnTop(true); - } + SecureViewerDialog secureViewer = new SecureViewerDialog(null, messages, + closeListener, closeCommand, + 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. + Window window = SwingUtilities.getWindowAncestor(contentPane); + if (window != null && window.isAlwaysOnTop()) { + log.debug("make secureViewer alwaysOnTop"); + secureViewer.setAlwaysOnTop(true); } secureViewer.setContent(dataToBeSigned); - log.trace("show secure viewer returned"); + log.trace("viewer setContent returned"); } + + private void showSignedReferencesListDialog(final List signedReferences, final ActionListener backListener, final String backCommand) { @@ -1468,44 +1495,10 @@ public class BKUGUIImpl implements BKUGUIFacade { hashDataTable.setDefaultRenderer(HashDataInput.class, new HyperlinkRenderer(renderRefId)); hashDataTable.setTableHeader(null); - // not possible to add mouse listener to TableCellRenderer - hashDataTable.addMouseMotionListener(new MouseMotionAdapter() { - - @Override - public void mouseMoved(MouseEvent e) { - if (hashDataTable.columnAtPoint(e.getPoint()) == 0) { - hashDataTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } else { - hashDataTable.setCursor(Cursor.getDefaultCursor()); - } - } - }); + hashDataTable.addMouseMotionListener(new SignedReferencesMouseMotionListener(hashDataTable)); hashDataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - hashDataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - - @Override - public void valueChanged(final ListSelectionEvent e) { - //invoke later to allow thread to paint selection background - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - ListSelectionModel lsm = (ListSelectionModel) e.getSource(); - int selectionIdx = lsm.getMinSelectionIndex(); - if (selectionIdx >= 0) { - final HashDataInput selection = signedReferences.get(selectionIdx); - try { - showSecureViewer(selection); - } catch (FontProviderException ex) { - log.error("failed to display secure viewer", ex); - showErrorDialog(ERR_VIEWER, new Object[] {ex.getMessage()}, backListener, backCommand); - } - } - } - }); - } - }); + hashDataTable.getSelectionModel().addListSelectionListener(new SignedReferencesSelectionListener(signedReferences, backListener, backCommand)); JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); @@ -1560,97 +1553,106 @@ public class BKUGUIImpl implements BKUGUIFacade { }); } + + /** - * @param okListener may be null + * not possible to add mouse listener to TableCellRenderer + * to change cursor on specific columns only, use table.columnAtPoint(e.getPoint()) + * */ -// private void showSaveDialog(final List signedRefs, -// final ActionListener okListener, final String okCommand) { -// -// log.debug("scheduling save dialog"); -// -// SwingUtilities.invokeLater(new Runnable() { -// -// @Override -// public void run() { -// -// log.debug("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); -// if (signedRefs.size() == 1) { -// fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVE)); -// fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); -// String mimeType = signedRefs.get(0).getMimeType(); -// MimeFilter mimeFilter = new MimeFilter(mimeType, messages); -// fileDialog.setFileFilter(mimeFilter); -// String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); -// fileDialog.setSelectedFile(new File(userHome, filename)); -// } else { -// fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVEDIR)); -// fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); -// } -// -// //parent contentPane -> placed over applet -// switch (fileDialog.showSaveDialog(fileDialog)) { -// case JFileChooser.APPROVE_OPTION: -// File f = fileDialog.getSelectedFile(); -// for (HashDataInput hashDataInput : signedRefs) { -// String mimeType = hashDataInput.getMimeType(); -// String id = hashDataInput.getReferenceId(); -// File file; -// if (f.isDirectory()) { -// String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); -// file = new File(f, filename); -// } else { -// file = f; -// } -// if (file.exists()) { -// String ovrwrt = getMessage(MESSAGE_OVERWRITE); -// int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), getMessage(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); -// if (overwrite != JOptionPane.OK_OPTION) { -// continue; -// } -// } -// 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()); -// showErrorDialog(ERR_WRITE_HASHDATA, new Object[] {ex.getMessage()}, null, null); -// ex.printStackTrace(); -// } finally { -// try { -// 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)); -// } -// } -// }); -// } + private class SignedReferencesMouseMotionListener extends MouseMotionAdapter { + + JTable hashDataTable; + + public SignedReferencesMouseMotionListener(JTable table) { + this.hashDataTable = table; + } + + @Override + public void mouseMoved(MouseEvent e) { +// if (hashDataTable.columnAtPoint(e.getPoint()) == 0) { + hashDataTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } + } + + /////////// + // SignedReferencesList (TODO pull out) + + public class SignedReferencesSelectionListener implements ListSelectionListener { + + List signedReferences; + ActionListener backListener; + String backCommand; + + public SignedReferencesSelectionListener(List signedReferences, ActionListener backListener, String backCommand) { + this.signedReferences = signedReferences; + this.backListener = backListener; + this.backCommand = backCommand; + } + + @Override + public void valueChanged(ListSelectionEvent event) { + + if (event.getValueIsAdjusting()) { + return; + } + + ListSelectionModel lsm = (ListSelectionModel) event.getSource(); + int selectionIdx = lsm.getMinSelectionIndex(); + + log.debug("[" + Thread.currentThread().getName() + "] reference " + selectionIdx + " selected"); + + if (selectionIdx >= 0) { + final HashDataInput selection = signedReferences.get(selectionIdx); + final SignedReferencesListDisplayer backToListListener = new SignedReferencesListDisplayer(signedReferences, backListener, backCommand); + + if (SecureViewerDialog.SUPPORTED_MIME_TYPES.contains(selection.getMimeType())) { + log.debug("[" + Thread.currentThread().getName() + "] scheduling secure viewer dialog"); + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + try { + showMessageDialog(TITLE_HASHDATA, MESSAGE_HASHDATA_VIEWER); + showSecureViewer(selection, backToListListener, null); +// SecureViewerDialog.showSecureViewer(selection, messages, fontProvider, helpMouseListener.getActionListener(), false); + } catch (FontProviderException ex) { + log.error("failed to display secure viewer", ex); + showErrorDialog(BKUGUIFacade.ERR_VIEWER, new Object[] {ex.getMessage()}, backToListListener, null); + } + + } + }); + } else { + log.debug("[" + Thread.currentThread().getName() + "] mime-type not supported by secure viewer, scheduling save dialog"); + showMessageDialog(BKUGUIFacade.TITLE_HASHDATA, BKUGUIFacade.MESSAGE_UNSUPPORTED_MIMETYPE); + SecureViewerSaveDialog.showSaveDialog(selection, messages, backToListListener, null); + } + } + } + + /** + * ActionListener that returns to signed references list + */ + private class SignedReferencesListDisplayer implements ActionListener { + List sr; + ActionListener bl; + String bc; + + public SignedReferencesListDisplayer(List signedReferences, ActionListener backListener, String backCommand) { + sr = signedReferences; + bl = backListener; + bc = backCommand; + } + + @Override + public void actionPerformed(ActionEvent e) { +// log.debug("[" + Thread.currentThread().getName() + "] displaying signed references list"); + showSignedReferencesListDialog(sr, bl, bc); + } + } + } + //////////////////////////////////////////////////////////////////////////// // UTILITY METHODS diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java deleted file mode 100644 index 4b48081a..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java +++ /dev/null @@ -1,110 +0,0 @@ -/* -* 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.io.File; -import java.util.ResourceBundle; -import javax.swing.filechooser.FileFilter; - -/** - * - * @author clemens - */ -class MimeFilter extends FileFilter { - - private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; - private static final String MIMETYPE_DESC_HTML = "mimetype.desc.html"; - private static final String MIMETYPE_DESC_XHTML = "mimetype.desc.xhtml"; - private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; - private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; - private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; - - protected String mimeType; - protected ResourceBundle messages; - - public MimeFilter(String mimeType, ResourceBundle messages) { - this.mimeType = mimeType; - this.messages = messages; - } - - @Override - public boolean accept(File f) { - - if (f.isDirectory()) { - return true; - } - - String ext = getExtension(f); - if ("text/xml".equals(mimeType)) { - return "xml".equalsIgnoreCase(ext); - } else if ("text/html".equals(mimeType)) { - return "html".equalsIgnoreCase(ext) || "htm".equalsIgnoreCase(ext); - } else if ("application/xhtml+xml".equals(mimeType)) { - return "xhtml".equalsIgnoreCase(ext); - } else if ("text/plain".equals(mimeType)) { - return "txt".equalsIgnoreCase(ext); - } else if ("application/pdf".equals(mimeType)) { - return "pdf".equalsIgnoreCase(ext); - } else { - return true; - } - } - - private String getExtension(File f) { - String ext = null; - String s = f.getName(); - int i = s.lastIndexOf('.'); - - if (i > 0 && i < s.length() - 1) { - ext = s.substring(i + 1).toLowerCase(); - } - return ext; - } - - @Override - public String getDescription() { - if ("text/xml".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_XML); - } else if ("text/html".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_HTML); - } else if ("application/xhtml+xml".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_XHTML); - } else if ("text/plain".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_TXT); - } else if ("application/pdf".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_PDF); - } else { - return messages.getString(MIMETYPE_DESC_BIN); - } - } - - public static String getExtension(String mimeType) { - if ("text/xml".equals(mimeType)) { - return ".xml"; - } else if ("text/html".equals(mimeType)) { - return ".html"; - } else if ("application/xhtml+xml".equals(mimeType)) { - return ".xhtml"; - } else if ("text/plain".equals(mimeType)) { - return ".txt"; - } else if ("application/pdf".equals(mimeType)) { - return ".pdf"; - } else { - return ".bin"; - } - } -} \ No newline at end of file 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)); - } - } - }); - } } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java new file mode 100644 index 00000000..c0385dce --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java @@ -0,0 +1,115 @@ +/* +* 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.io.File; +import java.util.ResourceBundle; +import javax.swing.filechooser.FileFilter; + +/** + * + * @author clemens + */ +class MimeFilter extends FileFilter { + + private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; + private static final String MIMETYPE_DESC_HTML = "mimetype.desc.html"; + private static final String MIMETYPE_DESC_XHTML = "mimetype.desc.xhtml"; + private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; + private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; + private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; + private static final String MIMETYPE_DESC_UNKNOWN = "mimetype.desc.unknown"; + + protected String mimeType; + protected ResourceBundle messages; + + public MimeFilter(String mimeType, ResourceBundle messages) { + this.mimeType = mimeType; + this.messages = messages; + } + + @Override + public boolean accept(File f) { + + if (f.isDirectory()) { + return true; + } + + String ext = getExtension(f); + if ("text/xml".equals(mimeType)) { + return "xml".equalsIgnoreCase(ext); + } else if ("text/html".equals(mimeType)) { + return "html".equalsIgnoreCase(ext) || "htm".equalsIgnoreCase(ext); + } else if ("application/xhtml+xml".equals(mimeType)) { + return "xhtml".equalsIgnoreCase(ext); + } else if ("text/plain".equals(mimeType)) { + return "txt".equalsIgnoreCase(ext); + } else if ("application/pdf".equals(mimeType)) { + return "pdf".equalsIgnoreCase(ext); + } else { + return true; + } + } + + private String getExtension(File f) { + String ext = null; + String s = f.getName(); + int i = s.lastIndexOf('.'); + + if (i > 0 && i < s.length() - 1) { + ext = s.substring(i + 1).toLowerCase(); + } + return ext; + } + + @Override + public String getDescription() { + if ("text/xml".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_XML); + } else if ("text/html".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_HTML); + } else if ("application/xhtml+xml".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_XHTML); + } else if ("text/plain".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_TXT); + } else if ("application/pdf".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_PDF); + } else if ("application/octet-stream".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_BIN); + } else { + return messages.getString(MIMETYPE_DESC_UNKNOWN); + } + } + + public static String getExtension(String mimeType) { + if ("text/xml".equals(mimeType)) { + return ".xml"; + } else if ("text/html".equals(mimeType)) { + return ".html"; + } else if ("application/xhtml+xml".equals(mimeType)) { + return ".xhtml"; + } else if ("text/plain".equals(mimeType)) { + return ".txt"; + } else if ("application/pdf".equals(mimeType)) { + return ".pdf"; + } else if ("application/octet-stream".equals(mimeType)) { + return ".bin"; + } else { + return ""; + } + } +} \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java new file mode 100644 index 00000000..40133f95 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java @@ -0,0 +1,120 @@ +package at.gv.egiz.bku.gui.viewer; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.Locale; +import java.util.ResourceBundle; + +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.stal.HashDataInput; + +public class SecureViewerSaveDialog { + + protected static final Log log = LogFactory.getLog(SecureViewerSaveDialog.class); + + public static void showSaveDialog(final HashDataInput hashDataInput, final ResourceBundle messages, + 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) { + break; + } + } + 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 5af9b75dccc1b52d1382fe0f2df30affd509f5b9 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 24 Nov 2009 18:48:00 +0000 Subject: Filenames derived from reference URI git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@553 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../java/at/gv/egiz/bku/gui/HyperlinkRenderer.java | 10 ++-- .../java/at/gv/egiz/bku/gui/viewer/MimeFilter.java | 56 ++-------------------- .../java/at/gv/egiz/bku/gui/viewer/MimeTypes.java | 53 ++++++++++++++++++++ .../bku/gui/viewer/SecureViewerSaveDialog.java | 5 +- 4 files changed, 66 insertions(+), 58 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeTypes.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java index 16024fcc..6af22815 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java @@ -39,10 +39,14 @@ public class HyperlinkRenderer extends DefaultTableCellRenderer { @Override protected void setValue(Object value) { String hrefText; - if (renderReferenceId) { - hrefText = ((HashDataInput) value).getReferenceId(); + if (((HashDataInput) value).getFilename() != null) { + hrefText = ((HashDataInput) value).getFilename(); } else { - hrefText = ((HashDataInput) value).getMimeType(); + if (renderReferenceId) { + hrefText = ((HashDataInput) value).getReferenceId(); + } else { + hrefText = ((HashDataInput) value).getMimeType(); + } } super.setText("" + hrefText + ""); setForeground(BKUGUIFacade.HYPERLINK_COLOR); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java index c0385dce..5d64eb4f 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeFilter.java @@ -26,14 +26,6 @@ import javax.swing.filechooser.FileFilter; */ class MimeFilter extends FileFilter { - private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; - private static final String MIMETYPE_DESC_HTML = "mimetype.desc.html"; - private static final String MIMETYPE_DESC_XHTML = "mimetype.desc.xhtml"; - private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; - private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; - private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; - private static final String MIMETYPE_DESC_UNKNOWN = "mimetype.desc.unknown"; - protected String mimeType; protected ResourceBundle messages; @@ -48,21 +40,7 @@ class MimeFilter extends FileFilter { if (f.isDirectory()) { return true; } - - String ext = getExtension(f); - if ("text/xml".equals(mimeType)) { - return "xml".equalsIgnoreCase(ext); - } else if ("text/html".equals(mimeType)) { - return "html".equalsIgnoreCase(ext) || "htm".equalsIgnoreCase(ext); - } else if ("application/xhtml+xml".equals(mimeType)) { - return "xhtml".equalsIgnoreCase(ext); - } else if ("text/plain".equals(mimeType)) { - return "txt".equalsIgnoreCase(ext); - } else if ("application/pdf".equals(mimeType)) { - return "pdf".equalsIgnoreCase(ext); - } else { - return true; - } + return MimeTypes.getExtension(mimeType).equalsIgnoreCase(getExtension(f)); } private String getExtension(File f) { @@ -78,38 +56,10 @@ class MimeFilter extends FileFilter { @Override public String getDescription() { - if ("text/xml".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_XML); - } else if ("text/html".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_HTML); - } else if ("application/xhtml+xml".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_XHTML); - } else if ("text/plain".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_TXT); - } else if ("application/pdf".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_PDF); - } else if ("application/octet-stream".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_BIN); - } else { - return messages.getString(MIMETYPE_DESC_UNKNOWN); - } + return messages.getString(MimeTypes.getDescriptionKey(mimeType)); } public static String getExtension(String mimeType) { - if ("text/xml".equals(mimeType)) { - return ".xml"; - } else if ("text/html".equals(mimeType)) { - return ".html"; - } else if ("application/xhtml+xml".equals(mimeType)) { - return ".xhtml"; - } else if ("text/plain".equals(mimeType)) { - return ".txt"; - } else if ("application/pdf".equals(mimeType)) { - return ".pdf"; - } else if ("application/octet-stream".equals(mimeType)) { - return ".bin"; - } else { - return ""; - } + return MimeTypes.getExtension(mimeType); } } \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeTypes.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeTypes.java new file mode 100644 index 00000000..4500fa71 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/MimeTypes.java @@ -0,0 +1,53 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.gui.viewer; + +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author clemens + */ +public class MimeTypes { + + private static final Map FILE_EXTENSIONS = new HashMap() {{ + put("application/msword", ".doc"); + put("application/octet-stream", ".bin"); + put("application/pdf", ".pdf"); + put("application/xhtml+xml", ".xhtml"); + put("text/html", ".html"); + put("text/plain", ".txt"); + put("text/xml", ".xml"); + }}; + + private static final Map DESCRIPTIONS = new HashMap() {{ + put("application/msword", "mimetype.desc.doc"); + put("application/octet-stream", "mimetype.desc.bin"); + put("application/pdf", "mimetype.desc.pdf"); + put("application/xhtml+xml", "mimetype.desc.xhtml"); + put("text/html", "mimetype.desc.html"); + put("text/plain", "mimetype.desc.txt"); + put("text/xml", "mimetype.desc.xml"); + }}; + + public static String getExtension(String mimetype) { + if (FILE_EXTENSIONS.containsKey(mimetype)) { + return FILE_EXTENSIONS.get(mimetype); + } + return ""; + } + + /** + * @return bundle key to be resolved in message resource bundle + */ + public static String getDescriptionKey(String mimetype) { + if (DESCRIPTIONS.containsKey(mimetype)) { + return DESCRIPTIONS.get(mimetype); + } + return "mimetype.desc.unknown"; + } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java index 40133f95..3303d4ef 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/SecureViewerSaveDialog.java @@ -52,8 +52,9 @@ public class SecureViewerSaveDialog { String mimeType = hashDataInput.getMimeType(); MimeFilter mimeFilter = new MimeFilter(mimeType, messages); fileDialog.setFileFilter(mimeFilter); - String filename = messages - .getString(BKUGUIFacade.SAVE_HASHDATAINPUT_PREFIX) + String filename = (hashDataInput.getFilename() != null) ? + hashDataInput.getFilename() : + messages.getString(BKUGUIFacade.SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); fileDialog.setSelectedFile(new File(userHome, filename)); -- 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 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 28 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 765 +++++++++------------ .../main/java/at/gv/egiz/bku/gui/PinDocument.java | 125 +--- .../at/gv/egiz/bku/gui/SecureViewerDialog.java | 118 ++-- 4 files changed, 436 insertions(+), 600 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 91c91dcb..1e23c64c 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -16,7 +16,7 @@ */ package at.gv.egiz.bku.gui; -import at.gv.egiz.stal.HashDataInput; + import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.smcc.PINSpec; import java.awt.Color; import java.awt.event.ActionListener; @@ -53,14 +53,15 @@ public interface BKUGUIFacade { public static final String TITLE_WELCOME = "title.welcome"; public static final String TITLE_INSERTCARD = "title.insertcard"; public static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; - public static final String TITLE_CARDPIN = "title.cardpin"; + public static final String TITLE_VERIFY_PIN = "title.verify.pin"; public static final String TITLE_SIGN = "title.sign"; + public static final String TITLE_VERIFY_PINPAD = "title.verify.pinpad"; public static final String TITLE_ERROR = "title.error"; public static final String TITLE_WARNING = "title.warning"; public static final String TITLE_ENTRY_TIMEOUT = "title.entry.timeout"; public static final String TITLE_RETRY = "title.retry"; public static final String TITLE_WAIT = "title.wait"; - public static final String TITLE_HASHDATA = "title.hashdata"; + public static final String TITLE_SIGNATURE_DATA = "title.signature.data"; public static final String WINDOWTITLE_SAVE = "windowtitle.save"; public static final String WINDOWTITLE_ERROR = "windowtitle.error"; public static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; @@ -75,6 +76,7 @@ public interface BKUGUIFacade { public static final String MESSAGE_CARD_NOT_SUPPORTED = "cardnotsupported"; public static final String MESSAGE_ENTERPIN = "enterpin"; public static final String MESSAGE_ENTERPIN_PINPAD = "enterpin.pinpad"; + public static final String MESSAGE_ENTERPIN_PINPAD_DIRECT = "enterpin.pinpad.direct"; public static final String MESSAGE_HASHDATALINK = "hashdatalink"; public static final String MESSAGE_HASHDATALINK_TINY = "hashdatalink.tiny"; public static final String MESSAGE_HASHDATALINK_FOCUS = "hashdatalink.focus"; @@ -96,8 +98,9 @@ public interface BKUGUIFacade { public static final String HELP_WAIT = "help.wait"; public static final String HELP_CARDNOTSUPPORTED = "help.cardnotsupported"; public static final String HELP_INSERTCARD = "help.insertcard"; - public static final String HELP_CARDPIN = "help.cardpin"; + public static final String HELP_VERIFY_PIN = "help.cardpin"; public static final String HELP_SIGNPIN = "help.signpin"; + public static final String HELP_PINPAD = "help.pinpad"; public static final String HELP_RETRY = "help.retry"; public static final String HELP_HASHDATA = "help.hashdata"; public static final String HELP_HASHDATALIST = "help.hashdatalist"; @@ -111,6 +114,18 @@ public interface BKUGUIFacade { public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; public static final String ALT_HELP = "alt.help"; + public void showEnterPINDirect(PINSpec spec, int retries); + + public void showEnterPIN(PINSpec spec, int retries); + + public void showSignatureDataDialog(PINSpec spec, ActionListener listener, String string, ActionListener aThis0, String string0, ActionListener aThis1, String string1); + + public void correctionButtonPressed(); + + public void allKeysCleared(); + + public void validKeyPressed(); + public enum Style { tiny, simple, advanced }; /** @@ -119,7 +134,7 @@ public interface BKUGUIFacade { */ public Locale getLocale(); - public void showCardPINDialog(PINSpec pinSpec, int numRetries, + public void showVerifyPINDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); @@ -128,9 +143,6 @@ public interface BKUGUIFacade { ActionListener cancelListener, String cancelCommand, ActionListener viewerListener, String viewerCommand); - public void showPinpadSignaturePINDialog(PINSpec pinSpec, int numRetries, - ActionListener viewerListener, String viewerCommand); - public char[] getPin(); /** 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 baffb3fd..3fc631c3 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 @@ -93,6 +93,7 @@ public class BKUGUIImpl implements BKUGUIFacade { protected JLabel switchFocusDummyLabel; /** remember the pinfield to return to worker */ protected JPasswordField pinField; + protected JPasswordField pinpadPINField; protected int buttonSize; @@ -360,221 +361,27 @@ public class BKUGUIImpl implements BKUGUIFacade { return messages.containsKey(key); } -// @Override -// public void showWelcomeDialog() { -// -// log.debug("scheduling welcome dialog"); -// -// SwingUtilities.invokeLater(new Runnable() { -// -// @Override -// public void run() { -// -// log.debug("show welcome dialog"); -// -// mainPanel.removeAll(); -// buttonPanel.removeAll(); -// -// helpListener.setHelpTopic(HELP_WELCOME); -// -// JLabel welcomeMsgLabel = new JLabel(); -// welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); -// -// if (renderHeaderPanel) { -// titleLabel.setText(getMessage(TITLE_WELCOME)); -// welcomeMsgLabel.setText(getMessage(MESSAGE_WAIT)); -// } else { -// welcomeMsgLabel.setText(getMessage(TITLE_WELCOME)); -// } -// -// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); -// mainPanel.setLayout(mainPanelLayout); -// -// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() -// .addComponent(welcomeMsgLabel); -// GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(welcomeMsgLabel); -// if (!renderHeaderPanel) { -// messageHorizontal -// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) -// .addComponent(helpLabel); -// messageVertical -// .addComponent(helpLabel); -// } -// -// mainPanelLayout.setHorizontalGroup(messageHorizontal); -// mainPanelLayout.setVerticalGroup(messageVertical); -// -// contentPanel.validate(); -// -// } -// }); -// } - -// @Override -// public void showInsertCardDialog( -// final ActionListener cancelListener, final String cancelCommand) { -// -// log.debug("scheduling insert card dialog"); -// -// SwingUtilities.invokeLater(new Runnable() { -// -// @Override -// public void run() { -// -// log.debug("show insert card dialog"); -// -// mainPanel.removeAll(); -// buttonPanel.removeAll(); -// -// if (renderHeaderPanel) { -// titleLabel.setText(getMessage(TITLE_INSERTCARD)); -// } -// -// helpListener.setHelpTopic(HELP_INSERTCARD); -// -// JLabel insertCardMsgLabel = new JLabel(); -// insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); -// insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); -// -// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); -// mainPanel.setLayout(mainPanelLayout); -// -// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() -// .addComponent(insertCardMsgLabel); -// GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup() -// .addComponent(insertCardMsgLabel); -// -// if (!renderHeaderPanel) { -// messageHorizontal -// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) -// .addComponent(helpLabel); -// messageVertical -// .addComponent(helpLabel); -// } -// -// mainPanelLayout.setHorizontalGroup(messageHorizontal); -// mainPanelLayout.setVerticalGroup(messageVertical); -// -// if (renderCancelButton) { -// JButton cancelButton = new JButton(); -// cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); -// cancelButton.setText(getMessage(BUTTON_CANCEL)); -// cancelButton.addActionListener(cancelListener); -// cancelButton.setActionCommand(cancelCommand); -// -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addComponent(cancelButton)); -// } -// -// contentPanel.validate(); -// } -// }); -// } - - /** - * only difference to showInsertCard: title text: card not supported - * @param cancelListener - * @param cancelCommand - */ -// @Override -// public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { -// -// log.debug("scheduling card not supported dialog"); -// -// SwingUtilities.invokeLater(new Runnable() { -// -// @Override -// public void run() { -// -// log.debug("show card not supported dialog"); -// -// mainPanel.removeAll(); -// buttonPanel.removeAll(); -// -// JLabel insertCardMsgLabel = new JLabel(); -// insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); -// -// if (renderHeaderPanel) { -// titleLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); -// insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); -// } else { -// insertCardMsgLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); -// } -// -// helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); -// -// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); -// mainPanel.setLayout(mainPanelLayout); -// -// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() -// .addComponent(insertCardMsgLabel); -// GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(insertCardMsgLabel); -// if (!renderHeaderPanel) { -// messageHorizontal -// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) -// .addComponent(helpLabel); -// messageVertical -// .addComponent(helpLabel); -// } -// -// mainPanelLayout.setHorizontalGroup(messageHorizontal); -// mainPanelLayout.setVerticalGroup(messageVertical); -// -// if (renderCancelButton) { -// JButton cancelButton = new JButton(); -// cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); -// cancelButton.setText(getMessage(BUTTON_CANCEL)); -// cancelButton.addActionListener(cancelListener); -// cancelButton.setActionCommand(cancelCommand); -// -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addComponent(cancelButton)); -// } -// -// contentPanel.validate(); -// } -// }); -// } - @Override - public void showCardPINDialog(final PINSpec pinSpec, final int numRetries, + public void showVerifyPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { - log.debug("scheduling card-pin dialog"); + log.debug("scheduling verify pin dialog"); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - log.debug("[" + Thread.currentThread().getName() + "] show card-pin dialog"); + log.debug("[" + Thread.currentThread().getName() + "] show verify pin dialog"); mainPanel.removeAll(); buttonPanel.removeAll(); if (renderHeaderPanel) { if (numRetries < 0) { - String cardpinTitle = getMessage(TITLE_CARDPIN); - titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); + String verifyTitle = getMessage(TITLE_VERIFY_PIN); + titleLabel.setText(MessageFormat.format(verifyTitle, new Object[]{pinSpec.getLocalizedName()})); } else { titleLabel.setText(getMessage(TITLE_RETRY)); } @@ -615,8 +422,8 @@ public class BKUGUIImpl implements BKUGUIFacade { } else { infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); } - helpMouseListener.setHelpTopic(HELP_CARDPIN); - helpKeyListener.setHelpTopic(HELP_CARDPIN); + helpMouseListener.setHelpTopic(HELP_VERIFY_PIN); + helpKeyListener.setHelpTopic(HELP_VERIFY_PIN); } else { String retryPattern; if (numRetries < 2) { @@ -732,194 +539,346 @@ public class BKUGUIImpl implements BKUGUIFacade { }); } -// @Override -// public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { -// showCardPINDialog(pinSpec, -1, okListener, okCommand, cancelListener, cancelCommand); -// } -// -// @Override -// public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { -// showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); -// } + @Override + public void showEnterPINDirect(PINSpec pinSpec, int retries) { + if (retries < 0) { + showMessageDialog(TITLE_VERIFY_PINPAD, MESSAGE_ENTERPIN_PINPAD_DIRECT, new Object[] { + pinSpec.getLocalizedName(), pinSpec.getLocalizedLength() }); + } else { + showMessageDialog(TITLE_RETRY, MESSAGE_RETRIES, new Object[]{String.valueOf(retries) }); + } + } -// @Override -// public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { -// showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); -// } + @Override + public void showEnterPIN(final PINSpec pinSpec, final int retries) { + showEnterPIN(pinSpec, retries, TITLE_VERIFY_PINPAD, MESSAGE_ENTERPIN_PINPAD, null); + } - @Override - public void showPinpadSignaturePINDialog(final PINSpec pinSpec, final int numRetries, -// final ActionListener cancelListener, final String cancelCommand, - final ActionListener hashdataListener, final String hashdataCommand) { + protected void showEnterPIN(final PINSpec pinSpec, final int retries, final String titleKey, final String messageKey, final Object[] messageParams) { + log.debug("scheduling pinpad dialog"); - log.debug("scheduling pinpad signature-pin dialog"); + SwingUtilities.invokeLater(new Runnable() { - SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { - @Override - public void run() { + log.debug("[" + Thread.currentThread().getName() + "] show pinpad dialog"); - log.debug("[" + Thread.currentThread().getName() + "] show pinpad signature-pin dialog"); + mainPanel.removeAll(); + buttonPanel.removeAll(); - mainPanel.removeAll(); - buttonPanel.removeAll(); + if (renderHeaderPanel) { + if (retries < 0) { + titleLabel.setText(getMessage(titleKey)); + } else { + titleLabel.setText(getMessage(TITLE_RETRY)); + } + } - if (renderHeaderPanel) { - if (numRetries < 0) { - titleLabel.setText(getMessage(TITLE_SIGN)); - } else { - titleLabel.setText(getMessage(TITLE_RETRY)); - } - } + final JLabel infoLabel = new JLabel(); + if (retries < 0) { + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + infoLabel.setText(MessageFormat.format(getMessage(messageKey), messageParams)); + helpMouseListener.setHelpTopic(HELP_PINPAD); + helpKeyListener.setHelpTopic(HELP_PINPAD); + } else { + String retryPattern; + if (retries == 1) { + retryPattern = getMessage(MESSAGE_LAST_RETRY); + } else { + retryPattern = getMessage(MESSAGE_RETRIES); + } + infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(retries)})); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); + infoLabel.setForeground(ERROR_COLOR); + helpMouseListener.setHelpTopic(HELP_RETRY); + helpKeyListener.setHelpTopic(HELP_RETRY); + } + + JLabel pinLabel = new JLabel(); + pinLabel.setFont(pinLabel.getFont().deriveFont(pinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String pinName = getMessage(LABEL_PIN); + pinLabel.setText(MessageFormat.format(pinName, new Object[]{pinSpec.getLocalizedName()})); + + pinpadPINField = new JPasswordField(); + pinpadPINField.setText(""); + pinpadPINField.setEnabled(false); + + JLabel pinsizeLabel = new JLabel(); + pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); + pinsizeLabel.setText(MessageFormat.format(getMessage(LABEL_PINSIZE), pinSpec.getLocalizedLength())); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel); + + if (!renderHeaderPanel) { + infoHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; + infoVertical + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; + } + + // align pinfield and pinsize to the right + GroupLayout.Group pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING); + GroupLayout.SequentialGroup pinVertical = mainPanelLayout.createSequentialGroup(); + + if (pinLabelPos == PinLabelPosition.ABOVE) { + pinHorizontal + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(pinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(pinpadPINField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + pinVertical + .addComponent(pinLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinpadPINField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel); + } else { // PinLabelPosition.LEFT + pinHorizontal + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(pinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinpadPINField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + pinVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(pinLabel) + .addComponent(pinpadPINField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel); + } + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(infoHorizontal) + .addGroup(pinHorizontal)); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(pinVertical)); + + contentPanel.validate(); + } + }); + } + + @Override + public void showSignatureDataDialog(PINSpec spec, + final ActionListener enterPINListener, final String enterPINCommand, + final ActionListener cancelListener, final String cancelCommand, + final ActionListener hashdataListener, final String hashdataCommand) { + + log.debug("scheduling signature-data dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("[" + Thread.currentThread().getName() + "] show signature-data dialog"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (renderHeaderPanel) { + titleLabel.setText(getMessage(TITLE_SIGNATURE_DATA)); + } + + final JLabel infoLabel = new JLabel(); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (shortText) { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); + } else { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); + } + infoLabel.setFocusable(true); + infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + infoLabel.setForeground(HYPERLINK_COLOR); + infoLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent me) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e); + } + }); + + infoLabel.addKeyListener(new KeyAdapter() { + + @Override + public void keyPressed(KeyEvent e) { + + if(e.getKeyCode() == KeyEvent.VK_ENTER) { + ActionEvent e1 = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e1); + } + } + + }); + + infoLabel.addFocusListener(new FocusAdapter() { + + @Override + public void focusGained(FocusEvent e) { - final JLabel infoLabel = new JLabel(); - if (numRetries < 0) { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); if (shortText) { - infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); - } else { - infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); - } - infoLabel.setFocusable(true); - infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - infoLabel.setForeground(HYPERLINK_COLOR); - infoLabel.addMouseListener(new MouseAdapter() { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY_FOCUS)); + } else { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_FOCUS)); + } + } - @Override - public void mouseClicked(MouseEvent me) { - ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); - hashdataListener.actionPerformed(e); - } - }); - - infoLabel.addKeyListener(new KeyAdapter() { - - @Override - public void keyPressed(KeyEvent e) { - - if(e.getKeyCode() == KeyEvent.VK_ENTER) { - ActionEvent e1 = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); - hashdataListener.actionPerformed(e1); - } - } - - }); - - infoLabel.addFocusListener(new FocusAdapter() { - - @Override - public void focusGained(FocusEvent e) { - - if (shortText) { - infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY_FOCUS)); - } else { - infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_FOCUS)); - } - } - - @Override - public void focusLost(FocusEvent e) { - - if (shortText) { - infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); - } else { - infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); - } - - } - - }); - - helpMouseListener.setHelpTopic(HELP_SIGNPIN); - helpKeyListener.setHelpTopic(HELP_SIGNPIN); - } else { - String retryPattern; - if (numRetries < 2) { - retryPattern = getMessage(MESSAGE_LAST_RETRY); - } else { - retryPattern = getMessage(MESSAGE_RETRIES); - } - infoLabel.setFocusable(true); - infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); - infoLabel.setForeground(ERROR_COLOR); - helpMouseListener.setHelpTopic(HELP_RETRY); - helpKeyListener.setHelpTopic(HELP_RETRY); - } + @Override + public void focusLost(FocusEvent e) { - String msgPattern = getMessage(MESSAGE_ENTERPIN_PINPAD); - String msg = MessageFormat.format(msgPattern, new Object[] { - pinSpec.getLocalizedName(), pinSpec.getLocalizedLength() }); + if (shortText) { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); + } else { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); + } - JLabel msgLabel = new JLabel(); - msgLabel.setFont(msgLabel.getFont().deriveFont(msgLabel.getFont().getStyle() & ~Font.BOLD)); - msgLabel.setText(msg); + } - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); + }); - GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel); - GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel); + helpMouseListener.setHelpTopic(HELP_SIGNPIN); + helpKeyListener.setHelpTopic(HELP_SIGNPIN); - if (!renderHeaderPanel) { - infoHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(switchFocusDummyLabel) - .addComponent(helpLabel) - ; - infoVertical - .addComponent(switchFocusDummyLabel) - .addComponent(helpLabel) - ; - } + //TODO message panel - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(infoHorizontal) - .addComponent(msgLabel)); +// String msgPattern = getMessage(MESSAGE_ENTERPIN_PINPAD); +// String msg = MessageFormat.format(msgPattern, new Object[] { +// pinSpec.getLocalizedName(), pinSpec.getLocalizedLength() }); +// +// JLabel msgLabel = new JLabel(); +// msgLabel.setFont(msgLabel.getFont().deriveFont(msgLabel.getFont().getStyle() & ~Font.BOLD)); +// msgLabel.setText(msg); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(infoVertical) + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel); + + if (!renderHeaderPanel) { + infoHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; + infoVertical + .addComponent(switchFocusDummyLabel) + .addComponent(helpLabel) + ; + } + + mainPanelLayout.setHorizontalGroup( + infoHorizontal); +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(infoHorizontal) +// .addComponent(msgLabel)); + + mainPanelLayout.setVerticalGroup( + infoVertical); +// mainPanelLayout.createSequentialGroup() +// .addGroup(infoVertical) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(msgLabel)); + + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup(); + GroupLayout.Group buttonVertical; + + JButton enterPINButton = new JButton(); + enterPINButton.setFont(enterPINButton.getFont().deriveFont(enterPINButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + enterPINButton.setText(getMessage(BUTTON_SIGN)); + enterPINButton.setActionCommand(enterPINCommand); + enterPINButton.addActionListener(enterPINListener); + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + cancelButton.setText(getMessage(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + buttonHorizontal + .addComponent(enterPINButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(msgLabel)); - - //no cancel button (cancel via pinpad) -// if (renderCancelButton) { -// JButton cancelButton = new JButton(); -// cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); -// cancelButton.setText(getMessage(BUTTON_CANCEL)); -// cancelButton.setActionCommand(cancelCommand); -// cancelButton.addActionListener(cancelListener); -// -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() -// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); -// GroupLayout.SequentialGroup buttonVertical = buttonPanelLayout.createSequentialGroup() -// .addComponent(cancelButton); -// -// buttonPanelLayout.setHorizontalGroup(buttonHorizontal); -// buttonPanelLayout.setVerticalGroup(buttonVertical); -// } + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + ; + buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(enterPINButton) + .addComponent(cancelButton) + ; + } else { + buttonHorizontal + .addComponent(enterPINButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + ; + buttonVertical = buttonPanelLayout.createSequentialGroup() + .addComponent(enterPINButton) + ; + } - contentPanel.validate(); - } - }); + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); + buttonPanelLayout.setVerticalGroup(buttonVertical); + + contentPanel.validate(); + } + }); + } + + @Override + public void correctionButtonPressed() { + log.debug("[" + Thread.currentThread().getName() + "] correction button pressed"); + + if (pinpadPINField != null) { + String maskedPIN = pinpadPINField.getText(); + pinpadPINField.setText(maskedPIN.substring(0, maskedPIN.length() - 1)); + } + } + + @Override + public void allKeysCleared() { + log.debug("[" + Thread.currentThread().getName() + "] all keys cleared"); + + if (pinpadPINField != null) { + pinpadPINField.setText(""); + } + } + + @Override + public void validKeyPressed() { + log.debug("[" + Thread.currentThread().getName() + "] valid key pressed"); + + if (pinpadPINField != null) { + pinpadPINField.setText(pinpadPINField.getText() + '*'); } + } @Override public void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { -// showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); -// } -// -// private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { log.debug("scheduling signature-pin dialog"); @@ -1302,57 +1261,6 @@ public class BKUGUIImpl implements BKUGUIFacade { }); } -// @Override -// public void showWaitDialog(final String waitMessage) { -// -// log.debug("scheduling wait dialog"); -// -// SwingUtilities.invokeLater(new Runnable() { -// -// @Override -// public void run() { -// -// log.debug("show wait dialog"); -// -// mainPanel.removeAll(); -// buttonPanel.removeAll(); -// -// if (renderHeaderPanel) { -// titleLabel.setText(getMessage(TITLE_WAIT)); -// } -// -// helpListener.setHelpTopic(HELP_WAIT); -// -// JLabel waitMsgLabel = new JLabel(); -// waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); -// if (waitMessage != null) { -// waitMsgLabel.setText("" + waitMessage + ""); -// } else { -// waitMsgLabel.setText(getMessage(MESSAGE_WAIT)); -// } -// -// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); -// mainPanel.setLayout(mainPanelLayout); -// -// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() -// .addComponent(waitMsgLabel); -// GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(waitMsgLabel); -// -// if (!renderHeaderPanel) { -// messageHorizontal -// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) -// .addComponent(helpLabel); -// messageVertical -// .addComponent(helpLabel); -// } -// mainPanelLayout.setHorizontalGroup(messageHorizontal); -// mainPanelLayout.setVerticalGroup(messageVertical); -// -// contentPanel.validate(); -// } -// }); -// } @Override public char[] getPin() { @@ -1395,7 +1303,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { try { - showMessageDialog(TITLE_HASHDATA, MESSAGE_HASHDATA_VIEWER); + showMessageDialog(TITLE_SIGNATURE_DATA, MESSAGE_HASHDATA_VIEWER); showSecureViewer(dataToBeSigned.get(0), backListener, backCommand); } catch (FontProviderException ex) { log.error("failed to display secure viewer", ex); @@ -1411,7 +1319,7 @@ public class BKUGUIImpl implements BKUGUIFacade { } } else { log.debug("[" + Thread.currentThread().getName() + "] mime-type not supported by secure viewer, scheduling save dialog"); - showMessageDialog(TITLE_HASHDATA, MESSAGE_UNSUPPORTED_MIMETYPE); + showMessageDialog(TITLE_SIGNATURE_DATA, MESSAGE_UNSUPPORTED_MIMETYPE); SecureViewerSaveDialog.showSaveDialog(dataToBeSigned.get(0), messages, backListener, backCommand); } } else { @@ -1421,28 +1329,7 @@ public class BKUGUIImpl implements BKUGUIFacade { /** * has to be called from event dispatcher thread - * @param hashDataText - * @param saveListener - * @param saveCommand */ -// private void showSecureViewer(HashDataInput dataToBeSigned) throws FontProviderException { -// -// log.debug("[" + Thread.currentThread().getName() + "] show secure viewer"); -// if (secureViewer == null) { -// secureViewer = new SecureViewerDialog(null, messages, -// 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. -// Window window = SwingUtilities.getWindowAncestor(contentPane); -// if (window != null && window.isAlwaysOnTop()) { -// log.debug("make secureViewer alwaysOnTop"); -// secureViewer.setAlwaysOnTop(true); -// } -// } -// secureViewer.setContent(dataToBeSigned); -// log.trace("show secure viewer returned"); -// } private void showSecureViewer(HashDataInput dataToBeSigned, ActionListener closeListener, String closeCommand) throws FontProviderException { log.debug("[" + Thread.currentThread().getName() + "] show secure viewer"); @@ -1479,7 +1366,7 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanel.removeAll(); if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_HASHDATA)); + titleLabel.setText(getMessage(TITLE_SIGNATURE_DATA)); } helpMouseListener.setHelpTopic(HELP_HASHDATALIST); @@ -1613,7 +1500,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { try { - showMessageDialog(TITLE_HASHDATA, MESSAGE_HASHDATA_VIEWER); + showMessageDialog(TITLE_SIGNATURE_DATA, MESSAGE_HASHDATA_VIEWER); showSecureViewer(selection, backToListListener, null); // SecureViewerDialog.showSecureViewer(selection, messages, fontProvider, helpMouseListener.getActionListener(), false); } catch (FontProviderException ex) { @@ -1625,7 +1512,7 @@ public class BKUGUIImpl implements BKUGUIFacade { }); } else { log.debug("[" + Thread.currentThread().getName() + "] mime-type not supported by secure viewer, scheduling save dialog"); - showMessageDialog(BKUGUIFacade.TITLE_HASHDATA, BKUGUIFacade.MESSAGE_UNSUPPORTED_MIMETYPE); + showMessageDialog(BKUGUIFacade.TITLE_SIGNATURE_DATA, BKUGUIFacade.MESSAGE_UNSUPPORTED_MIMETYPE); SecureViewerSaveDialog.showSaveDialog(selection, messages, backToListListener, null); } } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java index 96032dc1..52a3d5fe 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java @@ -1,19 +1,19 @@ /* -* 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. -*/ + * 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.util.regex.Matcher; @@ -21,7 +21,6 @@ import java.util.regex.Pattern; import javax.swing.JButton; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; -import javax.swing.text.Document; import javax.swing.text.PlainDocument; /** @@ -31,16 +30,15 @@ import javax.swing.text.PlainDocument; class PINDocument extends PlainDocument { private static final long serialVersionUID = 1L; - protected Pattern pinPattern; protected int minLength; protected int maxLength; - protected JButton enterButton; - protected Document compareTo; - protected Document oldPin; public PINDocument(int minLength, int maxLength, String pattern, JButton enterButton) { + if (enterButton == null) { + throw new NullPointerException("OK button null"); + } if (pattern != null) { pinPattern = Pattern.compile(pattern); } else { @@ -51,73 +49,26 @@ class PINDocument extends PlainDocument { this.enterButton = enterButton; } - /** - * @param pinSpec - * @param enterButton - * @param compareTo - * enable enterButton if this pinDocument's pin equals to - * compareTo's pin. may be null - */ - public PINDocument(int minLength, int maxLength, String pattern, JButton enterButton, Document compareTo) { - this(minLength, maxLength, pattern, enterButton); - this.compareTo = compareTo; + @Override + public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { + if (maxLength < 0 || maxLength >= (getLength() + str.length())) { + boolean matches = true; + for (int i = 0; i < str.length(); i++) { + Matcher m = pinPattern.matcher(str.substring(i, i + 1)); + if (!m.matches()) { + matches = false; + } + } + if (matches) { + super.insertString(offs, str, a); + enterButton.setEnabled(getLength() >= minLength); + } + } } - /** - * @param pinSpec - * @param enterButton - * may be null - * @param compareTo - * enable enterButton if this pinDocument's pin equals to - * compareTo's pin. may be null - * @param oldPin - * enable enterButton if oldPin meets the pinSpec pin length - * requirements, may be null - */ - public PINDocument(int minLength, int maxLength, String pattern, - JButton enterButton, Document compareTo, Document oldPin) { - this(minLength, maxLength, pattern, enterButton); - this.compareTo = compareTo; - this.oldPin = oldPin; + @Override + public void remove(int offs, int len) throws BadLocationException { + super.remove(offs, len); + enterButton.setEnabled(getLength() >= minLength); } - - @Override - public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { - if (maxLength < 0 || maxLength >= (getLength() + str.length())) { - boolean matches = true; - for (int i = 0; i < str.length(); i++) { - Matcher m = pinPattern.matcher(str.substring(i, i + 1)); - if (!m.matches()) { - matches = false; - } - } - if (matches) { - super.insertString(offs, str, a); - } - } - if (enterButton != null) { - enterButton.setEnabled( - (oldPin == null || oldPin.getLength() >= minLength) && - getLength() >= minLength && - compare()); - } - } - - @Override - public void remove(int offs, int len) throws BadLocationException { - super.remove(offs, len); - if (enterButton != null) { - enterButton.setEnabled( - (oldPin == null || oldPin.getLength() >= minLength) && - getLength() >= minLength && - compare()); - } - } - - private boolean compare() throws BadLocationException { - if (compareTo == null) { - return true; - } - return compareTo.getText(0, compareTo.getLength()).equals(getText(0, getLength())); - } - } \ No newline at end of file +} 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 From d592f2a95096d4f234a24564b794c712359756fb Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 19 Jan 2010 12:10:37 +0000 Subject: clear pin after use bugfix correction/backspace button pinpadPinGUI git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@581 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 35 +++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui') 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 3fc631c3..e005836c 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 @@ -41,6 +41,8 @@ import java.text.MessageFormat; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -55,6 +57,8 @@ import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -93,7 +97,7 @@ public class BKUGUIImpl implements BKUGUIFacade { protected JLabel switchFocusDummyLabel; /** remember the pinfield to return to worker */ protected JPasswordField pinField; - protected JPasswordField pinpadPINField; + protected Document pinpadPIN; protected int buttonSize; @@ -600,9 +604,10 @@ public class BKUGUIImpl implements BKUGUIFacade { String pinName = getMessage(LABEL_PIN); pinLabel.setText(MessageFormat.format(pinName, new Object[]{pinSpec.getLocalizedName()})); - pinpadPINField = new JPasswordField(); + JPasswordField pinpadPINField = new JPasswordField(); pinpadPINField.setText(""); pinpadPINField.setEnabled(false); + pinpadPIN = pinpadPINField.getDocument(); JLabel pinsizeLabel = new JLabel(); pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); @@ -850,9 +855,11 @@ public class BKUGUIImpl implements BKUGUIFacade { public void correctionButtonPressed() { log.debug("[" + Thread.currentThread().getName() + "] correction button pressed"); - if (pinpadPINField != null) { - String maskedPIN = pinpadPINField.getText(); - pinpadPINField.setText(maskedPIN.substring(0, maskedPIN.length() - 1)); + if (pinpadPIN != null) { + try { + pinpadPIN.remove(0, 1); + } catch (BadLocationException ex) { + } } } @@ -860,8 +867,11 @@ public class BKUGUIImpl implements BKUGUIFacade { public void allKeysCleared() { log.debug("[" + Thread.currentThread().getName() + "] all keys cleared"); - if (pinpadPINField != null) { - pinpadPINField.setText(""); + if (pinpadPIN != null) { + try { + pinpadPIN.remove(0, pinpadPIN.getLength()); + } catch (BadLocationException ex) { + } } } @@ -869,8 +879,11 @@ public class BKUGUIImpl implements BKUGUIFacade { public void validKeyPressed() { log.debug("[" + Thread.currentThread().getName() + "] valid key pressed"); - if (pinpadPINField != null) { - pinpadPINField.setText(pinpadPINField.getText() + '*'); + if (pinpadPIN != null) { + try { + pinpadPIN.insertString(0, "*", null); + } catch (BadLocationException ex) { + } } } @@ -1265,8 +1278,8 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public char[] getPin() { if (pinField != null) { - char[] pin = pinField.getPassword(); - pinField = null; + char[] pin = pinField.getPassword(); //returns a copy + pinField = null; //garbage collect original pin (make sure to clear char[] after use) return pin; } return null; -- cgit v1.2.3