super("Rectangle View");
controller = new RectangleController(new Rectangle(), this);
createField(this, "widthField", "Width", true)
JPanel fields = createVertGroup(); fields.add(createField(this, "widthField", "Width", true)); fields.add(createField(this, "heightField", "Height", true)); fields.add(createField(this, "areaField", "Area", false)); fields.add(createField(this, "perimeterField", "Perimeter", false)); fields.add(createField(this, "diagonalField", "Diagonal", false)); fields.add(createMultiLineField(this, "summaryField", "Summary", false, new Dimension(200, 200)));
private JPanel createButtonGroup() { JPanel buttons = createHorizGroup(); JButton button = new JButton("Calculate"); button.setName("calculateButton"); buttons.add(button); return buttons; }
protected void hookUpEvents() { JButton button = (JButton) this.get("calculateButton"); button.addActionListener(evt -> this.clickedGo()); }
/** refresh the view from the model */ public void refresh() { setFieldValue("widthField", this.getModel().getWidth()); setFieldValue("heightField", this.getModel().getHeight()); setFieldValue("areaField", this.getModel().getArea()); setFieldValue("perimeterField", this.getModel().getPerimeter()); setFieldValue("diagonalField", this.getModel().getDiagonal()); setMultiLineFieldValue("summaryField", this.getModel().getSummary()); }
/** apply the view values to the model */ public void apply() { this.getModel().setWidth(getFieldValueAsInteger("widthField")); this.getModel().setHeight(getFieldValueAsInteger("heightField")); }