コード例 #1
0
    @Override
    public void dispose() {
      if (isShowing()) {
        hide();
      }

      if (myWindowListener != null) {
        myWindowListener.saveSize();
        removeWindowListener(myWindowListener);
        myWindowListener = null;
      }

      if (myComponentListener != null) {
        removeComponentListener(myComponentListener);
        myComponentListener = null;
      }

      if (myFocusTrackback != null
          && !(myFocusTrackback.isSheduledForRestore()
              || myFocusTrackback.isWillBeSheduledForRestore())) {
        myFocusTrackback.dispose();
        myFocusTrackback = null;
      }

      final BufferStrategy strategy = getBufferStrategy();
      if (strategy != null) {
        strategy.dispose();
      }
      super.dispose();

      if (rootPane != null) { // Workaround for bug in native code to hold rootPane
        try {
          Field field = rootPane.getClass().getDeclaredField("glassPane");
          field.setAccessible(true);
          field.set(rootPane, null);

          field = rootPane.getClass().getDeclaredField("contentPane");
          field.setAccessible(true);
          field.set(rootPane, null);
          rootPane = null;

          field = Window.class.getDeclaredField("windowListener");
          field.setAccessible(true);
          field.set(this, null);
        } catch (Exception ignored) {
        }
      }

      // http://bugs.sun.com/view_bug.do?bug_id=6614056
      try {
        final Field field = Dialog.class.getDeclaredField("modalDialogs");
        field.setAccessible(true);
        final List<?> list = (List<?>) field.get(null);
        list.remove(this);
      } catch (final Exception ignored) {
      }
    }
コード例 #2
0
    private void _setSizeForLocation(int width, int height, @Nullable Point initial) {
      Point location = initial != null ? initial : getLocation();
      Rectangle rect = new Rectangle(location.x, location.y, width, height);
      ScreenUtil.fitToScreen(rect);
      if (initial != null || location.x != rect.x || location.y != rect.y) {
        setLocation(rect.x, rect.y);
      }

      super.setSize(rect.width, rect.height);
    }
コード例 #3
0
    @Override
    public void paint(Graphics g) {
      if (!SystemInfo.isMac
          || UIUtil
              .isUnderAquaLookAndFeel()) { // avoid rendering problems with non-aqua (alloy) LaFs
                                           // under mac
        // actually, it's a bad idea to globally enable this for dialog graphics since renderers,
        // for example, may not
        // inherit graphics so rendering hints won't be applied and trees or lists may render ugly.
        UIUtil.applyRenderingHints(g);
      }

      super.paint(g);
    }
コード例 #4
0
 @Override
 @SuppressWarnings("deprecation")
 public void hide() {
   super.hide();
   if (myFocusTrackback != null
       && !(myFocusTrackback.isSheduledForRestore()
           || myFocusTrackback.isWillBeSheduledForRestore())) {
     myFocusTrackback.setWillBeSheduledForRestore();
     IdeFocusManager mgr = getFocusManager();
     Runnable r =
         new Runnable() {
           @Override
           public void run() {
             if (myFocusTrackback != null) myFocusTrackback.restoreFocus();
             myFocusTrackback = null;
           }
         };
     mgr.doWhenFocusSettlesDown(r);
   }
 }
