Advertisement
Guest User

AWindow

a guest
Oct 16th, 2012
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.57 KB | None | 0 0
  1. /******************************************************************************
  2.  * Product: Adempiere ERP & CRM Smart Business Solution                       *
  3.  * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.                *
  4.  * This program is free software; you can redistribute it and/or modify it    *
  5.  * under the terms version 2 of the GNU General Public License as published   *
  6.  * by the Free Software Foundation. This program is distributed in the hope   *
  7.  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
  8.  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.           *
  9.  * See the GNU General Public License for more details.                       *
  10.  * You should have received a copy of the GNU General Public License along    *
  11.  * with this program; if not, write to the Free Software Foundation, Inc.,    *
  12.  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                     *
  13.  * For the text or an alternative of this public license, you may reach us    *
  14.  * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA        *
  15.  * or via info@compiere.org or http://www.compiere.org/license.html           *
  16.  *****************************************************************************/
  17. package org.compiere.apps;
  18.  
  19. import java.awt.BorderLayout;
  20. import java.awt.GraphicsConfiguration;
  21. import java.awt.Image;
  22. import java.awt.event.WindowEvent;
  23.  
  24. import org.compiere.model.MQuery;
  25. import org.compiere.swing.CFrame;
  26. import org.compiere.util.CLogger;
  27. import org.compiere.util.Env;
  28.  
  29. /**
  30.  *  Main Application Window.
  31.  *  - Constructs, initializes and positions JFrame
  32.  *  - Gets content, menu, title from APanel
  33.  *
  34.  *  @author     Jorg Janke
  35.  *  @version    $Id: AWindow.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $
  36.  *
  37.  * @author Teo Sarca, www.arhipac.ro
  38.  *              <li>BF [ 1836908 ] Report customize NPE when no window access
  39.  */
  40. public class AWindow extends CFrame
  41. {
  42.     /**
  43.      *
  44.      */
  45.     private static final long serialVersionUID = -1925388774073536474L;
  46.  
  47.     /**
  48.      *  @deprecated
  49.      *  Standard Constructor - requires initWindow
  50.      */
  51.     public AWindow ()
  52.     {
  53.         this(null);
  54.     }   //  AWindow
  55.    
  56.     /**
  57.      *  Standard Constructor - requires initWindow
  58.      *  @param gc
  59.      */
  60.     public AWindow (GraphicsConfiguration gc)
  61.     {
  62.         super(gc);
  63.         //  Set UI Components
  64.         this.setIconImage(Env.getImage("mWindow.gif"));
  65.         this.getContentPane().add(m_APanel, BorderLayout.CENTER);
  66.         this.setGlassPane(m_glassPane);
  67.     }   //  AWindow
  68.  
  69.     /** The GlassPane           */
  70.     private AGlassPane      m_glassPane = new AGlassPane();
  71.     /** Application Window      */
  72.     private APanel          m_APanel = new APanel(this);
  73.    
  74.     /** Logger                  */
  75.     private static CLogger  log = CLogger.getCLogger(AWindow.class);
  76.  
  77.     /**
  78.      *  Dynamic Initialization Workbench
  79.      *  @param AD_Workbench_ID workbench
  80.      *  @return true if loaded OK
  81.      */
  82.     protected boolean initWorkbench (int AD_Workbench_ID)
  83.     {
  84.         this.setName("AWindow_WB_" + AD_Workbench_ID);
  85.         boolean loadedOK = m_APanel.initPanel (AD_Workbench_ID, 0, null);
  86.         //
  87.         commonInit();
  88.         return loadedOK;
  89.     }   //  initWorkbench
  90.  
  91.     /**
  92.      *  Dynamic Initialization Single Window
  93.      *  @param AD_Window_ID window
  94.      *  @param query query
  95.      *  @return true if loaded OK
  96.      */
  97.     public boolean initWindow (int AD_Window_ID, MQuery query)
  98.     {
  99.         this.setName("AWindow_" + AD_Window_ID);
  100.         setAD_Window_ID(AD_Window_ID);
  101.         //
  102.         boolean loadedOK = m_APanel.initPanel (0, AD_Window_ID, query);
  103.         if (loadedOK)
  104.         {
  105.             commonInit();
  106.         }
  107.         return loadedOK;
  108.     }   //  initWindow
  109.  
  110.     /**
  111.      *  Common Init.
  112.      *  After APanel loaded
  113.      */
  114.     private void commonInit()
  115.     {
  116.         this.setJMenuBar(m_APanel.getMenuBar());
  117.         this.setTitle(m_APanel.getTitle());
  118.         //
  119.         Image image = m_APanel.getImage();
  120.         if (image != null)
  121.             setIconImage(image);
  122.     }   //  commonInit
  123.  
  124.    
  125.     /*************************************************************************
  126.      *  Set Window Busy
  127.      *  @param busy busy
  128.      */
  129.     public void setBusy (boolean busy)
  130.     {
  131.         if (busy == m_glassPane.isVisible())
  132.             return;
  133.         log.config(getName() + " - " + busy);
  134.         m_glassPane.setMessage(null);
  135.         m_glassPane.setVisible(busy);
  136.         if (busy)
  137.             m_glassPane.requestFocus();
  138.     }   //  setBusy
  139.  
  140.     /**
  141.      *  Set Busy Message
  142.      *  @param AD_Message message
  143.      */
  144.     public void setBusyMessage (String AD_Message)
  145.     {
  146.         m_glassPane.setMessage(AD_Message);
  147.     }   //  setBusyMessage
  148.  
  149.     /**
  150.      *  Set and start Busy Counter
  151.      *  @param time in seconds
  152.      */
  153.     public void setBusyTimer (int time)
  154.     {
  155.         m_glassPane.setBusyTimer (time);
  156.     }   //  setBusyTimer
  157.  
  158.     /**
  159.      *  Window Events
  160.      *  @param e event
  161.      */
  162.     protected void processWindowEvent(WindowEvent e)
  163.     {
  164.         super.processWindowEvent(e);
  165. //      System.out.println(">> Apps WE_" + e.getID()    // + " Frames=" + getFrames().length
  166. //          + " " + e);
  167.     }   //  processWindowEvent
  168.  
  169.     /**
  170.      *  Get Application Panel
  171.      *  @return application panel
  172.      */
  173.     public APanel getAPanel()
  174.     {
  175.         return m_APanel;
  176.     }   //  getAPanel
  177.    
  178.     /**
  179.      *  Dispose
  180.      */
  181.     public void dispose()
  182.     {
  183.         if (Env.hideWindow(this))
  184.             return;
  185.         log.info(toString());
  186.         if (m_APanel != null)
  187.             m_APanel.dispose();
  188.         m_APanel = null;
  189.         this.removeAll();
  190.         super.dispose();
  191.     //  System.gc();
  192.     }   //  dispose
  193.  
  194.     /**
  195.      *  Get Window No of Panel
  196.      *  @return window no
  197.      */
  198.     public int getWindowNo()
  199.     {
  200.         if (m_APanel != null)
  201.             return m_APanel.getWindowNo();
  202.         return 0;
  203.     }   //  getWindowNo
  204.    
  205.     /**
  206.      *  String Representation
  207.      *  @return Name
  208.      */
  209.     public  String toString()
  210.     {
  211.         return getName() + "_" + getWindowNo();
  212.     }   //  toString
  213.  
  214. }   //  AWindow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement