javax.swing.JButton#doClick ( )源码实例Demo

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

源代码1 项目: netbeans   文件: AntSanityTest.java
/**
 * Evaluates simple expression during debugging session.
 */
public void evaluateExpression() throws IllegalAccessException, InvocationTargetException, InterruptedException, InvalidExpressionException {
    TopComponentOperator variablesView = new TopComponentOperator(new ContainerOperator(MainWindowOperator.getDefault(), VIEW_CHOOSER), "Variables");
    JToggleButtonOperator showEvaluationResultButton = new JToggleButtonOperator(variablesView, 0);
    showEvaluationResultButton.clickMouse();
    TopComponentOperator evaluationResultView = new TopComponentOperator("Evaluation Result");
    new Action("Debug|Evaluate Expression...", null).perform();
    TopComponentOperator expressionEvaluator = new TopComponentOperator("Evaluate Expression");
    JEditorPaneOperator expressionEditor = new JEditorPaneOperator(expressionEvaluator);
    new EventTool().waitNoEvent(1000);
    expressionEditor.setText("\"If n is: \" + n + \", then n + 1 is: \" + (n + 1)");
    JPanel buttonsPanel = (JPanel) expressionEvaluator.getComponent(2);
    JButton expressionEvaluatorButton = (JButton) buttonsPanel.getComponent(1);
    assertEquals("Evaluate code fragment (Ctrl + Enter)", expressionEvaluatorButton.getToolTipText());
    expressionEvaluatorButton.doClick();
    JTableOperator variablesTable = new JTableOperator(evaluationResultView);
    assertValue(variablesTable, 0, 2, "\"If n is: 50, then n + 1 is: 51\"");
    assertEquals("\"If n is: \" + n + \", then n + 1 is: \" + (n + 1)", variablesTable.getValueAt(0, 0).toString().trim());
}
 
源代码2 项目: netbeans   文件: SQLExecutionBaseActionTest.java
public void testActionPerformed() {
    instanceContent.add(sqlExecution);
    Component tp = ((Presenter.Toolbar)action).getToolbarPresenter();
    assertTrue("The toolbar presenter should be a JButton", tp instanceof JButton);

    JButton button = (JButton)tp;
    button.doClick();
    assertTrue("Should perform the action when SQLExecution in the context", baseAction.actionPeformedCount == 1);

    instanceContent.remove(sqlExecution);
    button.doClick();
    assertTrue("Should not perform the action when no SQLExecution in the context", baseAction.actionPeformedCount == 1);

    instanceContent.add(sqlExecution);
    button.doClick();
    assertTrue("Should perform the action when SQLExecution in the context", baseAction.actionPeformedCount == 2);
}
 
源代码3 项目: netbeans   文件: DialogDisplayer50960Test.java
public void testRedundantActionPerformed () {
    JButton b1 = new JButton ("Do");
    JButton b2 = new JButton ("Don't");
    ActionListener listener = new ActionListener () {
        public void actionPerformed (ActionEvent event) {
            assertFalse ("actionPerformed() only once.", performed);
            performed = true;
        }
    };
    DialogDescriptor dd = new DialogDescriptor (
                        "...",
                        "My Dialog",
                        true,
                        new JButton[] {b1, b2},
                        b2,
                        DialogDescriptor.DEFAULT_ALIGN,
                        null,
                        null
                    );
    dd.setButtonListener (listener);
    Dialog dlg = DialogDisplayer.getDefault ().createDialog (dd);
    b1.doClick ();
    assertTrue ("Button b1 invoked.", performed);
}
 
源代码4 项目: ib-controller   文件: SwingUtils.java
/**
 * Performs a click on the button labelled with the specified text.
 * @param window
 *  The window containing the button.
 * @param buttonText
 *  The button's label.
 * @return
 *  true if the button was found;  false if the button was not found
 */
static boolean clickButton(final Window window, final String buttonText) {
    final JButton button = findButton(window, buttonText);
    if (button == null) return false;

    if (! button.isEnabled()) {
        button.setEnabled(true);
        Utils.logToConsole("Button was disabled, has been enabled: " + buttonText);
    }

    Utils.logToConsole("Click button: " + buttonText);
    button.doClick();
    if (! button.isEnabled()) Utils.logToConsole("Button now disabled: " + buttonText);
    return true;
}
 
