コード例 #1
0
 TabItem findItem(String value, TabItem[] items) {
   for (int i = 0; i < items.length; i++) {
     TabItem item = items[i];
     if (item.getText().equals(value)) return item;
   }
   return null;
 }
コード例 #2
0
  /**
   * Creates an instance of a ControlExample embedded inside the supplied parent Composite.
   *
   * @param parent the container of the example
   */
  public ControlExample(Composite parent) {
    initResources();
    tabFolder = new TabFolder(parent, SWT.NONE);
    tabs = createTabs();
    for (Tab tab : tabs) {
      TabItem item = new TabItem(tabFolder, SWT.NONE);
      item.setText(tab.getTabText());
      item.setControl(tab.createTabFolderPage(tabFolder));
      item.setData(tab);
    }

    /* Workaround: if the tab folder is wider than the screen,
     * Mac platforms clip instead of somehow scrolling the tab items.
     * We try to recover some width by using shorter tab names. */
    Point size = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = parent.getMonitor().getClientArea();
    boolean isMac = SWT.getPlatform().equals("cocoa");
    if (size.x > monitorArea.width && isMac) {
      TabItem[] tabItems = tabFolder.getItems();
      for (int i = 0; i < tabItems.length; i++) {
        tabItems[i].setText(tabs[i].getShortTabText());
      }
    }
    startup = false;
  }
コード例 #3
0
 void removeControl(Control control) {
   super.removeControl(control);
   int count = getItemCount();
   for (int i = 0; i < count; i++) {
     TabItem item = items[i];
     if (item.control == control) item.setControl(null);
   }
 }
コード例 #4
0
 public static void labelTab() {
   TabItem tab = new TabItem(folder, SWT.CLOSE);
   tab.setText("A Label"); // Text on the tab
   tab.setToolTipText("A simple label");
   Label label = new Label(folder, SWT.CENTER);
   label.setText("Label text");
   tab.setControl(label);
 }
コード例 #5
0
 public static void scribbleTab() {
   TabItem tab = new TabItem(folder, SWT.CLOSE);
   tab.setText("Scribble");
   tab.setToolTipText("Simple graphics: drawing");
   final Canvas canvas = new Canvas(folder, SWT.NONE);
   ScribbleMouseListener sml = new ScribbleMouseListener();
   canvas.addMouseListener(sml);
   canvas.addMouseMoveListener(sml);
   tab.setControl(canvas);
 }
コード例 #6
0
 void releaseChildren(boolean destroy) {
   if (items != null) {
     for (int i = 0; i < items.length; i++) {
       TabItem item = items[i];
       if (item != null && !item.isDisposed()) {
         item.release(false);
       }
     }
     items = null;
   }
   super.releaseChildren(destroy);
 }
コード例 #7
0
 void reskinChildren(int flags) {
   if (items != null) {
     long /*int*/ list = OS.gtk_container_get_children(handle);
     if (list != 0) {
       int count = OS.g_list_length(list);
       OS.g_list_free(list);
       for (int i = 0; i < count; i++) {
         TabItem item = items[i];
         if (item != null) item.reskin(flags);
       }
     }
   }
   super.reskinChildren(flags);
 }
コード例 #8
0
 /**
  * Returns the tab item at the given point in the receiver or null if no such item exists. The
  * point is in the coordinate system of the receiver.
  *
  * @param point the point used to locate the item
  * @return the tab item at the given point, or null if the point is not in a tab item
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the point is null
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @since 3.4
  */
 public TabItem getItem(Point point) {
   checkWidget();
   if (point == null) error(SWT.ERROR_NULL_ARGUMENT);
   long /*int*/ list = OS.gtk_container_get_children(handle);
   if (list == 0) return null;
   int itemCount = OS.g_list_length(list);
   OS.g_list_free(list);
   for (int i = 0; i < itemCount; i++) {
     TabItem item = items[i];
     Rectangle rect = item.getBounds();
     if (rect.contains(point)) return item;
   }
   return null;
 }
コード例 #9
0
 public static void sliderTab() {
   TabItem tab = new TabItem(folder, SWT.CLOSE);
   tab.setText("Sliders and Progress bars");
   tab.setToolTipText("Tied Slider to ProgressBar");
   Composite composite = new Composite(folder, SWT.NONE);
   composite.setLayout(new GridLayout(2, true));
   final Slider slider = new Slider(composite, SWT.HORIZONTAL);
   final ProgressBar progress = new ProgressBar(composite, SWT.HORIZONTAL);
   slider.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent event) {
           progress.setSelection(slider.getSelection());
         }
       });
   tab.setControl(composite);
 }
コード例 #10
0
 public static void buttonTab() {
   TabItem tab = new TabItem(folder, SWT.CLOSE);
   tab.setText("Buttons");
   tab.setToolTipText("Different kinds of Buttons");
   Composite composite = new Composite(folder, SWT.NONE);
   composite.setLayout(new GridLayout(4, true));
   for (int dir : new int[] {SWT.UP, SWT.RIGHT, SWT.LEFT, SWT.DOWN}) {
     Button b = new Button(composite, SWT.ARROW | dir);
     b.addListener(SWT.MouseDown, listener);
   }
   newButton(composite, SWT.CHECK, "Check button");
   newButton(composite, SWT.PUSH, "Push button");
   newButton(composite, SWT.RADIO, "Radio button");
   newButton(composite, SWT.TOGGLE, "Toggle button");
   newButton(composite, SWT.FLAT, "Flat button");
   tab.setControl(composite);
 }
