/** * Copyright 1999-2009 The Pegadi Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.pegadi.client; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.io.IOException; import java.util.ResourceBundle; public class Splash extends JFrame { MediaTracker mt; Image splashImage; private final Logger log = LoggerFactory.getLogger(getClass()); public Splash(String imageURL) { ImageIcon icon = new ImageIcon(getClass().getResource("/images/pegadi.gif")); setIconImage(icon.getImage()); setTitle("Pegadi"); log.debug("Image URL is {}", imageURL); try { splashImage = ImageIO.read(getClass().getResourceAsStream(imageURL)); } catch (IOException e) { log.error("error loading image", e); } ResourceBundle bundle = ResourceBundle.getBundle("org.pegadi.client.ClientStrings"); String version = bundle.getString("version"); int height = splashImage.getHeight(this); int width = splashImage.getWidth(this); Graphics graphics = splashImage.getGraphics(); int drawy = splashImage.getHeight(null) - 20; int drawx = splashImage.getWidth(null) - 275; graphics.drawString(version, drawx, drawy); mt = new MediaTracker(this); mt.addImage(splashImage, 0); try { mt.waitForID(0); } catch (InterruptedException ie) { log.error("Image loading interrupted", ie); } this.setSize(width, height); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((screen.width - width) / 2, (screen.height - height) / 2); setUndecorated(true); } public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.drawImage(splashImage, 0, 0, this); } public void dispose() { splashImage.flush(); super.dispose(); } }