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

📄 listview.java

📁 一个简单的visio程序。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
					Vscrollbar.setBounds(1,Height-16,Width-2-14,14);
				}
				Vscrollbar.setVisible(true);

				int columnheadersWidth = 0;
				for(int i = 0;i<ColumnHeadersCount;i++){
					ColumnHeader columnheader = (ColumnHeader)(columnheaders.getStoreColumnHeaders().elementAt(i));
					columnheadersWidth = columnheadersWidth + columnheader.getWidth();
				}
    			Vscrollbar.setMaximum(columnheadersWidth);
    			Vscrollbar.setMinimum(0);
    			Vscrollbar.setVisibleAmount(getSize().width - 2);

				Vscrollbar.setBlockIncrement(16*4);
				Vscrollbar.setUnitIncrement(16);
			}else{
				Vscrollbar.setVisible(false);
				startValue = 0;
			}

			if(HscrollIsVisible(fontheight))
			{
				if(!VscrollIsVisible()){
					Hscrollbar.setBounds(Width-16,1,14,Height-2);
				}else
				{
					Hscrollbar.setBounds(Width-16,1,14,Height-2-14);
				}
				Hscrollbar.setVisible(true);
    			Hscrollbar.setMaximum((ListItemsCount)*(fontheight+1));
    			Hscrollbar.setMinimum(0);
    			Hscrollbar.setVisibleAmount(((getSize().height - 4 - fontheight*3/2)/(fontheight+1))*(fontheight+1));

				Hscrollbar.setBlockIncrement((fontheight+1)*4);
				Hscrollbar.setUnitIncrement(fontheight+1);
			}else{
				Hscrollbar.setVisible(false);
				start = 0;
			}

			for(int i = 0 ; i<ColumnHeadersCount ; i++){
				ColumnHeader columnheader = (ColumnHeader)(columnheaders.getStoreColumnHeaders().elementAt(i));
				String s = columnheader.getText();
				drawrect(s,columnheader.getPressed(),bordadd+1+columnheaderLeft,bordadd*2,bordadd+columnheaderLeft+columnheader.getWidth(),fm.getHeight()*3/2,g);
				if(i == 1){
					if(columnheaderLeft+6 < imagewidth)
					{
						g.setColor(backcolor);
						g.fillRect(columnheaderLeft+6, bordadd+fm.getHeight()*3/2/*+fm.getHeight()*/, Width-2*bordadd-columnheaderLeft+6, Height-2*bordadd);
					}
				}
				for(int j = 0;j < ListItemsCount - start; j++){
					if((fontheight+1)*(j) > Height) break;
					ListItem listitem = (ListItem)(listitems.getStoreListItems().elementAt(j+start));
					if(i == 0){
						String listitemString = listitem.getText();

						int fwidth = fm.stringWidth(listitemString);
						if(fwidth + imagewidth  > columnheader.getWidth()){
							for(int x = listitemString.length();x>0;x--){
								if(pointWidth + fm.stringWidth(listitemString.substring(0,x)) + imagewidth < columnheader.getWidth()){
									listitemString = listitemString.substring(0,x) + "...";
									break;
								}
							}
							if(!listitemString.endsWith("...")){
								listitemString = listitemString.substring(0,1) + "...";
								int n = 3;
								while(fm.stringWidth(listitemString) + imagewidth > columnheader.getWidth() && n > 0){
									n--;
									listitemString = listitemString.substring(0,n);
								}
							}
						}

						if(fm.getHeight() < imageheight){
							if((j+start) != CurrentListIndex){
								g.setColor(Color.black);
								g.drawString(listitemString,columnheaderLeft+6+imagewidth,(fontheight+1)*j+/*fm.getHeight()*3/2+*/2*fm.getHeight()+fontheight/2+2);
								if(getSmallImage(listitem) != null){
									g.drawImage(getSmallImage(listitem),columnheaderLeft/*+6*/,(fontheight+1)*j+fm.getHeight()*3/2+2/*fm.getHeight()*/,imagewidth,imageheight,this);
								}
							}else{
									g.setColor(new Color(30,35,140));
									g.fillRect(columnheaderLeft+6+imagewidth,(fontheight+1)*j+fm.getHeight()*3/2+2,fm.stringWidth(listitemString),imageheight);

									g.setColor(Color.yellow);
									BorderLine.drawPoints(g,columnheaderLeft+6+imagewidth,(fontheight+1)*j+fm.getHeight()*3/2+2,fm.stringWidth(listitemString)-1,imageheight-1);

									g.setColor(Color.white);
									g.drawString(listitemString,columnheaderLeft+6+imagewidth,(fontheight+1)*j+2*fm.getHeight()+fontheight/2+2);
								if(getSmallImage(listitem) != null){
									g.drawImage(getSmallImage(listitem),columnheaderLeft/*+6*/,(fontheight+1)*j+fm.getHeight()*3/2+2/*fm.getHeight()*/,imagewidth,imageheight,this);
								}
							}
							this.ListRectangle3[j+start] = new Rectangle(columnheaderLeft+6+imagewidth,(fontheight+1)*j+fm.getHeight()*3/2+2,fm.stringWidth(listitemString),imageheight);
						}else{
							if((j+start) != CurrentListIndex){
								g.setColor(Color.black);
								g.drawString(listitemString,columnheaderLeft+6+imagewidth,(fontheight+1)*j+fm.getHeight()*2+4);
								if(getSmallImage(listitem) != null){
									g.drawImage(getSmallImage(listitem),columnheaderLeft,(fontheight+1)*j+fm.getHeight()*3/2+2,imagewidth,imageheight,this);
								}
							}else{
									g.setColor(new Color(30,35,140));
									g.fillRect(columnheaderLeft+6+imagewidth,(fontheight+1)*j+fm.getHeight()*3/2+2,fm.stringWidth(listitemString),fontheight);

									g.setColor(Color.yellow);
									BorderLine.drawPoints(g,columnheaderLeft+6+imagewidth,(fontheight+1)*j+fm.getHeight()*3/2+2,fm.stringWidth(listitemString)-1,fontheight-1);

									g.setColor(Color.white);
									g.drawString(listitemString,columnheaderLeft+6+imagewidth,(fontheight+1)*j+fm.getHeight()*2+4);
								if(getSmallImage(listitem) != null){
									g.drawImage(getSmallImage(listitem),columnheaderLeft/*+6*/,(fontheight+1)*j+fm.getHeight()*3/2+2/*fm.getHeight()*/,imagewidth,imageheight,this);
								}
							}
							this.ListRectangle3[j+start] = new Rectangle(columnheaderLeft+6+imagewidth,(fontheight+1)*j+fm.getHeight()*3/2+2,fm.stringWidth(listitemString),fontheight);
						}

						if(getGridLines())
						{
							g.setColor(Color.lightGray);
							g.drawLine(columnheaderLeft,(fontheight+1)*j+fm.getHeight()*3/2+2+imageheight,columnheaderLeft+1000,(fontheight+1)*j+fm.getHeight()*3/2+2+imageheight);
						}
					}
					if(i > 0)
					{
						String subString = listitem.getSubItemsWithIndex(i);

						int fwidth = fm.stringWidth(subString);
						if(fwidth> columnheader.getWidth()){
							for(int x = subString.length();x>0;x--){
								if(pointWidth + fm.stringWidth(subString.substring(0,x))< columnheader.getWidth()){
									subString = subString.substring(0,x) + "...";
									break;
								}
							}
							if(!subString.endsWith("...")){
								subString = subString.substring(0,1) + "...";
								int n = 3;
								while(fm.stringWidth(subString)> columnheader.getWidth() && n > 0){
									n--;
									subString = subString.substring(0,n);
								}
							}
						}

						g.setColor(Color.black);
						if(subString != "")
						if(fm.getHeight() < imageheight){
							g.drawString(subString,columnheaderLeft+6,(fontheight+1)*j+2*fm.getHeight()+2+fontheight/2);
						}else{
							g.drawString(subString,columnheaderLeft+6,(fontheight+1)*j+fm.getHeight()*2+4);
						}
					}
				}
				if(getGridLines())
				{
					g.setColor(Color.lightGray);
					g.drawLine(bordadd+columnheaderLeft+columnheader.getWidth(),fm.getHeight()*3/2,bordadd+columnheaderLeft+columnheader.getWidth(),(ListItemsCount)*(fontheight+1)+fm.getHeight()*3/2);
				}
				columnheaderLeft = columnheaderLeft + columnheader.getWidth();
			}
			drawrect("",false,bordadd+1+columnheaderLeft,bordadd*2,bordadd+columnheaderLeft+Width,fm.getHeight()*3/2,g);
				break;

			}
		}

		if(drawLineRect && multiselect)
		{
			drawLineOfRect(g,mousepressedx+startValue,mousepressedy+startValueY,mousex+startValue,mousey+startValueY);
		}
        g.translate(startValue, startValueY);
		if(Hscrollbar.isVisible() && Vscrollbar.isVisible()){
			g.setColor(Color.lightGray);
			g.fillRect(Width - 16 , Height - 16 ,14 , 14);
		}
		if (appearance==1)
		{
			g.setColor(Color.gray);
			g.drawLine(0,0,Width,0);
			g.drawLine(0,0,0,Height);
			g.setColor(Color.black);
			g.drawLine(1,1,Width-1,1);
			g.drawLine(1,1,1,Height-1);
			g.setColor(Color.white);
			g.drawLine(Width-1,Height-1,Width-1,0);
			g.drawLine(Width-1,Height-1,0,Height-1);
			g.setColor(Color.lightGray);
			g.drawLine(Width-2,Height-2,Width-2,1);
			g.drawLine(Width-2,Height-2,1,Height-2);
		}
		else
		{
			g.setColor(Color.black);
			g.drawLine(0,0,0,Height);
			g.drawLine(0,0,Width,0);
			g.drawLine(Width-1,Height-1,Width-1,0);
			g.drawLine(Width-1,Height-1,0,Height-1);
		}
	}

    private  boolean validateImage()
	{
		try {
			Dimension offsize = this.getSize();
			if (offimg  ==  null
			|| offimg.getWidth(this) != offsize.width
			|| offimg.getHeight(this) != offsize.height)
			{
				if (offsize.width > 0 && offsize.height > 0)
					offimg = this.createImage(offsize.width, offsize.height);
				else return false;
			}
			return true;
		} catch (java.lang.Throwable ex) {return false;}
	}

 public void mouseClicked(MouseEvent e){}
 public void mouseEntered(MouseEvent e){}
 public void mouseExited(MouseEvent e){}

 public void mousePressed(MouseEvent e) {
		isDragg = false;
		FontMetrics fm = getFontMetrics(getFont());
		if(fm == null) return;
        int fontheight  = fm.getHeight();
		int columnheaderLeft = 0  - startValue;
		mousey = e.getY();
		mousex = e.getX();
		mousepressedx = mousex;
		mousepressedy = mousey;
		if(!canResize){
			if(mousey > 0 && mousey < 2*fontheight)
			{
				for(int i = 0;i<columnheaders.getStoreColumnHeaders().size();i++){
					ColumnHeader columnheader = (ColumnHeader)(columnheaders.getStoreColumnHeaders().elementAt(i));
					columnheaderLeft = columnheaderLeft + columnheader.getWidth();
					if(mousex < columnheaderLeft){
						pressColumnheader = columnheader;
						pressColumnheader.setPressed(true);
						this.columnheader = pressColumnheader;
						isPressed = true;
						repaint();
						break;
					}
				}
			}
		}

		int ListItemsCount = listitems.getStoreListItems().size();
		int n = 0;
		getCurrent = false;
			while ((n < ListItemsCount))
		{
    		if(view == 3 && this.ListRectangle3 != null && (this.ListRectangle3[n] != null) && (this.ListRectangle3[n].contains(mousex+startValue,mousey+startValueY))){
			listitemclick = (ListItem)(listitems.getStoreListItems().elementAt(n));
				if(n == CurrentListIndex){
					if(iflongClick()){
						ListItem currentListItem = (ListItem)(listitems.getStoreListItems().elementAt(CurrentListIndex));
						String listitemString = currentListItem.getText();
					}
    			    clickMListItem(e,listitemclick);
					return;
				}else{
				   CurrentListIndex = n;
				   repaint();
   			       clickMListItem(e,listitemclick);
				   return;
				}
			}else if(view == 2 && this.ListRectangle2 != null && (this.ListRectangle2[n] != null) && (this.ListRectangle2[n].contains(mousex+startValue,mousey+startValueY))){
				listitemclick = (ListItem)(listitems.getStoreListItems().elementAt(n));
				if(n == CurrentListIndex){
    	    		clickMListItem(e,listitemclick); 
					return;
				}else{
				   CurrentListIndex = n;
				   repaint();
                   clickMListItem(e,listitemclick); 
				}
			}
			repaint();
			n++;
		}

      if(CurrentListIndex != -1){
		int m = 0;
		while ((m < ListItemsCount))
		{
			ListItem listitem = (ListItem)(listitems.getStoreListItems().elementAt(m));
			listitem.setSelected(false);
			m++;
		}
		if(listitems.getStoreListItems().size() > 0)
		{
			ListItem currentListItem = (ListItem)(listitems.getStoreListItems().elementAt(CurrentListIndex));
			currentListItem.setSelected(true);
		}
	  }
	}

    private void clickMListItem(MouseEvent e,ListItem clistitem){
    	if(clistitem != null) {
    	    String itemSt = clistitem.getText();
    	    boolean isdir = clistitem.getIsDir();
    	    if(e.getClickCount() == 2){
                filedialog.clickListItems(itemSt,isdir);
            }else{
                if(!clistitem.getIsDir())  filedialog.setText(itemSt);
            }
    	}
    }

   public void mouseReleased(MouseEvent e){
		if(isPressed){
			if(pressColumnheader != null)
			pressColumnheader.setPressed(false);
			repaint();
		}
		isPressed = false;
		canResize = false;
		requestFocus();
 }

 public void adjustmentValueChanged(AdjustmentEvent e){
    	Object obj = e.getSource();
		if(obj.equals(Hscrollbar)){

			if(view != 3)
			{
				float value   = (float)Hscrollbar.getValue();
				if(view == 0 && arrange == 0){
					startValueY = (int)(value+minYView0);
				}else if(view == 1 && arrange == 0){
					startValueY = (int)(value+minYView1);
				}else{
					startValueY = (int)(value);
				}
			}
			else
			{
				int ListItemsCount = listitems.getStoreListItems().size();

				int visible = Hscrollbar.getVisibleAmount();
				int min    = Hscrollbar.getMinimum();

⌨️ 快捷键说明

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