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

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

源代码1 项目: netbeans   文件: TopComponentDraggable.java
Rectangle getBounds() {
    Rectangle bounds = null;
    TopComponent modeTC = getTopComponent();
    if( null == modeTC ) {
        modeTC = mode.getSelectedTopComponent();
        if( null == modeTC ) {
            TopComponent[] tcs = mode.getTopComponents();
            if( null != tcs && tcs.length > 0 )
                modeTC = tcs[0];
        }
    }
    Component modeComp = ( Component ) SwingUtilities.getAncestorOfClass(ModeComponent.class, modeTC);
    if( modeComp != null ) {
        bounds = modeComp.getBounds();
    }
    return bounds;
}
 
源代码2 项目: netbeans   文件: DrawEngineTest.java
@RandomlyFails
public void testViewToModelConsistency() throws Throwable {
    for(String text : TEXTS) {
        JEditorPane jep = createJep(text);
        try {
            checkViewToModelConsistency(jep);
        } catch (Throwable e) {
            System.err.println("testViewToModelConsistency processing {");
            System.err.println(text);
            System.err.println("} failed with:");
            e.printStackTrace();
            throw e;
        } finally {
            JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, jep);
            if (frame != null) {
                frame.dispose();
            }
        }
    }
}
 
源代码3 项目: netbeans   文件: EditorUI.java
public final int getSideBarWidth(){
    JScrollPane scroll = (JScrollPane)SwingUtilities.getAncestorOfClass(JScrollPane.class, getParentViewport());
    if (scroll!=null && scroll.getRowHeader()!=null){
        Rectangle bounds = scroll.getRowHeader().getBounds();
        if (bounds!=null){
            return bounds.width;
        }
    }
    return 40;
}
 
源代码4 项目: rapidminer-studio   文件: BeltOpenChartAction.java
@Override
public void loggedActionPerformed(ActionEvent e) {

	// look up the panel invoking the pop up invoking the action
	BeltColumnStatisticsPanel asp = null;

	// the action should only be invoked by AttributePopupMenus
	Container parent = ((JComponent) e.getSource()).getParent();
	if ((parent instanceof BeltColumnPopupMenu)) {
		asp = ((BeltColumnPopupMenu) parent).getColumnStatisticsPanel();
	} else {
		asp = (BeltColumnStatisticsPanel) SwingUtilities.getAncestorOfClass(BeltColumnStatisticsPanel.class, parent);
		if (asp == null) {
			// we are not inside a AttributesStatisticPanel
			return;
		}
	}

	ButtonBarCardPanel cardPanel = (ButtonBarCardPanel) SwingUtilities.getAncestorOfClass(ButtonBarCardPanel.class, asp);
	AbstractBeltColumnStatisticsModel model = asp.getModel();

	// select the visualizations view
	cardPanel.selectCard("visualizations");

	// get the opened visualization
	getOpenedVisualizations(cardPanel, model);
}
 
源代码5 项目: mzmine2   文件: AddAdductsAction.java
@Override
public void actionPerformed(final ActionEvent e) {

  // Parent component.
  final AdductsComponent parent = (AdductsComponent) SwingUtilities
      .getAncestorOfClass(AdductsComponent.class, (Component) e.getSource());

  if (parent != null) {

    // Show dialog.
    final ParameterSet parameters = new AddAdductParameters();
    if (parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(),
        true) == ExitCode.OK) {

      // Create new adduct.
      final AdductType adduct =
          new AdductType(parameters.getParameter(AddAdductParameters.NAME).getValue(),
              parameters.getParameter(AddAdductParameters.MASS_DIFFERENCE).getValue());

      // Add to list of choices (if not already present).
      final Collection<AdductType> choices =
          new ArrayList<AdductType>(Arrays.asList((AdductType[]) parent.getChoices()));
      if (!choices.contains(adduct)) {

        choices.add(adduct);
        parent.setChoices(choices.toArray(new AdductType[choices.size()]));
      }
    }
  }
}
 
