From d768477ac4d17279430cd5d53b870981fdb7e267 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 31 Jul 2008 16:37:50 +0000 Subject: Client: Created Manage Subscriptions form --- .../fourisland/instadisc/AddSubscriptionForm.form | 3 + .../fourisland/instadisc/AddSubscriptionForm.java | 13 +- .../com/fourisland/instadisc/Database/Wrapper.java | 37 +++++ .../instadisc/IDItemListCellRenderer.java | 2 - .../instadisc/IDSubscriptionListCellRenderer.java | 36 +++++ .../com/fourisland/instadisc/InstaDiscView.form | 3 + .../com/fourisland/instadisc/InstaDiscView.java | 13 +- .../instadisc/ManageSubscriptionsForm.form | 123 +++++++++++++++ .../instadisc/ManageSubscriptionsForm.java | 174 +++++++++++++++++++++ .../resources/AddSubscriptionForm.properties | 2 +- .../resources/ManageSubscriptionsForm.properties | 6 + 11 files changed, 405 insertions(+), 7 deletions(-) create mode 100644 client/trunk/src/com/fourisland/instadisc/IDSubscriptionListCellRenderer.java create mode 100644 client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.form create mode 100644 client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java create mode 100644 client/trunk/src/com/fourisland/instadisc/resources/ManageSubscriptionsForm.properties (limited to 'client/trunk') diff --git a/client/trunk/src/com/fourisland/instadisc/AddSubscriptionForm.form b/client/trunk/src/com/fourisland/instadisc/AddSubscriptionForm.form index 91459ed..22f7ea6 100644 --- a/client/trunk/src/com/fourisland/instadisc/AddSubscriptionForm.form +++ b/client/trunk/src/com/fourisland/instadisc/AddSubscriptionForm.form @@ -103,6 +103,9 @@ + + + diff --git a/client/trunk/src/com/fourisland/instadisc/AddSubscriptionForm.java b/client/trunk/src/com/fourisland/instadisc/AddSubscriptionForm.java index fb05037..1609875 100644 --- a/client/trunk/src/com/fourisland/instadisc/AddSubscriptionForm.java +++ b/client/trunk/src/com/fourisland/instadisc/AddSubscriptionForm.java @@ -57,6 +57,11 @@ public class AddSubscriptionForm extends javax.swing.JDialog { jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N jButton1.setName("jButton1"); // NOI18N + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N jButton2.setName("jButton2"); // NOI18N @@ -117,12 +122,16 @@ public class AddSubscriptionForm extends javax.swing.JDialog { private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed try { - URL url = new URL(jTextField1.getText());//GEN-LAST:event_jButton2ActionPerformed + URL url = new URL(jTextField1.getText()); SubscriptionFile sf = new SubscriptionFile(url, jLabel4); } catch (MalformedURLException ex) { jLabel4.setText("Error: Subscription URL is malformed"); } - } + }//GEN-LAST:event_jButton2ActionPerformed + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + setVisible(false); + }//GEN-LAST:event_jButton1ActionPerformed /** * @param args the command line arguments diff --git a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java index 57ec799..3aed859 100644 --- a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java +++ b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java @@ -223,4 +223,41 @@ public class Wrapper { } } } + + public static Subscription[] getAllSubscription() { + synchronized (subscription) { + try { + Iterator i = subscription.entities().iterator(); + Subscription[] temp = new Subscription[0]; + int len = 0; + + while (i.hasNext()) { + Subscription[] temp2 = new Subscription[len + 1]; + int j = 0; + for (j = 0; j < len; j++) { + temp2[j] = temp[j]; + } + temp2[len] = i.next(); + temp = temp2; + } + + return temp; + } catch (DatabaseException ex) { + Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); + return new Subscription[0]; + } + } + } + + public static void deleteSubscription(String url) + { + synchronized (subscription) + { + try { + subscription.delete(url); + } catch (DatabaseException ex) { + Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); + } + } + } } diff --git a/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java b/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java index 39c6445..b5204e6 100644 --- a/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java +++ b/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java @@ -7,9 +7,7 @@ package com.fourisland.instadisc; import com.fourisland.instadisc.Database.Item; import com.fourisland.instadisc.Database.Wrapper; import com.fourisland.instadisc.Item.Categories.Category; -import java.awt.Color; import java.awt.Component; -import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.ListCellRenderer; diff --git a/client/trunk/src/com/fourisland/instadisc/IDSubscriptionListCellRenderer.java b/client/trunk/src/com/fourisland/instadisc/IDSubscriptionListCellRenderer.java new file mode 100644 index 0000000..546f3ac --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/IDSubscriptionListCellRenderer.java @@ -0,0 +1,36 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.fourisland.instadisc; + +import com.fourisland.instadisc.Database.Subscription; +import java.awt.Component; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; + +/** + * + * @author hatkirby + */ +class IDSubscriptionListCellRenderer extends JLabel implements ListCellRenderer { + + public Component getListCellRendererComponent(JList arg0, Object arg1, int arg2, boolean arg3, boolean arg4) { + this.setText(((Subscription) arg1).getTitle()); + + if (arg3) { + this.setForeground(arg0.getSelectionForeground()); + this.setBackground(arg0.getSelectionBackground()); + } else { + this.setForeground(arg0.getForeground()); + this.setBackground(arg0.getBackground()); + } + + this.setOpaque(true); + this.setFont(arg0.getFont()); + this.setEnabled(arg0.isEnabled()); + + return this; + } +} diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.form b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.form index 0f42036..7baafca 100644 --- a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.form +++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.form @@ -79,6 +79,9 @@ + + + diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java index 7cce3cd..2a4481a 100644 --- a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java +++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java @@ -7,7 +7,6 @@ import com.fourisland.instadisc.Database.Item; import com.fourisland.instadisc.Database.Wrapper; import com.fourisland.instadisc.Item.Categories.InstaDiscIcon; import java.awt.AWTException; -import java.awt.Image; import java.awt.SystemTray; import java.awt.TrayIcon; import org.jdesktop.application.Action; @@ -198,6 +197,11 @@ public class InstaDiscView extends FrameView { jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N jMenuItem2.setName("jMenuItem2"); // NOI18N + jMenuItem2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jMenuItem2ActionPerformed(evt); + } + }); fileMenu.add(jMenuItem2); jSeparator1.setName("jSeparator1"); // NOI18N @@ -296,6 +300,11 @@ public class InstaDiscView extends FrameView { asf.setVisible(true); }//GEN-LAST:event_jMenuItem1ActionPerformed + private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed + ManageSubscriptionsForm msf = new ManageSubscriptionsForm(new JFrame(), true); + msf.setVisible(true); + }//GEN-LAST:event_jMenuItem2ActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JList jList1; private javax.swing.JMenu jMenu1; @@ -322,7 +331,7 @@ public class InstaDiscView extends FrameView { private DefaultListModel lm = new DefaultListModel(); public void refreshItemPane() { - lm.capacity(); + lm.clear(); Item[] items = Wrapper.getAllItem(); int i = 0; for (i = 0; i < items.length; i++) { diff --git a/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.form b/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.form new file mode 100644 index 0000000..aba7b45 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.form @@ -0,0 +1,123 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java b/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java new file mode 100644 index 0000000..c3cbf4a --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java @@ -0,0 +1,174 @@ +/* + * ManageSubscriptionsForm.java + * + * Created on July 31, 2008, 12:14 PM + */ + +package com.fourisland.instadisc; + +import com.fourisland.instadisc.Database.Subscription; +import com.fourisland.instadisc.Database.Wrapper; +import javax.swing.DefaultListModel; + +/** + * + * @author hatkirby + */ +public class ManageSubscriptionsForm extends javax.swing.JDialog { + + /** Creates new form ManageSubscriptionsForm */ + public ManageSubscriptionsForm(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + + jList1.setCellRenderer(new IDSubscriptionListCellRenderer()); + jList1.setModel(lm); + refreshSubscriptionPane(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jList1 = new javax.swing.JList(); + jButton1 = new javax.swing.JButton(); + jButton2 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setName("Form"); // NOI18N + + org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.fourisland.instadisc.InstaDiscApp.class).getContext().getResourceMap(ManageSubscriptionsForm.class); + jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N + jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N + jLabel1.setName("jLabel1"); // NOI18N + + jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N + jLabel2.setName("jLabel2"); // NOI18N + + jScrollPane1.setName("jScrollPane1"); // NOI18N + + jList1.setName("jList1"); // NOI18N + jScrollPane1.setViewportView(jList1); + + jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N + jButton1.setName("jButton1"); // NOI18N + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N + jButton2.setName("jButton2"); // NOI18N + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1) + .addGroup(layout.createSequentialGroup() + .addGap(12, 12, 12) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2))))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(235, Short.MAX_VALUE) + .addComponent(jButton1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton2))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jButton2) + .addComponent(jButton1)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + if (!jList1.isSelectionEmpty()) + { + Subscription subscription = (Subscription) jList1.getSelectedValue(); + Wrapper.deleteSubscription(subscription.getURL()); + + XmlRpc xmlrpc = new XmlRpc("deleteSubscription"); + xmlrpc.addParam(subscription.getURL()); + xmlrpc.execute(); + + refreshSubscriptionPane(); + } + }//GEN-LAST:event_jButton1ActionPerformed + + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + setVisible(false); + }//GEN-LAST:event_jButton2ActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + ManageSubscriptionsForm dialog = new ManageSubscriptionsForm(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JList jList1; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables + + DefaultListModel lm = new DefaultListModel(); + + public void refreshSubscriptionPane() { + lm.clear(); + Subscription[] subscriptions = Wrapper.getAllSubscription(); + int i = 0; + for (i = 0; i < subscriptions.length; i++) { + lm.addElement(subscriptions[i]); + } + + jList1.setEnabled(!lm.isEmpty()); + jButton1.setEnabled(!lm.isEmpty()); + } +} diff --git a/client/trunk/src/com/fourisland/instadisc/resources/AddSubscriptionForm.properties b/client/trunk/src/com/fourisland/instadisc/resources/AddSubscriptionForm.properties index 1bafc98..a528bf6 100644 --- a/client/trunk/src/com/fourisland/instadisc/resources/AddSubscriptionForm.properties +++ b/client/trunk/src/com/fourisland/instadisc/resources/AddSubscriptionForm.properties @@ -4,6 +4,6 @@ jLabel1.font=DejaVu Sans-Plain-18 jLabel2.text=To recieve InstaDisc notifications, you need to subscribe
to a website's content. If a website supports InstaDisc
it should be advertising a link to an "InstaDisc Subscription
File". To subscribe to that website's content, copy the URL
into the box below. jLabel3.text=Subscription File URL: jTextField1.text= -jButton1.text=Cancel +jButton1.text=Done jButton2.text=OK jLabel4.text= diff --git a/client/trunk/src/com/fourisland/instadisc/resources/ManageSubscriptionsForm.properties b/client/trunk/src/com/fourisland/instadisc/resources/ManageSubscriptionsForm.properties new file mode 100644 index 0000000..1fae114 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/resources/ManageSubscriptionsForm.properties @@ -0,0 +1,6 @@ +jLabel1.text=Manage Subscriptions +#NOI18N +jLabel1.font=DejaVu Sans-Plain-18 +jLabel2.text=If you get bored or annoyed with a certain subscription,
you can unsubscribe from it right here. Just choose the
subscription from the list below and click "Unsubscribe". +jButton1.text=Unsubscribe +jButton2.text=Done -- cgit 1.4.1