[db4o-om commit] r39 - in trunk/objectmanager-swing/src/com/db4o/objectManager/v2: . configuration connections res...

0 views
Skip to first unread message

codesite...@google.com

unread,
Apr 15, 2008, 1:06:25 AM4/15/08
to db4o-om-c...@googlegroups.com
Author: gishac
Date: Mon Apr 14 22:03:50 2008
New Revision: 39

Added:
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationDialog.java
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationPanel.java
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/EncryptionProviderComboBoxModel.java
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/EncryptionProviderComboBoxRenderer.java

trunk/objectmanager-swing/src/com/db4o/objectManager/v2/resources/images/icons/plain/16x16/configure.png
(contents, props changed)
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/uiHelper/UIHelper.java
Modified:
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/Dashboard.java
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/connections/ConnectionForm.java

Log:
Preview for Encryption support

Modified: trunk/objectmanager-swing/src/com/db4o/objectManager/v2/Dashboard.java
==============================================================================
---
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/Dashboard.java (original)
+++
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/Dashboard.java
Mon Apr 14 22:03:50 2008
@@ -118,7 +118,7 @@

frame.setIconImage(ResourceManager.createImageIcon(ResourceManager.ICONS_PLAIN_16X16 + "data.png", "database").getImage());
frame.setJMenuBar(buildMenuBar());
frame.setContentPane(buildContentPane());
- frame.setSize(600, 462);
+ frame.setSize(600, 510);
frame.setResizable(false);
locateOnScreen(frame);
frame.setTitle(TITLE);

Added: trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationDialog.java
==============================================================================
--- (empty file)
+++
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationDialog.java
Mon Apr 14 22:03:50 2008
@@ -0,0 +1,80 @@
+/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */
+/**
+ * User: gishac
+ * Date: Feb 02, 2008
+ * Time: 08:15:00 PM
+ */
+
+package com.db4o.objectManager.v2.configuration;
+
+import java.awt.event.*;
+
+import javax.swing.JDialog;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import com.db4o.config.Configuration;
+import com.db4o.objectManager.v2.custom.BackgroundPanel;
+import com.db4o.objectManager.v2.resources.ResourceManager;
+import com.db4o.objectmanager.configuration.ConfigurationFacade;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+
+public class ConfigurationDialog extends JDialog {
+
+ private final String TITLE="Configuration";
+ private ConfigurationPanel configurationPanel = null;
+ private BackgroundPanel mainPanel;
+
+ /**
+ * This method initializes
+ *
+ */
+ public ConfigurationDialog() {
+ super();
+ initialize();
+ this.setModal(true);
+ }
+
+ /**
+ * This method initializes this
+ *
+ */
+ private void initialize() {
+ this.setSize(new Dimension(484, 289));
+ this.setContentPane(getConfigurationPanel());
+
this.setIconImage(ResourceManager.createImageIcon(ResourceManager.ICONS_PLAIN_16X16 + "configure.png", "configure").getImage());
+ this.setTitle(TITLE);
+ this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ this.addWindowListener(new java.awt.event.WindowAdapter() {
+ public void windowClosed(java.awt.event.WindowEvent e) {
+
+ }
+ });
+ }
+
+ /**
+ * This method initializes configurationPanel
+ *
+ * @return com.configuration.demo.ConfigurationPanel
+ */
+ private JPanel getConfigurationPanel() {
+ if (configurationPanel == null) {
+ mainPanel = new BackgroundPanel();
+ configurationPanel = new ConfigurationPanel(this);
+ mainPanel.add(configurationPanel.buildPanel());
+ }
+ return mainPanel;
+ }
+
+ /**
+ *
+ * @return Configured object, null if it's not configured
+ */
+ public ConfigurationFacade getConfiguration(){
+ return configurationPanel.configuration();
+ }
+
+} // @jve:decl-index=0:visual-constraint="10,10"

Added: trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationPanel.java
==============================================================================
--- (empty file)
+++
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/ConfigurationPanel.java
Mon Apr 14 22:03:50 2008
@@ -0,0 +1,277 @@
+/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */
+/**
+ * User: gishac
+ * Date: Feb 02, 2008
+ * Time: 08:19:23 PM
+ */
+
+package com.db4o.objectManager.v2.configuration;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.io.*;
+import javax.swing.*;
+import javax.swing.filechooser.*;
+import com.db4o.Db4o;
+import com.db4o.config.Configuration;
+import com.db4o.objectmanager.configuration.*;
+import com.jgoodies.forms.builder.*;
+import com.jgoodies.forms.layout.*;
+import com.jgoodies.looks.Fonts;
+
+public class ConfigurationPanel {
+
+ private JComboBox _encryptionProvider;
+ private ConfigurationProvider _configurationProvider;
+ private JCheckBox _unicode;
+ private JCheckBox _lockDatabase;
+ private JCheckBox _callConstructors;
+ private JTextField _encryptionPassword;
+ private JButton _buildConfiguration;
+ private ConfigurationFacade _configuration;
+ private JDialog _container;
+ private JPanel panel;
+
+ // private Component dashboard;
+
+ /**
+ * This method initializes
+ *
+ */
+ public ConfigurationPanel() {
+ super();
+ initialize();
+ }
+
+ /**
+ *
+ * @param container The form which contains the panel
+ */
+ public ConfigurationPanel(JDialog container){
+ this();
+ _container = container;
+ }
+
+ /**
+ * This method initializes this
+ *
+ */
+ private void initialize() {
+ }
+
+ /**
+ * Create all the UI elements for the configuration panel
+ *
+ * @return
+ */
+ public JPanel buildPanel() {
+ FormLayout layout = new FormLayout(
+ "right:max(40dlu;pref), 3dlu, 120dlu, 7dlu,"
+ + "right:max(10dlu;pref), 3dlu, 80dlu", "");
+ DefaultFormBuilder builder = new DefaultFormBuilder(layout);
+ builder.setDefaultDialogBorder();
+
+ JLabel descriptionLabel = new JLabel("Set Configuration");
+ descriptionLabel.setFont(Fonts.WINDOWS_VISTA_96DPI_LARGE);
+ descriptionLabel.setForeground(Color.white);
+ builder.append(descriptionLabel);
+
+ builder.nextLine();
+
+ builder.append(getLabel("Unicode: "), unicode());
+
+ builder.nextLine();
+
+ builder.append(getLabel("Lock Database file: "), lockDatabase());
+
+ builder.nextLine();
+
+ builder.append(getLabel("Call Constructors: "), callConstructors());
+
+ builder.nextLine();
+
+ builder.append(getLabel("Encryption Provider: "), encryptionProvider(),findEncryptionProvider());
+
+ builder.nextLine();
+
+ builder.append(getLabel("Encryption Password: "), encryptionPassword());
+
+ builder.nextLine();
+
+ builder.append(buildConfiguration(),cancel());
+
+ panel = builder.getPanel();
+ panel.setOpaque(false);
+ return panel;
+ }
+
+ /**
+ * Create the checkbox to set unicode configuration
+ *
+ * @return
+ */
+ private JCheckBox unicode() {
+ _unicode = new JCheckBox();
+ _unicode.setOpaque(false);
+ _unicode.setSelected(true);
+ return _unicode;
+ }
+
+ /**
+ * Create the checkbox to set lock database file configuration
+ *
+ * @return
+ */
+ private JCheckBox lockDatabase() {
+ _lockDatabase = new JCheckBox();
+ _lockDatabase.setOpaque(false);
+ return _lockDatabase;
+ }
+
+ /**
+ * Create the checkbox to set callConstructor configuration
+ *
+ * @return
+ */
+ private JCheckBox callConstructors() {
+ _callConstructors = new JCheckBox();
+ _callConstructors.setOpaque(false);
+ return _callConstructors;
+ }
+
+ /**
+ * Create the combobox to select the encription provider
+ *
+ * @return
+ */
+ private JComboBox encryptionProvider() {
+ _encryptionProvider = new JComboBox();
+ return _encryptionProvider;
+ }
+
+ /**
+ * Builds a label to append in the pannel
+ * @param text
+ * @return
+ */
+ private JLabel getLabel(String text){
+ JLabel label = new JLabel(text);
+ label.setForeground(Color.black);
+ return label;
+ }
+
+ /**
+ * Create the button to search encryption provider
+ *
+ * @return
+ */
+ private JButton findEncryptionProvider() {
+ JButton findEncryptionProvider = new JButton("...");
+ findEncryptionProvider.setSize(new Dimension(25,25));
+ findEncryptionProvider.setMaximumSize(new Dimension(25,25));
+ findEncryptionProvider.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ JFileChooser jarFileChooser = jarFileChooser();
+ int dialogResult = jarFileChooser.showDialog(_container, "Ok");
+ if (dialogResult == JFileChooser.APPROVE_OPTION) {
+ File file = jarFileChooser.getSelectedFile();
+ JarLoader jarLoader = new JarLoader(file.getPath());
+ EncryptionProviderComboBoxModel model = new EncryptionProviderComboBoxModel(
+ jarLoader.getClasses(file.getPath()));
+ _encryptionProvider.setModel(model);
+ if(model.getDataSource().size() > 0)
+ _encryptionProvider.setSelectedIndex(0);
+ _encryptionProvider.setRenderer(new EncryptionProviderComboBoxRenderer());
+ }
+ }
+ });
+ return findEncryptionProvider;
+ }
+
+ /**
+ *
+ * @return
+ */
+ private JButton cancel(){
+ JButton cancel = new JButton("Cancel");
+ cancel.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent e) {
+ _container.setVisible(false);
+ _container.dispose();
+ }
+
+ });
+ return cancel;
+ }
+
+
+ /**
+ * Create the select file dialog, to find the jar file to be used as
+ * encryption provider
+ *
+ * @return
+ */
+ private JFileChooser jarFileChooser() {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Select your Encryption Provider");
+ FileNameExtensionFilter filter = new FileNameExtensionFilter(
+ "Jar Files", "jar");
+ fileChooser.setFileFilter(filter);
+ fileChooser.setMultiSelectionEnabled(false);
+ return fileChooser;
+ }
+
+ /**
+ * Create the textfield for the password
+ *
+ * @return
+ */
+ private JTextField encryptionPassword() {
+ _encryptionPassword = new JTextField();
+ return _encryptionPassword;
+ }
+
+ /**
+ * Build the Configuration with the selected parameters
+ * @return
+ */
+ private JButton buildConfiguration() {
+ _buildConfiguration = new JButton("Ok");
+ _buildConfiguration.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ _configurationProvider = new ConfigurationProvider();
+ _configurationProvider.unicodeEnabled(_unicode.isSelected());
+ _configurationProvider.lockDatabase(_lockDatabase.isSelected());
+ _configurationProvider.callConstructors(_callConstructors.isSelected());
+ try {
+ _configurationProvider.encryptionProvider(
+ EncryptionProviderHandler.getEncryptionProvider((Class) _encryptionProvider.getSelectedItem(),
+ _encryptionPassword.getText()));
+ } catch (Exception ex) {
+ JOptionPane.showMessageDialog(null, "Can't create an instance of
the Encryption Provider");
+ }
+ configuration(_configurationProvider.buildConfiguration());
+ _container.setVisible(false);
+ _container.dispose();
+ }
+
+ });
+ return _buildConfiguration;
+ }
+
+ /**
+ * Get the configuration object built by the configuration window
+ * @return
+ */
+ public ConfigurationFacade configuration(){
+ return this._configuration;
+ }
+
+ /**
+ * Set the configuration object
+ * @param configurationConfigurationFacade
+ */
+ private void configuration(ConfigurationFacade configuration){
+ this._configuration = configuration;
+ }
+}

Added: trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/EncryptionProviderComboBoxModel.java
==============================================================================
--- (empty file)
+++
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/EncryptionProviderComboBoxModel.java
Mon Apr 14 22:03:50 2008
@@ -0,0 +1,43 @@
+package com.db4o.objectManager.v2.configuration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.AbstractListModel;
+import javax.swing.ComboBoxModel;
+import javax.swing.event.ListDataListener;
+
+public class EncryptionProviderComboBoxModel extends AbstractListModel
+ implements ComboBoxModel {
+
+ private List<Class> dataSource;
+ Class current;
+
+ public EncryptionProviderComboBoxModel(List<Class> dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public Object getElementAt(int index) {
+ return getDataSource().get(index);
+ }
+
+ public int getSize() {
+ return getDataSource().size();
+ }
+
+ public List<Class> getDataSource() {
+ if (dataSource == null)
+ dataSource = new ArrayList<Class>();
+ return dataSource;
+ }
+
+ public Object getSelectedItem() {
+ return current;
+ }
+
+ public void setSelectedItem(Object selectedItem) {
+ current = (Class) selectedItem;
+ fireContentsChanged(selectedItem, -1, -1);
+ }
+
+}

Added: trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/EncryptionProviderComboBoxRenderer.java
==============================================================================
--- (empty file)
+++
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/configuration/EncryptionProviderComboBoxRenderer.java
Mon Apr 14 22:03:50 2008
@@ -0,0 +1,35 @@
+package com.db4o.objectManager.v2.configuration;
+
+import java.awt.Component;
+
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
+
+public class EncryptionProviderComboBoxRenderer extends JLabel
implements ListCellRenderer {
+
+ public Component getListCellRendererComponent(JList list, Object value,
+ int index, boolean isSelected, boolean cellHasFocus) {
+ try {
+ if (value != null) {
+ if(isSelected)
+ {
+ this.setBackground(list.getSelectionBackground());
+ this.setForeground(list.getSelectionForeground());
+ }
+ else
+ {
+ this.setBackground(list.getBackground());
+ this.setForeground(list.getSelectionForeground());
+ }
+ this.setText(((Class)value).getCanonicalName());
+ }
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return this;
+ }
+
+
+}

Modified: trunk/objectmanager-swing/src/com/db4o/objectManager/v2/connections/ConnectionForm.java
==============================================================================
---
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/connections/ConnectionForm.java (original)
+++
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/connections/ConnectionForm.java
Mon Apr 14 22:03:50 2008
@@ -3,13 +3,17 @@
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.looks.Fonts;
+import com.db4o.config.Configuration;
import com.db4o.objectmanager.model.Db4oConnectionSpec;
import com.db4o.objectmanager.model.Db4oFileConnectionSpec;
import com.db4o.objectmanager.model.Db4oSocketConnectionSpec;
import com.db4o.objectmanager.api.prefs.Preferences;
+import com.db4o.objectmanager.configuration.ConfigurationFacade;
import com.db4o.ObjectContainer;
+import com.db4o.objectManager.v2.configuration.ConfigurationDialog;
import com.db4o.objectManager.v2.connections.RecentConnectionList;
import com.db4o.objectManager.v2.connections.ConnectionHelper;
+import com.db4o.objectManager.v2.uiHelper.UIHelper;
import com.db4o.objectManager.v2.Dashboard;
import com.db4o.objectManager.v2.MainFrame;
import com.db4o.objectManager.v2.WindowPrefsListener;
@@ -30,7 +34,7 @@
private JTextField usernameTextField;
private JTextField passwordTextField;
private JTextField fileTextField;
-
+ private ConfigurationFacade configuration;
private JPanel panel;
private Dashboard dashboard;
private RecentConnectionList recentConnectionList;
@@ -92,6 +96,25 @@
builder.append(welcome2);
builder.nextLine();
//builder.append("");
+
+ builder.appendSeparator("Configuration");
+ JButton configurationButton = new JButton("Configure");
+ configurationButton.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent e) {
+ //JOptionPane.showMessageDialog(null, "Configure database");
+ ConfigurationDialog configurationForm = new ConfigurationDialog();
+ configurationForm.setAlwaysOnTop(true);
+ UIHelper.CenterFormInScreen(configurationForm, configurationForm.getToolkit());
+ configurationForm.setVisible(true);
+ configuration = configurationForm.getConfiguration();
+ }
+ });
+
+
+ builder.append("",configurationButton);
+
+ builder.nextLine();
+
builder.appendSeparator("Local");
fileTextField = new JTextField();
builder.append("File:", fileTextField);
@@ -119,8 +142,9 @@
connectToFile();
}
});
- builder.append("", openButton);
-
+ builder.append("",openButton);
+
+

