📄 percentageimage.java
字号:
/**
* DuMP3 version morpheus_0.2.9 - a duplicate/similar file finder in Java<BR>
* Copyright 2005 Alexander Grässer<BR>
* All Rights Reserved, http://dump3.sourceforge.net/<BR>
* <BR>
* This file is part of DuMP3.<BR>
* <BR>
* DuMP3 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.<BR>
* <BR>
* DuMP3 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.<BR>
* <BR>
* You should have received a copy of the GNU General Public License along with DuMP3; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
* Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.za.grasser.duplicate.gui;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
/**
* This class ...
*
* @author <a href="http://sourceforge.net/sendmessage.php?touser=733840">pyropunk at sourceforge dot net</a>
* @version $Revision: 1.5 $
*/
public class PercentageImage {
/**
* <code>image</code> PercentageImage -
*/
private Image image;
/**
* Constructor
*
* @param percentage
* @param pForeground
* @param pBackground
* @param pFont
* @param pText
*/
public PercentageImage(final double percentage, final Color pForeground, final Color pBackground, final Font pFont, final Color pText) {
image = new Image(Display.getDefault(), 16, 16);
final GC gc = new GC(image);
gc.setBackground(pBackground);
gc.fillRectangle(image.getBounds());
gc.setForeground(pForeground);
drawPercentage(gc, percentage);
gc.setFont(pFont);
gc.setForeground(pText);
final String perc = String.valueOf((int)percentage);
final Point p = gc.stringExtent(perc);
gc.drawString(perc, 8 - (p.x >> 1), 8 - (p.y >> 1), true);
gc.dispose();
}
/**
* This method filling percentage indicator
*
* @param gc
* @param percentage
*/
private void drawPercentage(final GC gc, final double percentage) {
int level = (int)(percentage / 100.0 * 256.0);
for (int y = 15; y >= 0; y--) {
for (int x = 0; x < 16; x++) {
if (level-- <= 0) {
return;
}
gc.drawPoint(x, y);
}
}
}
/**
* This method will draw a rotating percentage indicator
*
* @param gc
* @param percentage
*/
void drawPercentage1(final GC gc, final double percentage) {
int level = (int)(percentage / 100.0 * 256.0);
// Q1
for (int y = 7; y >= 0; y--) {
for (int x = 15; x >= 15 - y; x--) {
if (level-- <= 0) {
return;
}
gc.drawPoint(x, y);
}
}
for (int d = 0; d < 7; d++) {
for (int i = 0; i <= 6 - d; i++) {
if (level-- <= 0) {
return;
}
gc.drawPoint(14 - d - i, i);
}
}
// Q2
for (int x = 7; x >= 0; x--) {
for (int y = 0; y <= x; y++) {
if (level-- <= 0) {
return;
}
gc.drawPoint(x, y);
}
}
for (int d = 0; d < 7; d++) {
for (int i = 0; i <= 6 - d; i++) {
if (level-- <= 0) {
return;
}
gc.drawPoint(i, i + d + 1);
}
}
// Q3
for (int y = 8; y < 16; y++) {
for (int x = 0; x < 16 - y; x++) {
if (level-- <= 0) {
return;
}
gc.drawPoint(x, y);
}
}
for (int d = 0; d < 7; d++) {
for (int i = 0; i <= 6 - d; i++) {
if (level-- <= 0) {
return;
}
gc.drawPoint(i + 1 + d, 15 - i);
}
}
// Q4
for (int x = 8; x < 16; x++) {
for (int y = 15; y >= x; y--) {
if (level-- <= 0) {
return;
}
gc.drawPoint(x, y);
}
}
for (int d = 0; d < 7; d++) {
for (int i = 0; i <= 6 - d; i++) {
if (level-- <= 0) {
return;
}
gc.drawPoint(15 - i, 14 - i - d);
}
}
}
/**
* This method ...
*
* @return Image
*/
public Image getImage() {
return image;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -