Added Buttons

workbranch
asdfasdf 6 years ago
parent bc7542de7a
commit 5e92eae32f

@ -44,4 +44,3 @@ Rebuild tags with:
```
gradle tags
```

@ -7,6 +7,7 @@ public class StockEntry {
private StockType stype;
private double price;
private double change;
private boolean updating = false;
public StockEntry(StockType stype, String idstring) {
identifier = idstring;
@ -14,9 +15,11 @@ public class StockEntry {
}
public void update() {
updating = true;
double[] result = this.stype.update(this.identifier);
this.price = result[0];
this.change = result[1];
updating = false;
}
public String getTypeName() {
@ -35,6 +38,10 @@ public class StockEntry {
return change;
}
public boolean isUpdating() {
return updating;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {

@ -59,6 +59,11 @@ public class WatchList extends Subject implements Load,Save {
return entryset.iterator();
}
//XXX index access method
public StockEntry getStock(int index) {
return (StockEntry) listdata.entrySet().toArray()[index];
}
// Effects: Return the size of list
public int size() {
return listdata.size();

@ -34,5 +34,4 @@ public class AlphaVantage extends DataSource {
}
return result;
}
}

@ -1,18 +1,69 @@
package ui;
import javax.swing.*;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JComponent;
import javax.swing.JButton;
import javax.swing.GroupLayout;
import java.awt.Container;
import java.awt.LayoutManager;
import ui.guicomp.*;
import static data.Const.PROGRAM_NAME;
import javax.swing.GroupLayout.Alignment;
public class Gui {
//public Gui() {
// JLabel label = new JLabel("Hello World");
// based on http://zetcode.com/tutorials/javaswingtutorial/firstprograms/
public class Gui extends JFrame implements Iface {
private JButton addButton;
private JButton delButton;
private JButton upButton;
private Runnable init = new Runnable() {
public void run() {
addComponents();
createLayout();
setTitle(PROGRAM_NAME);
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
// JFrame.setDefaultLookAndFeelDecorated(true);
// JFrame f = new JFrame("Hello World");
// f.setSize(300,150);
// f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
private void addComponents() {
addButton = new AddButt();
delButton = new DelButt();
upButton = new UpButt();
}
// f.add(label);
private void createLayout() {
Container pane = getContentPane();
GroupLayout lman = new GroupLayout(pane);
pane.setLayout(lman);
lman.setAutoCreateContainerGaps(true);
lman.setHorizontalGroup(lman.createParallelGroup(GroupLayout.Alignment.CENTER)
.addGroup(lman.createSequentialGroup()
.addComponent(addButton)
.addComponent(delButton)
.addComponent(upButton)
));
lman.setVerticalGroup(lman.createSequentialGroup()
.addGroup(lman.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(addButton)
.addComponent(delButton)
.addComponent(upButton)
));
}
};
// f.setVisible(true);
//}
public Gui() {
SwingUtilities.invokeLater(init);
setVisible(true);
}
@Override
public void redraw() {
//Nothing for now
}
@Override
public void destory() {
//Nothing for now
}
}

@ -6,6 +6,8 @@ public class IfaceFactory {
// Produce Iface given the config
public static Iface getIface() {
//uses Tui for now
return new Tui();
//return new Tui();
//Test Gui
return new Gui();
}
}

@ -0,0 +1,19 @@
package ui.guicomp;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class AddButt extends JButton {
public AddButt() {
super("Add Stock...");
addActionListener(new AddButtList());
}
private class AddButtList implements ActionListener {
public void actionPerformed(ActionEvent e) {
//XXX Ask for input dialogue
//https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#input
}
}
}

@ -0,0 +1,19 @@
package ui.guicomp;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class DelButt extends JButton {
public DelButt() {
super("Remove Stock...");
addActionListener(new DelButtList());
}
private class DelButtList implements ActionListener {
public void actionPerformed(ActionEvent e) {
//XXX Ask for input dialogue
//https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#input
}
}
}

@ -0,0 +1,18 @@
package ui.guicomp;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class UpButt extends JButton {
public UpButt() {
super("Update");
addActionListener(new UpButtList());
}
private class UpButtList implements ActionListener {
public void actionPerformed(ActionEvent e) {
//XXX Update WatchList
}
}
}

@ -0,0 +1,50 @@
package ui.guicomp;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import javax.swing.event.*;
import data.WatchList;
import data.StockEntry;
// Ref: https://docs.oracle.com/javase/tutorial/uiswing/components/table.html
// Ref2: https://docs.oracle.com/javase/8/docs/api/javax/swing/table/AbstractTableModel.html
public class WatchTableModel extends AbstractTableModel {
private final String[] colnames = {"Identifier", "Price", "% change", "Status"};
private WatchList watch;
public WatchTableModel(WatchList wlist) {
watch = wlist;
}
public int getColumnCount() {
return colnames.length;
}
public int getRowCount() {
return watch.size();
}
public String getColumnName(int num) {
return colnames[num];
}
public Object getValueAt(int stock, int field) {
StockEntry entry = watch.getStock(stock);
switch (field) {
case 0: //Name
return entry.getID();
case 1: //Price
return entry.getPrice();
case 2: //% change
return entry.getChange() + " %";
case 3:
return entry.isUpdating() ? "Updating" : "Ok";
default:
return false;
}
}
public Class getColumnClass(int col) {
return getValueAt(0,col).getClass();
}
}
Loading…
Cancel
Save