public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Load"); int choice = 0; do { int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); try { if (file != null) { fileName = file.getCanonicalPath(); reader = new BufferedReader(new FileReader(fileName)); String line; while ((line = reader.readLine()) != null) { myPatternList.add(line); } // for(int i=0;i<myPatternList.size();i++) { // responseArea.append(myPatternList.get(i)+"\n"); // } } choice = 2; reader.close(); } catch (IOException c) { c.printStackTrace(); Object[] options = new String[] {"Load New File", "Exit"}; choice = JOptionPane.showOptionDialog( null, "Invalid FileChoosen." + "Would you like to load a new file " + "or exit?", "Options", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); if (choice == 1) System.exit(0); } } else if (result == JFileChooser.CANCEL_OPTION) { Object[] options = new String[] {"Load Different File", "Exit"}; choice = JOptionPane.showOptionDialog( null, "Would you like to load a new file " + " or exit?", "Options", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); if (choice == 1) System.exit(0); } } while (choice == 0); }
public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("SaveAs"); int choice = 0; do { int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); try { if (file != null) { fileName = file.getCanonicalPath(); printWriter = new PrintWriter(new FileOutputStream(fileName), true); } printWriter.append(responseArea.getText()); choice = 2; } catch (IOException c) { c.printStackTrace(); Object[] options = new String[] {"Choose New File", "Exit"}; choice = JOptionPane.showOptionDialog( null, "Invalid FileChoosen." + "Would you like to choose a new file " + "or exit?", "Options", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); if (choice == 1) System.exit(0); } } else if (result == JFileChooser.CANCEL_OPTION) { Object[] options = new String[] {"Choose Different File", "Exit"}; choice = JOptionPane.showOptionDialog( null, "Would you like to choose a new file " + " or exit?", "Options", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); if (choice == 1) System.exit(0); } } while (choice == 0); printWriter.flush(); printWriter.close(); }
private boolean setServiceParameter( GlobalEnvironment.PropertyType type, JLabel label, JTextField textField) { String name = String.valueOf(type).toLowerCase(); String startDirectory = StringUtil.isEmptyOrSpaces(textField.getText()) ? System.getProperty("user.home") : textField.getText(); JFileChooser fileChooser = new JFileChooser(startDirectory); fileChooser.setDialogTitle("Select Emacs " + name + " directory"); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { String dir = fileChooser.getSelectedFile().getAbsolutePath(); textField.setText(dir); if (GlobalEnvironment.testProperty(type, dir)) { infoLabel.setText("Emacs " + name + " directory successfully set"); label.setForeground(Color.black); return true; } else { onWrongProperty(label, type); return false; } } else { if (GlobalEnvironment.isEmacsPropertyOk(type)) return true; onWrongProperty(label, type); return false; } }
private void loadTopicsFromFile() throws IOException { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("ExtempFiller2"); chooser.setFileFilter( new FileFilter() { @Override public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(".txt"); } @Override public String getDescription() { return "Text Files"; } }); int response = chooser.showOpenDialog(this); if (response == JFileChooser.APPROVE_OPTION) { // get everything currently researched java.util.List<String> researched = managerPanel.getTopics(); // load everything from file File file = chooser.getSelectedFile(); Scanner readScanner = new Scanner(file); while (readScanner.hasNext()) { String topic = readScanner.nextLine(); if (!researched.contains(topic)) { Topic t = new Topic(topic); managerPanel.addTopic(t); inQueue.add(new InMessage(InMessage.Type.RESEARCH, t)); } } } }
private void setupFileChooser() { fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Select directory to output ISArchive to..."); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); fileChooser.setApproveButtonText("Output to selected directory"); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); }
// 保存图像到文件 public void saveImage() throws IOException { JFileChooser jfc = new JFileChooser(); jfc.setDialogTitle("保存"); // 文件过滤器,用户过滤可选择文件 FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG", "jpg"); jfc.setFileFilter(filter); // 初始化一个默认文件(此文件会生成到桌面上) SimpleDateFormat sdf = new SimpleDateFormat("yyyymmddHHmmss"); String fileName = sdf.format(new Date()); File filePath = FileSystemView.getFileSystemView().getHomeDirectory(); File defaultFile = new File(filePath + File.separator + fileName + ".jpg"); jfc.setSelectedFile(defaultFile); int flag = jfc.showSaveDialog(this); if (flag == JFileChooser.APPROVE_OPTION) { File file = jfc.getSelectedFile(); String path = file.getPath(); // 检查文件后缀,放置用户忘记输入后缀或者输入不正确的后缀 if (!(path.endsWith(".jpg") || path.endsWith(".JPG"))) { path += ".jpg"; } // 写入文件 ImageIO.write(saveImage, "jpg", new File(path)); System.exit(0); } }
public void saveScriptToFile( String code, String filename, Component parent, PropertyPanelController cont) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save to file"); String currentDirectory = new File(".").getAbsolutePath(); fileChooser.setSelectedFile(new File(currentDirectory, filename)); fileChooser.setName(FILE_CHOOSER); if (fileChooser.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try { if (file.createNewFile()) { OutputStream out = new FileOutputStream(file); out.write(code.getBytes()); out.close(); cont.fileSaveSuccess(file.getAbsolutePath()); } } catch (IOException e) { Log.error(e.getMessage(), e); cont.fileSaveError(file.getAbsolutePath()); } } }
public void initGame() { String cfgname = null; if (isApplet()) { cfgname = getParameter("configfile"); } else { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(System.getProperty("user.dir"))); chooser.setDialogTitle("Choose a config file"); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { cfgname = chooser.getSelectedFile().getAbsolutePath(); } else { System.exit(0); } // XXX read this as resource! // cfgname = "mygeneratedgame.appconfig"; } gamecfg = new AppConfig("Game parameters", this, cfgname); gamecfg.loadFromFile(); gamecfg.defineFields("gp_", "", "", ""); gamecfg.saveToObject(); initMotionPars(); // unpause and copy settingswhen config window is closed gamecfg.setListener( new ActionListener() { public void actionPerformed(ActionEvent e) { start(); requestGameFocus(); initMotionPars(); } }); defineMedia("simplegeneratedgame.tbl"); setFrameRate(35, 1); }
public void actionPerformed(ActionEvent e) { Object sender = e.getSource(); /* if (sender == addButton) { if (project != null) { if (dirChooser != null) { dirChooser.setDialogTitle( "add a file" ) ; dirChooser.setFileSelectionMode( JFileChooser.FILES_ONLY) ; if ( dirChooser.showOpenDialog( this ) == JFileChooser.APPROVE_OPTION ) { addFile( dirChooser.getSelectedFile() ) ; } } else System.out.println( "no chooser" ) ; } else System.out.println( "no project" ) ; } else if (sender == removeButton) { int row = table.getSelectedRow() ; if (project != null) { TProjectData data = project.getProjectData() ; TProjectFileList list = data.getAvailableLangs() ; TLanguageFile file = list.getData(row) ; list.removeLanguageVersion(file) ; if (list.getSize() < 1) { removeButton.setEnabled(false); } model.fireTableDataChanged(); } } else if (sender == rescanButton) { } else */ if (sender == this.baseButton) { // dirChooser.setProjectFileFilter( (String) typeCombo.getSelectedItem() ); dirChooser.setDialogTitle("select a base file"); dirChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (dirChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { setBaseFile(dirChooser.getSelectedFile()); rescan(); } } }
/** The listener method. */ public void actionPerformed(ActionEvent event) { Object source = event.getSource(); if (source == b1) // click button { try { String message = tf.getText(); server.sendPrivateMessage(parent, selfIdentity, message); ta.append("<" + parent.getUserName() + ">: " + message + lineSeparator); ta.setCaretPosition(ta.getText().length()); tf.setText(""); } catch (RemoteException ex) { System.out.print("Exception encountered while sending" + " private message."); } } if (source == tf) // press return { try { String message = tf.getText(); server.sendPrivateMessage(parent, selfIdentity, message); ta.append("<" + parent.getUserName() + ">: " + message + lineSeparator); ta.setCaretPosition(ta.getText().length()); tf.setText(""); } catch (RemoteException ex) { System.out.print("Exception encountered while sending" + " private message."); } } if (source == jMenuItem3) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Choose or create a new file to store the conversation"); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setDoubleBuffered(true); fileChooser.showOpenDialog(this); File file = fileChooser.getSelectedFile(); try { if (file != null) { Writer writer = new BufferedWriter(new FileWriter(file)); writer.write(ta.getText()); writer.flush(); writer.close(); } } catch (IOException ex) { System.out.println("Can't write to file. " + ex); } } if (source == jMenuItem4) { selfRemove(); this.dispose(); } }
public Path dateiAuswählen(Path neuesLaufwerk) { JFileChooser fc1 = new JFileChooser(); fc1.setDialogTitle("SyncOrdner auswählen"); fc1.setCurrentDirectory(neuesLaufwerk.toFile()); fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (fc1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) return fc1.getSelectedFile().toPath(); else return null; }
/* * Present the user with a file chooser dialog to select a file for * output. The title of the dialog box is determined by the ``caption'' * argument. */ public File getOutputFile(String caption) { JFileChooser outputdialog = new JFileChooser(); outputdialog.setDialogTitle(caption); int openReturnVal = outputdialog.showSaveDialog(null); if (openReturnVal == JFileChooser.APPROVE_OPTION) { return outputdialog.getSelectedFile(); } else { return null; } }
/* * Present the user with a file chooser dialog to select a file for input. * The title of the dialog box is determined by the ``caption'' argument. */ public File getInputFile(String caption) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(caption); int openReturnVal = chooser.showOpenDialog(null); if (openReturnVal == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile(); } else { return null; } }
private void downloadDirectoryButtonActionPerformed(ActionEvent evt) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(Groovesquid.getConfig().getDownloadDirectory())); chooser.setDialogTitle(I18n.getLocaleString("SELECT_DOWNLOAD_DIRECTORY")); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String downloadDirectory = chooser.getSelectedFile().getPath(); Groovesquid.getConfig().setDownloadDirectory(downloadDirectory); downloadDirectoryTextField.setText(downloadDirectory); } }
private String getFileName(String title, String okButton, String currentDirectory) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle(title); fileChooser.setApproveButtonText(okButton); fileChooser.setCurrentDirectory(new File(currentDirectory)); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); return selectedFile.getAbsolutePath(); } return null; }
/* * This function just finds and loads the file */ private boolean loadFile() { JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Load File"); // Choose only files, not directories fc.setFileSelectionMode(JFileChooser.FILES_ONLY); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(fJavaFilter); // Now open chooser int result = fc.showOpenDialog(this); if (result == JFileChooser.CANCEL_OPTION) { // return true; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); String textFile = fFile.toString(); if (fileNo.equalsIgnoreCase("LOAD1")) { UpLoadFile.filePath1.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD2")) { UpLoadFile.filePath2.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD3")) { VisualizationInput.originalFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD4")) { VisualizationInput.DWDVecFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD5")) { VisualizationInput.DWDOutputFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD6")) { UpLoadMAGEMLFile.filePath1.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD7")) { UpLoadMAGEMLFile.filePath2.setText(textFile); } // Get the absolute path for the file being opened filePath = fFile.getAbsolutePath(); if (filePath == null) { // fTextField.setText (filePath); return false; } } else { return false; } return true; } /*End of loadFile*/
public void actionPerformed(ActionEvent e) { if (e.getSource() == save) { JFileChooser c = new JFileChooser(ResourceFactory.getRootDir()); c.setDialogTitle("Save result"); if (c.showSaveDialog(resultFrame) == JFileChooser.APPROVE_OPTION) { File output = c.getSelectedFile(); if (output.exists()) { String[] options = {"Overwrite", "Cancel"}; if (JOptionPane.showOptionDialog( resultFrame, output + "exists. Overwrite?", "Save result", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]) == 1) return; } try { PrintWriter w = new PrintWriter(new BufferedWriter(new FileWriter(output))); w.println("Searched for unused strings"); w.println("Number of hits: " + table.getRowCount()); w.println(""); for (int i = 0; i < table.getRowCount(); i++) { w.println( "StringRef: " + table.getTableItemAt(i).getObjectAt(1) + " /* " + table .getTableItemAt(i) .toString() .replaceAll("\r\n", System.getProperty("line.separator")) + " */"); } w.close(); JOptionPane.showMessageDialog( resultFrame, "Result saved to " + output, "Save complete", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog( resultFrame, "Error while saving " + output, "Error", JOptionPane.ERROR_MESSAGE); ex.printStackTrace(); } } } }
public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle(toolTip); chooser.setDialogType(dialogType); chooser.setFileSelectionMode(fileSelectionMode); chooser.setSelectedFile(new File(textField.getText())); chooser.setFileFilter(preferredFileFilter); // if the user selects APPROVE then take the text if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { // put the text in the text field String pathString = chooser.getSelectedFile().getAbsolutePath(); textField.setText(pathString); } }
public void actionPerformed(ActionEvent e) { chooser = new JFileChooser(); chooser.setCurrentDirectory(new File("C:\\Program Files (x86)\\Tango04\\Dashboards\\Web")); chooser.setDialogTitle("Browse..."); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { textArea.setText(""); new Exportator().startExporting(chooser.getSelectedFile().getPath(), textArea); } else { textArea.setText("No Selection"); } }
private void selectFolder() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File(textFolder.getText())); fileChooser.setDialogTitle(CAPTION_SELECT_FOLDER); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setApproveButtonText("Select"); fileChooser.setApproveButtonToolTipText(TOOL_TIP_SELECT_FOLDER); if (fileChooser.showOpenDialog(FileTransferServer.this) == JFileChooser.APPROVE_OPTION) { // Get the selected file String path = fileChooser.getSelectedFile().getPath() + "\\"; textFolder.setText(path); } }
public void init() { tabbedPane.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getModifiers() == InputEvent.BUTTON3_MASK) { contextMenu.show(e.getComponent(), e.getX(), e.getY()); } } public void mouseReleased(MouseEvent e) {} }); fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save file"); fileChooser.setApproveButtonText("Save file"); fileChooser.setDialogType(JFileChooser.SAVE_DIALOG); }
@Override public void actionPerformed(ActionEvent e) { JFileChooser directoryChooser = new JFileChooser(); directoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); directoryChooser.setCurrentDirectory(new File(AbstractDownloader.directory)); directoryChooser.setDialogTitle("Choose directory"); // disable the "All files" option. directoryChooser.setAcceptAllFileFilterUsed(false); if (directoryChooser.showOpenDialog(directoryChooser) == JFileChooser.APPROVE_OPTION) { AbstractDownloader.directory = directoryChooser.getSelectedFile().getAbsolutePath() + "\\"; } else { AbstractDownloader.directory = AbstractDownloader.DEFAULT_DIRECTORY; } // показываем обновленную надпись в label view.getPathTextField().setText(AbstractDownloader.directory); }
private void jButtonWorkingDirectoryBrowseActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButtonWorkingDirectoryBrowseActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); String workDir = jTextWorkingDirectory.getText(); if (workDir.equals("")) { workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath(); } chooser.setSelectedFile(new File(workDir)); chooser.setDialogTitle( NbBundle.getMessage( CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse_Title")); // NOI18N if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { // NOI18N File file = FileUtil.normalizeFile(chooser.getSelectedFile()); jTextWorkingDirectory.setText(file.getAbsolutePath()); } } // GEN-LAST:event_jButtonWorkingDirectoryBrowseActionPerformed
private ObjectOutputStream getObjectOutputStream() { File f = new File("."); String loadDirectory = f.getAbsolutePath(); JFileChooser chooser = new JFileChooser(loadDirectory); chooser.setDialogTitle("Save Generation File As..."); chooser.setMultiSelectionEnabled(false); int result = chooser.showSaveDialog(this); File selectedFile = chooser.getSelectedFile(); if (result == JFileChooser.APPROVE_OPTION) { try { FileOutputStream fileStream = new FileOutputStream(selectedFile.getPath()); ObjectOutputStream objectStream = new ObjectOutputStream(fileStream); return objectStream; } catch (IOException e) { System.err.println(e); } } return null; }
private void createFileChooser() { fileChooser = new JFileChooser("Choose file or directory to load..."); fileChooser.setDialogTitle("Choose file or directory to load..."); fileChooser.setApproveButtonText("Select for mapping"); setStartingDirectory(); }
@Override public void actionPerformed(ActionEvent evt) { String command = evt.getActionCommand(); switch (command) { case "New File": { OSC = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); Graphics osg = OSC.getGraphics(); osg.setColor(fillColor); osg.fillRect(0, 0, getWidth(), getHeight()); osg.dispose(); repaint(); break; } case "Open": { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG or PNG Images", "jpg", "png"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { try { OSC = ImageIO.read(chooser.getSelectedFile()); Graphics2D g2 = (Graphics2D) OSC.getGraphics(); g2.scale((double) 640 / OSC.getWidth(), (double) 480 / OSC.getHeight()); g2.drawImage(OSC, 0, 0, OSC.getWidth(), OSC.getHeight(), null); } catch (Exception e) { } } repaint(); break; } case "Save": { JFileChooser fileDialog = new JFileChooser(); fileDialog.setSelectedFile(new File("image.PNG")); fileDialog.setDialogTitle("Select File to be Saved"); int option = fileDialog.showSaveDialog(null); if (option != JFileChooser.APPROVE_OPTION) return; // User canceled or clicked the dialog’s close box. File selectedFile = fileDialog.getSelectedFile(); if (selectedFile.exists()) { // Ask the user whether to replace the file. int response = JOptionPane.showConfirmDialog( null, "The file \"" + selectedFile.getName() + "\" already exists.\nDo you want to replace it?", "Confirm Save", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (response != JOptionPane.YES_OPTION) return; // User does not want to replace the file. } try { boolean hasFormat = ImageIO.write(OSC, "PNG", selectedFile); if (!hasFormat) throw new Exception("PNG" + " format is not available."); } catch (Exception e) { JOptionPane.showMessageDialog( null, "Sorry, an error occurred while trying to save image."); e.printStackTrace(); } break; } case "Exit": { System.exit(0); } case "Select Drawing Color...": { Color newColor = JColorChooser.showDialog(AdvancedGUIEX1.this, "Select Drawing Color", currentColor); if (newColor != null) currentColor = newColor; break; } case "Fill With Color...": { Color newColor = JColorChooser.showDialog(AdvancedGUIEX1.this, "Select Fill Color", fillColor); if (newColor != null) { fillColor = newColor; Graphics osg = OSC.getGraphics(); osg.setColor(fillColor); osg.fillRect(0, 0, OSC.getWidth(), OSC.getHeight()); osg.dispose(); AdvancedGUIEX1.this.repaint(); } break; } case "Draw With Black": currentColor = Color.BLACK; break; case "Draw With White": currentColor = Color.WHITE; break; case "Draw With Red": currentColor = Color.RED; break; case "Draw With Green": currentColor = Color.GREEN; break; case "Draw With Blue": currentColor = Color.BLUE; break; case "Draw With Yellow": currentColor = Color.YELLOW; break; case "Curve": currentTool = Tool.CURVE; break; case "Line": currentTool = Tool.LINE; break; case "Rectangle": currentTool = Tool.RECT; break; case "Oval": currentTool = Tool.OVAL; break; case "Filled Rectangle": currentTool = Tool.FILLED_RECT; break; case "Filled Oval": currentTool = Tool.FILLED_OVAL; break; case "Smudge": currentTool = Tool.SMUDGE; break; case "Erase": currentTool = Tool.ERASE; break; } }
private void createFileMenu() { fileMenu = new JMenu("File"); menuBar.add(fileMenu); newItem = new JMenuItem("New..."); fileMenu.add(newItem); // construct components of option pane to input name and type of new AM final Object[] newMsg = new Object[3]; newMsg[0] = "Name for new AM:"; final JTextField newName = new JTextField("new-am"); newMsg[1] = newName; final JComboBox cb = new JComboBox(); for (int i = 0; i < Libgist.extInfo.length; i++) { cb.addItem(Libgist.extInfo[i].name); } newMsg[2] = cb; newItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // first close the currently opened index int response = JOptionPane.showOptionDialog( MainWindow.this, newMsg, "New", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (response != JOptionPane.OK_OPTION) { return; } // create new AM cmd.reset(); cmd.cmdType = LibgistCommand.CREATE; cmd.indexName.append(newName.getText()); cmd.extension.append(Libgist.extInfo[cb.getSelectedIndex()]); opThread.dispatchCmd(cmd); } }); openItem = new JMenuItem("Open..."); final JFileChooser openChooser = new JFileChooser("."); openChooser.setDialogTitle("Open Index"); openChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileMenu.add(openItem); openItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // first close currently opened index // let user choose index file int retval = openChooser.showOpenDialog(MainWindow.this); if (retval != 0) { return; } String fileName = openChooser.getSelectedFile().getPath(); // open AM cmd.reset(); cmd.cmdType = LibgistCommand.OPEN; cmd.indexName.append(fileName); opThread.dispatchCmd(cmd); enableIndexOpened(); } }); closeItem = new JMenuItem("Close"); fileMenu.add(closeItem); closeItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // close AM cmd.reset(); cmd.cmdType = LibgistCommand.CLOSE; opThread.dispatchCmd(cmd); // MainWindow.this.setTitle("amdb"); } }); flushItem = new JMenuItem("Flush"); fileMenu.add(flushItem); flushItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // open AM cmd.reset(); cmd.cmdType = LibgistCommand.FLUSH; opThread.dispatchCmd(cmd); } }); fileMenu.addSeparator(); optionsItem = new JMenuItem("Properties..."); fileMenu.add(optionsItem); optionsItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Properties.edit(); } }); settingsItem = new JMenuItem("Save Settings"); fileMenu.add(settingsItem); settingsItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { saveConfig(); } }); fileMenu.addSeparator(); exitItem = new JMenuItem("Exit"); fileMenu.add(exitItem); exitItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // close AM opThread.stopNow(); Libgist.cleanup(); System.exit(0); } }); }
private void createOpsMenu() { opsMenu = new JMenu("Ops"); menuBar.add(opsMenu); insertItem = new JMenuItem("Insert..."); opsMenu.add(insertItem); final Object[] insertMsg = new Object[4]; insertMsg[0] = "Key:"; final JTextField insertKey = new JTextField(""); insertMsg[1] = insertKey; insertMsg[2] = "Data:"; final JTextField insertData = new JTextField(""); insertMsg[3] = insertData; insertItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { int response = JOptionPane.showOptionDialog( MainWindow.this, insertMsg, "Insert", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (response != JOptionPane.OK_OPTION) { return; } // insert new item cmd.reset(); cmd.cmdType = LibgistCommand.INSERT; cmd.key.append(insertKey.getText()); cmd.data.append(insertData.getText()); opThread.dispatchCmd(cmd); } }); deleteItem = new JMenuItem("Delete..."); opsMenu.add(deleteItem); final Object[] deleteMsg = new Object[2]; deleteMsg[0] = "Query:"; final JTextField deleteQuery = new JTextField(""); deleteMsg[1] = deleteQuery; deleteItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { int response = JOptionPane.showOptionDialog( MainWindow.this, deleteMsg, "Delete", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (response != JOptionPane.OK_OPTION) { return; } // delete item(s) cmd.reset(); cmd.cmdType = LibgistCommand.REMOVE; cmd.qual.append(deleteQuery.getText()); opThread.dispatchCmd(cmd); } }); searchItem = new JMenuItem("Search..."); opsMenu.add(searchItem); final Object[] searchMsg = new Object[4]; searchMsg[0] = "Query:"; final JTextField searchQuery = new JTextField(""); searchMsg[1] = searchQuery; searchMsg[2] = "Retrieval Limit:"; final JTextField retrLimit = new JTextField(""); searchMsg[3] = retrLimit; searchItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { int response = JOptionPane.showOptionDialog( MainWindow.this, searchMsg, "Search", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (response != JOptionPane.OK_OPTION) { return; } int limit = 0; // 0 means "get them all" // if no limit is specified: we leave it at 0 if (retrLimit.getText() != null) { try { limit = Integer.parseInt(retrLimit.getText()); } catch (NumberFormatException e) { // user typed junk limit = 0; retrLimit.setText(""); } } // execute query cmd.reset(); cmd.cmdType = LibgistCommand.FETCH; cmd.qual.append(searchQuery.getText()); cmd.fetchLimit = limit; opThread.dispatchCmd(cmd); } }); executeItem = new JMenuItem("Execute..."); final JFileChooser executeChooser = new JFileChooser("."); executeChooser.setDialogTitle("Execute Script"); executeChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); opsMenu.add(executeItem); executeItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { // let user choose script file int retval = executeChooser.showDialog(MainWindow.this, "Execute"); if (retval != 0) { return; } // execute script cmd.reset(); cmd.cmdType = LibgistCommand.SCRIPT; cmd.scriptFile.append(executeChooser.getSelectedFile().getPath()); opThread.dispatchCmd(cmd); } }); }
/** * Create JPanel asking users to select the file or directory containing files to be mapped and an * existing mapping file if they have one. * * @return JPanel containing elements! */ private JLayeredPane createSelectFilesPanel() { // create overall panel final JPanel selectFilesContainer = new JPanel(); selectFilesContainer.setSize(new Dimension(400, 100)); selectFilesContainer.setLayout(new BoxLayout(selectFilesContainer, BoxLayout.PAGE_AXIS)); // create selector for mapping files final FileSelectionPanel fileToMapFSP = new FileSelectionPanel( "<html>please select file(s) to be mapped (txt, csv or xls (Excel). Please ensure " + "that this file has <b>no empty columns</b> and if possible, please remove any special characters, e.g. μ</html>", fileChooser); selectFilesContainer.add(fileToMapFSP); JPanel selectMappingPanel = new JPanel(); selectMappingPanel.setLayout(new BoxLayout(selectMappingPanel, BoxLayout.PAGE_AXIS)); selectMappingPanel.setOpaque(false); // need a jcheckbox to ask users if they wish to use a mapping JPanel useMappingContainer = new JPanel(new BorderLayout()); useMappingContainer.setOpaque(false); // need a file selection panel to select the file. JFileChooser mappingFileChooser = new JFileChooser(); mappingFileChooser.setDialogTitle("Choose mapping file (XML)"); mappingFileChooser.setApproveButtonText("select file"); mappingFileChooser.setFont(UIHelper.VER_11_PLAIN); mappingFileChooser.setFileFilter(new CustomizableFileFilter("xml")); final FileSelectionPanel savedMappingsFile = new FileSelectionPanel( "<html>please select saved mapping file (xml): </html>", mappingFileChooser); savedMappingsFile.setVisible(false); final JCheckBox useMapping = new JCheckBox("use a previous mapping?"); UIHelper.renderComponent(useMapping, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false); useMapping.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { savedMappingsFile.setVisible(useMapping.isSelected()); } }); useMappingContainer.add(useMapping, BorderLayout.WEST); selectMappingPanel.add(useMappingContainer); selectMappingPanel.add(savedMappingsFile); selectFilesContainer.add(selectMappingPanel); final RoundedJTextField rowOffset = new RoundedJTextField(3); rowOffset.setEnabled(false); rowOffset.setSize(new Dimension(20, 20)); rowOffset.setText("1"); final JCheckBox overrideRowPosition = new JCheckBox("override row start position?"); UIHelper.renderComponent(overrideRowPosition, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false); overrideRowPosition.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { rowOffset.setEnabled(overrideRowPosition.isSelected()); } }); Box fileInputPanel = Box.createHorizontalBox(); fileInputPanel.setSize(new Dimension(100, 20)); fileInputPanel.add(overrideRowPosition); fileInputPanel.add(Box.createHorizontalStrut(5)); fileInputPanel.add(rowOffset); selectFilesContainer.add(fileInputPanel); selectFilesContainer.add(selectMappingPanel); final JCheckBox mapToBlankFieldsCheckbox = new JCheckBox("Do not remove blank fields?", false); UIHelper.renderComponent( mapToBlankFieldsCheckbox, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false); mapToBlankFieldsCheckbox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { mapToBlankFields = mapToBlankFieldsCheckbox.isSelected(); } }); JPanel removeBlanksContainer = new JPanel(new BorderLayout()); removeBlanksContainer.setOpaque(false); removeBlanksContainer.add(mapToBlankFieldsCheckbox, BorderLayout.WEST); selectFilesContainer.add(removeBlanksContainer); JPanel statusPanel = new JPanel(new GridLayout(1, 1)); statusPanel.setPreferredSize(new Dimension(400, 30)); final JLabel statusLab = UIHelper.createLabel("", UIHelper.VER_11_BOLD, UIHelper.RED_COLOR); statusPanel.add(statusLab); selectFilesContainer.add(statusPanel); final JLayeredPane finalLayout = getGeneralLayout(selectFilesHeader, breadcrumb1, "", selectFilesContainer, getHeight()); final MouseListener[] listeners = new MouseListener[2]; listeners[0] = new MouseAdapter() { public void mouseEntered(MouseEvent mouseEvent) { backButton.setIcon(backOver); } public void mouseExited(MouseEvent mouseEvent) { backButton.setIcon(back); } public void mousePressed(MouseEvent mouseEvent) { backButton.setIcon(back); SwingUtilities.invokeLater( new Runnable() { public void run() { ApplicationManager.getCurrentApplicationInstance().setCurrentPage(menuPanels); ApplicationManager.getCurrentApplicationInstance() .setGlassPanelContents(menuPanels.getCreateISAMenuGUI()); menuPanels.startAnimation(); } }); } }; assignListenerToLabel(backButton, listeners[0]); listeners[1] = new MouseAdapter() { public void mouseEntered(MouseEvent mouseEvent) { nextButton.setIcon(nextOver); } public void mouseExited(MouseEvent mouseEvent) { nextButton.setIcon(next); } public void mousePressed(MouseEvent mouseEvent) { nextButton.setIcon(next); Thread loadFile = new Thread( new Runnable() { public void run() { ISAcreatorProperties.setProperty( "isacreator.rowOffset", rowOffset.isEnabled() ? rowOffset.getText() : "1"); if (useMapping.isSelected()) { if (!savedMappingsFile.getSelectedFilePath().trim().equals("")) { MappingXMLLoader loader = new MappingXMLLoader(savedMappingsFile.getSelectedFilePath()); try { preExistingMapping = loader.loadMappings(); } catch (XmlException e) { log.error(e.getMessage()); statusLab.setText( "<html>problem found in xml for saved mapping: " + e.getMessage() + " </html>"); setCurrentPage(lastPage); return; } catch (IOException e) { log.error(e.getMessage()); statusLab.setText( "<html>problem found when resolving file for saved mapping: " + e.getMessage() + " </html>"); setCurrentPage(lastPage); return; } } else { statusLab.setText( "<html>please select a file containing previous mappings...</html>"); setCurrentPage(lastPage); return; } } else { log.info("Mapping is not selected"); statusLab.setText(""); } if (fileToMapFSP.notEmpty()) { previousPage.push(new HistoryComponent(finalLayout, listeners)); statusLab.setText(""); SwingUtilities.invokeLater( new Runnable() { public void run() { setCurrentPage( createAssayUsedPanel(fileToMapFSP.getSelectedFilePath())); } }); } else { statusLab.setText( "<html>please <strong>select</strong> a file to map!</html>"); setCurrentPage(lastPage); } } }); if (fileToMapFSP.notEmpty() && fileToMapFSP.checkFileExtensionValid("xls", "csv", "txt")) { statusLab.setText(""); lastPage = currentPage; setCurrentPage(workingProgressScreen); loadFile.start(); } else { statusLab.setText( "<html>please select a file with the extension <strong>.xls</strong>, <strong>.csv</strong> or <strong>.txt</strong>...</html>"); } } }; assignListenerToLabel(nextButton, listeners[1]); return finalLayout; }
/** * Create the JPanel to allow users to save the mappings created to be used in a proceeding * mapping activity! * * @return JLayeredPane containing the gui to allow a user to save the mapping file! */ private JLayeredPane createSaveMappings() { JPanel saveMappingFilesCont = new JPanel(); saveMappingFilesCont.setSize(new Dimension(400, 300)); saveMappingFilesCont.setLayout(new BoxLayout(saveMappingFilesCont, BoxLayout.PAGE_AXIS)); saveMappingFilesCont.add( UIHelper.wrapComponentInPanel(new JLabel(saveMappingHelp, SwingConstants.CENTER))); saveMappingFilesCont.add(Box.createVerticalStrut(10)); saveMappingFilesCont.add( UIHelper.wrapComponentInPanel( UIHelper.createLabel( "" + "<html>" + "Please be aware, the mappings saved are saved on a field by field basis. " + "This means that regardless of what assay you selected to do this/these mappings," + " common fields amongst all assays automatically inherit the mapping information. This has a number" + " of benefits and a number of negative points. " + "<br/>" + "<p>The <strong>main benefit</strong> being that common field mappings are transportable regardless of assay types.<p>" + "<p>The <strong>main problem</strong> is that because fields are saved on a field name basis, duplicate fields like" + " <strong>Protocol REF</strong> columns are not saved. This mechanism for saving will be changed in the next release!</p>" + "<br/>" + "<br/>" + "<br/>" + "</html>", UIHelper.VER_11_PLAIN, UIHelper.GREY_COLOR))); // create selector for mapping files JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Choose where and what to save the file as..."); chooser.setApproveButtonText("Select file"); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); JPanel selectMappingPanel = new JPanel(); selectMappingPanel.setLayout(new BoxLayout(selectMappingPanel, BoxLayout.PAGE_AXIS)); selectMappingPanel.setOpaque(false); // need a jcheckbox to ask users if they wish to use a mapping JPanel useMappingContainer = new JPanel(new BorderLayout()); useMappingContainer.setOpaque(false); final JPanel savedMappingsPanel = new JPanel(); savedMappingsPanel.setLayout(new BoxLayout(savedMappingsPanel, BoxLayout.PAGE_AXIS)); savedMappingsPanel.setOpaque(false); savedMappingsPanel.setVisible(false); final JLabel saveStatusInfo = UIHelper.createLabel("", UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR); final FileSelectionPanel savedMappingsFile = new FileSelectionPanel( "<html>select <strong>where</strong> to save file and <strong>it's name</strong>: </html>", chooser, FileSelectionPanel.SAVE); final JCheckBox useMapping = new JCheckBox("save mapping?"); UIHelper.renderComponent(useMapping, UIHelper.VER_11_BOLD, UIHelper.GREY_COLOR, false); useMapping.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { savedMappingsPanel.setVisible(useMapping.isSelected()); saveStatusInfo.setText(""); } }); useMappingContainer.add(useMapping, BorderLayout.WEST); selectMappingPanel.add(useMappingContainer); // add button to save mappings final JLabel saveMappingsButton = new JLabel(saveMappingsButtonIcon); saveMappingsButton.setVerticalAlignment(JLabel.BOTTOM); saveMappingsButton.addMouseListener( new MouseAdapter() { public void mouseEntered(MouseEvent mouseEvent) { saveMappingsButton.setIcon(saveMappingsButtonIconOver); } public void mouseExited(MouseEvent mouseEvent) { saveMappingsButton.setIcon(saveMappingsButtonIcon); } public void mousePressed(MouseEvent mouseEvent) { // save the mapping MappingXMLCreator mappingCreator = new MappingXMLCreator(); try { if (useMapping.isSelected()) { if (!savedMappingsFile.getSelectedFilePath().equals("")) { nextButton.setEnabled(false); backButton.setEnabled(false); mappingCreator.createXMLFile( savedMappingsFile.getSelectedFilePath(), mappingsToSave, assaysToBeDefined); saveStatusInfo.setText("mappings saved successfully..."); } else { saveStatusInfo.setText("please select a file..."); } } } catch (FileNotFoundException e) { e.printStackTrace(); saveStatusInfo.setText("mappings not saved..." + e.getMessage()); } finally { nextButton.setEnabled(true); backButton.setEnabled(true); } } }); final JLayeredPane finalPanel = getGeneralLayout(saveMappingsHeader, breadcrumb7, "", saveMappingFilesCont, getHeight()); final MouseListener[] listeners = new MouseListener[2]; listeners[0] = new MouseAdapter() { public void mouseEntered(MouseEvent mouseEvent) { backButton.setIcon(backOver); } public void mouseExited(MouseEvent mouseEvent) { backButton.setIcon(back); } public void mousePressed(MouseEvent mouseEvent) { backButton.setIcon(back); saveStatusInfo.setText(""); SwingUtilities.invokeLater( new Runnable() { public void run() { HistoryComponent hc = previousPage.pop(); setCurrentPage(hc.getDisplayComponent()); assignListenerToLabel(backButton, hc.getListeners()[0]); assignListenerToLabel(nextButton, hc.getListeners()[1]); } }); } }; assignListenerToLabel(backButton, listeners[0]); listeners[1] = new MouseAdapter() { public void mouseEntered(MouseEvent mouseEvent) { nextButton.setIcon(nextOver); } public void mouseExited(MouseEvent mouseEvent) { nextButton.setIcon(next); } public void mousePressed(MouseEvent mouseEvent) { nextButton.setIcon(next); Thread performMappingLogic = new Thread( new Runnable() { public void run() { investigation = MappingLogic.createInvestigation( definitions, assaySelections, dataEntryEnvironment); // now we need to construct the investigation from the defined table // reference objects and the ApplicationManager.assignDataEntryToISASection( investigation, new InvestigationDataEntry(investigation, dataEntryEnvironment)); investigation.setConfigurationCreateWith( ApplicationManager.getCurrentApplicationInstance() .getLoadedConfiguration()); investigation.setLastConfigurationUsed( ApplicationManager.getCurrentApplicationInstance() .getLoadedConfiguration()); dataEntryEnvironment.createGUIFromInvestigation(investigation); previousPage.push(new HistoryComponent(finalPanel, listeners)); ApplicationManager.getCurrentApplicationInstance().hideGlassPane(); ApplicationManager.getCurrentApplicationInstance() .setCurDataEntryPanel(dataEntryEnvironment); ApplicationManager.getCurrentApplicationInstance() .setCurrentPage(dataEntryEnvironment); } }); setCurrentPage(workingProgressScreen); performMappingLogic.start(); } }; JPanel saveMappingsSection = new JPanel(); saveMappingsSection.setLayout(new BoxLayout(saveMappingsSection, BoxLayout.LINE_AXIS)); saveMappingsSection.add(savedMappingsFile); saveMappingsSection.add(Box.createHorizontalStrut(10)); JPanel saveButtonContainer = new JPanel(new BorderLayout()); saveButtonContainer.add(saveMappingsButton, BorderLayout.SOUTH); saveMappingsSection.add(UIHelper.wrapComponentInPanel(saveButtonContainer)); savedMappingsPanel.add(saveMappingsSection); selectMappingPanel.add(savedMappingsPanel); saveMappingFilesCont.add(selectMappingPanel); saveMappingFilesCont.add(UIHelper.wrapComponentInPanel(saveStatusInfo)); assignListenerToLabel(nextButton, listeners[1]); return finalPanel; }