mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
preparing for the release of 3.32
This commit is contained in:
@@ -2,7 +2,6 @@ package org.diylc;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@@ -95,16 +94,6 @@ public class DIYLCStarter {
|
|||||||
LOG.error("Could not read config.properties file", e);
|
LOG.error("Could not read config.properties file", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// batch convert old format to new
|
|
||||||
// File dir = new File("c:\\Users\\bancika\\Downloads\\layouts_v1\\MarkM");
|
|
||||||
// File[] matchingFiles = dir.listFiles(new FilenameFilter() {
|
|
||||||
// public boolean accept(File dir, String name) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// for (File file : matchingFiles) {
|
|
||||||
// mainFrame.getPresenter().loadProjectFromFile(file.getAbsolutePath());
|
|
||||||
// mainFrame.getPresenter().saveProjectToFile(file.getParentFile().getAbsolutePath() + "\\converted\\" + file.getName(), false);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class DialogFactory {
|
|||||||
public File showOpenDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
|
public File showOpenDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
|
||||||
IFileChooserAccessory accessory) {
|
IFileChooserAccessory accessory) {
|
||||||
JFileChooser openFileChooser = new JFileChooser();
|
JFileChooser openFileChooser = new JFileChooser();
|
||||||
initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory);
|
initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory, false);
|
||||||
|
|
||||||
int result = openFileChooser.showOpenDialog(mainFrame);
|
int result = openFileChooser.showOpenDialog(mainFrame);
|
||||||
|
|
||||||
@@ -84,17 +84,27 @@ public class DialogFactory {
|
|||||||
public File showOpenDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
|
public File showOpenDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
|
||||||
IFileChooserAccessory accessory, JFrame ownerFrame) {
|
IFileChooserAccessory accessory, JFrame ownerFrame) {
|
||||||
JFileChooser openFileChooser = new JFileChooser();
|
JFileChooser openFileChooser = new JFileChooser();
|
||||||
initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory);
|
initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory, false);
|
||||||
|
|
||||||
int result = openFileChooser.showOpenDialog(ownerFrame);
|
int result = openFileChooser.showOpenDialog(ownerFrame);
|
||||||
|
|
||||||
return processFileChooserResult(result, openFileChooser, defaultExtension);
|
return processFileChooserResult(result, openFileChooser, defaultExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File[] showOpenMultiDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
|
||||||
|
IFileChooserAccessory accessory, JFrame ownerFrame) {
|
||||||
|
JFileChooser openFileChooser = new JFileChooser();
|
||||||
|
initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory, true);
|
||||||
|
|
||||||
|
int result = openFileChooser.showOpenDialog(ownerFrame);
|
||||||
|
|
||||||
|
return processFileMultiChooserResult(result, openFileChooser, defaultExtension);
|
||||||
|
}
|
||||||
|
|
||||||
public File showSaveDialog(Window owner, FileFilter fileFilter, File initialFile, String defaultExtension,
|
public File showSaveDialog(Window owner, FileFilter fileFilter, File initialFile, String defaultExtension,
|
||||||
IFileChooserAccessory accessory) {
|
IFileChooserAccessory accessory) {
|
||||||
JFileChooser saveFileChooser = new OverwritePromptFileChooser();
|
JFileChooser saveFileChooser = new OverwritePromptFileChooser();
|
||||||
initializeFileChooser(saveFileChooser, fileFilter, initialFile, defaultExtension, accessory);
|
initializeFileChooser(saveFileChooser, fileFilter, initialFile, defaultExtension, accessory, false);
|
||||||
|
|
||||||
int result = saveFileChooser.showSaveDialog(owner);
|
int result = saveFileChooser.showSaveDialog(owner);
|
||||||
|
|
||||||
@@ -102,7 +112,7 @@ public class DialogFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeFileChooser(JFileChooser fileChooser, FileFilter fileFilter, File initialFile,
|
private void initializeFileChooser(JFileChooser fileChooser, FileFilter fileFilter, File initialFile,
|
||||||
String defaultExtension, IFileChooserAccessory accessory) {
|
String defaultExtension, IFileChooserAccessory accessory, boolean allowMultiSelect) {
|
||||||
if (accessory != null) {
|
if (accessory != null) {
|
||||||
accessory.install(fileChooser);
|
accessory.install(fileChooser);
|
||||||
}
|
}
|
||||||
@@ -118,6 +128,8 @@ public class DialogFactory {
|
|||||||
fileChooser.setCurrentDirectory(lastDirectory);
|
fileChooser.setCurrentDirectory(lastDirectory);
|
||||||
}
|
}
|
||||||
fileChooser.setSelectedFile(initialFile);
|
fileChooser.setSelectedFile(initialFile);
|
||||||
|
if (allowMultiSelect)
|
||||||
|
fileChooser.setMultiSelectionEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File processFileChooserResult(int result, JFileChooser fileChooser, String defaultExtension) {
|
private File processFileChooserResult(int result, JFileChooser fileChooser, String defaultExtension) {
|
||||||
@@ -135,6 +147,17 @@ public class DialogFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File[] processFileMultiChooserResult(int result, JFileChooser fileChooser, String defaultExtension) {
|
||||||
|
fileChooser.setAccessory(null);
|
||||||
|
if (result == JFileChooser.APPROVE_OPTION) {
|
||||||
|
lastDirectory = fileChooser.getCurrentDirectory();
|
||||||
|
ConfigurationManager.getInstance().writeValue(PATH_KEY, lastDirectory.getAbsolutePath());
|
||||||
|
return fileChooser.getSelectedFiles();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public AboutDialog createAboutDialog(String appName, Icon icon, String version, String author, String url,
|
public AboutDialog createAboutDialog(String appName, Icon icon, String version, String author, String url,
|
||||||
String mail, String htmlContent) {
|
String mail, String htmlContent) {
|
||||||
AboutDialog dialog = new AboutDialog(mainFrame, appName, icon, version, author, url, mail, htmlContent);
|
AboutDialog dialog = new AboutDialog(mainFrame, appName, icon, version, author, url, mail, htmlContent);
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ package org.diylc.swing.plugins.cloud;
|
|||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
@@ -307,7 +310,8 @@ public class CloudPlugIn implements IPlugIn {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
try {
|
try {
|
||||||
final UserEditDialog dialog = DialogFactory.getInstance().createUserEditDialog(CloudPresenter.Instance.getUserDetails());
|
final UserEditDialog dialog =
|
||||||
|
DialogFactory.getInstance().createUserEditDialog(CloudPresenter.Instance.getUserDetails());
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||||
@@ -389,66 +393,82 @@ public class CloudPlugIn implements IPlugIn {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
LOG.info("UploadAction triggered");
|
LOG.info("UploadAction triggered");
|
||||||
|
|
||||||
final File file =
|
final File[] files =
|
||||||
DialogFactory.getInstance().showOpenDialog(FileFilterEnum.DIY.getFilter(), null,
|
DialogFactory.getInstance().showOpenMultiDialog(FileFilterEnum.DIY.getFilter(), null,
|
||||||
FileFilterEnum.DIY.getExtensions()[0], null);
|
FileFilterEnum.DIY.getExtensions()[0], null, swingUI.getOwnerFrame());
|
||||||
if (file != null) {
|
if (files != null && files.length > 0) {
|
||||||
swingUI.executeBackgroundTask(new ITask<String[]>() {
|
List<ITask<String[]>> tasks = new ArrayList<ITask<String[]>>();
|
||||||
|
final ListIterator<ITask<String[]>> taskIterator = tasks.listIterator();
|
||||||
|
|
||||||
@Override
|
for (final File file : files) {
|
||||||
public String[] doInBackground() throws Exception {
|
taskIterator.add(new ITask<String[]>() {
|
||||||
LOG.debug("Uploading from " + file.getAbsolutePath());
|
|
||||||
thumbnailPresenter.loadProjectFromFile(file.getAbsolutePath());
|
|
||||||
return CloudPresenter.Instance.getCategories();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void complete(final String[] result) {
|
public String[] doInBackground() throws Exception {
|
||||||
final UploadDialog dialog =
|
LOG.debug("Uploading from " + file.getAbsolutePath());
|
||||||
DialogFactory.getInstance().createUploadDialog(swingUI.getOwnerFrame(), thumbnailPresenter, result,
|
thumbnailPresenter.loadProjectFromFile(file.getAbsolutePath());
|
||||||
false);
|
return CloudPresenter.Instance.getCategories();
|
||||||
dialog.setVisible(true);
|
}
|
||||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
|
||||||
try {
|
|
||||||
final File thumbnailFile = File.createTempFile("upload-thumbnail", ".png");
|
|
||||||
if (ImageIO.write(dialog.getThumbnail(), "png", thumbnailFile)) {
|
|
||||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void doInBackground() throws Exception {
|
public void complete(final String[] result) {
|
||||||
CloudPresenter.Instance.uploadProject(dialog.getName(), dialog.getCategory(), dialog.getDescription(),
|
final UploadDialog dialog =
|
||||||
dialog.getKeywords(), plugInPort.getCurrentVersionNumber().toString(), thumbnailFile, file,
|
DialogFactory.getInstance().createUploadDialog(swingUI.getOwnerFrame(), thumbnailPresenter, result,
|
||||||
null);
|
false);
|
||||||
return null;
|
dialog.setVisible(true);
|
||||||
}
|
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
||||||
|
try {
|
||||||
|
final File thumbnailFile = File.createTempFile("upload-thumbnail", ".png");
|
||||||
|
if (ImageIO.write(dialog.getThumbnail(), "png", thumbnailFile)) {
|
||||||
|
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void failed(Exception e) {
|
public Void doInBackground() throws Exception {
|
||||||
swingUI.showMessage(e.getMessage(), "Upload Error", IView.ERROR_MESSAGE);
|
CloudPresenter.Instance.uploadProject(dialog.getName(), dialog.getCategory(), dialog
|
||||||
}
|
.getDescription(), dialog.getKeywords(), plugInPort.getCurrentVersionNumber().toString(),
|
||||||
|
thumbnailFile, file, null);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void complete(Void result) {
|
public void failed(Exception e) {
|
||||||
swingUI.showMessage(
|
swingUI.showMessage(e.getMessage(), "Upload Error", IView.ERROR_MESSAGE);
|
||||||
"The project has been uploaded to the cloud successfully. Thank you for your contribution!",
|
}
|
||||||
"Upload Success", IView.INFORMATION_MESSAGE);
|
|
||||||
}
|
@Override
|
||||||
});
|
public void complete(Void result) {
|
||||||
} else {
|
swingUI
|
||||||
swingUI.showMessage("Could not prepare temporary files to be uploaded to the cloud.", "Upload Error",
|
.showMessage(
|
||||||
IView.ERROR_MESSAGE);
|
"The project has been uploaded to the cloud successfully. Thank you for your contribution!",
|
||||||
|
"Upload Success", IView.INFORMATION_MESSAGE);
|
||||||
|
|
||||||
|
synchronized (taskIterator) {
|
||||||
|
if (taskIterator.hasPrevious())
|
||||||
|
swingUI.executeBackgroundTask(taskIterator.previous());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
swingUI.showMessage("Could not prepare temporary files to be uploaded to the cloud.",
|
||||||
|
"Upload Error", IView.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
swingUI.showMessage(e.getMessage(), "Upload Error", IView.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
swingUI.showMessage(e.getMessage(), "Upload Error", IView.ERROR_MESSAGE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void failed(Exception e) {
|
public void failed(Exception e) {
|
||||||
swingUI.showMessage("Could not open file. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
|
swingUI.showMessage("Could not open file. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (taskIterator) {
|
||||||
|
if (taskIterator.hasPrevious())
|
||||||
|
swingUI.executeBackgroundTask(taskIterator.previous());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package org.diylc.utils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.apache.log4j.PropertyConfigurator;
|
||||||
|
import org.diylc.DIYLCStarter;
|
||||||
|
import org.diylc.presenter.Presenter;
|
||||||
|
import org.diylc.swing.gui.DummyView;
|
||||||
|
|
||||||
|
public class BatchConverter {
|
||||||
|
|
||||||
|
private static final Logger LOG = Logger.getLogger(BatchConverter.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
URL url = DIYLCStarter.class.getResource("log4j.properties");
|
||||||
|
Properties properties = new Properties();
|
||||||
|
try {
|
||||||
|
properties.load(url.openStream());
|
||||||
|
PropertyConfigurator.configure(properties);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("Could not initialize log4j configuration", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
File dir = new File("C:\\Users\\Branislav Stojkovic\\Documents\\layouts_v1");
|
||||||
|
File[] matchingFiles = dir.listFiles(new FilenameFilter() {
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Presenter presenter = new Presenter(new DummyView());
|
||||||
|
for (File file : matchingFiles) {
|
||||||
|
if (file.getName() != "" && file.getName() != "." && file.getName() != ".." && !file.isDirectory())
|
||||||
|
presenter.loadProjectFromFile(file.getAbsolutePath());
|
||||||
|
presenter.saveProjectToFile(file.getParentFile().getAbsolutePath() + "\\converted\\" + file.getName(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user