001 /* sillyview : a free model-view-controller system for Java 002 * Copyright (C) 2004 T.J. Willis 003 * 004 * This program is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU General Public License 006 * as published by the Free Software Foundation; either version 2 007 * of the License, or (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program; if not, write to the Free Software 016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. 017 * 018 * $Header: /cvsroot/sillyview/sillyview/src/net/sourceforge/sillyview/JInternalFrameView.java,v 1.2 2004/05/15 01:58:51 tj_willis Exp $ 019 */ 020 package net.sourceforge.sillyview; 021 022 import javax.swing.*; 023 import javax.swing.border.*; 024 import java.util.Map; 025 import java.util.Enumeration; 026 027 /** 028 * This is a convenience class which wraps a JPanelView in a JInternalFrame. 029 * 030 * @author <a href="mailto:tj_willis@users.sourceforge.net">T.J. Willis</a> 031 * @version 1.0 032 * @has - Has 1 net.sourceforge.sillyview.JPanelView 033 */ 034 public class JInternalFrameView 035 extends javax.swing.JInternalFrame implements WindowView { 036 /** 037 * Describe variable <code>jPanel</code> here. 038 * 039 */ 040 private JPanelView jPanel; 041 042 /** 043 * Creates a JFrameView with the given backing model and view type. 044 * For types, see JPanelView. 045 * @param model a <code>WidgetModel</code> value 046 * @param type an <code>int</code> value 047 */ 048 public JInternalFrameView (WidgetModel model, int type) { 049 super (); 050 jPanel = new JPanelView (model, type); 051 JScrollPane sp = new JScrollPane (jPanel); 052 getContentPane ().add (sp); 053 //getContentPane().add(jPanel); 054 pack (); 055 } 056 057 /** 058 * Sets the given tokens en-masse, then calculates the JPanelView's 059 * text. 060 * @param props a <code>Map</code> value 061 */ 062 public void addTokens (Map < Object, Object > props) { 063 jPanel.addTokens (props); 064 065 } 066 /** 067 * Set one token and recalculate the text I display from the backing 068 * model. 069 * 070 * @param key an <code>Object</code> value 071 * @param value an <code>Object</code> value 072 */ 073 public void setToken (Object key, Object value) { 074 if (key == null) 075 return; 076 String la = key.toString (); 077 // FIXME: add support for WIDTH, HEIGHT, WINDOW_OPEN 078 if (TITLE.equals (la)) { 079 080 String ti = ""; 081 if (value != null) 082 ti = value.toString (); 083 setTitle (ti); 084 } else { 085 jPanel.setToken (key, value); 086 } 087 pack (); 088 setSize (getPreferredSize ()); //invalidate();//pack(); 089 } 090 091 /** 092 * Returns the value of the named token. 093 * 094 * @param key an <code>Object</code> value 095 * @return an <code>Object</code> value 096 */ 097 public Object getValue (Object key) { 098 if (key == null) 099 return null; 100 String la = key.toString (); 101 // FIXME: add support for WIDTH, HEIGHT, WINDOW_OPEN 102 if (TITLE.equals (la)) 103 return getTitle (); 104 105 return jPanel.getValue (key); 106 } 107 108 /** 109 * Return the backing model. 110 * 111 * @return a <code>WidgetModel</code> value 112 */ 113 public WidgetModel getModel () { 114 return jPanel.getModel (); 115 } 116 117 /** 118 * Set the backing model. 119 * 120 * @param newModel a <code>WidgetModel</code> value 121 */ 122 public void setModel (WidgetModel newModel) { 123 jPanel.setModel (newModel); 124 } 125 }