Exemplo n.º 1
0
  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;
  }
Exemplo n.º 2
0
  /** Notifies all views of a data reference change. */
  public void init() {
    final Data data = initHistory(gui.context);
    if (data != null) {
      // if a large database is opened, the user is asked if complex
      /// visualizations should be closed first
      final long size = data.meta.dbsize();
      boolean open = false;
      for (final View v : view) open |= v.visible() && v.db();
      if (open
          && size > LARGEDB
          && BaseXDialog.confirm(gui, Util.info(H_LARGE_DB, Performance.format(size)))) {
        for (final View v : view) if (v.visible() && v.db()) v.visible(false);
      }
    } else {
      // database closed: close open dialogs
      for (final Window w : gui.getOwnedWindows()) {
        if (w.isVisible() && w instanceof BaseXDialog) ((BaseXDialog) w).cancel();
      }
    }

    gui.context.focused = -1;
    for (final View v : view) v.refreshInit();
    gui.layoutViews();
    gui.setTitle(data != null ? data.meta.name : null);
  }
 private boolean noIntersections(Rectangle bounds) {
   Window owner = SwingUtilities.getWindowAncestor(myComponent);
   Window popup = SwingUtilities.getWindowAncestor(myTipComponent);
   Window focus = WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow();
   if (focus == owner.getOwner()) {
     focus = null; // do not check intersection with parent
   }
   boolean focused = SystemInfo.isWindows || owner.isFocused();
   for (Window other : owner.getOwnedWindows()) {
     if (!focused && !SystemInfo.isWindows) {
       focused = other.isFocused();
     }
     if (popup != other
         && other.isVisible()
         && bounds.x + 10 >= other.getX()
         && bounds.intersects(other.getBounds())) {
       return false;
     }
     if (focus == other) {
       focus = null; // already checked
     }
   }
   return focused
       && (focus == owner || focus == null || !owner.getBounds().intersects(focus.getBounds()));
 }
Exemplo n.º 4
0
  @Override
  public void progressChanged(ProgressChangeEvent e) {
    lastState = e.getState();
    if (lastState == ProgressState.Exception) {
      setVisible(false);
    }

    // Track state
    if (e.getState() == ProgressState.Start) {
      bar.setValue(0);
      if (!trackerDialog.isVisible() && !Property.DIALOGS_PROGRESS_AUTOSHOW.get()) {
        WindowsUtils.center(trackerDialog);
        setVisible(true);
      }
    }

    if (e.getState() == ProgressState.Stop) {
      setVisible(false);
    }

    if (e.getValue() != null) {
      if (e.getPercents() != null) {
        bar.setValue(e.getPercents());
        bar.setIndeterminate(false);
        bar.setString(null);
      } else {
        bar.setIndeterminate(true);
        bar.setString(SynchronizationUtils.makeSizeString(e));
      }
    }

    if (e.getText() != null) {
      bar.setToolTipText(e.getText());
    }
  }
Exemplo n.º 5
0
 public boolean focusAllowedFor() {
   Window window = (Window) this.target;
   if (!window.isVisible() || !window.isEnabled() || !window.isFocusableWindow()) {
     return false;
   }
   if (isModalBlocked()) {
     return false;
   }
   return true;
 }
Exemplo n.º 6
0
  public void setOpaque(boolean isOpaque) {
    synchronized (getStateLock()) {
      if (this.isOpaque == isOpaque) {
        return;
      }
    }

    Window target = (Window) getTarget();

    if (!isOpaque) {
      SunToolkit sunToolkit = (SunToolkit) target.getToolkit();
      if (!sunToolkit.isWindowTranslucencySupported()
          || !sunToolkit.isTranslucencyCapable(target.getGraphicsConfiguration())) {
        return;
      }
    }

    boolean isVistaOS = Win32GraphicsEnvironment.isVistaOS();

    if (this.isOpaque != isOpaque && !isVistaOS) {
      // non-Vista OS: only replace the surface data if the opacity
      // status changed (see WComponentPeer.isAccelCapable() for more)
      replaceSurfaceDataRecursively(target);
    }

    synchronized (getStateLock()) {
      this.isOpaque = isOpaque;
      setOpaqueImpl(isOpaque);
      if (isOpaque) {
        TranslucentWindowPainter currentPainter = painter;
        if (currentPainter != null) {
          currentPainter.flush();
          painter = null;
        }
      } else {
        painter = TranslucentWindowPainter.createInstance(this);
      }
    }

    if (isVistaOS) {
      // On Vista: setting the window non-opaque makes the window look
      // rectangular, though still catching the mouse clicks within
      // its shape only. To restore the correct visual appearance
      // of the window (i.e. w/ the correct shape) we have to reset
      // the shape.
      Shape shape = target.getShape();
      if (shape != null) {
        target.setShape(shape);
      }
    }

    if (target.isVisible()) {
      updateWindow(true);
    }
  }
