diff options
author | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2008-09-05 13:39:14 +0000 |
---|---|---|
committer | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2008-09-05 13:39:14 +0000 |
commit | 3808a5b4ec9d13c8cbb1b7fd95afa62c133342fd (patch) | |
tree | f6503574203cd102e5837cc53e61634a5f40f056 /BKUCommonGUI/src/main | |
parent | 83ffb9a9e1ffcb57e2adda4d48a8f972148897e6 (diff) | |
download | mocca-3808a5b4ec9d13c8cbb1b7fd95afa62c133342fd.tar.gz mocca-3808a5b4ec9d13c8cbb1b7fd95afa62c133342fd.tar.bz2 mocca-3808a5b4ec9d13c8cbb1b7fd95afa62c133342fd.zip |
HashDataInput
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@21 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'BKUCommonGUI/src/main')
4 files changed, 234 insertions, 259 deletions
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("<html>LoginDialog not supported yet.</html>"); + waitMsgLabel.setText("<html>LoginDialog not supported yet.</html>"); 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("<html>" + errorMsg + "</html>"); + errorMsgLabel.setText("<html>" + errorMsg + "</html>"); 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<HashDataInput> 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("<html>HashDataInputDialog not supported yet.</html>"); + errorMsgLabel.setText("<html>HashDataInputDialog not supported yet.</html>"); 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("<html>" + waitMessage + "</html>"); + } else { + waitMsgLabel.setText("<html>" + messages.getString(MESSAGE_WAIT) + "</html>"); + } + + 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(); - -} diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties index 62c5a670..21a6bd1b 100644 --- a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties +++ b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties @@ -13,8 +13,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. title.welcome=<html>Willkommen</html> title.insertcard=<html>Bitte B\u00FCrgerkarte in den Kartenleser stecken</html> title.cardnotsupported=<html>Die Karte wird nicht unterst\u00FCtzt</html> @@ -22,16 +20,22 @@ title.cardpin=<html>{0} eingeben</html> title.sign=<html>Signatur erstellen</html> title.error=<html>Ein Fehler trat auf</html> title.retry=<html>Falscher PIN</html> +title.wait=<html>Bitte warten</html> +title.hashdata=<html>Signaturdaten</html> windowtitle.save=Signaturdaten speichern +windowtitle.overwrite=Datei \u00FCberschreiben? message.wait=<html>Bitte warten...</html> message.insertcard=<html>Bitte B\u00FCrgerkarte in den Kartenleser stecken.</html> message.hashdatalink=<html><a href=\"anzeige\">Signaturdaten anzeigen...</a></html> +message.hashdata=<html>Referenz Id: {0}</html> message.retries=<html>Noch {0} Versuche</html> +message.overwrite=<html>M\u00F6chten Sie das existierende Dokument {0} \u00FCberschreiben?</html> label.pin=<html>{0}:</html> label.pinsize=<html>({0} stellig)</html> button.ok=OK button.cancel=Abbrechen button.sign=Signieren +button.save=Speichern... mimetype.desc.xml=XML-Dateien (*.xml) mimetype.desc.txt=Textdateien (*.txt) mimetype.desc.pdf=Adobe PDF-Dateien (*.pdf) |