源代码6 项目: Luyten   文件: JFontChooser.java
protected JDialog createDialog(Component parent) {
	Frame frame = parent instanceof Frame ? (Frame) parent
			: (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
	JDialog dialog = new JDialog(frame, ("Select Font"), true);

	Action okAction = new DialogOKAction(dialog);
	Action cancelAction = new DialogCancelAction(dialog);

	JButton okButton = new JButton(okAction);
	okButton.setFont(DEFAULT_FONT);
	JButton cancelButton = new JButton(cancelAction);
	cancelButton.setFont(DEFAULT_FONT);

	JPanel buttonsPanel = new JPanel();
	buttonsPanel.setLayout(new GridLayout(2, 1));
	buttonsPanel.add(okButton);
	buttonsPanel.add(cancelButton);
	buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));

	ActionMap actionMap = buttonsPanel.getActionMap();
	actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
	actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
	InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
	inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));

	JPanel dialogEastPanel = new JPanel();
	dialogEastPanel.setLayout(new BorderLayout());
	dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);

	dialog.getContentPane().add(this, BorderLayout.CENTER);
	dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
	dialog.pack();
	dialog.setLocationRelativeTo(frame);
	return dialog;
}
 
源代码7 项目: FlatLaf   文件: FlatListCellBorder.java
@Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
	if( !showCellFocusIndicator )
		return;

	// paint focus indicator border only if exactly one item is selected
	JList<?> list = (JList<?>) SwingUtilities.getAncestorOfClass( JList.class, c );
	if( list != null && list.getMinSelectionIndex() == list.getMaxSelectionIndex() )
		return;

	super.paintBorder( c, g, x, y, width, height );
}
 
源代码8 项目: netbeans   文件: MultiSplitPane.java
public void startResizing( Component child ) {
    doLayout();
    MultiSplitDivider divider = findSplitDividerFor( child );
    if( null == divider )
        return;
    MultiSplitCell resizingCell = findSplitCellFor( child );
    MultiSplitDivider parentDivider = null;
    MultiSplitPane parentSplit = ( MultiSplitPane ) SwingUtilities.getAncestorOfClass( MultiSplitPane.class, this );
    if( null != parentSplit ) {
        parentSplit.doLayout();
        parentDivider = parentSplit.findSplitDividerFor( this );
    }
    ModeResizer.start( resizingCell.getComponent(), divider, parentDivider );
}
 
源代码9 项目: netbeans   文件: PlatformsCustomizer.java
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (ExplorerManager.PROP_SELECTED_NODES.equals (evt.getPropertyName())) {
        Node[] nodes = (Node[]) evt.getNewValue();
        if (nodes.length!=1) {
            selectPlatform (null);
        }
        else {
            selectPlatform (nodes[0]);
            Dialog dialog = (Dialog) SwingUtilities.getAncestorOfClass (Dialog.class, this);
            if (dialog != null)
                dialog.pack ();
        }
    }
}
 
源代码10 项目: MtgDesktopCompanion   文件: ShortKeyModel.java
@Override
public Object getValueAt(int row, int column) {
	switch (column) 
	{
		case 0: return SwingUtilities.getAncestorOfClass(MTGUIComponent.class, items.get(row));	
		case 1: return items.get(row);
		case 2: return KeyEvent.getKeyText(items.get(row).getMnemonic());
		default: throw new IllegalArgumentException("Unexpected value: " + column);
	}
}
 
源代码11 项目: netbeans   文件: DescriptionComponent.java
public void actionPerformed(ActionEvent actionEvent) {
    PSheet sheet = (PSheet) SwingUtilities.getAncestorOfClass(PSheet.class, this);

    if (sheet != null) {
        sheet.helpRequested();
    }
}
 
源代码12 项目: netbeans   文件: PSheet.java
/**
 * Notification method that the user has requested a popup menu.
 */
protected void popupRequested(Point p) {
    PropertySheet ps = (PropertySheet) SwingUtilities.getAncestorOfClass(PropertySheet.class, this);

    if (ps != null) {
        ps.showPopup(p);
    }
}
 
源代码13 项目: netbeans   文件: PSheet.java
/**
 * Notification that the user has pressed the help button
 */
protected void helpRequested() {
    PropertySheet ps = (PropertySheet) SwingUtilities.getAncestorOfClass(PropertySheet.class, this);

    if (ps != null) {
        ps.helpAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "invokeHelp")); //NOI18N
    }
}
 
源代码14 项目: openvisualtraceroute   文件: WrapLayout.java
/**
 * Returns the minimum or preferred dimension needed to layout the target
 * container.
 *
 * @param target target to get layout size for
 * @param preferred should preferred size be calculated
 * @return the dimension to layout the target container
 */
private Dimension layoutSize(final Container target, final boolean preferred) {
	synchronized (target.getTreeLock()) {
		//  Each row must fit with the width allocated to the containter.
		//  When the container width = 0, the preferred width of the container
		//  has not yet been calculated so lets ask for the maximum.

		int targetWidth = target.getSize().width;

		if (targetWidth == 0) {
			targetWidth = Integer.MAX_VALUE;
		}

		final int hgap = getHgap();
		final int vgap = getVgap();
		final Insets insets = target.getInsets();
		final int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
		final int maxWidth = targetWidth - horizontalInsetsAndGap;

		//  Fit components into the allowed width

		final Dimension dim = new Dimension(0, 0);
		int rowWidth = 0;
		int rowHeight = 0;

		final int nmembers = target.getComponentCount();

		for (int i = 0; i < nmembers; i++) {
			final Component m = target.getComponent(i);

			if (m.isVisible()) {
				final Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();

				//  Can't add the component to current row. Start a new row.

				if (rowWidth + d.width > maxWidth) {
					addRow(dim, rowWidth, rowHeight);
					rowWidth = 0;
					rowHeight = 0;
				}

				//  Add a horizontal gap for all components after the first

				if (rowWidth != 0) {
					rowWidth += hgap;
				}

				rowWidth += d.width;
				rowHeight = Math.max(rowHeight, d.height);
			}
		}

		addRow(dim, rowWidth, rowHeight);

		dim.width += horizontalInsetsAndGap;
		dim.height += insets.top + insets.bottom + vgap * 2;

		//	When using a scroll pane or the DecoratedLookAndFeel we need to
		//  make sure the preferred size is less than the size of the
		//  target containter so shrinking the container size works
		//  correctly. Removing the horizontal gap is an easy way to do this.

		final Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);

		if (scrollPane != null && target.isValid()) {
			dim.width -= (hgap + 1);
		}

		return dim;
	}
}
 
源代码15 项目: FoxTelem   文件: WrapLayout.java
/**
* Returns the minimum or preferred dimension needed to layout the target
* container.
*
* @param target target to get layout size for
* @param preferred should preferred size be calculated
* @return the dimension to layout the target container
*/
private Dimension layoutSize(Container target, boolean preferred)
{
synchronized (target.getTreeLock())
{
	//  Each row must fit with the width allocated to the containter.
	//  When the container width = 0, the preferred width of the container
	//  has not yet been calculated so lets ask for the maximum.

	int targetWidth = target.getSize().width;

	if (targetWidth == 0)
		targetWidth = Integer.MAX_VALUE;

	int hgap = getHgap();
	int vgap = getVgap();
	Insets insets = target.getInsets();
	int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
	int maxWidth = targetWidth - horizontalInsetsAndGap;

	//  Fit components into the allowed width

	Dimension dim = new Dimension(0, 0);
	int rowWidth = 0;
	int rowHeight = 0;

	int nmembers = target.getComponentCount();

	for (int i = 0; i < nmembers; i++)
	{
		Component m = target.getComponent(i);

		if (m.isVisible())
		{
			Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();

			//  Can't add the component to current row. Start a new row.

			if (rowWidth + d.width > maxWidth)
			{
				addRow(dim, rowWidth, rowHeight);
				rowWidth = 0;
				rowHeight = 0;
			}

			//  Add a horizontal gap for all components after the first

			if (rowWidth != 0)
			{
				rowWidth += hgap;
			}

			rowWidth += d.width;
			rowHeight = Math.max(rowHeight, d.height);
		}
	}

	addRow(dim, rowWidth, rowHeight);

	dim.width += horizontalInsetsAndGap;
	dim.height += insets.top + insets.bottom + vgap * 2;

	//	When using a scroll pane or the DecoratedLookAndFeel we need to
	//  make sure the preferred size is less than the size of the
	//  target containter so shrinking the container size works
	//  correctly. Removing the horizontal gap is an easy way to do this.

	Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);

	if (scrollPane != null && target.isValid())
	{
		dim.width -= (hgap + 1);
	}

	return dim;
}
}
 
