Java Code Examples for javax.swing.JOptionPane.CLOSED_OPTION

The following are Jave code examples for showing how to use CLOSED_OPTION of the javax.swing.JOptionPane class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: appinventor-extensions   File: AIMerger.java   View Source Code Vote up 7 votes
private void closeApplication() {
  int response = JOptionPane.showOptionDialog(myCP, "Exit AIMerger?", "Exit",
      JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null,
      JOptionPane.YES_OPTION);
  switch (response) {
    default:
      // This should never happen
      throw new IllegalArgumentException("not an option");
    case JOptionPane.CLOSED_OPTION:
    case JOptionPane.CANCEL_OPTION:
      offerNewMerge();
      break;
    case JOptionPane.OK_OPTION:
      System.exit(0);
      break;
  }
}
 
Example 2
Project: incubator-netbeans   File: Terminal.java   View Source Code Vote up 6 votes
public void actionPerformed(ActionEvent e) {
    if (!isEnabled())
        return;

    TermOptions clonedTermOptions = termOptions.makeCopy();
    TermOptionsPanel subPanel = new TermOptionsPanel();
    subPanel.setTermOptions(clonedTermOptions);

    JOptionPane optionPane = new JOptionPane(subPanel,
                                             JOptionPane.PLAIN_MESSAGE,
                                             JOptionPane.OK_CANCEL_OPTION
                                             );
        JDialog dialog = optionPane.createDialog(Terminal.this,
                                                 "NBTerm Options");
        dialog.setVisible(true);      // WILL BLOCK!

        if (optionPane.getValue() == null)
            return;     // was closed at the window level

        switch ((Integer) optionPane.getValue()) {
            case JOptionPane.OK_OPTION:
                System.out.printf("Dialog returned OK\n");
                termOptions.assign(clonedTermOptions);
                applyTermOptions(false);
                termOptions.storeTo(prefs);
                break;
            case JOptionPane.CANCEL_OPTION:
                System.out.printf("Dialog returned CANCEL\n");
                break;
            case JOptionPane.CLOSED_OPTION:
                System.out.printf("Dialog returned CLOSED\n");
                break;
            default:
                System.out.printf("Dialog returned OTHER: %s\n",
                                  optionPane.getValue());
                break;
        }
}
 
Example 3
Project: DBan-Config-Generator   File: InputFrame.java   View Source Code Vote up 6 votes
public File getChosenSaveFile(){
    JFileChooser fc = new JFileChooser(){
        @Override
        public void approveSelection(){
            File f = getSelectedFile();
            if(f.exists() && getDialogType() == SAVE_DIALOG){
                int result = JOptionPane.showConfirmDialog(this,"The file exists, overwrite?","Existing file",JOptionPane.YES_NO_OPTION);
                switch(result){
                    case JOptionPane.YES_OPTION:
                        super.approveSelection();
                        return;
                    case JOptionPane.NO_OPTION:
                    case JOptionPane.CLOSED_OPTION:
                        return;
                }
            }
            super.approveSelection();
        }        
    };
            
    if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
        return fc.getSelectedFile();
    else
        return null;
}
 
Example 4
Project: VASSAL-src   File: Dialogs.java   View Source Code Vote up 6 votes
public static int showConfirmDialog(
    Component parent,
    String title,
    String heading,
    String message,
    int messageType,
    Icon icon,
    int optionType,
    Object key,
    String disableMsg)
{
  final Object o = showDialog(parent, title, buildContents(heading, message),
    messageType, icon, optionType, null, null, key, disableMsg);

  if (o == null || !(o instanceof Integer))
    return JOptionPane.CLOSED_OPTION;
  else
    return ((Integer) o).intValue();
}
 
Example 5
Project: etomica   File: Display.java   View Source Code Vote up 6 votes
public static String prompt(String label, String data, String[] list,
                            boolean asButtons) {
  try {
    if (!asButtons)
      return JOptionPane.showInputDialog(label, data);
    if (data != null)
      list = TextFormat.splitChars(data, "|");
    int i = JOptionPane.showOptionDialog(null, label, "Jmol prompt",
        JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
        list, list[0]);
    // ESCAPE will close the panel with no option selected.
    return (data == null ? "" + i : i == JOptionPane.CLOSED_OPTION ? "null"
        : list[i]);
  } catch (Throwable e) {
    return "null";
  }

}
 
