001 /*
002 * Copyright 2002-2006 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.springframework.richclient.application.splash;
017
018 import java.awt.AWTException;
019 import java.awt.Color;
020 import java.awt.Component;
021 import java.awt.Dimension;
022 import java.awt.Image;
023 import java.awt.Rectangle;
024 import java.awt.Robot;
025 import java.awt.Toolkit;
026
027 import javax.swing.BorderFactory;
028
029 import org.springframework.richclient.progress.ProgressMonitor;
030
031 /**
032 * MacOSX style splash screen inspired by a blog post by <a
033 * href="http://jroller.com/page/gfx?entry=wait_with_style_in_swing">Romain Guy</a>.
034 *
035 * @author Peter De Bruycker
036 */
037 public class MacOSXSplashScreen extends AbstractSplashScreen implements MonitoringSplashScreen {
038 private InfiniteProgressPanel progressPanel = new InfiniteProgressPanel();;
039
040 protected Component createContentPane() {
041 progressPanel.setPreferredSize(new Dimension(400, 250));
042 progressPanel.shield = 0.5f;
043 progressPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
044 progressPanel.setBackground(takeScreenshot());
045
046 return progressPanel;
047 }
048
049 private Image takeScreenshot() {
050 // take a screenshot
051 try {
052 Robot robot = new Robot();
053 Toolkit tk = Toolkit.getDefaultToolkit();
054 Dimension dim = tk.getScreenSize();
055 return robot.createScreenCapture(new Rectangle(0, 0, dim.width, dim.height));
056 }
057 catch (AWTException e) {
058 e.printStackTrace();
059 return null;
060 }
061 }
062
063 public ProgressMonitor getProgressMonitor() {
064 return new InfiniteProgressPanelProgressMonitor(progressPanel);
065 }
066 }