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.conv; 025 026import java.util.Locale; 027 028import javax.swing.BorderFactory; 029import javax.swing.border.Border; 030 031import org.x4o.xml.conv.AbstractStringObjectConverter; 032import org.x4o.xml.conv.ObjectConverter; 033import org.x4o.xml.conv.ObjectConverterException; 034 035/** 036 * BorderConverter test converter. 037 * 038 * @author Willem Cazander 039 * @version 1.0 Aug 17, 2012 040 */ 041public class BorderConverter extends AbstractStringObjectConverter { 042 043 private static final long serialVersionUID = 6729812931433525103L; 044 045 public Class<?> getObjectClassTo() { 046 return Border.class; 047 } 048 049 public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException { 050 return ((Border)obj).toString(); 051 } 052 053 public Object convertStringTo(String str, Locale locale) throws ObjectConverterException { 054 try { 055 if ("LoweredBevelBorder".equals(str)) { 056 return BorderFactory.createLoweredBevelBorder(); 057 } else { 058 return BorderFactory.createEmptyBorder(); 059 } 060 } catch (Exception e) { 061 throw new ObjectConverterException(this,e.getMessage(),e); 062 } 063 } 064 065 @Override 066 public ObjectConverter clone() throws CloneNotSupportedException { 067 BorderConverter result = new BorderConverter(); 068 result.converters=cloneConverters(); 069 return result; 070 } 071}