about summary refs log tree commit diff stats
path: root/client/trunk/src/com/fourisland
diff options
context:
space:
mode:
Diffstat (limited to 'client/trunk/src/com/fourisland')
-rw-r--r--client/trunk/src/com/fourisland/instadisc/Database/Item.java85
-rw-r--r--client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java59
-rw-r--r--client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java2
-rw-r--r--client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java2
-rw-r--r--client/trunk/src/com/fourisland/instadisc/InstaDiscView.form1
-rw-r--r--client/trunk/src/com/fourisland/instadisc/InstaDiscView.java40
-rw-r--r--client/trunk/src/com/fourisland/instadisc/Item/Item.java123
7 files changed, 115 insertions, 197 deletions
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 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package com.fourisland.instadisc.Database;
6
7import com.sleepycat.persist.model.Entity;
8import com.sleepycat.persist.model.PrimaryKey;
9import java.util.HashMap;
10
11/**
12 *
13 * @author hatkirby
14 */
15@Entity
16public 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 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 {
26 public static EntityStore es = null; 26 public static EntityStore es = null;
27 public static PrimaryIndex<Integer, OldVerID> oldVerID; 27 public static PrimaryIndex<Integer, OldVerID> oldVerID;
28 public static PrimaryIndex<String, IDConfig> idConfig; 28 public static PrimaryIndex<String, IDConfig> idConfig;
29 public static PrimaryIndex<Integer, Item> item;
30 public static PrimaryIndex<String, Subscription> subscription; 29 public static PrimaryIndex<String, Subscription> subscription;
31 public static PrimaryIndex<Integer, Filter> filter; 30 public static PrimaryIndex<Integer, Filter> filter;
32 31
@@ -49,7 +48,6 @@ public class Wrapper {
49 try { 48 try {
50 oldVerID = es.getPrimaryIndex(Integer.class, OldVerID.class); 49 oldVerID = es.getPrimaryIndex(Integer.class, OldVerID.class);
51 idConfig = es.getPrimaryIndex(String.class, IDConfig.class); 50 idConfig = es.getPrimaryIndex(String.class, IDConfig.class);
52 item = es.getPrimaryIndex(Integer.class, Item.class);
53 subscription = es.getPrimaryIndex(String.class, Subscription.class); 51 subscription = es.getPrimaryIndex(String.class, Subscription.class);
54 filter = es.getPrimaryIndex(Integer.class, Filter.class); 52 filter = es.getPrimaryIndex(Integer.class, Filter.class);
55 } catch (DatabaseException ex) { 53 } catch (DatabaseException ex) {
@@ -137,63 +135,6 @@ public class Wrapper {
137 } 135 }
138 } 136 }
139 137
140 public static void addItem(Item m_item) {
141 synchronized (item) {
142 try {
143 item.put(m_item);
144 } catch (DatabaseException ex) {
145 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
146 }
147 }
148 }
149
150 public static int countItem() {
151 synchronized (item) {
152 try {
153 return (int) item.count();
154 } catch (DatabaseException ex) {
155 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
156 return 0;
157 }
158 }
159 }
160
161 public static void dropFromTopItem() {
162 synchronized (item) {
163 try {
164 Integer[] keySet = (Integer[]) item.map().keySet().toArray();
165 item.delete(keySet[0]);
166 } catch (DatabaseException ex) {
167 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
168 }
169 }
170 }
171
172 public static Item[] getAllItem() {
173 synchronized (item) {
174 try {
175 Iterator<Item> i = item.entities().iterator();
176 Item[] temp = new Item[0];
177 int len = 0;
178
179 while (i.hasNext()) {
180 Item[] temp2 = new Item[len + 1];
181 int j = 0;
182 for (j = 0; j < len; j++) {
183 temp2[j] = temp[j];
184 }
185 temp2[len] = i.next();
186 temp = temp2;
187 }
188
189 return temp;
190 } catch (DatabaseException ex) {
191 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
192 return new Item[0];
193 }
194 }
195 }
196
197 public static Subscription getSubscription(String url) { 138 public static Subscription getSubscription(String url) {
198 synchronized (subscription) { 139 synchronized (subscription) {
199 try { 140 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 @@
4 */ 4 */
5package com.fourisland.instadisc; 5package com.fourisland.instadisc;
6 6
7import com.fourisland.instadisc.Database.Item; 7import com.fourisland.instadisc.Item.Item;
8import com.fourisland.instadisc.Database.Wrapper; 8import com.fourisland.instadisc.Database.Wrapper;
9import com.fourisland.instadisc.Item.Categories.Category; 9import com.fourisland.instadisc.Item.Categories.Category;
10import java.awt.Component; 10import 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 {
56class HandleItemThread implements Runnable { 56class HandleItemThread implements Runnable {
57 57
58 Socket s; 58 Socket s;
59 59
60 public HandleItemThread(Socket s) { 60 public HandleItemThread(Socket s) {
61 this.s = s; 61 this.s = s;
62 } 62 }
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 @@
40 </Properties> 40 </Properties>
41 <Events> 41 <Events>
42 <EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jList1MouseClicked"/> 42 <EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jList1MouseClicked"/>
43 <EventHandler event="componentShown" listener="java.awt.event.ComponentListener" parameters="java.awt.event.ComponentEvent" handler="jList1ComponentShown"/>
43 </Events> 44 </Events>
44 </Component> 45 </Component>
45 </SubComponents> 46 </SubComponents>
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 @@
3 */ 3 */
4package com.fourisland.instadisc; 4package com.fourisland.instadisc;
5 5
6import com.fourisland.instadisc.Database.Item; 6import com.fourisland.instadisc.Item.Item;
7import com.fourisland.instadisc.Database.Wrapper; 7import com.fourisland.instadisc.Database.Wrapper;
8import com.fourisland.instadisc.Item.Categories.InstaDiscIcon; 8import com.fourisland.instadisc.Item.Categories.InstaDiscIcon;
9import java.awt.AWTException; 9import java.awt.AWTException;
@@ -94,11 +94,10 @@ public class InstaDiscView extends FrameView {
94 } 94 }
95 } 95 }
96 }); 96 });
97 97
98 this.getFrame().setIconImage(new ImageIcon(InstaDiscIcon.instadiscicon).getImage()); 98 this.getFrame().setIconImage(new ImageIcon(InstaDiscIcon.instadiscicon).getImage());
99 99
100 if (SystemTray.isSupported()) 100 if (SystemTray.isSupported()) {
101 {
102 try { 101 try {
103 TrayIcon ti = new TrayIcon(new ImageIcon(InstaDiscIcon.instadisciconmiddle).getImage(), "InstaDisc"); 102 TrayIcon ti = new TrayIcon(new ImageIcon(InstaDiscIcon.instadisciconmiddle).getImage(), "InstaDisc");
104 SystemTray.getSystemTray().add(ti); 103 SystemTray.getSystemTray().add(ti);
@@ -108,14 +107,15 @@ public class InstaDiscView extends FrameView {
108 } 107 }
109 } 108 }
110 109
111 jList1.setCellRenderer(new IDItemListCellRenderer()); 110 lm.ensureCapacity(10);
111 lm.clear();
112 jList1.setModel(lm); 112 jList1.setModel(lm);
113 refreshItemPane(); 113 jList1.setCellRenderer(new IDItemListCellRenderer());
114 114
115 InstaDiscThread idt = new InstaDiscThread(); 115 InstaDiscThread idt = new InstaDiscThread();
116 Thread idtt = new Thread(idt); 116 Thread idtt = new Thread(idt);
117 idtt.start(); 117 idtt.start();
118 118
119 XmlRpc xmlrpc = new XmlRpc("requestRetained"); 119 XmlRpc xmlrpc = new XmlRpc("requestRetained");
120 xmlrpc.execute(); 120 xmlrpc.execute();
121 } 121 }
@@ -170,6 +170,11 @@ public class InstaDiscView extends FrameView {
170 jList1MouseClicked(evt); 170 jList1MouseClicked(evt);
171 } 171 }
172 }); 172 });
173 jList1.addComponentListener(new java.awt.event.ComponentAdapter() {
174 public void componentShown(java.awt.event.ComponentEvent evt) {
175 jList1ComponentShown(evt);
176 }
177 });
173 jScrollPane1.setViewportView(jList1); 178 jScrollPane1.setViewportView(jList1);
174 179
175 javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); 180 javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
@@ -338,6 +343,10 @@ public class InstaDiscView extends FrameView {
338 xmlrpc.execute(); 343 xmlrpc.execute();
339 }//GEN-LAST:event_jMenuItem4ActionPerformed 344 }//GEN-LAST:event_jMenuItem4ActionPerformed
340 345
346 private void jList1ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jList1ComponentShown
347 jList1.repaint();
348 }//GEN-LAST:event_jList1ComponentShown
349
341 // Variables declaration - do not modify//GEN-BEGIN:variables 350 // Variables declaration - do not modify//GEN-BEGIN:variables
342 private javax.swing.JList jList1; 351 private javax.swing.JList jList1;
343 private javax.swing.JMenu jMenu1; 352 private javax.swing.JMenu jMenu1;
@@ -363,12 +372,15 @@ public class InstaDiscView extends FrameView {
363 private JDialog aboutBox; 372 private JDialog aboutBox;
364 private DefaultListModel lm = new DefaultListModel(); 373 private DefaultListModel lm = new DefaultListModel();
365 374
366 public void refreshItemPane() { 375 public void addItemPane(Item item) {
367 lm.clear(); 376 if (lm.size() >= Integer.decode(Wrapper.getConfig("itemBufferSize"))) {
368 Item[] items = Wrapper.getAllItem(); 377 while (lm.size() >= Integer.decode(Wrapper.getConfig("itemBufferSize"))) {
369 int i = 0; 378 lm.remove(0);
370 for (i = 0; i < items.length; i++) { 379 }
371 lm.addElement(items[i]);
372 } 380 }
381
382 lm.addElement(item);
383 jList1.setModel(lm);
384 jList1.repaint();
373 } 385 }
374} 386}
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;
10import com.fourisland.instadisc.XmlRpc; 10import com.fourisland.instadisc.XmlRpc;
11import java.awt.SystemTray; 11import java.awt.SystemTray;
12import java.awt.TrayIcon.MessageType; 12import java.awt.TrayIcon.MessageType;
13import java.net.MalformedURLException;
14import java.net.URL;
15import java.util.HashMap; 13import java.util.HashMap;
16import java.util.Iterator;
17import java.util.logging.Level;
18import java.util.logging.Logger;
19 14
20/** 15/**
21 * 16 *
@@ -24,8 +19,75 @@ import java.util.logging.Logger;
24public class Item { 19public class Item {
25 20
26 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 }
27 88
28 public Item(HashMap<String, String> headerMap) { 89 public Item(HashMap<String, String> headerMap) {
90 this();
29 this.headerMap = headerMap; 91 this.headerMap = headerMap;
30 } 92 }
31 93
@@ -35,41 +97,28 @@ public class Item {
35 XmlRpc xmlrpc = new XmlRpc("deleteItem"); 97 XmlRpc xmlrpc = new XmlRpc("deleteItem");
36 xmlrpc.addParam(Integer.decode(headerMap.get("ID"))); 98 xmlrpc.addParam(Integer.decode(headerMap.get("ID")));
37 xmlrpc.execute(); 99 xmlrpc.execute();
38
39 if (Wrapper.countItem() >= Integer.decode(Wrapper.getConfig("itemBufferSize")))
40 {
41 Wrapper.dropFromTopItem();
42 }
43 100
44 try { 101 setID(Integer.decode(headerMap.get("ID")));
45 com.fourisland.instadisc.Database.Item di = new com.fourisland.instadisc.Database.Item(); 102 setSubscription(headerMap.get("Subscription"));
46 di.setID(Integer.decode(headerMap.get("ID"))); 103 setTitle(headerMap.get("Title"));
47 di.setSubscription(headerMap.get("Subscription")); 104 setAuthor(headerMap.get("Author"));
48 di.setTitle(headerMap.get("Title")); 105 setURL(headerMap.get("URL"));
49 di.setAuthor(headerMap.get("Author")); 106
50 di.setURL(new URL(headerMap.get("URL")).toString()); 107 HashMap<String, String> temp = new HashMap<String, String>(headerMap);
51 108 temp.remove("ID");
52 HashMap<String, String> temp = new HashMap(headerMap); 109 temp.remove("Verification");
53 temp.remove("ID"); 110 temp.remove("Verification-ID");
54 temp.remove("Verification"); 111 temp.remove("Subscription");
55 temp.remove("Verification-ID"); 112 temp.remove("Title");
56 temp.remove("Subscription"); 113 temp.remove("Author");
57 temp.remove("Title"); 114 temp.remove("URL");
58 temp.remove("Author"); 115 setSemantics(temp);
59 temp.remove("URL"); 116
60 di.setSemantics(temp); 117 ((InstaDiscView) InstaDiscApp.getApplication().getMainView()).addItemPane(this);
61 118
62 Wrapper.addItem(di); 119 if (SystemTray.isSupported()) {
63 } catch (MalformedURLException ex) {
64 Logger.getLogger(Item.class.getName()).log(Level.SEVERE, null, ex);
65 }
66
67 if (SystemTray.isSupported())
68 {
69 InstaDiscApp.ti.displayMessage("New item recieved!", Wrapper.getSubscription(headerMap.get("Subscription")).getTitle() + ", " + headerMap.get("Title") + " by " + headerMap.get("Author"), MessageType.INFO); 120 InstaDiscApp.ti.displayMessage("New item recieved!", Wrapper.getSubscription(headerMap.get("Subscription")).getTitle() + ", " + headerMap.get("Title") + " by " + headerMap.get("Author"), MessageType.INFO);
70 } 121 }
71
72 ((InstaDiscView)InstaDiscApp.getApplication().getMainView()).refreshItemPane();
73 } 122 }
74 } 123 }
75} 124}