001/* 002 * jPOS Project [http://jpos.org] 003 * Copyright (C) 2000-2026 jPOS Software SRL 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jpos.ui.factory; 020 021import org.jdom2.Element; 022import org.jpos.iso.ISOChannel; 023import org.jpos.iso.ISOUtil; 024import org.jpos.iso.gui.ISOChannelPanel; 025import org.jpos.iso.gui.ISOMeter; 026import org.jpos.ui.UI; 027import org.jpos.ui.UIFactory; 028import org.jpos.util.NameRegistrar; 029 030import javax.swing.*; 031import java.util.Observable; 032 033/** 034 * @author Alejandro Revilla 035 * 036 * Creates an ISOMeter component 037 * i.e: 038 * <pre> 039 * <iso-meter idref="id" scroll="true|false" refresh="nnn"/> 040 * </pre> 041 * @see org.jpos.ui.UIFactory 042 */ 043 044public class ISOMeterFactory implements UIFactory { 045 public JComponent create (UI ui, Element e) { 046 ISOChannelPanel icp = null; 047 try { 048 Object obj = NameRegistrar.get (e.getAttributeValue ("idref")); 049 050 if (obj instanceof ISOChannel) { 051 icp = new ISOChannelPanel ((ISOChannel) obj, e.getText ()); 052 } else if (obj instanceof Observable) { 053 icp = new ISOChannelPanel (e.getText()); 054 ((Observable)obj).addObserver (icp); 055 } 056 ISOMeter meter = icp.getISOMeter (); 057 if ("false".equals (e.getAttributeValue ("scroll"))) 058 meter.setScroll (false); 059 060 String protect = e.getAttributeValue ("protect"); 061 if (protect != null) 062 icp.setProtectFields (ISOUtil.toIntArray (protect)); 063 String wipe = e.getAttributeValue ("wipe"); 064 if (wipe != null) 065 icp.setWipeFields (ISOUtil.toIntArray (wipe)); 066 067 String refresh = e.getAttributeValue ("refresh"); 068 if (refresh != null) 069 meter.setRefresh (Integer.parseInt (refresh)); 070 } catch (Exception ex) { 071 ex.printStackTrace (); 072 return new JLabel (ex.getMessage()); 073 } 074 return icp; 075 } 076} 077