源代码16 项目: COMP3204   文件: WrapLayout.java
/**
 * Returns the minimum or preferred dimension needed to layout the target
 * container.
 * 
 * @param target
 *            target to get layout size for
 * @param preferred
 *            should preferred size be calculated
 * @return the dimension to layout the target container
 */
private Dimension layoutSize(Container target, boolean preferred)
{
	synchronized (target.getTreeLock())
	{
		// Each row must fit with the width allocated to the containter.
		// When the container width = 0, the preferred width of the
		// container
		// has not yet been calculated so lets ask for the maximum.

		int targetWidth = target.getSize().width;

		if (targetWidth == 0)
			targetWidth = Integer.MAX_VALUE;

		final int hgap = getHgap();
		final int vgap = getVgap();
		final Insets insets = target.getInsets();
		final int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
		final int maxWidth = targetWidth - horizontalInsetsAndGap;

		// Fit components into the allowed width

		final Dimension dim = new Dimension(0, 0);
		int rowWidth = 0;
		int rowHeight = 0;

		final int nmembers = target.getComponentCount();

		for (int i = 0; i < nmembers; i++)
		{
			final Component m = target.getComponent(i);

			if (m.isVisible())
			{
				final Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();

				// Can't add the component to current row. Start a new row.

				if (rowWidth + d.width > maxWidth)
				{
					addRow(dim, rowWidth, rowHeight);
					rowWidth = 0;
					rowHeight = 0;
				}

				// Add a horizontal gap for all components after the first

				if (rowWidth != 0)
				{
					rowWidth += hgap;
				}

				rowWidth += d.width;
				rowHeight = Math.max(rowHeight, d.height);
			}
		}

		addRow(dim, rowWidth, rowHeight);

		dim.width += horizontalInsetsAndGap;
		dim.height += insets.top + insets.bottom + vgap * 2;

		// When using a scroll pane or the DecoratedLookAndFeel we need to
		// make sure the preferred size is less than the size of the
		// target containter so shrinking the container size works
		// correctly. Removing the horizontal gap is an easy way to do this.

		final Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);

		if (scrollPane != null && target.isValid())
		{
			dim.width -= (hgap + 1);
		}

		return dim;
	}
}
 
源代码17 项目: rapidminer-studio   文件: OpenChartAction.java
@Override
public void loggedActionPerformed(ActionEvent e) {

	// look up the panel invoking the pop up invoking the action
	AttributeStatisticsPanel asp = null;

	// the action should only be invoked by AttributePopupMenus
	Container parent = ((JComponent) e.getSource()).getParent();
	if ((parent instanceof AttributePopupMenu)) {
		asp = ((AttributePopupMenu) parent).getAttributeStatisticsPanel();
	} else {
		asp = (AttributeStatisticsPanel) SwingUtilities.getAncestorOfClass(AttributeStatisticsPanel.class, parent);
		if (asp == null) {
			// we are not inside a AttributesStatisticPanel
			return;
		}
	}

	ButtonBarCardPanel cardPanel = (ButtonBarCardPanel) SwingUtilities.getAncestorOfClass(ButtonBarCardPanel.class, asp);
	AbstractAttributeStatisticsModel model = asp.getModel();

	// select the visualizations view
	cardPanel.selectCard("visualizations");

	// get the opened visualization
	JPanel outerPanel = (JPanel) cardPanel.getShownComponent();
	for (Component innerComp : outerPanel.getComponents()) {
		if (innerComp != null && innerComp.getClass().getName().equals(VISUALIZATIONS_CLASS_NAME)) {
			// adjust settings
			String attributeName = model.getAttribute().getName();
			try {
				if (model instanceof NominalAttributeStatisticsModel) {
					Method showAggregatedColumnChart = innerComp.getClass().getDeclaredMethod(SHOW_AGGREGATED_COLUMN_METHOD_NAME, String.class);
					showAggregatedColumnChart.setAccessible(true);
					showAggregatedColumnChart.invoke(innerComp, attributeName);
				} else if (model instanceof NumericalAttributeStatisticsModel
						|| model instanceof DateTimeAttributeStatisticsModel) {
					Method showHistogramChart = innerComp.getClass().getDeclaredMethod(SHOW_HISTOGRAM_METHOD_NAME, String.class);
					showHistogramChart.setAccessible(true);
					showHistogramChart.invoke(innerComp, attributeName);
				}
			} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e1) {
				LogService.getRoot().log(Level.WARNING, "com.rapidminer.gui.viewer.metadata.actions.OpenChartAction.cannot_show_visualization", e1);
			}
			break;
		}
	}
}
 
