public void testColors() {
   Fixture.fakePhase(PhaseId.PROCESS_ACTION);
   Display display = new Display();
   Composite shell = new Shell(display, SWT.NONE);
   Twistie twistie = new Twistie(shell, SWT.NONE);
   Color decorationColor = Graphics.getColor(255, 0, 0);
   twistie.setDecorationColor(decorationColor);
   assertEquals(decorationColor, twistie.getDecorationColor());
   Color hoverColor = Graphics.getColor(0, 255, 0);
   twistie.setHoverDecorationColor(hoverColor);
   assertEquals(hoverColor, twistie.getHoverDecorationColor());
 }
Example #2
0
 @Test
 public void testGetLineHeight() {
   Text text = new Text(shell, SWT.MULTI);
   // default theme font is 11px
   assertEquals(16, text.getLineHeight());
   text.setFont(Graphics.getFont("Helvetica", 12, SWT.NORMAL));
   assertEquals(14, text.getLineHeight());
   text.setFont(null);
   assertEquals(16, text.getLineHeight());
 }
  private Button createPerspectiveButton(final IPerspectiveDescriptor desc) {

    Button result = (Button) perspectiveButtonMap.get(desc);
    if (result == null && desc != null && desc.getLabel() != null) {
      Composite buttonBg = new Composite(background, SWT.NONE);
      buttonBg.setBackground(Graphics.getColor(247, 247, 247));
      buttonBg.setLayout(new FormLayout());

      Label leftBg = new Label(buttonBg, SWT.NONE);
      leftBg.setImage(left);
      FormData fdLeftBg = new FormData();
      leftBg.setLayoutData(fdLeftBg);
      fdLeftBg.top = new FormAttachment(0);
      fdLeftBg.left = new FormAttachment(0);
      fdLeftBg.height = left.getBounds().height;
      fdLeftBg.width = left.getBounds().width;

      Label rightBg = new Label(buttonBg, SWT.NONE);
      rightBg.setImage(right);
      FormData fdRightBg = new FormData();
      rightBg.setLayoutData(fdRightBg);
      fdRightBg.top = new FormAttachment(0);
      fdRightBg.height = right.getBounds().height;
      fdRightBg.width = right.getBounds().width;

      final Button perspButton = new Button(buttonBg, SWT.PUSH | SWT.FLAT);
      perspButton.setData(RWT.CUSTOM_VARIANT, "perspective"); // $NON-NLS-1$
      FormData fdButton = new FormData();
      perspButton.setLayoutData(fdButton);
      fdButton.left = new FormAttachment(leftBg);
      FormData buttonPos = getLayoutSet().getPosition(ILayoutSetConstants.PERSP_BUTTON_POS);
      fdButton.top = buttonPos.top;
      fdRightBg.left = new FormAttachment(perspButton);

      perspButton.setText(desc.getLabel());

      perspectiveButtonMap.put(desc, perspButton);
      buttonPerspectiveMap.put(perspButton, desc);
      buttonList.add(perspButton);

      perspButton.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              cleanButtons(perspButton);
              switchPerspective(desc.getId());
            }
          });

      Menu menu = new Menu(perspButton);
      MenuItem item = new MenuItem(menu, SWT.PUSH);
      item.setText(Messages.get().PerspectiveSwitcherBuilder_Close);
      item.setImage(getImage(ILayoutSetConstants.PERSP_CLOSE));
      item.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              removeIdFromStore(desc.getId());
              Button button = (Button) perspectiveButtonMap.get(desc);
              if (button != null) {
                cleanUpButton(desc, button);
              }
              closePerspective(desc);
              background.layout();
            }
          });
      perspButton.setMenu(menu);
      if (otherButton != null) {
        otherButton.getParent().moveBelow(perspButton.getParent());
      }
      result = perspButton;
    }

    return result;
  }