} //GEN-LAST:event_copyItemActionPerformed private void saveAsItemActionPerformed(ActionEvent evt) { //GEN-FIRST:event_saveAsItemActionPerformed java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("pspsharp/languages/pspsharp"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override': //ORIGINAL LINE: sealed override javax.swing.JFileChooser fc = new javax.swing.JFileChooser(); JFileChooser fc = new JFileChooser(); fc.DialogTitle = bundle.getString("FileLoggerFrame.strSaveTable.text"); fc.SelectedFile = new File(State.discId + "_fileio.txt"); fc.CurrentDirectory = new File("."); fc.addChoosableFileFilter(Constants.fltTextFiles); fc.FileFilter = Constants.fltTextFiles; if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File f = fc.SelectedFile; if (f.exists()) { int rc = MessageBox.Show(this, bundle.getString("ConsoleWindow.strFileExists.text"), bundle.getString("ConsoleWindow.strFileExistsTitle.text"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (rc != DialogResult.Yes) { return; } } try { JTable source = (JTable)((JPopupMenu)((JMenuItem)evt.Source).Parent).Invoker; string data = ""; // list column headers for (int j = 0; j < source.ColumnCount; j++) { data += source.getColumnName(j) + ";"; } // strip last semicolon and put a newline there instead data = data.Substring(0, data.Length - 1) + System.getProperty("line.separator"); // list table content for (int i = 0; i < source.RowCount; i++) { for (int j = 0; j < source.ColumnCount; j++) { data += source.Model.getValueAt(i, j) + ";"; } // strip last semicolon and put a newline there instead data = data.Substring(0, data.Length - 1) + System.getProperty("line.separator"); } System.IO.StreamWriter os = new System.IO.StreamWriter(f); os.Write(data); os.Close(); } catch (IOException ioe) { MessageBox.Show(this, bundle.getString("FileLoggerFrame.strSaveFailed.text") + ioe.LocalizedMessage); } } } //GEN-LAST:event_saveAsItemActionPerformed
} //GEN-LAST:event_cbTraceWrite32ItemStateChanged private void btnExportActionPerformed([email protected] evt) { //GEN-FIRST:event_btnExportActionPerformed java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("pspsharp/languages/pspsharp"); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override': //ORIGINAL LINE: sealed override javax.swing.JFileChooser fc = new javax.swing.JFileChooser(); JFileChooser fc = new JFileChooser(); fc.DialogTitle = bundle.getString("MemoryBreakpointsDialog.dlgExport.title"); fc.SelectedFile = new File(State.discId + ".mbrk"); fc.CurrentDirectory = new File("."); fc.addChoosableFileFilter(Constants.fltMemoryBreakpointFiles); fc.FileFilter = Constants.fltMemoryBreakpointFiles; if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File f = fc.SelectedFile; if (f.exists()) { int rc = MessageBox.Show(this, bundle.getString("ConsoleWindow.strFileExists.text"), bundle.getString("ConsoleWindow.strFileExistsTitle.text"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (rc != DialogResult.Yes) { return; } } ((DebuggerMemory)Memory.Instance).exportBreakpoints(fc.SelectedFile); } } //GEN-LAST:event_btnExportActionPerformed
public FileProperty(PropertyHolder parent, string name, string defaultValue) : base((Class) ClassLiteral<String>.Value, parent, name, (object) defaultValue) { FileProperty fileProperty = this; JFileChooser.__\u003Cclinit\u003E(); this.chooser = new JFileChooser((string) this.getValue()); }
/// <summary>Creates new form ParserPanel</summary> public ParserPanel() { // constants for language specification // one second in milliseconds // parser takes approximately a minute to load // parser takes 5-60 seconds to parse a sentence // constants for finding nearest sentence boundary // for highlighting // worker threads to handle long operations // to monitor progress of long operations //private ProgressMonitor progressMonitor; // progress count // use glass pane to block input to components other than progressMonitor InitComponents(); // create dialogs for file selection jfc = new JFileChooser(Runtime.GetProperty("user.dir")); pageDialog = new OpenPageDialog(new Frame(), true); pageDialog.SetFileChooser(jfc); jfcLocation = new ParserPanel.JFileChooserLocation(jfc); tlp = new PennTreebankLanguagePack(); encoding = tlp.GetEncoding(); SetFont(); // create a timer timer = new Timer(OneSecond, new ParserPanel.TimerListener(this)); // for (un)highlighting text highlightStyle = new SimpleAttributeSet(); normalStyle = new SimpleAttributeSet(); StyleConstants.SetBackground(highlightStyle, Color.yellow); StyleConstants.SetBackground(normalStyle, textPane.GetBackground()); this.chooseJarParser = new JarFileChooser(".*\\.ser\\.gz", this); }
/// <summary>Creates new form OpenPageDialog</summary> public OpenPageDialog(Frame parent, bool modal) : base(parent, modal) { InitComponents(); jfc = new JFileChooser(); AddWindowListener(new _WindowAdapter_33(this)); }
protected internal virtual JFileChooser createFileChooser() { JFileChooser jfileChooser = new JFileChooser(); jfileChooser.addChoosableFileFilter((FileFilter) new ExtensionFileFilter(this.getFileDescription(), this.getFileExtension())); jfileChooser.setMultiSelectionEnabled(false); jfileChooser.setCurrentDirectory(this.getCurrentDirectory()); return jfileChooser; }
protected internal virtual File performSelectFile(File selectedFile, int dialogType, bool appendExtension) { if (this.fileChooser == null) this.fileChooser = this.createFileChooser(); this.fileChooser.setSelectedFile(selectedFile); this.fileChooser.setDialogType(dialogType); if (this.fileChooser.showDialog(this.parent, (string) null) != 0) return (File) null; string @base = this.fileChooser.getSelectedFile().getAbsolutePath(); if (!StringUtils.endsWithIgnoreCase(@base, this.getFileExtension())) @base = new StringBuffer().append(@base).append(this.getFileExtension()).toString(); return new File(@base); }
/// <summary> /// Opens a dialog from which users can browse for delta plot files. </summary> /// <returns> the path to the file the user chose, or "" if no file was selected. </returns> private string browseForFile() { JGUIUtil.setWaitCursor(__parent, true); string directory = JGUIUtil.getLastFileDialogDirectory(); JFileChooser fc = null; if (!string.ReferenceEquals(directory, null)) { fc = new JFileChooser(directory); } else { fc = new JFileChooser(); } fc.setDialogTitle("Select File"); SimpleFileFilter xre = new SimpleFileFilter("xdd", "ASCII xre"); SimpleFileFilter b44 = new SimpleFileFilter("b44", "Binary b44"); SimpleFileFilter xdd = new SimpleFileFilter("xdd", "ASCII xdd"); SimpleFileFilter b43 = new SimpleFileFilter("b43", "Binary b43"); fc.addChoosableFileFilter(xre); fc.addChoosableFileFilter(b44); fc.addChoosableFileFilter(xdd); fc.addChoosableFileFilter(b43); fc.setAcceptAllFileFilterUsed(true); fc.setFileFilter(xre); fc.setDialogType(JFileChooser.SAVE_DIALOG); JGUIUtil.setWaitCursor(__parent, false); int retVal = fc.showSaveDialog(__parent); if (retVal != JFileChooser.APPROVE_OPTION) { return(""); } string currDir = (fc.getCurrentDirectory()).ToString(); if (!currDir.Equals(directory, StringComparison.OrdinalIgnoreCase)) { JGUIUtil.setLastFileDialogDirectory(currDir); } string filename = fc.getSelectedFile().getName(); return(currDir + File.separator + filename); }
} //GEN-LAST:event_btnExportActionPerformed private void btnImportActionPerformed([email protected] evt) { //GEN-FIRST:event_btnImportActionPerformed //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override': //ORIGINAL LINE: sealed override javax.swing.JFileChooser fc = new javax.swing.JFileChooser(); JFileChooser fc = new JFileChooser(); fc.DialogTitle = java.util.ResourceBundle.getBundle("pspsharp/languages/pspsharp").getString("MemoryBreakpointsDialog.dlgImport.title"); fc.SelectedFile = new File(State.discId + ".mbrk"); fc.CurrentDirectory = new File("."); fc.addChoosableFileFilter(Constants.fltMemoryBreakpointFiles); fc.FileFilter = Constants.fltMemoryBreakpointFiles; if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { ((DebuggerMemory)Memory.Instance).importBreakpoints(fc.SelectedFile); } memoryBreakpointsModel.fireTableDataChanged(); updateTraceSettings(); } //GEN-LAST:event_btnImportActionPerformed
private void btnFilenameActionPerformed([email protected] evt) { //GEN-FIRST:event_btnFilenameActionPerformed JFileChooser fc = new JFileChooser(); fc.DialogTitle = java.util.ResourceBundle.getBundle("pspsharp/languages/pspsharp").getString("DumpCodeDialog.dlgOutputFile.title"); fc.SelectedFile = new File(txtFilename.Text); fc.addChoosableFileFilter(Constants.fltTextFiles); fc.FileFilter = Constants.fltTextFiles; int returnVal = fc.showOpenDialog(this); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } txtFilename.Text = fc.SelectedFile.AbsolutePath; } //GEN-LAST:event_btnFilenameActionPerformed
} //GEN-LAST:event_ClearMessageButtonActionPerformed private void SaveMessageToFileButtonActionPerformed([email protected] evt) { //GEN-FIRST:event_SaveMessageToFileButtonActionPerformed java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("pspsharp/languages/pspsharp"); // NOI18N JFileChooser m_fileChooser = new JFileChooser(); m_fileChooser.SelectedFile = new File("logoutput.txt"); m_fileChooser.DialogTitle = bundle.getString("ConsoleWindow.strSaveLogging.text"); m_fileChooser.CurrentDirectory = new File("."); int returnVal = m_fileChooser.showSaveDialog(this); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } File f = m_fileChooser.SelectedFile; System.IO.StreamWriter @out = null; try { if (f.exists()) { int res = MessageBox.Show(this, bundle.getString("ConsoleWindow.strFileExists.text"), bundle.getString("ConsoleWindow.strFileExistsTitle.text"), MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res != 0) { return; } } //IOHelper.saveTxtFile(f, ta_messages.getText(), false); @out = new System.IO.StreamWriter(f); @out.BaseStream.WriteByte(talogging.Text); } catch (Exception e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } finally { Utilities.close(@out); } } //GEN-LAST:event_SaveMessageToFileButtonActionPerformed
private string browseForFile() { JGUIUtil.setWaitCursor(this, true); string directory = JGUIUtil.getLastFileDialogDirectory(); JFileChooser fc = JFileChooserFactory.createJFileChooser(directory); string compName = __tableModel.getComponentName(__worksheet.getSelectedRow()); string ext = __dataset.getComponentFileExtension(__tableModel.getComponentTypeForRow(__worksheet.getSelectedRow())); fc.setDialogTitle("Select " + compName + " File"); SimpleFileFilter ff = new SimpleFileFilter(ext, compName + " files"); fc.addChoosableFileFilter(ff); fc.setAcceptAllFileFilterUsed(true); fc.setDialogType(JFileChooser.OPEN_DIALOG); fc.setFileFilter(ff); JGUIUtil.setWaitCursor(this, false); int retVal = fc.showOpenDialog(this); if (retVal != JFileChooser.APPROVE_OPTION) { return(""); } string currDir = (fc.getCurrentDirectory()).ToString(); if (!currDir.Equals(directory, StringComparison.OrdinalIgnoreCase)) { JGUIUtil.setLastFileDialogDirectory(currDir); } string filename = fc.getSelectedFile().getName(); return(currDir + File.separator + filename); }
/// <summary> /// Browse for a statemod output file. /// </summary> private string browseForFile() { JGUIUtil.setWaitCursor(__parent, true); string lastDirectorySelected = JGUIUtil.getLastFileDialogDirectory(); JFileChooser fc = JFileChooserFactory.createJFileChooser(lastDirectorySelected); fc.setDialogTitle("Select file"); // SimpleFileFilter ff = new SimpleFileFilter("???", "?Some kind of file?"); // fc.addChoosableFileFilter(ff); // fc.setAcceptAllFileFilterUsed(false); // fc.setFileFilter(ff); fc.setAcceptAllFileFilterUsed(true); fc.setDialogType(JFileChooser.OPEN_DIALOG); JGUIUtil.setWaitCursor(__parent, false); int retVal = fc.showOpenDialog(__parent); if (retVal != JFileChooser.APPROVE_OPTION) { return(null); } string currDir = (fc.getCurrentDirectory()).ToString(); if (!currDir.Equals(lastDirectorySelected, StringComparison.OrdinalIgnoreCase)) { JGUIUtil.setLastFileDialogDirectory(currDir); } string filename = fc.getSelectedFile().getName(); // do some work with the filename, perhaps return(currDir + File.separator + filename); }
/// <summary> /// Method main, that provides the dialog box prompts to create the /// 1-Wire XML tag. /// </summary> /// <param name="args"> command line arguments </param> public static void Main(string[] args) { OneWireContainer tag_owd; DSPortAdapter adapter = null; ArrayList owd_vect = new ArrayList(5); bool get_min = false, get_max = false, get_channel = false, get_init = false, get_scale = false; string file_type, label, tag_type, method_type = null, cluster; string min = null, max = null, channel = null, init = null, scale = null; // connect now message JOptionPane.showMessageDialog(null, "Connect the 1-Wire device to Tag onto the Default 1-Wire port", "1-Wire Tag Creator", JOptionPane.INFORMATION_MESSAGE); try { // get the default adapter adapter = OneWireAccessProvider.DefaultAdapter; // get exclusive use of adapter adapter.beginExclusive(true); // find all parts owd_vect = findAllDevices(adapter); // select a device tag_owd = selectDevice(owd_vect, "Select the 1-Wire Device to Tag"); // enter the label for this devcie label = JOptionPane.showInputDialog(null, "Enter a human readable label for this device: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE); if (string.ReferenceEquals(label, null)) { throw new InterruptedException("Aborted"); } // enter the cluster for this devcie cluster = JOptionPane.showInputDialog(null, "Enter a cluster where this device will reside: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE); if (string.ReferenceEquals(cluster, null)) { throw new InterruptedException("Aborted"); } // select the type of device string[] tag_types = new string[] { "sensor", "actuator", "branch" }; tag_type = (string)JOptionPane.showInputDialog(null, "Select the Tag Type", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE, null, tag_types, tag_types[0]); if (string.ReferenceEquals(tag_type, null)) { throw new InterruptedException("Aborted"); } // check if branch selected if (string.ReferenceEquals(tag_type, "branch")) { get_init = true; get_channel = true; } // sensor else if (string.ReferenceEquals(tag_type, "sensor")) { string[] sensor_types = new string[] { "Contact", "Humidity", "Event", "Thermal" }; method_type = (string)JOptionPane.showInputDialog(null, "Select the Sensor Type", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE, null, sensor_types, sensor_types[0]); if (string.ReferenceEquals(method_type, null)) { throw new InterruptedException("Aborted"); } // contact if (string.ReferenceEquals(method_type, "Contact")) { get_min = true; get_max = true; } // Event else if (string.ReferenceEquals(method_type, "Event")) { get_channel = true; get_max = true; } } // actuator else { string[] actuator_types = new string[] { "Switch", "D2A" }; method_type = (string)JOptionPane.showInputDialog(null, "Select the Actuator Type", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE, null, actuator_types, actuator_types[0]); if (string.ReferenceEquals(method_type, null)) { throw new InterruptedException("Aborted"); } get_channel = true; get_init = true; get_min = true; get_max = true; } // enter the tags required if (get_min) { min = JOptionPane.showInputDialog(null, "Enter the 'min' value: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE); } if (string.ReferenceEquals(min, null)) { get_min = false; } if (get_max) { max = JOptionPane.showInputDialog(null, "Enter the 'max' value: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE); } if (string.ReferenceEquals(max, null)) { get_max = false; } if (get_channel) { channel = JOptionPane.showInputDialog(null, "Enter the 'channel' value: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE); } if (string.ReferenceEquals(channel, null)) { get_channel = false; } if (get_init) { init = JOptionPane.showInputDialog(null, "Enter the 'init' value: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE); } if (string.ReferenceEquals(init, null)) { get_init = false; } if (get_scale) { scale = JOptionPane.showInputDialog(null, "Enter the 'scale' value: ", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE); } if (string.ReferenceEquals(scale, null)) { get_scale = false; } // build the XML file ArrayList xml = new ArrayList(5); xml.Add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); xml.Add("<cluster name=\"" + cluster + "\">"); xml.Add(" <" + tag_type + " addr=\"" + tag_owd.AddressAsString + "\" type=\"" + method_type + "\">"); xml.Add(" <label>" + label + "</label>"); if (get_max) { xml.Add(" <max>" + max + "</max>"); } if (get_min) { xml.Add(" <min>" + min + "</min>"); } if (get_channel) { xml.Add(" <channel>" + channel + "</channel>"); } if (get_init) { xml.Add(" <init>" + init + "</init>"); } if (get_scale) { xml.Add(" <scale>" + scale + "</scale>"); } xml.Add(" </" + tag_type + ">"); xml.Add("</cluster>"); // display the XML file JList list = new JList(xml.ToArray()); if (MessageBox.Show(null, list, "Is this correct?", MessageBoxButtons.YesNo) != DialogResult.Yes) { throw new InterruptedException("Aborted"); } // loop until file written bool file_written = false; do { // Check if doing desktop or 1-Wire file string[] file_types = new string[] { "Desktop File", "1-Wire File" }; file_type = (string)JOptionPane.showInputDialog(null, "Select where to put this XML 1-Wire Tag file", "1-Wire tag Creator", JOptionPane.INFORMATION_MESSAGE, null, file_types, file_types[0]); if (string.ReferenceEquals(file_type, null)) { throw new InterruptedException("Aborted"); } // save to a PC file if (string.ReferenceEquals(file_type, "Desktop File")) { JFileChooser chooser = new JFileChooser(); int returnVal = chooser.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { try { PrintWriter writer = new PrintWriter(new System.IO.FileStream(chooser.SelectedFile.CanonicalPath, true)); for (int i = 0; i < xml.Count; i++) { writer.println(xml[i]); } writer.flush(); writer.close(); JOptionPane.showMessageDialog(null, "XML File saved to: " + chooser.SelectedFile.CanonicalPath, "1-Wire Tag Creator", JOptionPane.INFORMATION_MESSAGE); file_written = true; } catch (FileNotFoundException e) { Console.WriteLine(e); JOptionPane.showMessageDialog(null, "ERROR saving XML File: " + chooser.SelectedFile.CanonicalPath, "1-Wire Tag Creator", JOptionPane.WARNING_MESSAGE); } } } // 1-Wire file else { // search parts again in case the target device was just connected owd_vect = findAllDevices(adapter); // select the 1-Wire device to save the file to tag_owd = selectDevice(owd_vect, "Select the 1-Wire Device to place XML Tag"); // attempt to write to the filesystem of this device try { PrintWriter writer = new PrintWriter(new OWFileOutputStream(tag_owd, "TAGX.0")); for (int i = 0; i < xml.Count; i++) { writer.println(xml[i]); } writer.flush(); writer.close(); JOptionPane.showMessageDialog(null, "XML File saved to: " + tag_owd.AddressAsString + "\\TAGX.000", "1-Wire Tag Creator", JOptionPane.INFORMATION_MESSAGE); file_written = true; } catch (OWFileNotFoundException e) { Console.WriteLine(e); JOptionPane.showMessageDialog(null, "ERROR saving XML File: " + tag_owd.AddressAsString + "\\TAGX.000", "1-Wire Tag Creator", JOptionPane.WARNING_MESSAGE); } } // check if file not written if (!file_written) { if (MessageBox.Show(null, "Try to save file again?", "1-Wire Tag Creator", MessageBoxButtons.OKCancel) != DialogResult.OK) { throw new InterruptedException("Aborted"); } } } while (!file_written); } catch (Exception e) { Console.WriteLine(e); } finally { if (adapter != null) { // end exclusive use of adapter adapter.endExclusive(); // free the port used by the adapter Console.WriteLine("Releasing adapter port"); try { adapter.freePort(); } catch (OneWireException e) { Console.WriteLine(e); } } } Environment.Exit(0); }
public FileProperty(PropertyHolder parent, string name) : base((Class) ClassLiteral<String>.Value, parent, name) { FileProperty fileProperty = this; this.chooser = new JFileChooser(); }
public virtual void CreateFileChooser() { dlg = new JFileChooser(); FileFilter filter = new _FileFilter_62(); dlg.AddChoosableFileFilter(filter); }
/// <summary> /// Returns the filename and format type of a file selected from a file chooser /// in order that the kind of delimiter for the file can be known when the data /// is formatted for output. Currently the only kinds of files that the data /// can be exported to are delimited files. No StateMod files are yet supported.<para> /// Also sets the last selected file dialog directory to whatever directory the /// file is located in, if the file selection was approved (i.e., Cancel was not /// pressed). /// </para> /// </summary> /// <param name="title"> the title of the file chooser. </param> /// <param name="formats"> a Vector of the valid formats for the file chooser. </param> /// <returns> a two-element String array where the first element is the name of the /// file and the second element is the delimiter selected. </returns> protected internal virtual string[] getFilenameAndFormat() { JGUIUtil.setWaitCursor(this, true); string dir = JGUIUtil.getLastFileDialogDirectory(); JFileChooser fc = JFileChooserFactory.createJFileChooser(dir); fc.setDialogTitle("Select Export File"); SimpleFileFilter tabFF = new SimpleFileFilter("txt", "Tab-delimited"); SimpleFileFilter commaFF = new SimpleFileFilter("csv", "Comma-delimited"); SimpleFileFilter semiFF = new SimpleFileFilter("txt", "Semicolon-delimited"); SimpleFileFilter pipeFF = new SimpleFileFilter("txt", "Pipe-delimited"); fc.addChoosableFileFilter(commaFF); fc.addChoosableFileFilter(pipeFF); fc.addChoosableFileFilter(semiFF); fc.addChoosableFileFilter(tabFF); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(commaFF); fc.setDialogType(JFileChooser.SAVE_DIALOG); JGUIUtil.setWaitCursor(this, false); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { string[] ret = new string[2]; string filename = fc.getCurrentDirectory() + File.separator + fc.getSelectedFile().getName(); JGUIUtil.setLastFileDialogDirectory("" + fc.getCurrentDirectory()); SimpleFileFilter sff = (SimpleFileFilter)fc.getFileFilter(); // this will always return a one-element vector IList <string> extensionV = sff.getFilters(); string extension = extensionV[0]; string desc = sff.getShortDescription(); string delimiter = "\t"; if (desc.Equals("Tab-delimited")) { delimiter = "\t"; } else if (desc.Equals("Comma-delimited")) { delimiter = ","; } else if (desc.Equals("Semicolon-delimited")) { delimiter = ";"; } else if (desc.Equals("Pipe-delimited")) { delimiter = "|"; } ret[0] = IOUtil.enforceFileExtension(filename, extension); ret[1] = delimiter; return(ret); } else { return(null); } }
/// <summary> /// Write list files for the main station lists. These can then be used with /// list-based commands in StateDMI. /// The user is prompted for a list file name. /// </summary> protected internal virtual void writeListFiles() { string routine = "StateMod_Network_JComponent.writeListFiles"; string lastDirectorySelected = JGUIUtil.getLastFileDialogDirectory(); JFileChooser fc = JFileChooserFactory.createJFileChooser(lastDirectorySelected); fc.setDialogTitle("Select Base Filename for List Files"); SimpleFileFilter tff = new SimpleFileFilter("txt", "Text Files"); fc.addChoosableFileFilter(tff); SimpleFileFilter csv_ff = new SimpleFileFilter("csv", "Comma-separated Values"); fc.addChoosableFileFilter(csv_ff); fc.setFileFilter(csv_ff); fc.setDialogType(JFileChooser.SAVE_DIALOG); int retVal = fc.showSaveDialog(this.__editorJComponent); if (retVal != JFileChooser.APPROVE_OPTION) { return; } string currDir = (fc.getCurrentDirectory()).ToString(); if (!currDir.Equals(lastDirectorySelected, StringComparison.OrdinalIgnoreCase)) { JGUIUtil.setLastFileDialogDirectory(currDir); } string filename = fc.getSelectedFile().getPath(); // Station types... int[] types = new int[] { -1, HydrologyNode.NODE_TYPE_FLOW, HydrologyNode.NODE_TYPE_DIV, HydrologyNode.NODE_TYPE_DIV_AND_WELL, HydrologyNode.NODE_TYPE_PLAN, HydrologyNode.NODE_TYPE_RES, HydrologyNode.NODE_TYPE_ISF, HydrologyNode.NODE_TYPE_WELL, HydrologyNode.NODE_TYPE_OTHER }; /* TODO SAM 2006-01-03 Just use node abbreviations from network * // Suffix for output, to be added to file basename... * * String[] nodetype_string = { * "All", * "StreamGage", * "Diversion", * "DiversionAndWell", * "Plan", * "Reservoir", * "InstreamFlow", * "Well", * // TODO SAM 2006-01-03 Evaluate similar to node type above. * //"StreamEstimate", * "Other" * }; */ // Put the extension on the file (user may or may not have added)... if (fc.getFileFilter() == tff) { filename = IOUtil.enforceFileExtension(filename, "txt"); } else if (fc.getFileFilter() == csv_ff) { filename = IOUtil.enforceFileExtension(filename, "csv"); } // Now get the base name and remaining extension so that the basename can be adjusted below... int lastIndex = filename.LastIndexOf(".", StringComparison.Ordinal); string front = filename.Substring(0, lastIndex); string end = filename.Substring((lastIndex + 1), filename.Length - (lastIndex + 1)); string outputFilename = null; IList <HydrologyNode> v = null; string warning = ""; string[] comments = null; for (int i = 0; i < types.Length; i++) { v = this.__editorJComponent.getNodesForType(types[i]); if (v != null && v.Count > 0) { comments = new string[1]; if (types[i] == -1) { comments[0] = "The following list contains data for all node types."; outputFilename = front + "_All." + end; } else { comments[0] = "The following list contains data for the following node type: " + HydrologyNode.getTypeString(types[i], HydrologyNode.ABBREVIATION) + " (" + HydrologyNode.getTypeString(types[i], HydrologyNode.FULL) + ")"; outputFilename = front + "_" + HydrologyNode.getTypeString(types[i], HydrologyNode.ABBREVIATION) + "." + end; } try { StateMod_NodeNetwork.writeListFile(outputFilename, ",", false, v, comments, false); } catch (Exception e) { Message.printWarning(3, routine, e); warning += "\nUnable to create list file \"" + outputFilename + "\""; } } } // TODO SAM 2006-01-03 Write at level 1 since this is currently triggered from an // interactive action. However, may need to change if executed in batch mode. if (warning.Length > 0) { Message.printWarning(1, routine, warning); } }
internal JFileChooserLocation(JFileChooser jfc) { this.jfc = jfc; jfc.AddAncestorListener(this); }
public const int STATUS_READ_START = 20, STATUS_READ_COMPLETE = 22, STATUS_READ_GVP_START = 50, STATUS_READ_GVP_END = 51; // End reading the GVP file; /// <summary> /// Add filename filters to the file chooser for time series files. A general ".stm" entry is added as well /// as well rights. </summary> /// <param name="fc"> File chooser. </param> /// <param name="timeInterval"> the TimeInterval for choices (TimeInterval.DAY, TimeInterval.MONTH, /// or TimeInterval.UNKNOWN for all). </param> /// <param name="addRightFiles"> indicate whether water right files should be added. </param> public static void addTimeSeriesFilenameFilters(JFileChooser fc, int timeInterval, bool addRightFiles) { // Interleave the entries because TimeInterval.UKNOWN will want a complete list if ((timeInterval == TimeInterval.DAY) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("ddd", "StateMod Diversion Demands (Daily)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("ddm", "StateMod Diversion Demands (Monthly)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("dda", "StateMod Diversion Demands (Average Monthly)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("ddo", "StateMod Diversion Demands Override (Monthly)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.DAY) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("ddy", "StateMod Diversions, Historical (Daily)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("ddh", "StateMod Diversions, Historicial (Monthly)"); fc.addChoosableFileFilter(sff); } if (addRightFiles) { SimpleFileFilter ssf = new SimpleFileFilter("ddr", "StateMod Diversion Rights"); fc.addChoosableFileFilter(ssf); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("eva", "StateMod Evaporation (Monthly)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.DAY) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("ifd", "StateMod Instream Flow Demands (Daily)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("ifa", "StateMod Instream Flow Demands (Average Monthly)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("ifm", "StateMod Instream Flow Demands (Monthly)"); fc.addChoosableFileFilter(sff); } if (addRightFiles) { SimpleFileFilter sff = new SimpleFileFilter("ifr", "StateMod Instream Flow Rights"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("ddc", "StateMod/StateCU Irrigation Water Requirement (Monthly)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("iwr", "StateMod/StateCU Irrigation Water Requirement (Monthly)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("xop", "StateMod Output - Operational Rights (Monthly)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("pre", "StateMod Precipitation (Monthly)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.DAY) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("eoy", "StateMod Reservoir Storage (End of Day)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("eom", "StateMod Reservoir Storage (End of Month)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.DAY) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("tad", "StateMod Reservoir Min/Max Targets (Daily)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("tar", "StateMod Reservoir Min/Max Targets (Monthly)"); fc.addChoosableFileFilter(sff); } if (addRightFiles) { SimpleFileFilter sff = new SimpleFileFilter("rer", "StateMod Reservoir Rights"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.DAY) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("riy", "StateMod Streamflow, Historical (Daily)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("rih", "StateMod Streamflow, Historicial (Monthly)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.DAY) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("riy", "StateMod Streamflow, Natural (Daily)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("rim", "StateMod Streamflow, Natural (Monthly, as input)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("xbm", "StateMod Streamflow, Natural (Monthly, as output)"); fc.addChoosableFileFilter(sff); } SimpleFileFilter stm_sff = new SimpleFileFilter("stm", "StateMod Time Series"); fc.addChoosableFileFilter(stm_sff); if ((timeInterval == TimeInterval.DAY) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("wed", "StateMod Well Demands (Daily)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("wem", "StateMod Well Demands (Monthly)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.DAY) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("wey", "StateMod Well Historical Pumping (Daily)"); fc.addChoosableFileFilter(sff); } if ((timeInterval == TimeInterval.MONTH) || (timeInterval == TimeInterval.UNKNOWN)) { SimpleFileFilter sff = new SimpleFileFilter("weh", "StateMod Well Historicial Pumping (Monthly)"); fc.addChoosableFileFilter(sff); } if (addRightFiles) { SimpleFileFilter sff = new SimpleFileFilter("wer", "StateMod Well Rights"); fc.addChoosableFileFilter(sff); } // Select the "stm" filter as the most generic. fc.setFileFilter(stm_sff); }
/// <summary>Sets the file chooser used by the Browse button</summary> public virtual void SetFileChooser(JFileChooser jfc) { this.jfc = jfc; }
/// <summary> /// Responds to action performed events. </summary> /// <param name="ae"> the ActionEvent that happened. </param> public virtual void actionPerformed(ActionEvent ae) { string routine = "StateMod_OutputControl_JFrame.actionPerformed"; string action = ae.getActionCommand(); if (action.Equals(__BUTTON_ADD_ROW)) { if (!__tableModel.canAddNewRow()) { return; } __dirty = true; int row = __worksheet.getRowCount(); StateMod_GraphNode n = new StateMod_GraphNode(); __worksheet.addRow(n); n.setType(""); n.setID(""); n.setSwitch(-1); __tableModel.setDirty(true); // when a row is added, mark the second and third columns // as uneditable. They will be set to editable as soon as // the user enters a value in the first column __worksheet.setCellEditable(row, 1, false); __worksheet.setCellEditable(row, 2, false); } else if (action.Equals(__BUTTON_CLEAR_LIST)) { __dirty = true; __worksheet.clear(); setMessages("Add station to list.", "Ready"); __tableModel.setDirty(true); } else if (action.Equals(__BUTTON_CLOSE)) { closeWindow(); } else if (action.Equals(__BUTTON_DELETE_ROW)) { int[] rows = __worksheet.getSelectedRows(); int length = rows.Length; __tableModel.setDirty(true); if (length == 0) { return; } for (int i = (length - 1); i >= 0; i--) { __worksheet.deleteRow(rows[i]); } __dirty = true; setMessages("Time series list has changed.", "Ready"); } else if (action.Equals(__BUTTON_HELP)) { // REVISIT HELP (JTS - 2003-07-09) } else if (action.Equals(__BUTTON_SAVE_FILE)) { JGUIUtil.setWaitCursor(this, true); string lastDirectorySelected = JGUIUtil.getLastFileDialogDirectory(); JFileChooser fc = null; if (!string.ReferenceEquals(lastDirectorySelected, null)) { fc = new JFileChooser(lastDirectorySelected); } else { fc = new JFileChooser(); } fc.setDialogTitle("Select Output Control File"); SimpleFileFilter @out = new SimpleFileFilter("out", "StateMod Output Control Files"); fc.addChoosableFileFilter(@out); SimpleFileFilter tpl = new SimpleFileFilter("tpo", "StateMod Output Control Files"); fc.addChoosableFileFilter(tpl); SimpleFileFilter xou = new SimpleFileFilter("xou", "StateMod Output Control Files"); fc.addChoosableFileFilter(xou); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(tpl); fc.setDialogType(JFileChooser.SAVE_DIALOG); JGUIUtil.setWaitCursor(this, false); int retVal = fc.showSaveDialog(this); if (retVal != JFileChooser.APPROVE_OPTION) { return; } string currDir = (fc.getCurrentDirectory()).ToString(); if (!currDir.Equals(lastDirectorySelected, StringComparison.OrdinalIgnoreCase)) { JGUIUtil.setLastFileDialogDirectory(currDir); } string filename = fc.getSelectedFile().getName(); FileFilter ff = fc.getFileFilter(); if (ff == @out) { filename = IOUtil.enforceFileExtension(filename, "out"); } else if (ff == tpl) { filename = IOUtil.enforceFileExtension(filename, "tpo"); } else if (ff == xou) { filename = IOUtil.enforceFileExtension(filename, "xou"); } __dirty = false; __tableModel.setDirty(false); System.Collections.IList theGraphNodes = __worksheet.getAllData(); try { StateMod_GraphNode.writeStateModOutputControlFile(null, currDir + File.separator + filename, theGraphNodes, null); } catch (Exception e) { Message.printWarning(1, routine, "Error saving output control file\n" + "\"" + currDir + File.separator + filename + "\"", this); Message.printWarning(2, routine, e); } } else if (action.Equals(__BUTTON_LOAD_FILE)) { JGUIUtil.setWaitCursor(this, true); string lastDirectorySelected = JGUIUtil.getLastFileDialogDirectory(); JFileChooser fc = null; if (!string.ReferenceEquals(lastDirectorySelected, null)) { fc = new JFileChooser(lastDirectorySelected); } else { fc = new JFileChooser(); } fc.setDialogTitle("Select Output Control File"); SimpleFileFilter @out = new SimpleFileFilter("out", "StateMod Output Control Files"); fc.addChoosableFileFilter(@out); SimpleFileFilter tpl = new SimpleFileFilter("tpo", "StateMod Output Control Files"); fc.addChoosableFileFilter(tpl); SimpleFileFilter xou = new SimpleFileFilter("xou", "StateMod Output Control Files"); fc.addChoosableFileFilter(xou); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(tpl); fc.setDialogType(JFileChooser.OPEN_DIALOG); JGUIUtil.setWaitCursor(this, false); int retVal = fc.showOpenDialog(this); if (retVal != JFileChooser.APPROVE_OPTION) { return; } string currDir = (fc.getCurrentDirectory()).ToString(); if (!currDir.Equals(lastDirectorySelected, StringComparison.OrdinalIgnoreCase)) { JGUIUtil.setLastFileDialogDirectory(currDir); } string filename = fc.getSelectedFile().getName(); JGUIUtil.setWaitCursor(this, true); __dirty = false; System.Collections.IList theGraphNodes = new List <object>(20, 1); try { __worksheet.clear(); __tableModel.setDirty(false); StateMod_GraphNode.readStateModOutputControlFile(theGraphNodes, currDir + File.separator + filename); int size = theGraphNodes.Count; StateMod_GraphNode g = null; int row = 0; for (int i = 0; i < size; i++) { row = __worksheet.getRowCount(); g = (StateMod_GraphNode)theGraphNodes[i]; if (i == 0) { if (g.getID().Equals("All")) { __useAllJCheckBox.setSelected(true); } else { __useAllJCheckBox.setSelected(false); } } __worksheet.addRow(g); __tableModel.fillIDColumn(row, g.getType()); } __worksheet.setData(theGraphNodes); } catch (Exception e) { Message.printWarning(1, routine, "Error loading output control file\n" + "\"" + currDir + File.separator + filename + "\"", this); Message.printWarning(2, routine, e); } JGUIUtil.setWaitCursor(this, false); } else if (action.Equals(__CHECKBOX_USE_ALL)) { // if the use all checkbox is selected, subtle changes from the // default functionality are made. The buttons to add and // delete rows are disabled, and the ID of the only record // in the worksheet is set to "All". This ID value is used // in the table model to determine when the checkbox is // selected. In addition, the ComboBox functionality of the // first and third data columns is turned off. if (__useAllJCheckBox.isSelected()) { __addRowButton.setEnabled(false); __deleteRowButton.setEnabled(false); __worksheet.setColumnJComboBoxValues(0, null); __worksheet.setColumnJComboBoxValues(2, null); __worksheet.clear(); StateMod_GraphNode g = new StateMod_GraphNode(); g.setID("All"); __worksheet.setCellEditable(0, 0, false); __worksheet.setCellEditable(0, 1, false); __worksheet.setCellEditable(0, 2, false); __worksheet.addRow(g); } else { __addRowButton.setEnabled(true); __deleteRowButton.setEnabled(true); System.Collections.IList v = StateMod_Util.arrayToList(StateMod_GraphNode.node_types); v.Add("Other"); __worksheet.setColumnJComboBoxValues(0, v); __worksheet.clear(); System.Collections.IList offOn = new List <object>(); offOn.Add("Off"); offOn.Add("On"); __worksheet.setCellEditable(0, 0, true); __worksheet.setColumnJComboBoxValues(2, offOn); } } }