parent
bc7542de7a
commit
5e92eae32f
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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…
Reference in new issue