javax.swing.SwingUtilities#getWindowAncestor ( )源码实例Demo

下面列出了javax.swing.SwingUtilities#getWindowAncestor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: swift-explorer   文件: MainPanel.java
/**
 * {@inheritDoc}.
 */
@Override
public void onDone() {

    if (busyCnt.decrementAndGet() == 0) {
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        statusPanel.onEnd();
        
        stopper.deleteObservers(); // because busyCnt equals zero
        
        ComputerSleepingManager.INSTANCE.keepAwake(false);
        
        progressButton.setEnabled(false);
        progressPanel.done() ;
        Window progressWindow = SwingUtilities.getWindowAncestor(progressPanel);            
        if (progressWindow != null)
        	progressWindow.setVisible(false) ;
    }
    enableDisable();
}
 
源代码2 项目: pumpernickel   文件: BasicSaveLocationPaneUI.java
protected void repackIfNecessary() {
	Window window = SwingUtilities.getWindowAncestor(locationPane);
	if (window == null)
		return;

	window.pack();

	// TODO: make this a little smarter
	/*
	 * if(isExpanded()==false) { window.pack(); return; }
	 * 
	 * Dimension realSize = locationPane.getSize(); Dimension preferredSize
	 * = locationPane.getPreferredSize();
	 * 
	 * if(realSize.height<preferredSize.height) { int deltaHeight =
	 * preferredSize.height-realSize.height; Dimension d = window.getSize();
	 * d.height += deltaHeight; window.setSize(d); }
	 */
}
 
源代码3 项目: 3Dscript   文件: AnimationAutoCompletion.java
/**
 * Called when the component hierarchy for our text component changes.
 * When the text component is added to a new {@link Window}, this method
 * registers listeners on that <code>Window</code>.
 *
 * @param e The event.
 */
@Override
public void hierarchyChanged(HierarchyEvent e) {

	// NOTE: e many be null as we call this method at other times.
	// System.out.println("Hierarchy changed! " + e);

	Window oldParentWindow = parentWindow;
	parentWindow = SwingUtilities.getWindowAncestor(textComponent);
	if (parentWindow != oldParentWindow) {
		if (oldParentWindow != null) {
			parentWindowListener.removeFrom(oldParentWindow);
		}
		if (parentWindow != null) {
			parentWindowListener.addTo(parentWindow);
		}
	}

}
 
源代码4 项目: openjdk-8-source   文件: WindowsRootPaneUI.java
public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed()) {
        // do not manage consumed event
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
源代码5 项目: netbeans   文件: AdjustConfigurationPanel.java
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getSource() == currentPanel) {
        if ("contentLoaded".equals(evt.getPropertyName())) { // NOI18N
                Window w = SwingUtilities.getWindowAncestor(this);
                if (w != null) {
                    w.pack();
                }
        }
    }
}
 
源代码6 项目: hottub   文件: WindowsRootPaneUI.java
public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed()) {
        // do not manage consumed event
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
源代码7 项目: MeteoInfo   文件: LayersLegend.java
private void onLabelClick(ActionEvent e) {
    LayerNode aLN = (LayerNode) _selectedNode;
    MapLayer aLayer = aLN.getMapFrame().getMapView().getLayerByHandle(aLN.getLayerHandle());
    if (aLayer.getLayerType() == LayerTypes.VectorLayer) {
        VectorLayer layer = (VectorLayer) aLayer;
        if (layer.getShapeNum() > 0) {
            JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this);
            FrmLabelSet aFrmLabel = new FrmLabelSet(frame, false, this.getActiveMapFrame().getMapView());
            aFrmLabel.setLayer(layer);
            aFrmLabel.setLocationRelativeTo(frame);
            aFrmLabel.setVisible(true);
        }
    }
}
 
源代码8 项目: pumpernickel   文件: MovWriterDemo.java
public void addAudio() {
	Frame frame = (Frame) SwingUtilities.getWindowAncestor(this);
	File file = FileDialogUtils.showOpenDialog(frame, "Open Audio", "wav",
			"aif");
	if (file == null)
		return;
	audioFileList.add(file);
}
 
