Java Code Examples for javax.swing.JOptionPane#CANCEL_OPTION

The following examples show how to use javax.swing.JOptionPane#CANCEL_OPTION . 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: MainFrame.java    From procamcalib with GNU General Public License v2.0 6 votes vote down vote up
private void calibrationSaveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calibrationSaveMenuItemActionPerformed
    if (calibrationWorker == null) {
        JOptionPane.showMessageDialog(this,
                "There is no calibration data to save.",
                NO_CALIBRATION_DATA,
                JOptionPane.WARNING_MESSAGE);
        return;
    }

    if (calibrationFile == null) {
        calibrationSaveAsMenuItemActionPerformed(evt);
    } else {
        if (calibrationFile.exists()) {
            int response = JOptionPane.showConfirmDialog(this,
                    OVERWRITE_EXISTING_FILE + calibrationFile + "\"?", CONFIRM_OVERWRITE,
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (response == JOptionPane.CANCEL_OPTION) {
                calibrationSaveAsMenuItemActionPerformed(evt);
                return;
            }
        }
        calibrationWorker.writeParameters(calibrationFile);
        statusLabel.setText("Calibration data saved.");
    }

}
 
Example 2
Source File: LaunchBuilder.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Offers to save changes, if any, to the specified tab.
 *
 * @param tab the tab
 * @return true unless cancelled by user
 */
protected boolean saveChanges(LaunchPanel tab) {
  LaunchNode root = tab.getRootNode();
  int n = tabbedPane.indexOfComponent(tab);
  String name = (n>-1) ? tabbedPane.getTitleAt(n) : getDisplayName(root.getFileName());
  boolean changed = changedFiles.contains(root.getFileName());
  LaunchNode[] nodes = root.getAllOwnedNodes();
  for(int i = 0; i<nodes.length; i++) {
    changed = changed||changedFiles.contains(nodes[i].getFileName());
  }
  if(changed) {
    int selected = JOptionPane.showConfirmDialog(frame, LaunchRes.getString("Dialog.SaveChanges.Tab.Message")+" \""+ //$NON-NLS-1$//$NON-NLS-2$
      name+"\""+XML.NEW_LINE+                               //$NON-NLS-1$
        LaunchRes.getString("Dialog.SaveChanges.Question"), //$NON-NLS-1$
          LaunchRes.getString("Dialog.SaveChanges.Title"),  //$NON-NLS-1$
            JOptionPane.YES_NO_CANCEL_OPTION);
    if(selected==JOptionPane.CANCEL_OPTION) {
      return false;
    }
    if(selected==JOptionPane.YES_OPTION) {
      // save root and all owned nodes
      save(root, root.getFileName());
    }
  }
  return true;
}
 
Example 3
Source File: FrmSimulator.java    From drmips with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Shows the file chooser to open a file.
 */
private void openFile() {
	boolean open = true;
	if(txtCode != null && txtCode.isDirty()) { // file changed?
		int opt = JOptionPane.showConfirmDialog(this, Lang.t("code_changed"), AppInfo.NAME, JOptionPane.YES_NO_CANCEL_OPTION);
		switch(opt) {
			case JOptionPane.YES_OPTION:
				open = true;
				saveFile();
				break;
			case JOptionPane.NO_OPTION: open = true; break;
			case JOptionPane.CANCEL_OPTION: open = false; break;
		}
	}

	if(open) {
		codeFileChooser.setDialogTitle(Lang.t("open"));
		if(codeFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
			openFile(codeFileChooser.getSelectedFile());
	}
}
 
Example 4
Source File: FrmSimulator.java    From drmips with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
	boolean open = true;
	if(txtCode != null && txtCode.isDirty()) { // file changed?
		int opt = JOptionPane.showConfirmDialog(FrmSimulator.this, Lang.t("code_changed"), AppInfo.NAME, JOptionPane.YES_NO_CANCEL_OPTION);
		switch(opt) {
			case JOptionPane.YES_OPTION:
				open = true;
				saveFile();
				break;
			case JOptionPane.NO_OPTION: open = true; break;
			case JOptionPane.CANCEL_OPTION: open = false; break;
		}
	}

	if(open)
		openFile(file);
}
 