源代码5 项目: netbeans   文件: EditablePropertyDisplayer.java
private void trySendEnterToDialog() {
    //        System.err.println("SendEnterToDialog");
    EventObject ev = EventQueue.getCurrentEvent();

    if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ENTER)) {
        if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) {
            return;
        }

        if (
            ev.getSource() instanceof JTextComponent &&
                ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox &&
                ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible()
        ) {
            return;
        }

        JRootPane jrp = getRootPane();

        if (jrp != null) {
            JButton b = jrp.getDefaultButton();

            if ((b != null) && b.isEnabled()) {
                b.doClick();
            }
        }
    }
}
 
源代码6 项目: netbeans   文件: LookupSensitiveActionUILogTest.java
public void testToolbarPushIsNotified() throws Exception {
       TestSupport.ChangeableLookup lookup = new TestSupport.ChangeableLookup();
       TestLSA tlsa = new TestLSA( lookup );
assertTrue ("TestLSA action is enabled.", tlsa.isEnabled ());
tlsa.refreshCounter = 0;
       TestPropertyChangeListener tpcl = new TestPropertyChangeListener();
       tlsa.addPropertyChangeListener( tpcl );
       lookup.change(d2);
       assertEquals( "Refresh should be called once", 1, tlsa.refreshCounter );
       assertEquals( "One event should be fired", 1, tpcl.getEvents().size() );
       assertTrue("Action is enabled", tlsa.isEnabled());

       tlsa.setDisplayName("Jarda");
    
       JToolBar bar = new JToolBar();
       JButton item = bar.add(tlsa);
       item.doClick();
       
       assertEquals("One record logged:\n" + my.recs, 1, my.recs.size());
       LogRecord r = my.recs.get(0);
       assertEquals("Menu push", "UI_ACTION_BUTTON_PRESS", r.getMessage());
       assertEquals("four args", 5, r.getParameters().length);
       assertEquals("first is the menu item", item, r.getParameters()[0]);
       assertEquals("second is its class", item.getClass().getName(), r.getParameters()[1]);
       assertEquals("3rd is action", tlsa, r.getParameters()[2]);
       assertEquals("4th its class", tlsa.getClass().getName(), r.getParameters()[3]);
       assertEquals("5th name", "Jarda", r.getParameters()[4]);
       
       tlsa.clear();
       tpcl.clear();
       lookup.change(d3);
       assertEquals( "Refresh should be called once", 1, tlsa.refreshCounter );
       assertEquals( "One event should be fired", 1, tpcl.getEvents().size() );        
   }
 
源代码7 项目: netbeans   文件: PropertyPanel.java
private void workaround11364() {
    JRootPane root = getRootPane();
    if (root != null) {
        JButton defaultButton = root.getDefaultButton();
        if (defaultButton != null) {
            defaultButton.doClick();
        }
    }
}
 
源代码8 项目: openjdk-8-source   文件: Test6788531.java
public static void main(String[] args) throws Exception {
    JButton button = new JButton("hi");
    button.addActionListener(EventHandler.create(ActionListener.class, new Private(), "run"));
    button.addActionListener(EventHandler.create(ActionListener.class, new PrivateGeneric(), "run", "actionCommand"));
    button.doClick();
}
 
源代码9 项目: jdk8u_jdk   文件: Test6788531.java
public static void main(String[] args) throws Exception {
    JButton button = new JButton("hi");
    button.addActionListener(EventHandler.create(ActionListener.class, new Private(), "run"));
    button.addActionListener(EventHandler.create(ActionListener.class, new PrivateGeneric(), "run", "actionCommand"));
    button.doClick();
}
 
源代码10 项目: jdk8u-dev-jdk   文件: Test6179222.java
private static void test(ActionListener listener) {
    JButton button = new JButton("hi");
    button.addActionListener(listener);
    button.doClick();
}
 
源代码11 项目: openjdk-8   文件: Test6179222.java
private static void test(ActionListener listener) {
    JButton button = new JButton("hi");
    button.addActionListener(listener);
    button.doClick();
}
 
