HoSwingEditor.java :  » J2EE » WiSerFramework » de » ug2t » channel » ho » client » swing » Java Open Source

Java Open Source » J2EE » WiSerFramework 
WiSerFramework » de » ug2t » channel » ho » client » swing » HoSwingEditor.java
// @@
// @@
/*
 * Wi.Ser Framework
 *
 * LGPL Version: 1.8.1, 20-September-2007  
 * Copyright (C) 2005-2006 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.channel.ho.client.swing;

import java.awt.event.*;
import java.io.*;
import java.net.*;

import javax.swing.*;

import de.ug2t.channel.ho.*;
import de.ug2t.kernel.*;
import de.ug2t.unifiedGui.interfaces.*;
import de.ug2t.xmlScript.*;

public final class HoSwingEditor extends HoSwingComponent implements IUnTextArea, IUnSyncComponent
{
  protected JEditorPane pdm_swingObj   = null;
  private JScrollPane   pem_pane       = null;
  private String        pem_mime       = null;
  protected char[]      pdm_validSigns = null;

  class MyEditorPane extends JEditorPane
  {
    public MyEditorPane()
    {
      super();
    }

    public MyEditorPane(String arg0) throws IOException
    {
      super(arg0);
    }

    public MyEditorPane(String arg0, String arg1)
    {
      super(arg0, arg1);
    }

    public MyEditorPane(URL arg0) throws IOException
    {
      super(arg0);
    }

    protected void processKeyEvent(KeyEvent arg0)
    {
      char l_char = arg0.getKeyChar();

      try
      {
        if (HoSwingEditor.this.pdm_validSigns != null)
        {
          for (int i = 0; i < HoSwingEditor.this.pdm_validSigns.length; i++)
            if (HoSwingEditor.this.pdm_validSigns[i] == l_char)
            {
              super.processKeyEvent(arg0);
              return;
            }
          arg0.consume();
        }
        super.processKeyEvent(arg0);
      }
      catch (Exception e)
      {
        KeLog.pcmf_log("ug2t", "error while dispatching key events", this, KeLog.DEBUG);
      }
    }
  }

  public HoSwingEditor(String xName, String xValue, String xMime, IUnApplication xAppl) throws Exception
  {
    super(xName, xAppl);

    this.pdm_swingObj = new MyEditorPane(xMime, xValue);
    this.pem_pane = new JScrollPane(this.pdm_swingObj);
    super.pdm_realSwingCmp = this.pem_pane;

    this.pcmf_setLocalValue(xValue);
    this.pem_mime = xMime;
    ((HoSwingClient) xAppl).pcmf_addKeyDispatcher(this);

    this.pemf_addScrollListeners();

    FocusListener l_f = new FocusAdapter()
    {
      public void focusLost(FocusEvent ev)
      {
        try
        {
          String l_objName = HoSwingEditor.this.pcmf_getObjName();

          // Lokale Listener aufrufen
          HoSwingEditor.this.pcmf_setLocalValue(HoSwingEditor.this.pdm_swingObj.getText());
          HoSwingEditor.this.pcmf_setRefresh();
          HoSwingEditor.this.pcmf_dispatchEvent();

          if (HoSwingEditor.this.pem_session.pcmf_isDisabled())
            return;

          // Werte setzen um diese zum Server zu bertragen
          ((HoSwingPage) HoSwingEditor.this.pcmf_getAppl().pcmf_getActive()).pcmf_setSubmitValue(l_objName, HoSwingEditor.this.pcmf_getValue().toString());
          HoSwingEditor.this.pcmf_addSyncedWidgets((HoSwingPage) HoSwingEditor.this.pcmf_getAppl().pcmf_getActive(), HoSwingEditor.this);
          if (HoSwingEditor.this.pcmf_getUnComponent().pcmf_isSubmit() == true)
            ((HoSwingPage) HoSwingEditor.this.pcmf_getAppl().pcmf_getActive()).pcmf_submit();
        }
        catch (Exception e)
        {
          KeLog.pcmf_logException("ug2t", this, e);
        };
      };
    };
    this.pdm_swingObj.addFocusListener(l_f);

    return;
  };

  private void pemf_addScrollListeners()
  {
    AdjustmentListener l_listen = new AdjustmentListener()
    {
      private int           pem_x    = 0;
      private int           pem_y    = 0;
      private HoDelayedCall pem_call = null;

      public void adjustmentValueChanged(AdjustmentEvent e)
      {
        if (this.pem_x == HoSwingEditor.this.pem_pane.getHorizontalScrollBar().getValue()
            && this.pem_y == HoSwingEditor.this.pem_pane.getVerticalScrollBar().getValue())
          return;

        if (pem_session != null)
        {
          KeStringTemplateWrapper l_remCall = new KeStringTemplateWrapper("");

          if (HoSwingEditor.this.pem_session.pcmf_isInTransaction())
          {
            ScXmlScript.pcmf_createPBody(l_remCall);
          }
          else
          {
            ScXmlScript.pcmf_createxScriptString(l_remCall, null);
            ScXmlScript.pcmf_addProc(l_remCall, null);
          };

          this.pem_x = HoSwingEditor.this.pem_pane.getHorizontalScrollBar().getValue();
          this.pem_y = HoSwingEditor.this.pem_pane.getVerticalScrollBar().getValue();

          ScXmlScript.pcmf_addCall(l_remCall, null, HoSwingEditor.this.pcmf_getObjName(), "pcmf_setScrollInfo");
          ScXmlScript.pcmf_addCallPar(l_remCall, Integer.toString(this.pem_x), "false", "int");
          ScXmlScript.pcmf_addCallPar(l_remCall, Integer.toString(this.pem_y), "false", "int");
          ScXmlScript.pcmf_endAll(l_remCall);

          if (this.pem_call == null || this.pem_call.pcmf_isReady())
            this.pem_call = new HoDelayedCall(l_remCall.toString(), HoSwingEditor.this.pem_session, IUnComponent.EVENT_LATENCY_SCROLL, HoSwingEditor.this,
                false);
          else
            this.pem_call.pcmf_refreshCall(l_remCall.toString());
        };
      }
    };
    this.pem_pane.getHorizontalScrollBar().addAdjustmentListener(l_listen);
    this.pem_pane.getVerticalScrollBar().addAdjustmentListener(l_listen);
  }

  public int pcmf_getCols()
  {
    return (0);
  };

  public int pcmf_getRows()
  {
    return (0);
  };

  public void pcmf_setValue(Object xValue)
  {
    this.pdm_swingObj.setText(xValue.toString());
    this.pdm_swingObj.setContentType(pem_mime);
    this.pdm_swingObj.setCaretPosition(0);
    this.pcmf_setLocalValue(xValue);

    return;
  };

  public void pcmf_disable()
  {
    this.pdm_swingObj.setEnabled(false);
    super.pcmf_disable();
    return;
  };

  public void pcmf_enable()
  {
    this.pdm_swingObj.setEnabled(true);
    super.pcmf_enable();
    return;
  };

  public void pcmf_setFgColor(String xCol)
  {
    try
    {
      this.pdm_swingObj.setForeground(HoSwingComponent.pcmf_createColor(xCol));

      super.pcmf_setFgColor(xCol);
    }
    catch (Exception e)
    {
      KeLog.pcmf_logException("ug2t", this, e);
    };

    return;
  };

  public void pcmf_setBgColor(String xCol)
  {
    try
    {
      if (this.pdm_realSwingCmp instanceof JComponent)
      {
        if (xCol.equals("transparent"))
        {
          ((JComponent) this.pdm_swingObj).setOpaque(false);
          return;
        }

        ((JComponent) this.pdm_swingObj).setOpaque(true);
        ((JComponent) this.pdm_swingObj).setBackground(HoSwingComponent.pcmf_createColor(xCol));
      }

      super.pcmf_setBgColor(xCol);
    }
    catch (Exception e)
    {
      KeLog.pcmf_logException("ug2t", this, e);
    };

    return;
  };

  public void pcmf_setScroll(boolean xScroll)
  {
    if (xScroll == true)
    {
      super.pdm_realSwingCmp = this.pem_pane;
      this.pem_pane.setViewportView(this.pdm_swingObj);
    }
    else
    {
      super.pdm_realSwingCmp = this.pdm_swingObj;
      this.pem_pane.setViewportView(null);
    }
  };

  public boolean pcmf_getScroll()
  {
    return (this.pem_pane.getViewport() == null ? false : true);
  }

  public java.awt.Container pcmf_getSwingWidget()
  {
    return (this.pdm_swingObj);
  };

  public void pcmf_scrollXRel(int xPx)
  {
    int l_x = this.pem_pane.getHorizontalScrollBar().getValue();
    l_x += xPx;
    this.pem_pane.getHorizontalScrollBar().setValue(l_x);
  }

  public void pcmf_scrollXAbs(int xPx)
  {
    this.pem_pane.getHorizontalScrollBar().setValue(xPx);
  }

  public void pcmf_scrollYRel(int xPy)
  {
    int l_y = this.pem_pane.getVerticalScrollBar().getValue();
    l_y += xPy;
    this.pem_pane.getVerticalScrollBar().setValue(l_y);
  }

  public void pcmf_scrollYAbs(int xPy)
  {
    this.pem_pane.getVerticalScrollBar().setValue(xPy);
  }

  public int pcmf_getXScroll()
  {
    return (this.pem_pane.getHorizontalScrollBar().getValue());
  }

  public int pcmf_getYScroll()
  {
    return (this.pem_pane.getVerticalScrollBar().getValue());
  }

  public void pcmf_setReadOnly(boolean xReadOnly)
  {
    this.pdm_swingObj.setEditable(!xReadOnly);
  }

  public boolean pcmf_isReadOnly()
  {
    return (!this.pdm_swingObj.isEditable());
  }

  private int pem_syncCnt = 0;

  public Object pcmf_getValueToSync()
  {
    return (this.pdm_swingObj.getText());
  }

  public void pcmf_setSynced()
  {
    this.pem_syncCnt++;
  }

  public void pcmf_unSync()
  {
    this.pem_syncCnt--;
    if (this.pem_syncCnt < 0)
      this.pem_syncCnt = 0;
  }

  public boolean pcmf_isSynced()
  {
    if (this.pem_syncCnt == 0)
      return (false);
    else
      return (true);
  }

  public void pcmf_setInputFilter(String xSigns)
  {
    this.pdm_validSigns = xSigns.toCharArray();
  }

  public void pcmf_removeInputFilter()
  {
    this.pdm_validSigns = null;
  }

  public String pcmf_getInputFilter()
  {
    return (new String(this.pdm_validSigns));
  }

  public void pcmf_setSelected()
  {
    this.pdm_swingObj.select(0, this.pdm_swingObj.getText().length());
  }

  public void pcmf_unSelect()
  {
    this.pdm_swingObj.select(0, 0);
  }

  public void pcmf_setCaretPosition(int xPos)
  {
    this.pcmf_setSelectionInterval(new SelectionInterval(xPos, xPos));
  }

  public void pcmf_setSelectionIntervall(int xBegin, int xLen)
  {
    this.pdm_swingObj.select(xBegin, xBegin + xLen);
  }

  public void pcmf_setSelectionInterval(SelectionInterval xIntervall)
  {
    throw (new UnsupportedOperationException());
  }
};
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.