Beispiel #1
0
  @Override
  public void renderWindow(Graphics gfx, Window w) {
    int x = w.getAbsoluteX();
    int y = w.getAbsoluteY();

    gfx.setColor(backColor1);
    gfx.fillRect(x, y, w.getWidth(), w.getHeight());
    gfx.setColor(borderColor);
    gfx.setLineWidth(2);
    gfx.drawRect(x, y, w.getWidth(), w.getHeight());
  }
Beispiel #2
0
 // get height of window
 public int getHeight() {
   Window w = vc.getFullScreenWindow();
   if (w != null) {
     return w.getHeight();
   } else {
     return 0;
   }
 }
Beispiel #3
0
  public static void centerWindow(Window window) {
    Preconditions.checkArgument(window != null);

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int x = ((int) screenSize.getWidth() - window.getWidth()) >> 1;
    int y = ((int) screenSize.getHeight() - window.getHeight()) >> 1;
    window.setLocation(x, y);
  }
    /**
     * Returns the corner that contains the point <code>x</code>, <code>y</code>, or -1 if the
     * position doesn't match a corner.
     */
    private int calculateCorner(Window w, int x, int y) {
      Insets insets = w.getInsets();
      int xPosition = calculatePosition(x - insets.left, w.getWidth() - insets.left - insets.right);
      int yPosition = calculatePosition(y - insets.top, w.getHeight() - insets.top - insets.bottom);

      if (xPosition == -1 || yPosition == -1) {
        return -1;
      }
      return yPosition * 5 + xPosition;
    }
  static Window createWindow(
      final Capabilities caps,
      final int x,
      final int y,
      final int width,
      final int height,
      final boolean onscreen,
      final boolean undecorated)
      throws InterruptedException {
    final boolean userPos = x >= 0 && y >= 0; // user has specified a position

    Assert.assertNotNull(caps);
    caps.setOnscreen(onscreen);
    // System.out.println("Requested: "+caps);

    //
    // Create native windowing resources .. X11/Win/OSX
    //
    final Window window = NewtFactory.createWindow(caps);
    Assert.assertNotNull(window);
    final Screen screen = window.getScreen();
    final Display display = screen.getDisplay();
    window.setUndecorated(onscreen && undecorated);
    if (userPos) {
      window.setPosition(x, y);
    }
    window.setSize(width, height);
    Assert.assertEquals(false, window.isNativeValid());
    Assert.assertEquals(false, window.isVisible());
    window.setVisible(true);
    // System.err.println("************* Created: "+window);

    Assert.assertEquals(true, display.isNativeValid());
    Assert.assertEquals(true, screen.isNativeValid());
    Assert.assertEquals(true, window.isVisible());
    Assert.assertEquals(true, window.isNativeValid());
    Assert.assertEquals(width, window.getWidth());
    Assert.assertEquals(height, window.getHeight());

    /**
     * we don't sync on position - unreliable test Point p0 = window.getLocationOnScreen(null);
     * Assert.assertEquals(p0.getX(), window.getX()); Assert.assertEquals(p0.getY(), window.getY());
     * if(userPos) { Assert.assertEquals(x, window.getX()); Assert.assertEquals(y, window.getY()); }
     */
    final CapabilitiesImmutable chosenCapabilities =
        window.getGraphicsConfiguration().getChosenCapabilities();
    Assert.assertNotNull(chosenCapabilities);
    Assert.assertTrue(chosenCapabilities.getGreenBits() >= 5);
    Assert.assertTrue(chosenCapabilities.getBlueBits() >= 5);
    Assert.assertTrue(chosenCapabilities.getRedBits() >= 5);
    Assert.assertEquals(chosenCapabilities.isOnscreen(), onscreen);

    return window;
  }
Beispiel #6
0
  // recenter the mouse using the robot
  public synchronized void recenterMouse() {
    Window w = s.getFullScreenWindow();

    if (robot != null && w.isShowing()) {
      center.x = w.getWidth() / 2;
      center.y = w.getHeight() / 2;

      SwingUtilities.convertPointToScreen(center, w);
      centering = true;
      robot.mouseMove(center.x, center.y);
    }
  }
 private void updateWindow(boolean repaint) {
   Window w = (Window) target;
   synchronized (getStateLock()) {
     if (isOpaque || !w.isVisible() || (w.getWidth() <= 0) || (w.getHeight() <= 0)) {
       return;
     }
     TranslucentWindowPainter currentPainter = painter;
     if (currentPainter != null) {
       currentPainter.updateWindow(repaint);
     } else if (log.isLoggable(PlatformLogger.Level.FINER)) {
       log.finer("Translucent window painter is null in updateWindow");
     }
   }
 }
  @Test
  public void testWindowNativeRecreate01Simple() throws InterruptedException {
    final Capabilities caps = new Capabilities();
    Assert.assertNotNull(caps);

    final Window window =
        createWindow(caps, -1, -1, width, height, true /* onscreen */, false /* undecorated */);
    destroyWindow(window, true);

    window.setVisible(true);
    Assert.assertEquals(true, window.isNativeValid());
    Assert.assertEquals(true, window.isVisible());
    Assert.assertEquals(width, window.getWidth());
    Assert.assertEquals(height, window.getHeight());

    destroyWindow(window, true);
  }
  protected synchronized Dialog createGotoDialog() {
    if (gotoDialog == null) {
      gotoDialog =
          DialogSupport.createDialog(
              NbBundle.getBundle(org.netbeans.editor.BaseKit.class)
                  .getString("goto-title"), // NOI18N
              gotoPanel,
              false, // non-modal
              gotoButtons,
              false, // sidebuttons,
              0, // defaultIndex = 0 => gotoButton
              1, // cancelIndex = 1 => cancelButton
              this // listener
              );

      gotoDialog.pack();

      // Position the dialog according to the history
      Rectangle lastBounds = (Rectangle) EditorState.get(BOUNDS_KEY);
      if (lastBounds != null) {
        gotoDialog.setBounds(lastBounds);
      } else { // no history, center it on the screen
        Dimension dim = gotoDialog.getPreferredSize();
        int x;
        int y;
        JTextComponent c = EditorRegistry.lastFocusedComponent();
        Window w = c != null ? SwingUtilities.getWindowAncestor(c) : null;
        if (w != null) {
          x = Math.max(0, w.getX() + (w.getWidth() - dim.width) / 2);
          y = Math.max(0, w.getY() + (w.getHeight() - dim.height) / 2);
        } else {
          Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
          x = Math.max(0, (screen.width - dim.width) / 2);
          y = Math.max(0, (screen.height - dim.height) / 2);
        }
        gotoDialog.setLocation(x, y);
      }

      return gotoDialog;
    } else {
      gotoDialog.setVisible(true);
      gotoDialog.toFront();
      return null;
    }
  }
    public void mousePressed(MouseEvent ev) {
      JRootPane rootPane = getRootPane();

      if (rootPane.getWindowDecorationStyle() == JRootPane.NONE) {
        return;
      }
      Point dragWindowOffset = ev.getPoint();
      Window w = (Window) ev.getSource();
      if (w != null) {
        w.toFront();
      }
      Point convertedDragWindowOffset =
          SwingUtilities.convertPoint(w, dragWindowOffset, getTitlePane());

      Frame f = null;
      Dialog d = null;

      if (w instanceof Frame) {
        f = (Frame) w;
      } else if (w instanceof Dialog) {
        d = (Dialog) w;
      }

      int frameState = (f != null) ? f.getExtendedState() : 0;

      if (getTitlePane() != null && getTitlePane().contains(convertedDragWindowOffset)) {
        if ((f != null && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null))
            && dragWindowOffset.y >= BORDER_DRAG_THICKNESS
            && dragWindowOffset.x >= BORDER_DRAG_THICKNESS
            && dragWindowOffset.x < w.getWidth() - BORDER_DRAG_THICKNESS) {
          isMovingWindow = true;
          dragOffsetX = dragWindowOffset.x;
          dragOffsetY = dragWindowOffset.y;
        }
      } else if (f != null && f.isResizable() && ((frameState & Frame.MAXIMIZED_BOTH) == 0)
          || (d != null && d.isResizable())) {
        dragOffsetX = dragWindowOffset.x;
        dragOffsetY = dragWindowOffset.y;
        dragWidth = w.getWidth();
        dragHeight = w.getHeight();
        dragCursor = getCursor(calculateCorner(w, dragWindowOffset.x, dragWindowOffset.y));
      }
    }
  public static void centerDialog(final Window dialog) {
    final GraphicsConfiguration config =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();

    final Rectangle screenBounds = config.getBounds();
    final Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config);

    screenBounds.x = screenBounds.x + insets.left;
    screenBounds.y = screenBounds.y + insets.top;
    screenBounds.width = screenBounds.width - (insets.left + insets.right);
    screenBounds.height = screenBounds.height - (insets.top + insets.bottom);

    // remember that casting doubles to int's always rounds down.
    dialog.setLocation(
        ((screenBounds.width / 2) + screenBounds.x - (dialog.getWidth() / 2)),
        ((screenBounds.height / 2) + screenBounds.y - (dialog.getHeight() / 2)));
  }
  public static void dumpRedsFromImage(Window w) {
    Point offset = w.getLocationOnScreen();

    System.err.println("");
    System.err.println("");
    System.err.println("");

    for (int y = 0; y < w.getHeight(); y++) {
      System.err.print("  ");
      for (int x = 0; x < w.getWidth(); x++) {
        Color rgb = kRobot.getPixelColor(offset.x + x, offset.y + y);
        int r = rgb.getRed();
        String c = (r == 0xff ? "X" : (r == 0 ? "." : "?"));
        System.err.print(c + " ");
        // System.err.print( r + " ");
      }
      System.err.println("");
    }
  }
Beispiel #13
0
  public static void main(String[] args) {
    final Window window = new Window(g_szApplicationName);
    window.setIconImage(LoadIcon("/SimpleSoccer/icon1.png"));
    window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    buffer = new BufferedImage(WindowWidth, WindowHeight, BufferedImage.TYPE_INT_RGB);
    hdcBackBuffer = buffer.createGraphics();
    // these hold the dimensions of the client window area
    cxClient = buffer.getWidth();
    cyClient = buffer.getHeight();
    // seed random number generator
    common.misc.utils.setSeed(0);

    window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    // Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    window.setResizable(false);

    int y = center.y - window.getHeight() / 2;
    window.setLocation(center.x - window.getWidth() / 2, y >= 0 ? y : 0);
    Script1.MyMenuBar menu = Script1.createMenu(IDR_MENU1);
    window.setJMenuBar(menu);

    g_SoccerPitch = new SoccerPitch(cxClient, cyClient);

    CheckAllMenuItemsAppropriately(menu);

    createPanel();

    window.add(panel);
    window.pack();

    window.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            CppToJava.keyCache.released(e);
            switch (e.getKeyChar()) {
              case KeyEvent.VK_ESCAPE:
                {
                  System.exit(0);
                }
                break;
              case 'r':
              case 'R':
                {
                  SoccerPitchLock.lock();
                  g_SoccerPitch = null;
                  g_SoccerPitch = new SoccerPitch(cxClient, cyClient);
                  JMenuBar bar = Script1.createMenu(IDR_MENU1);
                  window.setJMenuBar(bar);
                  bar.revalidate();
                  SoccerPitchLock.unlock();
                }
                break;

              case 'p':
              case 'P':
                {
                  g_SoccerPitch.TogglePause();
                }
                break;
            } // end switch
          } // end switch        }

          @Override
          public void keyPressed(KeyEvent e) {
            CppToJava.keyCache.pressed(e);
          }
        });

    window.addComponentListener(
        new ComponentAdapter() {
          @Override // has the user resized the client area?
          public void componentResized(ComponentEvent e) {
            // if so we need to update our variables so that any drawing
            // we do using cxClient and cyClient is scaled accordingly
            cxClient = e.getComponent().getBounds().width;
            cyClient = e.getComponent().getBounds().height;
            // now to resize the backbuffer accordingly.
            buffer = new BufferedImage(cxClient, cyClient, BufferedImage.TYPE_INT_RGB);
            hdcBackBuffer = buffer.createGraphics();
          }
        });

    // make the window visible
    window.setVisible(true);

    // timer.SmoothUpdatesOn();

    // start the timer
    timer.Start();

    while (true) {
      // update
      if (timer.ReadyForNextFrame()) {
        SoccerPitchLock.lock();
        g_SoccerPitch.Update();
        SoccerPitchLock.unlock();
        // render
        // panel.revalidate();
        panel.repaint();

        try {
          // System.out.println(timer.TimeElapsed());
          Thread.sleep(2);
        } catch (InterruptedException ex) {
        }
      }
    } // end while
  }
 public static void centreWindow(Window frame) {
   Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
   int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2);
   int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2);
   frame.setLocation(x, y);
 }