コード例 #11
0
 public static void directoryDialogTab() {
   TabItem tab = new TabItem(folder, SWT.CLOSE);
   tab.setText("Directory Dialog");
   tab.setToolTipText("Select a directory");
   final Button b = new Button(folder, SWT.PUSH);
   b.setText("Select a Directory");
   b.addListener(
       SWT.MouseDown,
       new Listener() {
         public void handleEvent(Event e) {
           DirectoryDialog dd = new DirectoryDialog(shell);
           String path = dd.open();
           if (path != null) b.setText(path);
         }
       });
   tab.setControl(b);
 }
コード例 #12
0
 public static void browserTab() {
   TabItem tab = new TabItem(folder, SWT.CLOSE);
   tab.setText("A Browser");
   tab.setToolTipText("A Web browser");
   Browser browser = null;
   try {
     browser = new Browser(folder, SWT.NONE);
   } catch (SWTError e) {
     Label label = new Label(folder, SWT.BORDER);
     label.setText("Could not initialize browser");
     tab.setControl(label);
   }
   if (browser != null) {
     browser.setUrl("http://www.mindview.net");
     tab.setControl(browser);
   }
 }
コード例 #13
0
 long /*int*/ gtk_switch_page(long /*int*/ widget, long /*int*/ page, long /*int*/ page_num) {
   int index = OS.gtk_notebook_get_current_page(handle);
   if (index != -1) {
     Control control = items[index].getControl();
     if (control != null && !control.isDisposed()) {
       control.setVisible(false);
     }
   }
   TabItem item = items[(int) /*64*/ page_num];
   Control control = item.getControl();
   if (control != null && !control.isDisposed()) {
     control.setBounds(getClientArea());
     control.setVisible(true);
   }
   Event event = new Event();
   event.item = item;
   sendSelectionEvent(SWT.Selection, event, false);
   return 0;
 }
コード例 #14
0
 void createItem(TabItem item, int index) {
   long /*int*/ list = OS.gtk_container_get_children(handle);
   int itemCount = 0;
   if (list != 0) {
     itemCount = OS.g_list_length(list);
     OS.g_list_free(list);
   }
   if (!(0 <= index && index <= itemCount)) error(SWT.ERROR_INVALID_RANGE);
   if (itemCount == items.length) {
     TabItem[] newItems = new TabItem[items.length + 4];
     System.arraycopy(items, 0, newItems, 0, items.length);
     items = newItems;
   }
   long /*int*/ boxHandle = gtk_box_new(OS.GTK_ORIENTATION_HORIZONTAL, false, 0);
   if (boxHandle == 0) error(SWT.ERROR_NO_HANDLES);
   long /*int*/ labelHandle = OS.gtk_label_new_with_mnemonic(null);
   if (labelHandle == 0) error(SWT.ERROR_NO_HANDLES);
   long /*int*/ imageHandle = OS.gtk_image_new();
   if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
   OS.gtk_container_add(boxHandle, imageHandle);
   OS.gtk_container_add(boxHandle, labelHandle);
   long /*int*/ pageHandle = OS.g_object_new(display.gtk_fixed_get_type(), 0);
   if (pageHandle == 0) error(SWT.ERROR_NO_HANDLES);
   if (OS.GTK3) {
     OS.gtk_widget_override_background_color(pageHandle, OS.GTK_STATE_FLAG_NORMAL, new GdkRGBA());
     long /*int*/ region = OS.gdk_region_new();
     OS.gtk_widget_input_shape_combine_region(pageHandle, region);
     OS.gdk_region_destroy(region);
   }
   OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   OS.gtk_notebook_insert_page(handle, pageHandle, boxHandle, index);
   OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   OS.gtk_widget_show(boxHandle);
   OS.gtk_widget_show(labelHandle);
   OS.gtk_widget_show(pageHandle);
   item.state |= HANDLE;
   item.handle = boxHandle;
   item.labelHandle = labelHandle;
   item.imageHandle = imageHandle;
   item.pageHandle = pageHandle;
   System.arraycopy(items, index, items, index + 1, itemCount++ - index);
   items[index] = item;
   if ((state & FOREGROUND) != 0) {
     item.setForegroundColor(getForegroundColor());
   }
   if ((state & FONT) != 0) {
     item.setFontDescription(getFontDescription());
   }
   if (itemCount == 1) {
     OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
     OS.gtk_notebook_set_current_page(handle, 0);
     OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
     Event event = new Event();
     event.item = items[0];
     sendSelectionEvent(SWT.Selection, event, false);
     // the widget could be destroyed at this point
   }
 }
コード例 #15
0
  /** Creates the "Example" widgets. */
  void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (topButton.getSelection()) style |= SWT.TOP;
    if (bottomButton.getSelection()) style |= SWT.BOTTOM;
    if (borderButton.getSelection()) style |= SWT.BORDER;

    /* Create the example widgets */
    tabFolder1 = new TabFolder(tabFolderGroup, style);
    for (int i = 0; i < TabItems1.length; i++) {
      TabItem item = new TabItem(tabFolder1, SWT.NONE);
      item.setText(TabItems1[i]);
      item.setToolTipText(ControlExample.getResourceString("Tooltip", new String[] {TabItems1[i]}));
      Text content = new Text(tabFolder1, SWT.WRAP | SWT.MULTI);
      content.setText(ControlExample.getResourceString("TabItem_content") + ": " + i);
      item.setControl(content);
    }
  }