/*
 This file is part of the software framework JStatCom, 
 a library for building applications for data based analysis.

 Copyright (C) 2000-2005  Markus Kraetzig

 This library 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 2.1 of the
 License, or (at your option) any later version.

 This library 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 library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA
 */

package com.jstatcom.component;
import javax.swing.JFrame;

/**
 * Class that simply holds a globally accessable reference
 * to the top frame of the application. This needs to be accessed
 * by classes that show messages that should be modal and
 * centered on the screen. The reference should be set at program start.
 * This class is a Singleton.
 *
 * @author Markus Kraetzig
 */
public final class TopFrameReference {
	
    private static JFrame topFrameRef = null; 

/**
 * TopFrameReference prevention constructor.
 */
private TopFrameReference() {

}


/**
 * Gets the top-level reference.
 *
 * @return the top reference 
 */
public static JFrame getTopFrameRef() {
	return topFrameRef;
}


/**
 * Set the reference to the top-level frame of the application.
 * The reference can only be once to make sure that it is
 * a Singleton. This method is not thread-safe.
 *
 * @param  newTopFrameRef the new top frame
 * @throws IllegalStateException if the reference was set before
 */
public static void setTopFrameRef(JFrame newTopFrameRef) {
    if (topFrameRef == null)
        topFrameRef = newTopFrameRef;
    else
        throw new IllegalStateException("Top-level reference was already set.");
}
}
 

Ads help maintain this website.