From ff856d52518882cb3fa6d9eaca83cb0655d672a1 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 4 Aug 2008 20:42:34 +0000 Subject: Client: Tweaked the client to work (better) --- .../com/fourisland/instadisc/Database/Item.java | 85 -------------- .../com/fourisland/instadisc/Database/Wrapper.java | 59 ---------- .../instadisc/IDItemListCellRenderer.java | 2 +- .../com/fourisland/instadisc/InstaDiscThread.java | 2 +- .../com/fourisland/instadisc/InstaDiscView.form | 1 + .../com/fourisland/instadisc/InstaDiscView.java | 40 ++++--- .../src/com/fourisland/instadisc/Item/Item.java | 123 ++++++++++++++------- 7 files changed, 115 insertions(+), 197 deletions(-) delete mode 100644 client/trunk/src/com/fourisland/instadisc/Database/Item.java (limited to 'client/trunk/src/com/fourisland') diff --git a/client/trunk/src/com/fourisland/instadisc/Database/Item.java b/client/trunk/src/com/fourisland/instadisc/Database/Item.java deleted file mode 100644 index 7dbc89b..0000000 --- a/client/trunk/src/com/fourisland/instadisc/Database/Item.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.fourisland.instadisc.Database; - -import com.sleepycat.persist.model.Entity; -import com.sleepycat.persist.model.PrimaryKey; -import java.util.HashMap; - -/** - * - * @author hatkirby - */ -@Entity -public class Item { - - @PrimaryKey - private Integer id; - private String subscription; - private String title; - private String author; - private String url; - private HashMap semantics; - - public Item() { - semantics = new HashMap(); - } - - public Integer getID() { - return id; - } - - public String getSubscription() { - return subscription; - } - - public String getTitle() { - return title; - } - - public String getAuthor() { - return author; - } - - public String getURL() { - return url; - } - - public HashMap getSemantics() { - return semantics; - } - - public void setID(Integer id) { - this.id = id; - } - - public void setSubscription(String subscription) { - this.subscription = subscription; - } - - public void setTitle(String title) { - this.title = title; - } - - public void setAuthor(String author) { - this.author = author; - } - - public void setURL(String url) { - this.url = url; - } - - public void setSemantics(HashMap semantics) { - this.semantics = semantics; - } - - public String getSemantics(String key) { - return semantics.get(key); - } - - public void putSemantics(String key, String value) { - semantics.put(key, value); - } -} diff --git a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java index 92c84cc..a5c59e8 100644 --- a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java +++ b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java @@ -26,7 +26,6 @@ public class Wrapper { public static EntityStore es = null; public static PrimaryIndex oldVerID; public static PrimaryIndex idConfig; - public static PrimaryIndex item; public static PrimaryIndex subscription; public static PrimaryIndex filter; @@ -49,7 +48,6 @@ public class Wrapper { try { oldVerID = es.getPrimaryIndex(Integer.class, OldVerID.class); idConfig = es.getPrimaryIndex(String.class, IDConfig.class); - item = es.getPrimaryIndex(Integer.class, Item.class); subscription = es.getPrimaryIndex(String.class, Subscription.class); filter = es.getPrimaryIndex(Integer.class, Filter.class); } catch (DatabaseException ex) { @@ -137,63 +135,6 @@ public class Wrapper { } } - public static void addItem(Item m_item) { - synchronized (item) { - try { - item.put(m_item); - } catch (DatabaseException ex) { - Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - - public static int countItem() { - synchronized (item) { - try { - return (int) item.count(); - } catch (DatabaseException ex) { - Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); - return 0; - } - } - } - - public static void dropFromTopItem() { - synchronized (item) { - try { - Integer[] keySet = (Integer[]) item.map().keySet().toArray(); - item.delete(keySet[0]); - } catch (DatabaseException ex) { - Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - - public static Item[] getAllItem() { - synchronized (item) { - try { - Iterator i = item.entities().iterator(); - Item[] temp = new Item[0]; - int len = 0; - - while (i.hasNext()) { - Item[] temp2 = new Item[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 Item[0]; - } - } - } - public static Subscription getSubscription(String url) { synchronized (subscription) { try { diff --git a/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java b/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java index 21924e8..cdbc686 100644 --- a/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java +++ b/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java @@ -4,7 +4,7 @@ */ package com.fourisland.instadisc; -import com.fourisland.instadisc.Database.Item; +import com.fourisland.instadisc.Item.Item; import com.fourisland.instadisc.Database.Wrapper; import com.fourisland.instadisc.Item.Categories.Category; import java.awt.Component; diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java b/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java index 224021b..8384502 100644 --- a/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java +++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java @@ -56,7 +56,7 @@ public class InstaDiscThread implements Runnable { class HandleItemThread implements Runnable { Socket s; - + public HandleItemThread(Socket s) { this.s = s; } diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.form b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.form index 30ff6fb..1be0305 100644 --- a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.form +++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.form @@ -40,6 +40,7 @@ + diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java index 12e1dbd..f5f767f 100644 --- a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java +++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java @@ -3,7 +3,7 @@ */ package com.fourisland.instadisc; -import com.fourisland.instadisc.Database.Item; +import com.fourisland.instadisc.Item.Item; import com.fourisland.instadisc.Database.Wrapper; import com.fourisland.instadisc.Item.Categories.InstaDiscIcon; import java.awt.AWTException; @@ -94,11 +94,10 @@ public class InstaDiscView extends FrameView { } } }); - + this.getFrame().setIconImage(new ImageIcon(InstaDiscIcon.instadiscicon).getImage()); - - if (SystemTray.isSupported()) - { + + if (SystemTray.isSupported()) { try { TrayIcon ti = new TrayIcon(new ImageIcon(InstaDiscIcon.instadisciconmiddle).getImage(), "InstaDisc"); SystemTray.getSystemTray().add(ti); @@ -108,14 +107,15 @@ public class InstaDiscView extends FrameView { } } - jList1.setCellRenderer(new IDItemListCellRenderer()); + lm.ensureCapacity(10); + lm.clear(); jList1.setModel(lm); - refreshItemPane(); + jList1.setCellRenderer(new IDItemListCellRenderer()); InstaDiscThread idt = new InstaDiscThread(); Thread idtt = new Thread(idt); idtt.start(); - + XmlRpc xmlrpc = new XmlRpc("requestRetained"); xmlrpc.execute(); } @@ -170,6 +170,11 @@ public class InstaDiscView extends FrameView { jList1MouseClicked(evt); } }); + jList1.addComponentListener(new java.awt.event.ComponentAdapter() { + public void componentShown(java.awt.event.ComponentEvent evt) { + jList1ComponentShown(evt); + } + }); jScrollPane1.setViewportView(jList1); javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); @@ -338,6 +343,10 @@ public class InstaDiscView extends FrameView { xmlrpc.execute(); }//GEN-LAST:event_jMenuItem4ActionPerformed + private void jList1ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jList1ComponentShown + jList1.repaint(); + }//GEN-LAST:event_jList1ComponentShown + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JList jList1; private javax.swing.JMenu jMenu1; @@ -363,12 +372,15 @@ public class InstaDiscView extends FrameView { private JDialog aboutBox; private DefaultListModel lm = new DefaultListModel(); - public void refreshItemPane() { - lm.clear(); - Item[] items = Wrapper.getAllItem(); - int i = 0; - for (i = 0; i < items.length; i++) { - lm.addElement(items[i]); + public void addItemPane(Item item) { + if (lm.size() >= Integer.decode(Wrapper.getConfig("itemBufferSize"))) { + while (lm.size() >= Integer.decode(Wrapper.getConfig("itemBufferSize"))) { + lm.remove(0); + } } + + lm.addElement(item); + jList1.setModel(lm); + jList1.repaint(); } } diff --git a/client/trunk/src/com/fourisland/instadisc/Item/Item.java b/client/trunk/src/com/fourisland/instadisc/Item/Item.java index 6510c60..143e06f 100644 --- a/client/trunk/src/com/fourisland/instadisc/Item/Item.java +++ b/client/trunk/src/com/fourisland/instadisc/Item/Item.java @@ -10,12 +10,7 @@ import com.fourisland.instadisc.InstaDiscView; import com.fourisland.instadisc.XmlRpc; import java.awt.SystemTray; import java.awt.TrayIcon.MessageType; -import java.net.MalformedURLException; -import java.net.URL; import java.util.HashMap; -import java.util.Iterator; -import java.util.logging.Level; -import java.util.logging.Logger; /** * @@ -24,8 +19,75 @@ import java.util.logging.Logger; public class Item { HashMap headerMap; + private Integer id; + private String subscription; + private String title; + private String author; + private String url; + private HashMap semantics; + + public Item() { + semantics = new HashMap(); + } + + public Integer getID() { + return id; + } + + public String getSubscription() { + return subscription; + } + + public String getTitle() { + return title; + } + + public String getAuthor() { + return author; + } + + public String getURL() { + return url; + } + + public HashMap getSemantics() { + return semantics; + } + + public void setID(Integer id) { + this.id = id; + } + + public void setSubscription(String subscription) { + this.subscription = subscription; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setAuthor(String author) { + this.author = author; + } + + public void setURL(String url) { + this.url = url; + } + + public void setSemantics(HashMap semantics) { + this.semantics = semantics; + } + + public String getSemantics(String key) { + return semantics.get(key); + } + + public void putSemantics(String key, String value) { + semantics.put(key, value); + } public Item(HashMap headerMap) { + this(); this.headerMap = headerMap; } @@ -35,41 +97,28 @@ public class Item { XmlRpc xmlrpc = new XmlRpc("deleteItem"); xmlrpc.addParam(Integer.decode(headerMap.get("ID"))); xmlrpc.execute(); - - if (Wrapper.countItem() >= Integer.decode(Wrapper.getConfig("itemBufferSize"))) - { - Wrapper.dropFromTopItem(); - } - try { - com.fourisland.instadisc.Database.Item di = new com.fourisland.instadisc.Database.Item(); - di.setID(Integer.decode(headerMap.get("ID"))); - di.setSubscription(headerMap.get("Subscription")); - di.setTitle(headerMap.get("Title")); - di.setAuthor(headerMap.get("Author")); - di.setURL(new URL(headerMap.get("URL")).toString()); - - HashMap temp = new HashMap(headerMap); - temp.remove("ID"); - temp.remove("Verification"); - temp.remove("Verification-ID"); - temp.remove("Subscription"); - temp.remove("Title"); - temp.remove("Author"); - temp.remove("URL"); - di.setSemantics(temp); - - Wrapper.addItem(di); - } catch (MalformedURLException ex) { - Logger.getLogger(Item.class.getName()).log(Level.SEVERE, null, ex); - } - - if (SystemTray.isSupported()) - { + setID(Integer.decode(headerMap.get("ID"))); + setSubscription(headerMap.get("Subscription")); + setTitle(headerMap.get("Title")); + setAuthor(headerMap.get("Author")); + setURL(headerMap.get("URL")); + + HashMap temp = new HashMap(headerMap); + temp.remove("ID"); + temp.remove("Verification"); + temp.remove("Verification-ID"); + temp.remove("Subscription"); + temp.remove("Title"); + temp.remove("Author"); + temp.remove("URL"); + setSemantics(temp); + + ((InstaDiscView) InstaDiscApp.getApplication().getMainView()).addItemPane(this); + + if (SystemTray.isSupported()) { InstaDiscApp.ti.displayMessage("New item recieved!", Wrapper.getSubscription(headerMap.get("Subscription")).getTitle() + ", " + headerMap.get("Title") + " by " + headerMap.get("Author"), MessageType.INFO); } - - ((InstaDiscView)InstaDiscApp.getApplication().getMainView()).refreshItemPane(); } } } -- cgit 1.4.1