From 4c7d34bcca02634892bea2253c027cd8d1d73947 Mon Sep 17 00:00:00 2001 From: mdb Date: Wed, 21 Mar 2001 00:41:03 +0000 Subject: [PATCH] Center the primary window. Created a "finished" panel which allows you to go back and rip another CD or (soon) to edit/categorize the CD you just ripped. Cleaned up various other kibbles. git-svn-id: https://samskivert.googlecode.com/svn/trunk@106 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/robodj/importer/CDDBLookupPanel.java | 5 +- .../java/robodj/importer/FinishedPanel.java | 79 +++++++++++++++++++ .../src/java/robodj/importer/Importer.java | 12 ++- .../java/robodj/importer/ImporterFrame.java | 14 +--- .../java/robodj/importer/InsertCDPanel.java | 5 +- .../src/java/robodj/importer/RipPanel.java | 27 +++++-- 6 files changed, 119 insertions(+), 23 deletions(-) create mode 100644 projects/robodj/src/java/robodj/importer/FinishedPanel.java diff --git a/projects/robodj/src/java/robodj/importer/CDDBLookupPanel.java b/projects/robodj/src/java/robodj/importer/CDDBLookupPanel.java index b0f602ec..75d03da8 100644 --- a/projects/robodj/src/java/robodj/importer/CDDBLookupPanel.java +++ b/projects/robodj/src/java/robodj/importer/CDDBLookupPanel.java @@ -1,5 +1,5 @@ // -// $Id: CDDBLookupPanel.java,v 1.2 2001/03/18 06:58:55 mdb Exp $ +// $Id: CDDBLookupPanel.java,v 1.3 2001/03/21 00:41:03 mdb Exp $ package robodj.importer; @@ -174,8 +174,7 @@ public class CDDBLookupPanel } // create the rip panel and pass the entry and info along - RipPanel panel = new RipPanel(_info, entry); - _frame.setPanel(panel); + _frame.setPanel(new RipPanel(_info, entry)); } protected boolean validate (String value, String errmsg) diff --git a/projects/robodj/src/java/robodj/importer/FinishedPanel.java b/projects/robodj/src/java/robodj/importer/FinishedPanel.java new file mode 100644 index 00000000..3a57c034 --- /dev/null +++ b/projects/robodj/src/java/robodj/importer/FinishedPanel.java @@ -0,0 +1,79 @@ +// +// $Id: FinishedPanel.java,v 1.1 2001/03/21 00:41:03 mdb Exp $ + +package robodj.importer; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.URL; +import javax.swing.*; + +import com.samskivert.swing.*; +import robodj.repository.*; + +public class FinishedPanel + extends ImporterPanel + implements ActionListener +{ + public FinishedPanel (Entry entry) + { + GroupLayout gl = new HGroupLayout(GroupLayout.STRETCH); + gl.setOffAxisPolicy(GroupLayout.STRETCH); + setLayout(gl); + + // create our label for the left hand side + JLabel cdlabel = new JLabel("Finished", JLabel.CENTER); + cdlabel.setFont(new Font("Helvetica", Font.BOLD, 24)); + add(cdlabel, GroupLayout.FIXED); + + // create a panel for the option buttons + GroupLayout vgl = new VGroupLayout(GroupLayout.NONE); + vgl.setOffAxisPolicy(GroupLayout.NONE); + vgl.setJustification(GroupLayout.CENTER); + JPanel ppanel = new JPanel(vgl); + + // create our action buttons + String[] labels = new String[] + { "Import another CD", "Edit/categorize CDs" }; + String[] actions = new String[] { "import", "edit" }; + + for (int i = 0; i < labels.length; i++) { + JButton abutton = new JButton(labels[i]); + abutton.setActionCommand(actions[i]); + abutton.addActionListener(this); + ppanel.add(abutton); + } + + // add our panel to the main group + add(ppanel); + + // save this guy for later + _entry = entry; + } + + public void wasAddedToFrame (ImporterFrame frame) + { + frame.addControlButton("Exit", "exit", this); + + // keep a handle on this for later + _frame = frame; + } + + public void actionPerformed (ActionEvent e) + { + String cmd = e.getActionCommand(); + if (cmd.equals("exit")) { + System.exit(0); + + } else if (cmd.equals("import")) { + _frame.setPanel(new InsertCDPanel()); + + } else { + System.out.println("Unknown action event: " + cmd); + } + } + + protected ImporterFrame _frame; + protected Entry _entry; +} diff --git a/projects/robodj/src/java/robodj/importer/Importer.java b/projects/robodj/src/java/robodj/importer/Importer.java index 1d00072a..b3cbf226 100644 --- a/projects/robodj/src/java/robodj/importer/Importer.java +++ b/projects/robodj/src/java/robodj/importer/Importer.java @@ -1,8 +1,10 @@ // -// $Id: Importer.java,v 1.2 2001/03/18 06:58:55 mdb Exp $ +// $Id: Importer.java,v 1.3 2001/03/21 00:41:03 mdb Exp $ package robodj.importer; +import java.awt.Dimension; +import java.awt.Toolkit; import java.sql.SQLException; import java.util.Properties; @@ -51,9 +53,17 @@ public class Importer System.exit(-1); } + // create our frame and first panel ImporterFrame frame = new ImporterFrame(); InsertCDPanel panel = new InsertCDPanel(); frame.setPanel(panel); + + // center the frame in the screen and show it + Toolkit tk = frame.getToolkit(); + Dimension ss = tk.getScreenSize(); + int width = 550, height = 300; + frame.setBounds((ss.width-width)/2, (ss.height-height)/2, + width, height); frame.setVisible(true); } } diff --git a/projects/robodj/src/java/robodj/importer/ImporterFrame.java b/projects/robodj/src/java/robodj/importer/ImporterFrame.java index 89edb7cf..613dd125 100644 --- a/projects/robodj/src/java/robodj/importer/ImporterFrame.java +++ b/projects/robodj/src/java/robodj/importer/ImporterFrame.java @@ -1,5 +1,5 @@ // -// $Id: ImporterFrame.java,v 1.2 2001/03/18 06:58:55 mdb Exp $ +// $Id: ImporterFrame.java,v 1.3 2001/03/21 00:41:03 mdb Exp $ package robodj.importer; @@ -38,13 +38,9 @@ public class ImporterFrame extends JFrame public void setPanel (ImporterPanel panel) { - boolean repack = true; - // clear out any old panel if (_panel != null) { _top.remove(_panel); - // don't repack if there was an old panel - repack = false; } // clear out old control buttons @@ -58,12 +54,8 @@ public class ImporterFrame extends JFrame _panel.wasAddedToFrame(this); } - // and possibly repack ourselves - if (repack) { - pack(); - } else { - validate(); - } + // and lay out the new panel + validate(); } public JButton addControlButton (String label, String command, diff --git a/projects/robodj/src/java/robodj/importer/InsertCDPanel.java b/projects/robodj/src/java/robodj/importer/InsertCDPanel.java index c30fbad8..03f5ff0e 100644 --- a/projects/robodj/src/java/robodj/importer/InsertCDPanel.java +++ b/projects/robodj/src/java/robodj/importer/InsertCDPanel.java @@ -1,5 +1,5 @@ // -// $Id: InsertCDPanel.java,v 1.1 2000/12/10 07:02:09 mdb Exp $ +// $Id: InsertCDPanel.java,v 1.2 2001/03/21 00:41:03 mdb Exp $ package robodj.importer; @@ -49,8 +49,7 @@ public class InsertCDPanel System.exit(0); } else if (cmd.equals("next")) { - CDDBLookupPanel panel = new CDDBLookupPanel(); - _frame.setPanel(panel); + _frame.setPanel(new CDDBLookupPanel()); } else { System.out.println("Unknown action event: " + cmd); diff --git a/projects/robodj/src/java/robodj/importer/RipPanel.java b/projects/robodj/src/java/robodj/importer/RipPanel.java index f66add90..d6eb7340 100644 --- a/projects/robodj/src/java/robodj/importer/RipPanel.java +++ b/projects/robodj/src/java/robodj/importer/RipPanel.java @@ -1,5 +1,5 @@ // -// $Id: RipPanel.java,v 1.2 2001/03/18 06:58:55 mdb Exp $ +// $Id: RipPanel.java,v 1.3 2001/03/21 00:41:03 mdb Exp $ package robodj.importer; @@ -248,7 +248,13 @@ public class RipPanel // insert the entry into the repository so that we get the // proper entry id which we'll need to put the tracks in their // proper place in the repository - Importer.repository.insertEntry(_entry); + RetryableTask iop = new RetryableTask() { + public void invoke () throws Exception + { + Importer.repository.insertEntry(_entry); + } + }; + iop.invokeTask(_frame, DB_FAILURE_MSG); // track this so that we can clean up in case of failure entryid = _entry.entryid; @@ -284,7 +290,13 @@ public class RipPanel } // finally update the entry in the database - Importer.repository.updateEntry(_entry); + RetryableTask uop = new RetryableTask() { + public void invoke () throws Exception + { + Importer.repository.updateEntry(_entry); + } + }; + uop.invokeTask(_frame, DB_FAILURE_MSG); // and clear out the entryid to indicate success entryid = -1; @@ -335,7 +347,6 @@ public class RipPanel } else if (name.equals("commit")) { // we're all done. fix up the buttons and call it good _cancel.setEnabled(false); - _next.setLabel("Exit"); _next.setEnabled(true); } } @@ -359,7 +370,7 @@ public class RipPanel System.exit(0); } else if (cmd.equals("next")) { - System.exit(0); + _frame.setPanel(new FinishedPanel(_entry)); } else { System.out.println("Unknown action event: " + cmd); @@ -377,4 +388,10 @@ public class RipPanel protected Ripper.TrackInfo[] _info; protected Entry _entry; + + protected static final String DB_FAILURE_MSG = + "An error occurred while communicating with the database. You " + + "may wish to examine the following error message, remedy the " + + "problem with the database and retry the operation. Or you can " + + "abort the operation and cancel the import process entirely."; }