Package org.geoforge.guillc.dialog

Source Code of org.geoforge.guillc.dialog.DlgViewSrcFileTxtAbs

/*
*  Copyright (C) 2011-2014 GeoForge Project
*
*  This program 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 3 of the License, or
*  (at your option) any later version.
*
*  This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
*/




package org.geoforge.guillc.dialog;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import javax.swing.*;
import org.geoforge.guillc.border.GfrUtilBorder;
import org.geoforge.guillc.button.GfrBcnCloseDialog;
import org.geoforge.guillc.button.BtnAbs;

/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/

abstract public class DlgViewSrcFileTxtAbs extends DlgAbs implements
    ActionListener
{
    // ---------------------------
    // final private static STRING

    /**
     *
     */

    final private static long serialVersionUID = 1L;
    final private static String _f_s_strFilePathNo = "file path: dummy";
    final private static String _f_s_strFileSourceNo = "file source: dummy";


    // ------
    // PUBLIC

    @Override
    public void destroy()
    {
        if (this._btnClose != null)
        {
            this._btnClose.destroy();
            this._btnClose = null;
        }

        super.destroy();
    }


    @Override
    public void actionPerformed(ActionEvent evtAction)
    {
        //String strMethod = "actionPerformed(evtAction)";

        if (! (evtAction.getSource() instanceof GfrBcnCloseDialog))
        {
          //TODO: show error then exit
            //MySystem.s_printOutExit(this, strMethod, "wrong source instance");
        }

        _cancel_();
    }



    @Override
    public void windowClosing(WindowEvent e)
    {
        _cancel_();
    }

    @Override
    public boolean init()
    {
       if(!super.init())
          return false;
      
        JPanel pnlDisplaySource = _createPanelFilePath();

        // --------------


        this._tpeFileSource = new JTextPane();
        this._tpeFileSource.setEditable(false);

        JPanel pnlContainerTpn = new JPanel();
        pnlContainerTpn.setLayout(new BorderLayout() );
        pnlContainerTpn.add(this._tpeFileSource, BorderLayout.CENTER);

  JScrollPane scrContainerPnl = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrContainerPnl.getViewport().add(pnlContainerTpn);

        // --------------

        JPanel pnlOkButton = _createPanelOkButton();

        // -------
        Container cntContentPane = getContentPane();
        cntContentPane.setLayout(new BorderLayout());

        JPanel pnlAll = new JPanel();
        // --- BEGIN border

        GfrUtilBorder.s_setEtched(pnlAll);

        // --- END border
        cntContentPane.add(pnlAll, BorderLayout.CENTER);

        pnlAll.setLayout(new BoxLayout(pnlAll, BoxLayout.Y_AXIS));
        pnlAll.add(pnlDisplaySource);
        pnlAll.add(Box.createVerticalStrut(10));
        pnlAll.add(scrContainerPnl);
        pnlAll.add(Box.createVerticalStrut(10));
        pnlAll.add(pnlOkButton);



        // ending
        return true;
    }

    // ---------
    // PROTECTED

    protected DlgViewSrcFileTxtAbs(Component cmpFrameOwner, String strTitleApplication)
    {
        super((Frame) cmpFrameOwner, true); // true ==> modal=true

        this._btnClose = new GfrBcnCloseDialog((ActionListener) this);

        String strTitleThis = "view source file";

        setTitle(strTitleApplication + " - " + strTitleThis);
    }


    protected boolean _show_(String strSource, String strName)
    {
        //String strMethod = "_show_(strSource, strName)";

        if (strSource==null || strName==null)
        {
            //MySystem.s_printOutError(this, strMethod, "nil arg");
            return false;
        }

        if (this._tpeFileSource == null)
        {
            //MySystem.s_printOutError(this, strMethod, "nil this._tpeFileSource");
            return false;
        }

        this._tpeFileSource.setText(strSource);

        if (this._lblFileName == null)
        {
            //MySystem.s_printOutError(this, strMethod, "nil this._lblFileName");
            return false;
        }

        this._lblFileName.setText(strName);


        super.setVisible(true);
        return true;
    }


    // -------
    // PRIVATE

    private JLabel _lblFileName = null;
    private JTextPane _tpeFileSource = null;

    private JPanel _createPanelFilePath()
    {
        JPanel pnl = new JPanel();
        this._lblFileName = new JLabel();
        this._lblFileName.setText(_f_s_strFilePathNo);
        pnl.add(this._lblFileName);
        return pnl;
    }

    private JPanel _createPanelOkButton()
    {
        JPanel pnl = new JPanel();

        this._btnClose = new GfrBcnCloseDialog((ActionListener) this);

        pnl.add(this._btnClose);
        return pnl;
    }


    private void _cancel_()
    {
        super._cancel();

        this._lblFileName.setText(_f_s_strFilePathNo);
        this._tpeFileSource.setText(_f_s_strFileSourceNo);
    }

    private BtnAbs _btnClose = null;
}
TOP

Related Classes of org.geoforge.guillc.dialog.DlgViewSrcFileTxtAbs

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.