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


Java FocusManager类代码示例

本文整理汇总了Java中javax.swing.FocusManager的典型用法代码示例。如果您正苦于以下问题:Java FocusManager类的具体用法?Java FocusManager怎么用?Java FocusManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: remove

import javax.swing.FocusManager; //导入依赖的package包/类
private void remove(LayerPanel layerPanel) {
	layerPanels.remove(layerPanel);
	overlays.remove(layerPanel.layer);
	this.remove((Component)layerPanel);

	Dimension lmMaxSize = getMaximumSize();

	Dimension size = new Dimension(
			lmMaxSize.width+20,
			lmMaxSize.height+40);
	Dimension maxSize = lmFrame.getMaximumSize();

	size.height = Math.min(size.height, maxSize.height);
	size.width = Math.min(size.width, maxSize.width);

	lmFrame.setMinimumSize(size);
	lmFrame.setSize(size);
	lmFrame.pack();
	this.revalidate();
	this.repaint();
	if ( lmFrame.isVisible() ) {
		Window activeWindow = FocusManager.getCurrentManager().getActiveWindow();
		lmFrame.toFront();
		if (activeWindow != null) activeWindow.requestFocus();
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:27,代码来源:LayerManager.java

示例2: isFocusOwner

import javax.swing.FocusManager; //导入依赖的package包/类
private static void isFocusOwner(Component queriedFocusOwner,
        String direction)
        throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            Component actualFocusOwner
                    = FocusManager.getCurrentManager().getFocusOwner();
            if (actualFocusOwner != queriedFocusOwner) {
                frame.dispose();
                throw new RuntimeException(
                        "Focus component is wrong after " + direction
                        + " direction ");

            }
        }
    });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:FocusTraversal.java

示例3: setVisible

