Java Code Examples for com.badlogic.gdx.files.FileHandle#equals()

The following examples show how to use com.badlogic.gdx.files.FileHandle#equals() . 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: ModelUtils.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Changes file path for {@link InputFile} instance.
 * Since all {@link InputFile}'s are unique by file withing {@link PackModel}, the only way to change file reference is to recreate {@link InputFile} properly.
 * @return Newly created {@link InputFile} instance that has replaced old one. May be null in case {@link InputFile} entry with that file already exist.
 */
public InputFile changeInputFileHandle(PackModel pack, InputFile inputFile, FileHandle file) {
    ensurePackExists(pack);

    if (file.equals(inputFile.getFileHandle())) return inputFile;

    InputFile newInputFile = new InputFile(file, inputFile.getType());
    newInputFile.setDirFilePrefix(inputFile.getDirFilePrefix());
    newInputFile.setRegionName(inputFile.getRegionName());

    if (pack.getInputFiles().contains(newInputFile, false)) {
        Gdx.app.error(TAG, "Pack: " + pack + " already contains input file entry for " + file);
        return null;
    }

    pack.removeInputFile(inputFile);
    pack.addInputFile(newInputFile);

    return newInputFile;
}
 
Example 2
Source File: MainController.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
private void updateRecentProjects() {
    Array<FileHandle> recentProjects = this.recentProjects.getRecentProjects();
    actorsFileMenu.miOpenRecent.setDisabled(recentProjects.size == 0);
    actorsFileMenu.pmOpenRecent.clear();
    for (final FileHandle file : recentProjects) {
        if (file.equals(getProject().getProjectFile())) continue;

        MenuItem menuItem = new MenuItem(file.nameWithoutExtension());
        menuItem.setShortcut(CommonUtils.ellipsize(file.path(), 72)); // Will use shortcut label to display file path
        menuItem.getShortcutCell().left().expandX();
        menuItem.getLabelCell().expand(false, false).left();
        menuItem.getImageCell().width(0); // Shrink image cell to zero, we don't need it
        menuItem.pack();
        menuItem.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                Gdx.app.postRunnable(new Runnable() {
                    @Override
                    public void run() {
                        final ProjectModel project = projectSerializer.loadProject(file);
                        if (project != null) {
                            globalActions.commonDialogs.checkUnsavedChanges(new Runnable() {
                                @Override
                                public void run() {
                                    modelService.setProject(project);
                                }
                            });
                        }
                    }
                });
            }
        });
        actorsFileMenu.pmOpenRecent.addItem(menuItem);
    }
}
 
Example 3
Source File: FileChooser.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/**
 * Changes file chooser active directory.
 * Warning: To avoid hanging listing directory is performed asynchronously. In case of passing invalid file handle
 * file chooser will fallback to default one.
 */
@Override
public void setDirectory (FileHandle directory, HistoryPolicy historyPolicy) {
	if (directory.equals(currentDirectory)) return;
	if (historyPolicy == HistoryPolicy.ADD) historyManager.historyAdd();

	currentDirectory = directory;
	iconProvider.directoryChanged(directory);

	rebuildFileList();

	if (historyPolicy == HistoryPolicy.CLEAR) historyManager.historyClear();

	updateFavoriteFolderButton();
}