util.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 320 行

JAVA
320
字号
package org.jnode.wt.components;

import java.awt.Color;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

/**
 * @author Kishore.
 */
public class Util {

    public static char[] carr = null;

    // These are for Image Colors finding ...

    static ArrayList arrColors = null;

    static int arr[] = null;


    public static Image _getImageOF(int arr[], int colors_rgb_arr[], int w, int h) {

        //Color colors_array[] = new Color[colors_rgb_arr.length];

/*for(int ci=o;ci<colors_rgb_arr.length;i++)
{
	colors_array = new Color( colors_rgb_arr[ci] );
}*/


        int[] rgbArray = new int[w * h];

        int nextrgb = -1;
        for (int i = 0; i < rgbArray.length; i++) {
            nextrgb = arr[i];
            rgbArray[i] = colors_rgb_arr[nextrgb];
        }


        BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        bi.setRGB(0, 0, w, h, rgbArray, 0, w);

        return bi;
    }

    public static Image _getSelectedCheckBoxImage() {
        int arr[] = {
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 1, 3, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 1, 1, 3, 2, 3,
            0, 1, 3, 1, 3, 3, 3, 1, 1, 1, 3, 2, 3,
            0, 1, 3, 1, 1, 3, 1, 1, 1, 3, 3, 2, 3,
            0, 1, 3, 1, 1, 1, 1, 1, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 1, 1, 1, 3, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 3, 1, 3, 3, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3,
            0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3,
            0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};

        int colors_rgb_arr[] = {-10461120, -16777216, -4144897, -1};

        int w = 13;
        int h = 13;

        return _getImageOF(arr, colors_rgb_arr, w, h);
    }

    public static Image _getSelectedRadioBoxImage() {
        int arr[] = {
            0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,
            0, 0, 1, 1, 2, 2, 2, 2, 1, 1, 0, 0,
            0, 1, 2, 2, 3, 3, 3, 3, 2, 2, 3, 0,
            0, 1, 2, 3, 3, 3, 3, 3, 3, 4, 3, 0,
            1, 2, 3, 3, 3, 2, 2, 3, 3, 3, 4, 3,
            1, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 3,
            1, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 3,
            1, 2, 3, 3, 3, 2, 2, 3, 3, 3, 4, 3,
            0, 1, 2, 3, 3, 3, 3, 3, 3, 4, 3, 0,
            0, 1, 4, 4, 3, 3, 3, 3, 4, 4, 3, 0,
            0, 0, 3, 3, 4, 4, 4, 4, 3, 3, 0, 0,
            0, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0
        };

//int colors_rgb_arr[] = { -6250368,  -10461120,  -16777216,  -1, -4144897 };
        //   set 0 to Label background color.
        int colors_rgb_arr[] = {-3158065, -10461120, -16777216, -1, -4144897};
        int w = 12;
        int h = 12;

        return _getImageOF(arr, colors_rgb_arr, w, h);
    }


    public static Image _getUnSelectedCheckBoxImage() {
        int arr[] = {
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3,
            0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3,
            0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3,
            0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};

        int colors_rgb_arr[] = {-10461120, -16777216, -4144897, -1};

        int w = 13;
        int h = 13;

        return _getImageOF(arr, colors_rgb_arr, w, h);
    }

    public static Image _getUnSelectedRadioBoxImage() {
        int arr[] = {
            0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,
            0, 0, 1, 1, 2, 2, 2, 2, 1, 1, 0, 0,
            0, 1, 2, 2, 3, 3, 3, 3, 2, 2, 3, 0,
            0, 1, 2, 3, 3, 3, 3, 3, 3, 4, 3, 0,
            1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3,
            1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3,
            1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3,
            1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3,
            0, 1, 2, 3, 3, 3, 3, 3, 3, 4, 3, 0,
            0, 1, 4, 4, 3, 3, 3, 3, 4, 4, 3, 0,
            0, 0, 3, 3, 4, 4, 4, 4, 3, 3, 0, 0,
            0, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0
        };

//int colors_rgb_arr[] = { -6250368,  -10461120,  -16777216,  -1, -4144897 };
        //   set 0 to Label background color.
        int colors_rgb_arr[] = {-3158065, -10461120, -16777216, -1, -4144897};
        int w = 12;
        int h = 12;

        return _getImageOF(arr, colors_rgb_arr, w, h);
    }


