Example #1
0
  private void createClearTextNew(Composite parent) {
    // only create the button if the text widget doesn't support one
    // natively
    if ((filterText.getStyle() & SWT.ICON_CANCEL) == 0) {
      final Image inactiveImage =
          new Image(
              this.getDisplay(),
              FilterTextComposite.class.getResourceAsStream(DISABLED_CLEAR_ICON));
      final Image activeImage =
          new Image(this.getDisplay(), FilterTextComposite.class.getResourceAsStream(CLEAR_ICON));
      final Image pressedImage = new Image(getDisplay(), activeImage, SWT.IMAGE_GRAY);

      final Label clearButton = new Label(parent, SWT.NONE);
      clearButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
      clearButton.setImage(inactiveImage);
      clearButton.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
      clearButton.setToolTipText("Tooltip");
      clearButton.addMouseListener(
          new MouseAdapter() {
            private MouseMoveListener fMoveListener;

            public void mouseDown(MouseEvent e) {
              clearButton.setImage(pressedImage);
              fMoveListener =
                  new MouseMoveListener() {
                    private boolean fMouseInButton = true;

                    public void mouseMove(MouseEvent e) {
                      boolean mouseInButton = isMouseInButton(e);
                      if (mouseInButton != fMouseInButton) {
                        fMouseInButton = mouseInButton;
                        clearButton.setImage(mouseInButton ? pressedImage : inactiveImage);
                      }
                    }
                  };
              clearButton.addMouseMoveListener(fMoveListener);
            }

            public void mouseUp(MouseEvent e) {
              if (fMoveListener != null) {
                clearButton.removeMouseMoveListener(fMoveListener);
                fMoveListener = null;
                boolean mouseInButton = isMouseInButton(e);
                clearButton.setImage(mouseInButton ? activeImage : inactiveImage);
                if (mouseInButton) {
                  clearText();
                  filterText.setFocus();
                }
              }
            }

            private boolean isMouseInButton(MouseEvent e) {
              Point buttonSize = clearButton.getSize();
              return 0 <= e.x && e.x < buttonSize.x && 0 <= e.y && e.y < buttonSize.y;
            }
          });
      clearButton.addMouseTrackListener(
          new MouseTrackListener() {
            public void mouseEnter(MouseEvent e) {
              clearButton.setImage(activeImage);
            }

            public void mouseExit(MouseEvent e) {
              clearButton.setImage(inactiveImage);
            }

            public void mouseHover(MouseEvent e) {}
          });
      clearButton.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
              inactiveImage.dispose();
              activeImage.dispose();
              pressedImage.dispose();
            }
          });

      this.clearButtonControl = clearButton;
    }
  }
