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:us.ihmc.codecs.loader.OpenH264Downloader.java
/** * Shows an about dialog for the license with disable button, as per license terms */// w w w.j ava 2 s .c om public static void showAboutCiscoDialog() { JPanel panel = new JPanel(); panel.add(new JLabel("OpenH264 Video Codec provided by Cisco Systems, Inc.")); panel.add(new JLabel("License terms")); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); JTextArea license = new JTextArea(getLicenseText()); license.setEditable(false); license.setLineWrap(true); license.setWrapStyleWord(true); JScrollPane scroll = new JScrollPane(license); scroll.setPreferredSize(new Dimension(500, 500)); panel.add(scroll); String[] options = new String[2]; boolean enabled = isEnabled(); if (enabled) { options[0] = "Disable Cisco OpenH264 plugin"; } else { options[0] = "Enable Cisco OpenH264 plugin"; } options[1] = "Close"; int res = JOptionPane.showOptionDialog(null, panel, "OpenH264 Video Codec provided by Cisco Systems, Inc.", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null); if (res == 0) { if (enabled) { deleteOpenH264Library(); } else { loadOpenH264(false); } } }
From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java
private JMenu createShortMenu() { JMenu shortMenu = new JMenu(); addDarkModeCallback(b -> {/*from ww w . j a v a2 s . c om*/ shortMenu.setBackground(b ? OPENBST_BLUE.darker().darker() : OPENBST_BLUE.brighter()); shortMenu.setForeground(b ? Color.WHITE : OPENBST_BLUE); }); shortMenu.setBackground(OPENBST_BLUE.brighter()); shortMenu.setForeground(OPENBST_BLUE); shortMenu.setText(Lang.get("banner.title")); shortMenu.setIcon(new ImageIcon(Icons.getImage("Logo", 16))); JMenuItem label = new JMenuItem(Lang.get("menu.title")); label.setEnabled(false); shortMenu.add(label); shortMenu.addSeparator(); shortMenu.add( new JMenuItem(new AbstractAction(Lang.get("menu.open"), new ImageIcon(Icons.getImage("Open", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { openStory(VisualsUtils.askForFile(OpenBSTGUI.this, Lang.get("file.title"))); } })); shortMenu.addSeparator(); shortMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.create"), new ImageIcon(Icons.getImage("Add Property", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { doNewEditor(); } })); JMenu additionalMenu = new JMenu(Lang.get("menu.advanced")); shortMenu.add(additionalMenu); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.package"), new ImageIcon(Icons.getImage("Open Archive", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { new PackageDialog(instance).setVisible(true); } })); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("langcheck"), new ImageIcon(Icons.getImage("LangCheck", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { final Map<String, String> languages = new Gson() .fromJson(new InputStreamReader( OpenBST.class.getResourceAsStream( "/utybo/branchingstorytree/swing/lang/langs.json"), StandardCharsets.UTF_8), new TypeToken<Map<String, String>>() { }.getType()); languages.remove("en"); languages.remove("default"); JComboBox<String> jcb = new JComboBox<>(new Vector<>(languages.keySet())); JPanel panel = new JPanel(); panel.add(new JLabel(Lang.get("langcheck.choose"))); panel.add(jcb); int result = JOptionPane.showOptionDialog(OpenBSTGUI.this, panel, Lang.get("langcheck"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) { Locale selected = new Locale((String) jcb.getSelectedItem()); if (!Lang.getMap().keySet().contains(selected)) { try { Lang.loadTranslationsFromFile(selected, OpenBST.class .getResourceAsStream("/utybo/branchingstorytree/swing/lang/" + languages.get(jcb.getSelectedItem().toString()))); } catch (UnrespectedModelException | IOException e1) { LOG.warn("Failed to load translation file", e1); } } ArrayList<String> list = new ArrayList<>(); Lang.getLocaleMap(Locale.ENGLISH).forEach((k, v) -> { if (!Lang.getLocaleMap(selected).containsKey(k)) { list.add(k + "\n"); } }); StringBuilder sb = new StringBuilder(); Collections.sort(list); list.forEach(s -> sb.append(s)); JDialog dialog = new JDialog(OpenBSTGUI.this, Lang.get("langcheck")); dialog.getContentPane().setLayout(new MigLayout()); dialog.getContentPane().add(new JLabel(Lang.get("langcheck.result")), "pushx, growx, wrap"); JTextArea area = new JTextArea(); area.setLineWrap(true); area.setWrapStyleWord(true); area.setText(sb.toString()); area.setEditable(false); area.setBorder(BorderFactory.createLoweredBevelBorder()); JScrollPane jsp = new JScrollPane(area); jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); dialog.getContentPane().add(jsp, "pushx, pushy, growx, growy"); dialog.setSize((int) (Icons.getScale() * 300), (int) (Icons.getScale() * 300)); dialog.setLocationRelativeTo(OpenBSTGUI.this); dialog.setModalityType(ModalityType.APPLICATION_MODAL); dialog.setVisible(true); } } })); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.debug"), new ImageIcon(Icons.getImage("Code", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { DebugInfo.launch(OpenBSTGUI.this); } })); JMenu includedFiles = new JMenu("Included BST files"); for (Entry<String, String> entry : OpenBST.getInternalFiles().entrySet()) { JMenuItem jmi = new JMenuItem(entry.getKey()); jmi.addActionListener(ev -> { String path = "/bst/" + entry.getValue(); InputStream is = OpenBSTGUI.class.getResourceAsStream(path); ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(OpenBSTGUI.this, "Extracting...", is); new Thread(() -> { try { File f = File.createTempFile("openbstinternal", ".bsp"); FileOutputStream fos = new FileOutputStream(f); IOUtils.copy(pmis, fos); openStory(f); } catch (final IOException e) { LOG.error("IOException caught", e); showException(Lang.get("file.error").replace("$e", e.getClass().getSimpleName()) .replace("$m", e.getMessage()), e); } }).start(); }); includedFiles.add(jmi); } additionalMenu.add(includedFiles); shortMenu.addSeparator(); JMenu themesMenu = new JMenu(Lang.get("menu.themes")); shortMenu.add(themesMenu); themesMenu.setIcon(new ImageIcon(Icons.getImage("Color Wheel", 16))); ButtonGroup themesGroup = new ButtonGroup(); JRadioButtonMenuItem jrbmi; jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.dark")); if (0 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(0, DARK_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.light")); if (1 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(1, LIGHT_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.debug")); if (2 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(2, DEBUG_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); JMenu additionalLightThemesMenu = new JMenu(Lang.get("menu.themes.morelight")); int j = 3; for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_LIGHT_THEMES.entrySet()) { int jf = j; jrbmi = new JRadioButtonMenuItem(entry.getKey()); if (j == selectedTheme) jrbmi.setSelected(true); jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue())); additionalLightThemesMenu.add(jrbmi); themesGroup.add(jrbmi); j++; } themesMenu.add(additionalLightThemesMenu); JMenu additionalDarkThemesMenu = new JMenu(Lang.get("menu.themes.moredark")); for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_DARK_THEMES.entrySet()) { int jf = j; jrbmi = new JRadioButtonMenuItem(entry.getKey()); if (j == selectedTheme) jrbmi.setSelected(true); jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue())); additionalDarkThemesMenu.add(jrbmi); themesGroup.add(jrbmi); j++; } themesMenu.add(additionalDarkThemesMenu); shortMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.about"), new ImageIcon(Icons.getImage("About", 16))) { /** * */ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { new AboutDialog(instance).setVisible(true); } })); return shortMenu; }
From source file:view.CertificateManagementDialog.java
private void btnRemoveCertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveCertActionPerformed int[] indices = jList1.getSelectedIndices(); if (indices.length != 0) { String msg = (indices.length == 1 ? Bundle.getBundle().getString("removeCert1") : Bundle.getBundle().getString("removeCert2") + " " + indices.length + " " + Bundle.getBundle().getString("removeCert3")); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.NO_OPTION) { return; }//from w w w. j a v a2 s .co m final ArrayList<Certificate> toRemove = new ArrayList<>(); for (int index : indices) { toRemove.add(alTrusted.get(index)); } String password = getUserInputPassword(); if (password == null) { return; } for (Certificate cert : toRemove) { removeCertFromKeystore(cert, password); alTrusted.remove(cert); } } }
From source file:view.CertificateManagementDialog.java
private String getUserInputPassword() { JPanel panel = new JPanel(); JLabel lblInsertPassword = new JLabel(Bundle.getBundle().getString("insertKeystorePassword")); JPasswordField pf = new JPasswordField(10); panel.add(lblInsertPassword);/*from w w w .j av a2s . co m*/ panel.add(pf); String[] options = new String[] { Bundle.getBundle().getString("btn.ok"), Bundle.getBundle().getString("btn.cancel") }; int option = JOptionPane.showOptionDialog(null, panel, null, JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if (option == JOptionPane.OK_OPTION) { char[] password = pf.getPassword(); return new String(password); } return null; }
From source file:View.Main.java
private void setup() { jButton_loadImage.setEnabled(true);/* w w w . jav a2 s . c o m*/ jButton_next.setEnabled(false); jButton_prev.setEnabled(false); jLabel_txtDoctorName.setVisible(false); jLabel_txtHospitalContact.setVisible(false); jLabel_txtHospitalName.setVisible(false); jButton_loadImage.setEnabled(false); File file = new File(Data.filePath_downloadNnet); if (!file.exists()) { Object[] options = { "Yes", "No" }; int choice = JOptionPane.showOptionDialog(null, Data.message_modelNotFoundatLocal, "Error", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); if (choice == 0) { try { System.out.println(Data.modelUpdating); downloader.download_nnet(); jButton_loadImage.setEnabled(true); jLabel_modelVersion.setText(downloader.getModelVersion()); System.out.println(Data.modelUpdated); } catch (JSONException ex) { System.out.println(Data.error_modelDownloadFailed); JOptionPane.showMessageDialog(null, Data.error_modelDownloadFailed, "Error", JOptionPane.ERROR_MESSAGE); //Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { System.out.println(Data.error_modelDownloadFailed); JOptionPane.showMessageDialog(null, Data.error_modelDownloadFailed, "Error", JOptionPane.ERROR_MESSAGE); //Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } } else { jButton_loadImage.setEnabled(true); } imageAnalizer = new ImageAnalyzer(Data.filePath_downloadNnet); try { downloader.createDirectories(); } catch (IOException ex) { System.out.println(Data.error_createDirectories); // Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:view.MainWindow.java
public void closeDocument(boolean showCloseDialog) { if (!workspacePanel.getStatus().equals(WorkspacePanel.Status.READY)) { return;/*from www . j av a 2 s. co m*/ } if (!files.isEmpty()) { int opt = -1; if (showCloseDialog) { String msg; if (jtOpenedDocuments.getSelectionRows().length == 1) { msg = Bundle.getBundle().getString("msg.closeSelectedDocument"); } else { msg = Bundle.getBundle().getString("msg.closeSelectedDocuments"); } Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); } boolean closedOpenedDocument = false; if (!showCloseDialog || opt == JOptionPane.YES_OPTION) { // Apagar da lista de documentos abertos for (int i = jtOpenedDocuments.getSelectionRows().length - 1; i >= 0; i--) { int index = jtOpenedDocuments.getSelectionRows()[i]; String path = jtOpenedDocuments.getPathForRow(index).getPathComponent(1).toString(); files.remove(new File(path)); if (null != openedFile) { if (openedFile.equals(new File(path))) { closedOpenedDocument = true; clearOpenedDocument(); setTitle(null); } } } dmtn.removeAllChildren(); for (File file : files) { dmtn.insert(new DefaultMutableTreeNode(file), 0); } int numOpened = dmtn.getChildCount(); if (1 == numOpened) { lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + " :"); dmtn.setUserObject(null); } else { lblOpenedDocuments .setText(numOpened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); if (closedOpenedDocument && !files.isEmpty()) { File first = files.get(files.size() - 1); jtOpenedDocuments.setSelectionRow(0); ctrl.openDocument(first.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = first; } } } }
From source file:view.MainWindow.java
public void closeDocuments(ArrayList<File> listaD, boolean showCloseDialog) { if (workspacePanel.getStatus().equals(WorkspacePanel.Status.SIGNING)) { if (listaD.contains(openedFile)) { String msg = Bundle.getBundle().getString("msg.cancelSignatureAndClose1") + " " + (listaD.size() == 1 ? Bundle.getBundle().getString("msg.cancelSignatureAndClose2") : Bundle.getBundle().getString("msg.cancelSignatureAndClose3")); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; int opt = JOptionPane.showOptionDialog(this, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt != JOptionPane.YES_OPTION) { return; }//from w w w . j a va 2 s. com } } if (!listaD.isEmpty()) { int opt = -1; if (showCloseDialog) { String msg; if (listaD.size() == 1) { msg = Bundle.getBundle().getString("msg.closeSelectedDocument"); } else { msg = Bundle.getBundle().getString("msg.closeSelectedDocuments"); } Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); } if (!showCloseDialog || opt == JOptionPane.YES_OPTION) { // Apagar da lista de documentos abertos boolean closedOpenedDocument = false; for (int r = jtOpenedDocuments.getRowCount() - 1; r >= 0; r--) { String str = ""; Object[] paths = jtOpenedDocuments.getPathForRow(r).getPath(); for (int i = 1; i < paths.length; i++) { str += paths[i]; if (i + 1 < paths.length) { str += File.separator; } } File currFile = new File(str.replaceAll("\\\\+", "\\\\")); for (File f : listaD) { if (f.getAbsolutePath().replaceAll("\\\\+", "\\\\").equals(currFile.getAbsolutePath())) { dmtn.remove(r); files.remove(currFile); if (null != openedFile) { if (openedFile.equals(currFile)) { closedOpenedDocument = true; clearOpenedDocument(); setTitle(null); } } break; } } } int numOpened = files.size(); if (1 == numOpened) { lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":"); dmtn.setUserObject(null); } else { lblOpenedDocuments .setText(numOpened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); if (closedOpenedDocument && !files.isEmpty()) { File first = files.get(files.size() - 1); jtOpenedDocuments.setSelectionRow(0); ctrl.openDocument(first.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = first; } } } }
From source file:view.MainWindow.java
public boolean loadPdf(File selectedFile, boolean showOpenDialog) { if (null == openedFile || !openedFile.equals(selectedFile)) { if (selectedFile.isFile() && selectedFile.exists()) { try { if (null == dmtn) { lblOpenedDocuments.setText("0 " + Bundle.getBundle().getString("tn.documentsLoaded")); dmtn = new DefaultMutableTreeNode(null); }// w ww .j ava 2s.c o m boolean exists = false; for (int i = 0; i < dmtn.getChildCount(); i++) { if (String.valueOf(dmtn.getChildAt(i)).equals(selectedFile.getAbsolutePath())) { exists = true; jtOpenedDocuments.setSelectionRow(i); ctrl.openDocument(selectedFile.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = selectedFile; break; } } if (!exists) { if (testPdf(selectedFile)) { dmtn.insert(new DefaultMutableTreeNode(selectedFile), 0); TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); // jtOpenedDocuments.setSelectionRow(1); int numOpened = dmtn.getChildCount(); if (1 == numOpened) { lblOpenedDocuments .setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":"); dmtn.setUserObject(null); } else { lblOpenedDocuments.setText( numOpened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } if (null == openedFile) { jtOpenedDocuments.setSelectionRow(0); jtOpenedDocuments.scrollRowToVisible(0); ctrl.openDocument(selectedFile.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); files.add(new File(selectedFile.getAbsolutePath())); openedFile = selectedFile; return true; } else { jtOpenedDocuments.setSelectionRow(1); jtOpenedDocuments.scrollRowToVisible(1); if (showOpenDialog) { String msg = Bundle.getBundle().getString("msg.openNewOrKeepCurrent"); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("opt.justAdd") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { jtOpenedDocuments.setSelectionRow(0); ctrl.openDocument(selectedFile.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = selectedFile; } } files.add(new File(selectedFile.getAbsolutePath())); return true; } } else { errorList.add(selectedFile.getAbsolutePath()); showErrors(); } } } catch (Exception e) { controller.Logger.getLogger().addEntry(e); } } } return false; }
From source file:view.MainWindow.java
private void refreshOpenedDocumentsList() { int tempCount = dmtn.getChildCount(); lblOpenedDocuments.setText("0 " + Bundle.getBundle().getString("tn.documentsLoaded")); dmtn = new DefaultMutableTreeNode(null); int num = 0;/*from www.j a v a2s . c om*/ if (!files.isEmpty()) { File last = null; for (File file : files) { dmtn.insert(new DefaultMutableTreeNode(file), 0); num++; if (files.size() == num) { last = file; } } if (null == openedFile) { ctrl.openDocument(last.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = last; int opened = dmtn.getChildCount(); if (opened == 1) { lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":"); dmtn.setUserObject(null); } else { lblOpenedDocuments .setText(opened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); jtOpenedDocuments.setSelectionRow(0); jtOpenedDocuments.scrollRowToVisible(0); } else if (tempCount != dmtn.getChildCount()) { String msg = Bundle.getBundle().getString("msg.openNewOrKeepCurrent2"); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("opt.justAdd") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { ctrl.openDocument(last.getAbsolutePath()); workspacePanel.setDocument(ctrl.getDocument()); openedFile = last; int opened = dmtn.getChildCount(); if (opened == 1) { lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":"); dmtn.setUserObject(null); } else { lblOpenedDocuments .setText(opened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); jtOpenedDocuments.setSelectionRow(0); jtOpenedDocuments.scrollRowToVisible(0); } else { int opened = dmtn.getChildCount(); if (opened == 1) { lblOpenedDocuments.setText("1 " + Bundle.getBundle().getString("tn.documentLoaded") + ":"); dmtn.setUserObject(null); } else { lblOpenedDocuments .setText(opened + " " + Bundle.getBundle().getString("tn.documentsLoaded") + ":"); dmtn.setUserObject(null); } TreeModel tm = new DefaultTreeModel(dmtn); jtOpenedDocuments.setModel(tm); jtOpenedDocuments.setSelectionRow(num); jtOpenedDocuments.scrollRowToVisible(num); } } } }
From source file:view.MultipleSignDialog.java
/** * Creates new form MultipleSignStatusDialog * * @param parent/*from w ww .j a va 2 s . c o m*/ * @param modal * @param alFiles * @param settings * @param dest */ public MultipleSignDialog(java.awt.Frame parent, boolean modal, final ArrayList<File> alFiles, final CCSignatureSettings settings, final String dest) { super(parent, modal); initComponents(); updateText(); jProgressBar1.setMinimum(0); jProgressBar1.setMaximum(alFiles.size()); jProgressBar1.setString(Bundle.getBundle().getString("pb.signed") + ": 0 " + Bundle.getBundle().getString("of") + alFiles.size()); final DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); final SignatureListener sl = new SignatureListener() { @Override public void onSignatureComplete(String filename, boolean valid, String message) { dtm.addRow(new Object[] { filename, (valid ? Bundle.getBundle().getString("label.signatureOk") : Bundle.getBundle().getString("label.signatureFailed")) + (message.isEmpty() ? "" : " - " + message) }); } }; Runnable r = new Runnable() { @Override public void run() { int numSigned = 0; btnClose.setEnabled(false); for (File file : alFiles) { String destinationPath = ""; boolean validPath = false; if (dest == null) { if (file.getName().endsWith(".pdf")) { destinationPath = file.getAbsolutePath() .substring(0, file.getAbsolutePath().length() - 4).concat("(aCCinado).pdf"); if (new File(destinationPath).exists()) { int num = 1; while (!validPath) { destinationPath = file.getAbsolutePath() .substring(0, file.getAbsolutePath().length() - 4) .concat("(aCCinado" + num + ").pdf"); if (new File(destinationPath).exists()) { destinationPath = file.getAbsolutePath() .substring(0, file.getAbsolutePath().length() - 4) .concat("(aCCinado).pdf"); num++; } else { break; } } } } } else { if (file.getName().endsWith(".pdf")) { destinationPath = dest + File.separator + file.getName() .substring(0, file.getName().length() - 4).concat("(aCCinado).pdf"); if (new File(destinationPath).exists()) { int num = 1; while (!validPath) { destinationPath = dest + File.separator + file.getName().substring(0, file.getName().length() - 4) .concat("(aCCinado" + num + ").pdf"); if (new File(destinationPath).exists()) { destinationPath = dest + File.separator + file.getName() .substring(0, file.getName().length() - 4).concat("(aCCinado).pdf"); num++; } else { break; } } } } } try { // Aplicar if (CCInstance.getInstance().signPdf(file.getAbsolutePath(), destinationPath, settings, sl)) { signedDocsList.add(new File(destinationPath)); numSigned++; jProgressBar1.setValue(numSigned); jProgressBar1.setString(Bundle.getBundle().getString("pb.signed") + ": " + numSigned + " " + Bundle.getBundle().getString("of") + " " + alFiles.size()); } else { //JOptionPane.showMessageDialog(this, "Erro desconhecido: ver log", "Assinatura falhou", JOptionPane.ERROR_MESSAGE); } } catch (CertificateException | IOException | DocumentException | KeyStoreException | NoSuchAlgorithmException | InvalidAlgorithmParameterException ex) { Logger.getLogger(MultipleSignDialog.class.getName()).log(Level.SEVERE, null, ex); } catch (SignatureFailedException ex) { if (ex.getLocalizedMessage().equals(Bundle.getBundle().getString("userCanceled"))) { String msg = Bundle.getBundle().getString("msg.cancelSigning"); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { jProgressBar1.setValue(jProgressBar1.getMaximum()); jProgressBar1.setString(Bundle.getBundle().getString("pb.canceled")); break; } } } } btnClose.setEnabled(true); } }; Thread t = new Thread(r); t.start(); }