Java Code Examples for javax.swing.JOptionPane.showInternalConfirmDialog()

The following are Jave code examples for showing how to use showInternalConfirmDialog() 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: AgentWorkbench   File: ChartEditorJPanel.java   View Source Code Vote up 6 votes
private void writeImageFile(BufferedImage image, String path, String extension){
	// --- Overwrite existing file ? ------------------
	File writeFile = new File(path);
	if (writeFile.exists()) {
		String msgHead = "Overwrite?";
		String msgText = "Overwrite existing file?";
		int msgAnswer = JOptionPane.showInternalConfirmDialog(this, msgText, msgHead, JOptionPane.YES_NO_OPTION);
		if (msgAnswer == JOptionPane.NO_OPTION) {
			return;
		}
	}
	
	try {
		ImageIO.write(image, extension, writeFile);

	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 2
Project: AgentWorkbench   File: BasicGraphGui.java   View Source Code Vote up 5 votes
/**
 * Export the current graph as image by using specified parameters. 
 *
 * @param vv the VisualizationViewer
 * @param file the current file to export to
 */
private void exportAsImage(BasicGraphGuiVisViewer<GraphNode, GraphEdge> vv, String path2File, String extension) {

	// --- If the VisualizationViewer is null ---------
	if (vv == null) {
		return;
	}
	// --- Overwrite existing file ? ------------------
	File writeFile = new File(path2File);
	if (writeFile.exists()) {
		String msgHead = "Overwrite?";
		String msgText = "Overwrite existing file?";
		int msgAnswer = JOptionPane.showInternalConfirmDialog(this, msgText, msgHead, JOptionPane.YES_NO_OPTION);
		if (msgAnswer == JOptionPane.NO_OPTION) {
			return;
		}
	}

	// --- Lets go ! ----------------------------------
	int width = vv.getSize().width;
	int height = vv.getSize().height;

	BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
	Graphics2D graphics = bi.createGraphics();
	graphics.fillRect(0, 0, width, height);

	boolean wasDoubleBuffered=vv.isDoubleBuffered();
	vv.setDoubleBuffered(false);
	vv.paint(graphics);
	vv.paintComponents(graphics);
	vv.setDoubleBuffered(wasDoubleBuffered);

	try {
		ImageIO.write(bi, extension, writeFile);

	} catch (Exception e) {
		e.printStackTrace();
	}

}
 
Example 3
Project: AgentWorkbench   File: Application.java   View Source Code Vote up 5 votes
/**
 * Enables to change the user language of the application  
 * If 'askUser' is set to false the changes will be done without user interaction. 
 * 
 * @param newLang => 'de', 'en', 'it', 'es' or 'fr' etc. is equal to the header line of the dictionary
 * @param askUser 
 */
public static void setLanguage(String newLang, boolean askUser) {

	String newLine = getGlobalInfo().getNewLineSeparator();
	
	if (askUser==true) {
		// --- Do we have identical Languages -------------------
		Integer newLangIndex = Language.getIndexOfLanguage(newLang);
		if ( newLangIndex == Language.currLanguageIndex ) return; 
		
		// --- Ask user -----------------------------------------
		String MsgHead = Language.translate("Anzeigesprache wechseln?");
		String MsgText = Language.translate(
						 "Möchten Sie die Anzeigesprache wirklich umstellen?" + newLine + 
						 "Die Anwendung muss hierzu neu gestartet und Projekte" + newLine +
						 "von Ihnen neu geöffnet werden.");
		Integer MsgAnswer = JOptionPane.showInternalConfirmDialog( Application.getMainWindow().getContentPane(), MsgText, MsgHead, JOptionPane.YES_NO_OPTION);
		if (MsgAnswer==1) return;
		
	}
	
	// --- Stop Agent.GUI ---------------------------------------
	if (stopAgentGUI()==false) return;
	// --- Switch Language --------------------------------------
	System.out.println("=> " + Language.translate("Sprachumstellung zu") + " '" + newLang + "'.");
	Language.changeApplicationLanguageTo(newLang);
	// --- Restart application ----------------------------------
	startAgentGUI();
}
 
Example 4
Project: AgentWorkbench   File: Platform.java   View Source Code Vote up 5 votes
/**
 * Asks the user to shutdown Jade.
 * @return true, if the user answered 'yes'
 */
public boolean stopAskUserBefore() {
	
	if (this.isMainContainerRunning()==true && Application.getMainWindow()!=null) {
		String title = Language.translate("JADE wird zur Zeit ausgeführt!");
		String message = Language.translate("Möchten Sie JADE nun beenden?");
		Integer answer =  JOptionPane.showInternalConfirmDialog( Application.getMainWindow().getContentPane(), message, title, JOptionPane.YES_NO_OPTION);
		if (answer==1) return false; // --- NO,just exit 
		// --- Stop the JADE-Platform -------------------
		this.stop();
	}
	return true;
}
 
Example 5
Project: AgentWorkbench   File: BasicGraphGuiProperties.java   View Source Code Vote up 4 votes
/**
 * Does the close action.
 */
private void doClose() {
	
	if (this.hasChanged()==true) {
		// --- Data model has changed ! ---------------------------
		String diaTitle = Language.translate("Close Properties", Language.EN);
		String diaQuestion = null;
		if (this.graphController.getProject()!=null) {
			// --- Setup case -------------
			diaQuestion = Language.translate("Save changes to network model?", Language.EN);
		} else {
			// --- Execution case ---------
			diaQuestion = Language.translate("Save and send data model changes to agent(s)?", Language.EN);
		}

		// --- User request ---------------------------------------
		int diaAnswer = JOptionPane.showInternalConfirmDialog(this, diaQuestion, diaTitle, JOptionPane.YES_NO_CANCEL_OPTION);
		if (diaAnswer==JOptionPane.YES_OPTION) {
			if (this.graphController.getProject()!=null) {
				// --- Setup case -------------
				this.save();	
			} else {
				// --- Execution case ---------
				this.save(true);
			}
			this.setVisible(false);
			this.dispose();
			
		} else if (diaAnswer==JOptionPane.NO_OPTION){
			this.setVisible(false);
			this.dispose();
			
		} else if (diaAnswer==JOptionPane.CANCEL_OPTION){
			// --- Do nothing ---- 
		}
		
	} else {
		// --- Data model has NOT changed ! ---
		this.setVisible(false);
		this.dispose();
	}
}
 
Example 6
Project: AgentWorkbench   File: Platform.java   View Source Code Vote up 4 votes
/**
 * Starts an agent as specified
 *
 * @param agentName the agent name
 * @param agentClass the class of the agent
 * @param startArguments the start arguments for the agent
 * @param inContainer the container name
 */
public void startAgent(String agentName, Class<? extends Agent> agentClass, Object[] startArguments, String inContainer) {
	
	// --- Was the system already started? ----------------------
	if (this.isMainContainerRunning()==false) {
		String msgHead = Language.translate("JADE wurde noch nicht gestartet!");
		String msgText = Language.translate("Möchten Sie JADE nun starten und fortfahren?");
		int msgAnswer = JOptionPane.showInternalConfirmDialog( Application.getMainWindow().getContentPane(), msgText, msgHead, JOptionPane.YES_NO_OPTION);
		if (msgAnswer==JOptionPane.NO_OPTION) return; // --- NO,just exit 
		
		// --- Start the JADE-Platform -------------------------------
		if (this.start() == false) {
			// --- Abort if JADE was not successfully started --------
			return;
		}
	}
	
	// --- Get the AgentContainer -------------------------------
	AgentContainer agentContainer = this.getContainer(inContainer);
	if (agentContainer==null) {
		// --- Do we have a remote container of that name? ------
		if (this.startRemoteAgent(agentName, agentClass, startArguments, inContainer)==true) return;
		// --- Start a new local container ----------------------
		agentContainer = this.createAgentContainer(inContainer);
	}
	
	// --- Check if the agent name is already used --------------
	Integer newAgentNoTmp = 0;
	String newAgentNameTmp = agentName;
	try {
		agentContainer.getAgent(newAgentNameTmp, AID.ISLOCALNAME);
		while (true) {
			newAgentNoTmp++;
			newAgentNameTmp = agentName + "-" + newAgentNoTmp;
			agentContainer.getAgent(newAgentNameTmp, AID.ISLOCALNAME);
		}
		
	} catch (ControllerException ce) {
		//ce.printStackTrace();
		if (newAgentNoTmp>0) {
			agentName = agentName + "-" + newAgentNoTmp;
		}
	}
	
	// --- Start the actual agent -------------------------------
	try {
		Agent agent = (Agent) ClassLoadServiceUtility.newInstance(agentClass.getName());
		agent.setArguments(startArguments);
		AgentController agentController = agentContainer.acceptNewAgent(agentName, agent);
		agentController.start();
		
	} catch (Exception ex) {
		ex.printStackTrace();
	}		
}