Complete UpButt.

workbranch
asdfasdf 6 years ago
parent f476d1e3cb
commit 7ab1b38684

@ -14,12 +14,17 @@ public class StockEntry {
this.stype = stype; this.stype = stype;
} }
public void update() { public boolean update() {
boolean changed = false;
updating = true; updating = true;
double[] result = this.stype.update(this.identifier); double[] result = this.stype.update(this.identifier);
if ((result[0] != price) || (result[1] != change)) {
changed = true;
}
this.price = result[0]; this.price = result[0];
this.change = result[1]; this.change = result[1];
updating = false; updating = false;
return changed;
} }
public String getTypeName() { public String getTypeName() {

@ -133,13 +133,19 @@ public class WatchList extends Observable implements Load,Save {
public void updateList() { public void updateList() {
Iterator watchit = iterator(); Iterator watchit = iterator();
boolean changed = false;
while (watchit.hasNext()) { while (watchit.hasNext()) {
Map.Entry entry = (Map.Entry)watchit.next(); Map.Entry entry = (Map.Entry)watchit.next();
StockEntry sentry = (StockEntry)entry.getValue(); StockEntry sentry = (StockEntry)entry.getValue();
if (!changed) {
changed = changed || sentry.update();
}
sentry.update(); sentry.update();
} }
setChanged(); if (changed) {
notifyObservers(new Wevent(Etype.UPDATE)); setChanged();
notifyObservers(new Wevent(Etype.UPDATE));
}
} }
public class Wevent { public class Wevent {

@ -11,12 +11,17 @@ public class UpButt extends JButton {
public UpButt(WatchList wlist) { public UpButt(WatchList wlist) {
super("Update"); super("Update");
addActionListener(new UpButtList()); addActionListener(new UpButtList());
this.wlist = wlist; this.wlist = wlist;
} }
private class UpButtList implements ActionListener { private class UpButtList implements ActionListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
//XXX Update WatchList new Thread(new Runnable() {
@Override
public void run() {
wlist.updateList();
}
}).start();
} }
} }
} }

Loading…
Cancel
Save