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 java.awt.Color;
 | 
				
			||||||
import javax.swing.JTextField;
 | 
					import javax.swing.JTextField;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Editor extends JTextField {
 | 
					import xl.controller.EditorController;
 | 
				
			||||||
 | 
					import java.awt.event.ActionListener;
 | 
				
			||||||
 | 
					import java.awt.event.ActionEvent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Editor() {
 | 
					public class Editor extends JTextField  {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Editor(EditorController editorController) {
 | 
				
			||||||
        setBackground(Color.WHITE);
 | 
					        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.CENTER;
 | 
				
			||||||
import static java.awt.BorderLayout.WEST;
 | 
					import static java.awt.BorderLayout.WEST;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import xl.controller.EditorController;
 | 
				
			||||||
 | 
					import xl.controller.SlotLabelController;
 | 
				
			||||||
 | 
					import xl.model.XLModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SheetPanel extends BorderPanel {
 | 
					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(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;
 | 
					package xl.gui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.awt.Color;
 | 
					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);
 | 
					        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.ArrayList;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import javax.swing.SwingConstants;
 | 
					import javax.swing.SwingConstants;
 | 
				
			||||||
 | 
					import xl.model.XLModel;
 | 
				
			||||||
 | 
					import xl.controller.EditorController;
 | 
				
			||||||
 | 
					import xl.controller.SlotLabelController;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SlotLabels extends GridPanel {
 | 
					public class SlotLabels extends GridPanel {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private List<SlotLabel> labelList;
 | 
					    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);
 | 
					        super(rows + 1, cols);
 | 
				
			||||||
        labelList = new ArrayList<SlotLabel>(rows * cols);
 | 
					        labelList = new ArrayList<SlotLabel>(rows * cols);
 | 
				
			||||||
        for (char ch = 'A'; ch < 'A' + cols; ch++) {
 | 
					        for (char ch = 'A'; ch < 'A' + cols; ch++) {
 | 
				
			||||||
            add(new ColoredLabel(Character.toString(ch), Color.LIGHT_GRAY, SwingConstants.CENTER));
 | 
					            add(new ColoredLabel(Character.toString(ch), Color.LIGHT_GRAY, SwingConstants.CENTER));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (int row = 1; row <= rows; row++) {
 | 
					        for (int row = 1; row <= rows; row++) {
 | 
				
			||||||
            for (char ch = 'A'; ch < 'A' + cols; ch++) {
 | 
					            for (char ch = 'A'; ch < 'A' + cols; ch++) {
 | 
				
			||||||
                SlotLabel label = new SlotLabel();
 | 
					                SlotLabel label = new SlotLabel(slotLabelController, row, ch);
 | 
				
			||||||
 | 
					                xlModel.addObserver(label);
 | 
				
			||||||
                add(label);
 | 
					                add(label);
 | 
				
			||||||
                labelList.add(label);
 | 
					                labelList.add(label);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        SlotLabel firstLabel = labelList.get(0);
 | 
					        SlotLabel firstLabel = labelList.get(0);
 | 
				
			||||||
        firstLabel.setBackground(Color.YELLOW);
 | 
					        firstLabel.setBackground(Color.YELLOW);
 | 
				
			||||||
 | 
					        xlModel.setCurrentAddress("A1");
 | 
				
			||||||
 | 
					        slotLabelController.setCurrentSlot(firstLabel);
 | 
				
			||||||
 | 
					        editorController.setCurrentSlot(firstLabel);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,16 +1,10 @@
 | 
				
			||||||
package xl.gui;
 | 
					package xl.gui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.awt.Color;
 | 
					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() {
 | 
					    public StatusLabel() {
 | 
				
			||||||
        super("", Color.WHITE);
 | 
					        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.CENTER;
 | 
				
			||||||
import static java.awt.BorderLayout.WEST;
 | 
					import static java.awt.BorderLayout.WEST;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import xl.controller.SlotLabelController;
 | 
				
			||||||
 | 
					import xl.model.XLModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class StatusPanel extends BorderPanel {
 | 
					public class StatusPanel extends BorderPanel {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected StatusPanel(StatusLabel statusLabel) {
 | 
					    protected StatusPanel(StatusLabel statusLabel, XLModel solver, SlotLabelController slotLabelController) {
 | 
				
			||||||
        add(WEST, new CurrentLabel());
 | 
					        CurrentLabel currentLabel = new CurrentLabel();
 | 
				
			||||||
 | 
					        slotLabelController.setCurrentLabel(currentLabel);
 | 
				
			||||||
 | 
					        add(WEST, currentLabel);
 | 
				
			||||||
        add(CENTER, statusLabel);
 | 
					        add(CENTER, statusLabel);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,11 @@ import static java.awt.BorderLayout.SOUTH;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.swing.JFrame;
 | 
					import javax.swing.JFrame;
 | 
				
			||||||
import javax.swing.JPanel;
 | 
					import javax.swing.JPanel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import xl.controller.EditorController;
 | 
				
			||||||
 | 
					import xl.controller.SlotLabelController;
 | 
				
			||||||
import xl.gui.menu.XLMenuBar;
 | 
					import xl.gui.menu.XLMenuBar;
 | 
				
			||||||
 | 
					import xl.model.XLModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class XL extends JFrame {
 | 
					public class XL extends JFrame {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,23 +19,31 @@ public class XL extends JFrame {
 | 
				
			||||||
    private StatusLabel statusLabel = new StatusLabel();
 | 
					    private StatusLabel statusLabel = new StatusLabel();
 | 
				
			||||||
    private XLList xlList;
 | 
					    private XLList xlList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public XL(XL oldXL) {
 | 
					    public XL(XL oldXL, XLModel XLModel) {
 | 
				
			||||||
        this(oldXL.xlList, oldXL.counter);
 | 
					        this(oldXL.xlList, oldXL.counter, XLModel);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public XL(XLList xlList, XLCounter counter) {
 | 
					    public XL(XLList xlList, XLCounter counter, XLModel XLModel) {
 | 
				
			||||||
        super("Untitled-" + counter);
 | 
					        super("Window " + counter);
 | 
				
			||||||
        this.xlList = xlList;
 | 
					        this.xlList = xlList;
 | 
				
			||||||
        this.counter = counter;
 | 
					        this.counter = counter;
 | 
				
			||||||
        xlList.add(this);
 | 
					        xlList.add(this);
 | 
				
			||||||
        counter.increment();
 | 
					        counter.increment();
 | 
				
			||||||
        JPanel statusPanel = new StatusPanel(statusLabel);
 | 
					
 | 
				
			||||||
        JPanel sheetPanel = new SheetPanel(ROWS, COLUMNS);
 | 
					        EditorController editorController = new EditorController(XLModel, statusLabel);
 | 
				
			||||||
        Editor editor = new Editor();
 | 
					        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(NORTH, statusPanel);
 | 
				
			||||||
        add(CENTER, editor);
 | 
					        add(CENTER, editor);
 | 
				
			||||||
        add(SOUTH, sheetPanel);
 | 
					        add(SOUTH, sheetPanel);
 | 
				
			||||||
        setJMenuBar(new XLMenuBar(this, xlList, statusLabel));
 | 
					        setJMenuBar(new XLMenuBar(this, xlList, statusLabel, XLModel));
 | 
				
			||||||
        pack();
 | 
					        pack();
 | 
				
			||||||
        setDefaultCloseOperation(EXIT_ON_CLOSE);
 | 
					        setDefaultCloseOperation(EXIT_ON_CLOSE);
 | 
				
			||||||
        setResizable(false);
 | 
					        setResizable(false);
 | 
				
			||||||
| 
						 | 
					@ -44,6 +56,6 @@ public class XL extends JFrame {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void main(String[] args) {
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
        new XL(new XLList(), new XLCounter());
 | 
					        new XL(new XLList(), new XLCounter(), new XLModel());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue