当前位置: 首页>>代码示例>>Java>>正文


Java SwingUtilities.getAncestorOfClass方法代码示例

本文整理汇总了Java中javax.swing.SwingUtilities.getAncestorOfClass方法的典型用法代码示例。如果您正苦于以下问题:Java SwingUtilities.getAncestorOfClass方法的具体用法?Java SwingUtilities.getAncestorOfClass怎么用?Java SwingUtilities.getAncestorOfClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.SwingUtilities的用法示例。


在下文中一共展示了SwingUtilities.getAncestorOfClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getListCellRendererComponent

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
@Override
public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus ) {
    if (!(value instanceof ListNode)) {
        //shoudln't happen
        return new JLabel();
    }
    if( list instanceof SelectionList ) {
        isSelected |= index == ((SelectionList)list).getMouseOverRow();
    }
    ListNode node = (ListNode) value;
    int rowHeight = list.getFixedCellHeight();
    int rowWidth = list.getWidth();
    JScrollPane scroll = ( JScrollPane ) SwingUtilities.getAncestorOfClass( JScrollPane.class, list);
    if( null != scroll )
        rowWidth = scroll.getViewport().getWidth();
    Color background = isSelected ? list.getSelectionBackground() : list.getBackground();
    Color foreground = isSelected ? list.getSelectionForeground() : list.getForeground();

    return node.getListRenderer(foreground, background, isSelected, cellHasFocus, rowHeight, rowWidth);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:SelectionList.java

示例2: createFileDialog

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
private FileDialog createFileDialog( File currentDirectory ) {
    if( badger != null )
        return null;
    if( !Boolean.getBoolean("nb.native.filechooser") )
        return null;
    if( dirsOnly && !BaseUtilities.isMac() )
        return null;
    Component parentComponent = findDialogParent();
    Frame parentFrame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent);
    FileDialog fileDialog = new FileDialog(parentFrame);
    if (title != null) {
        fileDialog.setTitle(title);
    }
    if( null != currentDirectory )
        fileDialog.setDirectory(currentDirectory.getAbsolutePath());
    return fileDialog;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:FileChooserBuilder.java

示例3: testViewToModelConsistency

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
@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();
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DrawEngineTest.java

示例4: testModelToViewCorrectness

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
@RandomlyFails
public void testModelToViewCorrectness() throws Throwable {
    for(String text : TEXTS) {
        JEditorPane jep = createJep(text);
        try {
            checkModelToViewCorrectness(jep);
        } catch (Throwable e) {
            System.err.println("testModelToViewCorrectness 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();
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DrawEngineTest.java

示例5: itemMadeDisplayable

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
static void itemMadeDisplayable(Item item) {
    // If the component was removed from the component hierarchy and then
    // returned back to the hierarchy it will be readded to the end of the component list.
    // If the item is not removed yet then the addAsLast() will do nothing.
    addToItemListAsLast(item);
    JTextComponent c = item.get();
    if (c == null)
        throw new IllegalStateException("Component should be non-null"); //NOI18N
    
    // Remember whether component should not be removed from registry upon removeNotify()
    item.ignoreAncestorChange = (ignoredAncestorClass != null) &&
            (SwingUtilities.getAncestorOfClass(ignoredAncestorClass, c) != null);
    item.usedByCloneableEditor = Boolean.TRUE.equals(c.getClientProperty(USED_BY_CLONEABLE_EDITOR_PROPERTY));
    item.ignoreAncestorChange |= item.usedByCloneableEditor; // possibly ignore ancestore change

    if (LOG.isLoggable(Level.FINER)) {
        LOG.fine("ancestorAdded: " + dumpComponent(item.get()) + '\n'); //NOI18N
        logItemListFinest();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:EditorRegistry.java

示例6: propertyChange

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
@Override
public void propertyChange (PropertyChangeEvent evt) {
    if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName()) && !internalTraverse) {
        Node[] selectedNodes = em.getSelectedNodes();
        final TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, view);
        if (tc != null) {
            tc.setActivatedNodes(selectedNodes);
        }
        if (selectedNodes.length == 1) {
            // single selection
            T node = convertNode(selectedNodes[0]);
            if (node != null) {
                nodeSelected(node);
                return;
            }
        }
        nodeSelected(null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:FileTreeView.java

示例7: valueChanged

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void valueChanged (ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) {
        return;
    }
    List<VCSStatusNode> selectedNodes = new ArrayList<VCSStatusNode>();
    ListSelectionModel selection = table.getSelectionModel();
    final TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, table);
    int min = selection.getMinSelectionIndex();
    if (min != -1) {
        int max = selection.getMaxSelectionIndex();
        for (int i = min; i <= max; i++) {
            if (selection.isSelectedIndex(i)) {
                int idx = table.convertRowIndexToModel(i);
                selectedNodes.add(tableModel.getNode(idx));
            }
        }
    }
    final T[] nodeArray = selectedNodes.toArray((T[]) java.lang.reflect.Array.newInstance(tableModel.getItemClass(), selectedNodes.size()));
    Mutex.EVENT.readAccess(new Runnable() {
        @Override
        public void run() {
            File[] selectedFiles = new File[nodeArray.length];
            for (int i = 0; i < nodeArray.length; ++i) {
                selectedFiles[i] = nodeArray[i].getFile();
            }
            support.firePropertyChange(PROP_SELECTED_FILES, null, selectedFiles);
            if (tc != null) {
                tc.setActivatedNodes(nodeArray);
            }
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:VCSStatusTable.java

示例8: getSideBarWidth

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:EditorUI.java

示例9: buildImportAction

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
protected Action buildImportAction(final Configurable target) {
  Action a = new AbstractAction("Add Imported Class") {
    private static final long serialVersionUID = 1L;

    public void actionPerformed(ActionEvent evt) {
      final Configurable child = importConfigurable();
      if (child != null) {
        try {
          child.build(null);
          final Configurable c = target;
          if (child.getConfigurer() != null) {
            PropertiesWindow w = new PropertiesWindow((Frame) SwingUtilities.getAncestorOfClass(Frame.class, ConfigureTree.this), false, child, helpWindow) {
              private static final long serialVersionUID = 1L;

              public void save() {
                super.save();
                insert(c, child, getTreeNode(c).getChildCount());
              }

              public void cancel() {
                dispose();
              }
            };
            w.setVisible(true);
          }
          else {
            insert(c, child, getTreeNode(c).getChildCount());
          }
        }
        // FIXME: review error message
        catch (Exception ex) {
          JOptionPane.showMessageDialog(getTopLevelAncestor(), "Error adding " + getConfigureName(child) + " to " + getConfigureName(target) + "\n"
              + ex.getMessage(), "Illegal configuration", JOptionPane.ERROR_MESSAGE);
        }
      }
    }
  };
  return a;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:40,代码来源:ConfigureTree.java

示例10: createDialog

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
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;
}
 
开发者ID:KevinPriv,项目名称:Luyten4Forge,代码行数:37,代码来源:JFontChooser.java

示例11: factory

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
public static PlayerActionFactory factory() {
  return new PlayerActionFactory() {
    public Action getAction(SimplePlayer p, JTree tree) {
      return new ShowProfileAction(p,
        (Frame) SwingUtilities.getAncestorOfClass(Frame.class, tree));
    }
  };
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:9,代码来源:ShowProfileAction.java

示例12: topComponentRequestVisible

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
protected void topComponentRequestVisible(TopComponent tc) {
    JFrame f = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, tc);

    if (f != null) {
        if (VISIBLE) {
            f.setVisible(true);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:DummyWindowManager.java

示例13: setupForDragging

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
private void setupForDragging(MouseEvent e)
{
	source.addMouseMotionListener( this );

	//  Determine the component that will ultimately be moved

	if (destinationComponent != null)
	{
		destination = destinationComponent;
	}
	else if (destinationClass == null)
	{
		destination = source;
	}
	else  //  forward events to destination component
	{
		destination = SwingUtilities.getAncestorOfClass(destinationClass, source);
	}

	pressed = e.getLocationOnScreen();
	location = destination.getLocation();

	if (changeCursor)
	{
		originalCursor = source.getCursor();
		source.setCursor( Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR) );
	}

	//  Making sure autoscrolls is false will allow for smoother dragging of
	//  individual components

	if (destination instanceof JComponent)
	{
		JComponent jc = (JComponent)destination;
		autoscrolls = jc.getAutoscrolls();
		jc.setAutoscrolls( false );
	}
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:39,代码来源:ComponentMover.java

示例14: actionPerformed

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
@Override
public final void actionPerformed(ActionEvent e) {
    if (context == null) {
        Object source = e.getSource();
        /*
 Kind of a hack, but I can't think up a better way to get a current
 terminal when Action is performed with the shortcut. Thus it's context
 independent and we need to find an active Terminal. Getting it from TC
 won't work because we can have multiple active Terminals on screen
 (debugger console and terminalemulator, for example).
 Luckily, we can get some useful information from the caller`s source
         */
        if (source instanceof Component) {
            Container container = SwingUtilities.getAncestorOfClass(Terminal.class, (Component) source);
            if (container != null && container instanceof Terminal) {
                this.context = (Terminal) container;
            }
        }
    }

    if (getTerminal() == null) {
        throw new IllegalStateException("No valid terminal component was provided"); // NOI18N
    }

    this.event = e;
    performAction();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:TerminalAction.java

示例15: propertyChange

import javax.swing.SwingUtilities; //导入方法依赖的package包/类
@Override
public void propertyChange (PropertyChangeEvent evt) {
    if (evt.getPropertyName() == ExplorerManager.PROP_SELECTED_NODES) {
        TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, this);
        if (tc != null) {
            tc.setActivatedNodes(getExplorerManager().getSelectedNodes());
        }
        
        currRepository = null;
        Revision oldRevision = currRevision;
        currRevision = null;
        if (getExplorerManager().getSelectedNodes().length == 1) {
            Node selectedNode = getExplorerManager().getSelectedNodes()[0];
            currRevision = selectedNode.getLookup().lookup(Revision.class);
            currRepository = lookupRepository(selectedNode);
        }
        if ((currRevision != null || oldRevision != null) && !(currRevision != null && oldRevision != null 
                && currRevision.equals(oldRevision))) {
            firePropertyChange(PROP_REVISION_CHANGED, oldRevision, currRevision);
        }
        if (options.contains(Option.DISPLAY_REVISIONS) && currRevision != null) {
            revisionsPanel1.updateHistory(currRepository, roots, currRevision);
        }
    } else if (options.contains(Option.DISPLAY_REVISIONS) && "focusOwner".equals(evt.getPropertyName())) {
        Component compNew = (Component) evt.getNewValue();
        if (compNew != null) {
            if (SwingUtilities.getAncestorOfClass(tree.getClass(), compNew) != null) {
                if (getExplorerManager().getSelectedNodes().length == 1) {
                    propertyChange(new PropertyChangeEvent(tree, ExplorerManager.PROP_SELECTED_NODES, getExplorerManager().getSelectedNodes(), getExplorerManager().getSelectedNodes()));
                }
            } else if (revisionsPanel1.lstRevisions == compNew) {
                int selection = revisionsPanel1.lstRevisions.getSelectedIndex();
                if (selection != -1) {
                    valueChanged(new ListSelectionEvent(revisionsPanel1.lstRevisions, selection, selection, false));
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:RepositoryBrowserPanel.java


注:本文中的javax.swing.SwingUtilities.getAncestorOfClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。