use of javax.swing.JFileChooser in project openblocks by mikaelhg.
the class CFileHandler method writeToFile.
public static boolean writeToFile(JComponent parent, String source) {
JFileChooser fc = new JFileChooser("Saving Data");
int returnVal = fc.showSaveDialog(parent.getTopLevelAncestor());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File f = fc.getSelectedFile();
new CProgressBar("Saving Data to " + f.getName());
try {
if (f.getPath().length() > 4) {
String extension = f.getPath().substring(f.getPath().length() - 4, f.getPath().length());
if (extension.equals(".csv")) {
System.out.println("Saving with default extension: " + extension);
//do nothing
} else {
System.out.println("Generating extension: " + extension);
f = new File(f.getPath() + ".csv");
}
} else {
System.out.println("Filename too short");
f = new File(f.getPath() + ".csv");
}
Writer output = null;
output = new BufferedWriter(new FileWriter(f));
output.write(source);
output.close();
return true;
} catch (IOException io) {
return false;
}
}
return false;
}
use of javax.swing.JFileChooser in project openblocks by mikaelhg.
the class CFileHandler method writeToFile.
public static boolean writeToFile(JComponent parent, BufferedImage image) {
JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(parent.getTopLevelAncestor());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File f = fc.getSelectedFile();
new CProgressBar("Saving Graph to " + f.getName());
try {
if (f.getPath().length() > 4) {
String extension = f.getPath().substring(f.getPath().length() - 4, f.getPath().length());
String extension2 = f.getPath().substring(f.getPath().length() - 5, f.getPath().length());
if (extension.equals(".jpg") || extension.equals(".gif") || extension.equals(".tif") || extension.equals(".png") || extension2.equals(".jpeg") || extension2.equals(".tiff")) {
System.out.println("Saving with default extension: " + extension);
//do nothing
} else {
System.out.println("Generating extension: " + extension);
f = new File(f.getPath() + ".jpg");
}
} else {
System.out.println("Filename too short");
f = new File(f.getPath() + ".jpg");
}
ImageIO.write(image, "jpg", f);
return true;
} catch (IOException io) {
return false;
}
}
return false;
}
use of javax.swing.JFileChooser in project javatari by ppeccin.
the class FileROMChooser method createChooser.
private static synchronized void createChooser() throws AccessControlException {
if (chooser != null)
return;
chooser = new JFileChooser();
chooser.setPreferredSize(new Dimension(580, 400));
}
use of javax.swing.JFileChooser in project hid-serial by rayshobby.
the class G4P method selectImpl.
/**
* The implementation of the select input and output methods.
* @param prompt
* @param mode
* @param types
* @param typeDesc
* @return the absolute path name for the selected folder, or null if action
* cancelled.
*/
private static String selectImpl(String prompt, int mode, String types, String typeDesc) {
// If no initial selection made then use last selection
// Assume that a file will not be selected
String selectedFile = null;
// Get the owner
Frame owner = (sketchApplet == null) ? null : sketchApplet.frame;
// Create a file filter
if (PApplet.useNativeSelect) {
FileDialog dialog = new FileDialog(owner, prompt, mode);
FilenameFilter filter = null;
if (types != null && types.length() > 0) {
filter = new FilenameChooserFilter(types);
dialog.setFilenameFilter(filter);
}
dialog.setVisible(true);
String directory = dialog.getDirectory();
if (directory != null) {
selectedFile = dialog.getFile();
if (selectedFile != null) {
try {
selectedFile = (new File(directory, selectedFile)).getCanonicalPath();
} catch (IOException e) {
selectedFile = null;
}
}
}
} else {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(prompt);
FileFilter filter = null;
if (types != null && types.length() > 0) {
filter = new FileChooserFilter(types, typeDesc);
chooser.setFileFilter(filter);
}
int result = JFileChooser.ERROR_OPTION;
if (mode == FileDialog.SAVE) {
result = chooser.showSaveDialog(owner);
} else if (mode == FileDialog.LOAD) {
result = chooser.showOpenDialog(owner);
}
if (result == JFileChooser.APPROVE_OPTION) {
try {
selectedFile = chooser.getSelectedFile().getCanonicalPath();
} catch (IOException e) {
selectedFile = null;
}
}
}
return selectedFile;
}
use of javax.swing.JFileChooser in project lombok by rzwitserloot.
the class InstallerGUI method buildIdeArea.
private Component buildIdeArea() {
JPanel container = new JPanel();
container.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.WEST;
constraints.insets = new Insets(8, 0, 0, 16);
container.add(new JLabel(IDE_TITLE), constraints);
constraints.gridy = 1;
container.add(new JLabel(IDE_EXPLANATION), constraints);
constraints.gridy = 2;
loadingExpl = Box.createHorizontalBox();
loadingExpl.add(new JLabel(new ImageIcon(Installer.class.getResource("loading.gif"))));
loadingExpl.add(new JLabel(IDE_LOADING_EXPLANATION));
container.add(loadingExpl, constraints);
constraints.weightx = 1.0;
constraints.gridy = 3;
constraints.fill = GridBagConstraints.HORIZONTAL;
idesList = new IdesList();
JScrollPane idesListScroll = new JScrollPane(idesList);
idesListScroll.setBackground(Color.WHITE);
idesListScroll.getViewport().setBackground(Color.WHITE);
container.add(idesListScroll, constraints);
Thread findIdesThread = new Thread() {
@Override
public void run() {
try {
final List<IdeLocation> locations = new ArrayList<IdeLocation>();
final List<CorruptedIdeLocationException> problems = new ArrayList<CorruptedIdeLocationException>();
Installer.autoDiscover(locations, problems);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (IdeLocation location : locations) {
try {
idesList.addLocation(location);
} catch (Throwable t) {
handleException(t);
}
}
for (CorruptedIdeLocationException problem : problems) {
problem.showDialog(appWindow);
}
loadingExpl.setVisible(false);
if (locations.size() + problems.size() == 0) {
JOptionPane.showMessageDialog(appWindow, "I can't find any IDEs on your computer.\n" + "If you have IDEs installed on this computer, please use the " + "'Specify Location...' button to manually point out the \n" + "location of your IDE installation to me. Thanks!", "Can't find IDE", JOptionPane.INFORMATION_MESSAGE);
}
}
});
} catch (Throwable t) {
handleException(t);
}
}
};
findIdesThread.start();
Box buttonBar = Box.createHorizontalBox();
JButton specifyIdeLocationButton = new JButton("Specify location...");
buttonBar.add(specifyIdeLocationButton);
specifyIdeLocationButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
final List<Pattern> exeNames = Installer.getIdeExecutableNames();
String file = null;
if (OsUtils.getOS() == OS.MAC_OS_X) {
FileDialog chooser = new FileDialog(appWindow);
chooser.setMode(FileDialog.LOAD);
chooser.setFilenameFilter(new FilenameFilter() {
@Override
public boolean accept(File dir, String fileName) {
for (Pattern exeName : exeNames) if (exeName.matcher(fileName).matches())
return true;
return false;
}
});
chooser.setVisible(true);
if (chooser.getDirectory() != null && chooser.getFile() != null) {
file = new File(chooser.getDirectory(), chooser.getFile()).getAbsolutePath();
}
} else {
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
if (f.isDirectory())
return true;
for (Pattern exeName : exeNames) if (exeName.matcher(f.getName()).matches())
return true;
return false;
}
@Override
public String getDescription() {
return "IDE Installation";
}
});
switch(chooser.showDialog(appWindow, "Select")) {
case JFileChooser.APPROVE_OPTION:
file = chooser.getSelectedFile().getAbsolutePath();
}
}
if (file != null) {
try {
IdeLocation loc = Installer.tryAllProviders(file);
if (loc != null)
idesList.addLocation(loc);
else
JOptionPane.showMessageDialog(appWindow, "I can't find any IDE that lombok supports at location: " + file, "No IDE found", JOptionPane.WARNING_MESSAGE);
} catch (CorruptedIdeLocationException e) {
e.showDialog(appWindow);
} catch (Throwable t) {
handleException(t);
}
}
}
});
buttonBar.add(Box.createHorizontalGlue());
installButton = new JButton("Install / Update");
buttonBar.add(installButton);
installButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<IdeLocation> locationsToInstall = new ArrayList<IdeLocation>(idesList.getSelectedIdes());
if (locationsToInstall.isEmpty()) {
JOptionPane.showMessageDialog(appWindow, "You haven't selected any IDE installations!.", "No Selection", JOptionPane.WARNING_MESSAGE);
return;
}
install(locationsToInstall);
}
});
constraints.gridy = 4;
constraints.weightx = 0;
container.add(buttonBar, constraints);
constraints.gridy = 5;
constraints.fill = GridBagConstraints.NONE;
JHyperLink showMe = new JHyperLink("Show me what this installer will do to my IDE installation.");
container.add(showMe, constraints);
showMe.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showWhatIDo();
}
});
constraints.gridy = 6;
uninstallButton = new JHyperLink("Uninstall lombok from selected IDE installations.");
uninstallPlaceholder = new JLabel("<html> </html>");
uninstallButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<IdeLocation> locationsToUninstall = new ArrayList<IdeLocation>();
for (IdeLocation location : idesList.getSelectedIdes()) {
if (location.hasLombok())
locationsToUninstall.add(location);
}
if (locationsToUninstall.isEmpty()) {
JOptionPane.showMessageDialog(appWindow, "You haven't selected any IDE installations that have been lombok-enabled.", "No Selection", JOptionPane.WARNING_MESSAGE);
return;
}
uninstall(locationsToUninstall);
}
});
container.add(uninstallButton, constraints);
uninstallPlaceholder.setVisible(false);
container.add(uninstallPlaceholder, constraints);
container.setPreferredSize(new Dimension(INSTALLER_WINDOW_WIDTH, 296));
return container;
}
Aggregations