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

The following examples show how to use javax.swing.JButton#equals() . 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: CloneableEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** @return 0 => cannot close, -1 can close and do not save, 1 can close and save */
private int canCloseImpl() {
	String msg = messageSave();

	ResourceBundle bundle = NbBundle.getBundle(CloneableEditorSupport.class);

	JButton saveOption = new JButton(bundle.getString("CTL_Save")); // NOI18N
	saveOption.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_Save")); // NOI18N
	saveOption.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_CTL_Save")); // NOI18N

	JButton discardOption = new JButton(bundle.getString("CTL_Discard")); // NOI18N
	discardOption.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_Discard")); // NOI18N
	discardOption.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_CTL_Discard")); // NOI18N
	discardOption.setMnemonic(bundle.getString("CTL_Discard_Mnemonic").charAt(0)); // NOI18N

	NotifyDescriptor nd = new NotifyDescriptor(
			msg, bundle.getString("LBL_SaveFile_Title"), NotifyDescriptor.YES_NO_CANCEL_OPTION,
			NotifyDescriptor.QUESTION_MESSAGE,
			new Object[] { saveOption, discardOption, NotifyDescriptor.CANCEL_OPTION }, saveOption
		);

	Object ret = DialogDisplayer.getDefault().notify(nd);

	if (NotifyDescriptor.CANCEL_OPTION.equals(ret) || NotifyDescriptor.CLOSED_OPTION.equals(ret)) {
		return 0;
	}

	if (saveOption.equals(ret)) {
		return 1;
	} else {
		return -1;
	}
}
 
Example 2
Source File: JUnitLibraryInstaller.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Messages({"cancel=Cancel", "installAnyway=Install anyway", "warning=Write permission problem",
    "writePermissionDetails=<html>You don't have permission to install JUnit Library into the installation directory which is recommened.<br><br>"
    + "To perform installation into the shared directory, you should run IDE as a user with administrative<br>"
    + "privilege, or install the JUnit Library into your user directory."})
private static void showWritePermissionDialog(Runnable installAnyway) {
    JButton cancel = new JButton();
    Mnemonics.setLocalizedText(cancel, cancel());
    JButton install = new JButton();
    Mnemonics.setLocalizedText(install, installAnyway());
    DialogDescriptor descriptor = new DialogDescriptor(
            new JLabel(writePermissionDetails()),
            warning(),
            true, // Modal
            new JButton[]{install, cancel}, // Option list
            null, // Default
            DialogDescriptor.DEFAULT_ALIGN, // Align
            null, // Help
            null);
    
    descriptor.setMessageType(NotifyDescriptor.QUESTION_MESSAGE);
    descriptor.setClosingOptions(null);
    DialogDisplayer.getDefault().createDialog(descriptor).setVisible(true);
    if (install.equals(descriptor.getValue())) {
        // install anyway
        LOG.info("user install JUnit into userdir anyway");
        InstallLibraryTask.RP.post(installAnyway);
    } else {
        LOG.info("user canceled install JUnit into userdir");
    }
    
}
 
Example 3
Source File: PanelSourceFolders.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void searchClassFiles(File[] folders) throws WizardValidationException {
    List<File> classFiles = new ArrayList<File>();
    for (File folder : folders) {
        findClassFiles(folder, classFiles);
    }
    if (!classFiles.isEmpty()) {
        JButton DELETE_OPTION = new JButton(NbBundle.getMessage(PanelSourceFolders.class, "TXT_DeleteOption")); // NOI18N
        JButton KEEP_OPTION = new JButton(NbBundle.getMessage(PanelSourceFolders.class, "TXT_KeepOption")); // NOI18N
        JButton CANCEL_OPTION = new JButton(NbBundle.getMessage(PanelSourceFolders.class, "TXT_CancelOption")); // NOI18N
        KEEP_OPTION.setMnemonic(NbBundle.getMessage(PanelSourceFolders.class, "MNE_KeepOption").charAt(0)); // NOI18N
        DELETE_OPTION.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PanelSourceFolders.class, "AD_DeleteOption")); // NOI18N
        KEEP_OPTION.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PanelSourceFolders.class, "AD_KeepOption")); // NOI18N
        CANCEL_OPTION.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PanelSourceFolders.class, "AD_CancelOption")); // NOI18N
        NotifyDescriptor desc = new NotifyDescriptor(
                NbBundle.getMessage(PanelSourceFolders.class, "MSG_FoundClassFiles"), // NOI18N
                NbBundle.getMessage(PanelSourceFolders.class, "MSG_FoundClassFiles_Title"), // NOI18N
                NotifyDescriptor.YES_NO_CANCEL_OPTION,
                NotifyDescriptor.QUESTION_MESSAGE,
                new Object[]{DELETE_OPTION, KEEP_OPTION, CANCEL_OPTION},
                DELETE_OPTION);
        Object result = DialogDisplayer.getDefault().notify(desc);
        if (DELETE_OPTION.equals(result)) {
            for (File f : classFiles) {
                f.delete(); // ignore if fails
            }
        } else if (!KEEP_OPTION.equals(result)) {
            // cancel, back to wizard
            throw new WizardValidationException(this.sourcePanel, "", ""); // NOI18N
        }
    }
}
 