Example 5
Source File: J2DBench.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static boolean saveOrDiscardLastResults() {
    if (lastResults != null) {
        int ret = JOptionPane.showConfirmDialog
            (guiFrame,
             "The results of the last test will be "+
             "discarded if you continue!  Do you want "+
             "to save them?",
             "Discard last results?",
             JOptionPane.YES_NO_CANCEL_OPTION);
        if (ret == JOptionPane.CANCEL_OPTION) {
            return false;
        } else if (ret == JOptionPane.YES_OPTION) {
            if (saveResults()) {
                lastResults = null;
            } else {
                return false;
            }
        }
    }
    return true;
}
 
Example 6
Source File: MainFrame.java    From zxpoly with GNU General Public License v3.0 6 votes vote down vote up
private void openSzeFileForPath(final String path) {
  final File file = new File(path);
  if (file.isFile()) {
    if (this.mainEditor.isChanged()) {
      if (showConfirmDialog(this, "Open file '" + file.getName() + "'?", "Confirmation",
          JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
        return;
      }
    }

    final SZEPlugin szePlugin = container.getComponent(SZEPlugin.class);

    try {
      loadFileWithPlugin(szePlugin, file, -1);
    } catch (IOException ex) {
      JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
  } else {
    JOptionPane.showMessageDialog(this, "Can't find file '" + path + '\'', "Error",
        JOptionPane.ERROR_MESSAGE);
  }
}
 
Example 7
Source File: GMLEditor.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void checkForChanges() throws CancelledByUserException {
    if (changed) {
        switch (JOptionPane.showConfirmDialog(null, "The current map has changes. Do you want to save them?")) {
        case JOptionPane.YES_OPTION:
            try {
                save();
            }
            catch (MapException e) {
                JOptionPane.showMessageDialog(null, e);
                throw new CancelledByUserException();
            }
            break;
        case JOptionPane.NO_OPTION:
            changed = false;
            return;
        case JOptionPane.CANCEL_OPTION:
            throw new CancelledByUserException();
        default:
            throw new RuntimeException("JOptionPane.showConfirmDialog returned something weird");
        }
    }
}
 
Example 8
Source File: EditWindow.java    From Pixie with MIT License 5 votes vote down vote up
/**
 * Checks if the frame attributes are correctly set and asks the user to
 * correct them. If the user chooses to correct them, the application does
 * not continue with the saving of data; it will cancel the process and go
 * back to the normal state.
 *
 * @return true if the user wants to save the data as it is and false if the
 * saving of data shall not be done yet, because the user wants to correct
 * it
 */
protected boolean isObjectAttributesSet() {
    // make sure the user wants to check the frame attributes
    if (!userPrefs.isCheckObjectAttributes()) {
        return true;
    }

    StringBuilder invalidAttribute = new StringBuilder();

    // check each frame attribute and create a list of missing frame attributes
    Utils.checkAttributeValid(invalidAttribute, jCBObjType.getItemAt(jCBObjType.getSelectedIndex()), jLType.getText());
    Utils.checkAttributeValid(invalidAttribute, jCBObjClass.getItemAt(jCBObjClass.getSelectedIndex()), jLClass.getText());
    Utils.checkAttributeValid(invalidAttribute, jCBObjValue.getItemAt(jCBObjValue.getSelectedIndex()), jLValue.getText());
    Utils.checkAttributeValid(invalidAttribute, jCBOccluded.getItemAt(jCBOccluded.getSelectedIndex()), jLOccluded.getText());

    // if missing attributes were found, display the message window to warn the user to correct the attributes
    if (invalidAttribute.length() > 0) {
        // remove the last comma and the last space from the string
        invalidAttribute.replace(invalidAttribute.length() - 2, invalidAttribute.length(), "");

        // ask the user if the current attributes shall be saved or not; if the user wants to correct them, stop the application and let him fix them
        int userChoice = Utils.messageAttributesSet(invalidAttribute.toString(), true, this);

        if (userChoice == JOptionPane.CANCEL_OPTION) {
            // the user chose to edit the attributes; display the dialog and allow it
            observable.notifyObservers(ObservedActions.Action.DISPLAY_EDIT_ATTRIBUTES_WIN);
        }

        return ((JOptionPane.YES_OPTION != userChoice) && (JOptionPane.CANCEL_OPTION != userChoice));
    }

    return true;
}
 
Example 9
Source File: TestSetValidator.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private Boolean removeInvalidSteps() {
    int i = 0;
    List<Integer> steps = new ArrayList<>();
    for (ExecutionStep testStep1 : getCurrentTestSet().getTestSteps()) {
        Boolean isFull = !Objects.toString(testStep1.getTestScenarioName(), "").isEmpty()
                && !Objects.toString(testStep1.getTestCaseName(), "").isEmpty()
                && !Objects.toString(testStep1.getBrowser(), "").isEmpty()
                && !Objects.toString(testStep1.getIteration(), "").isEmpty()
                && !Objects.toString(testStep1.getBrowserVersion(), "").isEmpty()
                && !Objects.toString(testStep1.getPlatform(), "").isEmpty();
        if (!isFull) {
            steps.add(i);
        }
        i++;
    }
    if (!steps.isEmpty()) {
        int val = JOptionPane.showConfirmDialog(null,
                "The TestSet has Invalid entries."
                + steps
                + ". Do you want to remove them?",
                "Remove Invalid Entries", JOptionPane.YES_NO_CANCEL_OPTION);
        if (val == JOptionPane.CANCEL_OPTION) {
            return false;
        } else if (val == JOptionPane.YES_OPTION) {
            Collections.reverse(steps);
            getCurrentTestSet().removeSteps(steps);
        }
    }
    return true;
}
 
Example 10
Source File: MethodCallDialog.java    From blocktalk with GNU General Public License v3.0 5 votes vote down vote up
int buildMessage() {
    Method m = methodMap.get(methodComboBox.getSelectedItem());

    Object[] argValues = new Object[3];

    Parameter[] pars = m.getParameters();
    for (int i = 0; i < pars.length && i < 3; i++) {
        String type = pars[i].getType().getName();
        if (type.equals(Address.class.getName())) {
            Address addr = Emulator.getInstance().getAddress(args[i].getText());
            argValues[i] = addr;
        } else if (type.equals(Long.class.getName()) || type.equals("long")) {
            argValues[i] = Long.valueOf(args[i].getText());
        } else if (type.equals(Integer.class.getName()) || type.equals("int")) {
            argValues[i] = Integer.valueOf(args[i].getText());
        } else if (type.equals(Boolean.class.getName()) || type.equals("boolean")) {
            argValues[i] = Boolean.valueOf(args[i].getText());
        } else {
            // unsuported value type

            return JOptionPane.CANCEL_OPTION;
        }
    }

    msg = Register.newMethodCall(m, argValues);

    return JOptionPane.OK_OPTION;
}
 
Example 11
Source File: MiniEdit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void close() {
    Doc doc = getSelectedDoc();
    if (doc != null) {
        if (doc.isModified()) {
            /*
            int opt = JOptionPane.showOptionDialog(this, 
                "Document is modified. Save?", "Unsaved changes", null,
                //JOptionPane.YES_NO_CANCEL_OPTION,  
                JOptionPane.QUESTION_MESSAGE, (Icon) null, 
                new String[] {"OK", "Cancel"}, 
                "Close");
             */
            int opt = JOptionPane.showConfirmDialog(this, 
                "Document is modified. Save?", "Unsaved changes",
                JOptionPane.YES_NO_CANCEL_OPTION, 
                JOptionPane.QUESTION_MESSAGE);
            if (opt == JOptionPane.CANCEL_OPTION) {
                return;
            }
            if (opt == JOptionPane.YES_OPTION) {
                doc.save();
            }
        }
        documentTabs.remove(doc.getTextPane().getParent().getParent());
        openDocs.remove(doc);
    }
}
 
Example 12
Source File: GUILabelingTool.java    From Pixie with MIT License 5 votes vote down vote up
/**
 * Close application in a safe way. Close all the open resources and stop
 * the application.
 */
private void closeApplication() {
    // ask the user to save its work if there are objects unsaved

    if (gc.getObjectsListSize() > 0) {
        int response = Messages.showQuestionYesNoCancelMessage(this,
                "There are objects which were not saved in the ground truth storage.\nThe work will be lost if you choose no!\nDo you want to save them?",
                "Objects not saved!!!");
        if (JOptionPane.YES_OPTION == response) {
            // make sure the frame attributes are saved and ask the user to correct them otherwise
            if (!isFrameAttribSet()) {
                // the user wants to correct the data, do not close the application!
                return;
            }

            // save the list of objects
            saveImgResultsAndData();
        } else if (JOptionPane.CANCEL_OPTION == response) {
            // do not close the application
            return;
        }
    }

    userPrefs.setPlayBackward(jCBPlayBackward.isSelected());

    userPrefs.saveUserPreferences();

    gc.terminateThreads();

    System.exit(0);
}
 
Example 13
Source File: DeleteFromOverviewAction.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * When the action is performed, selection is deleted if possible. Error is
 * displayed if no graph item is selected.
 *
 * @param e The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
	Object[] currentSelection = _theOverview.getSelectionCells();

	if (currentSelection.length != 1) {
		return;
	}

	Object cell = currentSelection[0];
	String confirm = "Are you sure you want to delete selected item?";

	if (cell instanceof SketchNode) {
		if (((SketchNode) cell).getMModel().isSynced()) {
			confirm = "Warning: this sketch is currently synced with a db; delete and break synchronization?";
		}

		if (JOptionPane.showConfirmDialog(_theOverview.getFrame(), confirm, "Warning!",
				JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
			return;
		}

		_theOverview.removeSketch((SketchNode) cell);
	} else if (cell instanceof ViewNode) {
		if (((ViewNode) cell).getMModel().getSketch().isSynced()) {
			confirm = "Warning: this view is of a sketch that is currently synced with a db; delete and break synchronization?";
		}

		if (JOptionPane.showConfirmDialog(_theOverview.getFrame(), confirm, "Warning!",
				JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
			return;
		}

		_theOverview.removeView((ViewNode) cell);
	}

	_theOverview.setDirty(true);
	_theOverview.clearSelection();
}
 
Example 14
Source File: QFixMessengerFrame.java    From quickfix-messenger with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Disposes the frame and gracefully exits the application
 */
public void close()
{
	int choice = JOptionPane.showConfirmDialog(this,
			"Exit QuickFIX Messenger?", "Quit", JOptionPane.YES_NO_OPTION);
	if (choice == JOptionPane.YES_OPTION)
	{
		if (activeXmlProject != null)
		{
			choice = JOptionPane.showConfirmDialog(this,
					"Do you want to save \"" + activeXmlProject.getName()
							+ "\"?", "Save Current Project",
					JOptionPane.YES_NO_CANCEL_OPTION);
			switch (choice)
			{
			case JOptionPane.NO_OPTION:
				break;
			case JOptionPane.YES_OPTION:
				marshallActiveXmlProject();
				break;
			case JOptionPane.CANCEL_OPTION:
				return;
			}
		}
		dispose();
		messenger.exit();
	}
}
 
Example 15
Source File: AddUniqueKeyAction.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Inserts a unique key to the currently selected entity
 * 
 * @param e The action event
 */
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
	// If there is nothing selected then just do nothing
	if (_theFrame.getMModel().getSelectionCells().length != 1) {
		return;
	}

	// If we're currently synced with a db, give the user the chance to
	// cancel operation
	if (_theFrame.getMModel().isSynced()) {
		int choice = JOptionPane.showConfirmDialog(_theFrame,
				"Warning: this sketch is currently synced with a db; continue and break synchronization?",
				"Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);

		if (choice == JOptionPane.CANCEL_OPTION) {
			return;
		}
	}

	// Get currently selected object
	Object curSelected = _theFrame.getMModel().getSelectionCells()[0];
	N curEntity;

	// Check what is currently selected
	if (curSelected instanceof ModelVertex) {
		// Entity is selected so set it as current entity
		curEntity = (N) curSelected;
	} else {
		JOptionPane.showMessageDialog(_theFrame,
				"You have not selected an entity to add the unique key to.\nPlease select an entity and try again.",
				"No entity selected", JOptionPane.ERROR_MESSAGE);

		return;
	}

	// If the entity does not contain any attributes
	if (curEntity.getEntityAttributes().isEmpty() && curEntity.getIndexableEdges().isEmpty()) {
		// Pop up error dialog
		JOptionPane.showMessageDialog(_theFrame,
				"The selected entity has no attributes/edges.\nA unique key can only be added to an entity with\nattributes or outgoing, non-injective edges.",
				"Entity has no attributes/edges", JOptionPane.ERROR_MESSAGE);

		return;
	}

	UniqueKeyUI<F, GM, M, N, E> myUI = new UniqueKeyUI<>(_theFrame, curEntity);

	if (myUI.showDialog()) {
		UniqueKey<F, GM, M, N, E> newKey = new UniqueKey<>(curEntity, myUI.getSelectedElements(),
				myUI.getKeyName());

		// Create new unique key
		curEntity.addUniqueKey(newKey);
		_theFrame.getInfoTreeUI().refreshTree(curEntity); // Refresh view of
															// entity keys
		_theFrame.getMModel().clearSelection();
		_theFrame.getMModel().setDirty();
		_theFrame.getMModel().setSynced(false);
	}
}
 
Example 16
Source File: DialogCallbackHandler.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 17
Source File: PCGenFrame.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Loads a character from a file. Any sources that are required for
 * this character are loaded first, then the character is loaded
 * from the file and a tab is opened for it.
 * @param pcgFile a file specifying the character to be loaded
 */
public void loadCharacterFromFile(final File pcgFile)
{
	if (!PCGFile.isPCGenCharacterFile(pcgFile))
	{
		this.showErrorMessage(LanguageBundle.getFormattedString("in_loadPcInvalid", pcgFile),
				LanguageBundle.getFormattedString("in_loadPcInvalid", pcgFile)	);
		return;
	}
	if (!pcgFile.canRead())
	{
		this.showErrorMessage(LanguageBundle.getFormattedString("in_loadPcFailTtile"),
				LanguageBundle.getFormattedString("in_loadPcNoRead", pcgFile)	);
		return;
	}

	SourceSelectionFacade sources = CharacterManager.getRequiredSourcesForCharacter(pcgFile, this);
	if (sources == null)
	{
		this.showErrorMessage(LanguageBundle.getFormattedString("in_loadPcNoSources", pcgFile),
				LanguageBundle.getString("in_loadPcFailTtile"));
	}
	else if (!sources.getCampaigns().isEmpty())
	{
		// Check if the user has asked that sources not be loaded with the character
		boolean dontLoadSources = currentSourceSelection.get() != null
			&& !PCGenSettings.OPTIONS_CONTEXT.initBoolean(PCGenSettings.OPTION_AUTOLOAD_SOURCES_WITH_PC, true);
		boolean sourcesSame = checkSourceEquality(sources, currentSourceSelection.get());
		boolean gameModesSame = checkGameModeEquality(sources, currentSourceSelection.get());
		if (!dontLoadSources && !sourcesSame && gameModesSame)
		{
			Object[] btnNames = {LanguageBundle.getString("in_loadPcDiffSourcesLoaded"),
				LanguageBundle.getString("in_loadPcDiffSourcesCharacter"), LanguageBundle.getString("in_cancel")};
			int choice = JOptionPane.showOptionDialog(this,
				LanguageBundle.getFormattedString("in_loadPcDiffSources",
					getFormattedCampaigns(currentSourceSelection.get()), getFormattedCampaigns(sources)),
				LanguageBundle.getString("in_loadPcSourcesLoadTitle"), JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.QUESTION_MESSAGE, null, btnNames, null);
			if (choice == JOptionPane.CANCEL_OPTION)
			{
				return;
			}
			if (choice == JOptionPane.YES_OPTION)
			{
				openCharacter(pcgFile, currentDataSetRef.get());
				return;
			}
		}

		if (dontLoadSources)
		{
			if (!checkSourceEquality(sources, currentSourceSelection.get()))
			{
				Logging.log(Logging.WARNING, "Loading character with different sources. Character: " + sources
					+ " current: " + currentSourceSelection.get());
			}
			openCharacter(pcgFile, currentDataSetRef.get());
		}
		else if (loadSourceSelection(sources))
		{
			if (sourceSelectionDialog == null)
			{
				sourceSelectionDialog = new SourceSelectionDialog(this, uiContext);
			}
			((SourceSelectionDialog) sourceSelectionDialog).setAdvancedSources(sources);
			currentSourceSelection.set(sources);
			loadSourcesThenCharacter(pcgFile);
		}
		else
		{
			JOptionPane.showMessageDialog(this, LanguageBundle.getString("in_loadPcIncompatSource"), //$NON-NLS-1$
				LanguageBundle.getString("in_loadPcFailTtile"), //$NON-NLS-1$
				JOptionPane.ERROR_MESSAGE);
		}
	}
	else if (currentDataSetRef.get() != null)
	{
		if (showWarningConfirm(Constants.APPLICATION_NAME,
			LanguageBundle.getFormattedString("in_loadPcSourcesLoadQuery", //$NON-NLS-1$
				pcgFile)))
		{
			openCharacter(pcgFile, currentDataSetRef.get());
		}
	}
	else
	{
		// No character sources and no sources loaded.
		this.showErrorMessage(LanguageBundle.getFormattedString("in_loadPcNoSources", pcgFile),
				LanguageBundle.getString("in_loadPcFailTtile"));
	}
}
 
Example 18
Source File: FramePrincipal.java    From brModelo with GNU General Public License v3.0 4 votes vote down vote up
public void Fechador(boolean sofecha) throws HeadlessException {
        if (formPartes != null && formPartes.Partes.isMudou() && (!sofecha)) {
            if (util.Dialogos.ShowMessageConfirm(this.getRootPane(), Editor.fromConfiguracao.getValor("Controler.MSG_SAVE_TEMPLATE")) == JOptionPane.YES_OPTION) {
                formPartes.Salva();
            }
        }

        Salvar fm = new Salvar(this, true);
        fm.Carregue(Manager);
        fm.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        fm.setLocationRelativeTo(this);
        if (sofecha && Manager.getDiagramas().size() == 1 && (!Manager.diagramaAtual.getMudou())) {
            Manager.FechaDiagrama(0);
            return;
        } else {
            fm.setVisible(true);
        }
        if (fm.resultado == JOptionPane.CANCEL_OPTION) {
            return;
        }
        int i = 0;
        for (Diagrama d : Manager.getDiagramas()) {
            if (d.getMudou()) {
                if (fm.getCheks().get(i).isSelected()) {
                    if (!d.Salvar(d.getArquivo())) {
                        return;
                    }
                }
            }
            i++;
        }
        if (sofecha) {
            Manager.FecharTudo();
        }

        String tmp = "";
        tmp = Manager.getRecentes().stream().map(s -> s + ";").reduce(tmp, String::concat);
        if (tmp.trim().length() > 2) {
            tmp = tmp.substring(0, tmp.length() - 1);
        } else {
            tmp = "";
        }
        Editor.fromConfiguracao.setValor("cfg.location.x", String.valueOf(getLocation().x));
        Editor.fromConfiguracao.setValor("cfg.location.y", String.valueOf(getLocation().y));
        Editor.fromConfiguracao.setValor("cfg.recentes", tmp);
        if (!sofecha) {
            if (formAjuda != null && formAjuda.AjudaMng.isMudou()) {
                if (util.Dialogos.ShowMessageConfirm(this.getRootPane(), Editor.fromConfiguracao.getValor("Controler.MSG_SAVE_HELP")) == JOptionPane.YES_OPTION) {
                    formAjuda.Salva();
                }
            }
            Manager.EndAutoSave();
            System.exit(0);
        }
//                Editor.fromConfiguracao.getValor("Controler.MSG_CLOSE_TITLE"),
//                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
//        if (i == JOptionPane.YES_OPTION) {
//            //Utilidade.configFile.clear();
//            System.exit(0);
//        }
    }
 
Example 19
Source File: PCGenFrame.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Loads a character from a file. Any sources that are required for
 * this character are loaded first, then the character is loaded
 * from the file and a tab is opened for it.
 * @param pcgFile a file specifying the character to be loaded
 */
public void loadCharacterFromFile(final File pcgFile)
{
	if (!PCGFile.isPCGenCharacterFile(pcgFile))
	{
		this.showErrorMessage(LanguageBundle.getFormattedString("in_loadPcInvalid", pcgFile),
				LanguageBundle.getFormattedString("in_loadPcInvalid", pcgFile)	);
		return;
	}
	if (!pcgFile.canRead())
	{
		this.showErrorMessage(LanguageBundle.getFormattedString("in_loadPcFailTtile"),
				LanguageBundle.getFormattedString("in_loadPcNoRead", pcgFile)	);
		return;
	}

	SourceSelectionFacade sources = CharacterManager.getRequiredSourcesForCharacter(pcgFile, this);
	if (sources == null)
	{
		this.showErrorMessage(LanguageBundle.getFormattedString("in_loadPcNoSources", pcgFile),
				LanguageBundle.getString("in_loadPcFailTtile"));
	}
	else if (!sources.getCampaigns().isEmpty())
	{
		// Check if the user has asked that sources not be loaded with the character
		boolean dontLoadSources = currentSourceSelection.get() != null
			&& !PCGenSettings.OPTIONS_CONTEXT.initBoolean(PCGenSettings.OPTION_AUTOLOAD_SOURCES_WITH_PC, true);
		boolean sourcesSame = checkSourceEquality(sources, currentSourceSelection.get());
		boolean gameModesSame = checkGameModeEquality(sources, currentSourceSelection.get());
		if (!dontLoadSources && !sourcesSame && gameModesSame)
		{
			Object[] btnNames = {LanguageBundle.getString("in_loadPcDiffSourcesLoaded"),
				LanguageBundle.getString("in_loadPcDiffSourcesCharacter"), LanguageBundle.getString("in_cancel")};
			int choice = JOptionPane.showOptionDialog(this,
				LanguageBundle.getFormattedString("in_loadPcDiffSources",
					getFormattedCampaigns(currentSourceSelection.get()), getFormattedCampaigns(sources)),
				LanguageBundle.getString("in_loadPcSourcesLoadTitle"), JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.QUESTION_MESSAGE, null, btnNames, null);
			if (choice == JOptionPane.CANCEL_OPTION)
			{
				return;
			}
			if (choice == JOptionPane.YES_OPTION)
			{
				openCharacter(pcgFile, currentDataSetRef.get());
				return;
			}
		}

		if (dontLoadSources)
		{
			if (!checkSourceEquality(sources, currentSourceSelection.get()))
			{
				Logging.log(Logging.WARNING, "Loading character with different sources. Character: " + sources
					+ " current: " + currentSourceSelection.get());
			}
			openCharacter(pcgFile, currentDataSetRef.get());
		}
		else if (loadSourceSelection(sources))
		{
			if (sourceSelectionDialog == null)
			{
				sourceSelectionDialog = new SourceSelectionDialog(this, uiContext);
			}
			((SourceSelectionDialog) sourceSelectionDialog).setAdvancedSources(sources);
			currentSourceSelection.set(sources);
			loadSourcesThenCharacter(pcgFile);
		}
		else
		{
			JOptionPane.showMessageDialog(this, LanguageBundle.getString("in_loadPcIncompatSource"), //$NON-NLS-1$
				LanguageBundle.getString("in_loadPcFailTtile"), //$NON-NLS-1$
				JOptionPane.ERROR_MESSAGE);
		}
	}
	else if (currentDataSetRef.get() != null)
	{
		if (showWarningConfirm(Constants.APPLICATION_NAME,
			LanguageBundle.getFormattedString("in_loadPcSourcesLoadQuery", //$NON-NLS-1$
				pcgFile)))
		{
			openCharacter(pcgFile, currentDataSetRef.get());
		}
	}
	else
	{
		// No character sources and no sources loaded.
		this.showErrorMessage(LanguageBundle.getFormattedString("in_loadPcNoSources", pcgFile),
				LanguageBundle.getString("in_loadPcFailTtile"));
	}
}
 
Example 20
Source File: DiagramGraphIO.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private static File selectGraphFile(Component parentComponent,
                                    String title,
                                    SnapFileFilter[] fileFilters,
                                    PropertyMap preferences,
                                    boolean open) {
    String lastDirPath = preferences.getPropertyString(DIAGRAM_GRAPH_IO_LAST_DIR_KEY, ".");
    SnapFileChooser fileChooser = new SnapFileChooser(new File(lastDirPath));
    fileChooser.setAcceptAllFileFilterUsed(true);
    fileChooser.setDialogTitle(title);
    for (SnapFileFilter fileFilter : fileFilters) {
        fileChooser.addChoosableFileFilter(fileFilter);
    }
    fileChooser.setFileFilter(fileFilters[0]);
    if (open) {
        fileChooser.setDialogType(SnapFileChooser.OPEN_DIALOG);
    } else {
        fileChooser.setDialogType(SnapFileChooser.SAVE_DIALOG);
    }
    File selectedFile;
    while (true) {
        int i = fileChooser.showDialog(parentComponent, null);
        if (i == SnapFileChooser.APPROVE_OPTION) {
            selectedFile = fileChooser.getSelectedFile();
            if (open || !selectedFile.exists()) {
                break;
            }
            i = JOptionPane.showConfirmDialog(parentComponent,
                                              "The file\n" + selectedFile + "\nalready exists.\nOverwrite?",
                                              "File exists", JOptionPane.YES_NO_CANCEL_OPTION);
            if (i == JOptionPane.CANCEL_OPTION) {
                // Canceled
                selectedFile = null;
                break;
            } else if (i == JOptionPane.YES_OPTION) {
                // Overwrite existing file
                break;
            }
        } else {
            // Canceled
            selectedFile = null;
            break;
        }
    }
    if (selectedFile != null) {
        preferences.setPropertyString(DIAGRAM_GRAPH_IO_LAST_DIR_KEY, selectedFile.getParent());
    }
    return selectedFile;
}