Exemplo n.º 1
0
  private void init() {
    mBigButtonListeners = new ArrayList<SelectionListener>();
    mBigButtonMenu = new Menu(mShell);

    mToolbar = new QuickAccessShellToolbar(this);
    updateCalculations();
    mShell.setLayout(new RibbonShellLayout());

    mTabFolder = new RibbonTabFolder(mShell, SWT.NONE, this);

    mShell.addMouseListener(this);
    mShell.addMouseMoveListener(this);
    mShell.addShellListener(this);
    mShell.addKeyListener(this);
    mShell.addControlListener(this);

    mShell.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            drawBackground(e.gc);
          }
        });

    mShell.addShellListener(
        new ShellAdapter() {
          @Override
          public void shellActivated(ShellEvent e) {
            e.display.asyncExec(
                new Runnable() {
                  public void run() {
                    // re-layout post shell open or the tabfolder will look unpopulated
                    // until some action happens
                    mTabFolder.layout(true, true);
                    mTabFolder.redraw();
                    mToolbar.updateBounds();
                  }
                });
            mShell.removeShellListener(this);
          }
        });
  }
Exemplo n.º 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());
  }
Exemplo n.º 3
0
  private Shell createShell(final Display display, String name) {
    final Shell shell = new Shell(display);
    shell.setText(name);
    shell.setSize(500, 400);
    shell.addDisposeListener(
        new DisposeListener() {
          @Override
          public void widgetDisposed(DisposeEvent e) {
            shells--;
          }
        });
    shell.addMouseListener(
        new MouseListener() {
          @Override
          public void mouseUp(MouseEvent e) {
            GraphVisualizer.this.graph.shake(); // += 2.0;
          }

          @Override
          public void mouseDown(MouseEvent e) {}

          @Override
          public void mouseDoubleClick(MouseEvent e) {}
        });
    shell.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            final Rectangle clientArea = shell.getClientArea();
            final Point zero = new Point(clientArea.width / 2, clientArea.height / 2);
            final double fx = 50;
            final double fy = 50;
            e.gc.setLineWidth(2);
            for (final Edge edge : GraphVisualizer.this.graph.edges) {
              e.gc.drawLine(
                  (int) (edge.source.x * fx) + zero.x,
                  (int) (edge.source.y * fy) + zero.y,
                  (int) (edge.target.x * fx) + zero.x,
                  (int) (edge.target.y * fy) + zero.y);
              Delta dir = new Delta(edge.source.x - edge.target.x, edge.source.y - edge.target.y);
              double n = dir.length();
              dir.dx /= n;
              dir.dy /= n;
              e.gc.drawLine(
                  (int) ((edge.target.x + dir.dx / 5.0) * fx + zero.x),
                  (int) ((edge.target.y + dir.dy / 5.0) * fx + zero.y),
                  (int) ((edge.target.x + dir.dx / 2.5 + dir.dy / 10.0) * fx + zero.x),
                  (int) ((edge.target.y + dir.dy / 2.5 - dir.dx / 10.0) * fx + zero.y));
              e.gc.drawLine(
                  (int) ((edge.target.x + dir.dx / 5.0) * fx + zero.x),
                  (int) ((edge.target.y + dir.dy / 5.0) * fx + zero.y),
                  (int) ((edge.target.x + dir.dx / 2.5 - dir.dy / 10.0) * fx + zero.x),
                  (int) ((edge.target.y + dir.dy / 2.5 + dir.dx / 10.0) * fx + zero.y));
            }
            for (final Node node : GraphVisualizer.this.graph.nodes) {
              e.gc.setBackground(node.color.getColor(display));
              e.gc.fillOval(
                  (int) (node.x * fx) + zero.x - 10,
                  (int) (node.y * fy) + zero.y - 10,
                  (int) 20,
                  (int) 20);
              e.gc.drawOval(
                  (int) (node.x * fx) + zero.x - 10,
                  (int) (node.y * fy) + zero.y - 10,
                  (int) 20,
                  (int) 20);
            }
          }
        });
    new Thread() {
      @Override
      public void run() {
        while (true && !shell.isDisposed()) {
          GraphVisualizer.this.graph.step();
          display.asyncExec(
              new Runnable() {
                @Override
                public void run() {
                  if (!shell.isDisposed()) shell.redraw();
                }
              });
          try {
            Thread.sleep(5);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
    }.start();
    return shell;
  }