All pastes #485979 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-05-13 18:03 UTC
rendered paste body
/*   **********************************************************************  **
 **   Copyright notice                                                       **
 **                                                                          **
 **   (c) 2005-2006 RSSOwl Development Team                                  **
 **   http://www.rssowl.org/                                                 **
 **                                                                          **
 **   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.rssowl.org/legal/epl-v10.html                               **
 **                                                                          **
 **   A copy is found in the file epl-v10.html and important notices to the  **
 **   license from the team is found in the textfile LICENSE.txt distributed **
 **   in this package.                                                       **
 **                                                                          **
 **   This copyright notice MUST APPEAR in all copies of the file!           **
 **                                                                          **
 **   Contributors:                                                          **
 **     RSSOwl Development Team - initial API and implementation             **
 **                                                                          **
 **  **********************************************************************  */

package org.eclipse.swt.snippets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Scrollable;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

public class Main {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Table t = new Table(shell, SWT.FULL_SELECTION);
    t.setHeaderVisible(true);

    TableItem item1 = new TableItem(t, SWT.NONE);
    item1.setText("Hello World");

    TableItem item2 = new TableItem(t, SWT.NONE);
    item2.setText("Hello World");

    t.setForeground(display.getSystemColor(SWT.COLOR_RED));

    t.addListener(SWT.EraseItem, new Listener() {
      public void handleEvent(Event event) {
        Scrollable scrollable = (Scrollable) event.widget;
        GC gc = event.gc;
        if ((event.detail & SWT.SELECTED) != 0) {
          Rectangle clArea = scrollable.getClientArea();
          Rectangle itemRect = event.getBounds();

          /* Draw Rectangle */
          Color oldBackground = gc.getBackground();
          gc.setBackground(scrollable.getDisplay().getSystemColor(SWT.COLOR_RED));
          gc.fillRectangle(0, itemRect.y, clArea.width, itemRect.height);
          gc.setBackground(oldBackground);
          gc.setForeground(scrollable.getDisplay().getSystemColor(SWT.COLOR_WHITE));

          /* Mark as Selected being handled */
          event.detail &= ~SWT.SELECTED;
        }
      }
    });

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
  }
}