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

📄 tableview.java

📁 这是一个基于java编写的torrent的P2P源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
									: dataSourcesCore);
      			}
      		}
      	}
      }

			public void widgetDefaultSelected(SelectionEvent e) {
				if (lCancelSelectionTriggeredOn > 0
						&& System.currentTimeMillis() - lCancelSelectionTriggeredOn < 200) {
					e.doit = false;
					lCancelSelectionTriggeredOn = -1;
				} else {
					runDefaultAction();
				}
			}
    });
    
    // we are sent a SWT.Settings event when the language changes and
    // when System fonts/colors change.  In both cases, invalidate
    if (SWT.getVersion() > 3200) {
	    table.addListener(SWT.Settings, new Listener() {
	      public void handleEvent(Event e) {
	      	tableInvalidate();
	      }
	    });
    }

    // XXX Disabled.  We handle unset rows ourselves via table paints which
    //     are more reliable.
    if (bTableVirtual || false)
	    table.addListener(SWT.SetData, new Listener() {
	      public void handleEvent(Event e) {
					final TableItem item = (TableItem) e.item;
		  		// This is catch is temporary for SWT 3212, because there are cases where
		  		// it says it isn't disposed, when it really almost is
		  		try {
		  			if (item.getData("SD") != null) {
		  				return;
		  			}
						item.setData("SD", "1");
		  		} catch (NullPointerException badSWT) {
		  			return;
		  		}
	
					int tableIndex = table.indexOf(item);
					if (tableIndex < 0) {
						System.out.println("XXX TI < 0!!");
						return;
					}
					
					TableRowCore row = (TableRowCore) item.getData("TableRow");
					if (row == null || row.getIndex() != tableIndex) {
						//System.out.println("SetData " + tableIndex + ": Sort..");
						fillRowGaps(false);
	
						row = (TableRowCore) item.getData("TableRow");
						if (row == null || row.getIndex() != tableIndex) {
							// row's been deleted.  tableitem probably about to be remove
							// (hopefully!)
							if (DEBUGADDREMOVE)
								Debug.outStackTrace();
							return;
						}
					} else {
						//System.out.println("SetData " + tableIndex + ": invalidate");
						row.invalidate();
					}
					
					// User made the row visible, they want satisfaction now!
					if (!row.setIconSize(ptIconSize)) {
						row.refresh(true, true);
					}

					if (!Utils.TABLE_GRIDLINE_IS_ALTERNATING_COLOR) {
						Utils.alternateRowBackground(item);
						// Bug, background color doesn't fully draw in SetData
						Rectangle r = item.getBounds(0);
						table.redraw(0, r.y, table.getClientArea().width, r.height, false);
					}
				}
	    });

    // bypasses disappearing graphic glitch on Mac OS X
