⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listview.java

📁 一个简单的visio程序。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package webide.itools;

import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.Vector;
import java.io.Serializable;
import java.lang.reflect.*;

import hc.util.MsgBox;

public class ListView extends java.awt.Panel
                                   implements Serializable,
                                   MouseListener,
                                   AdjustmentListener,
						           MouseMotionListener,
						           FocusListener,
						           KeyListener
{

	private  static Cursor nwResizeCursor = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);
	private  static Cursor neResizeCursor = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);
	private  static Cursor swResizeCursor = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);
	private  static Cursor seResizeCursor = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);
	private  static Cursor nResizeCursor = Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR);
	private  static Cursor eResizeCursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
	private  static Cursor sResizeCursor = Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
	private  static Cursor wResizeCursor = Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR);
	private  static Cursor crosshairCursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
	private  static Cursor defaultCursor = Cursor.getDefaultCursor();
	private  static Cursor textCursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
	private  static Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
	private  static Cursor handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
	private  static Cursor moveCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);

	private java.awt.Image CoverImage1 = null;
	private java.awt.Image CoverImage2 = null;

    private int          appearance = 1;
    private int          arrange = 0;
	private boolean      gridlines = false;
	private boolean      multiselect = true;
	private boolean      visible = true;
	public  int          view =2;

	private  Font       ft0           = new Font("Dialog",0,11);
	private  int        bordadd       = 1;

	public ColumnHeaders columnheaders = new ColumnHeaders(this);
	ListItems listitems = new ListItems(this);

	java.awt.Scrollbar Hscrollbar;
	java.awt.Scrollbar Vscrollbar;

	private  Rectangle[]  ListRectangle2;
	private  Rectangle[]  ListRectangle3;

	private boolean focus = false;
	private  java.awt.Image        offimg = null;
	private  java.awt.Graphics     offg;
	private  java.awt.Dimension    offsize;

	int start = 0;
	int increseunit = 0;
	int startValue = 0;
	int startValueY = 0;

	int startValue0 = 0;
	int startValue1 = 0;
	int startValueY0 = 0;
	int startValueY1 = 0;

	int CurrentArrange = 0;
	int CurrentListIndex = 0;
	int maxXView0 = 0;
	int mayYView0 = 0;
	int minXView0 = 0;
	int minYView0 = 0;

	int maxXView1 = 0;
	int mayYView1 = 0;
	int minXView1 = 0;
	int minYView1 = 0;

	ColumnHeader ChangeColumnWidth;
	int mousey = 0;
	int mousex = 0;
	boolean canResize = false;

	boolean getCurrent = false;
	int mousepressedx = 0;
	int mousepressedy = 0;

	boolean drawLineRect = false;

	int gapTop = 0;
	int gapLeft = 0;
	boolean view0MouseDragged = false;

	int maxNView0 = 0;
	int mayNView0 = 0;
	int minxNView0 = 0;
	int minyNView0 = 0;

	int maxNView1 = 0;
	int mayNView1 = 0;
	int minxNView1 = 0;
	int minyNView1 = 0;

	boolean isDragg = false;
	Rectangle LineRect = null;
	int oldy = 0;
	int oldx = 0;

	private java.awt.Image CoverIconImage = null;


	ColumnHeader pressColumnheader;
	ColumnHeader columnheader = null;
	boolean isPressed = false;
	Rectangle oldcurrentRectangle = null;
	NewFileDialog filedialog;

	ListItem listitemclick;
	public String labeltext;
	int cancel;


	int count = 0;
    int  clickcount1 = 0;
    long firsttime = System.currentTimeMillis();
    public boolean iflongClick() {
        if (clickcount1 == 0 ){
            clickcount1++;
        }
        if (clickcount1 == 1){
            clickcount1 = 0;
            if((System.currentTimeMillis() - firsttime) > 2000) {
				count++;
                firsttime = System.currentTimeMillis();
                return true;
            }
        }
        firsttime = System.currentTimeMillis();
        return false;
    } //end of iflongClick.


	public ListView(NewFileDialog filedialog)
	{
		super();
		this.filedialog = filedialog;
		setLayout(null);
		super.setBackground(Color.white);
		super.setForeground(Color.black);
		CoverImage1 = filedialog.image[0];
		CoverImage2 = filedialog.image[1];
		try{
            java.awt.MediaTracker tracker = new java.awt.MediaTracker(this);
            tracker.addImage(CoverImage1, 0);
            tracker.waitForID(0);
            tracker.addImage(CoverImage2, 1);
            tracker.waitForID(1);
	    }catch(Exception e){}


		Hscrollbar = new Scrollbar(Scrollbar.VERTICAL);
		Vscrollbar = new Scrollbar(Scrollbar.HORIZONTAL);

		Hscrollbar.setVisible(false);
		Vscrollbar.setVisible(false);
		add(Hscrollbar);
		add(Vscrollbar);
		Hscrollbar.addAdjustmentListener(this);
		Vscrollbar.addAdjustmentListener(this);

		addMouseListener(this);
		addMouseMotionListener(this);
		addFocusListener(this);
		addKeyListener(this);

        this.setFont(new Font("Dialog", Font.PLAIN, 11));
		setSize(100,100);
	}

	public synchronized void paint(Graphics g)
	{
		update(g);
	}

	public synchronized void update(Graphics g)
	{
	   if( validateImage() )
	   {
		   offg    = offimg.getGraphics();
		   draw(offg);
		   g.drawImage(offimg, 0, 0, this);
		   offg.dispose();
	   }
	   else
		   draw(g);
	}

	public void draw(Graphics g)
	{
		FontMetrics fm = getFontMetrics(getFont());
		if(fm == null) return;
        int fontheight  = fm.getHeight();

		boolean designtime = false;
		Color backcolor = this.getBackColor();
        Color forecolor = this.getForeColor();
		int bordadd = 1;
		Rectangle r = getBounds();
		int Width = r.width;
		int Height = r.height;

		int ColumnHeadersCount = columnheaders.getStoreColumnHeaders().size();
		int ListItemsCount = listitems.getStoreListItems().size();

		g.setColor(backcolor);
		g.fillRect(bordadd, bordadd, Width-2*bordadd, Height-2*bordadd);
        g.translate(-startValue, -startValueY);

		int columnheaderLeft = 0;
		int pointWidth = fm.stringWidth("...");

		int imagewidth = CoverImage1.getWidth(this);
		int imageheight = CoverImage1.getHeight(this);

		if(!designtime){
			switch(this.view) {
				case 2://List

				if(this.ListRectangle2 == null || (ListRectangle2 != null && ListRectangle2.length != ListItemsCount)){
					this.ListRectangle2 = new Rectangle[ListItemsCount];
				}
				for (int n = 0; n < ListItemsCount; n++) this.ListRectangle2[n] = null;

				if(fontheight < imageheight)
				{
					fontheight = imageheight;
				}
				int listStrWidth = getlistStrWidth(imagewidth);
				if(Hscrollbar.isVisible()){
					Hscrollbar.setVisible(false);
				}

				int listHeight = 0;
				listHeight = ((Height-14)/(fontheight+1))*(fontheight+1);
				if(listHeight == 0) listHeight = fontheight+1;
				if((ListItemsCount*(fontheight+1)/listHeight+1)*listStrWidth > Width){
					Vscrollbar.setVisible(true);
					Vscrollbar.setBounds(1,Height-16,Width-2,14);
    				Vscrollbar.setMaximum((ListItemsCount*(fontheight+1)/listHeight+1)*listStrWidth);
    				Vscrollbar.setMinimum(0);
    				Vscrollbar.setVisibleAmount(getSize().width - 2);

					Vscrollbar.setBlockIncrement(listStrWidth*4);
					Vscrollbar.setUnitIncrement(listStrWidth);
				}else{
					listHeight = (Height/(fontheight+1))*(fontheight+1);
					Vscrollbar.setVisible(false);
					startValue = 0;
				}

				for(int i = 0;i < ListItemsCount; i++){
					ListItem listitem = (ListItem)(listitems.getStoreListItems().elementAt(i));
					String listitemString = listitem.getText();
					int column = i*(fontheight+1)/listHeight;
					if(fm.getHeight() < imageheight){
						ListRectangle2[i] = new Rectangle(listStrWidth*column+6+imagewidth,((fontheight+1)*i)%listHeight+6,fm.stringWidth(listitemString),imageheight);
						if(listitem.getSelected() && ListRectangle2[i] != null){
								g.setColor(new Color(30,35,140));
								g.fillRect(listStrWidth*column+6+imagewidth,((fontheight+1)*i)%listHeight+6,fm.stringWidth(listitemString),imageheight);

								if(i == CurrentListIndex)
								{
									g.setColor(Color.yellow);
									BorderLine.drawPoints(g,listStrWidth*column+6+imagewidth,((fontheight+1)*i)%listHeight+6,fm.stringWidth(listitemString)-1,imageheight-1);
								}

								g.setColor(Color.white);
								g.drawString(listitemString,listStrWidth*column+6+imagewidth,((fontheight+1)*i)%listHeight+(fontheight+1)/2+fm.getHeight()-2);

								if(getSmallImage(listitem) != null)
								g.drawImage(getSmallImage(listitem),listStrWidth*column+6,((fontheight+1)*i)%listHeight+6,imagewidth,imageheight,this);
						}else{

							g.setColor(Color.black);
							g.drawString(listitemString,listStrWidth*column+6+imagewidth,((fontheight+1)*i)%listHeight+(fontheight+1)/2+fm.getHeight()-2);

							if(listitem.getGhosted())
							{
							}
							else if(getSmallImage(listitem) != null)
							g.drawImage(getSmallImage(listitem),listStrWidth*column+6,((fontheight+1)*i)%listHeight+6,imagewidth,imageheight,this);

						}
					}else{
						ListRectangle2[i] = new Rectangle(listStrWidth*column+6+imagewidth,((fontheight+1)*i)%listHeight+6,fm.stringWidth(listitemString),fontheight);
						if(listitem.getSelected() && ListRectangle2[i] != null){

								g.setColor(new Color(30,35,140));
								g.fillRect(listStrWidth*column+6+imagewidth,((fontheight+1)*i)%listHeight+6,fm.stringWidth(listitemString),fontheight);

								if(i == CurrentListIndex){
								g.setColor(Color.yellow);
								BorderLine.drawPoints(g,listStrWidth*column+6+imagewidth,((fontheight+1)*i)%listHeight+6,fm.stringWidth(listitemString)-1,fontheight-1);
								}

								g.setColor(Color.white);
								g.drawString(listitemString,listStrWidth*column+6+imagewidth,((fontheight+1)*i)%listHeight+10+(fontheight+1)/2);

							if(getSmallImage(listitem) != null)
							g.drawImage(getSmallImage(listitem),listStrWidth*column+6,((fontheight+1)*i)%listHeight+6,imagewidth,imageheight,this);
						}else{
							g.setColor(Color.black);
							g.drawString(listitemString,listStrWidth*column+6+imagewidth,((fontheight+1)*i)%listHeight+10+(fontheight+1)/2);
							if(getSmallImage(listitem) != null)
							g.drawImage(getSmallImage(listitem),listStrWidth*column+6,((fontheight+1)*i)%listHeight+6,imagewidth,imageheight,this);
						}
					}
				}


				break;
			case 3://Report

			if(this.ListRectangle3 == null || (ListRectangle3 != null && ListRectangle3.length != ListItemsCount)){
				this.ListRectangle3 = new Rectangle[ListItemsCount];
			}
			for (int n = 0; n < ListItemsCount; n++) this.ListRectangle3[n] = null;
			if(imageheight > fontheight)
			{
				fontheight = imageheight;
			}


			if(VscrollIsVisible()){
				if(!HscrollIsVisible(fontheight))
				{
					Vscrollbar.setBounds(1,Height-16,Width-2,14);
				}else
				{

⌨️ 快捷键说明

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