Esempio n. 1
0
        }         //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