源代码9 项目: gate-core   文件: DocumentEditor.java
@Override
public void actionPerformed(ActionEvent evt) {
  if(searchDialog == null) {
    Window parent = SwingUtilities.getWindowAncestor(DocumentEditor.this);
    searchDialog =
        (parent instanceof Dialog)
            ? new SearchDialog((Dialog)parent)
            : new SearchDialog((Frame)parent);
    searchDialog.pack();
    searchDialog.setLocationRelativeTo(DocumentEditor.this);
    searchDialog.setResizable(true);
    MainFrame.getGuiRoots().add(searchDialog);
  }
  JTextComponent textPane = getTextComponent();
  // if the user never gives the focus to the textPane then
  // there will never be any selection in it so we force it
  textPane.requestFocusInWindow();
  // put the selection of the document into the search text field
  if(textPane.getSelectedText() != null) {
    searchDialog.patternTextField.setText(textPane.getSelectedText());
  }
  if(searchDialog.isVisible()) {
    searchDialog.toFront();
  } else {
    searchDialog.setVisible(true);
  }
  searchDialog.patternTextField.selectAll();
  searchDialog.patternTextField.requestFocusInWindow();
}
 
源代码10 项目: snap-desktop   文件: MaskFormActions.java
static Window getWindow(ActionEvent e) {
    Object source = e.getSource();
    Window window = null;
    if (source instanceof Component) {
        Component component = (Component) source;
        window = SwingUtilities.getWindowAncestor(component);
    }
    return window;
}
 
源代码11 项目: netbeans   文件: StringTableCellEditor.java
@Override
public void hierarchyChanged(HierarchyEvent e) {
    Window window = SwingUtilities.getWindowAncestor(pane);
    if (window instanceof Dialog) {
        Dialog dialog = (Dialog) window;
        if (!dialog.isResizable()) {
            dialog.setResizable(true);
        }
    }
}
 
源代码12 项目: LGoodDatePicker   文件: DatePicker.java
/**
 * zSetPopupLocation, This calculates and sets the appropriate location for the popup windows,
 * for both the DatePicker and the TimePicker.
 */
static void zSetPopupLocation(CustomPopup popup, int defaultX, int defaultY, JComponent picker,
        JComponent verticalFlipReference, int verticalFlipDistance, int bottomOverlapAllowed) {
    // Gather some variables that we will need.
    Window topWindowOrNull = SwingUtilities.getWindowAncestor(picker);
    Rectangle workingArea = InternalUtilities.getScreenWorkingArea(topWindowOrNull);
    int popupWidth = popup.getBounds().width;
    int popupHeight = popup.getBounds().height;
    // Calculate the default rectangle for the popup.
    Rectangle popupRectangle = new Rectangle(defaultX, defaultY, popupWidth, popupHeight);
    // If the popup rectangle is below the bottom of the working area, then move it upwards by 
    // the minimum amount which will ensure that it will never cover the picker component.
    if (popupRectangle.getMaxY() > (workingArea.getMaxY() + bottomOverlapAllowed)) {
        popupRectangle.y = verticalFlipReference.getLocationOnScreen().y - popupHeight
                - verticalFlipDistance;
    }
    // Confine the popup to be within the working area.
    if (popupRectangle.getMaxX() > (workingArea.getMaxX())) {
        popupRectangle.x -= (popupRectangle.getMaxX() - workingArea.getMaxX());
    }
    if (popupRectangle.getMaxY() > (workingArea.getMaxY() + bottomOverlapAllowed)) {
        popupRectangle.y -= (popupRectangle.getMaxY() - workingArea.getMaxY());
    }
    if (popupRectangle.x < workingArea.x) {
        popupRectangle.x += (workingArea.x - popupRectangle.x);
    }
    if (popupRectangle.y < workingArea.y) {
        popupRectangle.y += (workingArea.y - popupRectangle.y);
    }
    // Set the location of the popup.
    popup.setLocation(popupRectangle.x, popupRectangle.y);
}
 