Example #2
0
  @Override
  protected void configureShell(Shell newShell) {
    newShell.setText(getTitle());
    newShell.setImage(getImage());
    newShell.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            Shell shell = (Shell) e.getSource();
            Rectangle rect = shell.getClientArea();
            rect.width--;
            rect.height--;
            Color c = new Color(shell.getDisplay(), 0x1E, 0x3E, 0x93);
            e.gc.setForeground(c);
            e.gc.drawRectangle(0, 0, rect.width, rect.height);
            c.dispose();

            c = new Color(shell.getDisplay(), 0xAA, 0xE1, 0xFF);
            e.gc.setForeground(c);
            e.gc.drawRectangle(1, 1, rect.width - 2, rect.height - 2);
            c.dispose();

            c = new Color(shell.getDisplay(), 0x53, 0xAE, 0xF3);
            e.gc.setForeground(c);
            e.gc.drawRectangle(2, 2, rect.width - 4, rect.height - 4);
            c.dispose();

            Color top = new Color(shell.getDisplay(), 0x15, 0x77, 0xD3);
            Color bottom = new Color(shell.getDisplay(), 0x68, 0xB6, 0xF7);
            String title = getTitle();
            Point extent = e.gc.textExtent(title);
            int height = Math.max(18, extent.y + 6);
            e.gc.setForeground(top);
            e.gc.setBackground(bottom);
            e.gc.fillGradientRectangle(2, 2, rect.width - 4, height, true);
            top.dispose();
            bottom.dispose();

            c = new Color(shell.getDisplay(), 0x4F, 0x93, 0xD5);
            e.gc.setForeground(c);
            e.gc.setBackground(shell.getBackground());
            e.gc.drawRectangle(3, 2 + height, rect.width - 6, 2 + height);
            c.dispose();

            Image image = getImage();
            Rectangle imageRect = image.getBounds();
            e.gc.drawImage(getImage(), 4, 2 + ((height - imageRect.height) >> 1));

            e.gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
            e.gc.setFont(Resources.getInstance().getDefaultFont());
            e.gc.drawString(
                title, 6 + imageRect.width, Math.max(5, (height - extent.y) >> 1), true);

            bottom = new Color(shell.getDisplay(), 0xCC, 0xEB, 0xFF);
            e.gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
            e.gc.setBackground(bottom);
            e.gc.fillGradientRectangle(
                3, 3 + height, rect.width - 5, rect.height - 5 - height, true);
            bottom.dispose();

            Rectangle btnRect = btnDefault.getBounds();
            c = new Color(shell.getDisplay(), 0x9A, 0xBD, 0xE2);
            int x = btnRect.x;
            int y = btnRect.y - 5;
            while (x < rect.width - 3) {
              e.gc.setForeground(c);
              e.gc.drawPoint(x, y);
              e.gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
              e.gc.drawPoint(x, y + 1);
              x += 3;
            }
            c.dispose();

            e.gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_BLUE));
            TextLayout layout = new TextLayout(shell.getDisplay());
            layout.setWidth(215);
            layout.setText(getTip());
            layout.setFont(res.getDefaultFont());
            layout.draw(e.gc, 3 + getLeftMargin(), 2 + height + getTopMargin());
            layout.dispose();
          }
        });
    newShell.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDown(MouseEvent e) {
            downX = e.x;
            downY = e.y;
            isMove = true;
          }

          @Override
          public void mouseUp(MouseEvent e) {
            isMove = false;
          }
        });
    newShell.addMouseMoveListener(
        new MouseMoveListener() {
          public void mouseMove(MouseEvent e) {
            if (isMove) {
              Point loc = getShell().getLocation();
              int x = loc.x + e.x - downX;
              int y = loc.y + e.y - downY;
              getShell().setLocation(x, y);
            }
          }
        });

    // create default button
    newShell.setLayout(new FormLayout());
    // close button
    Label lblClose = new Label(newShell, SWT.CENTER);
    lblClose.setImage(res.getImage(Resources.bmpCloseNormal));
    FormData fd = new FormData();
    fd.top = new FormAttachment(0, 3);
    fd.height = 16;
    fd.right = new FormAttachment(100, -3);
    fd.width = 17;
    lblClose.setLayoutData(fd);
    lblClose.addMouseTrackListener(
        new MouseTrackAdapter() {
          @Override
          public void mouseEnter(MouseEvent e) {
            Label lbl = (Label) e.getSource();
            lbl.setImage(res.getImage(Resources.bmpCloseHover));
          }

          @Override
          public void mouseExit(MouseEvent e) {
            Label lbl = (Label) e.getSource();
            lbl.setImage(res.getImage(Resources.bmpCloseNormal));
          }
        });
    lblClose.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDown(MouseEvent e) {
            Label lbl = (Label) e.getSource();
            lbl.setImage(res.getImage(Resources.bmpCloseDown));
          }

          @Override
          public void mouseUp(MouseEvent e) {
            getShell().close();
          }
        });
    btnDefault = new Slat(newShell);
    btnDefault.setText(getButtonLabel());
    fd = new FormData();
    fd.bottom = new FormAttachment(100, -6);
    fd.left = new FormAttachment(0, 6);
    btnDefault.setLayoutData(fd);
    btnDefault.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseUp(MouseEvent e) {
            getShell().close();
            onButton();
          }
        });
    btnDefault.setVisible(showButton());
  }
Example #3
0
  public void showContent(Composite parent) {

    GridLayout gl = new GridLayout(1, true);
    parent.setLayout(gl);

    Label l = new Label(parent, SWT.NONE);
    l.setText(laClasse.getLabel());
    l.setLayoutData(new GridData(GridData.FILL_BOTH));
    Font f = new Font(Display.getCurrent(), "arial", 10, SWT.BOLD); // $NON-NLS-1$
    l.setFont(f);

    l.addMouseTrackListener(
        new MouseTrackListener() {

          public void mouseEnter(MouseEvent e) {
            Label l = (Label) e.widget;
            l.setForeground(new Color(Display.getCurrent(), 0, 0, 200));
          }

          public void mouseExit(MouseEvent e) {
            Label l = (Label) e.widget;
            l.setForeground(new Color(Display.getCurrent(), 0, 0, 0));
          }

          public void mouseHover(MouseEvent e) {}
        });

    l.addMouseListener(
        new MouseListener() {

          public void mouseDoubleClick(MouseEvent e) {}

          public void mouseDown(MouseEvent e) {}

          public void mouseUp(MouseEvent e) {

            // StructuredSelection ss = new StructuredSelection(laClasse);
            // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().getActivePart().getSite().getSelectionProvider().setSelection(ss);

            Label l = (Label) e.widget;
            l.setForeground(new Color(Display.getCurrent(), 0, 0, 0));
            // org.dafoe.ontologiclevel.Activator.currentClasse= laClasse;
            org.dafoe.ontologiclevel.Activator.setCurrentClass(laClasse);

            List<String> perpsectiveIdsFromContextLevel =
                org.dafoe.contextlevel.Activator.getDefault()
                    .getContextLevel()
                    .getPerpsectiveIdsFromContextLevel("ontologic"); // $NON-NLS-1$

            IPerspectiveRegistry perspectiveRegistry =
                PlatformUI.getWorkbench().getPerspectiveRegistry();
            IPerspectiveDescriptor perspectiveWithId =
                perspectiveRegistry.findPerspectiveWithId(perpsectiveIdsFromContextLevel.get(0));

            PlatformUI.getWorkbench()
                .getActiveWorkbenchWindow()
                .getActivePage()
                .setPerspective(perspectiveWithId);
          }
        });
  }