Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
JRuby/SWTSnippets/Snippet3.rb
< JRuby | SWTSnippets
################################################################################ # Copyright (c) 2009 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html # # Contributors: # IBM Corporation - initial API and implementation ################################################################################ require 'java' # # Table example snippet: find a table cell from mouse down (SWT.FULL_SELECTION) # # For a list of SWT example snippets ported to JRuby, see # http://wiki.eclipse.org/JRuby/SWTSnippets # class Snippet3 include_package 'org.eclipse.swt' include_package 'org.eclipse.swt.widgets' include_package 'org.eclipse.swt.graphics' def Snippet3.main display = Display.new shell = Shell.new(display) table = Table.new(shell, SWT::BORDER | SWT::V_SCROLL | SWT::FULL_SELECTION) table.setHeaderVisible(true) table.setLinesVisible(true) rowCount = 64; columnCount = 4 columnCount.times do |i| column = TableColumn.new(table, SWT::NONE) column.setText("Column #{i}") end rowCount.times do |i| item = TableItem.new(table, SWT::NONE) columnCount.times do |j| item.setText(j, "Item #{i}-#{j}") end end columnCount.times do |i| table.getColumn(i).pack() end size = table.computeSize(SWT::DEFAULT, 200) table.setSize(size) table.addListener(SWT::MouseDown) do |event| pt = Point.new(event.x, event.y) item = table.getItem(pt) return unless item columnCount.times do |i| rect = item.getBounds(i) if rect.contains(pt) index = table.indexOf(item) puts "Item #{index}-#{i}" end end end shell.open display.sleep unless display.readAndDispatch until shell.isDisposed display.dispose end end Snippet3.main
Compare with the Java version.