001 /** 002 * planningtool - A Planning Tool with Critiquing Support. 003 * 004 * Copyright (C) 2006 olale 005 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU General Public License 008 * as published by the Free Software Foundation; either version 2 009 * of the License, or (at your option) any later version. 010 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 016 * You should have received a copy of the GNU General Public License 017 * along with this program; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 020 * Contact information: 021 * E-mail: olale@ida.liu.se 022 * olale@lysator.liu.se 023 */ 024 package se.liu.ida.critiquer.gui; 025 026 import java.awt.Graphics; 027 import java.awt.Graphics2D; 028 import java.awt.LayoutManager; 029 030 import javax.swing.BorderFactory; 031 import javax.swing.JPanel; 032 033 import se.liu.ida.critiquer.constraints.VisualConstraint; 034 import se.liu.ida.critiquer.constraints.VisualConstraints; 035 036 public abstract class AbstractView extends JPanel implements View { 037 038 /** 039 * Subclasses are free to place the critiquePanel wherever they like, but it 040 * is declared here for convenience. It is implcitly required by the View 041 * interface. 042 */ 043 protected ConstraintComponent critiqueComponent = new ConstraintComponent(); 044 045 public JPanel getConstraintPanel() { 046 return critiqueComponent.getPanel(); 047 } 048 049 050 public AbstractView(LayoutManager layout) { 051 super(layout); 052 init(); 053 } 054 055 public AbstractView() { 056 super(); 057 init(); 058 } 059 060 061 private void init() { 062 critiqueComponent.getPanel().setBorder(BorderFactory.createEtchedBorder()); 063 } 064 065 /* 066 * (non-Javadoc) 067 * 068 * @see javax.swing.JComponent#paint(java.awt.Graphics) 069 */ 070 @Override 071 public void paint(Graphics g) { 072 super.paint(g); 073 updateView((Graphics2D) g); 074 } 075 076 public void updateView(Graphics2D g2) { 077 for (VisualConstraint constraint : VisualConstraints.getActiveConstraints()) { 078 if (constraint.isApplicableFor(this)) { 079 constraint.viewUpdated(this, g2); 080 } 081 } 082 } 083 084 }