added clear button to the ShowAllPanel.java

fixed the export save dialog to automatically handle extensions
added new order stats to the order pane
This commit is contained in:
2011-01-23 04:22:27 +00:00
parent 7d1fe95e5a
commit 21c7d0642b
8 changed files with 98 additions and 41 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -54,7 +54,9 @@ public class OrderPane extends JScrollPane {
mOutput.setText(null); mOutput.setText(null);
BigDecimal possible = new BigDecimal(0); BigDecimal possible = new BigDecimal(0);
BigDecimal actual = new BigDecimal(0); BigDecimal actual = new BigDecimal(0);
BigDecimal possibleNew = new BigDecimal(0);
int total = 0; int total = 0;
int newOrders = 0;
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
if(mListener != null) if(mListener != null)
@@ -67,6 +69,8 @@ public class OrderPane extends JScrollPane {
break; break;
case NEW: case NEW:
styles.add(TextStyle.BLUE.toString()); styles.add(TextStyle.BLUE.toString());
newOrders++;
possibleNew = possibleNew.add(new BigDecimal(list.get(i).getOrderAmount()));
break; break;
default: default:
styles.add(TextStyle.REGULAR.toString()); styles.add(TextStyle.REGULAR.toString());
@@ -82,7 +86,12 @@ public class OrderPane extends JScrollPane {
} }
updateTextPane(list, styles); updateTextPane(list, styles);
updateTextPane("\nPossible sales: $" + possible.setScale(2, BigDecimal.ROUND_DOWN) + "\nActual sales: $" + actual.setScale(2, BigDecimal.ROUND_DOWN) + "\nPossible sold:" + list.size() + "\nTotal sold: " + total, TextStyle.BOLD); updateTextPane("\nPossible sold:" + list.size()
+"\nPossible sales: $" + possible.setScale(2, BigDecimal.ROUND_DOWN)
+ "\n\nTotal new sales: "+ newOrders
+ "\nPossible new sales: $"+ possibleNew.setScale(2, BigDecimal.ROUND_DOWN)
+ "\n\nTotal sold: " + total
+ "\nActual sales: $" + actual.setScale(2, BigDecimal.ROUND_DOWN) , TextStyle.BOLD);
} }
/** /**

View File

@@ -53,7 +53,7 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
private JCheckBox mExclusiveCheckBox; private JCheckBox mExclusiveCheckBox;
private JButton mExportButton; private JButton mExportButton;
private JFileChooser fc; private JFileChooser fc;
private JCheckBox fcCheckBox; // private JCheckBox fcCheckBox;
private JFrame mFrame; private JFrame mFrame;
/** /**
@@ -120,9 +120,6 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
//file chooser //file chooser
fc = new JFileChooser(); fc = new JFileChooser();
fc.setFileFilter(new FileFilter()); fc.setFileFilter(new FileFilter());
fcCheckBox = new JCheckBox("Automatically append extention");
fcCheckBox.setSelected(true);
fc.setAccessory(fcCheckBox);
setVisible(true); setVisible(true);
} }
@@ -161,15 +158,21 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
private boolean exportToCSV() { private boolean exportToCSV() {
if(fc.showDialog(SearchPanel.this, "Export") == JFileChooser.APPROVE_OPTION){ if(fc.showDialog(SearchPanel.this, "Export") == JFileChooser.APPROVE_OPTION){
int write = 0; int write = 0;
boolean hasExtention;
String filename = fc.getSelectedFile().toString();
String ext =filename.substring((filename.lastIndexOf(".")+1),filename.length());
hasExtention = ext.equalsIgnoreCase("csv");
//file exists dialog //file exists dialog
if(fc.getSelectedFile().exists()){ if(new File(filename + (( ! hasExtention ) ? ".csv" : "") ).exists()){
//default icon, custom title //default icon, custom title
write = JOptionPane.showConfirmDialog( write = JOptionPane.showConfirmDialog(
mFrame, mFrame, "Do you want to overwrite"+ filename + ((! hasExtention ) ? ".csv" : ""),
"Do you want to overwrite"+ fc.getSelectedFile().toString(),
"Overwrite?", "Overwrite?",
JOptionPane.YES_NO_OPTION); JOptionPane.YES_NO_OPTION);
System.out.print(write);
} }
if(write == 0){ if(write == 0){
@@ -189,11 +192,7 @@ public class SearchPanel extends JPanel implements ActionListener, ProgressListe
} }
//write to the selceted file //write to the selceted file
try { try {
FileOutputStream theFile; FileOutputStream theFile = new FileOutputStream(filename + (( ! hasExtention ) ? ".csv" : ""));
if (fcCheckBox.isSelected())
theFile = new FileOutputStream(new File(fc.getSelectedFile().toString()+".csv"));
else
theFile = new FileOutputStream(fc.getSelectedFile());
theFile.write(sb.toString().getBytes()); theFile.write(sb.toString().getBytes());
theFile.flush(); theFile.flush();
theFile.close(); theFile.close();

View File

@@ -53,36 +53,42 @@ public class SettingsPanel extends JPanel implements ActionListener {
JLabel lblMysqlServerLocation = new JLabel("MYsql server location:"); JLabel lblMysqlServerLocation = new JLabel("MYsql server location:");
//mql database location
mServerLocation = new JTextField(); mServerLocation = new JTextField();
mServerLocation.setColumns(10); mServerLocation.setColumns(10);
//use remote database checkbox
mUseRemoteDatabase = new JCheckBox("Use Remote Database?"); mUseRemoteDatabase = new JCheckBox("Use Remote Database?");
mUseRemoteDatabase.addActionListener(this); mUseRemoteDatabase.addActionListener(this);
JLabel lblMysqlServerPort = new JLabel("MYsql server port:"); JLabel lblMysqlServerPort = new JLabel("MYsql server port:");
//server port number
mPortNumber = new JTextField(); mPortNumber = new JTextField();
mPortNumber.setColumns(10); mPortNumber.setColumns(10);
mPortNumber.setText("3306"); mPortNumber.setText("3306");
JLabel lblMysql = new JLabel("MYsql serevr username:"); JLabel lblMysql = new JLabel("MYsql serevr username:");
JLabel lblMysqlServerPassword = new JLabel("MYsql server password:"); JLabel lblMysqlServerPassword = new JLabel("MYsql server password:");
//username
mUserName = new JTextField(); mUserName = new JTextField();
mUserName.setColumns(10); mUserName.setColumns(10);
//user password
mUserPassword = new JPasswordField(); mUserPassword = new JPasswordField();
mUserPassword.setColumns(10); mUserPassword.setColumns(10);
//disable everything
mServerLocation.setEnabled(false); mServerLocation.setEnabled(false);
mPortNumber.setEnabled(false); mPortNumber.setEnabled(false);
mUserName.setEnabled(false); mUserName.setEnabled(false);
mUserPassword.setEnabled(false); mUserPassword.setEnabled(false);
//save button
mSaveButton = new JButton("Save"); mSaveButton = new JButton("Save");
mSaveButton.addActionListener(this); mSaveButton.addActionListener(this);
//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)
@@ -137,9 +143,6 @@ public class SettingsPanel extends JPanel implements ActionListener {
// create and load default properties // create and load default properties
mProps = new Properties(); mProps = new Properties();
mProps = new java.util.Properties();
try { try {
FileInputStream in = new FileInputStream(".settings.propertys"); FileInputStream in = new FileInputStream(".settings.propertys");
mProps.load(in); mProps.load(in);
@@ -164,8 +167,16 @@ public class SettingsPanel extends JPanel implements ActionListener {
} }
} }
/**
* called when the save button is clicked, or the use remote database check box is clicked
* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
* @author ricky barrette
*/
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
//save button
if(e.getSource() == mSaveButton){ if(e.getSource() == mSaveButton){
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());
@@ -185,6 +196,7 @@ public class SettingsPanel extends JPanel implements ActionListener {
} }
//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 { try {
@@ -192,10 +204,8 @@ public class SettingsPanel extends JPanel implements ActionListener {
mProps.store(out, "---No Comment---"); mProps.store(out, "---No Comment---");
out.close(); out.close();
} catch (FileNotFoundException e1) { } catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace(); e1.printStackTrace();
} catch (IOException e1) { } catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace(); e1.printStackTrace();
} }

