|
| 1 | +/* |
| 2 | + * This file is part of Arduino. |
| 3 | + * |
| 4 | + * Code inspired by this tutorial http://wiki.netbeans.org/Splash_Screen_Beginner_Tutorial. License says "You may modify and use it as you wish." |
| 5 | + * |
| 6 | + * Copyright 2015 Arduino LLC (http://www.arduino.cc/) |
| 7 | + * |
| 8 | + * Arduino is free software; you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as published by |
| 10 | + * the Free Software Foundation; either version 2 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License |
| 19 | + * along with this program; if not, write to the Free Software |
| 20 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | + * |
| 22 | + * As a special exception, you may use this file as part of a free software |
| 23 | + * library without restriction. Specifically, if other files instantiate |
| 24 | + * templates or use macros or inline functions from this file, or you compile |
| 25 | + * this file and link it with other files to produce an executable, this |
| 26 | + * file does not by itself cause the resulting executable to be covered by |
| 27 | + * the GNU General Public License. This exception does not however |
| 28 | + * invalidate any other reasons why the executable file might be covered by |
| 29 | + * the GNU General Public License. |
| 30 | + */ |
| 31 | + |
| 32 | +package cc.arduino.view; |
| 33 | + |
| 34 | +import java.awt.*; |
| 35 | +import java.awt.geom.Rectangle2D; |
| 36 | +import java.util.Map; |
| 37 | + |
| 38 | +public class SplashScreenHelper { |
| 39 | + |
| 40 | + private final Map desktopHints; |
| 41 | + private SplashScreen splash; |
| 42 | + private Rectangle2D.Double splashTextArea; |
| 43 | + private Graphics2D splashGraphics; |
| 44 | + |
| 45 | + public SplashScreenHelper(SplashScreen splash) { |
| 46 | + this.splash = splash; |
| 47 | + Toolkit tk = Toolkit.getDefaultToolkit(); |
| 48 | + desktopHints = (Map) tk.getDesktopProperty("awt.font.desktophints"); |
| 49 | + } |
| 50 | + |
| 51 | + public void splashText(String str) { |
| 52 | + if (splash == null) { |
| 53 | + printText(str); |
| 54 | + return; |
| 55 | + } |
| 56 | + if (!splash.isVisible()) { |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + if (splashTextArea == null) { |
| 61 | + // stake out some area for our status information |
| 62 | + splashTextArea = new Rectangle2D.Double(0, 300, 520, 30); |
| 63 | + |
| 64 | + // create the Graphics environment for drawing status info |
| 65 | + splashGraphics = splash.createGraphics(); |
| 66 | + |
| 67 | + if (desktopHints != null) { |
| 68 | + splashGraphics.addRenderingHints(desktopHints); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + // erase the last status text |
| 73 | + splashGraphics.setPaint(new Color(245, 245, 245)); |
| 74 | + splashGraphics.fill(splashTextArea); |
| 75 | + |
| 76 | + // draw the text |
| 77 | + splashGraphics.setPaint(Color.BLACK); |
| 78 | + FontMetrics metrics = splashGraphics.getFontMetrics(); |
| 79 | + splashGraphics.drawString(str, (int) splashTextArea.getX() + 10, (int) splashTextArea.getY() + (30 - metrics.getHeight()) + 4); |
| 80 | + |
| 81 | + // make sure it's displayed |
| 82 | + splash.update(); |
| 83 | + } |
| 84 | + |
| 85 | + public void close() { |
| 86 | + if (splash == null) { |
| 87 | + return; |
| 88 | + } |
| 89 | + splash.close(); |
| 90 | + } |
| 91 | + |
| 92 | + public void printText(String str) { |
| 93 | + System.out.println(str); |
| 94 | + } |
| 95 | + |
| 96 | +} |
0 commit comments