List of usage examples for javax.swing JOptionPane showInputDialog
public static String showInputDialog(Component parentComponent, Object message, Object initialSelectionValue)
parentComponent
. From source file:org.broad.igv.track.TrackMenuUtils.java
public static int getIntValue(String parameter, int value) { while (true) { String height = JOptionPane.showInputDialog(IGV.getMainFrame(), parameter + ": ", String.valueOf(value)); if ((height == null) || height.trim().equals("")) { return Integer.MIN_VALUE; // <= the logical "null" value }//from ww w . j av a 2 s .c o m try { value = Integer.parseInt(height); return value; } catch (NumberFormatException numberFormatException) { JOptionPane.showMessageDialog(IGV.getMainFrame(), parameter + " must be an integer number."); } } }
From source file:org.interreg.docexplore.authoring.AuthoringToolFrame.java
public AuthoringToolFrame(final DocExploreDataLink link, final Startup startup) throws Exception { super("Authoring Tool"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.startup = startup; this.displayHelp = startup.showHelp; startup.screen.setText("Initializing history"); this.historyManager = new HistoryManager(50, new File(DocExploreTool.getHomeDir(), ".at-cache")); this.historyDialog = new JDialog(this, XMLResourceBundle.getBundledString("generalHistory")); historyDialog.add(new HistoryPanel(historyManager)); historyDialog.pack();//w w w . j a va 2 s .c om setJMenuBar(this.menu = new AuthoringMenu(this)); startup.screen.setText("Initializing plugins"); plugins = new Vector<MetaDataPlugin>(); List<PluginConfig> pluginConfigs = startup.filterPlugins(MetaDataPlugin.class); for (PluginConfig config : pluginConfigs) { MetaDataPlugin plugin = null; if ((plugin = (MetaDataPlugin) config.clazz.newInstance()) != null) { plugins.add(plugin); plugin.setHost(config.jarFile, config.dependencies); System.out.println( "Loaded plugin '" + plugin.getName() + "' (" + plugin.getClass().getSimpleName() + ")"); } } startup.screen.setText("Initializing filters"); //filter = new FilterPanel(link); this.importOptions = new ImportOptions(this); startup.screen.setText("Initializing styles"); this.styleManager = new StyleManager(this); startup.screen.setText("Creating explorer data link"); this.linkExplorer = new DataLinkExplorer(this, link, null); //linkExplorer.toolPanel.add(filter); //linkExplorer.setFilter(filter); startup.screen.setText("Creating explorer"); //this.fileExplorer = new FileExplorer(this); this.explorer = new JPanel(new BorderLayout()); explorer.add( new JLabel("<html><font style=\"font-size:16\">" + XMLResourceBundle.getBundledString("generalLibraryLabel") + "</font></html>"), BorderLayout.NORTH); explorer.add(linkExplorer, BorderLayout.CENTER); //explorer.addTab(XMLResourceBundle.getBundledString("generalFilesLabel"), fileExplorer); startup.screen.setText("Creating editor data link"); recovery = defaultFile.exists(); DataLink fslink = new DataLinkFS2Source(defaultFile.getAbsolutePath()).getDataLink(); fslink.setProperty("autoWrite", false); final DocExploreDataLink editorLink = new DocExploreDataLink(); final JLabel titleLabel = new JLabel(); editorLink.addListener(new DocExploreDataLink.Listener() { public void dataLinkChanged(DataLink link) { String bookName = ""; try { List<Integer> books = editorLink.getLink().getAllBookIds(); if (!books.isEmpty()) { Book book = editorLink.getBook(books.get(0)); bookName = book.getName(); MetaDataKey key = editorLink.getOrCreateKey("styles", ""); List<MetaData> mds = book.getMetaDataListForKey(key); MetaData md = null; if (mds.isEmpty()) { md = new MetaData(editorLink, key, ""); book.addMetaData(md); } else md = mds.get(0); styleManager.setMD(md); } } catch (Exception e) { e.printStackTrace(); } String linkTitle = menu.curFile == null ? null : menu.curFile.getAbsolutePath(); titleLabel.setText("<html><font style=\"font-size:14\">" + XMLResourceBundle.getBundledString("generalPresentationLabel") + " : <b>" + bookName + "</b>" + (linkTitle != null ? " (" + linkTitle + ")" : "") + "</font></html>"); setTitle(XMLResourceBundle.getBundledString("frameTitle") + " " + (linkTitle != null ? linkTitle : "")); historyManager.reset(-1); repaint(); } }); editorLink.setLink(fslink); startup.screen.setText("Creating editor"); this.editor = new DataLinkExplorer(this, editorLink, new BookImporter()); for (ExplorerView view : editor.views) if (view instanceof PageEditorView) { this.mdEditor = new MetaDataEditor(((PageEditorView) view).editor); } editor.addListener(new Explorer.Listener() { @Override public void exploringChanged(Object object) { try { boolean isRegion = object instanceof Region; int div = splitPane.getDividerLocation(); mdEditor.setDocument(null); if (isRegion) mdEditor.setDocument((Region) object); if (isRegion != regionMode) splitPane.setRightComponent(isRegion ? mdEditor : explorer); regionMode = isRegion; validate(); splitPane.setDividerLocation(div); } catch (Exception e) { ErrorHandler.defaultHandler.submit(e); } } }); final JButton editBook = new JButton(new AbstractAction("", ImageUtils.getIcon("pencil-24x24.png")) { @Override public void actionPerformed(ActionEvent e) { try { Book book = editorLink.getBook(editorLink.getLink().getAllBookIds().get(0)); String name = JOptionPane.showInputDialog(AuthoringToolFrame.this, XMLResourceBundle.getBundledString("collectionAddBookMessage"), book.getName()); if (name == null) return; book.setName(name); editorLink.notifyDataLinkChanged(); editor.refreshPath(); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } }); editBook.setToolTipText(XMLResourceBundle.getBundledString("generalToolbarEdit")); this.splitPane = new JSplitPane(); JPanel editorPanel = new JPanel(new BorderLayout()); JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); titlePanel.add(titleLabel); titlePanel.add(editBook); //editorPanel.add(titlePanel, BorderLayout.NORTH); editorPanel.add(editor, BorderLayout.CENTER); splitPane.setLeftComponent(editorPanel); splitPane.setRightComponent(explorer); getContentPane().setLayout(new BorderLayout()); add(titlePanel, BorderLayout.NORTH); add(splitPane, BorderLayout.CENTER); this.clipboard = new MetaDataClipboard(this, new File(DocExploreTool.getHomeDir(), ".at-clipboard")); startup.screen.setText("Initializing exporter"); this.readerExporter = new ReaderExporter(this); this.webExporter = new WebExporter(this); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { quit(); } public void windowOpened(WindowEvent e) { splitPane.setDividerLocation(getWidth() / 2); } }); this.oldSize = getWidth(); addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { splitPane.setDividerLocation(splitPane.getDividerLocation() * getWidth() / oldSize); oldSize = getWidth(); } }); }
From source file:org.interreg.docexplore.PresentationImporter.java
void doImport(Component comp, String title, String desc, File bookFile) throws Exception { progress = 0;//ww w. j av a 2 s. co m File indexFile = new File(exportDir, "index.xml"); if (!indexFile.exists()) { ErrorHandler.defaultHandler.submit(new Exception("Invalid server resource directory")); } try { int bookNum = 0; for (String filename : exportDir.list()) if (filename.startsWith("book") && filename.endsWith(".xml")) { String numString = filename.substring(4, filename.length() - 4); try { int num = Integer.parseInt(numString); if (num >= bookNum) bookNum = num + 1; } catch (Exception e) { } } String bookFileName = "book" + bookNum + ".xml"; String xml = StringUtils.readFile(indexFile, "UTF-8"); //look for duplicate int curIndex = 0; while (curIndex >= 0) { int startIndex = xml.indexOf("<Book", curIndex); if (startIndex < 0) break; int index = xml.indexOf("title=\"", startIndex); if (index < 0) break; index += "title=\"".length(); int endIndex = xml.indexOf("\"", index); String testTitle = xml.substring(index, endIndex); if (testTitle.equals(title)) { int res = JOptionPane.showConfirmDialog(comp, XMLResourceBundle.getString("authoring-lrb", "exportDuplicateMessage"), "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION); if (res == JOptionPane.CANCEL_OPTION) return; if (res == JOptionPane.YES_OPTION) { endIndex = xml.indexOf("</Book>", startIndex); xml = xml.substring(0, startIndex) + xml.substring(endIndex + "</Book>".length(), xml.length()); } else { title = JOptionPane.showInputDialog(comp, XMLResourceBundle.getString("authoring-lrb", "collectionAddBookMessage"), title); if (title != null) doImport(comp, title, desc, bookFile); return; } break; } curIndex = endIndex; } int insertIndex = xml.indexOf("</Index>"); if (insertIndex < 0) throw new Exception("Invalid index file"); xml = xml.substring(0, insertIndex) + "\t<Book title=\"" + title + "\" src=\"" + bookFileName + "\">\n\t\t" + desc + "\n\t</Book>\n" + xml.substring(insertIndex); FileOutputStream indexOutput = new FileOutputStream(indexFile); indexOutput.write(xml.getBytes(Charset.forName("UTF-8"))); indexOutput.close(); File bookDir = new File(exportDir, "book" + bookNum); String bookSpec = StringUtils.readFile(bookFile, "UTF-8"); int start = bookSpec.indexOf("path=\"") + 6; int end = bookSpec.indexOf("\"", start); bookSpec = bookSpec.substring(0, start) + bookDir.getName() + "/" + bookSpec.substring(end); FileOutputStream bookOutput = new FileOutputStream(new File(exportDir, bookFileName)); bookOutput.write(bookSpec.toString().getBytes(Charset.forName("UTF-8"))); bookOutput.close(); File contentDir = new File(bookFile.getParentFile(), bookFile.getName().substring(0, bookFile.getName().length() - 4)); FileUtils.moveDirectory(contentDir, bookDir); } catch (Exception e) { ErrorHandler.defaultHandler.submit(e); } }
From source file:org.jbpm.bpel.tutorial.atm.terminal.DepositAction.java
public void actionPerformed(ActionEvent event) { Map context = AtmTerminal.getContext(); AtmPanel atmPanel = (AtmPanel) context.get(AtmTerminal.PANEL); // capture amount NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(); String amountText = JOptionPane.showInputDialog(atmPanel, "Amount", currencyFormat.format(0.0)); if (amountText == null) return;//from w w w .j ava 2 s .c o m try { // parse amount double amount = currencyFormat.parse(amountText).doubleValue(); // deposit funds to account FrontEnd atmFrontEnd = (FrontEnd) context.get(AtmTerminal.FRONT_END); String customerName = (String) context.get(AtmTerminal.CUSTOMER); double balance = atmFrontEnd.deposit(customerName, amount); // update atm panel atmPanel.setMessage("Your balance is " + currencyFormat.format(balance)); } catch (ParseException e) { log.debug("invalid amount", e); atmPanel.setMessage("Please enter a valid amount."); } catch (RemoteException e) { log.error("remote operation failure", e); atmPanel.setMessage("Communication with the bank failed.\n" + "Please log on again."); atmPanel.clearActions(); atmPanel.addAction(new LogOnAction()); atmPanel.setStatus("connected"); } }
From source file:org.jbpm.bpel.tutorial.atm.terminal.WithdrawAction.java
public void actionPerformed(ActionEvent event) { Map context = AtmTerminal.getContext(); AtmPanel atmPanel = (AtmPanel) context.get(AtmTerminal.PANEL); // capture amount NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(); String amountText = JOptionPane.showInputDialog(atmPanel, "Amount", currencyFormat.format(0.0)); if (amountText == null) return;/* www . j ava2s . c o m*/ try { // parse amount double amount = currencyFormat.parse(amountText).doubleValue(); // withdraw funds from account FrontEnd atmFrontEnd = (FrontEnd) context.get(AtmTerminal.FRONT_END); String customerName = (String) context.get(AtmTerminal.CUSTOMER); double balance = atmFrontEnd.withdraw(customerName, amount); // update atm panel atmPanel.setMessage("Your new balance is " + currencyFormat.format(balance)); } catch (ParseException e) { log.debug("invalid amount", e); atmPanel.setMessage("Please enter a valid amount."); } catch (InsufficientFunds e) { log.debug("insufficient funds", e); atmPanel.setMessage("I could not fulfill your request.\n" + "Your current balance is only " + currencyFormat.format(e.getAmount())); } catch (RemoteException e) { log.error("remote operation failure", e); atmPanel.setMessage("Communication with the bank failed.\n" + "Please log on again."); atmPanel.clearActions(); atmPanel.addAction(new LogOnAction()); atmPanel.setStatus("connected"); } }
From source file:org.jtrfp.trcl.gui.ConfigWindow.java
private void editVOXPath() { final String result = JOptionPane.showInputDialog(this, "Edit VOX Path", missionLM.get(missionList.getSelectedIndex())); if (checkVOX(new File(result))) missionLM.set(missionList.getSelectedIndex(), result); }
From source file:org.jtrfp.trcl.gui.ConfigWindow.java
private void editPODPath() { final String result = JOptionPane.showInputDialog(this, "Edit POD Path", podLM.get(missionList.getSelectedIndex())); if (checkPOD(new File(result))) podLM.set(podList.getSelectedIndex(), result); }
From source file:org.nuclos.client.relation.EntityRelationshipModelEditPanel.java
private void editSubformRelation(final mxCell cell) { if (cell.getValue() != null && (cell.getValue() instanceof String || cell.getValue() instanceof EntityFieldMetaDataVO)) { mxCell target = (mxCell) cell.getTarget(); mxCell source = (mxCell) cell.getSource(); EntityMetaDataVO voSource = (EntityMetaDataVO) source.getValue(); EntityMetaDataVO voTarget = (EntityMetaDataVO) target.getValue(); String sFieldName = null; boolean blnNotSet = true; final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate(); while (blnNotSet) { if (cell.getValue() instanceof EntityFieldMetaDataVO) { String sDefault = ((EntityFieldMetaDataVO) cell.getValue()).getField(); sFieldName = JOptionPane.showInputDialog(EntityRelationshipModelEditPanel.this, localeDelegate.getMessage("nuclos.entityrelation.editor.17", "Bitte geben Sie den Namen des Feldes an!"), sDefault);/*w ww. jav a 2 s . c o m*/ } else sFieldName = JOptionPane.showInputDialog(EntityRelationshipModelEditPanel.this, localeDelegate.getMessage("nuclos.entityrelation.editor.17", "Bitte geben Sie den Namen des Feldes an!")); if (sFieldName == null || sFieldName.length() < 1) { if (cell.getValue() instanceof String) getGraphModel().remove(cell); return; } else if (sFieldName != null) { blnNotSet = false; } for (EntityFieldMetaDataVO voField : MetaDataDelegate.getInstance() .getAllEntityFieldsByEntity(voSource.getEntity()).values()) { if (voField.getField().equals(sFieldName)) { JOptionPane.showMessageDialog(EntityRelationshipModelEditPanel.this, localeDelegate .getMessage("nuclos.entityrelation.editor.18", "Der Feldname ist schon vorhanden")); blnNotSet = true; break; } } } EntityFieldMetaDataVO vo = null; if (cell.getValue() instanceof EntityFieldMetaDataVO) { vo = (EntityFieldMetaDataVO) cell.getValue(); vo.flagUpdate(); } else { vo = new EntityFieldMetaDataVO(); vo.setModifiable(true); vo.setLogBookTracking(false); vo.setReadonly(false); vo.setShowMnemonic(true); vo.setInsertable(true); vo.setSearchable(true); vo.setNullable(false); vo.setUnique(true); vo.setDataType("java.lang.String"); } List<TranslationVO> lstTranslation = new ArrayList<TranslationVO>(); for (LocaleInfo voLocale : LocaleDelegate.getInstance().getAllLocales(false)) { String sLocaleLabel = voLocale.language; Integer iLocaleID = voLocale.localeId; String sCountry = voLocale.title; Map<String, String> map = new HashMap<String, String>(); TranslationVO translation = new TranslationVO(iLocaleID, sCountry, sLocaleLabel, map); for (String sLabel : labels) { translation.getLabels().put(sLabel, sFieldName); } lstTranslation.add(translation); } vo.setForeignEntity(voTarget.getEntity()); vo.setField(sFieldName); if (cell.getValue() instanceof String) { vo.setDbColumn("INTID_" + sFieldName); } cell.setValue(vo); List<EntityFieldMetaDataTO> toList = new ArrayList<EntityFieldMetaDataTO>(); EntityFieldMetaDataTO toField = new EntityFieldMetaDataTO(); toField.setEntityFieldMeta(vo); toField.setTranslation(lstTranslation); toList.add(toField); MetaDataDelegate.getInstance().modifyEntityMetaData(voSource, toList); EntityRelationshipModelEditPanel.this.loadReferenz(); } }
From source file:org.orbisgis.sif.components.fstree.TreeNodeFolder.java
/** * Create a sub folder, the folder name is given through an input dialog *//*from ww w . j av a 2 s. c om*/ public void onNewSubFolder() { String folderName = JOptionPane.showInputDialog(UIFactory.getMainFrame(), I18N.tr("Enter the folder name"), I18N.tr("Folder")); if (folderName != null) { File newFolderPath = getUniqueFileName(new File(getFilePath(), folderName)); try { if (!newFolderPath.mkdir()) { LOGGER.error(I18N.tr("The folder creation has failed")); } else { updateTree(); } } catch (Throwable ex) { LOGGER.error(I18N.tr("The folder creation has failed"), ex); } } }
From source file:org.orbisgis.sif.components.fstree.TreeNodeFolder.java
/** * Create a file from a Reader instance in this folder * @param tf Transferable instance//from w w w . j a v a 2s . c om * @param flavor DataFlavor * @return If the file has been created */ private boolean importReader(Transferable tf, DataFlavor flavor) { try { // From this transferable, a file can be created Object transferData = tf.getTransferData(flavor); if (!(transferData instanceof Reader)) { return false; } BufferedReader br = new BufferedReader((Reader) transferData); File fileName; if (transferData instanceof TransferableFileContent) { // The filename is given by the drag source fileName = new File(getFilePath(), ((TransferableFileContent) transferData).getFileNameHint()); } else { // The filename must be given by the user String contentFileName = JOptionPane.showInputDialog(UIFactory.getMainFrame(), I18N.tr("Enter the folder name"), I18N.tr("Folder")); if (contentFileName != null) { fileName = new File(getFilePath(), contentFileName); } else { return false; } } // If the file exists found a new one fileName = getUniqueFileName(fileName); FileWriter writer = new FileWriter(fileName); String res = br.readLine(); while (res != null) { writer.write(res + "\n"); res = br.readLine(); } writer.close(); return true; } catch (UnsupportedFlavorException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); return false; } catch (IOException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); return false; } }