コード例 #5
0
    @Override
    @SuppressWarnings("deprecation")
    public void show() {
      myFocusTrackback = new FocusTrackback(getDialogWrapper(), getParent(), true);

      final DialogWrapper dialogWrapper = getDialogWrapper();
      boolean isAutoAdjustable = dialogWrapper.isAutoAdjustable();
      Point location = null;
      if (isAutoAdjustable) {
        pack();

        Dimension packedSize = getSize();
        Dimension minSize = getMinimumSize();
        setSize(
            Math.max(packedSize.width, minSize.width), Math.max(packedSize.height, minSize.height));

        setSize(
            (int) (getWidth() * dialogWrapper.getHorizontalStretch()),
            (int) (getHeight() * dialogWrapper.getVerticalStretch()));

        // Restore dialog's size and location

        myDimensionServiceKey = dialogWrapper.getDimensionKey();

        if (myDimensionServiceKey != null) {
          final Project projectGuess =
              CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(this));
          location =
              DimensionService.getInstance().getLocation(myDimensionServiceKey, projectGuess);
          Dimension size =
              DimensionService.getInstance().getSize(myDimensionServiceKey, projectGuess);
          if (size != null) {
            myInitialSize = new Dimension(size);
            _setSizeForLocation(myInitialSize.width, myInitialSize.height, location);
          }
        }

        if (myInitialSize == null) {
          myInitialSize = getSize();
        }
      }

      if (location == null) {
        location = dialogWrapper.getInitialLocation();
      }

      if (location != null) {
        setLocation(location);
      } else {
        setLocationRelativeTo(getOwner());
      }

      if (isAutoAdjustable) {
        final Rectangle bounds = getBounds();
        ScreenUtil.fitToScreen(bounds);
        setBounds(bounds);
      }
      addWindowListener(
          new WindowAdapter() {
            @Override
            public void windowActivated(WindowEvent e) {
              final DialogWrapper wrapper = getDialogWrapper();
              if (wrapper != null && myFocusTrackback != null) {
                myFocusTrackback.cleanParentWindow();
                myFocusTrackback.registerFocusComponent(
                    new FocusTrackback.ComponentQuery() {
                      @Override
                      public Component getComponent() {
                        return wrapper.getPreferredFocusedComponent();
                      }
                    });
              }
            }

            @Override
            public void windowDeactivated(WindowEvent e) {
              if (!isModal()) {
                final Ref<IdeFocusManager> focusManager = new Ref<IdeFocusManager>(null);
                Project project = getProject();
                if (project != null && !project.isDisposed()) {
                  focusManager.set(getFocusManager());
                  focusManager
                      .get()
                      .doWhenFocusSettlesDown(
                          new Runnable() {
                            @Override
                            public void run() {
                              disposeFocusTrackbackIfNoChildWindowFocused(focusManager.get());
                            }
                          });
                } else {
                  disposeFocusTrackbackIfNoChildWindowFocused(focusManager.get());
                }
              }
            }

            @Override
            public void windowOpened(WindowEvent e) {
              if (!SystemInfo.isMacOSLion) return;
              Window window = e.getWindow();
              if (window instanceof Dialog) {
                ID _native = MacUtil.findWindowForTitle(((Dialog) window).getTitle());
                if (_native != null && _native.intValue() > 0) {
                  // see MacMainFrameDecorator
                  // NSCollectionBehaviorFullScreenAuxiliary = 1 << 8
                  Foundation.invoke(_native, "setCollectionBehavior:", 1 << 8);
                }
              }
            }
          });

      if (Registry.is("actionSystem.fixLostTyping")) {
        final IdeEventQueue queue = IdeEventQueue.getInstance();
        if (queue != null) {
          queue.getKeyEventDispatcher().resetState();
        }

        // if (myProject != null) {
        //   Project project = myProject.get();
        // if (project != null && !project.isDisposed() && project.isInitialized()) {
        // // IdeFocusManager.findInstanceByComponent(this).requestFocus(new
        // MyFocusCommand(dialogWrapper), true);
        // }
        // }
      }

      if (SystemInfo.isMac
          && myProject != null
          && Registry.is("ide.mac.fix.dialog.showing")
          && !dialogWrapper.isModalProgress()) {
        final IdeFrame frame = WindowManager.getInstance().getIdeFrame(myProject.get());
        AppIcon.getInstance().requestFocus(frame);
      }

      setBackground(UIUtil.getPanelBackground());

      final ApplicationEx app = ApplicationManagerEx.getApplicationEx();
      if (app != null && !app.isLoaded() && Splash.BOUNDS != null) {
        final Point loc = getLocation();
        loc.y = Splash.BOUNDS.y + Splash.BOUNDS.height;
        setLocation(loc);
      }
      super.show();
    }
コード例 #6
0
 @Override
 public void setBounds(Rectangle r) {
   ScreenUtil.fitToScreen(r);
   super.setBounds(r);
 }
コード例 #7
0
 @Override
 public void setBounds(int x, int y, int width, int height) {
   Rectangle rect = new Rectangle(x, y, width, height);
   ScreenUtil.fitToScreen(rect);
   super.setBounds(rect.x, rect.y, rect.width, rect.height);
 }