Gui/View extensive changes
This commit is contained in:
parent
7b3ddf17e0
commit
adbdfd3b99
7 changed files with 101 additions and 28 deletions
|
@ -3,9 +3,21 @@ package xl.gui;
|
|||
import java.awt.Color;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import xl.controller.EditorController;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class Editor extends JTextField {
|
||||
|
||||
public Editor() {
|
||||
public Editor(EditorController editorController) {
|
||||
setBackground(Color.WHITE);
|
||||
|
||||
// Listen for changes in the text
|
||||
addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
editorController.handleEditorAction();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,15 @@ package xl.gui;
|
|||
import static java.awt.BorderLayout.CENTER;
|
||||
import static java.awt.BorderLayout.WEST;
|
||||
|
||||
import xl.controller.EditorController;
|
||||
import xl.controller.SlotLabelController;
|
||||
import xl.model.XLModel;
|
||||
|
||||
public class SheetPanel extends BorderPanel {
|
||||
|
||||
public SheetPanel(int rows, int columns) {
|
||||
public SheetPanel(int rows, int columns, XLModel xlModel, SlotLabelController slotLabelController,
|
||||
EditorController editorController) {
|
||||
add(WEST, new RowLabels(rows));
|
||||
add(CENTER, new SlotLabels(rows, columns));
|
||||
add(CENTER, new SlotLabels(rows, columns, xlModel, slotLabelController, editorController));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,45 @@
|
|||
package xl.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import xl.controller.SlotLabelController;
|
||||
import java.util.Observer;
|
||||
import java.util.Observable;
|
||||
import xl.model.XLModel;
|
||||
|
||||
public class SlotLabel extends ColoredLabel {
|
||||
public class SlotLabel extends ColoredLabel implements Observer {
|
||||
private String address;
|
||||
|
||||
public SlotLabel() {
|
||||
public SlotLabel(SlotLabelController slotLabelController, int row, char column) {
|
||||
super(" ", Color.WHITE, RIGHT);
|
||||
this.address = "" + column + row;
|
||||
|
||||
// MouseListener for mouse clicks
|
||||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
slotLabelController.handleSlotClick(SlotLabel.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void update(Observable o, Object arg) {
|
||||
if (o instanceof XLModel) {
|
||||
XLModel xlModel = (XLModel) o;
|
||||
if (xlModel.containsKey(address)) {
|
||||
String tempCurrentAdress = xlModel.getAddressContent(address);
|
||||
xlModel.setCurrentAddress(address);
|
||||
String content = xlModel.getAddressValue(address);
|
||||
setText(content);
|
||||
xlModel.setCurrentAddress(tempCurrentAdress);
|
||||
} else {
|
||||
setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,25 +4,35 @@ import java.awt.Color;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.SwingConstants;
|
||||
import xl.model.XLModel;
|
||||
import xl.controller.EditorController;
|
||||
import xl.controller.SlotLabelController;
|
||||
|
||||
public class SlotLabels extends GridPanel {
|
||||
|
||||
private List<SlotLabel> labelList;
|
||||
|
||||
public SlotLabels(int rows, int cols) {
|
||||
public SlotLabels(int rows, int cols, XLModel xlModel, SlotLabelController slotLabelController,
|
||||
EditorController editorController) {
|
||||
super(rows + 1, cols);
|
||||
labelList = new ArrayList<SlotLabel>(rows * cols);
|
||||
for (char ch = 'A'; ch < 'A' + cols; ch++) {
|
||||
add(new ColoredLabel(Character.toString(ch), Color.LIGHT_GRAY, SwingConstants.CENTER));
|
||||
}
|
||||
|
||||
for (int row = 1; row <= rows; row++) {
|
||||
for (char ch = 'A'; ch < 'A' + cols; ch++) {
|
||||
SlotLabel label = new SlotLabel();
|
||||
SlotLabel label = new SlotLabel(slotLabelController, row, ch);
|
||||
xlModel.addObserver(label);
|
||||
add(label);
|
||||
labelList.add(label);
|
||||
}
|
||||
}
|
||||
|
||||
SlotLabel firstLabel = labelList.get(0);
|
||||
firstLabel.setBackground(Color.YELLOW);
|
||||
xlModel.setCurrentAddress("A1");
|
||||
slotLabelController.setCurrentSlot(firstLabel);
|
||||
editorController.setCurrentSlot(firstLabel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
package xl.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
public class StatusLabel extends ColoredLabel implements Observer {
|
||||
public class StatusLabel extends ColoredLabel {
|
||||
|
||||
public StatusLabel() {
|
||||
super("", Color.WHITE);
|
||||
}
|
||||
|
||||
public void update(Observable observable, Object object) {
|
||||
setText("");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,15 @@ package xl.gui;
|
|||
import static java.awt.BorderLayout.CENTER;
|
||||
import static java.awt.BorderLayout.WEST;
|
||||
|
||||
import xl.controller.SlotLabelController;
|
||||
import xl.model.XLModel;
|
||||
|
||||
public class StatusPanel extends BorderPanel {
|
||||
|
||||
protected StatusPanel(StatusLabel statusLabel) {
|
||||
add(WEST, new CurrentLabel());
|
||||
protected StatusPanel(StatusLabel statusLabel, XLModel solver, SlotLabelController slotLabelController) {
|
||||
CurrentLabel currentLabel = new CurrentLabel();
|
||||
slotLabelController.setCurrentLabel(currentLabel);
|
||||
add(WEST, currentLabel);
|
||||
add(CENTER, statusLabel);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,11 @@ import static java.awt.BorderLayout.SOUTH;
|
|||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import xl.controller.EditorController;
|
||||
import xl.controller.SlotLabelController;
|
||||
import xl.gui.menu.XLMenuBar;
|
||||
import xl.model.XLModel;
|
||||
|
||||
public class XL extends JFrame {
|
||||
|
||||
|
@ -15,23 +19,31 @@ public class XL extends JFrame {
|
|||
private StatusLabel statusLabel = new StatusLabel();
|
||||
private XLList xlList;
|
||||
|
||||
public XL(XL oldXL) {
|
||||
this(oldXL.xlList, oldXL.counter);
|
||||
public XL(XL oldXL, XLModel XLModel) {
|
||||
this(oldXL.xlList, oldXL.counter, XLModel);
|
||||
}
|
||||
|
||||
public XL(XLList xlList, XLCounter counter) {
|
||||
super("Untitled-" + counter);
|
||||
public XL(XLList xlList, XLCounter counter, XLModel XLModel) {
|
||||
super("Window " + counter);
|
||||
this.xlList = xlList;
|
||||
this.counter = counter;
|
||||
xlList.add(this);
|
||||
counter.increment();
|
||||
JPanel statusPanel = new StatusPanel(statusLabel);
|
||||
JPanel sheetPanel = new SheetPanel(ROWS, COLUMNS);
|
||||
Editor editor = new Editor();
|
||||
|
||||
EditorController editorController = new EditorController(XLModel, statusLabel);
|
||||
Editor editor = new Editor(editorController);
|
||||
editorController.setEditor(editor);
|
||||
|
||||
SlotLabelController slotLabelController = new SlotLabelController(XLModel, editor, statusLabel);
|
||||
slotLabelController.setEditorController(editorController);
|
||||
|
||||
JPanel statusPanel = new StatusPanel(statusLabel, XLModel, slotLabelController);
|
||||
JPanel sheetPanel = new SheetPanel(ROWS, COLUMNS, XLModel, slotLabelController, editorController);
|
||||
|
||||
add(NORTH, statusPanel);
|
||||
add(CENTER, editor);
|
||||
add(SOUTH, sheetPanel);
|
||||
setJMenuBar(new XLMenuBar(this, xlList, statusLabel));
|
||||
setJMenuBar(new XLMenuBar(this, xlList, statusLabel, XLModel));
|
||||
pack();
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setResizable(false);
|
||||
|
@ -44,6 +56,6 @@ public class XL extends JFrame {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new XL(new XLList(), new XLCounter());
|
||||
new XL(new XLList(), new XLCounter(), new XLModel());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue