org.lwjgl.util.tinyfd.TinyFileDialogs Java Examples

The following examples show how to use org.lwjgl.util.tinyfd.TinyFileDialogs. 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: LWJGUIDialog.java    From LWJGUI with MIT License 6 votes vote down vote up
/**
 * Opens a file open dialog.
 * 
 * @param title window title
 * @param defaultPath default file path
 * @param filterDescription description of the accepted file extension(s)
 * @param acceptedFileExtension the first accepted file extension (example: "txt", use * for all)
 * @param additionalAcceptedFileExtensions any additional accepted file extensions
 * 
 * @return the selected file
 */
public static File showOpenFileDialog(String title, File defaultPath, String filterDescription, String acceptedFileExtension, String... additionalAcceptedFileExtensions){

	MemoryStack stack = MemoryStack.stackPush();

	PointerBuffer filters = stack.mallocPointer(1 + additionalAcceptedFileExtensions.length);

       filters.put(stack.UTF8("*." + acceptedFileExtension));
       for(int i = 0; i < additionalAcceptedFileExtensions.length; i++){
		filters.put(stack.UTF8("*." + additionalAcceptedFileExtensions[i]));
       }

       filters.flip();

       defaultPath = defaultPath.getAbsoluteFile();
       String defaultString = defaultPath.getAbsolutePath();
       if(defaultPath.isDirectory() && !defaultString.endsWith(File.separator)){
       	defaultString += File.separator;
       }
       
       String result = TinyFileDialogs.tinyfd_openFileDialog(title, defaultString, filters, filterDescription, false);

	stack.pop();

	return result != null ? new File(result) : null; 
}
 
Example #2
Source File: Installer.java    From skin-composer with MIT License 6 votes vote down vote up
@Override
public FileHandle selectFolder(String title, FileHandle defaultPath) {
    //fix file path characters
    String path = defaultPath.path().replace("/", "\\");
    
    String result = TinyFileDialogs.tinyfd_selectFolderDialog(title, path);
    
    return result == null ? null : Gdx.files.absolute(result);
}
 
Example #3
Source File: DesktopPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
//FIXME tinyfd_inputBox isn't a full solution for this. No support for multiline, looks ugly. Ideally we'd have an opengl-based input box
public void promptTextInput(String title, String hintText, int maxLen, boolean multiLine, String posTxt, String negTxt, TextCallback callback) {
	String result = TinyFileDialogs.tinyfd_inputBox(title, title, hintText);
	if (result == null){
		callback.onSelect(false, "");
	} else {
		if (result.contains("\r\n"))    result = result.substring(0, result.indexOf("\r\n"));
		if (result.contains("\n"))      result = result.substring(0, result.indexOf("\n"));
		if (result.length() > maxLen)   result = result.substring(0, maxLen);
		callback.onSelect(true, result.replace("\r\n", "").replace("\n", ""));
	}
}
 
Example #4
Source File: DesktopLauncher.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public static void main (String[] args) {

		if (!DesktopLaunchValidator.verifyValidJVMState(args)){
			return;
		}
		
		final String title;
		if (DesktopLauncher.class.getPackage().getSpecificationTitle() == null){
			title = System.getProperty("Specification-Title");
		} else {
			title = DesktopLauncher.class.getPackage().getSpecificationTitle();
		}
		
		Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
			@Override
			public void uncaughtException(Thread thread, Throwable throwable) {
				Game.reportException(throwable);
				StringWriter sw = new StringWriter();
				PrintWriter pw = new PrintWriter(sw);
				throwable.printStackTrace(pw);
				pw.flush();
				String exceptionMsg = sw.toString();

				//shorten/simplify exception message to make it easier to fit into a message box
				exceptionMsg = exceptionMsg.replaceAll("\\(.*:([0-9]*)\\)", "($1)");
				exceptionMsg = exceptionMsg.replace("com.shatteredpixel.shatteredpixeldungeon.", "");
				exceptionMsg = exceptionMsg.replace("com.watabou.", "");
				exceptionMsg = exceptionMsg.replace("com.badlogic.gdx.", "");
				exceptionMsg = exceptionMsg.replace("\t", "    ");

				TinyFileDialogs.tinyfd_messageBox(title + " Has Crashed!",
						title + " has run into an error it can't recover from and has crashed, sorry about that!\n\n" +
						"If you could, please email this error message to the developer ([email protected]):\n\n" +
						"version: " + Game.version + "\n" +
						exceptionMsg,
						"ok", "error", false );
				if (Gdx.app != null) Gdx.app.exit();
			}
		});
		
		Game.version = DesktopLauncher.class.getPackage().getSpecificationVersion();
		if (Game.version == null) {
			Game.version = System.getProperty("Specification-Version");
		}
		
		try {
			Game.versionCode = Integer.parseInt(DesktopLauncher.class.getPackage().getImplementationVersion());
		} catch (NumberFormatException e) {
			Game.versionCode = Integer.parseInt(System.getProperty("Implementation-Version"));
		}

		if (UpdateImpl.supportsUpdates()){
			Updates.service = UpdateImpl.getUpdateService();
		}
		
		Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
		
		config.setTitle( title );
		
		String basePath = "";
		if (SharedLibraryLoader.isWindows) {
			if (System.getProperties().getProperty("os.name").equals("Windows XP")) {
				basePath = "Application Data/.shatteredpixel/Shattered Pixel Dungeon/";
			} else {
				basePath = "AppData/Roaming/.shatteredpixel/Shattered Pixel Dungeon/";
			}
		} else if (SharedLibraryLoader.isMac) {
			basePath = "Library/Application Support/Shattered Pixel Dungeon/";
		} else if (SharedLibraryLoader.isLinux) {
			basePath = ".shatteredpixel/shattered-pixel-dungeon/";
		}

		//copy over prefs from old file location from legacy desktop codebase
		FileHandle oldPrefs = new Lwjgl3FileHandle(basePath + "pd-prefs", Files.FileType.External);
		FileHandle newPrefs = new Lwjgl3FileHandle(basePath + SPDSettings.DEFAULT_PREFS_FILE, Files.FileType.External);
		if (oldPrefs.exists() && !newPrefs.exists()){
			oldPrefs.copyTo(newPrefs);
		}

		config.setPreferencesConfig( basePath, Files.FileType.External );
		SPDSettings.set( new Lwjgl3Preferences( SPDSettings.DEFAULT_PREFS_FILE, basePath) );
		FileUtils.setDefaultFileProperties( Files.FileType.External, basePath );
		
		config.setWindowSizeLimits( 480, 320, -1, -1 );
		Point p = SPDSettings.windowResolution();
		config.setWindowedMode( p.x, p.y );
		config.setAutoIconify( true );
		
		//we set fullscreen/maximized in the listener as doing it through the config seems to be buggy
		DesktopWindowListener listener = new DesktopWindowListener();
		config.setWindowListener( listener );
		
		config.setWindowIcon("icons/icon_16.png", "icons/icon_32.png", "icons/icon_64.png",
				"icons/icon_128.png", "icons/icon_256.png");

		new Lwjgl3Application(new ShatteredPixelDungeon(new DesktopPlatformSupport()), config);
	}
 
