summaryrefslogtreecommitdiff
path: root/BKUCommonGUI
diff options
context:
space:
mode:
authorclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2008-11-19 11:49:55 +0000
committerclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2008-11-19 11:49:55 +0000
commitbc81c317e254fa617fc24c8129b743ac74aad470 (patch)
treef0294c7d1c5c481a251ebac9a384efe37472c8ac /BKUCommonGUI
parent1d5ba689e1f95232504fe5e44b978038da8ff036 (diff)
downloadmocca-bc81c317e254fa617fc24c8129b743ac74aad470.tar.gz
mocca-bc81c317e254fa617fc24c8129b743ac74aad470.tar.bz2
mocca-bc81c317e254fa617fc24c8129b743ac74aad470.zip
GUI feature complete
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@180 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'BKUCommonGUI')
-rw-r--r--BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java158
-rw-r--r--BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java98
-rw-r--r--BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java6
-rw-r--r--BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java2
4 files changed, 139 insertions, 125 deletions
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<HashDataInput> 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<HashDataInput> 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<HashDataInput> hashDataInputs;
- private HashDataLinkRenderer renderer;
public HashDataTableModel(List<HashDataInput> 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);
diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java
index 82b42d0f..fec097f5 100644
--- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java
+++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java
@@ -81,7 +81,7 @@ public class BKUGUIWorker implements Runnable {
};
HashDataInput signedRef1 = new ByteArrayHashDataInput(
"Ich bin ein einfacher Text mit Umlauten: öäüßéç@€\n123\n456\n\tHello, world!\n\nlkjsd\nnksdjf".getBytes(),
- "ref-id-000000001",
+ "ref-id-0000000000000000000000001",
"text/plain",
"UTF-8");