源代码18 项目: Shuffle-Move   文件: WrapLayout.java
/**
 * Returns the minimum or preferred dimension needed to layout the target container.
 *
 * @param target
 *           target to get layout size for
 * @param preferred
 *           should preferred size be calculated
 * @return the dimension to layout the target container
 */
private Dimension layoutSize(Container target, boolean preferred) {
   synchronized (target.getTreeLock()) {
      // Each row must fit with the width allocated to the containter.
      // When the container width = 0, the preferred width of the
      // container
      // has not yet been calculated so lets ask for the maximum.
      
      int targetWidth = target.getSize().width;
      
      if (targetWidth == 0) {
         targetWidth = Integer.MAX_VALUE;
      }
      
      int hgap = getHgap();
      int vgap = getVgap();
      Insets insets = target.getInsets();
      int horizontalInsetsAndGap = insets.left + insets.right + hgap * 2;
      int maxWidth = targetWidth - horizontalInsetsAndGap;
      
      // Fit components into the allowed width
      
      Dimension dim = new Dimension(0, 0);
      int rowWidth = 0;
      int rowHeight = 0;
      
      int nmembers = target.getComponentCount();
      
      for (int i = 0; i < nmembers; i++) {
         Component m = target.getComponent(i);
         
         if (m.isVisible()) {
            Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
            
            // Can't add the component to current row. Start a new row.
            
            if (rowWidth + d.width > maxWidth) {
               addRow(dim, rowWidth, rowHeight);
               rowWidth = 0;
               rowHeight = 0;
            }
            
            // Add a horizontal gap for all components after the first
            
            if (rowWidth != 0) {
               rowWidth += hgap;
            }
            
            rowWidth += d.width;
            rowHeight = Math.max(rowHeight, d.height);
         }
      }
      
      addRow(dim, rowWidth, rowHeight);
      
      dim.width += horizontalInsetsAndGap;
      dim.height += insets.top + insets.bottom + vgap * 2;
      
      // When using a scroll pane or the DecoratedLookAndFeel we need to
      // make sure the preferred size is less than the size of the
      // target containter so shrinking the container size works
      // correctly. Removing the horizontal gap is an easy way to do this.
      
      Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
      
      if (scrollPane != null && target.isValid()) {
         int extra = 1;
         if (scrollPane instanceof JScrollPane) {
            JScrollPane jsp = (JScrollPane) scrollPane;
            JScrollBar vsb = jsp.getVerticalScrollBar();
            if (vsb != null) {
               extra += Math.max(0, vsb.getWidth());
            }
         }
         dim.width -= hgap + extra;
      }
      
      return dim;
   }
}
 
源代码19 项目: netbeans   文件: TabbedImpl.java
public static boolean isActive( Component c ) {
    Tabbed.Accessor acc = (Tabbed.Accessor)SwingUtilities.getAncestorOfClass(Tabbed.Accessor.class, c);
    return acc != null
            && acc.getTabbed() instanceof TabbedImpl
            && ((TabbedImpl) acc.getTabbed()).active;
}
 
源代码20 项目: javamelody   文件: MSwingUtilities.java
/**
 * Retourne l'instance courante de la classe componentClass contenant l'élément component. <br/>
 * Cette méthode peut-être très utile pour récupérer une référence à un parent éloigné (ancêtre), en l'absence de référence directe du type attribut.
 *
 * <br/>
 * Ex : un composant panel désire une référence sur sa JFrame parente, alors l'instruction suivante suffit : getAncestorOfClass(JFrame.class, panel)
 *
 * @return Component
 * @param <T>
 *           le type du composant recherché
 * @param componentClass
 *           Class
 * @param component
 *           Component
 */
@SuppressWarnings("unchecked")
public static <T> T getAncestorOfClass(final Class<T> componentClass,
		final Component component) {
	return (T) SwingUtilities.getAncestorOfClass(componentClass, component);
}