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/JFrameView.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 026 027 /** 028 * This is a convenience class which wraps a JPanelView in a JFrame. 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 JFrameView 035 extends javax.swing.JFrame 036 implements WindowView 037 { 038 039 private JPanelView jPanel; 040 041 /** 042 * Creates a JFrameView with the given backing model and view type. 043 * For types, see JPanelView. 044 * @param model a <code>WidgetModel</code> value 045 * @param type an <code>int</code> value 046 */ 047 public JFrameView (WidgetModel model, int type) { 048 super (); 049 jPanel = new JPanelView (model, type); 050 JScrollPane sp = new JScrollPane (jPanel); 051 getContentPane ().add (sp); 052 pack (); 053 } 054 055 /** 056 * Creates a JFrameView with no backing model and the given view type. 057 * For types, see JPanelView. 058 * @param type an <code>int</code> value 059 */ 060 public JFrameView (int type) { 061 this(null,type); 062 } 063 064 /** 065 * Sets the given tokens en-masse, then calculates the JPanelView's 066 * text. 067 * 068 */ 069 public void addTokens (Map < Object, Object > props) { 070 jPanel.addTokens (props); 071 072 } 073 /** 074 * Set one token and recalculate the text I display from the backing 075 * model. 076 * 077 * @param key an <code>Object</code> value 078 * @param value an <code>Object</code> value 079 */ 080 public void setToken (final Object key, final Object value) { 081 if (key == null) 082 return; 083 String la = key.toString (); 084 // FIXME: add support for WIDTH, HEIGHT, WINDOW_OPEN 085 if (TITLE.equals (la)) { 086 087 String ti = ""; 088 if (value != null) 089 ti = value.toString (); 090 setTitle (ti); 091 } else { 092 jPanel.setToken (key, value); 093 } 094 pack (); 095 setSize (getPreferredSize ()); //invalidate();//pack(); 096 } 097 098 /** 099 * Return the value of the named token. 100 * 101 * @param key an <code>Object</code> value 102 * @return an <code>Object</code> value 103 */ 104 public Object getValue (final Object key) { 105 if (key == null) 106 return null; 107 String la = key.toString (); 108 // FIXME: add support for WIDTH, HEIGHT, WINDOW_OPEN 109 if (TITLE.equals (la)) 110 return getTitle (); 111 112 return jPanel.getValue (key); 113 } 114 115 /** 116 * Return the backing model. 117 * 118 * @return a <code>WidgetModel</code> value 119 */ 120 public WidgetModel getModel () { 121 return jPanel.getModel (); 122 } 123 124 /** 125 * Set the backing model. 126 * 127 * @param newModel a <code>WidgetModel</code> value 128 */ 129 public void setModel (WidgetModel newModel) { 130 jPanel.setModel (newModel); 131 } 132 }