예제 #1
0
  protected void processCancel(ActionEvent event, boolean reallyCancel) {
    DeferredWizardResult deferredResult = parent.getDeferredResult();
    if (deferredResult != null && deferredResult.canAbort()) deferredResult.abort();
    Wizard wizard = parent.getWizard();
    MergeMap settings = parent.getSettings();

    boolean closeWindow;

    if (reallyCancel && parent.cancel()) {
      wizard.cancel(settings);
      return;
    }

    closeWindow = reallyCancel ? wizard.cancel(settings) : parent.receiver == null;

    // if we have the event (allowFinish was not deferred) then be very sure to close the proper
    // dialog
    if (closeWindow) {
      Window win =
          event != null
              ? (Window) ((JComponent) event.getSource()).getTopLevelAncestor()
              : getWindow();
      win.setVisible(false);
      win.dispose();
    }
  }
예제 #2
0
  public void start(KeyboardManager keymgr, Window root, RunQueue rqueue) {
    EventListener listener = new EventListener();
    try {
      // try to add a global event listener
      Toolkit.getDefaultToolkit().addAWTEventListener(listener, EVENT_MASK);
    } catch (SecurityException se) {
      // fall back to listening to our main window
      if (root != null) {
        root.addKeyListener(listener);
        root.addMouseListener(listener);
        root.addMouseMotionListener(listener);
      }
    }

    // and tie into the keyboard manager if one is provided
    if (keymgr != null) {
      keymgr.registerKeyObserver(
          new KeyboardManager.KeyObserver() {
            public void handleKeyEvent(int id, int keyCode, long timestamp) {
              handleUserActivity();
            }
          });
    }

    // register an interval to periodically check our last activity time
    new Interval(rqueue) {
      @Override
      public void expired() {
        checkIdle();
      }
    }.schedule(_toIdleTime / 3, true);
  }
  @Override
  public Point getLocationOnScreen(final Window frame) {
    try {
      final LocationStorage cfg = createConfig(frame);
      if (cfg.isValid()) {
        if ("absolute".equalsIgnoreCase(cfg.getType())) {
          return AbstractLocator.validate(new Point(cfg.getX(), cfg.getY()), frame);
        }
        // Do a "is on screen check" here
        Window parent = getParent();
        Container actualParent = frame.getParent();
        Point pLoc = null;

        if (parent != null) {
          pLoc = parent.getLocationOnScreen();
        }
        if (pLoc == null && actualParent != null) {
          pLoc = actualParent.getLocationOnScreen();
        }
        if (pLoc == null) {
          return getFallbackLocator().getLocationOnScreen(frame);
        }
        return AbstractLocator.validate(new Point(cfg.getX() + pLoc.x, cfg.getY() + pLoc.y), frame);
      }
    } catch (final Throwable e) {

      // frame.getParent() might be null or invisble
      // e.printStackTrace();
    }
    return getFallbackLocator().getLocationOnScreen(frame);
  }
 private void disposeAndUpdate(boolean update) {
   if (myView != null) {
     boolean visible = myView.isVisible();
     myView.setVisible(false);
     Container container = myContent.getParent();
     if (container != null) {
       container.remove(myContent);
     }
     if (myView instanceof Window) {
       myViewBounds = myView.getBounds();
       Window window = (Window) myView;
       if (!push(UIUtil.getWindow(myOwner), window)) {
         window.dispose();
       }
     } else {
       Container parent = myView.getParent();
       if (parent == null) {
         myViewBounds = new Rectangle(myContent.getPreferredSize());
       } else {
         myViewBounds = new Rectangle(myView.getBounds());
         parent.remove(myView);
         Point point = new Point(myViewBounds.x, myViewBounds.y);
         SwingUtilities.convertPointToScreen(point, parent);
         myViewBounds.x = point.x;
         myViewBounds.y = point.y;
       }
     }
     myView = null;
     if (update && visible) {
       setVisible(true);
     }
   }
 }
  static void subscribeTo(NavBarPanel panel) {
    if (panel.getClientProperty(LISTENER) != null) {
      unsubscribeFrom(panel);
    }

    final NavBarListener listener = new NavBarListener(panel);
    final Project project = panel.getProject();
    panel.putClientProperty(LISTENER, listener);
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(listener);
    FileStatusManager.getInstance(project).addFileStatusListener(listener);
    PsiManager.getInstance(project).addPsiTreeChangeListener(listener);
    WolfTheProblemSolver.getInstance(project).addProblemListener(listener);
    ActionManager.getInstance().addAnActionListener(listener);

    final MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, listener);
    connection.subscribe(NavBarModelListener.NAV_BAR, listener);
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
    panel.putClientProperty(BUS, connection);
    panel.addKeyListener(listener);

    if (panel.isInFloatingMode()) {
      final Window window = SwingUtilities.windowForComponent(panel);
      if (window != null) {
        window.addWindowFocusListener(listener);
      }
    }
  }
  private void maybeShowFor(Component c, MouseEvent me) {
    if (!(c instanceof JComponent)) return;

    JComponent comp = (JComponent) c;
    Window wnd = SwingUtilities.getWindowAncestor(comp);
    if (wnd == null) return;

    if (!wnd.isActive()) {
      if (JBPopupFactory.getInstance().isChildPopupFocused(wnd)) return;
    }

    String tooltipText = comp.getToolTipText(me);
    if (tooltipText == null || tooltipText.trim().isEmpty()) return;

    boolean centerDefault =
        Boolean.TRUE.equals(comp.getClientProperty(UIUtil.CENTER_TOOLTIP_DEFAULT));
    boolean centerStrict =
        Boolean.TRUE.equals(comp.getClientProperty(UIUtil.CENTER_TOOLTIP_STRICT));
    int shift = centerStrict ? 0 : centerDefault ? 4 : 0;

    // Balloon may appear exactly above useful content, such behavior is rather annoying.
    if (c instanceof JTree) {
      TreePath path = ((JTree) c).getClosestPathForLocation(me.getX(), me.getY());
      if (path != null) {
        Rectangle pathBounds = ((JTree) c).getPathBounds(path);
        if (pathBounds != null && pathBounds.y + 4 < me.getY()) {
          shift += me.getY() - pathBounds.y - 4;
        }
      }
    }

    queueShow(comp, me, centerStrict || centerDefault, shift, -shift, -shift);
  }
