List of usage examples for javax.swing JOptionPane showOptionDialog
@SuppressWarnings("deprecation") public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException
initialValue
parameter and the number of choices is determined by the optionType
parameter. From source file:com.sec.ose.osi.ui.frm.main.identification.JComboProjectName.java
public JComboProjectName() { this.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); this.setEditable(true); this.setPreferredSize(new Dimension(400, 27)); this.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { long start = System.currentTimeMillis(); actionOnProjectSelectedonProjectComboBox(); long end = System.currentTimeMillis(); log.debug(// w w w . ja v a 2 s . c o m "[JComboProjectName.addActionListener()] Project Loding TIME : " + (end - start) / 1000.0); } }); final JTextField editor = (JTextField) this.getEditor().getEditorComponent(); editor.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { char ch = e.getKeyChar(); int count = 0; String newProjectName = editor.getText(); if (ch != KeyEvent.VK_ENTER && ch != KeyEvent.VK_BACK_SPACE && (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch))) { return; } if (newProjectName.length() <= 0 && ch == KeyEvent.VK_BACK_SPACE) { count++; if (count >= 2) { String projectName = IdentifyMediator.getInstance().getSelectedProjectName(); ((JTextField) JComboProjectName.this.getEditor().getEditorComponent()).setText(projectName); count = 0; return; } } if (JComboProjectName.this.getComponentCount() > 0) { JComboProjectName.this.removeAllItems(); } JComboProjectName.this.addItem(newProjectName); try { Collection<OSIProjectInfo> ProjectsInfo = OSIProjectInfoMgr.getInstance().getAllProjects(); String tmpProName = null; boolean bAnalysis = false; if (newProjectName.length() > 0) { for (OSIProjectInfo projectInfo : ProjectsInfo) { tmpProName = projectInfo.getProjectName(); bAnalysis = projectInfo.isAnalyzed(); if (tmpProName.toLowerCase().contains(newProjectName.toLowerCase()) && bAnalysis) JComboProjectName.this.addItem(tmpProName); } if (JComboProjectName.this.getItemCount() <= 1) { JComboProjectName.this.removeAllItems(); JOptionPane.showOptionDialog(null, "There is no project.", "Project Filter", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null, buttonOK, "OK"); } } else { for (OSIProjectInfo projectInfo : ProjectsInfo) { if (projectInfo.isManaged() == true && projectInfo.isAnalyzed()) { JComboProjectName.this.addItem(projectInfo.getProjectName()); } } JComboProjectName.this.addItem(DIVIDER_LINE); for (OSIProjectInfo projectInfo : ProjectsInfo) { if (projectInfo.isManaged() == false && projectInfo.isAnalyzed()) { JComboProjectName.this.addItem(projectInfo.getProjectName()); } } ((JTextField) JComboProjectName.this.getEditor().getEditorComponent()).setText(""); } } catch (Exception e1) { log.warn(e1.getMessage()); } JComboProjectName.this.hidePopup(); if (newProjectName.length() > 0) JComboProjectName.this.showPopup(); } }); }
From source file:br.gov.serpro.cert.AuthSSLX509TrustManager.java
/** * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],String authType) *//*from w ww . j a va 2s. c o m*/ public void checkServerTrusted(X509Certificate[] certificates, String authType) throws CertificateException { if (LOG.isInfoEnabled() && certificates != null) { for (int c = 0; c < certificates.length; c++) { X509Certificate cert = certificates[c]; LOG.info(" Server certificate " + (c + 1) + ":"); LOG.info(" Subject DN: " + cert.getSubjectDN()); LOG.info(" Signature Algorithm: " + cert.getSigAlgName()); LOG.info(" Valid from: " + cert.getNotBefore()); LOG.info(" Valid until: " + cert.getNotAfter()); LOG.info(" Issuer: " + cert.getIssuerDN()); } } // TODO: Implementar uma caixa de dilogo que pergunta para o usurio se ele quer aceitar o certificado do site // Implementado com try/catch usando JOptionPanel try { defaultTrustManager.checkServerTrusted(certificates, authType); } catch (CertificateException e) { //Object[] options = {"Aceitar Certificado", "Aceitar Permanentemente", "Cancelar"}; Object[] options = { "Aceitar Certificado", "Cancelar" }; switch (JOptionPane.showOptionDialog(null, "Falha na validao do seguinte certificado:\n" + certificates[0].getSubjectX500Principal().getName(), "\nO que voc quer fazer?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0])) { case 2: // Rejeita certificado! throw e; case 1: // Aceita certificado permanentemente // TODO: Adicionar cdigo para inserir o certificado como um certificado confivel break; // Aceita certificado para esta sesso } } }
From source file:com.codedx.burp.security.InvalidCertificateDialogStrategy.java
@Override public CertificateAcceptance checkAcceptance(Certificate genericCert, CertificateException certError) { if (genericCert instanceof X509Certificate && defaultHostVerifier instanceof DefaultHostnameVerifier) { X509Certificate cert = (X509Certificate) genericCert; DefaultHostnameVerifier verifier = (DefaultHostnameVerifier) defaultHostVerifier; JPanel message = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = 2;/*from w w w . j av a 2s . co m*/ gbc.insets = new Insets(0, 0, 10, 0); gbc.anchor = GridBagConstraints.WEST; message.add( new JLabel("Unable to establish a secure connection because the certificate is not trusted"), gbc); gbc = new GridBagConstraints(); gbc.gridy = 2; gbc.insets = new Insets(2, 0, 2, 0); gbc.anchor = GridBagConstraints.WEST; JLabel issuer = new JLabel("Issuer: "); Font defaultFont = issuer.getFont(); Font bold = new Font(defaultFont.getName(), Font.BOLD, defaultFont.getSize()); issuer.setFont(bold); message.add(issuer, gbc); gbc.gridx = 1; message.add(new JLabel(cert.getIssuerDN().toString()), gbc); try { JLabel fingerprint = new JLabel("Thumbprint: "); fingerprint.setFont(bold); gbc.gridx = 0; gbc.gridy += 1; message.add(fingerprint, gbc); gbc.gridx = 1; message.add(new JLabel(toHexString(getSHA1(cert.getEncoded()), " ")), gbc); } catch (CertificateEncodingException e) { // this shouldn't actually ever happen } try { verifier.verify(host, cert); } catch (SSLException e) { String cn = getCN(cert); JLabel mismatch = new JLabel("Host Mismatch: "); mismatch.setFont(bold); gbc.gridx = 0; gbc.gridy += 1; message.add(mismatch, gbc); String msg; if (cn != null) { msg = String.format("Expected '%s', but the certificate is for '%s'.", host, cn); } else { msg = e.getMessage(); } gbc.gridx = 1; message.add(new JLabel(msg), gbc); } // Open the dialog, and return its result int choice = JOptionPane.showOptionDialog(burpExtender.getUiComponent(), message, dialogTitle, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, dialogButtons, null); switch (choice) { case (0): return CertificateAcceptance.REJECT; case (1): return CertificateAcceptance.ACCEPT_TEMPORARILY; case (2): return CertificateAcceptance.ACCEPT_PERMANENTLY; } } return CertificateAcceptance.REJECT; }
From source file:ste.travian.gui.WorldController.java
/** * Shows the dialog to edit the map URL. */// w ww .java2 s . co m public void updateWorld() { MapUrlPanel mapUrlPanel = new MapUrlPanel(); int result = JOptionPane.showOptionDialog(mainWindow, mapUrlPanel, mainWindow.getTitle(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { "Download", "Cancel" }, null); if (result != JOptionPane.NO_OPTION) { try { load(mapUrlPanel.getUrl()); load(); } catch (Exception e) { mainWindow.error(e.getMessage(), e); } } }
From source file:me.childintime.childintime.InitialSetup.java
/** * Clean and refresh the application environment for developers. * This deletes all application files and configurations from previous versions. * This ensures that a fresh application instance is used for development. *///from w w w. j av a 2 s . c o m private void cleanApplicationEnvironment() { // Show a status message this.progressDialog.setStatus("Confirming environment cleanup..."); // Make sure the clean environment feature is enabled if (!App.APP_CLEAN_ENVIRONMENT) return; // Show a warning if (!Arrays.asList(Core.getInstance().getStarupArgs()).contains(FLAG_HIDE_CLEAN_ENVIRONMENT_WARNING)) { // Create a list with the buttons to show in the option dialog List<String> buttons = new ArrayList<>(); buttons.add("Clean Environment"); buttons.add("Keep Environment"); // Reverse the button list if we're on a Mac OS X system if (Platform.isMacOsX()) Collections.reverse(buttons); // Show the option dialog final int option = JOptionPane.showOptionDialog(this.progressDialog, "The developer option Clean Environment is enabled.\n\n" + "Would you like to clean your application environment?\n\n" + "Cleaning the environment will delete all previous application files and configurations,\n" + "to ensure that you're using a fresh application instance for development.\n\n" + "This feature must be disabled in production.", App.APP_NAME + " - Developer mode - Environment cleanup", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, buttons.toArray(), buttons.get(!Platform.isMacOsX() ? 0 : 1)); // Make sure the clean option is pressed if (option != (!Platform.isMacOsX() ? 0 : 1)) return; } // Show a status message this.progressDialog.setStatus("Refreshing application environment..."); // Delete the application directory try { if (App.getDirectory().exists()) FileUtils.deleteDirectory(App.getDirectory()); } catch (IOException e) { showError("Failed to refresh application environment."); e.printStackTrace(); } }
From source file:edu.ku.brc.specify.tasks.InteractionsProcessor.java
/** * Asks where the source of the Loan Preps should come from. * @return the source enum/*from www . j a v a2s.c om*/ */ protected ASK_TYPE askSourceOfPreps(final boolean hasInfoReqs, final boolean hasColObjRS, final T currPrepProvider) { String label; if (hasInfoReqs && hasColObjRS) { label = getResourceString("NEW_INTER_USE_RS_IR"); } else if (hasInfoReqs) { label = getResourceString("NEW_INTER_USE_IR"); } else { label = getResourceString("NEW_INTER_USE_RS"); } boolean isForAcc = isFor == forAcc; Object[] options = new Object[!isForAcc || (isForAcc && ((!hasInfoReqs && !hasColObjRS) || currPrepProvider != null)) ? 2 : 3]; Integer dosOpt = null; Integer rsOpt = null; Integer noneOpt = null; if (!isForAcc || currPrepProvider != null) { options[0] = label; options[1] = getResourceString("NEW_INTER_ENTER_CATNUM"); rsOpt = JOptionPane.YES_OPTION; dosOpt = JOptionPane.NO_OPTION; } else { if (options.length == 2) { options[0] = getResourceString("NEW_INTER_ENTER_CATNUM"); options[1] = getResourceString("NEW_INTER_EMPTY"); dosOpt = JOptionPane.YES_OPTION; noneOpt = JOptionPane.NO_OPTION; } else { options[0] = label; options[1] = getResourceString("NEW_INTER_ENTER_CATNUM"); options[2] = getResourceString("NEW_INTER_EMPTY"); rsOpt = JOptionPane.YES_OPTION; dosOpt = JOptionPane.NO_OPTION; noneOpt = JOptionPane.CANCEL_OPTION; } } int userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), getResourceString("NEW_INTER_CHOOSE_RSOPT"), getResourceString("NEW_INTER_CHOOSE_RSOPT_TITLE"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (userChoice == dosOpt) { return ASK_TYPE.EnterDataObjs; } else if (rsOpt != null && userChoice == rsOpt) { return ASK_TYPE.ChooseRS; } else if (noneOpt != null && userChoice == noneOpt) { return ASK_TYPE.None; } return ASK_TYPE.Cancel; }
From source file:com.sec.ose.osi.ui.ApplicationCloseMgr.java
public void run() { log.debug("run() start"); boolean loop = true; int queueSize = IdentifyQueue.getInstance().size(); log.info("Trying to Sending item to Protex Server - Identify Queue Size: " + queueSize); long startTime = System.currentTimeMillis(); while (loop) { // block BackgroundJobManager.getInstance().requestStopIdentifyThread(); long endTime = System.currentTimeMillis(); long timeDuration = endTime - startTime; if (timeDuration % 100 == 0) System.out.println("delayTime : " + timeDuration); if (timeDuration >= TIME_LIMIT) { log.error("TIME_LIMIT_EXCEED during completing sending items to Protex server "); loop = false;//from w ww . jav a 2 s. c om aDialogDiaplayerThread.closeDialog(); String exitMessage = "OSI fails to sync with Protex Server.\n" + "Please contact to OSI Development Team to resolve this problem."; String[] button = { "OK" }; JOptionPane.showOptionDialog( // block null, exitMessage, "Exit", JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, button, "OK"); continue; } else { boolean isAllidentifyThreadStopped = BackgroundJobManager.getInstance() .isAllIdentifyThreadReadyStatus(); if (isAllidentifyThreadStopped) { queueSize = IdentifyQueue.getInstance().size(); log.info("OSI succeeds to sync with Protex Server. - Identify Queue Size: " + queueSize + " / " + timeDuration + " ms."); loop = false; aDialogDiaplayerThread.closeDialog(); } } try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } log.debug("run() end"); }
From source file:hr.fer.zemris.vhdllab.platform.ui.command.DevFloodWithCompliationRequestsCommand.java
private void showResults(List<String> results) { logger.info(results);//from ww w . ja va 2s .c om JList list = new JList(results.toArray()); JOptionPane.showOptionDialog(null, new JScrollPane(list), "Results", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); }
From source file:com.sec.ose.osi.sdk.protexsdk.project.ProjectAPIWrapper.java
private static String createProject(String newProjectName, AnalysisSourceLocation newAnalysisSourceLocation, UIResponseObserver observer) {//from ww w . j a v a 2s . c om if (observer == null) { observer = new DefaultUIResponseObserver(); } if (isExistedProjectName(newProjectName) == true) { observer.setFailMessage("\"" + newProjectName + "\" is already existed."); log.debug("\"" + newProjectName + "\" is already existed."); return null; } String projectID = null; ProjectRequest pRequest = new ProjectRequest(); PolicyCheckResult p = ProjectNamePolicy.checkProjectName(newProjectName); if (p.getResult() != PolicyCheckResult.PROJECT_NAME_OK) { observer.setFailMessage(p.getResultMsg()); return null; } final String DESCRIPTION = "This project is created by OSI - " + DateUtil.getCurrentTime("[%1$tY/%1$tm/%1$te(%1$ta) %1$tl:%1$tM:%1$tS %1$tp]"); pRequest.setName(newProjectName); pRequest.setDescription(DESCRIPTION); if (newAnalysisSourceLocation != null) { pRequest.setAnalysisSourceLocation(newAnalysisSourceLocation); } try { projectID = ProtexSDKAPIManager.getProjectAPI().createProject(pRequest, LicenseCategory.PROPRIETARY); } catch (SdkFault e) { log.warn(e); ErrorCode errorCode = e.getFaultInfo().getErrorCode(); try { Thread.sleep(1000); } catch (InterruptedException ie) { ie.printStackTrace(); } if (errorCode == ErrorCode.DUPLICATE_PROJECT_NAME) { String[] button = { "OK" }; JOptionPane.showOptionDialog( // block null, "The project name \"" + newProjectName + "\" is already created by other user.", "Duplicated project name", JOptionPane.YES_OPTION, JOptionPane.ERROR_MESSAGE, null, button, "OK"); } return null; } if (projectID == null) return null; setScanIgnorePattern(projectID, ProjectNamePolicy.IGNORED_PATTERN, observer); observer.pushMessage("[ok]\n"); return projectID; }
From source file:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java
/** * Initialize the view components.//w ww . j a va 2s . c o m */ private void initView() { // create new view loadTracksPanel = new LoadTracksPanel(); // disable the IMPORT FILES button loadTracksPanel.getImportFilesButton().setEnabled(false); // initialize the flag to keep track of importing isImported = false; // populate the combobox with available file formats // note: these are annoatated as spring beans Set<String> parsers = TrackFileParserFactory.getInstance().getParserBeanNames(); for (String parser : parsers) { loadTracksPanel.getFileFormatComboBox().addItem(parser); } // format the table JTableHeader tracksTableHeader = loadTracksPanel.getTracksTable().getTableHeader(); tracksTableHeader.setBackground(GuiUtils.getHeaderColor()); tracksTableHeader.setFont(GuiUtils.getHeaderFont()); tracksTableHeader.setReorderingAllowed(false); /** * Action Listeners. */ // load directory loadTracksPanel.getLoadDirectoryButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (directory == null) { chooseDirectoryAndLoadData(); } else { // otherwise we ask the user if they want to reload the directory Object[] options = { "Load a different directory", "Cancel" }; int showOptionDialog = JOptionPane.showOptionDialog(null, "It seems a directory was already loaded.\nWhat do you want to do?", "", JOptionPane.CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); switch (showOptionDialog) { case 0: // load a different directory: // reset the model of the directory tree DefaultTreeModel model = (DefaultTreeModel) loadTracksPanel.getDirectoryTree().getModel(); DefaultMutableTreeNode rootNote = (DefaultMutableTreeNode) model.getRoot(); rootNote.removeAllChildren(); model.reload(); chooseDirectoryAndLoadData(); loadTracksPanel.getChosenDirectoryTextArea().setText(directory.getAbsolutePath()); break; // cancel: do nothing } } } }); // import the selected files in the tree loadTracksPanel.getImportFilesButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // check if an import already took place if (!isImported) { // get the selected file(s) from the JTree TreePath[] selectionPaths = loadTracksPanel.getDirectoryTree().getSelectionPaths(); if (selectionPaths != null && selectionPaths.length != 0) { // at least a file was selected -- proceed with the import importFiles(); isImported = true; cellCoordController.showMessage(selectionPaths.length + " file(s) successfully imported!", "success loading", JOptionPane.INFORMATION_MESSAGE); // do basic computations preprocess(); // go to child controllers and show samples in the tables summaryDataController.showSamplesInTable(); computationMainController.showSamplesInTable(); // proceed with next step in the plugin cellCoordController.getCellCoordFrame().getNextButton().setEnabled(true); } else { // inform the user that no file was selected! cellCoordController.showMessage("You have to select at least one file!", "no files selected", JOptionPane.WARNING_MESSAGE); } } else { // an import already took place: ask for user input Object[] options = { "Load other file(s)", "Cancel" }; int showOptionDialog = JOptionPane.showOptionDialog(loadTracksPanel, "It seems some files were already loaded.\nWhat do you want to do?", "", JOptionPane.CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); switch (showOptionDialog) { case 0: // load other files // clear the sample list samples.clear(); // clear the track spot list trackSpotsBindingList.clear(); // clear the selection in the JTree loadTracksPanel.getDirectoryTree().clearSelection(); isImported = false; // inform the user they need to select other files JOptionPane.showMessageDialog(loadTracksPanel, "Please select other files", "", JOptionPane.INFORMATION_MESSAGE); break; // cancel: do nothing } } } }); // add view to parent component cellCoordController.getCellCoordFrame().getLoadTracksParentPanel().add(loadTracksPanel, gridBagConstraints); }