源代码12 项目: openjdk-jdk9   文件: Test6179222.java
private static void test(ActionListener listener) {
    JButton button = new JButton("hi");
    button.addActionListener(listener);
    button.doClick();
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: Test6788531.java
public static void main(String[] args) throws Exception {
    JButton button = new JButton("hi");
    button.addActionListener(EventHandler.create(ActionListener.class, new Private(), "run"));
    button.addActionListener(EventHandler.create(ActionListener.class, new PrivateGeneric(), "run", "actionCommand"));
    button.doClick();
}
 
源代码14 项目: openjdk-jdk8u   文件: Test6179222.java
private static void test(ActionListener listener) {
    JButton button = new JButton("hi");
    button.addActionListener(listener);
    button.doClick();
}
 
源代码15 项目: openjdk-jdk9   文件: Test6788531.java
public static void main(String[] args) throws Exception {
    JButton button = new JButton("hi");
    button.addActionListener(EventHandler.create(ActionListener.class, new Private(), "run"));
    button.addActionListener(EventHandler.create(ActionListener.class, new PrivateGeneric(), "run", "actionCommand"));
    button.doClick();
}
 
源代码16 项目: sc2gears   文件: ReplayRenameDialog.java
/**
 * Creates a new ReplayRenameDialog.
 * @param replayOpCallback optional callback that has to be called upon file changes
 * @param files            files to operate on
 */
public ReplayRenameDialog( final ReplayOpCallback replayOpCallback, final File[] files ) {
	super( "replayops.renameDialog.title", Icons.DOCUMENT_RENAME );
	
	final JPanel editorPanel = new JPanel( new BorderLayout() );
	editorPanel.setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) );
	
	final JComboBox< String > nameTemplateComboBox = GuiUtils.createPredefinedListComboBox( PredefinedList.REP_RENAME_TEMPLATE );
	nameTemplateComboBox.setSelectedItem( Settings.getString( Settings.KEY_REP_SEARCH_RESULTS_RENAME_TEMPLATE ) );
	editorPanel.add( GuiUtils.createNameTemplateEditor( nameTemplateComboBox, Symbol.REPLAY_COUNTER ), BorderLayout.CENTER );
	
	final JPanel buttonsPanel = new JPanel();
	final JButton previewButton = new JButton();
	GuiUtils.updateButtonText( previewButton, "replayops.renameDialog.previewButton" );
	buttonsPanel.add( previewButton );
	final JButton renameButton = new JButton();
	GuiUtils.updateButtonText( renameButton, "replayops.renameDialog.renameButton" );
	buttonsPanel.add( renameButton );
	final JButton cancelButton = createCloseButton( "button.cancel" );
	buttonsPanel.add( cancelButton );
	editorPanel.add( buttonsPanel, BorderLayout.SOUTH );
	
	getContentPane().add( editorPanel, BorderLayout.NORTH );
	
	final JTextArea previewTextArea = new JTextArea( 10, 50 );
	previewTextArea.setEditable( false );
	getContentPane().add( new JScrollPane( previewTextArea ), BorderLayout.CENTER );
	
	final ActionListener renameActionListener = new ActionListener() {
		@Override
		public void actionPerformed( final ActionEvent event ) {
			final boolean preview = event.getSource() == previewButton;
			
			if ( preview )
				previewTextArea.setText( "" );
			
			int errorCounter = 0;
			try {
				final TemplateEngine templatEngine = new TemplateEngine( nameTemplateComboBox.getSelectedItem().toString() );
				for ( int fileIndex = 0; fileIndex < files.length; fileIndex++ ) {
					final File   file    = files[ fileIndex ];
					final String newName = templatEngine.applyToReplay( file, file.getParentFile() );
					if ( newName == null ) {
						errorCounter++;
						continue;
					}
					
					if ( preview )
						previewTextArea.append( newName + "\n" );
					else {
						if ( newName.equals( file.getName() ) )
							continue; // Same name, no need to rename (and if we would proceed, we would wrongly append something like " (2)" at the end of it...
						final File destinationFile = GeneralUtils.generateUniqueName( new File( file.getParent(), newName ) );
						// Create potential sub-folders specified by the name template
						final File parentOfDestinationFile = destinationFile.getParentFile();
						boolean failedToCreateSubfolders = false;
						if ( !parentOfDestinationFile.exists() )
							failedToCreateSubfolders = !parentOfDestinationFile.mkdirs();
						if ( file.renameTo( destinationFile ) ) {
							if ( replayOpCallback != null )
								replayOpCallback.replayRenamed( file, destinationFile, fileIndex );
						}
						else {
							System.out.println( "Failed to rename replay file" + ( destinationFile.exists() ? " (target file already exists)" : failedToCreateSubfolders ? " (failed to create sub-folders)" : "" ) + "!" );
							errorCounter++;
						}
					}
				}
			} catch ( final Exception e ) {
				e.printStackTrace();
				GuiUtils.showErrorDialog( Language.getText( "replayops.renameDialog.invalidTemplate", e.getMessage() ) );
				return;
			} finally {
				nameTemplateComboBox.requestFocusInWindow();
			}
			
			if ( preview )
				previewTextArea.setCaretPosition( 0 );
			else {
				if ( replayOpCallback != null )
					replayOpCallback.moveRenameDeleteEnded();
				// Template is valid here, so we can store it
				Settings.set( Settings.KEY_REP_SEARCH_RESULTS_RENAME_TEMPLATE, nameTemplateComboBox.getSelectedItem().toString() );
				if ( errorCounter == 0 )
					GuiUtils.showInfoDialog( Language.getText( "replayops.renameDialog.successfullyRenamed", files.length ) );
				else
					GuiUtils.showErrorDialog( new Object[] { Language.getText( "replayops.renameDialog.successfullyRenamed", files.length - errorCounter ), Language.getText( "replayops.renameDialog.failedToRename", errorCounter ) } );
				dispose();
			}
		}
	};
	previewButton.addActionListener( renameActionListener );
	renameButton .addActionListener( renameActionListener );
	
	previewButton.doClick();
	packAndShow( nameTemplateComboBox, false );
}
 