Exemplo n.º 7
0
  protected boolean focusAllowedFor() {
    Window window = getTarget();
    // TODO: check if modal blocked

    boolean allowed =
        (getBlocker() == null) && window.isVisible() && window.isEnabled() && isFocusableWindow();

    focusLog.fine(
        "Checking whether the focus is allowed ["
            + allowed
            + "] for "
            + window.getName()
            + "; blocker: "
            + ((getBlocker() == null) ? "null" : getBlocker().getClass().getName())
            + "; window.isVisible: "
            + window.isVisible()
            + "; window.isEnabled: "
            + window.isEnabled()
            + "; isFocusableWindow: "
            + isFocusableWindow());

    return allowed;
  }
Exemplo n.º 8
0
 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");
     }
   }
 }
Exemplo n.º 9
0
    /** Recycles the passed in <code>HeavyWeightPopup</code>. */
    private static void recycleHeavyWeightPopup(HeavyWeightPopup popup) {
      synchronized (HeavyWeightPopup.class) {
        List<HeavyWeightPopup> cache;
        Window window = SwingUtilities.getWindowAncestor(popup.getComponent());
        Map<Window, List<HeavyWeightPopup>> heavyPopupCache = getHeavyWeightPopupCache();

        if (window instanceof Popup.DefaultFrame || !window.isVisible()) {
          // If the Window isn't visible, we don't cache it as we
          // likely won't ever get a windowClosed event to clean up.
          // We also don't cache DefaultFrames as this indicates
          // there wasn't a valid Window parent, and thus we don't
          // know when to clean up.
          popup._dispose();
          return;
        } else if (heavyPopupCache.containsKey(window)) {
          cache = heavyPopupCache.get(window);
        } else {
          cache = new ArrayList<HeavyWeightPopup>();
          heavyPopupCache.put(window, cache);
          // Clean up if the Window is closed
          final Window w = window;

          w.addWindowListener(
              new WindowAdapter() {
                public void windowClosed(WindowEvent e) {
                  List<HeavyWeightPopup> popups;

                  synchronized (HeavyWeightPopup.class) {
                    Map<Window, List<HeavyWeightPopup>> heavyPopupCache2 =
                        getHeavyWeightPopupCache();

                    popups = heavyPopupCache2.remove(w);
                  }
                  if (popups != null) {
                    for (int counter = popups.size() - 1; counter >= 0; counter--) {
                      popups.get(counter)._dispose();
                    }
                  }
                }
              });
        }

        if (cache.size() < MAX_CACHE_SIZE) {
          cache.add(popup);
        } else {
          popup._dispose();
        }
      }
    }
Exemplo n.º 10
0
  @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);
  }
Exemplo n.º 11
0
 static void destroyWindow(final Window window, final boolean last) {
   if (null == window) {
     return;
   }
   final Screen screen = window.getScreen();
   final Display display = screen.getDisplay();
   window.destroy();
   // System.err.println("************* Destroyed: "+window);
   if (last) {
     Assert.assertEquals(false, screen.isNativeValid());
     Assert.assertEquals(false, display.isNativeValid());
   } else {
     Assert.assertEquals(true, screen.isNativeValid());
     Assert.assertEquals(true, display.isNativeValid());
   }
   Assert.assertEquals(false, window.isNativeValid());
   Assert.assertEquals(false, window.isVisible());
 }
Exemplo n.º 12
0
    boolean overlappedByOwnedWindow() {
      Component component = getComponent();
      if (owner != null && component != null) {
        Window w = SwingUtilities.getWindowAncestor(owner);
        if (w == null) {
          return false;
        }
        Window[] ownedWindows = w.getOwnedWindows();
        if (ownedWindows != null) {
          Rectangle bnd = component.getBounds();
          for (Window window : ownedWindows) {
            if (window.isVisible() && bnd.intersects(window.getBounds())) {

              return true;
            }
          }
        }
      }
      return false;
    }
Exemplo n.º 13
0
    public WindowMenuItem(final Window window, String title) {
      super(title, window.isVisible());
      addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              // window.pack();
              window.setVisible(!window.isVisible());
            }
          });

      window.addWindowListener(
          new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
              WindowMenuItem.this.setSelected(false);
            }

            public void windowOpened(WindowEvent e) {
              WindowMenuItem.this.setSelected(USE_SYSTEM_UI);
            }
          });
    }
Exemplo n.º 14
0
 /**
  * Hide the Window from view
  *
  * @param container - Window to hide.
  */
 public void hidePopup(Window container) {
   if ((container != null) && container.isVisible()) {
     container.setVisible(false);
   }
 }
 public void actionPerformed(ActionEvent e) {
   if (palette != null) {
     putValue(Actions.SELECTED_KEY, !palette.isVisible());
   }
 }
Exemplo n.º 16
0
 private boolean focusAllowedFor() {
   Window window = getTarget();
   // TODO: check if modal blocked
   return window.isVisible() && window.isEnabled() && isFocusableWindow();
 }