jntextarea.java

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

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

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.peer.TextAreaPeer;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

/**
 * @author: Kishore
 */
public class JNTextArea extends JNTextComponent implements TextAreaPeer{

    public static int INSETS_WIDTH = 10;
    public static int INSETS_HEIGHT = 3;

    protected BufferedImage bi = null;
    protected Graphics big = null;
    protected int biwidth = -1;
    protected int biheight = -1;

/*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/

    protected StringBuffer sb = new StringBuffer();
    protected ArrayList charsWidthArray = new ArrayList();

    protected boolean currentMode = true;
/* CURSOR ALWAYS SITS 'BEFORE' THE INDEX'ED CHARECTER */
    protected int cursorLocationOnScreen = 1;
    protected int cursorIndexInArray = 0;

    public static final boolean MODE_NORMAL = true;
    public static final boolean MODE_INSERT = false;

    protected static final int LEFT = 3;
    protected static final int RIGHT = 4;

    //private int visibleTextWidth = -1;
    //private int visibleTextHeight = -1;
// This is only temp adjustment to call paint

    //private int _LCI = 0;
    //private int _RCI = 0;

    String message = "TextArea is not yet Complete";

    public JNTextArea() {
        super();

        init();

    }

    protected void createBufferedImage(int w, int h) {
        //if((this.getWidth() == w) &&(this.getHeight() == height) ) return;


        /* Create bufferedImage of this size */
        bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        big = bi.getGraphics();

        big.setColor(this.getBackground()); // white.
        big.fillRect(0, 0, w, h);

        /*   Draw BorderLines.   */
/*	// white, right and bottom.
	big.drawLine(w,0, w,h);
	big.drawLine(0,h, w,h);*/

        // darkgray top and left
        big.setColor(Color.darkGray);
        big.drawLine(0, 0, w - 2, 0);
        big.drawLine(0, 0, 0, h - 2);

        // lightgray right-1 and bottom-1
        big.setColor(Color.lightGray);
        big.drawLine(w - 2, 1, w - 2, h - 2);
        big.drawLine(1, h - 2, w - 2, h - 2);

        // black top-1 and left-1
        big.setColor(this.getForeground()); // black.
        big.drawLine(1, 1, w - 3, 1);
        big.drawLine(1, 1, 1, h - 3);


    }

    private void init() {
    }

    public void internallyPaint(Graphics big) {
        /* and finally call repaint(). */
        // add this char to BufferedImage.
/*	big.setColor( this.getBackground() );
//	big.fillRect(0,0,this.getWidth(), this.getHeight());
	big.fillRect(2,2, this.getWidth()-4, this.getHeight()-4);

	big.setColor( this.getForeground() );
	big.drawString( message, 2, this.getHeight()-6 );
	*/

        big.drawImage(bi, 0, 0, null);

        big.drawString("TextArea is not yet Complete.", 5, 18);
    }

    /**
     * recalculate method comment.
     */
    public void recalculate() {
    }

    /**
     * resize method comment.
     */
    public void resize() {
    }

    /**
     * setText method comment.
     */
    public void setSize(Dimension d) {
        super.setSize(d);

        createBufferedImage(this.getWidth(), this.getHeight());
    }

    /**
     * setText method comment.
     */
    public void setText(String str) {
        //TODO: implement it
    }

    public int getCaretPosition() {
        //TODO: implement it
        return 0;
    }

    public Dimension getMinimumSize(int rows, int cols) {
        //TODO: implement it
        return null;
    }

    public Dimension getPreferredSize(int rows, int cols) {
        //TODO: implement it
        return null;
    }

    public int getSelectionEnd() {
        //TODO: implement it
        return 0;
    }

    public int getSelectionStart() {
        //TODO: implement it
        return 0;
    }

    public String getText() {
        //TODO: implement it
        return null;
    }

    public void insert(String text, int pos) {
        //TODO: implement it
    }

    public void insertText(String text, int pos) {
        //TODO: implement it
    }

    public Dimension minimumSize(int rows, int cols) {
        //TODO: implement it
        return null;
    }

    public Dimension preferredSize(int rows, int cols) {
        //TODO: implement it
        return null;
    }

    public void replaceRange(String text, int start_pos, int end_pos) {
        //TODO: implement it
    }

    public void replaceText(String text, int start_pos, int end_pos) {
        //TODO: implement it
    }

    public void select(int start_pos, int end_pos) {
        //TODO: implement it
    }

    public void setCaretPosition(int pos) {
        //TODO: implement it
    }

    public void setEditable(boolean editable) {
        //TODO: implement it
    }
}

⌨️ 快捷键说明

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