diff options
author | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2008-09-15 18:02:18 +0000 |
---|---|---|
committer | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2008-09-15 18:02:18 +0000 |
commit | a288c99fa6955a2c9055b28dc1c805dacbe5fc93 (patch) | |
tree | 98319f46d37be10e7c5545e4ae451e650ce5c3b9 /BKUCommonGUI/src/main/java | |
parent | fd1db02bdc9fbd2a5beca0cc2b214c1adbcc1a7a (diff) | |
download | mocca-a288c99fa6955a2c9055b28dc1c805dacbe5fc93.tar.gz mocca-a288c99fa6955a2c9055b28dc1c805dacbe5fc93.tar.bz2 mocca-a288c99fa6955a2c9055b28dc1c805dacbe5fc93.zip |
encoding
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@40 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'BKUCommonGUI/src/main/java')
4 files changed, 251 insertions, 142 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 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(); @@ -846,6 +844,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("<html>" + waitMessage + "</html>"); + } else { + waitMsgLabel.setText("<html>" + messages.getString(MESSAGE_WAIT) + "</html>"); + } + + 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<HashDataInput> signedReferences, final ActionListener okListener, final String okCommand) { if (signedReferences == null) { @@ -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("<html>" + waitMessage + "</html>"); - } else { - waitMsgLabel.setText("<html>" + messages.getString(MESSAGE_WAIT) + "</html>"); - } - - 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<HashDataInput> signedReferences; - - Class[] types = new Class[]{ - java.lang.String.class, java.lang.Boolean.class - }; - - public HashDataTableModel(List<HashDataInput> 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<HashDataInput> 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<HashDataInput> 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<HashDataInput> getSelectedHashData() { - ArrayList<HashDataInput> selection = new ArrayList<HashDataInput>(); - 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<String> getSelectedReferenceIds() { + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + if (columnIndex == 1) + return true; + return false; + } + + public List<HashDataInput> getSelectedHashData() { + ArrayList<HashDataInput> selection = new ArrayList<HashDataInput>(); + 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<String> getSelectedReferenceIds() { // ArrayList<String> selection = new ArrayList<String>(); // 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; |