Example 6
Project: appinventor-extensions   File: AIMerger.java   View Source Code Vote up 6 votes
private void offerNewMerge() {
  int response = JOptionPane.showOptionDialog(myCP, "Projects Successfully Merged. "
          + "Would you like to merge more projects?", "Projects Merged", JOptionPane.YES_NO_OPTION,
      JOptionPane.INFORMATION_MESSAGE, null, null, JOptionPane.YES_OPTION);
  switch (response) {
    default:
      // This should never happen
      throw new IllegalArgumentException("not an option");
    case JOptionPane.CLOSED_OPTION:
    case JOptionPane.NO_OPTION:
      closeApplication();
      break;
    case JOptionPane.YES_OPTION:
      offerToMergeToNewProject();
      break;
  }
}
 
Example 7
Project: appinventor-extensions   File: AIMerger.java   View Source Code Vote up 6 votes
private void offerToMergeToNewProject() {
  int response = JOptionPane.showOptionDialog(myCP, "Would you like one of the projects to merge"
          + " to be the project you just created?", "Merge More Projects", JOptionPane.YES_NO_OPTION,
      JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.YES_OPTION);
  switch (response) {
    default:
      // This should never happen
      throw new IllegalArgumentException("not an option");
    case JOptionPane.CLOSED_OPTION:
      closeApplication();
      break;
    case JOptionPane.NO_OPTION:
      resetAIMerger(null);
      break;
    case JOptionPane.YES_OPTION:
      resetAIMerger(mergeProjectPath);
      break;
  }
}
 
Example 8
Project: appinventor-extensions   File: AIMerger.java   View Source Code Vote up 6 votes
private void offerNewMerge() {
  int response = JOptionPane.showOptionDialog(myCP, "Projects Successfully Merged. "
      + "Would you like to merge more projects?", "Projects Merged", JOptionPane.YES_NO_OPTION,
      JOptionPane.INFORMATION_MESSAGE, null, null, JOptionPane.YES_OPTION);
  switch (response) {
    default:
      // This should never happen
      throw new IllegalArgumentException("not an option");
    case JOptionPane.CLOSED_OPTION:
    case JOptionPane.NO_OPTION:
      closeApplication();
      break;
    case JOptionPane.YES_OPTION:
      offerToMergeToNewProject();
      break;
  }
}
 
Example 9
Project: appinventor-extensions   File: AIMerger.java   View Source Code Vote up 6 votes
private void offerToMergeToNewProject() {
  int response = JOptionPane.showOptionDialog(myCP, "Would you like one of the projects to merge"
      + "to be the project you just created?", "Merge More Projects", JOptionPane.YES_NO_OPTION,
      JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.YES_OPTION);
  switch (response) {
    default:
      // This should never happen
      throw new IllegalArgumentException("not an option");
    case JOptionPane.CLOSED_OPTION:
      closeApplication();
      break;
    case JOptionPane.NO_OPTION:
      resetAIMerger(null);
      break;
    case JOptionPane.YES_OPTION:
      resetAIMerger(mergeProjectPath);
      break;
  }
}
 
Example 10
Project: appinventor-extensions   File: AIMerger.java   View Source Code Vote up 6 votes
private void closeApplication() {
  int response = JOptionPane.showOptionDialog(myCP, "Exit AIMerger?", "Exit",
      JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null,
      JOptionPane.YES_OPTION);
  switch (response) {
    default:
      // This should never happen
      throw new IllegalArgumentException("not an option");
    case JOptionPane.CLOSED_OPTION:
    case JOptionPane.CANCEL_OPTION:
      offerNewMerge();
      break;
    case JOptionPane.OK_OPTION:
      System.exit(0);
      break;
  }
}
 
