001/* 002 * Copyright (c) 2004-2012, Willem Cazander 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, are permitted provided 006 * that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, this list of conditions and the 009 * following disclaimer. 010 * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 011 * the following disclaimer in the documentation and/or other materials provided with the distribution. 012 * 013 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 015 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 016 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 017 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 018 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 019 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 020 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 021 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 022 */ 023 024package org.x4o.xml.test.swixml.bind; 025 026import java.awt.BorderLayout; 027 028import javax.swing.JComponent; 029import javax.swing.JInternalFrame; 030 031import org.x4o.xml.element.AbstractElementBindingHandler; 032import org.x4o.xml.element.Element; 033import org.x4o.xml.element.ElementBindingHandlerException; 034 035/** 036 * 037 * 038 * @author Willem Cazander 039 * @version 1.0 Aug 16, 2012 040 */ 041public class JInternalFrameBindingHandler extends AbstractElementBindingHandler { 042 043 /** 044 * @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass() 045 */ 046 public Class<?> getBindParentClass() { 047 return JInternalFrame.class; 048 } 049 050 /** 051 * @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses() 052 */ 053 public Class<?>[] getBindChildClasses() { 054 return new Class[] {JComponent.class}; 055 } 056 057 /** 058 * @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element) 059 */ 060 public void doBind(Object parentObject, Object childObject, Element childElement) throws ElementBindingHandlerException { 061 JComponent child = (JComponent)childObject; 062 063 String c = childElement.getAttributes().get("constraints"); 064 Object con = null; 065 if ("BorderLayout.CENTER".equals(c)) { 066 con = BorderLayout.CENTER; 067 } else if ("BorderLayout.NORTH".equals(c)) { 068 con = BorderLayout.NORTH; 069 } else if ("BorderLayout.CENTER".equals(c)) { 070 con = BorderLayout.CENTER; 071 } else if ("BorderLayout.SOUTH".equals(c)) { 072 con = BorderLayout.SOUTH; 073 } 074 075 JInternalFrame frame = (JInternalFrame)parentObject; 076 if (con==null) { 077 frame.getContentPane().add(child); 078 } else { 079 frame.getContentPane().add(child,con); 080 } 081 } 082}