コード例 #1
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;
  }
コード例 #2
0
ファイル: HoverHelp.java プロジェクト: mbigigns/SWTGuitar
 public void createPartControl(org.eclipse.swt.widgets.Composite frame) {
   final org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHandler tooltip =
       new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHandler(frame.getShell());
   org.eclipse.swt.layout.GridLayout layout = new org.eclipse.swt.layout.GridLayout();
   layout.numColumns = 3;
   frame.setLayout(layout);
   java.lang.String platform = SWT.getPlatform();
   java.lang.String helpKey = "F1";
   if (platform.equals("gtk")) {
     helpKey = "Ctrl+F1";
   }
   if (platform.equals("carbon") || platform.equals("cocoa")) {
     helpKey = "Help";
   }
   org.eclipse.swt.widgets.ToolBar bar = new org.eclipse.swt.widgets.ToolBar(frame, SWT.BORDER);
   for (int i = 0; i < 5; i++) {
     org.eclipse.swt.widgets.ToolItem item = new org.eclipse.swt.widgets.ToolItem(bar, SWT.PUSH);
     item.setText(
         getResourceString("ToolItem.text", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData(
         "TIP_TEXT",
         getResourceString("ToolItem.tooltip", new java.lang.Object[] {item.getText(), helpKey}));
     item.setData(
         "TIP_HELPTEXTHANDLER",
         new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler() {
           public java.lang.String getHelpText(org.eclipse.swt.widgets.Widget widget) {
             org.eclipse.swt.widgets.Item item = (org.eclipse.swt.widgets.Item) widget;
             return getResourceString("ToolItem.help", new java.lang.Object[] {item.getText()});
           }
         });
   }
   org.eclipse.swt.layout.GridData gridData = new org.eclipse.swt.layout.GridData();
   gridData.horizontalSpan = 3;
   bar.setLayoutData(gridData);
   tooltip.activateHoverHelp(bar);
   org.eclipse.swt.widgets.Table table = new org.eclipse.swt.widgets.Table(frame, SWT.BORDER);
   for (int i = 0; i < 4; i++) {
     org.eclipse.swt.widgets.TableItem item =
         new org.eclipse.swt.widgets.TableItem(table, SWT.PUSH);
     item.setText(getResourceString("Item", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData("TIP_IMAGE", images[hhiInformation]);
     item.setText(
         getResourceString("TableItem.text", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData(
         "TIP_TEXT",
         getResourceString("TableItem.tooltip", new java.lang.Object[] {item.getText(), helpKey}));
     item.setData(
         "TIP_HELPTEXTHANDLER",
         new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler() {
           public java.lang.String getHelpText(org.eclipse.swt.widgets.Widget widget) {
             org.eclipse.swt.widgets.Item item = (org.eclipse.swt.widgets.Item) widget;
             return getResourceString("TableItem.help", new java.lang.Object[] {item.getText()});
           }
         });
   }
   table.setLayoutData(new org.eclipse.swt.layout.GridData(GridData.VERTICAL_ALIGN_FILL));
   tooltip.activateHoverHelp(table);
   org.eclipse.swt.widgets.Tree tree = new org.eclipse.swt.widgets.Tree(frame, SWT.BORDER);
   for (int i = 0; i < 4; i++) {
     org.eclipse.swt.widgets.TreeItem item = new org.eclipse.swt.widgets.TreeItem(tree, SWT.PUSH);
     item.setText(getResourceString("Item", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData("TIP_IMAGE", images[hhiWarning]);
     item.setText(
         getResourceString("TreeItem.text", new java.lang.Object[] {new java.lang.Integer(i)}));
     item.setData(
         "TIP_TEXT",
         getResourceString("TreeItem.tooltip", new java.lang.Object[] {item.getText(), helpKey}));
     item.setData(
         "TIP_HELPTEXTHANDLER",
         new org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler() {
           public java.lang.String getHelpText(org.eclipse.swt.widgets.Widget widget) {
             org.eclipse.swt.widgets.Item item = (org.eclipse.swt.widgets.Item) widget;
             return getResourceString("TreeItem.help", new java.lang.Object[] {item.getText()});
           }
         });
   }
   tree.setLayoutData(new org.eclipse.swt.layout.GridData(GridData.VERTICAL_ALIGN_FILL));
   tooltip.activateHoverHelp(tree);
   org.eclipse.swt.widgets.Button button = new org.eclipse.swt.widgets.Button(frame, SWT.PUSH);
   button.setText(getResourceString("Hello.text"));
   button.setData("TIP_TEXT", getResourceString("Hello.tooltip"));
   tooltip.activateHoverHelp(button);
 }