예제 #7
0
 /*
  * Retrieves the owner of the peer.
  * Note: this method returns the owner which can be activated, (i.e. the instance
  * of Frame or Dialog may be returned).
  */
 static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
   Window owner = (peer != null ? peer.getTarget().getOwner() : null);
   while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
     owner = owner.getOwner();
   }
   return owner == null ? null : (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
 }
예제 #8
0
  void test3(Window owner, Window child1, Window child2) {
    System.out.println("* * * STAGE 3 * * *\nWidow owner: " + owner);

    owner.setFocusableWindowState(true);
    owner.setVisible(true);

    child1.setFocusableWindowState(false);
    child1.setVisible(true);

    child2.setFocusableWindowState(true);
    child2.add(button);
    child2.setVisible(true);

    Util.waitTillShown(child2);

    Util.clickOnComp(button, robot);
    System.err.println(
        "focus owner: " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
    if (button != KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
      throw new RuntimeException("Test failed.");
    }
    child1.dispose();
    child2.dispose();
    owner.dispose();
  }
 public final boolean isAlphaModeEnabled(final Window window) {
   if (!window.isDisplayable() || !window.isShowing()) {
     throw new IllegalArgumentException(
         "window must be displayable and showing. window=" + window);
   }
   return isAlphaModeSupported();
 }
 /** Restores the screen's display mode. */
 public void restoreScreen() {
   Window window = device.getFullScreenWindow();
   if (window != null) {
     window.dispose();
   }
   device.setFullScreenWindow(null);
 }
예제 #11
0
  /** Returns the popup type to use for the specified parameters. */
  private int getPopupType(Component owner, Component contents, int ownerX, int ownerY) {
    int popupType = getPopupType();

    if (owner == null || invokerInHeavyWeightPopup(owner)) {
      popupType = HEAVY_WEIGHT_POPUP;
    } else if (popupType == LIGHT_WEIGHT_POPUP
        && !(contents instanceof JToolTip)
        && !(contents instanceof JPopupMenu)) {
      popupType = MEDIUM_WEIGHT_POPUP;
    }

    // Check if the parent component is an option pane.  If so we need to
    // force a heavy weight popup in order to have event dispatching work
    // correctly.
    Component c = owner;
    while (c != null) {
      if (c instanceof JComponent) {
        if (((JComponent) c).getClientProperty(PopupFactory_FORCE_HEAVYWEIGHT_POPUP)
            == Boolean.TRUE) {
          popupType = HEAVY_WEIGHT_POPUP;
          break;
        }
      } else if (c instanceof Window) {
        Window w = (Window) c;
        if (!w.isOpaque() || w.getOpacity() < 1 || w.getShape() != null) {
          popupType = HEAVY_WEIGHT_POPUP;
          break;
        }
      }
      c = c.getParent();
    }

    return popupType;
  }
예제 #12
0
 static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
   Window owner = (peer != null ? peer.getTarget().getOwner() : null);
   while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
     owner = owner.getOwner();
   }
   return owner != null ? (LWWindowPeer) owner.getPeer() : null;
 }
