Source code file content

Revision: 40 (of 40)

Freshly signed JDom
» Project Revision History

» Checkout URL

onyx / src / org / pushingpixels / onyx / details / DetailsWindowManager.java

Size: 4452 bytes, 1 line
/*
 * Copyright (c) 2009-2010 Onyx Kirill Grouchnikov. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 * 
 *  o Redistributions of source code must retain the above copyright notice, 
 *    this list of conditions and the following disclaimer. 
 *     
 *  o Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution. 
 *     
 *  o Neither the name of Onyx Kirill Grouchnikov nor the names of 
 *    its contributors may be used to endorse or promote products derived 
 *    from this software without specific prior written permission. 
 *     
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */
package org.pushingpixels.onyx.details;

import java.awt.*;
import java.lang.reflect.Method;

import org.pushingpixels.onyx.MainWindow;
import org.pushingpixels.onyx.OnyxUtils;
import org.pushingpixels.onyx.data.Album;
import org.pushingpixels.trident.Timeline;
import org.pushingpixels.trident.TimelinePropertyBuilder.PropertySetter;

/**
 * Utility manager for handling the functionality related to the details window.
 * 
 * @author Kirill Grouchnikov
 */
public class DetailsWindowManager {
	/**
	 * The currently shown details window.
	 */
	static DetailsWindow currentlyShownWindow;

	/**
	 * Disposes the currently shown details window.
	 */
	public static void disposeCurrentlyShowing() {
		if ((currentlyShownWindow != null) && currentlyShownWindow.isVisible()) {
			OnyxUtils.fadeOutAndDispose(currentlyShownWindow, 500);
		}
	}

	/**
	 * Shows the details for the specified album item.
	 * 
	 * @param mainWindow
	 *            The main application window.
	 * @param album
	 *            Album item details from Amazon.
	 */
	public static void show(MainWindow mainWindow, Album album) {
		if ((currentlyShownWindow != null) && currentlyShownWindow.isVisible()) {
			currentlyShownWindow.setAlbum(album);
			return;
		}

		currentlyShownWindow = new DetailsWindow();
		currentlyShownWindow.setAlwaysOnTop(true);
		// place the details window centered along the bottom edge of the
		// main application window
		Point mainWindowLoc = mainWindow.getLocation();
		Dimension mainWindowDim = mainWindow.getSize();
		int x = mainWindowLoc.x + mainWindowDim.width / 2
				- currentlyShownWindow.getWidth() / 2;
		int y = mainWindowLoc.y + mainWindowDim.height
				- currentlyShownWindow.getHeight() / 2;
		currentlyShownWindow.setLocation(x, y);

		try {
			Class clazz = Class.forName("com.sun.awt.AWTUtilities");
			final Method opacityMethod = clazz.getDeclaredMethod(
					"setWindowOpacity", Window.class, float.class);

			opacityMethod.invoke(null, currentlyShownWindow, 0.0f);

			OnyxUtils.setWindowAsNonOpaque(currentlyShownWindow);
			currentlyShownWindow.setVisible(true);
			currentlyShownWindow.setAlbum(album);

			Timeline showWindow = new Timeline(currentlyShownWindow);
			showWindow.addPropertyToInterpolate(Timeline.<Float> property(
					"opacity").from(0.0f).to(1.0f).setWith(
					new PropertySetter<Float>() {
						@Override
						public void set(Object obj, String fieldName,
								Float value) {
							try {
								opacityMethod.invoke(null, obj, value);
							} catch (Exception exc) {
								exc.printStackTrace();
							}
						}
					}));
			showWindow.setDuration(500);
			showWindow.play();
		} catch (Exception exc) {
			exc.printStackTrace();
		}
	}
}
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close