# HG changeset patch
# User nolith
# Date 1181833083 -7200
# Branch trunk
# Node ID 2671a2d977f2900c96cf95d8226c7949957c6724
# Parent 3cccfcb79dd10d154d3a99f40c712364296307a9
[svn] [NEW] preferences may be edited in GUI mode
[NEW] added menubar
diff -r 3cccfcb79dd10d154d3a99f40c712364296307a9 -r 2671a2d977f2900c96cf95d8226c7949957c6724 build.xml
--- a/build.xml Thu Jun 14 10:14:04 2007 +0200
+++ b/build.xml Thu Jun 14 16:58:03 2007 +0200
@@ -149,6 +149,7 @@
jvmversion="1.6+" version="0.1"
workingdirectory="$APP_PACKAGE/Contents/Resources" >
+
diff -r 3cccfcb79dd10d154d3a99f40c712364296307a9 -r 2671a2d977f2900c96cf95d8226c7949957c6724 src/org/abisso/PortableNotary/GUI/MainFrame.java
--- a/src/org/abisso/PortableNotary/GUI/MainFrame.java Thu Jun 14 10:14:04 2007 +0200
+++ b/src/org/abisso/PortableNotary/GUI/MainFrame.java Thu Jun 14 16:58:03 2007 +0200
@@ -18,8 +18,13 @@
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
import javax.swing.JPanel;
import net.iharder.dnd.FileDrop;
@@ -31,8 +36,13 @@
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
-
private JPanel Image = null;
+ private JMenuBar menubar = null;
+ private JMenu file = null;
+ private JMenuItem checkFile = null;
+ private JMenuItem exit = null;
+ private JMenu option = null;
+ private JMenuItem preferences = null;
//private Preferences pref = Preferences.getIstance();
@@ -54,8 +64,13 @@
this.setContentPane(getJContentPane());
this.setTitle("PortableNotary");
Dimension d = getImage().getPreferredSize();
- d.height += 25;
+ int increase = 50;
+ if (System.getProperty("os.name").toUpperCase().indexOf("MAC OS X") == 0) {
+ increase /= 2;
+ }
+ d.height += increase;
this.setSize(d);
+ setJMenuBar(getMenubar());
new FileDrop( getImage(), new FileDrop.Listener(){
public void filesDropped( java.io.File[] files )
{
@@ -71,6 +86,36 @@
}); // end FileDrop.Listener
}
+ private JMenuBar getMenubar() {
+ if (menubar == null) {
+ menubar = new JMenuBar();
+ file = new JMenu("File");
+ option = new JMenu("Options");
+ checkFile = new JMenuItem("Check file");
+ exit = new JMenuItem("Quit");
+ exit.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ System.exit(0);
+ }
+ });
+ preferences = new JMenuItem("Preferences");
+ preferences.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ //TODO: shoul be a modal window!
+ Preferences pWin = new Preferences(
+ org.abisso.PortableNotary.Preferences.getIstance());
+ pWin.setVisible(true);
+ }
+ });
+ option.add(preferences);
+ file.add(checkFile);
+ file.add(exit);
+ menubar.add(file);
+ menubar.add(option);
+ }
+ return menubar;
+ }
+
/**
* This method initializes jContentPane
*
diff -r 3cccfcb79dd10d154d3a99f40c712364296307a9 -r 2671a2d977f2900c96cf95d8226c7949957c6724 src/org/abisso/PortableNotary/GUI/Preferences.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/abisso/PortableNotary/GUI/Preferences.java Thu Jun 14 16:58:03 2007 +0200
@@ -0,0 +1,208 @@
+/**
+ Copyright 2007 Alessio Caiazza
+
+ 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 org.abisso.PortableNotary.GUI;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JPasswordField;
+import javax.swing.JTextField;
+
+public class Preferences extends JDialog {
+
+ private static final long serialVersionUID = 1L;
+
+ private JPanel jContentPane = null;
+ private JLabel warning = null;
+ private JLabel labelPath = null;
+ private JTextField textPath = null;
+ private JLabel labelPassword = null;
+ private JPasswordField textPassword = null;
+ private JButton browse = null;
+ private JButton save = null;
+ private JButton cancel = null;
+
+ private org.abisso.PortableNotary.Preferences pref;
+
+ /**
+ * This is the default constructor
+ */
+ public Preferences(org.abisso.PortableNotary.Preferences pref) {
+ super();
+ this.pref = pref;
+ initialize();
+ this.setModal(true);
+ }
+
+ /**
+ * This method initializes this
+ *
+ * @return void
+ */
+ private void initialize() {
+ this.setSize(400, 200);
+ this.setContentPane(getJContentPane());
+ this.setTitle("Preferences");
+ }
+
+ /**
+ * This method initializes jContentPane
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJContentPane() {
+ if (jContentPane == null) {
+ GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
+ gridBagConstraints3.gridx = 2;
+ gridBagConstraints3.gridy = 1;
+ GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
+ gridBagConstraints21.fill = GridBagConstraints.HORIZONTAL;
+ gridBagConstraints21.gridy = 2;
+ gridBagConstraints21.weightx = 1.0;
+ gridBagConstraints21.gridx = 1;
+ GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
+ gridBagConstraints11.gridx = 0;
+ gridBagConstraints11.gridy = 2;
+ gridBagConstraints11.anchor = GridBagConstraints.WEST;
+ labelPassword = new JLabel();
+ labelPassword.setText("Keystore's password:");
+ labelPassword.setLabelFor(getTextPassword());
+ GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
+ gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL;
+ gridBagConstraints2.gridy = 1;
+ gridBagConstraints2.weightx = 1.0;
+ gridBagConstraints2.gridx = 1;
+ GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
+ gridBagConstraints1.gridx = 0;
+ gridBagConstraints1.gridy = 1;
+ gridBagConstraints1.anchor = GridBagConstraints.WEST;
+ labelPath = new JLabel();
+ labelPath.setText("Keystore path:");
+ labelPath.setLabelFor(getTextPath());
+ GridBagConstraints gridBagConstraints = new GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridwidth = 3;
+ gridBagConstraints.gridy = 0;
+ warning = new JLabel();
+ warning.setText("WARNING: Password are stored in unsafe way");
+ jContentPane = new JPanel();
+ jContentPane.setLayout(new GridBagLayout());
+ jContentPane.add(warning, gridBagConstraints);
+ jContentPane.add(labelPath, gridBagConstraints1);
+ jContentPane.add(getTextPath(), gridBagConstraints2);
+ jContentPane.add(labelPassword, gridBagConstraints11);
+ jContentPane.add(getTextPassword(), gridBagConstraints21);
+ jContentPane.add(getBrowse(), gridBagConstraints3);
+ GridBagConstraints gridBagConstraints22 = new GridBagConstraints();
+ gridBagConstraints22.fill = GridBagConstraints.VERTICAL;
+ gridBagConstraints22.gridy = 3;
+ gridBagConstraints22.weightx = 1.0;
+ gridBagConstraints22.gridx = 1;
+ gridBagConstraints22.anchor = GridBagConstraints.EAST;
+ GridBagConstraints gridBagConstraints32 = new GridBagConstraints();
+ gridBagConstraints32.gridy = 3;
+ gridBagConstraints32.gridx = 2;
+ gridBagConstraints32.anchor = GridBagConstraints.WEST;
+ jContentPane.add(getSave(), gridBagConstraints22);
+ jContentPane.add(getCancel(), gridBagConstraints32);
+ }
+ return jContentPane;
+ }
+
+ /**
+ * This method initializes textPath
+ *
+ * @return javax.swing.JTextField
+ */
+ private JTextField getTextPath() {
+ if (textPath == null) {
+ textPath = new JTextField();
+ textPath.setText(pref.getKeystore_path());
+ }
+ return textPath;
+ }
+
+ /**
+ * This method initializes textPassword
+ *
+ * @return javax.swing.JPasswordField
+ */
+ private JPasswordField getTextPassword() {
+ if (textPassword == null) {
+ textPassword = new JPasswordField();
+ textPassword.setText(pref.getKeystore_pass());
+ }
+ return textPassword;
+ }
+
+ /**
+ * This method initializes browse
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getBrowse() {
+ if (browse == null) {
+ browse = new JButton("Browse");
+ //TODO: implement keystore browsing
+ browse.setEnabled(false);
+ }
+ return browse;
+ }
+
+ /**
+ * This method initializes save
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getSave() {
+ if (save == null) {
+ save = new JButton("Save");
+ save.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ pref.setKeystore_pass(textPassword.getPassword().toString());
+ pref.setKeystore_path(textPath.getText());
+ //TODO: check if this is the correct way
+ setVisible(false);
+ }
+ });
+ }
+ return save;
+ }
+
+ /**
+ * This method initializes cancel
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getCancel() {
+ if (cancel == null) {
+ cancel = new JButton("Cancel");
+ cancel.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ //TODO: check if this is the correct way
+ setVisible(false);
+ }
+ });
+ }
+ return cancel;
+ }
+}
diff -r 3cccfcb79dd10d154d3a99f40c712364296307a9 -r 2671a2d977f2900c96cf95d8226c7949957c6724 src/org/abisso/PortableNotary/PortableNotary.java
--- a/src/org/abisso/PortableNotary/PortableNotary.java Thu Jun 14 10:14:04 2007 +0200
+++ b/src/org/abisso/PortableNotary/PortableNotary.java Thu Jun 14 16:58:03 2007 +0200
@@ -29,10 +29,10 @@
private static final short NO_ERROR = 0;
@SuppressWarnings("unused")
- private static final short LEGACY_JVM = 1;
- private static final short WRONG_PARAMS_NUMBER = 2;
- private static final short WRONG_PARAMS = 3;
- private static final String VERSION = "0.1alpha"; //$NON-NLS-1$
+ public static final short LEGACY_JVM = 1;
+ public static final short WRONG_PARAMS_NUMBER = 2;
+ public static final short WRONG_PARAMS = 3;
+ public static final String VERSION = "0.1alpha"; //$NON-NLS-1$
static String file_path;
static String keystore_path;