use of java.awt.FileDialog in project chipKIT32-MAX by chipKIT32.
the class Archiver method run.
public void run() {
Sketch sketch = editor.getSketch();
// first save the sketch so that things don't archive strangely
boolean success = false;
try {
success = sketch.save();
} catch (Exception e) {
e.printStackTrace();
}
if (!success) {
Base.showWarning("Couldn't archive sketch", "Archiving the sketch has been canceled because\n" + "the sketch couldn't save properly.", null);
return;
}
File location = sketch.getFolder();
String name = location.getName();
File parent = new File(location.getParent());
//System.out.println("loc " + location);
//System.out.println("par " + parent);
File newbie = null;
String namely = null;
int index = 0;
do {
// only use the date if the sketch name isn't the default name
useDate = !name.startsWith("sketch_");
if (useDate) {
String purty = dateFormat.format(new Date());
String stamp = purty + ((char) ('a' + index));
namely = name + "-" + stamp;
newbie = new File(parent, namely + ".zip");
} else {
String diggie = numberFormat.format(index + 1);
namely = name + "-" + diggie;
newbie = new File(parent, namely + ".zip");
}
index++;
} while (newbie.exists());
// open up a prompt for where to save this fella
FileDialog fd = new FileDialog(editor, "Archive sketch as:", FileDialog.SAVE);
fd.setDirectory(parent.getAbsolutePath());
fd.setFile(newbie.getName());
fd.setVisible(true);
String directory = fd.getDirectory();
String filename = fd.getFile();
// only write the file if not canceled
if (filename != null) {
newbie = new File(directory, filename);
try {
//System.out.println(newbie);
FileOutputStream zipOutputFile = new FileOutputStream(newbie);
ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
// recursively fill the zip file
buildZip(location, name, zos);
// close up the jar file
zos.flush();
zos.close();
editor.statusNotice("Created archive " + newbie.getName() + ".");
} catch (IOException e) {
e.printStackTrace();
}
} else {
editor.statusNotice("Archive sketch canceled.");
}
}
use of java.awt.FileDialog in project processdash by dtuma.
the class ManualExportDialog method actionPerformed.
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
FileDialog fd;
String lastFile, lastDir;
boolean fail = false;
if (cmd.equals("XData")) {
operation = X_DATA;
} else if (cmd.equals("XList")) {
operation = X_LIST;
} else if (cmd.equals("Close")) {
setVisible(false);
} else if (cmd.equals("Apply")) {
DefaultMutableTreeNode dmn;
Vector v = tree.getSelectedPaths();
switch(operation) {
case X_DATA:
// Perform operation (filter TBD)
// export the data
// use file dialog to get file name/loc?
// (extend file dialog class to add more functionality/options?)
fd = new FileDialog(parent, resource.getString("ExportDataTo"), FileDialog.SAVE);
// fd.setDirectory ("");
fd.setFile("dash.txt");
fd.show();
lastDir = fd.getDirectory();
lastFile = fd.getFile();
if (lastFile != null)
exportInteractively(v, new File(lastDir, lastFile));
break;
case X_LIST:
// Perform operation (filter TBD)
// export the hierarchy
// use file dialog to get file name/loc?
// (extend file dialog class to add more functionality/options?)
fd = new FileDialog(parent, resource.getString("ExportHierarchyTo"), FileDialog.SAVE);
// fd.setDirectory ("");
fd.setFile("hierarch.txt");
fd.show();
lastFile = fd.getFile();
if (lastFile != null) {
JDialog working;
working = new JDialog(parent, resource.getString("ExportExportingDots"));
working.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
JLabel lab = new JLabel(resource.getString("ExportExportingMessage"));
working.getContentPane().add(lab, "Center");
working.pack();
working.show();
Thread.yield();
lastDir = fd.getDirectory();
try {
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(lastDir + FILE_SEP + lastFile)));
parent.getHierarchy().orderedDump(out, v);
out.close();
} catch (IOException ioe) {
fail = true;
System.out.println("IOException: " + e);
}
;
lab.setText(resource.getString("ExportComplete"));
working.invalidate();
}
break;
}
}
}
use of java.awt.FileDialog in project jdk8u_jdk by JetBrains.
the class FileDialogForDirectories method init.
@Override
public void init() {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
Sysout.createDialogWithInstructions(new String[] { "Press PASS, this test is for MacOS X only." });
return;
}
System.setProperty("apple.awt.fileDialogForDirectories", "true");
setLayout(new GridLayout(1, 1));
fd = new FileDialog(new Frame(), "Open");
showBtn = new Button("Show File Dialog");
showBtn.addActionListener(this);
add(showBtn);
String[] instructions = { "1) Click on 'Show File Dialog' button. A file dialog will come up.", "2) Check that files can't be selected.", "3) Check that directories can be selected.", "4) Repeat steps 1 - 3 a few times for different files and directories.", "5) If it's true then the test passed, otherwise it failed." };
Sysout.createDialogWithInstructions(instructions);
}
use of java.awt.FileDialog in project megameklab by MegaMek.
the class MenuBarCreator method jMenuInsertImageFile_actionPerformed.
private void jMenuInsertImageFile_actionPerformed() {
String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
File unitFile = new File(filePathName);
JFileChooser f = new JFileChooser(filePathName);
f.setLocation(parentFrame.getLocation().x + 150, parentFrame.getLocation().y + 100);
f.setDialogTitle("Load Mech");
f.setDialogType(JFileChooser.OPEN_DIALOG);
f.setMultiSelectionEnabled(false);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf", "hmp");
// Add a filter for mul files
f.setFileFilter(filter);
int returnVal = f.showOpenDialog(parentFrame);
if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
// I want a file, y'know!
return;
}
unitFile = f.getSelectedFile();
try {
Entity tempEntity = new MechFileParser(unitFile).getEntity();
if (UnitUtil.validateUnit(parentFrame.getEntity()).trim().length() > 0) {
JOptionPane.showMessageDialog(parentFrame, "Warning:Invalid unit, it might load incorrectly!");
}
FileDialog fDialog = new FileDialog(parentFrame, "Image Path", FileDialog.LOAD);
if (parentFrame.getEntity().getFluff().getMMLImagePath().trim().length() > 0) {
String fullPath = new File(parentFrame.getEntity().getFluff().getMMLImagePath()).getAbsolutePath();
String imageName = fullPath.substring(fullPath.lastIndexOf(File.separatorChar) + 1);
fullPath = fullPath.substring(0, fullPath.lastIndexOf(File.separatorChar) + 1);
fDialog.setDirectory(fullPath);
fDialog.setFile(imageName);
} else {
fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + "mech" + File.separatorChar);
fDialog.setFile(parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel() + ".png");
}
fDialog.setLocationRelativeTo(parentFrame);
fDialog.setVisible(true);
if (fDialog.getFile() != null) {
String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath();
relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir").toString()).getAbsolutePath().length() + 1);
parentFrame.getEntity().getFluff().setMMLImagePath(relativeFilePath);
BLKFile.encode(unitFile.getAbsolutePath(), tempEntity);
}
} catch (Exception ex) {
}
return;
}
use of java.awt.FileDialog in project megameklab by MegaMek.
the class MenuBarCreator method jMenuExportEntityText_actionPerformed.
public void jMenuExportEntityText_actionPerformed(ActionEvent event) {
if (UnitUtil.validateUnit(parentFrame.getEntity()).length() > 0) {
JOptionPane.showMessageDialog(parentFrame, "Warning: exporting an invalid unit!");
}
String unitName = parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel();
MechView mview = new MechView(parentFrame.getEntity(), true, true, false);
FileDialog fDialog = new FileDialog(parentFrame, "Save As", FileDialog.SAVE);
String filePathName = new File(System.getProperty("user.dir").toString()).getAbsolutePath();
fDialog.setDirectory(filePathName);
fDialog.setFile(unitName + ".txt");
fDialog.setLocationRelativeTo(parentFrame);
fDialog.setVisible(true);
if (fDialog.getFile() != null) {
filePathName = fDialog.getDirectory() + fDialog.getFile();
} else {
return;
}
try {
FileOutputStream out = new FileOutputStream(filePathName);
PrintStream p = new PrintStream(out);
p.println(mview.getMechReadout());
p.close();
out.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
Aggregations