Package swing.form

Source Code of swing.form.Form$DefaultExitListener

/*
* Form.java
*
* Created on 2009. oktober 20., 13:19
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package swing.form;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FocusTraversalPolicy;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventObject;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import swing.button.Button;
import swing.button.OpenFormButton;
import swing.panel.TkodPanel;
import system.util.LogUtil;
import system.util.Login;
import system.util.ResourceUtil;

/**
*
* @author laci
*/
public abstract class Form extends JFrame{
 
// <editor-fold defaultstate="collapsed" desc="Parameterek">
 
  private JScrollPane mainFrame;
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="Konstruktor">
  /** Peldanyositja a <code>Form</code> osztalyt */
  public Form(Login login) {
    super();
    initialize(login);
  }
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="Inicializalo">
  /** Alapbeallitasok */
  private void initialize(Login login) {
    setLogin(login);
    enabler(new EventObject(this));
  }
 
  // TODO: Title ne csak a form nev�t �rja ki.
  protected void initialize(String name, String title,Container content, boolean resizable, FocusTraversalPolicy focus) {
    setDefaultCloseOperation(Form.DO_NOTHING_ON_CLOSE);
    setName(name);
    setTitle(title);
    setContentPane(content);
    setFocusCycleRoot(true);
    setResizable(resizable);
    setFont(new Font(getMainResource("Font.DefaultStyle"), 0, Integer.parseInt(getMainResource("Font.DefaultSize"))));
    this.setSize(10,10);
    if (focus != null) {
      setFocusTraversalPolicy(focus);
    }
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="DefaultExitListener">
 
  public class DefaultExitListener implements ActionListener {
   
// <editor-fold defaultstate="collapsed" desc="Konstansok">
   
    public static final int EXIT = 0;
   
    public static final int DEACTIVA = 1;
   
// </editor-fold>
   
// <editor-fold defaultstate="collapsed" desc="Param�terek">
   
    private int tipus;
   
    private Form form;
   
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="Konstruktor">
    public DefaultExitListener(Form object, int mire) {
      tipus = mire;
      form = object;
    }
   
// </editor-fold>
       
// <editor-fold defaultstate="collapsed" desc="actionPerformed">
   
    public void actionPerformed(ActionEvent e) {
      form.deactivate();
      if (tipus == DefaultExitListener.EXIT) {
        LogUtil.log("PROGRAM STOP",Form.this.getClass() ,LogUtil.INFO);
        System.exit(0);
      }
    }
   
// </editor-fold>
   
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="getContentTilte">
   
    private JLabel contentTitle;
   
    protected JLabel getContentTitle() {
      if (contentTitle == null) {
        contentTitle = new JLabel("");
        contentTitle.setFont(new Font(getMainResource("Font.DefaultSize"),Font.BOLD,Integer.parseInt(getMainResource("Font.ContentTitleSize"))));
      }
     
      return contentTitle;
    }
   
    protected void setContentTitle(String mire) {
      getContentTitle().setText(mire);
    }
   
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="getExitListener">
 
  private DefaultExitListener exitListener;
 
  public DefaultExitListener getExitListener() {
    return new DefaultExitListener(this,DefaultExitListener.EXIT);
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="run">
 
  public abstract boolean run();
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="getDeactiveListener">
 
  public DefaultExitListener getDeactiveListener() {
    return new DefaultExitListener(this,DefaultExitListener.DEACTIVA);
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="Login">
 
  private Login login;
 
  /** Login be�ll�t�sa */
  protected void setLogin(Login login) {
    this.login = login;
  }
 
  /** Login lek�rdez�se */
  public Login getLogin() {
    return login;
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="szulo Form">
 
  private Form parentForm;
 
  public Form getParentForm() {
    return parentForm;
  }
 
  public void setParentForm(Form mire) {
    parentForm = mire;
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="enabler">
 
  /** Formon l�v� mez�k tilt�s�ra, enged�lyez�s�re szolg�l. */
  protected abstract void enabler(EventObject e);
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="mainFrame">
 
  /** Vissza adja a f� megjelen�t� panelt (Singleton pattern) */
  public JScrollPane getMainFrame() {
    if (mainFrame == null) {
      mainFrame = createMainFrame();
    }
    return mainFrame;
  }
 
  /** Kesobb, ha uj componenst akarunk felrakni, csak ezt kell felol irni. */
  protected JScrollPane createMainFrame() {
    JScrollPane temp = new JScrollPane();
    temp.setViewportView(getContent());
   
    return temp;
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="getContent">
 
  private JPanel content;
 
  protected JPanel getContent() {
    if (content == null) {
      content = createContent();
    }
   
    return content;
  }
 
  protected JPanel createContent() {
    JPanel temp = new JPanel(new GridBagLayout());
   
    return temp;
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="Eroforras lekerdezes">
 
  private ResourceUtil resourceUtil;
 
  private ResourceUtil getResourceUtil() {
    if (resourceUtil == null) {
      resourceUtil = new ResourceUtil();
    }
   
    return resourceUtil;
  }
 
  public String getFormResource(String key) {
    return getResourceUtil().getFormResource(key);
  }
 
  public String getMainResource(String key) {
    return getResourceUtil().getMainResource(key);
  }
 
  /** Vissza adja az er�forr�s �rt�ket legyen b�rmelyikben is */
  public String getResource(String key) {
    String eroforras;
    eroforras = getMainResource(key);
    if (eroforras == null) {
      return getFormResource(key);
    }
    return eroforras;
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="fokusz order">
 
  /** F�kusz sorrend be�ll�t�sa */
  protected abstract Vector getFocusOrder();
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="aktival/deaktival">
 
  // TODO: Fokusz beallitas kimaradt ... MEEEG
  public boolean activate() {
    if (isActived())
      return false;
    fill();
    pack();
    toCenter();
    setActived(true);
    setVisible(true);
    //getFocusTraversalPolicy().getDefaultComponent(this).requestFocusInWindow();
    return true;
  }
 
  public boolean deactivate() {
    if (!isActived())
      return false;
    if ((getParentForm() != null) && (!getParentForm().isActived()))
      getParentForm().activate();
    setActived(false);
    setVisible(false);
    reset();
    return true;
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="Kozepre">
 
  protected void toCenter() {
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = getSize();
       
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }
       
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
       
        setSize(frameSize.width, frameSize.height);
        setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="aktiv-e">
 
  private boolean actived;
 
  public void setActived(boolean mire) {
    actived = mire;
  }
 
  public boolean isActived() {
    return actived;
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="kitolt">
 
  /** Kepernyo kitoltese */
  protected abstract void fill();
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="reszet">
 
  /** Kepernyo torlese */
  protected abstract void reset();
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="OkGomb">
 
  private OpenFormButton okButton;
 
  public OpenFormButton getOkButton() {
    if (okButton == null) {
      okButton = createOkButton();
    }
   
    return okButton;
  }
 
  protected OpenFormButton createOkButton() {
    OpenFormButton temp = new OpenFormButton(getFormResource("Form.OkButton"));
   
    return temp;
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="addOkGomblistener">
 
  public void addOkButtonListener(ActionListener l) {
    getOkButton().addActionListener(l);
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="MegsemGomb">
 
  private Button cancelButton;
 
  public Button getCancelButton() {
    if (cancelButton == null) {
      cancelButton = createCancelButton();
    }
   
    return cancelButton;
  }
 
  protected Button createCancelButton() {
    Button temp = new Button(getFormResource("Form.CancelButton"));
   
    return temp;
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="MegsemGomb">
 
  private Button resetButton;
 
  public Button getResetButton() {
    if (resetButton == null) {
      resetButton = createResetButton();
    }
   
    return resetButton;
  }
 
  protected Button createResetButton() {
    Button temp = new Button(getFormResource("Button.Reset"));
    temp.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        reset();
      }
    });
   
    return temp;
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="addMegsemGomblistener">
 
  public void addCancelButtonListener(ActionListener l) {
    getCancelButton().addActionListener(l);
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="Objektum">
 
  private Object elem;
 
  public Object getValue() {
    return elem;
  }
 
  public void setValue(Object mire) {
    elem = mire;
  }
 
  public abstract void setTkod(Integer tkod);
 
  public abstract Integer getTkod();
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="valid">
 
  public abstract boolean valid();
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="tkodPanel">
 
  private TkodPanel tkodPanel;
 
  protected TkodPanel getTkodPanel() {
    if (tkodPanel == null) {
      tkodPanel = createTkodPanel();
    }
   
    return tkodPanel;
  }
 
  protected TkodPanel createTkodPanel() {
    TkodPanel temp = new TkodPanel(getLogin(), getFormResource("Form.TkodPanel"));
   
    return temp;
  }
 
  protected void fillTkodPanel() {
    Integer tkod = getTkod();
    if (tkod == null) {
      getTkodPanel().setText(null);
    } else {
      getTkodPanel().setText(tkod.toString());
    }
  }
 
// </editor-fold>
 
// <editor-fold defaultstate="collapsed" desc="Dokumentum listener">
 
  private DocumentListener docListener;
 
  protected DocumentListener getDocListener() {
    if (docListener == null) {
      docListener =
          new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
          enabler(new EventObject(e.getDocument()));
        }
       
       
        public void insertUpdate(DocumentEvent e) {
          changedUpdate(e);
        }
       
       
        public void removeUpdate(DocumentEvent e) {
          changedUpdate(e);
        }
      };
    }
    return docListener;
}
 
// </editor-fold>
 
}
TOP

Related Classes of swing.form.Form$DefaultExitListener

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.