added more options in settings allowing user to pick the database name.
added an option to allow the user to save their password added a password field to the main panel to allow for easy password entry added a connect button to the main panel
This commit is contained in:
@@ -1,7 +0,0 @@
|
|||||||
#---No Comment---
|
|
||||||
#Wed Jan 26 13:29:05 EST 2011
|
|
||||||
server_parrword=kwz5vDLcNnKG6agAnGSm8nwzSncF2SK5
|
|
||||||
server_location=tcdevsvn1
|
|
||||||
use_remote_server=true
|
|
||||||
server_port_number=3306
|
|
||||||
server_user_name=ricky.barrette
|
|
||||||
BIN
Order Processor/images/remove.png
Normal file
BIN
Order Processor/images/remove.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
BIN
Order Processor/images/repeat.png
Normal file
BIN
Order Processor/images/repeat.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
@@ -57,12 +57,13 @@ public class OrderDB {
|
|||||||
/**
|
/**
|
||||||
* Creates a new OrderDB
|
* Creates a new OrderDB
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
|
* @param password
|
||||||
* @throws ClassNotFoundException
|
* @throws ClassNotFoundException
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
* @throws SocketException
|
* @throws SocketException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public OrderDB() throws ClassNotFoundException, SQLException, SocketException {
|
public OrderDB(String password) throws ClassNotFoundException, SQLException, SocketException {
|
||||||
|
|
||||||
Properties props = getProperties();
|
Properties props = getProperties();
|
||||||
|
|
||||||
@@ -76,7 +77,12 @@ public class OrderDB {
|
|||||||
dbLocation = System.getProperty("user.home") +"/.TwentyCodesOrders";
|
dbLocation = System.getProperty("user.home") +"/.TwentyCodesOrders";
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection conn = getConnection();
|
Connection conn;
|
||||||
|
if(password == null)
|
||||||
|
conn = getConnection();
|
||||||
|
else
|
||||||
|
conn = getConnection(password);
|
||||||
|
|
||||||
Statement stat = conn.createStatement();
|
Statement stat = conn.createStatement();
|
||||||
|
|
||||||
// stat.executeUpdate("drop table if exists Orders;");
|
// stat.executeUpdate("drop table if exists Orders;");
|
||||||
@@ -216,7 +222,7 @@ public class OrderDB {
|
|||||||
passwordEncryptor.setPassword(PASSWORD);
|
passwordEncryptor.setPassword(PASSWORD);
|
||||||
|
|
||||||
if(isUsingRemoteDatabase){
|
if(isUsingRemoteDatabase){
|
||||||
String url = "jdbc:mysql://"+props.getProperty(SettingsPanel.SERVER_LOCATION)+":"+props.getProperty(SettingsPanel.SERVER_PORT_NUMBER, "3306")+"/Orders";
|
String url = "jdbc:mysql://"+props.getProperty(SettingsPanel.SERVER_LOCATION)+":"+props.getProperty(SettingsPanel.SERVER_PORT_NUMBER, "3306")+"/"+props.getProperty(SettingsPanel.DATABASE_NAME,"Orders");
|
||||||
|
|
||||||
if(props.getProperty(SettingsPanel.SERVER_USERNAME).length() > 0)
|
if(props.getProperty(SettingsPanel.SERVER_USERNAME).length() > 0)
|
||||||
url += "?user="+ props.getProperty(SettingsPanel.SERVER_USERNAME);
|
url += "?user="+ props.getProperty(SettingsPanel.SERVER_USERNAME);
|
||||||
@@ -231,6 +237,26 @@ public class OrderDB {
|
|||||||
return DriverManager.getConnection("jdbc:sqlite:"+ dbLocation+".db");
|
return DriverManager.getConnection("jdbc:sqlite:"+ dbLocation+".db");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Connection getConnection(String password) throws SQLException {
|
||||||
|
Properties props = getProperties();
|
||||||
|
BasicTextEncryptor passwordEncryptor = new BasicTextEncryptor();
|
||||||
|
passwordEncryptor.setPassword(PASSWORD);
|
||||||
|
|
||||||
|
if(isUsingRemoteDatabase){
|
||||||
|
String url = "jdbc:mysql://"+props.getProperty(SettingsPanel.SERVER_LOCATION)+":"+props.getProperty(SettingsPanel.SERVER_PORT_NUMBER, "3306")+"/"+props.getProperty(SettingsPanel.DATABASE_NAME,"Orders");
|
||||||
|
|
||||||
|
if(props.getProperty(SettingsPanel.SERVER_USERNAME).length() > 0)
|
||||||
|
url += "?user="+ props.getProperty(SettingsPanel.SERVER_USERNAME);
|
||||||
|
|
||||||
|
url += "&password="+ password;
|
||||||
|
|
||||||
|
return DriverManager.getConnection(url);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return DriverManager.getConnection("jdbc:sqlite:"+ dbLocation+".db");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the row count
|
* returns the row count
|
||||||
* @return number orders in the database
|
* @return number orders in the database
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ package com.TwentyCodes.java.OrderProcessor.UI;
|
|||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@@ -27,6 +29,7 @@ import com.TwentyCodes.java.OrderProcessor.FileFilter;
|
|||||||
import com.TwentyCodes.java.OrderProcessor.ProgressListener;
|
import com.TwentyCodes.java.OrderProcessor.ProgressListener;
|
||||||
import com.TwentyCodes.java.OrderProcessor.UncaughtExceptionHandler;
|
import com.TwentyCodes.java.OrderProcessor.UncaughtExceptionHandler;
|
||||||
import com.TwentyCodes.java.OrderProcessor.DB.OrderDB;
|
import com.TwentyCodes.java.OrderProcessor.DB.OrderDB;
|
||||||
|
import javax.swing.JPasswordField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this is the main window and class of this application
|
* this is the main window and class of this application
|
||||||
@@ -42,6 +45,9 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
|||||||
private UncaughtExceptionHandler mExceptionReport = new UncaughtExceptionHandler(this.getClass());
|
private UncaughtExceptionHandler mExceptionReport = new UncaughtExceptionHandler(this.getClass());
|
||||||
private static JLabel orderCountLabel;
|
private static JLabel orderCountLabel;
|
||||||
private static JLabel mWarningLabel;
|
private static JLabel mWarningLabel;
|
||||||
|
private static JButton mConnectButton;
|
||||||
|
private static JPasswordField mPassWord;
|
||||||
|
private JLabel lblDatabasePassword;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new MainWindow
|
* Creates a new MainWindow
|
||||||
@@ -97,6 +103,17 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
|||||||
|
|
||||||
panel.add(mLoadFileButton);
|
panel.add(mLoadFileButton);
|
||||||
|
|
||||||
|
lblDatabasePassword = new JLabel("Database Password");
|
||||||
|
panel.add(lblDatabasePassword);
|
||||||
|
|
||||||
|
mPassWord = new JPasswordField();
|
||||||
|
mPassWord.setColumns(10);
|
||||||
|
panel.add(mPassWord);
|
||||||
|
|
||||||
|
mConnectButton = new JButton("Connect", new ImageIcon(getClass().getResource("/repeat.png")));
|
||||||
|
mConnectButton.addActionListener(this);
|
||||||
|
panel.add(mConnectButton);
|
||||||
|
|
||||||
panel.add(mWarningLabel);
|
panel.add(mWarningLabel);
|
||||||
|
|
||||||
//progress bar
|
//progress bar
|
||||||
@@ -104,10 +121,24 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
|||||||
mProgressBar.setStringPainted(true);
|
mProgressBar.setStringPainted(true);
|
||||||
|
|
||||||
mainPanel.add(mProgressBar, BorderLayout.SOUTH);
|
mainPanel.add(mProgressBar, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return mainPanel;
|
return mainPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadDatabase() {
|
public static void loadDatabase() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Properties p = getProperties();
|
||||||
|
mPassWord.setEnabled(! Boolean.parseBoolean(p.getProperty(SettingsPanel.SAVE_PASSWORD, "false")));
|
||||||
|
if(! mPassWord.isEnabled())
|
||||||
|
mPassWord.setText(p.getProperty(SettingsPanel.SERVER_PASSWORD));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
mConnectButton.setEnabled(false);
|
||||||
mProgressBar.setString("Connecting to database");
|
mProgressBar.setString("Connecting to database");
|
||||||
mProgressBar.setIndeterminate(true);
|
mProgressBar.setIndeterminate(true);
|
||||||
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
|
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
|
||||||
@@ -115,23 +146,30 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
|||||||
|
|
||||||
//order count labels
|
//order count labels
|
||||||
try {
|
try {
|
||||||
db = new OrderDB();
|
db = new OrderDB(mPassWord.isEnabled() ? new String(mPassWord.getPassword()) : null);
|
||||||
orderCountLabel.setText(db.getCount()+"");
|
orderCountLabel.setText(db.getCount()+"");
|
||||||
mWarningLabel.setText(null);
|
mWarningLabel.setText("Connected");
|
||||||
|
mPassWord.setEnabled(false);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
mWarningLabel.setText(e.getMessage());
|
mWarningLabel.setText(e.getMessage());
|
||||||
mWarningLabel.setVisible(true);
|
mWarningLabel.setVisible(true);
|
||||||
|
mConnectButton.setEnabled(true);
|
||||||
|
orderCountLabel.setText("");
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
mWarningLabel.setText(e.getMessage());
|
mWarningLabel.setText(e.getMessage());
|
||||||
mWarningLabel.setVisible(true);
|
mWarningLabel.setVisible(true);
|
||||||
|
mConnectButton.setEnabled(true);
|
||||||
|
orderCountLabel.setText("");
|
||||||
} catch (NullPointerException e){
|
} catch (NullPointerException e){
|
||||||
mWarningLabel.setText("Database not avilable");
|
mWarningLabel.setText("Database not avilable");
|
||||||
mWarningLabel.setVisible(true);
|
mWarningLabel.setVisible(true);
|
||||||
|
mConnectButton.setEnabled(true);
|
||||||
|
orderCountLabel.setText("");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
mProgressBar.setString(null);
|
mProgressBar.setString(mWarningLabel.getText());
|
||||||
mProgressBar.setIndeterminate(false);
|
mProgressBar.setIndeterminate(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -178,6 +216,10 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
|||||||
mProgressBar.setIndeterminate(false);
|
mProgressBar.setIndeterminate(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(e.getSource() == mConnectButton){
|
||||||
|
loadDatabase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -207,4 +249,19 @@ public class MainWindow extends JFrame implements ActionListener, ProgressListen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the properties from the save file
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private static Properties getProperties() throws IOException{
|
||||||
|
// create and load default properties
|
||||||
|
Properties props = new Properties();
|
||||||
|
FileInputStream in = new FileInputStream(".settings.propertys");
|
||||||
|
props.load(in);
|
||||||
|
in.close();
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import javax.swing.GroupLayout;
|
import javax.swing.GroupLayout;
|
||||||
import javax.swing.GroupLayout.Alignment;
|
import javax.swing.GroupLayout.Alignment;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@@ -40,6 +41,8 @@ public class SettingsPanel extends JPanel implements ActionListener {
|
|||||||
public static final String SERVER_PORT_NUMBER = "server_port_number";
|
public static final String SERVER_PORT_NUMBER = "server_port_number";
|
||||||
public static final String SERVER_USERNAME = "server_user_name";
|
public static final String SERVER_USERNAME = "server_user_name";
|
||||||
public static final String SERVER_PASSWORD = "server_parrword";
|
public static final String SERVER_PASSWORD = "server_parrword";
|
||||||
|
public static final String SAVE_PASSWORD = "save_password";
|
||||||
|
public static final String DATABASE_NAME = "database_name";
|
||||||
private JTextField mServerLocation;
|
private JTextField mServerLocation;
|
||||||
private JTextField mPortNumber;
|
private JTextField mPortNumber;
|
||||||
private JTextField mUserName;
|
private JTextField mUserName;
|
||||||
@@ -48,6 +51,8 @@ public class SettingsPanel extends JPanel implements ActionListener {
|
|||||||
private JButton mSaveButton;
|
private JButton mSaveButton;
|
||||||
private JCheckBox mUseRemoteDatabase;
|
private JCheckBox mUseRemoteDatabase;
|
||||||
private Properties mProps;
|
private Properties mProps;
|
||||||
|
private JTextField mDatabaseName;
|
||||||
|
private JCheckBox mSavePassword;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SettingsPanel
|
* Creates a new SettingsPanel
|
||||||
@@ -69,10 +74,10 @@ public class SettingsPanel extends JPanel implements ActionListener {
|
|||||||
|
|
||||||
//server port number
|
//server port number
|
||||||
mPortNumber = new JTextField();
|
mPortNumber = new JTextField();
|
||||||
|
mPortNumber.setEnabled(false);
|
||||||
mPortNumber.setColumns(10);
|
mPortNumber.setColumns(10);
|
||||||
mPortNumber.setText("3306");
|
|
||||||
|
|
||||||
JLabel lblMysql = new JLabel("MYsql serevr username:");
|
JLabel lblMysql = new JLabel("MYsql server user name:");
|
||||||
JLabel lblMysqlServerPassword = new JLabel("MYsql server password:");
|
JLabel lblMysqlServerPassword = new JLabel("MYsql server password:");
|
||||||
//username
|
//username
|
||||||
mUserName = new JTextField();
|
mUserName = new JTextField();
|
||||||
@@ -84,38 +89,58 @@ public class SettingsPanel extends JPanel implements ActionListener {
|
|||||||
|
|
||||||
//disable everything
|
//disable everything
|
||||||
mServerLocation.setEnabled(false);
|
mServerLocation.setEnabled(false);
|
||||||
mPortNumber.setEnabled(false);
|
|
||||||
mUserName.setEnabled(false);
|
mUserName.setEnabled(false);
|
||||||
mUserPassword.setEnabled(false);
|
mUserPassword.setEnabled(false);
|
||||||
|
|
||||||
//save button
|
//save button
|
||||||
mSaveButton = new JButton("Save");
|
mSaveButton = new JButton("Save", new ImageIcon(getClass().getResource("/floppy_disc.png")));
|
||||||
mSaveButton.addActionListener(this);
|
mSaveButton.addActionListener(this);
|
||||||
|
|
||||||
|
mSavePassword = new JCheckBox("Save Password?");
|
||||||
|
mSavePassword.addActionListener(this);
|
||||||
|
|
||||||
|
JLabel lblDatabaseName = new JLabel("Database Name:");
|
||||||
|
|
||||||
|
mDatabaseName = new JTextField();
|
||||||
|
mDatabaseName.setEnabled(false);
|
||||||
|
|
||||||
|
mDatabaseName.setColumns(10);
|
||||||
|
|
||||||
//group layout bullshit
|
//group layout bullshit
|
||||||
GroupLayout groupLayout = new GroupLayout(this);
|
GroupLayout groupLayout = new GroupLayout(this);
|
||||||
groupLayout.setHorizontalGroup(
|
groupLayout.setHorizontalGroup(
|
||||||
groupLayout.createParallelGroup(Alignment.LEADING)
|
groupLayout.createParallelGroup(Alignment.LEADING)
|
||||||
|
.addGroup(groupLayout.createSequentialGroup()
|
||||||
|
.addContainerGap()
|
||||||
|
.addComponent(mUseRemoteDatabase)
|
||||||
|
.addContainerGap(1087, Short.MAX_VALUE))
|
||||||
.addGroup(groupLayout.createSequentialGroup()
|
.addGroup(groupLayout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||||
.addGroup(groupLayout.createSequentialGroup()
|
.addGroup(groupLayout.createSequentialGroup()
|
||||||
.addComponent(mUseRemoteDatabase)
|
.addComponent(mSavePassword)
|
||||||
.addContainerGap())
|
.addContainerGap())
|
||||||
.addGroup(groupLayout.createSequentialGroup()
|
.addGroup(groupLayout.createSequentialGroup()
|
||||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||||
.addComponent(lblMysqlServerLocation)
|
.addComponent(lblMysqlServerLocation)
|
||||||
.addComponent(lblMysqlServerPort)
|
.addComponent(lblMysqlServerPort)
|
||||||
.addComponent(lblMysql)
|
.addComponent(lblDatabaseName)
|
||||||
.addComponent(lblMysqlServerPassword))
|
.addComponent(lblMysql))
|
||||||
.addPreferredGap(ComponentPlacement.RELATED)
|
.addPreferredGap(ComponentPlacement.RELATED)
|
||||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
|
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
|
||||||
.addComponent(mServerLocation)
|
.addComponent(mPortNumber, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1079, Short.MAX_VALUE)
|
||||||
.addComponent(mSaveButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
.addComponent(mServerLocation, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1079, Short.MAX_VALUE)
|
||||||
.addComponent(mUserPassword)
|
.addComponent(mDatabaseName, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1079, Short.MAX_VALUE)
|
||||||
.addComponent(mUserName)
|
.addComponent(mUserName, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 1079, Short.MAX_VALUE))
|
||||||
.addComponent(mPortNumber))
|
.addContainerGap())))
|
||||||
.addContainerGap(139, Short.MAX_VALUE))))
|
.addGroup(groupLayout.createSequentialGroup()
|
||||||
|
.addContainerGap()
|
||||||
|
.addComponent(lblMysqlServerPassword)
|
||||||
|
.addPreferredGap(ComponentPlacement.RELATED)
|
||||||
|
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||||
|
.addComponent(mUserPassword, GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE)
|
||||||
|
.addComponent(mSaveButton, GroupLayout.DEFAULT_SIZE, 949, Short.MAX_VALUE))
|
||||||
|
.addContainerGap())
|
||||||
);
|
);
|
||||||
groupLayout.setVerticalGroup(
|
groupLayout.setVerticalGroup(
|
||||||
groupLayout.createParallelGroup(Alignment.LEADING)
|
groupLayout.createParallelGroup(Alignment.LEADING)
|
||||||
@@ -131,16 +156,22 @@ public class SettingsPanel extends JPanel implements ActionListener {
|
|||||||
.addComponent(lblMysqlServerPort)
|
.addComponent(lblMysqlServerPort)
|
||||||
.addComponent(mPortNumber, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
.addComponent(mPortNumber, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||||
.addPreferredGap(ComponentPlacement.RELATED)
|
.addPreferredGap(ComponentPlacement.RELATED)
|
||||||
|
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
|
||||||
|
.addComponent(lblDatabaseName)
|
||||||
|
.addComponent(mDatabaseName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||||
|
.addPreferredGap(ComponentPlacement.RELATED)
|
||||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||||
.addComponent(lblMysql)
|
.addComponent(mUserName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
||||||
.addComponent(mUserName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
.addComponent(lblMysql))
|
||||||
|
.addPreferredGap(ComponentPlacement.RELATED)
|
||||||
|
.addComponent(mSavePassword)
|
||||||
.addPreferredGap(ComponentPlacement.RELATED)
|
.addPreferredGap(ComponentPlacement.RELATED)
|
||||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||||
.addComponent(lblMysqlServerPassword)
|
.addComponent(lblMysqlServerPassword)
|
||||||
.addComponent(mUserPassword, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
.addComponent(mUserPassword, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||||
.addPreferredGap(ComponentPlacement.RELATED)
|
.addPreferredGap(ComponentPlacement.RELATED)
|
||||||
.addComponent(mSaveButton)
|
.addComponent(mSaveButton)
|
||||||
.addContainerGap(142, Short.MAX_VALUE))
|
.addContainerGap(264, Short.MAX_VALUE))
|
||||||
);
|
);
|
||||||
setLayout(groupLayout);
|
setLayout(groupLayout);
|
||||||
|
|
||||||
@@ -157,17 +188,22 @@ public class SettingsPanel extends JPanel implements ActionListener {
|
|||||||
mServerLocation.setEnabled(true);
|
mServerLocation.setEnabled(true);
|
||||||
mPortNumber.setEnabled(true);
|
mPortNumber.setEnabled(true);
|
||||||
mUserName.setEnabled(true);
|
mUserName.setEnabled(true);
|
||||||
mUserPassword.setEnabled(true);
|
mUserPassword.setEnabled( Boolean.parseBoolean(mProps.getProperty(SAVE_PASSWORD, "false")));
|
||||||
mUseRemoteDatabase.setSelected(true);
|
mUseRemoteDatabase.setSelected(true);
|
||||||
|
mDatabaseName.setEnabled(true);
|
||||||
|
mSavePassword.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mDatabaseName.setText(mProps.getProperty(DATABASE_NAME, "Orders"));
|
||||||
mServerLocation.setText(mProps.getProperty(SERVER_LOCATION));
|
mServerLocation.setText(mProps.getProperty(SERVER_LOCATION));
|
||||||
mPortNumber.setText(mProps.getProperty(SERVER_PORT_NUMBER));;
|
mPortNumber.setText(mProps.getProperty(SERVER_PORT_NUMBER, "3306"));
|
||||||
mUserName.setText(mProps.getProperty(SERVER_USERNAME));;
|
mUserName.setText(mProps.getProperty(SERVER_USERNAME));
|
||||||
|
mSavePassword.setSelected(Boolean.parseBoolean(mProps.getProperty(SAVE_PASSWORD, "false")));
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
mDatabaseName.setText("Orders");
|
||||||
|
mPortNumber.setText("3306");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,49 +223,67 @@ public class SettingsPanel extends JPanel implements ActionListener {
|
|||||||
mProps.put(SERVER_LOCATION, mServerLocation.getText());
|
mProps.put(SERVER_LOCATION, mServerLocation.getText());
|
||||||
mProps.put(SERVER_PORT_NUMBER, mPortNumber.getText());
|
mProps.put(SERVER_PORT_NUMBER, mPortNumber.getText());
|
||||||
mProps.put(SERVER_USERNAME, mUserName.getText());
|
mProps.put(SERVER_USERNAME, mUserName.getText());
|
||||||
|
mProps.put(DATABASE_NAME, mDatabaseName.getText());
|
||||||
|
|
||||||
|
if(mSavePassword.isSelected())
|
||||||
mProps.put(SERVER_PASSWORD, new String(passwordEncryptor.encrypt(new String(mUserPassword.getPassword()))));
|
mProps.put(SERVER_PASSWORD, new String(passwordEncryptor.encrypt(new String(mUserPassword.getPassword()))));
|
||||||
try {
|
|
||||||
FileOutputStream out = new FileOutputStream(".settings.propertys");
|
writeProperties(mProps);
|
||||||
mProps.store(out, "---No Comment---");
|
|
||||||
out.close();
|
|
||||||
} catch (FileNotFoundException e1) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (IOException e1) {
|
|
||||||
// TODO Auto-gene1rated catch block
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//use remote database checkbox
|
//use remote database checkbox
|
||||||
if(e.getSource() == mUseRemoteDatabase){
|
if(e.getSource() == mUseRemoteDatabase){
|
||||||
mProps.put(IS_USING_REMOTE_SERVER, Boolean.toString(mUseRemoteDatabase.isSelected()));
|
mProps.put(IS_USING_REMOTE_SERVER, Boolean.toString(mUseRemoteDatabase.isSelected()));
|
||||||
try {
|
writeProperties(mProps);
|
||||||
FileOutputStream out = new FileOutputStream(".settings.propertys");
|
|
||||||
mProps.store(out, "---No Comment---");
|
|
||||||
out.close();
|
|
||||||
} catch (FileNotFoundException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(mUseRemoteDatabase.isSelected()){
|
if(mUseRemoteDatabase.isSelected()){
|
||||||
mServerLocation.setEnabled(true);
|
mServerLocation.setEnabled(true);
|
||||||
mPortNumber.setEnabled(true);
|
mPortNumber.setEnabled(true);
|
||||||
mUserName.setEnabled(true);
|
mUserName.setEnabled(true);
|
||||||
mUserPassword.setEnabled(true);
|
mUserPassword.setEnabled(true);
|
||||||
|
mDatabaseName.setEnabled(true);
|
||||||
|
mSavePassword.setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
mServerLocation.setEnabled(false);
|
mServerLocation.setEnabled(false);
|
||||||
mPortNumber.setEnabled(false);
|
mPortNumber.setEnabled(false);
|
||||||
mUserName.setEnabled(false);
|
mUserName.setEnabled(false);
|
||||||
mUserPassword.setEnabled(false);
|
mUserPassword.setEnabled(false);
|
||||||
|
mDatabaseName.setEnabled(false);
|
||||||
|
mSavePassword.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(e.getSource() == mSavePassword){
|
||||||
|
mProps.setProperty(SAVE_PASSWORD, Boolean.toString(mSavePassword.isSelected()));
|
||||||
|
writeProperties(mProps);
|
||||||
|
if(mSavePassword.isSelected()){
|
||||||
|
mUserPassword.setEnabled(true);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
mUserPassword.setEnabled(false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow.loadDatabase();
|
MainWindow.loadDatabase();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* writes the Properties to a persitent file
|
||||||
|
* @param p
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
private void writeProperties(Properties p){
|
||||||
|
try {
|
||||||
|
FileOutputStream out = new FileOutputStream(".settings.propertys");
|
||||||
|
p.store(out, "---Order Processor Settings---");
|
||||||
|
out.close();
|
||||||
|
} catch (FileNotFoundException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -43,3 +43,8 @@ added new order stats to the order pane
|
|||||||
fixed processed order stats to only display new order stats when theres new orders
|
fixed processed order stats to only display new order stats when theres new orders
|
||||||
added password encryption using jasypt
|
added password encryption using jasypt
|
||||||
|
|
||||||
|
1.1.4 b 49
|
||||||
|
added more options in settings allowing user to pick the database name.
|
||||||
|
added an option to allow the user to save their password
|
||||||
|
added a password field to the main panel to allow for easy password entry
|
||||||
|
added a connect button to the main panel
|
||||||
@@ -1 +1 @@
|
|||||||
1.1.3 b 48
|
1.1.4 b 49
|
||||||
Reference in New Issue
Block a user