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

📄 tableview.java

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

		// FormData for Folder
		formData = new FormData();
		formData.left = new FormAttachment(0, 0);
		formData.right = new FormAttachment(100, 0);
		formData.bottom = new FormAttachment(100, 0);
		int iSplitAt = configMan.getIntParameter(sPropertiesPrefix + ".SplitAt",
				3000);
		// Was stored at whole
		if (iSplitAt < 100)
			iSplitAt *= 100;

		double pct = iSplitAt / 10000.0;
		if (pct < 0.03)
			pct = 0.03;
		else if (pct > 0.97)
			pct = 0.97;

		// height will be set on first resize call
		sash.setData("PCT", new Double(pct));
		tabFolder.setLayoutData(formData);
		final FormData tabFolderData = formData;

		// FormData for Sash
		formData = new FormData();
		formData.left = new FormAttachment(0, 0);
		formData.right = new FormAttachment(100, 0);
		formData.bottom = new FormAttachment(tabFolder);
		formData.height = 5;
		sash.setLayoutData(formData);

		// FormData for table Composite
		formData = new FormData();
		formData.left = new FormAttachment(0, 0);
		formData.right = new FormAttachment(100, 0);
		formData.top = new FormAttachment(0, 0);
		formData.bottom = new FormAttachment(sash);
		tableComposite.setLayoutData(formData);

		// Listeners to size the folder
		sash.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				final boolean FASTDRAG = true;

				if (FASTDRAG && e.detail == SWT.DRAG)
					return;

				if (tabFolder.getMinimized()) {
					tabFolder.setMinimized(false);
					refreshSelectedSubView();
					configMan.setParameter(sPropertiesPrefix + ".subViews.minimized", false);
				}

				Rectangle area = form.getClientArea();
				tabFolderData.height = area.height - e.y - e.height - iFolderHeightAdj;
				form.layout();

				Double l = new Double((double) tabFolder.getBounds().height
						/ form.getBounds().height);
				sash.setData("PCT", l);
				if (e.detail != SWT.DRAG)
					configMan.setParameter(sPropertiesPrefix + ".SplitAt", (int) (l
							.doubleValue() * 10000));
			}
		});

		final CTabFolder2Adapter folderListener = new CTabFolder2Adapter() {
			public void minimize(CTabFolderEvent event) {
				tabFolder.setMinimized(true);
				tabFolderData.height = iFolderHeightAdj;
				form.layout();
				
				configMan.setParameter(sPropertiesPrefix + ".subViews.minimized", true);
			}

			public void restore(CTabFolderEvent event) {
				tabFolder.setMinimized(false);
				form.notifyListeners(SWT.Resize, null);
				
				refreshSelectedSubView();

				configMan.setParameter(sPropertiesPrefix + ".subViews.minimized", false);
			}
		};
		tabFolder.addCTabFolder2Listener(folderListener);
		
		tabFolder.addMouseListener(new MouseAdapter() {
			public void mouseDown(MouseEvent e) {
				if (tabFolder.getMinimized()) {
					folderListener.restore(null);
					// If the user clicked down on the restore button, and we restore
					// before the CTabFolder does, CTabFolder will minimize us again
					// There's no way that I know of to determine if the mouse is 
					// on that button!
					
					// one of these will tell tabFolder to cancel
					e.button = 0;
					tabFolder.notifyListeners(SWT.MouseExit, null);
				}
			}
		});

		form.addListener(SWT.Resize, new Listener() {
			public void handleEvent(Event e) {
				if (tabFolder.getMinimized())
					return;

				Double l = (Double) sash.getData("PCT");
				if (l != null) {
					tabFolderData.height = (int) (form.getBounds().height * l
							.doubleValue())
							- iFolderHeightAdj;
					form.layout();
				}
			}
		});

		if (coreTabViews != null)
			for (int i = 0; i < coreTabViews.length; i++)
				addTabView(coreTabViews[i]);

		// Call plugin listeners
		if (pluginViews != null) {
			String[] sNames = (String[]) pluginViews.keySet().toArray(new String[0]);
			for (int i = 0; i < sNames.length; i++) {
				UISWTViewEventListener l = (UISWTViewEventListener) pluginViews
						.get(sNames[i]);
				if (l != null) {
					try {
						UISWTViewImpl view = new UISWTViewImpl(sTableID, sNames[i], l);
						addTabView(view);
					} catch (Exception e) {
						// skip, plugin probably specifically asked to not be added
					}
				}
			}
		}
		
		if (configMan.getBooleanParameter(
				sPropertiesPrefix + ".subViews.minimized", false)) {
			tabFolder.setMinimized(true);
			tabFolderData.height = iFolderHeightAdj;
		} else {
			tabFolder.setMinimized(false);
		}

		tabFolder.setSelection(0);

		return form;
	}
  
	
  /** Creates a composite within the specified composite and sets its layout
   * to a default FillLayout().
   *
   * @param composite to create your Composite under
   * @return The newly created composite
   */
  public Composite createMainPanel(Composite composite) {
    Composite panel = new Composite(composite,SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    panel.setLayout(layout);

    return panel;
  }
    
  /** Creates the Table.
   *
   * @return The created Table.
   */
  public Table createTable(Composite panel) {
    table = new Table(panel, iTableStyle);
    table.setLayoutData(new GridData(GridData.FILL_BOTH));

    return table;
  }

  /** Sets up the sorter, columns, and context menu.
   *
   * @param table Table to be initialized
   */
  public void initializeTable(final Table table) {
    initializeColumnDefs();

    iTableStyle = table.getStyle();
    bTableVirtual = (iTableStyle & SWT.VIRTUAL) != 0;

    table.setLinesVisible(Utils.TABLE_GRIDLINE_IS_ALTERNATING_COLOR);
    table.setMenu(menu);
    table.setData("Name", sTableID);
    table.setData("TableView", this);

    // Setup table
    // -----------

    // XXX On linux (an other OSes?), changing the column indicator doesn't 
    //     work until the table is shown.  Since SWT.Show doesn't trigger,
    //     use the first paint trigger.
    if (!Utils.SWT32_TABLEPAINT) {

			table.addPaintListener(new PaintListener() {
				boolean first = true;

				public void paintControl(PaintEvent event) {
					if (first) {
						changeColumnIndicator();
						// This fixes the scrollbar not being long enough on Win2k
						// There may be other methods to get it to refresh right, but
						// layout(true, true) didn't work.
						table.setRedraw(false);
						table.setRedraw(true);
						first = false;
					}
					if (event.width == 0 || event.height == 0)
						return;
					doPaint(event.gc);
					visibleRowsChanged();
				}
			});
		}

    if (Utils.SWT32_TABLEPAINT) {
  		// SWT 3.2 only.  Code Ok -- Only called in SWT 3.2 mode
			table.addListener(SWT.PaintItem, new Listener() {
				public void handleEvent(Event event) {
					paintItem(event);
				}
			});
			table.addListener(SWT.EraseItem, new Listener() {
				public void handleEvent(Event event) {
				}
			});
		}

    // Deselect rows if user clicks on a black spot (a spot with no row)
    table.addMouseListener(new MouseAdapter() {
    	private TableCellMouseEvent createMouseEvent(TableCellCore cell,
					MouseEvent e, int type) {
				TableCellMouseEvent event = new TableCellMouseEvent();
				event.cell = cell;
				event.eventType = type;
				event.button = e.button;
				// TODO: Change to not use SWT masks
				event.keyboardState = e.stateMask;
				event.skipCoreFunctionality = false;
				Rectangle r = cell.getBounds();
				event.x = e.x - r.x + VerticalAligner.getTableAdjustHorizontallyBy(table);
				event.y = e.y - r.y + VerticalAligner.getTableAdjustVerticalBy(table);
				return event;
    	}
    	
    	public void mouseDoubleClick(MouseEvent e) {
    		TableColumnCore tc = getTableColumnByOffset(e.x);
				TableCellCore cell = getTableCell(e.x, e.y);
				if (cell != null && tc != null) {
					TableCellMouseEvent event = createMouseEvent(cell, e,
							TableCellMouseEvent.EVENT_MOUSEDOUBLECLICK);
					tc.invokeCellMouseListeners(event);
					cell.invokeMouseListeners(event);
					if (event.skipCoreFunctionality)
						lCancelSelectionTriggeredOn = System.currentTimeMillis();
				}
    	}

    	public void mouseUp(MouseEvent e) {
    		TableColumnCore tc = getTableColumnByOffset(e.x);
				TableCellCore cell = getTableCell(e.x, e.y);
				if (cell != null && tc != null) {
					TableCellMouseEvent event = createMouseEvent(cell, e,
							TableCellMouseEvent.EVENT_MOUSEUP);
					tc.invokeCellMouseListeners(event);
					cell.invokeMouseListeners(event);
					if (event.skipCoreFunctionality)
						lCancelSelectionTriggeredOn = System.currentTimeMillis();
				}
    	}

      public void mouseDown(MouseEvent e) {
    		TableColumnCore tc = getTableColumnByOffset(e.x);
				TableCellCore cell = getTableCell(e.x, e.y);
				if (cell != null && tc != null) {
	      	if (e.button == 2 && e.stateMask == SWT.CONTROL) {
	      		((TableCellImpl)cell).bDebug = !((TableCellImpl)cell).bDebug;
	      		System.out.println("Set debug for " + cell + " to "
								+ ((TableCellImpl) cell).bDebug);
	      	}
					TableCellMouseEvent event = createMouseEvent(cell, e,
							TableCellMouseEvent.EVENT_MOUSEDOWN);
					tc.invokeCellMouseListeners(event);
					cell.invokeMouseListeners(event);
					if (event.skipCoreFunctionality)
						lCancelSelectionTriggeredOn = System.currentTimeMillis();
				}

        iMouseX = e.x;
        try {
          if (table.getItemCount() <= 0)
            return;

          // skip if outside client area (ie. scrollbars)
          Rectangle rTableArea = table.getClientArea();
          //System.out.println("Mouse="+iMouseX+"x"+e.y+";TableArea="+rTableArea);
          Point pMousePosition = new Point(e.x, e.y);
          if (rTableArea.contains(pMousePosition)) {
          	int[] columnOrder = table.getColumnOrder();
          	if (columnOrder.length == 0) {
          		return;
          	}
          	TableItem ti = table.getItem(table.getItemCount() - 1);
            Rectangle cellBounds = ti.getBounds(columnOrder[columnOrder.length - 1]);
            // OSX returns 0 size if the cell is not on screen (sometimes? all the time?)
            if (cellBounds.width <= 0 || cellBounds.height <= 0)
              return;
            //System.out.println("cellbounds="+cellBounds);
            if (e.x > cellBounds.x + cellBounds.width ||
                e.y > cellBounds.y + cellBounds.height) {
              table.deselectAll();
            }
/*        // This doesn't work because of OS inconsistencies when table is scrolled
          // Re-enable once SWT fixes the problem
          // Bug 103934: Table.getItem(Point) uses incorrect calculation on Motif
          //             Fixed 20050718 SWT 3.2M1 (3201) & SWT 3.1.1 (3139)
          // TODO: Get Build IDs and use this code (if it works)
            TableItem ti = table.getItem(pMousePosition);
            if (ti == null)
              table.deselectAll();
*/
          }
        } catch (Exception ex) {
          System.out.println("MouseDownError");
          Debug.printStackTrace( ex );
        }
      }
    });
    
    table.addMouseMoveListener(new MouseMoveListener() {
    	TableCellCore lastCell = null;
    	int lastCursorID = -1;
    	
      public void mouseMove(MouseEvent e) {
        // XXX this may not be needed if all platforms process mouseDown
        //     before the menu
      	try {
          iMouseX = e.x;
          
  				TableCellCore cell = getTableCell(e.x, e.y);
  				int iCursorID = -1;
  				if (cell==null){
  					lastCell = null;					
  				}else if ( cell != lastCell) {			
  					iCursorID = cell.getCursorID();
  					lastCell = cell;
  				}
  
  				if (iCursorID != lastCursorID) {
  					lastCursorID = iCursorID;
  
  					if (iCursorID >= 0) {
  						table.setCursor(table.getDisplay().getSystemCursor(iCursorID));
  					} else {
  						table.setCursor(null);
  					}
  				}
      	} catch (Exception ex) {
      		Debug.out(ex);
      	}
      }
    });

    table.addSelectionListener(new SelectionListener() {
      public void widgetSelected(SelectionEvent event) {
      	if (tabViews == null || tabViews.size() == 0)
      		return;

      	// Set Data Object for all tabs.  Tabs of PluginView are sent the plugin
      	// Peer object, while Tabs of IView are sent the core PEPeer object.

      	// TODO: Send all datasources
      	Object[] dataSourcesCore = getSelectedDataSources(true);
      	Object[] dataSourcesPlugin = null;

      	for (int i = 0; i < tabViews.size(); i++) {
      		IView view = (IView) tabViews.get(i);
      		if (view != null) {
      			if (view instanceof UISWTViewImpl) {
      				if (dataSourcesPlugin == null)
      					dataSourcesPlugin = getSelectedDataSources(false);

      				((UISWTViewImpl) view)
									.dataSourceChanged(dataSourcesPlugin.length == 0 ? null
											: dataSourcesPlugin);
      			} else {
      				view.dataSourceChanged(dataSourcesCore.length == 0 ? null

⌨️ 快捷键说明

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