源代码13 项目: beautyeye   文件: Platform.java
/**
 * Finds out the monitor where the user currently has the input focus.
 * This method is usually used to help the client code to figure out on
 * which monitor it should place newly created windows/frames/dialogs.
 *
 * @return the GraphicsConfiguration of the monitor which currently has the
 * input focus
 */
private static GraphicsConfiguration getCurrentGraphicsConfiguration() {
    Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (focusOwner != null) {
        Window w = SwingUtilities.getWindowAncestor(focusOwner);
        if (w != null) {
            return w.getGraphicsConfiguration();
        }
    }

    return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}
 
源代码14 项目: netbeans   文件: DecorationUtils.java
public void mouseDragged(MouseEvent e) {
    check(e);
    Window w = SwingUtilities.getWindowAncestor((Component)e.getSource());

    if (Cursor.DEFAULT_CURSOR == cursorType) {
        // resize only when mouse pointer in resize areas
        return;
    }

    Rectangle newBounds = computeNewBounds(w, getScreenLoc(e));
    if (!w.getBounds().equals(newBounds)) {
        w.setBounds(newBounds);
    }
}
 
源代码15 项目: pumpernickel   文件: PreferencePanel.java
private void repack() {
	contents.animateStates(layoutRunnable);
	Window w = SwingUtilities.getWindowAncestor(this);

	if (w != null) {
		// TODO: this feature never really got off the ground, nor was it
		// essential.
		// if(animateResizing) {
		// contents.resizeWindow();
		// } else {
		w.pack();
		// }
	}
}
 
源代码16 项目: cropplanning   文件: CPSDialog.java
public CPSDialog ( Component parent, String title ) {

      super( (JFrame) SwingUtilities.getWindowAncestor(parent), true );

      this.parent = parent;
      
        header = new JXTitledPanel();
        header.setBorder(BorderFactory.createEmptyBorder());
        setTitle( title );
        
        initContentsPanel();
        
        initButtonPanel();
        fillButtonPanel();
        
        buildMainPanel();
     
        super.add( jplMain );
        
    }
 
源代码17 项目: MeteoInfo   文件: LegendView.java
private void showSymbolSetForm(ColorBreak aCB) {
    switch (_legendScheme.getBreakType()) {
        case PointBreak:
            PointBreak aPB = (PointBreak) aCB;

            if (_frmPointSymbolSet == null) {
                _frmPointSymbolSet = new FrmPointSymbolSet((JDialog) SwingUtilities.getWindowAncestor(this), false, this);
                _frmPointSymbolSet.setLocationRelativeTo(this);
                _frmPointSymbolSet.setVisible(true);
            }
            _frmPointSymbolSet.setPointBreak(aPB);
            _frmPointSymbolSet.setVisible(true);
            break;
        case PolylineBreak:
            PolylineBreak aPLB = (PolylineBreak) aCB;

            if (_frmPolylineSymbolSet == null) {
                _frmPolylineSymbolSet = new FrmPolylineSymbolSet((JDialog) SwingUtilities.getWindowAncestor(this), false, this);
                _frmPolylineSymbolSet.setLocationRelativeTo(this);
                _frmPolylineSymbolSet.setVisible(true);
            }
            _frmPolylineSymbolSet.setPolylineBreak(aPLB);
            _frmPolylineSymbolSet.setVisible(true);
            break;
        case PolygonBreak:
            PolygonBreak aPGB = (PolygonBreak) aCB;

            if (_frmPolygonSymbolSet == null) {
                _frmPolygonSymbolSet = new FrmPolygonSymbolSet((JDialog) SwingUtilities.getWindowAncestor(this), false, this);
                _frmPolygonSymbolSet.setLocationRelativeTo(this);
                _frmPolygonSymbolSet.setVisible(true);
            }
            _frmPolygonSymbolSet.setPolygonBreak(aPGB);
            _frmPolygonSymbolSet.setVisible(true);
            break;
        case ColorBreak:
            if (_frmColorSymbolSet == null) {
                _frmColorSymbolSet = new FrmColorSymbolSet((JDialog) SwingUtilities.getWindowAncestor(this), false, this);
                _frmColorSymbolSet.setLocationRelativeTo(this);
                _frmColorSymbolSet.setVisible(true);
            }
            _frmColorSymbolSet.setColorBreak(aCB);
            _frmColorSymbolSet.setVisible(true);
            break;
    }
}
 