예제 #13
0
  /**
   * Applies this geometry to a window. Makes sure that the window is not placed outside of the
   * coordinate range of all available screens.
   *
   * @param window the window
   */
  public void applySafe(Window window) {
    Point p = new Point(topLeft);

    Rectangle virtualBounds = new Rectangle();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (GraphicsDevice gd : gs) {
      if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
        virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds());
      }
    }

    if (p.x < virtualBounds.x) {
      p.x = virtualBounds.x;
    } else if (p.x > virtualBounds.x + virtualBounds.width - extent.width) {
      p.x = virtualBounds.x + virtualBounds.width - extent.width;
    }

    if (p.y < virtualBounds.y) {
      p.y = virtualBounds.y;
    } else if (p.y > virtualBounds.y + virtualBounds.height - extent.height) {
      p.y = virtualBounds.y + virtualBounds.height - extent.height;
    }

    window.setLocation(p);
    window.setSize(extent);
  }
예제 #14
0
 /** Recupera el modo de pantalla no completa */
 public void recuperarPantalla() {
   Window window = device.getFullScreenWindow();
   if (window != null) {
     window.dispose();
   }
   device.setFullScreenWindow(null);
 }
예제 #15
0
    protected void repack() {

      Window w = SwingUtilities.getWindowAncestor(panel);
      if (w != null) {
        w.pack();
      }
    }
  private void close() {
    Window window = getWindow();

    if (window != null) {
      window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
    }
  }
예제 #17
0
  private void shoutAlert(Collection<ChatMessage> shouts) {
    Window window = SwingUtilities.windowForComponent(this);
    boolean windowActive = window.isActive();
    if (windowActive) return;

    alertUser(shouts);
  }
  private void updateSystemIcon() {
    Window window = getWindow();
    if (window == null) {
      mySystemIcon = null;
      return;
    }

    List<Image> icons = window.getIconImages();
    assert icons != null;

    if (icons.size() == 0) {
      mySystemIcon = null;
    } else if (icons.size() == 1) {
      mySystemIcon = icons.get(0);
    } else {
      final JBDimension size = JBUI.size(32);
      final Image image = icons.get(0);
      mySystemIcon =
          Scalr.resize(
              ImageUtil.toBufferedImage(image),
              Scalr.Method.ULTRA_QUALITY,
              size.width,
              size.height);
    }
  }
예제 #19
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);
  }