import javax.swing.FocusManager; //导入依赖的package包/类
public void setVisible(boolean tf) {
	if (tf && !isVisible()) {
		stolenFocus = FocusManager.getCurrentManager().getActiveWindow();
	}

	if (owner != null)	{
		setLocation(owner.getX() + 60, owner.getY() + 60);
	}
	super.setVisible(tf);

	if (!tf) {
		if (hasFocus()) {
			if (stolenFocus != owner && 
					stolenFocus != null && 
					stolenFocus.isVisible()) {
				stolenFocus.requestFocus();
			} else
			{
				owner.requestFocus();
				map.requestFocusInWindow();
			}
		}
		stolenFocus = null;
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:26,代码来源:ProcessingDialog.java

示例4: editChallenge

import javax.swing.FocusManager; //导入依赖的package包/类
protected void editChallenge()
{
	UUID curid = ChallengeGUI.state.getCurrentChallengeId();
	for (Challenge c : Database.d.getChallengesForEvent(ChallengeGUI.state.getCurrentEventId()))
	{
		if (c.getChallengeId().equals(curid))
		{
			String response = (String)JOptionPane.showInputDialog(FocusManager.getCurrentManager().getActiveWindow(), "Edit Challenge", c.getName());
			if (response != null)
			{
				c.setName(response);
				Database.d.updateChallenge(c);
				Messenger.sendEvent(MT.NEW_CHALLENGE, c);
			}
		}
	}
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:18,代码来源:Menus.java

示例5: actionPerformed

import javax.swing.FocusManager; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent ae)
{
    if (ae.getSource() == cancel)
    {
        close();
    }
    else if (ae.getSource() == ok)
    {
        errorMessage = null;
        if (verifyData())
        {
            valid = true;
            close();
        }
        else if (errorMessage != null)
        {
            JOptionPane.showMessageDialog(FocusManager.getCurrentManager().getActiveWindow(), errorMessage, "Dialog Error", JOptionPane.WARNING_MESSAGE);
        }
        else
        {
            Toolkit.getDefaultToolkit().beep();
        }
    }
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:26,代码来源:BaseDialog.java

示例6: appSetup

import javax.swing.FocusManager; //导入依赖的package包/类
/**
 * Do some common setup for all applications at startup
 * @param name the application name used for Java logging and database logging
 */
public static void appSetup(String name)
{
    // Set our platform wide L&F 
    System.setProperty("swing.defaultlaf", "javax.swing.plaf.nimbus.NimbusLookAndFeel");
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    defaults.put("Table.gridColor", new Color(140,140,140));
    defaults.put("Table.showGrid", true);
    
    // Set the program name which is used by PostgresqlDatabase to identify the app in logs
    System.setProperty("program.name", name);
    
    // Start with a fresh root set at warning
    Logger root = LogManager.getLogManager().getLogger("");
    Formatter format = new SingleLineFormatter();

    root.setLevel(Level.WARNING);
    for(Handler handler : root.getHandlers()) {
        root.removeHandler(handler);
    }

    // Set prefs levels before windows preference load barfs useless data on the user
    Logger.getLogger("java.util.prefs").setLevel(Level.SEVERE);
    // postgres JDBC spits out a lot of data even though we catch the exception
    Logger.getLogger("org.postgresql.jdbc").setLevel(Level.OFF);
    Logger.getLogger("org.postgresql.Driver").setLevel(Level.OFF);

    // Add console handler if running in debug mode
    if (Prefs.isDebug()) {
        ConsoleHandler ch = new ConsoleHandler();
        ch.setLevel(Level.ALL);
        ch.setFormatter(format);
        root.addHandler(ch);
    }

    // For our own logs, we can set super fine level or info depending on if debug mode and attach dialogs to those
    Logger applog = Logger.getLogger("org.wwscc");
    applog.setLevel(Prefs.isDebug() ? Level.FINEST : Level.INFO);
    applog.addHandler(new AlertHandler());

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            applog.log(Level.WARNING, String.format("\bUncaughtException in %s: %s", t, e), e);
        }});

    try {
        File logdir = Prefs.getLogDirectory().toFile();
        if (!logdir.exists())
            if (!logdir.mkdirs())
                throw new IOException("Can't create log directory " + logdir);
        FileHandler fh = new FileHandler(new File(logdir, name+".%g.log").getAbsolutePath(), 1000000, 10, true);
        fh.setFormatter(format);
        fh.setLevel(Level.ALL);
        root.addHandler(fh);
    } catch (IOException ioe) {
        JOptionPane.showMessageDialog(FocusManager.getCurrentManager().getActiveWindow(),
                "Unable to enable logging to file: " + ioe, "Log Error", JOptionPane.ERROR_MESSAGE);
    }

    // force the initialization of IdGenerator on another thread so app can start now without an odd delay later
    new Thread() {
        public void run() {
            IdGenerator.generateId();
        }
    }.start();
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:71,代码来源:AppSetup.java

示例7: getFocusedEditor

import javax.swing.FocusManager; //导入依赖的package包/类
/**
 * Requests focus in the editor, waits and returns editor component
 */
@Nullable
private JComponent getFocusedEditor() {
  Editor editor = execute(new GuiQuery<Editor>() {
    @Override
    @Nullable
    protected Editor executeInEDT() throws Throwable {
      FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
      return manager.getSelectedTextEditor(); // Must be called from the EDT
    }
  });

  if (editor != null) {
    JComponent contentComponent = editor.getContentComponent();
    new ComponentDriver(robot).focusAndWaitForFocusGain(contentComponent);
    assertSame(contentComponent, FocusManager.getCurrentManager().getFocusOwner());
    return contentComponent;
  } else {
    fail("Expected to find editor to focus, but there is no current editor");
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:EditorFixture.java

示例8: doIt

import javax.swing.FocusManager; //导入依赖的package包/类
@Override
public void doIt() {
	RecordDataEditorView recordDataView = 
			(RecordDataEditorView)getEditor().getViewModel().getView(RecordDataEditorView.VIEW_NAME);
	if(recordDataView.currentGroupIndex() == groupIndex) {
		final Component focusedComp = 
				FocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
		if(focusedComp != null && focusedComp instanceof GroupField) {
			final GroupField<?> grpField = (GroupField<?>)focusedComp;
			grpField.validateAndUpdate();
		}
	}
	
	if(groupIndex+1 >= record.numberOfGroups()) return;
	
	wordIndex = record.mergeGroups(groupIndex, groupIndex+1);
	
	queueEvent(EditorEventType.GROUP_LIST_CHANGE_EVT, getSource(), null);
}
 
开发者ID:phon-ca,项目名称:phon,代码行数:20,代码来源:MergeGroupEdit.java

示例9: setConfigPanel

import javax.swing.FocusManager; //导入依赖的package包/类
private static void setConfigPanel(final JPanel configPanelAnchor, final ScopeToolState state) {
  configPanelAnchor.removeAll();
  final JComponent additionalConfigPanel = state.getAdditionalConfigPanel();
  if (additionalConfigPanel != null) {
    final JScrollPane pane = ScrollPaneFactory.createScrollPane(additionalConfigPanel, SideBorder.NONE);
    FocusManager.getCurrentManager().addPropertyChangeListener("focusOwner", new PropertyChangeListener() {
      @Override
      public void propertyChange(PropertyChangeEvent evt) {
        if (!(evt.getNewValue() instanceof JComponent)) {
          return;
        }
        final JComponent component = (JComponent)evt.getNewValue();
        if (component.isAncestorOf(pane)) {
          pane.scrollRectToVisible(component.getBounds());
        }
      }
    });
    configPanelAnchor.add(pane);
  }
  UIUtil.setEnabled(configPanelAnchor, state.isEnabled(), true);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:SingleInspectionProfilePanel.java

示例10: paintComponent

import javax.swing.FocusManager; //导入依赖的package包/类
@Override
	protected void paintComponent(java.awt.Graphics g) {
		super.paintComponent(g);

		if (getText().isEmpty()
				&& !(FocusManager.getCurrentKeyboardFocusManager()
						.getFocusOwner() == this)) {
			Graphics2D g2 = (Graphics2D) g.create();
			// g2.setBackground(Color.gray);
			// g2.setPaint(UIManager.getDefaults().getColor("TextField.shadow"));
//			g2.setPaint(this.getForeground().brighter().brighter().brighter()
//					.brighter().brighter().brighter().brighter());
			 g2.setPaint(Color.gray);
			g2.setFont(getFont().deriveFont(Font.ITALIC));
			g2.drawString(hint, 5, 20); // figure out x, y from font's
										// FontMetrics and size of component.
			g2.dispose();
		}
	}
 
开发者ID:oliver32767,项目名称:MonkeyBoard,代码行数:20,代码来源:JHintTextField.java

示例11: isFocused

import javax.swing.FocusManager; //导入依赖的package包/类
public boolean isFocused() {
    ResultViewPanel rvp = getCurrentResultViewPanel();
    if (rvp != null) {
        Component owner = FocusManager.getCurrentManager().getFocusOwner();
        return owner != null && SwingUtilities.isDescendingFrom(owner, rvp);
    } else {
        return false;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:ResultView.java

示例12: requestFocusForMessage

import javax.swing.FocusManager; //导入依赖的package包/类
/** Requests focus for <code>currentMessage</code> component.
 * If it is of <code>JComponent</code> type it tries default focus
 * request first. */
private void requestFocusForMessage() {
    Component comp = currentMessage;
    
    if(comp == null) {
        return;
    }

    if (/*!Constants.AUTO_FOCUS &&*/ FocusManager.getCurrentManager().getActiveWindow() == null) {
        // Do not steal focus if no Java window have it
        Component defComp = null;
        Container nearestRoot =
            (comp instanceof Container && ((Container) comp).isFocusCycleRoot()) ? (Container) comp : comp.getFocusCycleRootAncestor();
        if (nearestRoot != null) {
            defComp = nearestRoot.getFocusTraversalPolicy().getDefaultComponent(nearestRoot);
        }
        if (defComp != null) {
            defComp.requestFocusInWindow();
        } else {
            comp.requestFocusInWindow();
        }
    } else {
        if (!(comp instanceof JComponent)
            || !((JComponent)comp).requestDefaultFocus()) {

            comp.requestFocus();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:NbPresenter.java

示例13: actionPerformed

import javax.swing.FocusManager; //导入依赖的package包/类
public void actionPerformed (ActionEvent evt) {
    Component focusOwner = FocusManager.getCurrentManager().getFocusOwner();
    // move focus away only from navigator AWT children,
    // but not combo box to preserve its ESC functionality
    if (lastActivatedRef == null ||
        focusOwner == null ||
        !SwingUtilities.isDescendingFrom(focusOwner, navigatorTC.getTopComponent()) ||
        focusOwner instanceof JComboBox) {
        return;
    }
    TopComponent prevFocusedTc = lastActivatedRef.get();
    if (prevFocusedTc != null) {
        prevFocusedTc.requestActive();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:NavigatorController.java

示例14: backupRequest

import javax.swing.FocusManager; //导入依赖的package包/类
public void backupRequest()
{
    String msg = "Backup failed. See logs.";
    if (doBackup())
        msg = "Backup complete";
    JOptionPane.showMessageDialog(FocusManager.getCurrentManager().getActiveWindow(), msg);
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:8,代码来源:StateControl.java

示例15: actionPerformed

import javax.swing.FocusManager; //导入依赖的package包/类
public void actionPerformed(ActionEvent e) {
    String host = JOptionPane.showInputDialog(FocusManager.getCurrentManager().getActiveWindow(), "Enter the remote host name");
    if ((host != null) && !host.trim().equals("")) {
        Database.d.mergeServerSetRemote(host, "", 10);
        Messenger.sendEvent(MT.POKE_SYNC_SERVER, true);
    }
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:8,代码来源:Actions.java


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