/*
* 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.java.awt.dialog;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.geoforge.java.awt.button.GfrAwtButtonCancel;
import org.geoforge.java.awt.button.GfrAwtButtonOk;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
public class GfrAwtDialogConfirm extends GfrAwtDialogAbs implements
ActionListener
{
private boolean _blnIsCancelled_ = true;//trick!!!
private Button _btnCancel_ = null;
private Button _btnOk_ = null;
public boolean isCancelled()
{
return this._blnIsCancelled_;
}
public GfrAwtDialogConfirm(
Frame owner,
String title,
String strText)
{
super(
owner,
title,
true,
strText);
this._btnCancel_ = new GfrAwtButtonCancel((ActionListener) this);
this._btnOk_ = new GfrAwtButtonOk((ActionListener) this);
_initialise_();
}
private void _initialise_()
{
Panel pnlCommandLeft = new Panel();
Panel pnlCommandRight = new Panel();
pnlCommandLeft.setPreferredSize(new Dimension(50, 25));
pnlCommandLeft.setMaximumSize(new Dimension(50, 25));
pnlCommandLeft.setSize(new Dimension(50, 25));
pnlCommandRight.setPreferredSize(new Dimension(50, 25));
pnlCommandRight.setMaximumSize(new Dimension(50, 25));
pnlCommandRight.setSize(new Dimension(50, 25));
super._pnlCommand.setLayout(new GridLayout(1, 2, 5, 10));
this._btnOk_.setPreferredSize(new Dimension(70, 25));
this._btnOk_.setMaximumSize(new Dimension(70, 25));
this._btnOk_.setSize(new Dimension(70, 25));
this._btnCancel_.setPreferredSize(new Dimension(70, 25));
this._btnCancel_.setMaximumSize(new Dimension(70, 25));
this._btnCancel_.setSize(new Dimension(70, 25));
super._pnlCommand.add(pnlCommandLeft);
super._pnlCommand.add(this._btnOk_);
super._pnlCommand.add(this._btnCancel_);
super._pnlCommand.add(pnlCommandRight);
super.add(super._pnlCommand);
super.pack();
super.setResizable(false);
super.pack();
}
@Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource().equals(this._btnCancel_))
{
this._blnIsCancelled_ = true;
this.dispose();
}
if (e.getSource().equals(this._btnOk_))
{
this._blnIsCancelled_ = false;
this.dispose();
}
}
public static void main(String[] strs)
{
String strBodyDialogConfirm = "Got \"Clean-Up\" hotkey (Alt+C+U)";
strBodyDialogConfirm += "\n\n" + "Please confirm";
GfrAwtDialogConfirm dlg = new GfrAwtDialogConfirm(
null,
"Force Exit",
strBodyDialogConfirm);
dlg.setVisible(true);
boolean bln = dlg.isCancelled();
if (bln)
System.out.println("UserCancelled");
else
System.out.println("UserConfirmed");
dlg = null;
System.exit(1);
}
}