コード例 #1
0
ファイル: TrackerAction.java プロジェクト: weimingtom/jzoomer
  public void mouseDown(MouseEvent e) {

    if (isChecked()) {
      if (e.button == 1 && e.stateMask == SWT.None) {
        point = new Point(e.x, e.y);
        // System.out.println( point );
        tracker.setRectangles(new Rectangle[] {new Rectangle(point.x, point.y, 0, 0)});
        // tracker.setStippled( true );
        tracker.open();
      }
    }
  }
コード例 #2
0
ファイル: TrackerAction.java プロジェクト: weimingtom/jzoomer
  public void controlResized(ControlEvent e) {

    if (isChecked()) {
      int rate = window.getCurrentZoomRate();
      Rectangle rectangle = tracker.getRectangles()[0];
      Point realSize =
          new Point(getRealValue(rectangle.width, rate), getRealValue(rectangle.height, rate));
      // Point p = new Point( point.x + tracker.getRectangles()[ 0 ].width, point.y +
      // tracker.getRectangles()[ 0 ].height );
      //			canvas.setToolTipText( getMessage(
      //					"action.tracker.canvas.tooltip",
      //					"" + rectangle.width,
      //					"" + rectangle.height,
      //					"" + realSize.x,
      //					"" + realSize.y
      //			) );
      tooltip.setText(
          getMessage(
              "action.tracker.canvas.tooltip",
              "" + rectangle.width,
              "" + rectangle.height,
              "" + realSize.x,
              "" + realSize.y));
      tooltip.show(point);
    }
  }
コード例 #3
0
  public TitleBar(final Window parent, final int size, int flags) {
    this.flags = flags;

    composite = new Composite(parent.getContentPanel(), SWT.NONE);

    composite.setSize(parent.getSize().x, size);

    buttonListener =
        new Listener() {
          public void handleEvent(Event event) {
            if (event.type == SWT.MouseUp) {
              // If the click is still on the button.
              if (event.x >= 0 && event.x < size && event.y >= 0 && event.y < size) {
                if (event.widget == closeButton) {
                  parent.close();
                } else if (event.widget == restoreButton) {
                  dontSetX = true;
                  parent.setMaximized(!parent.isMaximized());
                } else if (event.widget == minimizeButton) {
                  parent.setMinimized(true);
                }
              }
            } else if (event.type == SWT.MouseEnter) {
              Label button = (Label) event.widget;

              button.setBackground(hoverColor);
            } else if (event.type == SWT.MouseExit) {
              Label button = (Label) event.widget;

              button.setBackground(normalColor);
            }
          }
        };

    addButtons();

    titleLabel = new Label(composite, SWT.NONE);
    FontData fd = titleLabel.getFont().getFontData()[0];
    fd.setHeight(14);
    titleLabel.setFont(new Font(Display.getDefault(), fd));

    titleGC = new GC(titleLabel);
    setTitle(parent.getTitle());

    iconLabel = new Label(composite, SWT.NONE);
    setIcon(parent.getIcon());

    dontSetX = true;
    wasRestored = true;
    wasMaximized = parent.isMaximized();

    ControlListener resizeListener =
        new ControlListener() {
          public void controlResized(ControlEvent e) {
            composite.setSize(parent.getClientArea().width, size);

            setTitleLocation();

            layoutButtons();

            if (parent.isMaximized()) {
              if (restoreButton != null) {
                restoreButton.setImage(restoreImage);
              }
            } else {
              if (wasMaximized && !dontSetX) {
                parent.setLocation(mouseX - parent.getSize().x / 2, parent.getLocation().y);
              }

              if (restoreButton != null) {
                restoreButton.setImage(maximizeImage);
              }
            }

            dontSetX = false;

            wasRestored = false;

            wasMaximized = false;

            if (parent.isFullscreen()) {
              if (minimizeButton != null) {
                minimizeButton.setEnabled(false); // .setVisible(false);
              }
              if (restoreButton != null) {
                restoreButton.setEnabled(false); // .setVisible(false);
              }
            } else {
              if (minimizeButton != null) {
                minimizeButton.setEnabled(true); // .setVisible(true);
              }
              if (restoreButton != null) {
                restoreButton.setEnabled(true); // .setVisible(true);
              }
            }
          }

          public void controlMoved(ControlEvent e) {}
        };

    parent.addControlListener(resizeListener);

    final Tracker tracker = new Tracker(parent.getShell(), SWT.NONE);

    tracker.addControlListener(
        new ControlListener() {
          public void controlResized(ControlEvent e) {}

          public void controlMoved(ControlEvent e) {
            if (parent.isMaximized()) {
              parent.setMaximized(false);
            }

            Point loc =
                new Point(
                    tracker.getRectangles()[0].x + 99999, tracker.getRectangles()[0].y + 99999);

            int dx = loc.x - startX;
            int dy = loc.y - startY;

            parent.setLocation(parent.getLocation().x + dx, parent.getLocation().y + dy);

            startX = loc.x;
            startY = loc.y;
          }
        });

    Listener moveListener =
        new Listener() {
          public void handleEvent(Event event) {
            if (!parent.isFullscreen()) {
              if (event.type == SWT.MouseDown) {
                dragging = true;

                Control control = (Control) event.widget;

                mouseX = event.x + parent.getBorderSize() + control.getLocation().x;
                mouseY = event.y + parent.getBorderSize() + control.getLocation().y;

                wasMaximized = parent.isMaximized();

                startX = 0;
                startY = 0;

                tracker.setRectangles(new Rectangle[] {new Rectangle(-99999, -99999, 0, 0)});
                tracker.open();

                tracker.close();
                dragging = false;

                if (parent.getLocation().y + mouseY <= 0) {
                  wasRestored = true;
                  parent.setMaximized(true);
                }
              } else if (event.type == SWT.MouseDoubleClick) {
                dontSetX = true;
                wasRestored = true;
                parent.setMaximized(!parent.isMaximized());
              }
            }
          }
        };

    titleLabel.addListener(SWT.MouseDown, moveListener);
    titleLabel.addListener(SWT.MouseDoubleClick, moveListener);
    composite.addListener(SWT.MouseDown, moveListener);
    composite.addListener(SWT.MouseDoubleClick, moveListener);

    parent.addWindowListener(
        new WindowListener() {
          public boolean titleChanged(String newTitle) {
            setTitle(newTitle);

            return true;
          }

          public boolean iconChanged(Image newIcon) {
            setIcon(newIcon);

            return true;
          }
        });

    composite.setBackgroundMode(SWT.INHERIT_DEFAULT);
  }