下面列出了org.eclipse.swt.widgets.TableItem#getBounds ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static int getClickedItemColumnIndex(Table table, TableItem item,
Point point){
int column = -1;
if (item != null) {
// Determine which column was selected
for (int i = 0, n = table.getColumnCount(); i < n; i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(point)) {
// This is the selected column
column = i;
break;
}
}
}
return column;
}
public static int getClickedItemColumnIndex(Table table, TableItem item,
Point point) {
int column = -1;
if (item != null) {
// Determine which column was selected
for (int i = 0, n = table.getColumnCount(); i < n; i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(point)) {
// This is the selected column
column = i;
break;
}
}
}
return column;
}
/**
* Returns the item at the given location.
*
* @param x
* @param y
* @return
*/
private int getItemColumnAt(int x, int y) {
Point pt = new Point(x, y);
int index = table.getTopIndex();
while (index < table.getItemCount()) {
final TableItem item = table.getItem(index);
for (int i = 0; i < table.getColumns().length; i++) {
final Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
return i;
}
}
index++;
}
return -1;
}
/**
* Returns the item at the given location.
*
* @param x
* @param y
* @return
*/
private int getItemRowAt(int x, int y) {
Point pt = new Point(x, y);
int index = table.getTopIndex();
while (index < table.getItemCount()) {
final TableItem item = table.getItem(index);
for (int i = 0; i < table.getColumns().length; i++) {
final Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
return index;
}
}
index++;
}
return -1;
}
/**
* Returns the item at the given location.
*
* @param x
* @param y
* @return
*/
private TableItem getItemAt(int x, int y) {
Point pt = new Point(x, y);
int index = table.getTopIndex();
while (index < table.getItemCount()) {
final TableItem item = table.getItem(index);
for (int i = 0; i < table.getColumnCount(); i++) {
final Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) { return item; }
}
index++;
}
return null;
}
private void setDetailCompositeContent(FontData fontData, Event event)
{
TableItem item = (TableItem) event.item;
ICompletionProposal curProposal = (ICompletionProposal) item.getData();
if (curProposal == selectedProposal)
{
return;
}
selectedProposal = curProposal;
descriptionPanel.execute("setDocFont(\"" + fontData.getName() + "\",\"" + fontData.getHeight() + "\")");
GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
int itemHeight = item.getBounds().height;
int rightHeight = itemHeight * PROPOSAL_ITEMS_VISIBLE;
gd.heightHint = rightHeight;
detailProposalComposite.setLayoutData(gd);
detailProposalComposite.setBounds(fProposalTable.getSize().x + 2, 1, 320, rightHeight);
Rectangle rect = detailProposalComposite.getBounds();
descriptionPanel.setBounds(0, 0, rect.width, rightHeight - 1);
if (curProposal instanceof ICommonCompletionProposal)
{
ICommonCompletionProposal proposal = (ICommonCompletionProposal)curProposal;
String location = "";
String title = proposal.getDisplayString();
title = title.replace("<", "<");
title = title.replace(">", ">");
descriptionPanel.execute("setTitle(\"" + title + "\")");
String info = proposal.getAdditionalProposalInfo();
descriptionPanel.execute("cleanAddition()");
if(info == null) {
info = "";
}
info = info.replace("\"", "'");
info = info.replaceAll("(\n|\r)\\s*", "<br/>");
descriptionPanel.execute("setAddition(\"" + info + "\")");
descriptionPanel.execute("clearLocation()");
descriptionPanel.execute("setLocation(\"" + location + "\")");
}
fProposalShell.pack();
}