源代码17 项目: hottub   文件: Test6788531.java
public static void main(String[] args) throws Exception {
    JButton button = new JButton("hi");
    button.addActionListener(EventHandler.create(ActionListener.class, new Private(), "run"));
    button.addActionListener(EventHandler.create(ActionListener.class, new PrivateGeneric(), "run", "actionCommand"));
    button.doClick();
}
 
源代码18 项目: netbeans   文件: NbPresenterTest.java
private void doTestDialogsOptions () {
    boolean modal = false;
    //boolean modal = true;
    JButton erase = new JButton ("Erase all my data");
    JButton rescue = new JButton ("Rescue");
    JButton cancel = new JButton ("Cancel");
    JButton [] options = new JButton [] {erase, rescue, cancel};
    DialogDescriptor dd = new DialogDescriptor (new JLabel ("Something interesting"), "My dialog", modal,
            // options
            options,
            rescue,
            // align
            DialogDescriptor.RIGHT_ALIGN,
            new HelpCtx (NbPresenterTest.class), null);
    

    dd.setClosingOptions (new Object[0]);
            
    NbPresenter presenter = new NbDialog (dd, (JFrame)null);
    presenter.setVisible (true);
    
    erase.doClick ();
    assertEquals ("Erase was invoked.", erase.getText (), ((JButton)dd.getValue ()).getText ());
    erase.doClick ();
    assertEquals ("Erase was invoked again on same dialog.", erase.getText (), ((JButton)dd.getValue ()).getText ());
    presenter.dispose ();

    presenter = new NbDialog (dd, (JFrame)null);
    presenter.setVisible (true);

    erase.doClick ();
    assertEquals ("Erase was invoked of reused dialog.", erase.getText (), ((JButton)dd.getValue ()).getText ());
    erase.doClick ();
    assertEquals ("Erase was invoked again on reused dialog.", erase.getText (), ((JButton)dd.getValue ()).getText ());
    presenter.dispose ();

    presenter = new NbDialog (dd, (JFrame)null);
    presenter.setVisible (true);

    rescue.doClick ();
    assertEquals ("Rescue was invoked of reused dialog.", rescue.getText (), ((JButton)dd.getValue ()).getText ());
    rescue.doClick ();
    assertEquals ("Rescue was invoked again on reused dialog.", rescue.getText (), ((JButton)dd.getValue ()).getText ());
    presenter.dispose ();
    
    presenter = new NbDialog (dd, (JFrame)null);
    presenter.setVisible (true);

    cancel.doClick ();
    assertEquals ("Cancel was invoked of reused dialog.", cancel.getText (), ((JButton)dd.getValue ()).getText ());
    cancel.doClick ();
    assertEquals ("Cancel was invoked again on reused dialog.", cancel.getText (), ((JButton)dd.getValue ()).getText ());
    presenter.dispose ();
}
 
private JButton renderInstallButton(org.esa.snap.core.gpf.descriptor.dependency.Bundle currentBundle,
                                 JPanel bundlePanel) {
    JButton installButton = new JButton() {
        @Override
        public void setText(String text) {
            super.setText(text);
            adjustDimension(this);
        }
    };
    installButton.setText((currentBundle.getLocation() == BundleLocation.REMOTE ?
            "Download and " :
            "") + "Install Now");
    installButton.setToolTipText(currentBundle.getLocation() == BundleLocation.REMOTE ?
                                         currentBundle.getDownloadURL() :
                                         currentBundle.getSource() != null ?
                                                 currentBundle.getSource().toString() : "");
    installButton.setMaximumSize(installButton.getPreferredSize());
    installButton.addActionListener((ActionEvent e) -> {
        newOperatorDescriptor.setBundles(bundleForm.applyChanges());
        org.esa.snap.core.gpf.descriptor.dependency.Bundle modifiedBundle = newOperatorDescriptor.getBundle();
        try (BundleInstaller installer = new BundleInstaller(newOperatorDescriptor)) {
            ProgressHandle progressHandle = ProgressHandleFactory.createSystemHandle("Installing bundle");
            installer.setProgressMonitor(new ProgressHandler(progressHandle, false));
            installer.setCallback(() -> {
                if (modifiedBundle.isInstalled()) {
                    Path path = newOperatorDescriptor.resolveVariables(modifiedBundle.getTargetLocation())
                            .toPath()
                            .resolve(FileUtils.getFilenameWithoutExtension(modifiedBundle.getEntryPoint()));
                    SwingUtilities.invokeLater(() -> {
                        progressHandle.finish();
                        Dialogs.showInformation(String.format("Bundle was installed in location:\n%s", path));
                        installButton.setVisible(false);
                        bundlePanel.revalidate();
                    });
                    String updateVariable = modifiedBundle.getUpdateVariable();
                    if (updateVariable != null) {
                        Optional<SystemVariable> variable = newOperatorDescriptor.getVariables()
                                .stream()
                                .filter(v -> v.getKey().equals(updateVariable))
                                .findFirst();
                        variable.ifPresent(systemVariable -> {
                            systemVariable.setShared(true);
                            systemVariable.setValue(path.toString());
                        });
                        varTable.revalidate();
                    }
                } else {
                    SwingUtilities.invokeLater(() -> {
                        progressHandle.finish();
                        Dialogs.showInformation("Bundle installation failed. \n" +
                                                        "Please see the application log for details.");
                        bundlePanel.revalidate();
                    });
                }
                return null;
            });
            installButton.setVisible(false);
            installer.install(true);
        } catch (Exception ex) {
            logger.warning(ex.getMessage());
        }
    });
    this.downloadAction = () -> {
        tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
        installButton.requestFocusInWindow();
        installButton.doClick();
        return null;
    };
    installButton.setVisible(canInstall(currentBundle));
    return installButton;
}
 
源代码20 项目: netbeans   文件: TopComponentGetLookupTest.java
public void testActionMapFromFocusedOneButNotOwnButton() {
    ContextAwareAction a = Actions.callback("find", null, false, "Find", null, false);
    
    class Act extends AbstractAction {
        int cnt;
        Action check;
        
        @Override
        public void actionPerformed(ActionEvent ev) {
            cnt++;
        }
    }
    Act act1 = new Act();
    Act act3 = new Act();

    Action action = a;
    act1.check = action;
    act3.check = action;
    final JButton disabled = new JButton();
    top.add(BorderLayout.CENTER, disabled);
    final JButton f = new JButton(action);
    class L implements PropertyChangeListener {
        private int cnt;
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            assertEquals("enabled", evt.getPropertyName());
            cnt++;
        }
    }
    L listener = new L();
    action.addPropertyChangeListener(listener);
    top.add(BorderLayout.SOUTH, f);
    defaultFocusManager.setC(top);

    disabled.getActionMap().put("find", act3);
    top.open();
    top.requestActive();
    assertFalse("Disabled by default", action.isEnabled());
    assertFalse("Button disabled too", f.isEnabled());
    assertEquals("no change yet", 0, listener.cnt);
    
    defaultFocusManager.setC(disabled);
    
    assertEquals("One change", 1, listener.cnt);
    assertTrue("Still enabled", action.isEnabled());
    assertTrue("Button enabled too", f.isEnabled());
    
    f.getModel().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (f.getModel().isPressed()) {
                defaultFocusManager.setC(f);
            } else {
                defaultFocusManager.setC(disabled);
            }
        }
    });
    f.doClick();

    assertEquals("Not Delegated to act1", 0, act1.cnt);
    assertEquals("Delegated to act3", 1, act3.cnt);
}