View File

@@ -21,7 +21,7 @@ import javax.swing.JProgressBar;
import com.TwentyCodes.java.OrderProcessor.ProgressListener; import com.TwentyCodes.java.OrderProcessor.ProgressListener;
/** /**
* This panel will be used to display all Vehicles in the VechicleDB * This panel will be used to display all orders in the order database
*/ */
public class ShowAllPanel extends JPanel implements ActionListener, ProgressListener { public class ShowAllPanel extends JPanel implements ActionListener, ProgressListener {
@@ -29,6 +29,8 @@ public class ShowAllPanel extends JPanel implements ActionListener, ProgressList
private JProgressBar mProgressBar; private JProgressBar mProgressBar;
private OrderPane mOutput; private OrderPane mOutput;
private JFrame mFrame; private JFrame mFrame;
private JButton ok;
private JButton clear;
/** /**
* Creates a new ShowAllDialog * Creates a new ShowAllDialog
@@ -37,41 +39,73 @@ public class ShowAllPanel extends JPanel implements ActionListener, ProgressList
super(new BorderLayout()); super(new BorderLayout());
mFrame = frame; mFrame = frame;
JPanel panel = new JPanel();
// setTitle("Show All Orders"); // setTitle("Show All Orders");
// setIconImage(new ImageIcon(getClass().getResource("/database.png")).getImage()); // setIconImage(new ImageIcon(getClass().getResource("/database.png")).getImage());
JButton ok = new JButton("Refresh", new ImageIcon(getClass().getResource("/process.png"))); //ok button
ok = new JButton("Refresh", new ImageIcon(getClass().getResource("/page_process.png")));
ok.addActionListener(this); ok.addActionListener(this);
panel.add(ok);
//clear button
clear = new JButton("Clear", new ImageIcon(getClass().getResource("/page.png")));
clear.addActionListener(this);
panel.add(clear);
mOutput = new OrderPane(); mOutput = new OrderPane();
mProgressBar = new JProgressBar(); mProgressBar = new JProgressBar();
add(mProgressBar, BorderLayout.SOUTH); add(mProgressBar, BorderLayout.SOUTH);
add(mOutput, BorderLayout.CENTER); add(mOutput, BorderLayout.CENTER);
add(ok, BorderLayout.NORTH); add(panel, BorderLayout.NORTH);
mProgressBar.setString("Loading from Database");
mProgressBar.setStringPainted(true); mProgressBar.setStringPainted(true);
frame.pack(); frame.pack();
setVisible(true); setVisible(true);
} }
/**
* called when the buttons are clicked
* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
* @author ricky barrette
*/
@Override @Override
public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent e) {
MainWindow.db.setOnProgressListerner(this);
java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() { //display all the orders
public void run() { if(e.getSource() == ok){
try { MainWindow.db.setOnProgressListerner(this);
mOutput.displayOrders(MainWindow.db.getAllOrders()); java.util.concurrent.Executors.newSingleThreadExecutor().submit(new Runnable() {
} catch (SQLException e) { public void run() {
e.printStackTrace(); try {
} catch (IOException e) { mOutput.displayOrders(MainWindow.db.getAllOrders());
e.printStackTrace(); } catch (SQLException e) {
} catch (ClassNotFoundException e) { e.printStackTrace();
e.printStackTrace(); } catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
mFrame.pack();
} }
mFrame.pack(); });
} }
});
//clear the output
if(e.getSource() == clear){
mOutput.setText(null);
onProgressUpdate(null, false, 0, 1);
mFrame.pack();
}
} }
/**
* called when there is a progress update
* (non-Javadoc)
* @see com.TwentyCodes.java.OrderProcessor.ProgressListener#onProgressUpdate(java.lang.String, boolean, int, int)
* @author ricky barrette
*/
@Override @Override
public void onProgressUpdate(String string, boolean isIndeterminate, int progress, int max) { public void onProgressUpdate(String string, boolean isIndeterminate, int progress, int max) {
mProgressBar.setMaximum(max); mProgressBar.setMaximum(max);

View File

@@ -33,3 +33,8 @@ modified the date picker to be easier to use
1.1.1 b 46 1.1.1 b 46
re-added the show all dialog. re-added the show all dialog.
MainWinod.java, reorganized the constructor so the progress bar will be indeterminate when connecting to the database MainWinod.java, reorganized the constructor so the progress bar will be indeterminate when connecting to the database
1.1.2 b 47
added clear button to the ShowAllPanel.java
fixed the export save dialog to automatically handle extensions
added new order stats to the order pane

View File

@@ -1 +1 @@
1.1.0 b 35 1.1.2 b 47