-
-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the file dialog for Linux and started migrating other dialogs. (#…
- Loading branch information
Showing
9 changed files
with
233 additions
and
74 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
ugs-core/src/com/willwinder/universalgcodesender/uielements/FileDialogBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
Copyright 2024 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.universalgcodesender.uielements; | ||
|
||
import com.willwinder.universalgcodesender.uielements.helpers.FilenameFilterAdapter; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import javax.swing.filechooser.FileFilter; | ||
import java.awt.FileDialog; | ||
import java.awt.Frame; | ||
import java.io.File; | ||
import java.util.Optional; | ||
|
||
/** | ||
* A generic file dialog base | ||
*/ | ||
public class FileDialogBase extends FileDialog { | ||
|
||
public FileDialogBase(String directory) { | ||
super((Frame) null); | ||
|
||
File directoryFile = new File(directory); | ||
if (directoryFile.isFile()) { | ||
directory = directoryFile.getParent(); | ||
} | ||
setDirectory(directory); | ||
} | ||
|
||
@Override | ||
public void setVisible(boolean visible) { | ||
super.setVisible(visible); | ||
setModal(true); | ||
requestFocus(); | ||
} | ||
|
||
/** | ||
* Returns the selected file or an empty optional | ||
* | ||
* @return the selected file | ||
*/ | ||
public Optional<File> getSelectedFile() { | ||
String file = getFile(); | ||
if (StringUtils.isEmpty(file)) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of(new File(getDirectory() + File.separatorChar + getFile())); | ||
} | ||
|
||
/** | ||
* Sets a file filter | ||
* | ||
* @param fileFilter the file filter | ||
*/ | ||
public void setFileFilter(FileFilter fileFilter) { | ||
setFilenameFilter(new FilenameFilterAdapter(fileFilter)); | ||
} | ||
|
||
/** | ||
* Sets the selected file | ||
* | ||
* @param file the selected file | ||
*/ | ||
public void setSelectedFile(File file) { | ||
setDirectory(file.getParent()); | ||
setFile(file.getName()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
ugs-core/src/com/willwinder/universalgcodesender/uielements/FileOpenDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright 2024 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.universalgcodesender.uielements; | ||
|
||
import java.awt.FileDialog; | ||
|
||
public class FileOpenDialog extends FileDialogBase { | ||
public FileOpenDialog(String directory) { | ||
super(directory); | ||
setMode(FileDialog.LOAD); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
ugs-core/src/com/willwinder/universalgcodesender/uielements/FileSaveDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright 2024 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.universalgcodesender.uielements; | ||
|
||
import java.awt.FileDialog; | ||
|
||
public class FileSaveDialog extends FileDialogBase { | ||
public FileSaveDialog(String directory) { | ||
super(directory); | ||
setMode(FileDialog.SAVE); | ||
} | ||
|
||
public FileSaveDialog() { | ||
this(""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ore/src/com/willwinder/universalgcodesender/uielements/helpers/FilenameFilterAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright 2024 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.universalgcodesender.uielements.helpers; | ||
|
||
import org.apache.commons.io.filefilter.IOFileFilter; | ||
|
||
import javax.swing.filechooser.FileFilter; | ||
import java.io.File; | ||
|
||
/** | ||
* A file filter adapter to be used together with apache commons | ||
* | ||
* @author Joacim Breiler | ||
*/ | ||
public class FilenameFilterAdapter implements IOFileFilter { | ||
|
||
private final FileFilter fileFilter; | ||
|
||
public FilenameFilterAdapter(FileFilter fileFilter) { | ||
this.fileFilter = fileFilter; | ||
} | ||
|
||
@Override | ||
public boolean accept(File file) { | ||
return fileFilter.accept(file); | ||
} | ||
|
||
@Override | ||
public boolean accept(File dir, String name) { | ||
return fileFilter.accept(new File(dir.getAbsolutePath() + File.separatorChar + name)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.