/* Temporarily Disabled to see if we need it anymore
    if(Constants.isOSX) {
        table.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected( SelectionEvent event) {
                GroupTableRowRunner refresher = new GroupTableRowRunner() {
                  public void run(TableRowCore row) {
                      row.setValid(false);
                      row.refresh(true);
                  }
                };

                TableItem[] sel = table.getSelection();

                ArrayList toRefresh = new ArrayList(sel.length);

                if(oldSelectedItems != null) {
                    runForTableItems(oldSelectedItems, refresher);
                    for (int i = 0; i < sel.length; i++) {
                        if(!oldSelectedItems.contains(sel[i]))
                            toRefresh.add(sel[i]);
                    }
                }
                else {
                    for (int i = 0; i < sel.length; i++) {
                        toRefresh.add(sel[i]);
                    }
                }

                runForTableItems(toRefresh, refresher);

                oldSelectedItems = toRefresh;
            }
        });
    }
*/

    new TableTooltips(table);
  	
  	table.addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent event) {
				if (event.keyCode == SWT.F5) { 
					if ((event.stateMask & SWT.SHIFT) > 0) {
      			runForSelectedRows(new GroupTableRowRunner() {
							public void run(TableRowCore row) {
								row.invalidate();
								row.refresh(true);
							}
						});
					} else {
						sortColumn(true);
					}
					event.doit = false;
				}
			}
  	});
  	
  	ScrollBar bar = table.getVerticalBar();
  	if (bar != null) {
  		bar.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					// Bug: Scroll is slow when table is not focus
					if (!table.isFocusControl()) {
						table.setFocus();
					}
				}
  		});
		}
  	
    table.setHeaderVisible(true);

    initializeTableColumns(table);
  }
  
  /**
	 * @param event
	 */
	protected void paintItem(Event event) {
		TableItem item = (TableItem) event.item;
		if (item == null || item.isDisposed()) {
			return;
		}

		TableRowCore row;
		try {
			row = (TableRowCore) item.getData("TableRow");
		} catch (NullPointerException e) {
			return;
		}

		// SWT 3.2 only.  Code Ok -- Only called in SWT 3.2 mode
		Rectangle cellBounds = item.getBounds(event.index);
		
		cellBounds.x += 3;
		cellBounds.width -= 6;
		
		try {
			// SWT 3.2 only.  Code Ok -- Only called in SWT 3.2 mode
			int iColumnNo = event.index;
			
			if (item.getImage(iColumnNo) != null) {
				cellBounds.x += 18;
				cellBounds.width -= 18;
			}
			
			if (cellBounds.width <= 0 || cellBounds.height <= 0) {
				return;
			}

			if (bSkipFirstColumn) {
				if (iColumnNo == 0) {
					return;
				}
				iColumnNo--;
			}
			
			if (iColumnNo >= columnsOrdered.length) {
				System.out.println(iColumnNo + " >= " + columnsOrdered.length);
				return;
			}
			
			TableCellCore cell = row.getTableCellCore(columnsOrdered[iColumnNo].getName());
			
			if (!cell.isUpToDate()) {
				//System.out.println("R " + table.indexOf(item));
				cell.refresh(true, true);
				return;
			}
			
			//System.out.println("PS " + table.indexOf(item) + ";" + cellBounds);
			GCStringPrinter.printString(event.gc, cell.getText(),
					cellBounds, true, true, columnsOrdered[iColumnNo].getSWTAlign());

			if (cell.needsPainting()) {
				cell.doPaint(event.gc);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void runDefaultAction() {
  	
  }

  protected void initializeTableColumns(final Table table) {
  	TableColumn[] oldColumns = table.getColumns();

    if (SWT.getVersion() >= 3100)
    	for (int i = 0; i < oldColumns.length; i++)
    		oldColumns[i].removeListener(SWT.Move, columnMoveListener);

  	for (int i = oldColumns.length - 1; i >= 0 ; i--)
  		oldColumns[i].dispose();
  	
    // Pre 3.0RC1 SWT on OSX doesn't call this!! :(
    ControlListener resizeListener = new ControlAdapter() {
      // Bug: getClientArea() eventually calls back to controlResized,
    	//      creating a loop until a stack overflow
      private boolean bInFunction = false;

      public void controlResized(ControlEvent e) {
        TableColumn column = (TableColumn) e.widget;
        if (column == null || column.isDisposed() || bInFunction)
          return;
        
        try {
	        bInFunction = true;
	
	        TableColumnCore tc = (TableColumnCore)column.getData("TableColumnCore");
	        if (tc != null)
	          tc.setWidth(column.getWidth());
	
	        int columnNumber = table.indexOf(column);
	        locationChanged(columnNumber);
        } finally {
        	bInFunction = false;
        }
      }
    };

    // Add 1 to position because we make a non resizable 0-sized 1st column
    // to fix the 1st column gap problem (Eclipse Bug 43910)

    // SWT does not set 0 column width as expected in OS X; see bug 43910
    // this will be removed when a SWT-provided solution is available to satisfy all platforms with identation issue
    bSkipFirstColumn = bSkipFirstColumn && !Constants.isOSX;

    if (bSkipFirstColumn) {
      TableColumn tc = new TableColumn(table, SWT.NULL);
      tc.setWidth(0);
      tc.setResizable(false);
    }

    TableColumnCore[] tmpColumnsOrdered = new TableColumnCore[tableColumns.length];
    //Create all columns
    for (int i = 0; i < tableColumns.length; i++) {
      int position = tableColumns[i].getPosition();
      if (position != -1) {
        new TableColumn(table, SWT.NULL);
        tmpColumnsOrdered[position] = tableColumns[i];
      }
    }
    int numSWTColumns = table.getColumnCount();
    int iNewLength = numSWTColumns - (bSkipFirstColumn ? 1 : 0);
    columnsOrdered = new TableColumnCore[iNewLength];
    System.arraycopy(tmpColumnsOrdered, 0, columnsOrdered, 0, iNewLength);
    
    ColumnSelectionListener columnSelectionListener = new ColumnSelectionListener();
    
    //Assign length and titles
    //We can only do it after ALL columns are created, as position (order)
    //may not be in the natural order (if the user re-order the columns).
    for (int i = 0; i < tableColumns.length; i++) {
      int position = tableColumns[i].getPosition();
      if (position == -1)
        continue;

      String sName = tableColumns[i].getName();
      // +1 for Eclipse Bug 43910 (see above)
      // user has reported a problem here with index-out-of-bounds - not sure why
      // but putting in a preventative check so that hopefully the view still opens
      // so they can fix it
      
      int	adjusted_position = position + (bSkipFirstColumn ? 1 : 0);
      
      if (adjusted_position >= numSWTColumns) {
				Debug.out("Incorrect table column setup, skipping column '" + sName
						+ "', position=" + adjusted_position + ";numCols=" + numSWTColumns);
				continue;
			}
      
      TableColumn column = table.getColumn(adjusted_position);
      try {
      	column.setMoveable(true);
      } catch (NoSuchMethodError e) {
      	// Ignore < SWT 3.1
      }
      column.setAlignment(tableColumns[i].getSWTAlign());
      Messages.setLanguageText(column, tableColumns[i].getTitleLanguageKey());
      column.setWidth(tableColumns[i].getWidth());
      column.setData("TableColumnCore", tableColumns[i]);
      column.setData("configName", "Table." + sTableID + "." + sName);
      column.setData("Name", sName);
      
      column.addControlListener(resizeListener);
      // At the time of writing this SWT (3.0RC1) on OSX doesn't call the 
      // selection listener for tables
      column.addListener(SWT.Selection, columnSelectionListener);
    }

    // Initialize the sorter after the columns have been added
		String sSortColumn = configMan.getStringParameter(sTableID
				+ ".sortColumn", sDefaultSortOn);
		int iSortDirection = configMan.getIntParameter(CFG_SORTDIRECTION);
		boolean bSortAscending = configMan.getBooleanParameter(sTableID
				+ ".sortAsc", iSortDirection == 1 ? false : true);

    TableColumnManager tcManager = TableColumnManager.getInstance();
    TableColumnCore tc = tcManager.getTableColumnCore(sTableID, sSortColumn);
    if (tc == null) {
    	tc = tableColumns[0];
    }
		sortColumn = tc;
		sortColumn.setSortAscending(bSortAscending);
		changeColumnIndicator();
		
    // Add move listener at the very end, so we don't get a bazillion useless 
    // move triggers
    if (SWT.getVersion() >= 3100) {
			Listener columnResizeListener = (!COLUMN_CLICK_DELAY) ? null
					: new Listener() {
						public void handleEvent(Event event) {
							lLastColumnResizeOn = System.currentTimeMillis();
						}
					};
    	
	    for (int i = 0; i < tableColumns.length; i++) {
	      int position = tableColumns[i].getPosition();
	      if (position == -1)
	        continue;
	
	      int	adjusted_position = position + (bSkipFirstColumn ? 1 : 0);
	      if (adjusted_position >= numSWTColumns)
	      	continue;
	      
	      TableColumn column = table.getColumn(adjusted_position);
	      column.addListener(SWT.Move, columnMoveListener);
	    	if (COLUMN_CLICK_DELAY)
	    		column.addListener(SWT.Resize, columnResizeListener);
	    }
    }
  }

  /** Creates the Context Menu.
   *
   * @return a new Menu object
   */
  public Menu createMenu() {
    final Menu menu = new Menu(tableComposite.getShell(), SWT.POP_UP);
    menu.addMenuListener(new MenuListener() {
    	boolean bShown = false;
    	
			public void menuHidden(MenuEvent e) {
				bShown = false;

				if (Constants.isOSX)
					return;

				// Must dispose in an asyncExec, otherwise SWT.Selection doesn't
				// get fired (async workaround provided by Eclipse Bug #87678)
				e.widget.getDisplay().asyncExec(new AERunnable() {
					public void runSupport() {
						if (bShown || menu.isDisposed())

⌨️ 快捷键说明

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