UnObjAddListener.java :  » J2EE » WiSerFramework » de » ug2t » unifiedGui » listener » Java Open Source

Java Open Source » J2EE » WiSerFramework 
WiSerFramework » de » ug2t » unifiedGui » listener » UnObjAddListener.java
// @@
// @@
/*
 * Wi.Ser Framework
 *
 * Version: 1.8.1, 20-September-2007  
 * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library located in LGPL.txt in the 
 * license directory; if not, write to the 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 * 
 * If this agreement does not cover your requirements, please contact us
 * via email to get detailed information about the commercial license 
 * or our service offerings!
 *
 */
// @@

package de.ug2t.unifiedGui.listener;

import de.ug2t.kernel.*;
import de.ug2t.unifiedGui.*;
import de.ug2t.unifiedGui.interfaces.*;

public class UnObjAddListener implements IUnGuiEventListener, IKeExecutable
{
  private String  pem_parent;
  private String  pem_child;
  private boolean pem_useReg;
  private boolean pem_multiAdd = false;
  private int     pem_x        = -1;
  private int     pem_y        = -1;
  private int     pem_w        = -1;
  private int     pem_h        = -1;
  private String  pem_align    = "WEST";

  public UnObjAddListener(String xParent, String xChild, boolean xUseRegistry)
  {
    this.pem_parent = xParent;
    this.pem_child = xChild;
    this.pem_useReg = xUseRegistry;

    return;
  }

  public UnObjAddListener(String xParent, String xChild, boolean xUseRegistry, boolean xMulti)
  {
    this.pem_parent = xParent;
    this.pem_child = xChild;
    this.pem_useReg = xUseRegistry;
    this.pem_multiAdd = xMulti;

    return;
  }

  public UnObjAddListener(String xParent, String xChild)
  {
    this.pem_parent = xParent;
    this.pem_child = xChild;
    this.pem_useReg = true;

    return;
  }

  public UnObjAddListener(String xParent, String xChild, boolean xUseRegistry, int x, int y, int h, int w, String xAlign)
  {
    this.pem_parent = xParent;
    this.pem_child = xChild;
    this.pem_useReg = xUseRegistry;

    this.pem_x = x;
    this.pem_y = y;
    this.pem_h = h;
    this.pem_w = w;
    this.pem_align = xAlign;

    return;
  }

  public UnObjAddListener(String xParent, String xChild, boolean xUseRegistry, boolean xMulti, int x, int y, int h, int w, String xAlign)
  {
    this.pem_parent = xParent;
    this.pem_child = xChild;
    this.pem_useReg = xUseRegistry;
    this.pem_multiAdd = xMulti;

    this.pem_x = x;
    this.pem_y = y;
    this.pem_h = h;
    this.pem_w = w;
    this.pem_align = xAlign;

    return;
  }

  public UnObjAddListener(String xParent, String xChild, int x, int y, int h, int w, String xAlign)
  {
    this.pem_parent = xParent;
    this.pem_child = xChild;
    this.pem_useReg = true;

    this.pem_x = x;
    this.pem_y = y;
    this.pem_h = h;
    this.pem_w = w;
    this.pem_align = xAlign;

    return;
  }

  public void pcmf_execListener(UnComponent xParam) throws Exception
  {
    UnComponent l_parent;
    UnComponent l_child;

    if (this.pem_useReg)
    {
      l_parent = (UnComponent) KeRegisteredObject.pcmf_getObjByName(pem_parent);
      l_child = (UnComponent) KeRegisteredObject.pcmf_getObjByName(pem_child);
    }
    else
    {
      l_parent = (UnComponent) xParam.pcmf_getAppl().pcmf_getUnComponent().pcmf_getByPath(pem_parent);
      l_child = (UnComponent) xParam.pcmf_getAppl().pcmf_getUnComponent().pcmf_getByPath(pem_child);
    }
    if (l_parent != null && l_child != null)
    {
      if (l_parent.pcmf_getSubNode(l_child.pcmf_getName()) == null || this.pem_multiAdd)
      {
        l_parent.pcmf_addNode(l_child.pcmf_getName(), l_child);
        if (this.pem_x != -1 && this.pem_y != -1)
        {
          if (l_parent instanceof IUnContainer)
            ((IUnPanel) l_parent).pcmf_setGuiObjPosition(((UnComponent) l_child).pcmf_getName(), this.pem_x, this.pem_y, this.pem_w, this.pem_h,
                this.pem_align);
          else if (l_parent instanceof IUnApplication)
            ((IUnApplication) l_parent).pcmf_setGuiObjPosition(((UnComponent) l_child).pcmf_getName(), this.pem_x, this.pem_y, this.pem_w, this.pem_h,
                this.pem_align);
          else
            KeLog.pcmf_log("ug2t", "cannot set position, parent object is no container or application: ", this, KeLog.ERROR);
        }

      }
      else
      {
        l_parent.pcmf_removeNode(l_child.pcmf_getName());
        l_parent.pcmf_addNode(l_child.pcmf_getName(), l_child);
        if (this.pem_x != -1 && this.pem_y != -1)
        {
          if (l_parent instanceof IUnContainer)
            ((IUnPanel) l_parent).pcmf_setGuiObjPosition(((UnComponent) l_child).pcmf_getName(), this.pem_x, this.pem_y, this.pem_w, this.pem_h,
                this.pem_align);
          else if (l_parent instanceof IUnApplication)
            ((IUnApplication) l_parent).pcmf_setGuiObjPosition(((UnComponent) l_child).pcmf_getName(), this.pem_x, this.pem_y, this.pem_w, this.pem_h,
                this.pem_align);
          else
            KeLog.pcmf_log("ug2t", "cannot set position, parent object is no container or application: ", this, KeLog.ERROR);
        }

        KeLog.pcmf_log(xParam.pcmf_getAppl().pcmf_getUnComponent().pcmf_getName(), "change object: " + pem_parent + ", " + pem_child + " name is not unique",
            this, KeLog.MESSAGE);
      }

      l_parent.pcmf_repaint();
    }
    else
      KeLog.pcmf_log(xParam.pcmf_getAppl().pcmf_getUnComponent().pcmf_getName(), "cannot find parent or child: " + pem_parent + ", " + pem_child, this,
          KeLog.ERROR);
  }

  /**
   * <p>
   * Does...
   * </p>
   * <p>
   * 
   * @return a Type with
   *         </p>
   *         <p>
   * @param
   *         </p>
   */
  public Object pcmf_execObj(Object xObj)
  {
    try
    {
      this.pcmf_execListener((UnComponent) xObj);
    }
    catch (Exception e)
    {
      KeLog.pcmf_log("ug2t", "maybe cannot find parent or child (Exception): " + pem_parent + ", " + pem_child, this, KeLog.ERROR);
    }

    return (xObj);
  }
}

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.