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 javax.swing.JTextPane; 027 028 import se.liu.ida.critiquer.constraints.ConstraintStatusListener; 029 import se.liu.ida.critiquer.constraints.StandardConstraint; 030 import se.liu.ida.critiquer.constraints.TextCritic; 031 032 /** 033 * 034 * This class models the critic text area and makes cure to clear 035 * @author olale 036 * 037 */ 038 public class CriticTextArea implements ConstraintStatusListener { 039 040 private JTextPane textArea = new JTextPane(); 041 private TextCritic controllingCritic; 042 /** 043 * 044 */ 045 public CriticTextArea() { 046 super(); 047 StandardConstraint.addStatusListener(this); 048 } 049 050 public JTextPane getTextArea() { 051 return textArea; 052 } 053 /** 054 * 055 * Replace the controlling critic with this one if there is a new text critic active 056 * 057 * @see se.liu.ida.critiquer.constraints.ConstraintStatusListener#activeStatusChanged(se.liu.ida.critiquer.constraints.StandardConstraint) 058 */ 059 public void activeStatusChanged(StandardConstraint c) { 060 if (c.isActive() && c instanceof TextCritic) { 061 /** 062 * Activation or re-activation of a critic 063 */ 064 if (c!=controllingCritic) { 065 controllingCritic = (TextCritic) c; 066 } 067 if (!c.isConsistent()) { 068 textArea.setText(controllingCritic.getText()); 069 } else { 070 textArea.setText("Displaying information from critic "+c.getClass().getSimpleName()+"\n\n"+ 071 "Description: "+c.getDescription()); 072 } 073 } else if (!c.isActive() && c==controllingCritic) { 074 /** 075 * De-activation of a critic 076 */ 077 textArea.setText(""); 078 } 079 } 080 081 /** 082 * Render critique if it is our constraint that fired this and it is active 083 * 084 * @see se.liu.ida.critiquer.constraints.ConstraintStatusListener#violationStatusChanged(se.liu.ida.critiquer.constraints.StandardConstraint) 085 */ 086 public void violationStatusChanged(StandardConstraint c) { 087 if ( c==controllingCritic && c.isActive() ) { 088 if (!c.isConsistent()) { 089 textArea.setText(controllingCritic.getText()); 090 } else { 091 textArea.setText(""); 092 } 093 } 094 } 095 }