Java Code Examples for java.awt.FileDialog#show()

The following examples show how to use java.awt.FileDialog#show() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Ted.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void jMenuItem4ActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
    // Add your handling code here:
    FileDialog fileDialog = new FileDialog (this, "Open...", FileDialog.LOAD);
    fileDialog.show ();
    if (fileDialog.getFile () == null)
        return;
    fileName = fileDialog.getDirectory () + File.separator + fileDialog.getFile ();

    FileInputStream fis = null;
    String str = null;
    try {
        fis = new FileInputStream (fileName);
        int size = fis.available ();
        byte[] bytes = new byte [size];
        fis.read (bytes);
        str = new String (bytes);
    } catch (IOException e) {
    } finally {
        try {
            fis.close ();
        } catch (IOException e2) {
        }
    }

    if (str != null)
        textBox.setText (str);
}
 
Example 2
Source File: Ted.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void doSaveAs () {
    FileDialog fileDialog = new FileDialog (this, "Save As...", FileDialog.SAVE);
    fileDialog.show ();
    if (fileDialog.getFile () == null)
        return;
    fileName = fileDialog.getDirectory () + File.separator + fileDialog.getFile ();

    doSave (fileName);
}
 
Example 3
Source File: MiniEdit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Invoker for the saveas action */
public void saveAs() {
    Doc doc = getSelectedDoc();
    if (doc == null) {
        throw new NullPointerException ("no doc");
    }
    

    FileDialog fd = new FileDialog (MiniEdit.this, "Save as");
    fd.setMode(fd.SAVE);
    fd.show();
    if (fd.getFile() != null) {
        File nue = new File (fd.getDirectory() + fd.getFile());
        try {
            boolean success = nue.createNewFile();
            if (success) {
                FileWriter w = new FileWriter (nue);
                doc.getTextPane().write(w);
                file = nue;
                documentTabs.setTitleAt(documentTabs.getSelectedIndex(), nue.getName());
                documentTabs.setToolTipTextAt(documentTabs.getSelectedIndex(), nue.toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 4
Source File: Ted.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** This method is called when File -> Open menu item is invoked.
 * It displays a dialog to choose the file to be opened and edited.
 * @param evt ActionEvent instance passed from actionPerformed event.
 */
private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
    FileDialog fileDialog = new FileDialog(this, "Open...", FileDialog.LOAD);
    fileDialog.show();
    if (fileDialog.getFile() == null)
        return;
    fileName = fileDialog.getDirectory() + File.separator + fileDialog.getFile();

    FileInputStream fis = null;
    String str = null;
    try {
        fis = new FileInputStream(fileName);
        int size = fis.available();
        byte[] bytes = new byte [size];
        fis.read(bytes);
        str = new String(bytes);
    } catch (IOException e) {
    } finally {
        try {
            fis.close();
        } catch (IOException e2) {
        }
    }

    if (str != null)
        textBox.setText(str);
}
 
Example 5
Source File: Ted.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Asks for a file name. then saves the current content of editor pane to the file.
 */
private void doSaveAs() {
    FileDialog fileDialog = new FileDialog(this, "Save As...", FileDialog.SAVE);
    fileDialog.show();
    if (fileDialog.getFile() == null)
        return;
    fileName = fileDialog.getDirectory() + File.separator + fileDialog.getFile();

    doSave(fileName);
}
 
Example 6
Source File: rtest.java    From RDMP1 with GNU General Public License v2.0 5 votes vote down vote up
public String rChooseFile(Rengine re, int newFile) {
	FileDialog fd = new FileDialog(new Frame(),
			(newFile == 0) ? "Select a file" : "Select a new file",
			(newFile == 0) ? FileDialog.LOAD : FileDialog.SAVE);
	fd.show();
	String res = null;
	if (fd.getDirectory() != null)
		res = fd.getDirectory();
	if (fd.getFile() != null)
		res = (res == null) ? fd.getFile() : (res + fd.getFile());
	return res;
}
 
Example 7
Source File: Read.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
* Import to a jMusic score a standard MIDI file
* Assume the MIDI file name is the same as the score title with .mid appended
* prompt for a fileName
* @param Score
*/ 
public static void midi(Score score) {
    FileDialog fd = new FileDialog(new Frame(), 
                                   "Select a MIDI file to open.", 
                                   FileDialog.LOAD);
    fd.show();
    if (fd.getFile() != null) {
        Read.midi(score, fd.getDirectory() + fd.getFile());                
    }
}
 
Example 8
Source File: Read.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
* Import the xml file as a jMusic score.
* Prompt for a fileName
* @param Score
*/ 
public static void xml(Score score) {
    FileDialog fd = new FileDialog(new Frame(), 
            "Select a jMusic XML file to open.", 
            FileDialog.LOAD);
    fd.show();
    if (fd.getFile() != null) {
        Read.xml(score, fd.getDirectory() + fd.getFile());                
    }
}
 
Example 9
Source File: Write.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
* Save the jMusic score as a standard MIDI file
* Prompt user for a filename
* @param Score
*/ 
public static void midi(Score score) {
    FileDialog fd = new FileDialog(new Frame(), 
                                   "Save as a MIDI file ...", 
                                   FileDialog.SAVE);
    fd.setFile("jMusic_composition.mid");
    fd.show();
    if (fd.getFile() != null) {
        Write.midi(score, fd.getDirectory() + fd.getFile());                
    }
    
}
 
Example 10
Source File: Notate.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
* Dialog to import a MIDI file
*/
 public void openMidi() {
    Score s = new Score();
    FileDialog loadMidi = new FileDialog(this, "Select a MIDI file.", FileDialog.LOAD);
    loadMidi.setDirectory( lastDirectory );
    loadMidi.setFile( lastFileName );
    loadMidi.show();
    String fileName = loadMidi.getFile();
    if (fileName != null) {
        lastFileName = fileName;
        lastDirectory = loadMidi.getDirectory();                        
        Read.midi(s, lastDirectory + fileName);  
        setNewScore(s);
    }
}
 
Example 11
Source File: Notate.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Dialog to import a jm file
 */
 
 public void openJM() {
    FileDialog loadjm = new FileDialog(this, "Select a jm score file.", FileDialog.LOAD);
    loadjm.setDirectory( lastDirectory );
    loadjm.show();
    String fileName = loadjm.getFile();
    if (fileName != null) {
        Score s = new Score();
        lastDirectory = loadjm.getDirectory();  
        Read.jm(s, lastDirectory + fileName);
        setNewScore(s);
    }
}
 
Example 12
Source File: Notate.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Dialog to import a jm XML file
 */
 
 public void openJMXML() {
    FileDialog loadjmxml = new FileDialog(this, "Select a jMusic XML score file.", FileDialog.LOAD);
    loadjmxml.setDirectory( lastDirectory );
    loadjmxml.show();
    String fileName = loadjmxml.getFile();
    if (fileName != null) {
        Score s = new Score();
        lastDirectory = loadjmxml.getDirectory(); 
        Read.xml(s, lastDirectory + fileName);
        setNewScore(s);
    }
}
 
Example 13
Source File: Notate.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Dialog to save phrase as a MIDI file.
 */
public void saveMidi() {
    FileDialog fd = new FileDialog(this, "Save as a MIDI file...",FileDialog.SAVE);
            fd.show();
                        
    //write a MIDI file and stave properties to disk
    if ( fd.getFile() != null) {
        Write.midi(score, fd.getDirectory()+fd.getFile());
        /*
        for(int i=0; i<staveArray.length; i++){
            System.out.println(i);
            StavePhraseProperties props =
                new StavePhraseProperties(
                        staveArray[i], staveArray[i].getPhrase());
            try {    
                System.out.println("props");
                props.writeToFile(                                         
                    fd.getDirectory()+fd.getFile());   
            }
            catch ( Throwable e) {
                System.out.println(
                    "Error Saving Properties " +
                    e.getMessage() );                                                
            }
        } 
        */
                                          
    }
}
 
Example 14
Source File: Notate.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Dialog to save score as a jMusic serialized jm file.
 */
public void saveJM() {
    FileDialog fd = new FileDialog(this, "Save as a jm file...",FileDialog.SAVE);
            fd.show();
                        
    //write a MIDI file to disk
    if ( fd.getFile() != null) {
        Write.jm(score, fd.getDirectory()+fd.getFile());
    }
}
 
Example 15
Source File: Notate.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Dialog to save score as a jMusic XML file.
 */
public void saveJMXML() {
    FileDialog fd = new FileDialog(this, "Save as a jMusic XML file...",FileDialog.SAVE);
            fd.show();
                        
    //write an XML file to disk
    if ( fd.getFile() != null) {
        Write.xml(score, fd.getDirectory()+fd.getFile());
    }
}
 
Example 16
Source File: Notate.java    From jmg with GNU General Public License v2.0 5 votes vote down vote up
/**
* Get the first phrase from a MIDI file.
*/
public Phrase readMidiPhrase() {
    FileDialog loadMidi = new FileDialog(this, "Select a MIDI file.", FileDialog.LOAD);
    loadMidi.show();
    String fileName = loadMidi.getFile();
    Phrase phr = new Phrase(0.0);
    Score scr = new Score();
    if (fileName != null) {
        Read.midi(scr, loadMidi.getDirectory() + fileName); 
    }
    scr.clean();
    if (scr.size() > 0 && scr.getPart(0).size() > 0) phr = scr.getPart(0).getPhrase(0);
    //System.out.println("Size = " + phr.size());
    return phr;
}