예제 #1
0
  public void positionWindow(boolean resetToDefault) {
    String mapWindow;

    mapShellBounds = mapShell.getBounds();
    mapWindow = prefs.get(RadarConsts.PREF_KEY_MAP_WINDOW, "");

    if (mapWindow.equals("") || resetToDefault) {
      Rectangle dispBounds, tableBounds;

      dispBounds = ((Display.getCurrent()).getPrimaryMonitor()).getClientArea();
      tableBounds = display.getShells()[1].getBounds();

      mapShellBounds.width = dispBounds.width - tableBounds.width;
      mapShellBounds.height = dispBounds.height;
      mapShellBounds.x = dispBounds.x + tableBounds.width;
      mapShellBounds.y = dispBounds.y;
    } else {
      String[] tokens = mapWindow.split(",");

      mapShellBounds =
          new Rectangle(
              new Integer(tokens[0]), // X value
              new Integer(tokens[1]), // Y value
              new Integer(tokens[2]), // Width
              new Integer(tokens[3]) // Height
              );
    }
    mapShell.setBounds(mapShellBounds);
  }
예제 #2
0
  public static void main(String[] args) {
    final Display display = new Display();
    final Image image = display.getSystemImage(SWT.ICON_INFORMATION);
    final Shell shell = new Shell(display, SWT.NO_TRIM);
    Region region = new Region();
    final ImageData imageData = image.getImageData();
    if (imageData.alphaData != null) {
      Rectangle pixel = new Rectangle(0, 0, 1, 1);
      for (int y = 0; y < imageData.height; y++) {
        for (int x = 0; x < imageData.width; x++) {
          if (imageData.getAlpha(x, y) == 255) {
            pixel.x = imageData.x + x;
            pixel.y = imageData.y + y;
            region.add(pixel);
          }
        }
      }
    } else {
      ImageData mask = imageData.getTransparencyMask();
      Rectangle pixel = new Rectangle(0, 0, 1, 1);
      for (int y = 0; y < mask.height; y++) {
        for (int x = 0; x < mask.width; x++) {
          if (mask.getPixel(x, y) != 0) {
            pixel.x = imageData.x + x;
            pixel.y = imageData.y + y;
            region.add(pixel);
          }
        }
      }
    }
    shell.setRegion(region);

    Listener l =
        new Listener() {
          /** The x/y of the MouseDown, relative to top-left of the shell. */
          int startX, startY;

          @Override
          public void handleEvent(Event e) {
            if (e.type == SWT.KeyDown && e.character == SWT.ESC) {
              shell.dispose();
            }
            if (e.type == SWT.MouseDown && e.button == 1) {
              Point p = shell.toDisplay(e.x, e.y);
              Point loc = shell.getLocation();
              startX = p.x - loc.x;
              startY = p.y - loc.y;
            }
            if (e.type == SWT.MouseMove && (e.stateMask & SWT.BUTTON1) != 0) {
              Point p = shell.toDisplay(e.x, e.y);
              p.x -= startX;
              p.y -= startY;
              shell.setLocation(p);
            }
            if (e.type == SWT.Paint) {
              e.gc.drawImage(image, imageData.x, imageData.y);
            }
          }
        };
    shell.addListener(SWT.KeyDown, l);
    shell.addListener(SWT.MouseDown, l);
    shell.addListener(SWT.MouseMove, l);
    shell.addListener(SWT.Paint, l);

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    region.dispose();
    image.dispose();
    display.dispose();
  }