    public static void endColorProcessing() {
        Color c = null;
        int rgb = -7;

        for (int i = 0; i < arrColors.size(); i++) {
            c = (Color) arrColors.get(i);

            if (c != null) {
                rgb = c.getRGB();
//			System.out.println("["+Util.fs( 3,i) +"] "+ Util.fs(10, rgb) );
                System.out.println(Util.fs(10, rgb) + ", ");

            } else {
                System.out.println("Util.endColorProcessing::arrColors contains NULL");
            }
        }


    }

    public static String fs(int fl, int num) {
        return getFixedLengthStringforInt(fl, num);
    }

    public static String fs(int fl, String s) {
        return getFixedLengthStringforInt(fl, s);
    }

    public static int getColorIndexOf(int rgb) {
//	Color c = new Color(r,g,b);
        Color c = new Color(rgb);

        int i = arrColors.indexOf(c);

        if (i < 0) {
            arrColors.add(c);
        }

        return arrColors.indexOf(c);
    }

    public static int getColorIndexOf(int r, int g, int b) {
        Color c = new Color(r, g, b);

        int i = arrColors.indexOf(c);

        if (i < 0) {
            arrColors.add(c);
        }

        return arrColors.indexOf(c);
    }
/*
   This method is to display numbers with fixed size strings,
   this especially usefull in making console outputs clean.
ex:-  see the following int outputs.

red  blue green
255  255  255
1  25  3
30  40  255


with this method, the output will be as follows.
red  blue green
255  255  255
  1   25    3
 30   40  255

*/
    public static String getFixedLengthStringforInt(int fixedlen, int num) {
        return getFixedLengthStringforInt(fixedlen, num + "");
    }
/*
   This method is to display numbers with fixed size strings,
   this especially usefull in making console outputs clean.
ex:-  see the following int outputs.

red  blue green
255  255  255
1  25  3
30  40  255


with this method, the output will be as follows.
red  blue green
255  255  255
  1   25    3
 30   40  255

*/
    public static String getFixedLengthStringforInt(int fixedlen, String s) {
        char EMTY_CHAR = ' ';

        int d = fixedlen - s.length();

        if (d > 0) {
            StringBuffer sb = new StringBuffer(fixedlen);

            for (int i = 0; i < d; i++)
                sb.append(EMTY_CHAR);

            sb.append(s);

            return sb.toString();
        }

        return s;
    }
/*
 * This is returns points of Rectangle in ClockWiseDirection.
 */
    public static Point[] getPoints(Rectangle r) {
        if (null == r)
            return null;


        Point[] ps = new Point[4];

        ps[0] = new Point(r.x, r.y);
        ps[1] = new Point(r.x + r.width, r.y);
        ps[1] = new Point(r.x + r.width, r.y + r.height);
        ps[3] = new Point(r.x, r.y + r.height);


        return ps;
    }

    public static void print(String str) {
//	if(printUnImplementedMessages)
        System.out.println(str);
    }

    public static void printIncorrectImp(String str) {
//	if(printUnImplementedMessages)
        print("Incorrect-Implemented   " + str);
    }

    public static void printNotImp(String str) {
//	if(printUnImplementedMessages)
        print("Not-Implemented   " + str);
    }

    public static void printTodo(String str) {
//	if(printUnImplementedMessages)
        print("@TODO::  " + str);
    }

    public static void startColorProcessing() {
        arrColors = new ArrayList();

    }

    public static Rectangle substract(Rectangle r, Insets insets) {
        if (null == insets) {
            return r;
        }

        if ((r != null) && (insets != null)) {
            int x = r.x + insets.left;
            int y = r.y + insets.top;

            int w = r.width - (insets.left + insets.right);
            int h = r.height - (insets.top + insets.bottom);

            return new Rectangle(x, y, w, h);
        }
        return null;
    }
}

⌨️ 快捷键说明

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