📄 infobox.java
字号:
/*
* YALE - Yet Another Learning Environment
* Copyright (C) 2001-2004
* Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,
* Katharina Morik, Oliver Ritthoff
* Artificial Intelligence Unit
* Computer Science Department
* University of Dortmund
* 44221 Dortmund, Germany
* email: yale-team@lists.sourceforge.net
* web: http://yale.cs.uni-dortmund.de/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 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 Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package edu.udo.cs.yale.gui;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import javax.imageio.ImageIO;
import java.io.File;
public class InfoBox extends JPanel {
public static final Paint NORTH_PAINT = new Color(99,99,156);
public static final int RAINBOW_THICKNESS = 4;
private static final Paint[] RAINBOW_COLORS =
{ new Color(156,0,49), new Color(206,156,156),new Color(206,206,99), new Color(155,156,0)};
private static final Font PRODUCT_NAME_FONT = new Font("LucidaSans", Font.PLAIN, 12);
private static final Paint PRODUCT_NAME_PAINT = Color.white;
private static final Paint PRODUCT_NAME_BACKGROUND = Color.black;
public static final int PRODUCT_NAME_X = 15;
private int northHeight;
private int width, height;
private String productName, version;
private int productFontSize;
private int productNameHeight;
private int versionFontSize;
public InfoBox(int width, int height, int northHeight,
String productName, int productNameHeight,
String version, int versionHeight) {
this.width = width;
this.height = height;
this.northHeight = northHeight;
this.productFontSize = (int)(productNameHeight * 0.8);
this.productName = productName;
this.productNameHeight = productNameHeight;
this.version = version;
this.versionFontSize = (int)(versionHeight * 0.8);
setPreferredSize(new Dimension(width, height));
setMaximumSize(new Dimension(width, height));
setMinimumSize(new Dimension(width, height));
}
protected void drawNorth(Graphics2D g) {
g.setPaint(NORTH_PAINT);
g.fillRect(0, 0, width, northHeight);
}
private void drawRainbow(Graphics2D g) {
for (int i = 0; i < RAINBOW_COLORS.length; i++) {
g.setPaint(RAINBOW_COLORS[i]);
g.fillRect(i*width/RAINBOW_COLORS.length, 0,
width/RAINBOW_COLORS.length+1, RAINBOW_THICKNESS);
}
}
private void drawProductName(Graphics2D g) {
g.setPaint(PRODUCT_NAME_BACKGROUND);
g.fillRect(0, 0, width, productNameHeight);
Font productFont = PRODUCT_NAME_FONT.deriveFont((float)productFontSize);
g.setFont(productFont);
g.setPaint(PRODUCT_NAME_PAINT);
g.drawString(productName, PRODUCT_NAME_X, productNameHeight/2 + productFontSize/3);
g.setFont(PRODUCT_NAME_FONT.deriveFont((float)versionFontSize));
int width = (int)productFont.getStringBounds(productName+" ", g.getFontRenderContext()).getWidth();
g.drawString(version, PRODUCT_NAME_X + width, productNameHeight/2 + productFontSize/3);
}
public void drawMain(Graphics2D g) { }
public static void drawLogos(Graphics g, Image[] logos) {
int x = PRODUCT_NAME_X;
for (int i = 0; i < logos.length;i++) {
g.drawImage(logos[i], x, 0, null);
x += logos[i].getWidth(null) + 11;
}
}
public static Dimension getLogoSize(Image[] logos) {
int w = PRODUCT_NAME_X;
int h = 0;
for (int i = 0; i < logos.length; i++) {
w += PRODUCT_NAME_X + logos[i].getWidth(null);
h = Math.max(h, logos[i].getHeight(null));
}
return new Dimension(w, h);
}
public int getMainHeight() {
return height - (northHeight+RAINBOW_THICKNESS+productNameHeight);
}
public void paint(Graphics graphics) {
Graphics2D g = (Graphics2D)graphics;
Graphics2D tempG = (Graphics2D)g.create(0, 0, width, northHeight);
drawNorth(g);
tempG.dispose();
tempG = (Graphics2D)g.create(0, northHeight, width, RAINBOW_THICKNESS);
drawRainbow(tempG);
tempG.dispose();
tempG = (Graphics2D)g.create(0, northHeight+RAINBOW_THICKNESS, width, productNameHeight);
drawProductName(tempG);
tempG.dispose();
tempG = (Graphics2D)g.create(0, northHeight+RAINBOW_THICKNESS+productNameHeight, width, getMainHeight());
drawMain(tempG);
tempG.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -