/*
 * Image/J Plugins
 * Copyright (C) 2002-2009 Jarek Sacha
 *
 * 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
 *
 * Latest release available at http://sourceforge.net/projects/ij-plugins/
 *
 */
package net.sf.ij_plugins.grow;

import ij.IJ;
import ij.Prefs;
import ij.gui.GUI;
import ij.plugin.PlugIn;

import javax.swing.*;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


/**
 * ImageJ plugin for running Seeded Region Growing.
 *
 * @author Jarek Sacha
 * @since Feb 8, 2008
 */
public final class RegionGrowingPlugIn implements PlugIn {

    private static final String LOC_KEY = "RegionGrowingPlugIn.loc";
    private static final String WIDTH_KEY = "RegionGrowingPlugIn.width";
    private static final String HEIGHT_KEY = "RegionGrowingPlugIn.height";

    private static final String TITLE = "Seeded Region Growing";

    private static RegionGrowingView view;
    private static JDialog dialog;


    public void run(final String arg) {
        if (view == null) {
            view = new RegionGrowingView();
            dialog = new JDialog(IJ.getInstance(), TITLE, false);
            dialog.getContentPane().add(view);
            dialog.pack();
            dialog.setLocationRelativeTo(null);
            dialog.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

            // Add listener to store window location and size on close
            dialog.addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    super.windowClosing(e);
                    Prefs.saveLocation(LOC_KEY, dialog.getLocation());
                    final Dimension d = dialog.getSize();
                    Prefs.set(WIDTH_KEY, d.width);
                    Prefs.set(HEIGHT_KEY, d.height);
                }
            });

            // Restore location and size
            final Point loc = Prefs.getLocation(LOC_KEY);
            final int w = (int) Prefs.get(WIDTH_KEY, 0.0);
            final int h = (int) Prefs.get(HEIGHT_KEY, 0.0);
            if (loc != null && w > 0 && h > 0) {
                dialog.setSize(w, h);
                dialog.setLocation(loc);
            } else {
//                setSize(width, height);
                GUI.center(dialog);
            }
        }

        dialog.setVisible(true);
    }
}

@@ -57,20 +57,80 @@
  Sacha%0D%0A
+ * Author's email: jsacha at users dot sourceforge dot net%0D%0A
  *%0D%0A
-
  * This 
@@ -950,20 +950,16 @@
 ugins/%0D%0A
- *%0D%0A
  */%0D%0Apac
@@ -994,23 +994,8 @@
 %0D%0A%0D%0A
-import ij.IJ;%0D%0A
 impo
@@ -1053,16 +1053,54 @@
 PlugIn;%0D
+%0Aimport net.sf.ij_plugins.ui.UIUtils;%0D
 %0A%0D%0Aimpor
@@ -1141,24 +1141,48 @@
 Dimension;%0D%0A
+import java.awt.Frame;%0D%0A
 import java.
@@ -1973,38 +1973,98 @@
 log(
-IJ.getInstance(), TITLE, false
+(Frame) null, TITLE, false);%0D%0A            dialog.setIconImage(UIUtils.getImageJIconImage()
 );%0D%0A

Change dialog behavior so to des not pop up front when the main ImageJ window is selected.