All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quinsoft.zeidon.objectbrowser.ObjectBrowser Maven / Gradle / Ivy

/**
    This file is part of the Zeidon Java Object Engine (Zeidon JOE).

    Zeidon JOE 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.

    Zeidon JOE 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 Zeidon JOE.  If not, see .

    Copyright 2009-2015 QuinSoft
 */
package com.quinsoft.zeidon.objectbrowser;

import java.awt.Component;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

import com.google.common.io.Resources;
import com.quinsoft.zeidon.ObjectEngine;

/**
 * The main Frame for the stand-alone OB.
 *
 * @author DG
 *
 */
public class ObjectBrowser
{
    private final FrameBrowserEnvironment env;
    private JFrame mainFrame;

    public ObjectBrowser( ObjectEngine oe )
    {
        super();
        env = new FrameBrowserEnvironment( oe, this );
    }

    protected void startup()
    {
        // Create and set up the window.
        mainFrame = new JFrame();
        mainFrame.setTitle( "Zeidon Object Browser" );
        mainFrame.setName( "Object Browser" );
        mainFrame.getContentPane().add( new MainPanel( env ) );

        URL iconUrl = Resources.getResource( "tzobrwad.png" );
        ImageIcon image = new ImageIcon( iconUrl );
        mainFrame.setIconImage( image.getImage() );

        BrowserEventHandler listener = new BrowserEventHandler();
        mainFrame.addWindowStateListener( listener );
        mainFrame.addWindowListener( listener );
        mainFrame.pack();

        env.restoreEnvironment();

        // Use invokeLater otherwise toFront() won't always work.
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                // Display the window.
                mainFrame.setVisible( true );
                mainFrame.toFront();
            }
        });

    }

    void saveEnvironment()
    {
        env.saveEnvironment();
        env.getOe().getSystemTask().log().info( "Browser environment saved" );
    }

    public JFrame getFrame()
    {
        return mainFrame;
    }

    private class BrowserEventHandler extends WindowAdapter
    {
        @Override
        public void windowClosing(WindowEvent e)
        {
            env.saveEnvironment();
            mainFrame.setVisible(false);
            mainFrame.dispose();
            mainFrame = null;
        }

        @Override
        public void windowStateChanged(WindowEvent e)
        {
            boolean visible = true;
            switch ( e.getNewState() )
            {
                case Frame.ICONIFIED:
                    visible = false;
                    break;
            }
        }
    }

    public Component getMainFrame()
    {
        return mainFrame;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy