當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。