builder.nextLine();
builder.appendSeparator("Remote");
@@ -166,6 +190,7 @@
if (fileTextField.getText().length() > 0) {
// then open file connection
Db4oConnectionSpec connectionSpec = new
Db4oFileConnectionSpec(fileTextField.getText(), false);
+ connectionSpec.setConfiguration(configuration);
connectAndOpenFrame(connectionSpec);
}
}
@@ -180,6 +205,7 @@
oc = ConnectionHelper.connect(dashboard.getFrame(), connectionSpec);
} catch (Exception ex) {
// if fails to open, stop, message already shown
+ System.out.println(ex.getMessage());
stopWorking();
return;
}

Added: trunk/objectmanager-swing/src/com/db4o/objectManager/v2/resources/images/icons/plain/16x16/configure.png
==============================================================================
Binary file. No diff available.

Added: trunk/objectmanager-swing/src/com/db4o/objectManager/v2/uiHelper/UIHelper.java
==============================================================================
--- (empty file)
+++
trunk/objectmanager-swing/src/com/db4o/objectManager/v2/uiHelper/UIHelper.java
Mon Apr 14 22:03:50 2008
@@ -0,0 +1,21 @@
+/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */
+/**
+ * User: gishac
+ * Date: Apr 14, 2008
+ * Time: 10:02:14 PM
+ */
+package com.db4o.objectManager.v2.uiHelper;
+
+import java.awt.*;
+
+public class UIHelper {
+
+ public static void CenterFormInScreen(Component component, Toolkit toolkit){
+ Dimension dimension = component.getSize();
+ Dimension screenSize = toolkit.getScreenSize();
+ component.setLocation(
+ (screenSize.width - dimension.width) / 2,
+ (screenSize.height - dimension.height) / 2);
+ }
+
+}

Reply all
Reply to author
Forward
0 new messages