예제 #20
0
  /**
   * Tries to load/restore the window state of the given window.
   *
   * @param aNamespace the namespace to use for the window state;
   * @param aProperties the properties to read from;
   * @param aWindow the window to load the state for.
   */
  public static void loadWindowState(final Preferences aProperties, final Window aWindow) {
    // Special case: for FileDialog/JFileChooser we also should restore the
    // properties...
    loadFileDialogState(aProperties, aWindow);

    try {
      final int xPos = aProperties.getInt("winXpos", -1);
      final int yPos = aProperties.getInt("winYpos", -1);
      if ((xPos >= 0) && (yPos >= 0)) {
        aWindow.setLocation(xPos, yPos);
      }
    } catch (NumberFormatException exception) {
      // Ignore...
    }

    if (isNonResizableWindow(aWindow)) {
      // In case the window cannot be resized, don't restore its width &
      // height...
      return;
    }

    try {
      final int width = aProperties.getInt("winWidth", -1);
      final int height = aProperties.getInt("winHeight", -1);
      if ((width >= 0) && (height >= 0)) {
        aWindow.setSize(width, height);
      }
    } catch (NumberFormatException exception) {
      // Ignore...
    }
  }
예제 #21
0
    @Override
    public void paint(Graphics g) {
      if ((target instanceof Frame && !(target instanceof JFrame))
          || (target instanceof Dialog && !(target instanceof JDialog))) {
        SwingBaseWindow<?, ?> sf = SwingBaseWindow.this;
        Window f = target;

        Color bg = f.getBackground();
        if (bg == null) bg = UIManager.getColor("window");
        if (bg == null) bg = UIManager.getColor("control");
        if (bg == null) bg = Color.GRAY;

        g.setColor(bg);
        g.fillRect(0, 0, getWidth(), getHeight());

        Point f_loc = sf.getLocationOnScreen();
        Point p_loc = this.getLocationOnScreen();

        int dx = p_loc.x - f_loc.x;
        int dy = p_loc.y - f_loc.y;

        for (Component c : f.getComponents()) {
          Graphics cg = g.create(c.getX() - dx, c.getY() - dy, c.getWidth(), c.getHeight());
          c.paintAll(cg);
          cg.dispose();
        }
      }
    }
예제 #22
0
 // get out of full screen
 public void restoreScreen() {
   Window w = vc.getFullScreenWindow();
   if (w != null) {
     w.dispose();
   }
   vc.setFullScreenWindow(null);
 }
예제 #23
0
  public void actionPerformed(ActionEvent evt) {
    if (model.names().isEmpty() || model.files().isEmpty()) {
      return;
    }

    BackgroundMatcher backgroundMatcher =
        new BackgroundMatcher(model, EpisodeMetrics.defaultSequence(true));
    backgroundMatcher.execute();

    Window window = getWindow(evt.getSource());
    window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    try {
      // wait a for little while (matcher might finish in less than a second)
      backgroundMatcher.get(2, TimeUnit.SECONDS);
    } catch (TimeoutException ex) {
      // matcher will probably take a while
      ProgressDialog dialog = createProgressDialog(window, backgroundMatcher);
      dialog.setLocation(getOffsetLocation(dialog.getOwner()));

      // display progress dialog and stop blocking EDT
      dialog.setVisible(true);
    } catch (Exception e) {
      Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e);
    } finally {
      window.setCursor(Cursor.getDefaultCursor());
    }
  }
예제 #24
0
  @IMEventHandler(IMEventType.SHOW_MEMBERS_WINDOW)
  protected void showMembersWindow(IMEvent event) {
    UINamedObject named = (UINamedObject) event.getTarget();
    Window win = event.getData("view");
    Rectangle rect = win.getBounds();
    setLocation(rect.x + rect.width - 30, rect.y + 25);

    setIconImage(named.getIcon());
    setTitle(named.getName());
    this.namedObject = named;

    progressOverlay.setShowLoad(true);
    setVisible(true);

    isLoadFace = true; // 设置允许下载头像

    checkReloadMembers(namedObject); // 显示成员

    win.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentMoved(ComponentEvent e) {
            int x = e.getComponent().getX() + e.getComponent().getWidth() - 30;
            int y = e.getComponent().getY() + 25;
            if (isPtInRect(getBounds(), new Point(x, y))) {
              setLocation(x, y);
            }
          }
        });
  }
