Java Code Examples for javax.swing.JButton#doClick()

The following examples show how to use javax.swing.JButton#doClick() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DialogDisplayer50960Test.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: SQLExecutionBaseActionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: AntSanityTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example 4
Source File: PropertyPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void workaround11364() {
    JRootPane root = getRootPane();
    if (root != null) {
        JButton defaultButton = root.getDefaultButton();
        if (defaultButton != null) {
            defaultButton.doClick();
        }
    }
}
 
Example 5
Source File: LookupSensitiveActionUILogTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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() );        
   }
 
Example 6
Source File: EditablePropertyDisplayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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();
            }
        }
    }
}
 
Example 7
Source File: SwingUtils.java    From ib-controller with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: Test6788531.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 9
Source File: Test6179222.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void test(ActionListener listener) {
    JButton button = new JButton("hi");
    button.addActionListener(listener);
    button.doClick();
}
 
Example 10
Source File: Test6788531.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 11
Source File: ReplayRenameDialog.java    From sc2gears with Apache License 2.0 4 votes vote down vote up
/**
 * 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 );
}
 
Example 12
Source File: Test6179222.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void test(ActionListener listener) {
    JButton button = new JButton("hi");
    button.addActionListener(listener);
    button.doClick();
}
 
Example 13
Source File: Test6179222.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void test(ActionListener listener) {
    JButton button = new JButton("hi");
    button.addActionListener(listener);
    button.doClick();
}
 
Example 14
Source File: Test6788531.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 15
Source File: Test6179222.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void test(ActionListener listener) {
    JButton button = new JButton("hi");
    button.addActionListener(listener);
    button.doClick();
}
 
Example 16
Source File: NbPresenterTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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 ();
}
 
Example 17
Source File: ToolAdapterTabbedEditorDialog.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 18
Source File: TopComponentGetLookupTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 19
Source File: Test6788531.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
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();
}
 
Example 20
Source File: Test6788531.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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();
}