Beispiel #15
0
  /** Installs the sheet on the owner. This method is invoked just before the JSheet is shown. */
  protected void installSheet() {
    if (!isNativeSheetSupported() && !isInstalled && isExperimentalSheet()) {
      Window owner = getOwner();
      if (owner != null) {
        owner.addWindowListener(windowEventHandler);
      }
      isInstalled = true;
    } else {
      Window owner = getOwner();
      if (owner != null) {

        // Determine the location for the sheet and its owner while
        // the sheet will be visible.
        // In case we have to shift the owner to fully display the
        // dialog, we remember the shift back position.
        Point ownerLoc = owner.getLocation();
        Point sheetLoc;
        if (isShowAsSheet()) {
          if (owner instanceof JFrame) {
            sheetLoc =
                new Point(
                    ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                    ownerLoc.y
                        + owner.getInsets().top
                        + ((JFrame) owner).getRootPane().getContentPane().getY());
          } else if (owner instanceof JDialog) {
            sheetLoc =
                new Point(
                    ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                    ownerLoc.y
                        + owner.getInsets().top
                        + ((JDialog) owner).getRootPane().getContentPane().getY());
          } else {
            sheetLoc =
                new Point(
                    ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                    ownerLoc.y + owner.getInsets().top);
          }

          if (sheetLoc.x < 0) {
            owner.setLocation(ownerLoc.x - sheetLoc.x, ownerLoc.y);
            sheetLoc.x = 0;
            shiftBackLocation = ownerLoc;
            oldLocation = owner.getLocation();
          } else {
            shiftBackLocation = null;
            oldLocation = ownerLoc;
          }
        } else {
          sheetLoc =
              new Point(
                  ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                  ownerLoc.y + (owner.getHeight() - getHeight()) / 2);
        }
        setLocation(sheetLoc);

        oldFocusOwner = owner.getFocusOwner();

        // Note: We mustn't change the windows focusable state because
        // this also affects the focusable state of the JSheet.
        // owner.setFocusableWindowState(false);
        owner.setEnabled(false);
        // ((JFrame) owner).setResizable(false);
        if (isShowAsSheet()) {
          owner.addComponentListener(ownerMovementHandler);
        } else {
          if (owner instanceof Frame) {
            setTitle(((Frame) owner).getTitle());
          }
        }
      }
      isInstalled = true;
    }
  }
Beispiel #16
0
  public static void setToplevelLocation(
      Window toplevel, Component component, int relativePosition) {

    Rectangle compBounds = component.getBounds();

    // Convert component location to screen coordinates
    Point p = new Point();
    SwingUtilities.convertPointToScreen(p, component);

    int x;
    int y;

    // Set frame location to be centered on panel
    switch (relativePosition) {
      case SwingConstants.NORTH:
        {
          x = (p.x + (compBounds.width / 2)) - (toplevel.getWidth() / 2);
          y = p.y - toplevel.getHeight();
          break;
        }
      case SwingConstants.EAST:
        {
          x = p.x + compBounds.width;
          y = (p.y + (compBounds.height / 2)) - (toplevel.getHeight() / 2);
          break;
        }
      case SwingConstants.SOUTH:
        {
          x = (p.x + (compBounds.width / 2)) - (toplevel.getWidth() / 2);
          y = p.y + compBounds.height;
          break;
        }
      case SwingConstants.WEST:
        {
          x = p.x - toplevel.getWidth();
          y = (p.y + (compBounds.height / 2)) - (toplevel.getHeight() / 2);
          break;
        }
      case SwingConstants.NORTH_EAST:
        {
          x = p.x + compBounds.width;
          y = p.y - toplevel.getHeight();
          break;
        }
      case SwingConstants.NORTH_WEST:
        {
          x = p.x - toplevel.getWidth();
          y = p.y - toplevel.getHeight();
          break;
        }
      case SwingConstants.SOUTH_EAST:
        {
          x = p.x + compBounds.width;
          y = p.y + compBounds.height;
          break;
        }
      case SwingConstants.SOUTH_WEST:
        {
          x = p.x - toplevel.getWidth();
          y = p.y + compBounds.height;
          break;
        }
      default:
      case SwingConstants.CENTER:
        {
          x = (p.x + (compBounds.width / 2)) - (toplevel.getWidth() / 2);
          y = (p.y + (compBounds.height / 2)) - (toplevel.getHeight() / 2);
        }
    }
    toplevel.setLocation(x, y);
  }