Example 4
Source File: StopManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean displayServerRunning() {
    JButton cancelButton = new JButton();
    Mnemonics.setLocalizedText(cancelButton, NbBundle.getMessage(StopManager.class, "StopManager.CancelButton")); // NOI18N
    cancelButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(StopManager.class, "StopManager.CancelButtonA11yDesc")); //NOI18N

    JButton keepWaitingButton = new JButton();
    Mnemonics.setLocalizedText(keepWaitingButton, NbBundle.getMessage(StopManager.class, "StopManager.KeepWaitingButton")); // NOI18N
    keepWaitingButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(StopManager.class, "StopManager.KeepWaitingButtonA11yDesc")); //NOI18N

    JButton propsButton = new JButton();
    Mnemonics.setLocalizedText(propsButton, NbBundle.getMessage(StopManager.class, "StopManager.PropsButton")); // NOI18N
    propsButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(StopManager.class, "StopManager.PropsButtonA11yDesc")); //NOI18N

    String message = NbBundle.getMessage(StopManager.class, "MSG_ServerStillRunning");
    final NotifyDescriptor ndesc = new NotifyDescriptor(message,
            NbBundle.getMessage(StopManager.class, "StopManager.ServerStillRunningTitle"),
            NotifyDescriptor.YES_NO_CANCEL_OPTION,
            NotifyDescriptor.QUESTION_MESSAGE,
            new Object[] {keepWaitingButton, propsButton, cancelButton},
            NotifyDescriptor.CANCEL_OPTION); //NOI18N

    Object ret = Mutex.EVENT.readAccess(new Action<Object>() {
        @Override
        public Object run() {
            return DialogDisplayer.getDefault().notify(ndesc);
        }

    });

    if (cancelButton.equals(ret)) {
        stopRequested.set(false);
        return false;
    } else if (keepWaitingButton.equals(ret)) {
        return true;
    } else {
        displayAdminProperties(server);
        return false;
    }
}
 
Example 5
Source File: TurnsPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public void disableButtonsTo(JButton b) {
	for (Component c : getComponents()) {
		if (c instanceof JButton) {
			JButton but = (JButton) c;
			if (!but.equals(b)) {
				but.getAction().setEnabled(false);
			} else {
				return;
			}
		}
	}
}
 
Example 6
Source File: DataInstaller.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent actionEvent)
{
	JButton source = (JButton) actionEvent.getSource();

	if (source == null)
	{
		// Do nothing
	}
	else if (source.equals(closeButton))
	{
		setVisible(false);
		dispose();
	}
	else if (source.equals(selectButton))
	{
		FileChooser fileChooser = new FileChooser();
		fileChooser.setInitialDirectory(currFolder);
		fileChooser.setTitle(LanguageBundle.getString("in_diChooserTitle"));
		FileChooser.ExtensionFilter dataSetFilter = new FileChooser.ExtensionFilter(
				"Data Sets", "*.pcz", "*.zip"
		);
		fileChooser.getExtensionFilters().add(dataSetFilter);
		fileChooser.setSelectedExtensionFilter(dataSetFilter);
		File dataset = GuiUtility.runOnJavaFXThreadNow(() -> fileChooser.showOpenDialog(null));
		if (dataset == null)
		{
			return;
		}
		currFolder = dataset.getParentFile();
		readDataSet(dataset);
	}
	else if (source.equals(installButton))
	{
		if (installDataSource(currDataSet, getSelectedDestination()))
		{
			//PCGen_Frame1.getInst().getMainSource().refreshCampaigns();
			//TODO: Refresh the data cleanly.
			//					PersistenceManager.getInstance().refreshCampaigns();
			//					FacadeFactory.refresh();
			ShowMessageDelegate.showMessageDialog(
				LanguageBundle.getFormattedString("in_diInstalled", campaign //$NON-NLS-1$
				.getDisplayName()), TITLE, MessageType.INFORMATION);
		}
	}
}
 
Example 7
Source File: FileCloseAction.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
private static boolean saveAndConfirmClose(final Model model, boolean firstOfMany)
{
    final ConfirmSaveDiscardJPanel confirmPanel = new ConfirmSaveDiscardJPanel(firstOfMany);
    JButton cancelButton = new JButton("Cancel");
    DialogDescriptor confirmDialog = 
                 new DialogDescriptor(confirmPanel, 
                     "Confirm Save",
                     true,
                     new Object[]{new JButton("Save"), new JButton("Discard"), cancelButton},
                     cancelButton,
                     0, null, new ActionListener(){

         @Override
         public void actionPerformed(ActionEvent e) {
             String cmd = e.getActionCommand();
             boolean remember = confirmPanel.rememberUserChoice();
             if (remember){
                 if (cmd.equalsIgnoreCase("Save")){
                     OpenSimDB.setCurrentCloseModelDefaultAction(CloseModelDefaultAction.SAVE);
                     FileSaveModelAction.saveOrSaveAsModel(model, false);
                 }
                 else if (cmd.equalsIgnoreCase("Discard")){
                     OpenSimDB.setCurrentCloseModelDefaultAction(CloseModelDefaultAction.DISCARD);                       
                 }
              } // Even if user doesn't want to remember decision, save Model
             else if (cmd.equalsIgnoreCase("Save")){
                 FileSaveModelAction.saveOrSaveAsModel(model, false);
             }
         }
     });
    confirmDialog.setClosingOptions(null);
    DialogDisplayer.getDefault().createDialog(confirmDialog).setVisible(true);
    Object dlgReturn = confirmDialog.getValue();
    // We'll get here after user closes the dialog.
    boolean closed = ((dlgReturn instanceof Integer) && (((Integer)dlgReturn).intValue()==-1));
    return (!closed && ! cancelButton.equals(dlgReturn));
    /*
    NotifyDescriptor dlg = new NotifyDescriptor.Confirmation("Do you want to save the changes to " + model.getName() + "?", "Save model?");
   Object userSelection = DialogDisplayer.getDefault().notify(dlg);
   if (((Integer)userSelection).intValue() == ((Integer)NotifyDescriptor.OK_OPTION).intValue()) {
      return FileSaveModelAction.saveOrSaveAsModel(model);
   } else if (((Integer)userSelection).intValue() == ((Integer)NotifyDescriptor.NO_OPTION).intValue()) {
      return true;
   } else {
      return false;
   }*/
}
 
Example 8
Source File: DataInstaller.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent actionEvent)
{
	JButton source = (JButton) actionEvent.getSource();

	if (source == null)
	{
		// Do nothing
	}
	else if (source.equals(closeButton))
	{
		setVisible(false);
		dispose();
	}
	else if (source.equals(selectButton))
	{
		FileChooser fileChooser = new FileChooser();
		fileChooser.setInitialDirectory(currFolder);
		fileChooser.setTitle(LanguageBundle.getString("in_diChooserTitle"));
		FileChooser.ExtensionFilter dataSetFilter = new FileChooser.ExtensionFilter(
				"Data Sets", "*.pcz", "*.zip"
		);
		fileChooser.getExtensionFilters().add(dataSetFilter);
		fileChooser.setSelectedExtensionFilter(dataSetFilter);
		File dataset = GuiUtility.runOnJavaFXThreadNow(() -> fileChooser.showOpenDialog(null));
		if (dataset == null)
		{
			return;
		}
		currFolder = dataset.getParentFile();
		readDataSet(dataset);
	}
	else if (source.equals(installButton))
	{
		if (installDataSource(currDataSet, getSelectedDestination()))
		{
			//PCGen_Frame1.getInst().getMainSource().refreshCampaigns();
			//TODO: Refresh the data cleanly.
			//					PersistenceManager.getInstance().refreshCampaigns();
			//					FacadeFactory.refresh();
			ShowMessageDelegate.showMessageDialog(
				LanguageBundle.getFormattedString("in_diInstalled", campaign //$NON-NLS-1$
				.getDisplayName()), TITLE, MessageType.INFORMATION);
		}
	}
}