diff options
Diffstat (limited to 'client/trunk')
6 files changed, 155 insertions, 99 deletions
| diff --git a/client/trunk/src/com/fourisland/instadisc/Database/Item.java b/client/trunk/src/com/fourisland/instadisc/Database/Item.java new file mode 100644 index 0000000..7dbc89b --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/Database/Item.java | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | package com.fourisland.instadisc.Database; | ||
| 6 | |||
| 7 | import com.sleepycat.persist.model.Entity; | ||
| 8 | import com.sleepycat.persist.model.PrimaryKey; | ||
| 9 | import java.util.HashMap; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * | ||
| 13 | * @author hatkirby | ||
| 14 | */ | ||
| 15 | @Entity | ||
| 16 | public class Item { | ||
| 17 | |||
| 18 | @PrimaryKey | ||
| 19 | private Integer id; | ||
| 20 | private String subscription; | ||
| 21 | private String title; | ||
| 22 | private String author; | ||
| 23 | private String url; | ||
| 24 | private HashMap<String, String> semantics; | ||
| 25 | |||
| 26 | public Item() { | ||
| 27 | semantics = new HashMap<String, String>(); | ||
| 28 | } | ||
| 29 | |||
| 30 | public Integer getID() { | ||
| 31 | return id; | ||
| 32 | } | ||
| 33 | |||
| 34 | public String getSubscription() { | ||
| 35 | return subscription; | ||
| 36 | } | ||
| 37 | |||
| 38 | public String getTitle() { | ||
| 39 | return title; | ||
| 40 | } | ||
| 41 | |||
| 42 | public String getAuthor() { | ||
| 43 | return author; | ||
| 44 | } | ||
| 45 | |||
| 46 | public String getURL() { | ||
| 47 | return url; | ||
| 48 | } | ||
| 49 | |||
| 50 | public HashMap<String, String> getSemantics() { | ||
| 51 | return semantics; | ||
| 52 | } | ||
| 53 | |||
| 54 | public void setID(Integer id) { | ||
| 55 | this.id = id; | ||
| 56 | } | ||
| 57 | |||
| 58 | public void setSubscription(String subscription) { | ||
| 59 | this.subscription = subscription; | ||
| 60 | } | ||
| 61 | |||
| 62 | public void setTitle(String title) { | ||
| 63 | this.title = title; | ||
| 64 | } | ||
| 65 | |||
| 66 | public void setAuthor(String author) { | ||
| 67 | this.author = author; | ||
| 68 | } | ||
| 69 | |||
| 70 | public void setURL(String url) { | ||
| 71 | this.url = url; | ||
| 72 | } | ||
| 73 | |||
| 74 | public void setSemantics(HashMap<String, String> semantics) { | ||
| 75 | this.semantics = semantics; | ||
| 76 | } | ||
| 77 | |||
| 78 | public String getSemantics(String key) { | ||
| 79 | return semantics.get(key); | ||
| 80 | } | ||
| 81 | |||
| 82 | public void putSemantics(String key, String value) { | ||
| 83 | semantics.put(key, value); | ||
| 84 | } | ||
| 85 | } | ||
| diff --git a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java index 6ab0c72..3423e97 100644 --- a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java +++ b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java | |||
| @@ -14,6 +14,7 @@ import com.sleepycat.persist.StoreConfig; | |||
| 14 | import java.io.File; | 14 | import java.io.File; |
| 15 | import java.util.Collection; | 15 | import java.util.Collection; |
| 16 | import java.util.Iterator; | 16 | import java.util.Iterator; |
| 17 | import java.util.Map.Entry; | ||
| 17 | import java.util.logging.Level; | 18 | import java.util.logging.Level; |
| 18 | import java.util.logging.Logger; | 19 | import java.util.logging.Logger; |
| 19 | 20 | ||
| @@ -29,6 +30,7 @@ public class Wrapper { | |||
| 29 | public static PrimaryIndex<String, IDConfig> idConfig; | 30 | public static PrimaryIndex<String, IDConfig> idConfig; |
| 30 | public static PrimaryIndex<String, Subscription> subscription; | 31 | public static PrimaryIndex<String, Subscription> subscription; |
| 31 | public static PrimaryIndex<Integer, Filter> filter; | 32 | public static PrimaryIndex<Integer, Filter> filter; |
| 33 | public static PrimaryIndex<Integer, Item> item; | ||
| 32 | 34 | ||
| 33 | public static void init(String loc) { | 35 | public static void init(String loc) { |
| 34 | 36 | ||
| @@ -51,6 +53,7 @@ public class Wrapper { | |||
| 51 | idConfig = es.getPrimaryIndex(String.class, IDConfig.class); | 53 | idConfig = es.getPrimaryIndex(String.class, IDConfig.class); |
| 52 | subscription = es.getPrimaryIndex(String.class, Subscription.class); | 54 | subscription = es.getPrimaryIndex(String.class, Subscription.class); |
| 53 | filter = es.getPrimaryIndex(Integer.class, Filter.class); | 55 | filter = es.getPrimaryIndex(Integer.class, Filter.class); |
| 56 | item = es.getPrimaryIndex(Integer.class, Item.class); | ||
| 54 | } catch (DatabaseException ex) { | 57 | } catch (DatabaseException ex) { |
| 55 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 58 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 56 | } | 59 | } |
| @@ -173,9 +176,8 @@ public class Wrapper { | |||
| 173 | Collection vals = subscription.map().values(); | 176 | Collection vals = subscription.map().values(); |
| 174 | Subscription subs[] = new Subscription[vals.size()]; | 177 | Subscription subs[] = new Subscription[vals.size()]; |
| 175 | Iterator<Subscription> i = vals.iterator(); | 178 | Iterator<Subscription> i = vals.iterator(); |
| 176 | int j=0; | 179 | int j = 0; |
| 177 | while (i.hasNext()) | 180 | while (i.hasNext()) { |
| 178 | { | ||
| 179 | subs[j] = i.next(); | 181 | subs[j] = i.next(); |
| 180 | j++; | 182 | j++; |
| 181 | } | 183 | } |
| @@ -234,13 +236,53 @@ public class Wrapper { | |||
| 234 | Collection vals = filter.map().values(); | 236 | Collection vals = filter.map().values(); |
| 235 | Filter fils[] = new Filter[vals.size()]; | 237 | Filter fils[] = new Filter[vals.size()]; |
| 236 | Iterator<Filter> i = vals.iterator(); | 238 | Iterator<Filter> i = vals.iterator(); |
| 237 | int j=0; | 239 | int j = 0; |
| 238 | while (i.hasNext()) | 240 | while (i.hasNext()) { |
| 239 | { | ||
| 240 | fils[j] = i.next(); | 241 | fils[j] = i.next(); |
| 241 | j++; | 242 | j++; |
| 242 | } | 243 | } |
| 243 | return fils; | 244 | return fils; |
| 244 | } | 245 | } |
| 245 | } | 246 | } |
| 247 | |||
| 248 | public static Integer countItem() { | ||
| 249 | synchronized (item) { | ||
| 250 | return item.map().size(); | ||
| 251 | } | ||
| 252 | } | ||
| 253 | |||
| 254 | public static void dropFromTopItem() { | ||
| 255 | synchronized (item) { | ||
| 256 | try { | ||
| 257 | Iterator<Entry<Integer, Item>> i = item.map().entrySet().iterator(); | ||
| 258 | item.delete(i.next().getKey()); | ||
| 259 | } catch (DatabaseException ex) { | ||
| 260 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | ||
| 261 | } | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | public static Item[] getAllItem() { | ||
| 266 | synchronized (item) { | ||
| 267 | Collection vals = item.map().values(); | ||
| 268 | Item items[] = new Item[vals.size()]; | ||
| 269 | Iterator<Item> i = vals.iterator(); | ||
| 270 | int j = 0; | ||
| 271 | while (i.hasNext()) { | ||
| 272 | items[j] = i.next(); | ||
| 273 | j++; | ||
| 274 | } | ||
| 275 | return items; | ||
| 276 | } | ||
| 277 | } | ||
| 278 | |||
| 279 | public static void addItem(Item i) { | ||
| 280 | synchronized (item) { | ||
| 281 | try { | ||
| 282 | item.put(i); | ||
| 283 | } catch (DatabaseException ex) { | ||
| 284 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | ||
| 285 | } | ||
| 286 | } | ||
| 287 | } | ||
| 246 | } | 288 | } |
| diff --git a/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java b/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java index cdbc686..21924e8 100644 --- a/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java +++ b/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | */ | 4 | */ |
| 5 | package com.fourisland.instadisc; | 5 | package com.fourisland.instadisc; |
| 6 | 6 | ||
| 7 | import com.fourisland.instadisc.Item.Item; | 7 | import com.fourisland.instadisc.Database.Item; |
| 8 | import com.fourisland.instadisc.Database.Wrapper; | 8 | import com.fourisland.instadisc.Database.Wrapper; |
| 9 | import com.fourisland.instadisc.Item.Categories.Category; | 9 | import com.fourisland.instadisc.Item.Categories.Category; |
| 10 | import java.awt.Component; | 10 | import java.awt.Component; |
| diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java index f5f767f..be96e8a 100644 --- a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java +++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | */ | 3 | */ |
| 4 | package com.fourisland.instadisc; | 4 | package com.fourisland.instadisc; |
| 5 | 5 | ||
| 6 | import com.fourisland.instadisc.Item.Item; | 6 | import com.fourisland.instadisc.Database.Item; |
| 7 | import com.fourisland.instadisc.Database.Wrapper; | 7 | import com.fourisland.instadisc.Database.Wrapper; |
| 8 | import com.fourisland.instadisc.Item.Categories.InstaDiscIcon; | 8 | import com.fourisland.instadisc.Item.Categories.InstaDiscIcon; |
| 9 | import java.awt.AWTException; | 9 | import java.awt.AWTException; |
| @@ -21,7 +21,6 @@ import java.net.URI; | |||
| 21 | import java.net.URISyntaxException; | 21 | import java.net.URISyntaxException; |
| 22 | import java.util.logging.Level; | 22 | import java.util.logging.Level; |
| 23 | import java.util.logging.Logger; | 23 | import java.util.logging.Logger; |
| 24 | import javax.swing.DefaultListModel; | ||
| 25 | import javax.swing.Timer; | 24 | import javax.swing.Timer; |
| 26 | import javax.swing.Icon; | 25 | import javax.swing.Icon; |
| 27 | import javax.swing.ImageIcon; | 26 | import javax.swing.ImageIcon; |
| @@ -107,10 +106,8 @@ public class InstaDiscView extends FrameView { | |||
| 107 | } | 106 | } |
| 108 | } | 107 | } |
| 109 | 108 | ||
| 110 | lm.ensureCapacity(10); | ||
| 111 | lm.clear(); | ||
| 112 | jList1.setModel(lm); | ||
| 113 | jList1.setCellRenderer(new IDItemListCellRenderer()); | 109 | jList1.setCellRenderer(new IDItemListCellRenderer()); |
| 110 | refreshItemPane(); | ||
| 114 | 111 | ||
| 115 | InstaDiscThread idt = new InstaDiscThread(); | 112 | InstaDiscThread idt = new InstaDiscThread(); |
| 116 | Thread idtt = new Thread(idt); | 113 | Thread idtt = new Thread(idt); |
| @@ -370,17 +367,10 @@ public class InstaDiscView extends FrameView { | |||
| 370 | private final Icon[] busyIcons = new Icon[15]; | 367 | private final Icon[] busyIcons = new Icon[15]; |
| 371 | private int busyIconIndex = 0; | 368 | private int busyIconIndex = 0; |
| 372 | private JDialog aboutBox; | 369 | private JDialog aboutBox; |
| 373 | private DefaultListModel lm = new DefaultListModel(); | ||
| 374 | 370 | ||
| 375 | public void addItemPane(Item item) { | 371 | public void refreshItemPane() { |
| 376 | if (lm.size() >= Integer.decode(Wrapper.getConfig("itemBufferSize"))) { | 372 | Item items[] = Wrapper.getAllItem(); |
| 377 | while (lm.size() >= Integer.decode(Wrapper.getConfig("itemBufferSize"))) { | 373 | jList1.setListData(items); |
| 378 | lm.remove(0); | ||
| 379 | } | ||
| 380 | } | ||
| 381 | |||
| 382 | lm.addElement(item); | ||
| 383 | jList1.setModel(lm); | ||
| 384 | jList1.repaint(); | 374 | jList1.repaint(); |
| 385 | } | 375 | } |
| 386 | } | 376 | } |
| diff --git a/client/trunk/src/com/fourisland/instadisc/Item/Item.java b/client/trunk/src/com/fourisland/instadisc/Item/Item.java index 143e06f..927101b 100644 --- a/client/trunk/src/com/fourisland/instadisc/Item/Item.java +++ b/client/trunk/src/com/fourisland/instadisc/Item/Item.java | |||
| @@ -19,75 +19,8 @@ import java.util.HashMap; | |||
| 19 | public class Item { | 19 | public class Item { |
| 20 | 20 | ||
| 21 | HashMap<String, String> headerMap; | 21 | HashMap<String, String> headerMap; |
| 22 | private Integer id; | ||
| 23 | private String subscription; | ||
| 24 | private String title; | ||
| 25 | private String author; | ||
| 26 | private String url; | ||
| 27 | private HashMap<String, String> semantics; | ||
| 28 | |||
| 29 | public Item() { | ||
| 30 | semantics = new HashMap<String, String>(); | ||
| 31 | } | ||
| 32 | |||
| 33 | public Integer getID() { | ||
| 34 | return id; | ||
| 35 | } | ||
| 36 | |||
| 37 | public String getSubscription() { | ||
| 38 | return subscription; | ||
| 39 | } | ||
| 40 | |||
| 41 | public String getTitle() { | ||
| 42 | return title; | ||
| 43 | } | ||
| 44 | |||
| 45 | public String getAuthor() { | ||
| 46 | return author; | ||
| 47 | } | ||
| 48 | |||
| 49 | public String getURL() { | ||
| 50 | return url; | ||
| 51 | } | ||
| 52 | |||
| 53 | public HashMap<String, String> getSemantics() { | ||
| 54 | return semantics; | ||
| 55 | } | ||
| 56 | |||
| 57 | public void setID(Integer id) { | ||
| 58 | this.id = id; | ||
| 59 | } | ||
| 60 | |||
| 61 | public void setSubscription(String subscription) { | ||
| 62 | this.subscription = subscription; | ||
| 63 | } | ||
| 64 | |||
| 65 | public void setTitle(String title) { | ||
| 66 | this.title = title; | ||
| 67 | } | ||
| 68 | |||
| 69 | public void setAuthor(String author) { | ||
| 70 | this.author = author; | ||
| 71 | } | ||
| 72 | |||
| 73 | public void setURL(String url) { | ||
| 74 | this.url = url; | ||
| 75 | } | ||
| 76 | |||
| 77 | public void setSemantics(HashMap<String, String> semantics) { | ||
| 78 | this.semantics = semantics; | ||
| 79 | } | ||
| 80 | |||
| 81 | public String getSemantics(String key) { | ||
| 82 | return semantics.get(key); | ||
| 83 | } | ||
| 84 | |||
| 85 | public void putSemantics(String key, String value) { | ||
| 86 | semantics.put(key, value); | ||
| 87 | } | ||
| 88 | 22 | ||
| 89 | public Item(HashMap<String, String> headerMap) { | 23 | public Item(HashMap<String, String> headerMap) { |
| 90 | this(); | ||
| 91 | this.headerMap = headerMap; | 24 | this.headerMap = headerMap; |
| 92 | } | 25 | } |
| 93 | 26 | ||
| @@ -97,12 +30,19 @@ public class Item { | |||
| 97 | XmlRpc xmlrpc = new XmlRpc("deleteItem"); | 30 | XmlRpc xmlrpc = new XmlRpc("deleteItem"); |
| 98 | xmlrpc.addParam(Integer.decode(headerMap.get("ID"))); | 31 | xmlrpc.addParam(Integer.decode(headerMap.get("ID"))); |
| 99 | xmlrpc.execute(); | 32 | xmlrpc.execute(); |
| 33 | |||
| 34 | if (Wrapper.countItem() >= Integer.decode(Wrapper.getConfig("itemBufferSize"))) { | ||
| 35 | while (Wrapper.countItem() >= Integer.decode(Wrapper.getConfig("itemBufferSize"))) { | ||
| 36 | Wrapper.dropFromTopItem(); | ||
| 37 | } | ||
| 38 | } | ||
| 100 | 39 | ||
| 101 | setID(Integer.decode(headerMap.get("ID"))); | 40 | com.fourisland.instadisc.Database.Item item = new com.fourisland.instadisc.Database.Item(); |
| 102 | setSubscription(headerMap.get("Subscription")); | 41 | item.setID(Integer.decode(headerMap.get("ID"))); |
| 103 | setTitle(headerMap.get("Title")); | 42 | item.setSubscription(headerMap.get("Subscription")); |
| 104 | setAuthor(headerMap.get("Author")); | 43 | item.setTitle(headerMap.get("Title")); |
| 105 | setURL(headerMap.get("URL")); | 44 | item.setAuthor(headerMap.get("Author")); |
| 45 | item.setURL(headerMap.get("URL")); | ||
| 106 | 46 | ||
| 107 | HashMap<String, String> temp = new HashMap<String, String>(headerMap); | 47 | HashMap<String, String> temp = new HashMap<String, String>(headerMap); |
| 108 | temp.remove("ID"); | 48 | temp.remove("ID"); |
| @@ -112,9 +52,11 @@ public class Item { | |||
| 112 | temp.remove("Title"); | 52 | temp.remove("Title"); |
| 113 | temp.remove("Author"); | 53 | temp.remove("Author"); |
| 114 | temp.remove("URL"); | 54 | temp.remove("URL"); |
| 115 | setSemantics(temp); | 55 | item.setSemantics(temp); |
| 56 | |||
| 57 | Wrapper.addItem(item); | ||
| 116 | 58 | ||
| 117 | ((InstaDiscView) InstaDiscApp.getApplication().getMainView()).addItemPane(this); | 59 | ((InstaDiscView) InstaDiscApp.getApplication().getMainView()).refreshItemPane(); |
| 118 | 60 | ||
| 119 | if (SystemTray.isSupported()) { | 61 | if (SystemTray.isSupported()) { |
| 120 | InstaDiscApp.ti.displayMessage("New item recieved!", Wrapper.getSubscription(headerMap.get("Subscription")).getTitle() + ", " + headerMap.get("Title") + " by " + headerMap.get("Author"), MessageType.INFO); | 62 | InstaDiscApp.ti.displayMessage("New item recieved!", Wrapper.getSubscription(headerMap.get("Subscription")).getTitle() + ", " + headerMap.get("Title") + " by " + headerMap.get("Author"), MessageType.INFO); |
| diff --git a/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java b/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java index b1190f4..e6d2a6f 100644 --- a/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java +++ b/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java | |||
| @@ -153,11 +153,8 @@ public class ManageSubscriptionsForm extends javax.swing.JDialog { | |||
| 153 | private javax.swing.JScrollPane jScrollPane1; | 153 | private javax.swing.JScrollPane jScrollPane1; |
| 154 | // End of variables declaration//GEN-END:variables | 154 | // End of variables declaration//GEN-END:variables |
| 155 | 155 | ||
| 156 | DefaultListModel lm = new DefaultListModel(); | ||
| 157 | |||
| 158 | public void refreshSubscriptionPane() { | 156 | public void refreshSubscriptionPane() { |
| 159 | Subscription[] subscriptions = Wrapper.getAllSubscription(); | 157 | Subscription[] subscriptions = Wrapper.getAllSubscription(); |
| 160 | System.out.println(Arrays.deepToString(subscriptions)); | ||
| 161 | jList1.setListData(subscriptions); | 158 | jList1.setListData(subscriptions); |
| 162 | jList1.repaint(); | 159 | jList1.repaint(); |
| 163 | 160 | ||
