kpiattachment.java

来自「全面实现ilog地功能,没有使用第三方lib.」· Java 代码 · 共 66 行

JAVA
66
字号
/* * This source code is part of TWaver 1.3.1 * * SERVA Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * Copyright 2000-2005 SERVA Software, Inc. All rights reserved. */package demo.network.customui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;

import javax.swing.Icon;

import twaver.Element;
import twaver.TWaverConst;
import twaver.network.ui.ElementUI;
import twaver.network.ui.LayoutedIconAttachment;

public class KPIAttachment extends LayoutedIconAttachment {
	public final static double WIDTH = 20;
	public final static double HEIGHT = 25;

	public final static String[] KYES = new String[]{"PM-01", "PM-02", "PM-03", "PM-04", "PM-05"};
	public final static Color[] COLORS = new Color[]{Color.GREEN, Color.BLUE, Color.YELLOW, Color.RED, Color.CYAN};

    public KPIAttachment(String name, ElementUI ui) {
        super(name, ui, new Icon(){
			public int getIconHeight() {
				return (int)HEIGHT;
			}
			public int getIconWidth() {
				return (int)WIDTH;
			}
			public void paintIcon(Component c, Graphics g, int x, int y) {
			}
        });
    }

    public void paint(Graphics2D g2d) {
    	final int count = KYES.length;
    	final Point location = this.getLocation();

    	final double width = WIDTH / count;
    	Element element = getElementUI().getElement();
    	for(int i=0; i<count; i++){
    		double proportion = 0;
    		String valueText = (String)element.getClientProperty(KYES[i]);
    		if(valueText != null){
    			proportion = Double.parseDouble(valueText.substring(KYES[i].length() + 1));
    		}
    		g2d.setColor(COLORS[i]);
    		double x = location.x + i * width;
    		double height = HEIGHT * proportion;
    		double y = location.y + HEIGHT - height;
    		g2d.fillRect((int)x, (int)y, (int)width, (int)height);
    	}

    	g2d.setColor(Color.GRAY);
    	g2d.setStroke(TWaverConst.BASIC_STROKE);
    	g2d.drawRect(location.x, location.y-1, (int)WIDTH, (int)HEIGHT);
    }
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?