<commit_before>package org.cytoscape.internal.view;

/*
 * #%L
 * Cytoscape Swing Application Impl (swing-application-impl)
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2006 - 2013 The Cytoscape Consortium
 * %%
 * 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 2.1 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 General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */


import javax.swing.*;
import java.awt.*;
import org.cytoscape.application.swing.CyNetworkViewDesktopMgr;
import org.cytoscape.view.model.CyNetworkView;

/**
 *
  */
public class CyDesktopManager implements CyNetworkViewDesktopMgr {
	
	public static int MINIMUM_WIN_WIDTH = 200;
	public static int MINIMUM_WIN_HEIGHT = 200;
	public final CytoscapeDesktop desk;
	public final NetworkViewManager viewManager;
		
	public CyDesktopManager(final CytoscapeDesktop desk, final NetworkViewManager viewManager) { 
		this.desk = desk;
		this.viewManager = viewManager;
	}

	@Override
	public Dimension getDesktopViewAreaSize() {
		JDesktopPane desktop = desk.getNetworkViewManager().getDesktopPane();
		
		return desktop.getSize();
	}

	@Override
	public Rectangle getBounds (CyNetworkView view) {
		try {
			JInternalFrame frame = viewManager.getInternalFrame(view);
			if (frame != null)
				return frame.getBounds();
		} catch (Exception e) {
			// Fall through
		}
		return null;
	}

	@Override
	public void setBounds (CyNetworkView view, Rectangle bounds) {
		try {
			JInternalFrame frame = viewManager.getInternalFrame(view);
			if (frame == null)
				return;
			frame.setBounds(bounds);
		} catch (Exception e) {
			return;
		}	
	}
	
	// Arrange all windows in the desktop according to the given style
	@Override
	public void arrangeWindows(ArrangeType pStyle) {
		JDesktopPane desktop = desk.getNetworkViewManager().getDesktopPane();
		
		final Dimension desktopSize = desktop.getSize();
		
		final JInternalFrame[] allFrames = desktop.getAllFrames();
		
		int frameCount = allFrames.length; 
		if ( frameCount == 0)<commit_msg>Refs #2334 - set maximized to false before setting window bounds<commit_after>package org.cytoscape.internal.view;

/*
 * #%L
 * Cytoscape Swing Application Impl (swing-application-impl)
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2006 - 2013 The Cytoscape Consortium
 * %%
 * 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 2.1 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 General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */


import javax.swing.*;
import java.awt.*;
import org.cytoscape.application.swing.CyNetworkViewDesktopMgr;
import org.cytoscape.view.model.CyNetworkView;

/**
 *
  */
public class CyDesktopManager implements CyNetworkViewDesktopMgr {
	
	public static int MINIMUM_WIN_WIDTH = 200;
	public static int MINIMUM_WIN_HEIGHT = 200;
	public final CytoscapeDesktop desk;
	public final NetworkViewManager viewManager;
		
	public CyDesktopManager(final CytoscapeDesktop desk, final NetworkViewManager viewManager) { 
		this.desk = desk;
		this.viewManager = viewManager;
	}

	@Override
	public Dimension getDesktopViewAreaSize() {
		JDesktopPane desktop = desk.getNetworkViewManager().getDesktopPane();
		
		return desktop.getSize();
	}

	@Override
	public Rectangle getBounds (CyNetworkView view) {
		try {
			JInternalFrame frame = viewManager.getInternalFrame(view);
			if (frame != null)
				return frame.getBounds();
		} catch (Exception e) {
			// Fall through
		}
		return null;
	}

	@Override
	public void setBounds (CyNetworkView view, Rectangle bounds) {
		try {
			JInternalFrame frame = viewManager.getInternalFrame(view);
			if (frame == null)
				return;
            // It is CRITICAL that this setMaximum be performed before the setBounds().
            // If frame's state is such that isMaximum() is true, then it seems to
            // ignore any setBounds() statements until the iFrame is in a non-maximum
            // state. The result of this is that frame will use its previous
            // setting for the frame bounds when the frame is restored
            // (set to non Maximum state):
            frame.setMaximum(false);
			frame.setBounds(bounds);
		} catch (Exception e) {
			return;
		}	
	}
	
	// Arrange all windows in the desktop according to the given style
	@Override
	public void arrangeWindows(ArrangeType pStyle) {
		JDesktopPane desktop = desk.getNetworkViewManager().getDesktopPane();
		
		final Dimension desktopSize = desktop.getSize();
		
		final JInternalFrame[] allFrames = desktop.getAllFrames();
		
		int frameCount = allFrames.length; 
		if ( frameCount == 0)
{'fraction_non_alphanumeric': 0.08612099644128114, 'fraction_numerical': 0.007473309608540925, 'mean_word_length': 3.7116512992455992, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7491808', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1557, 'n_words': 565}