Example 11
Project: alevin-svn2   File: MyEditingPopupGraphMousePlugin.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
private void addLink(int layer, V src, V dest) {
	boolean addConstraint = true;
	E edge = edgeFactory.create();
	while (addConstraint) {
		new AddConstraintDialog((NetworkEntity<AbstractConstraint>) edge, layer, GUI.getInstance(),
				new Dimension(300, 150));
		// if a resource/demand has been added
		if (edge.get().size() > 0) {
			addConstraint = false;
			@SuppressWarnings("rawtypes")
			Network net = scenario.getNetworkStack()
					.getLayer(layer);
			if ((net instanceof SubstrateNetwork && ((SubstrateNetwork) net)
					.addEdge((SubstrateLink) edge, (SubstrateNode) src,
							(SubstrateNode) dest))
					|| (net instanceof VirtualNetwork && ((VirtualNetwork) net)
							.addEdge((VirtualLink) edge, (VirtualNode) src,
									(VirtualNode) dest))) {
				vv.updateUI();
			} else {
				throw new AssertionError("Adding link failed.");
			}
		} else {
			int option = JOptionPane.showConfirmDialog(GUI.getInstance(),
					"A " + (layer == 0 ? "Resource" : "Demand")
							+ " must be added for the link to be created!",
					"Create Node", JOptionPane.OK_CANCEL_OPTION);
			if (option == JOptionPane.CANCEL_OPTION
					|| option == JOptionPane.CLOSED_OPTION) {
				addConstraint = false;
			}
		}
	}
}
 
Example 12
Project: gate-core   File: MainFrame.java   View Source Code Vote up 5 votes
@Override
public void actionPerformed(ActionEvent e) {
  Runnable runner = new Runnable() {
    @Override
    public void run() {
      TreePath[] paths = resourcesTree.getSelectionPaths();
      if (paths == null) { return; }
      if (paths.length > 10) {
        Object[] possibleValues =
          { "Open the "+paths.length+" objects", "Don't open" };
        int selectedValue =
          JOptionPane.showOptionDialog(instance, "Do you want to open "
          +paths.length+" objects in the central tabbed pane ?",
          "Warning", JOptionPane.DEFAULT_OPTION,
          JOptionPane.QUESTION_MESSAGE, null,
          possibleValues, possibleValues[1]);
        if (selectedValue == 1
         || selectedValue == JOptionPane.CLOSED_OPTION) {
          return;
        }
      }
      for (TreePath path : paths) {
        if(path != null) {
          Object value = path.getLastPathComponent();
          value = ((DefaultMutableTreeNode)value).getUserObject();
          if(value instanceof Handle) {
            final Handle handle = (Handle)value;
            SwingUtilities.invokeLater(new Runnable() { @Override
            public void run() {
              select(handle);
            }});
          }
        }
      }
    }
  };
  Thread thread = new Thread(runner, "ShowSelectedResourcesAction");
  thread.setPriority(Thread.MIN_PRIORITY);
  thread.start();
}
 
Example 13
Project: VASSAL-src   File: GameState.java   View Source Code Vote up 4 votes
/**
 * Start/end a game.  Prompt to save if the game state has been
 * modified since last save.  Invoke {@link GameComponent#setup}
 * on all registered {@link GameComponent} objects.
 */
public void setup(boolean gameStarting) {
  if (!gameStarting && gameStarted && isModified()) {
    switch (JOptionPane.showConfirmDialog(
      GameModule.getGameModule().getFrame(),
      Resources.getString("GameState.save_game_query"), //$NON-NLS-1$
      Resources.getString("GameState.game_modified"),   //$NON-NLS-1$
      JOptionPane.YES_NO_CANCEL_OPTION)) {
    case JOptionPane.YES_OPTION:
      saveGame();
      break;
    case JOptionPane.CANCEL_OPTION:
    case JOptionPane.CLOSED_OPTION:
      return;
    }
  }

  this.gameStarting = gameStarting;
  if (!gameStarting) {
    pieces.clear();
  }

  newGame.setEnabled(!gameStarting);
  saveGame.setEnabled(gameStarting);
  saveGameAs.setEnabled(gameStarting);
  closeGame.setEnabled(gameStarting);

  if (gameStarting) {
    loadGame.putValue(Action.NAME,
      Resources.getString("GameState.load_continuation"));
    GameModule.getGameModule().getWizardSupport().showGameSetupWizard();
  }
  else {
    loadGame.putValue(Action.NAME,
      Resources.getString("GameState.load_game"));
    GameModule.getGameModule().appendToTitle(null);
  }

  gameStarted &= this.gameStarting;
  for (GameComponent gc : gameComponents) {
    gc.setup(this.gameStarting);
  }

  gameStarted |= this.gameStarting;
  lastSave = gameStarting ? saveString() : null;
}
 
Example 14
Project: OpenJSharp   File: DialogCallbackHandler.java   View Source Code Vote up 4 votes
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 15
Project: jdk8u-jdk   File: DialogCallbackHandler.java   View Source Code Vote up 4 votes
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 16
Project: WordnetLoom   File: DialogBox.java   View Source Code Vote up 2 votes
/**
 * wyświetlenie zapytanie tak, nie
 *
 * @param title - tytuł okienka
 * @param message - komunikat
 * @return wybrana odpowiedź
 */
static public int showYesNo(String title, String message) {
    int result = showConfirmDialog(message, title, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
    return result == JOptionPane.CLOSED_OPTION ? NO : result;
}
 
Example 17
Project: WordnetLoom   File: DialogBox.java   View Source Code Vote up 2 votes
/**
 * wyświetlenie zapytanie tak, nie, anuluj
 *
 * @param title - tytuł okienka
 * @param message - komunikat
 * @return wybrana odpowiedź
 */
static public int showYesNoCancel(String title, String message) {
    int result = showConfirmDialog(message, title, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
    return result == JOptionPane.CLOSED_OPTION ? CANCEL : result;
}
 
Example 18
Project: LanChatLite   File: MainGui.java   View Source Code Vote up 2 votes
/**
 * other party send "SFR - Send File Request"
 * asking me to receive the file,
 * if I click yes, then other party should give me the file
 * so, send GMF request to other party
 * and start TCP thread to receive file 
 * @param msg
 */
private void processSFR(String msg) {
    
	String l[] = msg.split("\\::");
	
	String otherHost = l[0];
	String filePath = l[1];		
	int fileSize = Integer.parseInt(l[2]);
	System.out.println("File length: " + fileSize);
	
	String otherIP = htblUsers.get(otherHost);
		
	Path p = Paths.get(filePath);
    String fileName = p.getFileName().toString();

    //System.out.println("filePath = " + filePath);
    //System.out.println("fileName = " + fileName);
      
	JDialog.setDefaultLookAndFeelDecorated(true);
    int response = JOptionPane.showConfirmDialog(null, 
    		"Do you want to receive file from " + otherHost + " ?",
    		"Receive File: " + fileName,
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    
    if (response == JOptionPane.NO_OPTION) {
      System.out.println("No button clicked");
      Utils.sendUdpMsg("GMF" + myHost + "::" + "" + "::" + "No file", otherIP, Config.UDP_PORT);
    } else if (response == JOptionPane.YES_OPTION) {
    
    System.out.println("Yes button clicked");  
    
 // parent component of the dialog
    JFrame parentFrame = new JFrame();
     
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Specify a file to save");   

    fileChooser.setSelectedFile(new File(System.getProperty("user.home") + File.separator  + fileName) ); 
    int userSelection = fileChooser.showSaveDialog(parentFrame);
     
    if (userSelection == JFileChooser.APPROVE_OPTION) {
        File fileToSave = fileChooser.getSelectedFile();
        
        
        
        String savePath = fileToSave.getAbsolutePath();
        System.out.println("Save as file: " + savePath);
        
        
        Config.TCP_PORT++;
        System.out.println("TCP Port : " +  Config.TCP_PORT );
	  	
	    new ReceiveFileThread(Config.TCP_PORT, savePath, fileSize).start();
	    Utils.sendUdpMsg("GMF" + myHost + "::" + Config.TCP_PORT + "::" + filePath, otherIP, Config.UDP_PORT);
    }
   
         
    } else if (response == JOptionPane.CLOSED_OPTION) {
      System.out.println("JOptionPane closed");
    }
}