源代码18 项目: pumpernickel   文件: QPopup.java
private boolean showUsingRootPaneContainer(Point screenLoc,
		CalloutType calloutType) {
	Window ownerWindow = owner instanceof Window ? (Window) owner
			: SwingUtilities.getWindowAncestor(owner);
	RootPaneContainer rpc = ownerWindow instanceof RootPaneContainer
			? (RootPaneContainer) ownerWindow
			: null;

	if (rpc == null)
		return false;

	JLayeredPane layeredPane = rpc.getLayeredPane();
	Point layeredPaneLoc = new Point(screenLoc);
	SwingUtilities.convertPointFromScreen(layeredPaneLoc, layeredPane);

	if (calloutType == null) {
		ui.setCalloutType(CalloutType.TOP_CENTER);
		ui.setCalloutSize(0);
	} else {
		ui.setCalloutType(calloutType);
		ui.setCalloutSize(CALLOUT_SIZE);
	}

	contents.validate();
	contents.setSize(contents.getPreferredSize());

	Rectangle layeredPaneBounds = new Rectangle(layeredPaneLoc.x,
			layeredPaneLoc.y, contents.getWidth(), contents.getHeight());
	if (calloutType != null) {
		Point calloutTip = ui.getCalloutTip(contents);
		layeredPaneBounds.x -= calloutTip.x;
		layeredPaneBounds.y -= calloutTip.y;
	}

	if (new Rectangle(0, 0, layeredPane.getWidth(), layeredPane.getHeight())
			.contains(layeredPaneBounds)) {

		if (contents.getParent() != layeredPane) {
			hide();
			layeredPane.add(contents, JLayeredPane.POPUP_LAYER);
		}

		contents.setBounds(layeredPaneBounds);
		contents.setVisible(true);

		return true;
	}
	return false;
}
 
源代码19 项目: netbeans   文件: NotifyLaterTest.java
public void testIfLasterWhenSplashShownThanWaitTillItFinished() throws Exception {
    class MyObj extends JComponent {
        public int called;
        
        public void addNotify() {
            called = 1;
            LOG.log(Level.INFO, "addNotify called=" + called, new Exception("Stacktrace"));
            super.addNotify();
        }
    }
    MyObj obj = new MyObj();

    LOG.info("createDescriptor");
    NotifyDescriptor ownerDD = createDescriptor(obj);
    LOG.info("createDescriptor = " + ownerDD);

    LOG.info("notifyLater");
    DialogDisplayer.getDefault ().notifyLater(ownerDD);
    LOG.info("done notifyLater");
    waitAWT();
    LOG.info("check");
    assertEquals("No notify yet", 0, obj.called);//fail("Ok");
    
    DialogDisplayerImplTest.postInAwtAndWaitOutsideAwt(new Runnable () {
        public void run() {
            DialogDisplayerImpl.runDelayed();
        }
    });
    
    
    waitAWT();
    assertEquals("Now it is showing", 1, obj.called);
    
    assertTrue("Is visible", obj.isShowing());
    Window root = SwingUtilities.getWindowAncestor(obj);
    assertNotNull("There is parent window", root);
    assertTrue("It is a dialog", root instanceof JDialog);
    JDialog d = (JDialog)root;
    assertEquals("The owner of d is the same as owner of dialog without owner", new JDialog().getParent(), d.getParent());
    
    SwingUtilities.invokeAndWait(new Runnable () {
        public void run() {
            DialogDisplayerImpl.runDelayed();
        }
    });
}
 
源代码20 项目: visualvm   文件: ProfilerTableHovers.java
private static boolean isInFocusedWindow(Component c) {
    Window w = SwingUtilities.getWindowAncestor(c);
    return w != null && w.isFocused();
}