예제 #25
0
파일: Tray.java 프로젝트: Tyf0n/musique
    private void showJPopupMenu(MouseEvent e) {
      try {
        if (e.isPopupTrigger() && menu != null) {
          if (window == null) {

            if (isWindows) {
              window = new JDialog((Frame) null);
              ((JDialog) window).setUndecorated(true);
            } else {
              window = new JWindow((Frame) null);
            }
            window.setAlwaysOnTop(true);
            Dimension size = menu.getPreferredSize();

            Point centerPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
            if (e.getY() > centerPoint.getY()) window.setLocation(e.getX(), e.getY() - size.height);
            else window.setLocation(e.getX(), e.getY());

            window.setVisible(true);

            menu.show(((RootPaneContainer) window).getContentPane(), 0, 0);

            // popup works only for focused windows
            window.toFront();
          }
        }
      } catch (Exception ignored) {
      }
    }
예제 #26
0
  @IMEventHandler(IMEventType.SHOW_MSG_HISTORY_WINDOW)
  protected void processIMShowWindow(IMEvent event) {
    namedObject = (UINamedObject) event.getTarget();
    setTitle(namedObject.getName() + " - Message History.");

    Window win = event.getData("view");
    Rectangle rect = win.getBounds();
    setLocation(rect.x + rect.width - 50, rect.y);
    setSize(getWidth(), rect.height);
    validate();
    setVisible(true);

    currentPage = 0;
    totalPage = 0;

    // 显示消息
    IMEvent imEvent = new IMEvent(IMEventType.MSG_HISTORY_FIND, namedObject.getEntity());
    imEvent.putData("limit", limit);
    IMEventService events = getContext().getSerivce(IMService.Type.EVENT);
    events.broadcast(imEvent);

    win.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentMoved(ComponentEvent e) {
            int x = e.getComponent().getX() + e.getComponent().getWidth() - 50;
            int y = e.getComponent().getY();
            if (isPtInRect(getBounds(), new Point(x, y))) {
              setLocation(x, y);
              setSize(getWidth(), e.getComponent().getHeight());
            }
          }
        });
  }
예제 #27
0
    public void mouseMoved(MouseEvent ev) {
      JRootPane root = getRootPane();

      if (root.getWindowDecorationStyle() == JRootPane.NONE) {
        return;
      }

      Window w = (Window) ev.getSource();

      Frame f = null;
      Dialog d = null;

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

      // Update the cursor
      int cursor = getCursor(calculateCorner(w, ev.getX(), ev.getY()));

      if (cursor != 0
          && ((f != null && (f.isResizable() && (f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0))
              || (d != null && d.isResizable()))) {
        w.setCursor(Cursor.getPredefinedCursor(cursor));
      } else {
        w.setCursor(lastCursor);
      }
    }
예제 #28
0
 protected void applyWindowLevel(Window target) {
   if (target.isAlwaysOnTop() && target.getType() != Window.Type.POPUP) {
     CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel);
   } else if (target.getType() == Window.Type.POPUP) {
     CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSPopUpMenuWindowLevel);
   }
 }
예제 #29
0
파일: KeyTest.java 프로젝트: Gogoro/Undef
 // draw on screen
 public synchronized void draw(Graphics2D g) {
   Window w = s.getFullScreenWindow();
   g.setColor(w.getBackground());
   g.fillRect(0, 0, s.getWidth(), s.getHeight());
   g.setColor(w.getForeground());
   g.drawString(mess, 100, 100);
 }
예제 #30
0
 /**
  * @param component component
  * @return whether the component in Swing tree or not. This method is more weak then {@link
  *     Component#isShowing() }
  */
 private boolean isInTree(final Component component) {
   if (component instanceof Window) {
     return component.isShowing();
   } else {
     Window windowAncestor = SwingUtilities.getWindowAncestor(component);
     return windowAncestor != null && windowAncestor.isShowing();
   }
 }