/*
* 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.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.EventObject;
import java.util.logging.Logger;
import javax.swing.*;
import org.geoforge.java.awt.container.GfrUtilContainer;
import org.geoforge.java.awt.font.GfrUtilFont;
import org.geoforge.guillc.GfrAppSpcAbs;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillc.progressbar.GfrProgressBar;
import org.geoforge.io.awt.image.GfrFactoryIconAppGfr;
import org.geoforge.lang.handler.IGfrHandlerEventListenerThreadJobProgress;
import org.geoforge.lang.thread.GfrThr;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
/**
*
* @author bantchao
*/
public class GfrDlgPgsSpaceOpen extends GfrDlgPgsAbs implements
IGfrHandlerEventListenerThreadJobProgress
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrDlgPgsSpaceOpen.class.getName());
static
{
GfrDlgPgsSpaceOpen._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
static private GfrDlgPgsSpaceOpen _INSTANCE_ = null;
public static GfrDlgPgsSpaceOpen s_getInstance()
{
if (_INSTANCE_ == null)
{
try
{
_INSTANCE_ = new GfrDlgPgsSpaceOpen();
}
catch(Exception exc)
{
exc.printStackTrace();
GfrDlgPgsSpaceOpen._LOGGER_.severe(exc.getMessage());
GfrOptionPaneAbs.s_showDialogError(null, exc.getMessage());
System.exit(1);
}
if (! _INSTANCE_.init())
{
GfrDlgPgsSpaceOpen._LOGGER_.severe("! _INSTANCE_.init()");
GfrOptionPaneAbs.s_showDialogError(null, "! _INSTANCE_.init()");
System.exit(1);
}
}
return _INSTANCE_;
}
private boolean _blnFirstRun_ = true;
public void setVisibleTrue(JFrame frmOwner)
{
super._frmOwner = frmOwner;
if (! this._blnFirstRun_)
{
this.setVisible(true);
return;
}
this._blnFirstRun_ = true;
_center_(frmOwner);
Image img = frmOwner.getIconImage();
if (img != null)
super.setIconImage(img);
frmOwner.addWindowListener(new WindowAdapter()
{
@Override
public void windowActivated(WindowEvent windowEvent)
{
if (GfrDlgPgsSpaceOpen.this.isVisible())
GfrDlgPgsSpaceOpen.this.toFront();
}
});
this.setVisible(true);
}
@Override
public void handleEventThreadJobDone(EventObject e)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean init()
{
if (! super.init())
return false;
super.pack();
return true;
}
@Override
public Dimension getPreferredSize()
{
Dimension superPref = super.getPreferredSize();
return new Dimension(400, superPref.height);
}
public void setMessage(String str)
{
_intDoneTask_ ++;
super._lbl.setText(str + " ...");
}
private GfrDlgPgsSpaceOpen() throws Exception
{
super(
null,
//null, // !!! cycling v/s PnlStatusBarMain !!!
(String) null, // strMessageTextfield
"Opening project", // tempo, quick fix
"In progress, please wait",
BorderLayout.WEST);
_createLabels_();
_createDonePanel_();
super._pnlCancel.setEnabledCancelCommandDialog(false);
}
private int _intDoneTask_ = 0;
private void _createDonePanel_()
{
JLabel lbl = new JLabel("Completed");
lbl.setFont(GfrUtilFont.s_get(Font.ITALIC, 14));
JPanel pnlLabel = new JPanel();
pnlLabel.setLayout(new BorderLayout());
pnlLabel.add(lbl, BorderLayout.WEST);
int intPos = GfrUtilContainer.s_getPosition(super._pnlAll, super._pbr); // TODO: get position of toolbar
intPos ++; // position of separator
super._pnlAll.add(Box.createVerticalStrut(10), intPos++); // !!!
super._pnlAll.add(pnlLabel, intPos++);
final GfrProgressBar pbr = new GfrProgressBar(0, GfrAppSpcAbs.F_INT_NB_TASK_SPLASH);
pbr.setValue(_intDoneTask_);
pbr.setIndeterminate(false);
super._pnlAll.add(Box.createVerticalStrut(10), intPos++); // !!!
super._pnlAll.add(pbr, intPos++);
super._pnlAll.add(Box.createVerticalStrut(10), intPos++); // !!!
new GfrThr(new Runnable()
{
@Override
public void run()
{
while (true)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
pbr.setValue(_intDoneTask_);
}
});
try { Thread.sleep(500); } catch (InterruptedException e) {}
}
}
}
,"openSpace").start();
}
private void _createLabels_() throws IOException
{
ImageIcon iinProject = GfrFactoryIconAppGfr.s_getSymbolSpaceProject();
ImageIcon iinWorkspace = GfrFactoryIconAppGfr.s_getSymbolSpaceWorkspace();
ImageIcon iinNavRight = GfrFactoryIconAppGfr.s_getSymbolSpaceNavRight();
JLabel lblProject = new JLabel(iinProject);
JLabel lblWorkspace = new JLabel(iinWorkspace);
JLabel lblNavRight = new JLabel(iinNavRight);
JPanel pnlPicture = new JPanel();
pnlPicture.setLayout(new BorderLayout());
pnlPicture.add(lblProject, BorderLayout.EAST);
pnlPicture.add(lblNavRight, BorderLayout.CENTER);
pnlPicture.add(lblWorkspace, BorderLayout.WEST);
super._pnlAll.add(pnlPicture, 0);
super._pnlAll.add(Box.createVerticalStrut(10), 1);
}
@Override
protected void _invokeLaterCleanUp()
{
// nothing to do, handler by (ActionListener) AcrSpcClsPrj
destroy();
}
public void addActionListenerCancel(ActionListener lstAction)
{
super._pnlCancel.addActionListenerCancel(lstAction);
}
public void removeActionListenerCancel(ActionListener actionListener)
{
super._pnlCancel.removeActionListenerCancel(actionListener);
}
@Override
public void setVisible(boolean bln)
{
if (! bln)
{
if (super._frmOwner != null)
super._frmOwner.setEnabled(true);
}
else
{
if (super._frmOwner != null)
super._frmOwner.setEnabled(false);
}
super.setVisible(bln);
}
private void _center_(JFrame frmOwner)
{
Rectangle rec = frmOwner.getBounds();
int x = rec.x + (rec.width - super.getSize().width)/2;
int y = rec.y + (rec.height - super.getSize().height)/2;
super.setLocation(x, y);
}
}