Example #5
Source File: LWJGUIDialog.java    From LWJGUI with MIT License 3 votes vote down vote up
/**
 * Opens a file save dialog.
 * 
 * @param title window title
 * @param defaultPath default file path
 * @param filterDescription description of the accepted file extension(s)
 * @param fileExtension the file extension (example: "txt")
 * @param forceExtension the user can select any file regardless of extension. If this is set to true, then the given extension will be automatically added if the extension is wrong.
 * 
 * @return the selected file
 */
public static File showSaveFileDialog(String title, File defaultPath, String filterDescription, String fileExtension, boolean forceExtension){

	MemoryStack stack = MemoryStack.stackPush();

	PointerBuffer filters = stack.mallocPointer(1);

       filters.put(stack.UTF8("*." + fileExtension)).flip();
       
       defaultPath = defaultPath.getAbsoluteFile();
       String defaultString = defaultPath.getAbsolutePath();
       if(defaultPath.isDirectory() && !defaultString.endsWith(File.separator)){
       	defaultString += File.separator;
       }

       //System.out.println(defaultString + " : exists: " + new File(defaultString).exists());
       
       String result = TinyFileDialogs.tinyfd_saveFileDialog(title, defaultString, filters, filterDescription);

       stack.pop();

       if(result == null){
       	return null;
       }
       
       if(forceExtension && !result.endsWith("." + fileExtension)){
       	result += "." + fileExtension;
       }

       return new File(result);
}
 
Example #6
Source File: LWJGUIDialog.java    From LWJGUI with MIT License 2 votes vote down vote up
/**
 * Shows a message dialog with the given window title and message.
 * 
 * @param title
 * @param message 
 */
public static void showMessageDialog(String title, String message, DialogIcon icon) {
	TinyFileDialogs.tinyfd_messageBox(title, message, DialogType.OK.key, icon.key, true);
}
 
Example #7
Source File: LWJGUIDialog.java    From LWJGUI with MIT License 2 votes vote down vote up
/**
 * Show a confirm dialog with the given settings.
 * 
 * @param title - window title
 * @param message - window message
 * @param type - confirm type (buttons used)
 * @param icon - window icon
 * @param defaultButtonIsOK - if true, the default button highlighted will be the "yes" button.
 * 
 * @return true if "yes" or an equivalent is selected.
 */
public static boolean showConfirmDialog(String title, String message, DialogType type, DialogIcon icon, boolean defaultButtonIsOK) {
	return TinyFileDialogs.tinyfd_messageBox(title, message, type.key, icon.key, defaultButtonIsOK);
}
 
Example #8
Source File: LWJGUIDialog.java    From LWJGUI with MIT License 2 votes vote down vote up
/**
 * Shows a dialog for selecting a folder. 
 * 
 * @param title - window title
 * @param defaultPath - default filepath to start from
 * 
	 * @return the selected folder path in a File object
 */
public static File showOpenFolderDialog(String title, File defaultPath){
       String result = TinyFileDialogs.tinyfd_selectFolderDialog(title, defaultPath.getAbsolutePath());
	return result != null ? new File(result) : null; 
}