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.Color; 027 import java.awt.event.ItemEvent; 028 import java.awt.event.ItemListener; 029 030 import javax.swing.JCheckBox; 031 032 import se.liu.ida.critiquer.constraints.ConstraintStatusListener; 033 import se.liu.ida.critiquer.constraints.StandardConstraint; 034 035 class ConstraintCheckBox extends JCheckBox implements ItemListener, ConstraintStatusListener { 036 037 /** 038 * 039 */ 040 private static final long serialVersionUID = 1L; 041 042 private StandardConstraint c; 043 public void itemStateChanged(ItemEvent e) { 044 if (isSelected()) { 045 c.setActive(true); 046 } else { 047 c.setActive(false); 048 } 049 PlanningTool.forceGUIUpdate(); 050 } 051 052 public ConstraintCheckBox(StandardConstraint c) { 053 this.c = c; 054 addItemListener(this); 055 StandardConstraint.addStatusListener(this); 056 057 } 058 059 public Class getClassMember() { 060 return c.getClass(); 061 } 062 public String getText() { 063 return (c != null ? c.getClass().getSimpleName() : ""); 064 } 065 066 @SuppressWarnings("unchecked") 067 public boolean isApplicableFor(View view) { 068 return c.isApplicableFor(view); 069 } 070 071 /** 072 * 073 * Set background color when activating the constraint 074 * 075 * @see se.liu.ida.critiquer.constraints.ConstraintStatusListener#activeStatusChanged(se.liu.ida.critiquer.constraints.StandardConstraint) 076 */ 077 public void activeStatusChanged(StandardConstraint constraint) { 078 if (constraint==c && !constraint.isActive()) { 079 updateBackground(constraint); 080 } 081 } 082 083 /** 084 * 085 * Set the background color of this cell if it is inactive to indicate that 086 * the constraint has information to show although it is not active. 087 * 088 * @see se.liu.ida.critiquer.constraints.ConstraintStatusListener#violationStatusChanged(se.liu.ida.critiquer.constraints.StandardConstraint) 089 */ 090 public void violationStatusChanged(StandardConstraint constraint) { 091 if (constraint == c && ! constraint.isActive()) { 092 updateBackground(constraint); 093 } 094 } 095 096 private void updateBackground(StandardConstraint constraint) { 097 if (constraint.isConsistent() ) { 098 setBackground(Color.WHITE); 099 } else { 100 setBackground(Color.RED); 101 } 102 revalidate(); 103 repaint(); 104 } 105 106 107 }