use of javax.swing.JFileChooser in project gephi by gephi.
the class ProjectControllerUIImpl method openFile.
@Override
public void openFile() {
final String LAST_PATH = "OpenFile_Last_Path";
final String LAST_PATH_DEFAULT = "OpenFile_Last_Path_Default";
//Get last directory
String lastPathDefault = NbPreferences.forModule(ProjectControllerUIImpl.class).get(LAST_PATH_DEFAULT, null);
String lastPath = NbPreferences.forModule(ProjectControllerUIImpl.class).get(LAST_PATH, lastPathDefault);
//Init dialog
final JFileChooser chooser = new JFileChooser(lastPath);
chooser.setMultiSelectionEnabled(true);
DialogFileFilter gephiFilter = new DialogFileFilter(NbBundle.getMessage(ProjectControllerUIImpl.class, "OpenProject_filechooser_filter"));
gephiFilter.addExtension(".gephi");
DialogFileFilter graphFilter = new DialogFileFilter(NbBundle.getMessage(getClass(), "OpenFile_filechooser_graphfilter"));
graphFilter.addExtension(".gephi");
ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
for (FileType fileType : importController.getImportController().getFileTypes()) {
DialogFileFilter dialogFileFilter = new DialogFileFilter(fileType.getName());
dialogFileFilter.addExtensions(fileType.getExtensions());
chooser.addChoosableFileFilter(dialogFileFilter);
graphFilter.addExtensions(fileType.getExtensions());
}
DialogFileFilter zipFileFilter = new DialogFileFilter(NbBundle.getMessage(getClass(), "OpenFile_filechooser_zipfilter"));
zipFileFilter.addExtensions(new String[] { ".zip", ".gz", ".bz2" });
chooser.addChoosableFileFilter(zipFileFilter);
chooser.addChoosableFileFilter(gephiFilter);
chooser.addChoosableFileFilter(graphFilter);
//Open dialog
int returnFile = chooser.showOpenDialog(null);
if (returnFile == JFileChooser.APPROVE_OPTION) {
File[] files = chooser.getSelectedFiles();
FileObject[] fileObjects = new FileObject[files.length];
int i = 0;
File gephiFile = null;
for (File file : files) {
file = FileUtil.normalizeFile(file);
FileObject fileObject = FileUtil.toFileObject(file);
fileObjects[i++] = fileObject;
if (fileObject.getExt().equalsIgnoreCase("gephi")) {
if (gephiFile != null) {
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(ProjectControllerUIImpl.class, "ProjectControllerUI.error.multipleGephi"), NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
return;
} else {
gephiFile = file;
}
}
//Save last path
NbPreferences.forModule(ProjectControllerUIImpl.class).put(LAST_PATH, file.getAbsolutePath());
}
if (gephiFile != null) {
//Project
if (controller.getCurrentProject() != null) {
if (!closeCurrentProject()) {
return;
}
}
try {
loadProject(gephiFile);
} catch (Exception ew) {
ew.printStackTrace();
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(ProjectControllerUIImpl.class, "OpenProject.defaulterror"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
} else {
//Import
importController.importFiles(fileObjects);
}
}
}
use of javax.swing.JFileChooser in project omegat by omegat-org.
the class AlignFilePickerController method chooseFile.
static File chooseFile(Component parent, String title, String dir) {
JFileChooser chooser = new JFileChooser(dir);
chooser.setDialogTitle(title);
chooser.setFileFilter(new FileFilter() {
@Override
public String getDescription() {
return OStrings.getString("ALIGNER_FILEPICKER_SUPPORTEDFILES");
}
@Override
public boolean accept(File f) {
return f.isDirectory() || Core.getFilterMaster().isFileSupported(f, true);
}
});
if (chooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
return chooser.getSelectedFile();
}
return null;
}
use of javax.swing.JFileChooser in project project1-ICS372 by sandip-rai.
the class FileAdapter method getPath.
/**
* Gets the path from the user for file importing and exporting.
*
* @param showSave the show save
* @return the path
*/
private String getPath(boolean showSave) {
JFileChooser fileChooser = new JFileChooser();
// Open the file selection dialog at the current project directory
fileChooser.setCurrentDirectory(new File("."));
if (showSave) {
fileChooser.showSaveDialog(null);
// Get the file
File selectedFile = fileChooser.getSelectedFile();
if (selectedFile != null) {
// Get the path
String filePath = selectedFile.getAbsolutePath();
return filePath;
}
} else {
int result = fileChooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
// Get the file
File selectedFile = fileChooser.getSelectedFile();
// Get the path
String filePath = selectedFile.getAbsolutePath();
return filePath;
}
}
return null;
}
use of javax.swing.JFileChooser in project Robot by fo0.
the class MainGUI method initialize.
/**
* Initialize the contents of the frame.
*/
private static void initialize() {
// create main frame
frame = new JFrame();
frame.setTitle("Robot v" + CONSTANTS.VERSION);
frame.getContentPane().setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// center frame on screen
frame.setSize(655, 528);
frame.setLocationRelativeTo(null);
frame.getContentPane().setBackground(Color.LIGHT_GRAY);
frame.setBackground(Color.LIGHT_GRAY);
frame.setResizable(false);
toggleConsole(currentMode);
JPanel panelTop = new JPanel();
panelTop.setBounds(0, 0, 653, 25);
frame.getContentPane().add(panelTop);
panelTop.setLayout(null);
JButton btnAdd = new JButton("ADD");
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new AddChainItemWindow();
}
});
btnAdd.setBounds(97, 0, 73, 24);
panelTop.add(btnAdd);
JButton btnDel = new JButton("DEL");
btnDel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int col = actionTable.getSelectedRow();
deleteItem(tableModel.getRow(col));
}
});
btnDel.setBounds(169, 0, 73, 24);
panelTop.add(btnDel);
JButton btnStart = new JButton("START");
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
new Thread(() -> {
SwingUtilities.invokeLater(() -> {
areaConsole.setText("");
areaChain.setText("");
});
SwingUtilities.invokeLater(() -> {
toggleConsole(EMode.Console);
});
Utils.sleep(TimeUnit.MILLISECONDS, 200);
// adding listener to receive events from backend
ControllerChain.getChain().addCmdListener((ctx, e) -> {
appendToChain(String.valueOf(e.getKey().getId()), e.getKey().getName(), e.getKey().getDescription(), e.getValue().getData().getState().getCmd().name());
});
// add listener for: Console output log
ControllerChain.getChain().getContext().addOutputListener(cli -> {
appendToConsole(cli);
});
Utils.sleep(TimeUnit.SECONDS, 1);
ControllerChain.getChain().start();
}).start();
}
});
btnStart.setBounds(0, 0, 98, 24);
panelTop.add(btnStart);
JButton buttonToggleConsole = new JButton(">_");
buttonToggleConsole.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (currentMode == EMode.Console) {
toggleConsole(EMode.Normal);
} else {
toggleConsole(EMode.Console);
}
}
});
buttonToggleConsole.setBounds(580, 0, 73, 24);
panelTop.add(buttonToggleConsole);
ErrorMode errMode = ErrorMode.FailOnErr;
if (Controller.getConfig().ignoreErrors)
errMode = ErrorMode.NotFailOnErr;
JButton btnTgleErrors = new JButton(errMode.name());
btnTgleErrors.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (btnTgleErrors.getText().equals(ErrorMode.FailOnErr.name())) {
Controller.getConfig().ignoreErrors = true;
btnTgleErrors.setText(ErrorMode.NotFailOnErr.name());
} else {
Controller.getConfig().ignoreErrors = false;
btnTgleErrors.setText(ErrorMode.FailOnErr.name());
}
}
});
btnTgleErrors.setBounds(453, 0, 105, 24);
panelTop.add(btnTgleErrors);
JPanel panelTable = new JPanel();
panelTable.setBounds(0, 26, 653, 265);
frame.getContentPane().add(panelTable);
panelTable.setLayout(new CardLayout(0, 0));
actionTable = new JTable();
actionTable.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2) {
JTable table = (JTable) e.getSource();
Point point = e.getPoint();
int row = table.rowAtPoint(point);
ActionItem item = tableModel.getRow(row);
new AddChainItemWindow(item);
}
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
});
tableModel = new BeanTableModelAction();
actionTable.setModel(tableModel);
JScrollPane scrollPaneTable = new JScrollPane(actionTable);
panelTable.add(scrollPaneTable, "name_7985051461163");
JPanel panelChain = new JPanel();
panelChain.setBounds(0, 292, 248, 188);
frame.getContentPane().add(panelChain);
panelChain.setLayout(new CardLayout(0, 0));
areaChain = new JTextArea();
areaChain.setEditable(false);
JScrollPane scrollPaneChain = new JScrollPane(areaChain);
// scrollPaneChain.getVerticalScrollBar().addAdjustmentListener(e -> {
// e.getAdjustable().setValue(e.getAdjustable().getMaximum());
// });
panelChain.add(scrollPaneChain, "name_1466312782685");
JPanel panelConsole = new JPanel();
panelConsole.setBounds(248, 292, 405, 188);
frame.getContentPane().add(panelConsole);
panelConsole.setLayout(new CardLayout(0, 0));
JScrollPane scrollPaneConsole = new JScrollPane((Component) null);
// scrollPaneConsole.getVerticalScrollBar().addAdjustmentListener(e -> {
// e.getAdjustable().setValue(e.getAdjustable().getMaximum());
// });
panelConsole.add(scrollPaneConsole, "name_2349855873542");
areaConsole = new JTextArea();
areaConsole.setEditable(false);
scrollPaneConsole.setViewportView(areaConsole);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu mnConfig = new JMenu("Config");
menuBar.add(mnConfig);
JMenuItem mntmConfigLoad = new JMenuItem("Load");
mntmConfigLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Robot", "robot");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
// load config from disk -> file
ControllerChain.getChain().getContext().load(file.getAbsolutePath());
MainGUI.getTableModel().loadActionContextFromController();
}
}
});
mnConfig.add(mntmConfigLoad);
JMenuItem mntmConfigSave = new JMenuItem("Save");
mntmConfigSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Robot", "robot");
chooser.setFileFilter(filter);
int returnVal = chooser.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
if (!file.getName().endsWith(".robot")) {
Logger.info("detected missing file extension, appending .robot to file");
File tmpFile = new File(file.getAbsolutePath() + ".robot");
file.renameTo(tmpFile);
file = tmpFile;
}
// save config to disk -> file
ControllerChain.getChain().getContext().save(file.getAbsolutePath());
}
}
});
mnConfig.add(mntmConfigSave);
JMenu mnHelp = new JMenu("Help");
menuBar.add(mnHelp);
JMenuItem mntmHelpAbout = new JMenuItem("About");
mntmHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
mnHelp.add(mntmHelpAbout);
JMenuItem mntmHelpUpdate = new JMenuItem("Update");
mntmHelpUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new UpdateWindow();
}
});
mnHelp.add(mntmHelpUpdate);
refreshTable();
}
use of javax.swing.JFileChooser in project gdx-skineditor by cobolfoo.
the class MenuBar method showExportDialog.
/*
* Show export dialog
*/
protected void showExportDialog() {
final Preferences prefs = Gdx.app.getPreferences("skin_editor_project_" + game.screenMain.getcurrentProject());
final TextField textDirectory = new TextField(prefs.getString("export_to_directory"), game.skin);
Dialog dlg = new Dialog("Export to Directory", game.skin) {
@Override
protected void result(Object object) {
if ((Boolean) object == true) {
if (textDirectory.getText().isEmpty() == true) {
game.showNotice("Warning", "Directory field is empty!", game.screenMain.stage);
return;
}
FileHandle targetDirectory = new FileHandle(textDirectory.getText());
if (targetDirectory.exists() == false) {
game.showNotice("Warning", "Directory not found!", game.screenMain.stage);
return;
}
// Copy uiskin.* and *.fnt
FileHandle projectFolder = Gdx.files.local("projects").child(game.screenMain.getcurrentProject());
for (FileHandle file : projectFolder.list()) {
if (file.name().startsWith("uiskin.") || (file.extension().equalsIgnoreCase("fnt"))) {
Gdx.app.log("MenuBar", "Copying file: " + file.name() + " ...");
FileHandle target = targetDirectory.child(file.name());
file.copyTo(target);
}
}
game.showNotice("Operation Completed", "Project successfully exported!", game.screenMain.stage);
}
}
};
dlg.pad(20);
Table table = dlg.getContentTable();
table.padTop(20);
table.add("Directory:");
table.add(textDirectory).width(320);
TextButton buttonChoose = new TextButton("...", game.skin);
buttonChoose.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
// Need to steal focus first with this hack (Thanks to Z-Man)
Frame frame = new Frame();
frame.setUndecorated(true);
frame.setOpacity(0);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.toFront();
frame.setVisible(false);
frame.dispose();
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int ret = chooser.showOpenDialog(null);
if (ret == JFileChooser.APPROVE_OPTION) {
File f = chooser.getSelectedFile();
textDirectory.setText(f.getAbsolutePath());
// Store to file
prefs.putString("export_to_directory", f.getAbsolutePath());
prefs.flush();
}
}
});
table.add(buttonChoose);
table.row();
table.padBottom(20);
dlg.button("Export", true);
dlg.button("Cancel", false);
dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
dlg.show(getStage());
}
Aggregations