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.FileInputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.net.URL;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -95,16 +94,6 @@ public class DIYLCStarter {
|
||||
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,
|
||||
IFileChooserAccessory accessory) {
|
||||
JFileChooser openFileChooser = new JFileChooser();
|
||||
initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory);
|
||||
initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory, false);
|
||||
|
||||
int result = openFileChooser.showOpenDialog(mainFrame);
|
||||
|
||||
@@ -84,17 +84,27 @@ public class DialogFactory {
|
||||
public File showOpenDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
|
||||
IFileChooserAccessory accessory, JFrame ownerFrame) {
|
||||
JFileChooser openFileChooser = new JFileChooser();
|
||||
initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory);
|
||||
initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory, false);
|
||||
|
||||
int result = openFileChooser.showOpenDialog(ownerFrame);
|
||||
|
||||
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,
|
||||
IFileChooserAccessory accessory) {
|
||||
JFileChooser saveFileChooser = new OverwritePromptFileChooser();
|
||||
initializeFileChooser(saveFileChooser, fileFilter, initialFile, defaultExtension, accessory);
|
||||
initializeFileChooser(saveFileChooser, fileFilter, initialFile, defaultExtension, accessory, false);
|
||||
|
||||
int result = saveFileChooser.showSaveDialog(owner);
|
||||
|
||||
@@ -102,7 +112,7 @@ public class DialogFactory {
|
||||
}
|
||||
|
||||
private void initializeFileChooser(JFileChooser fileChooser, FileFilter fileFilter, File initialFile,
|
||||
String defaultExtension, IFileChooserAccessory accessory) {
|
||||
String defaultExtension, IFileChooserAccessory accessory, boolean allowMultiSelect) {
|
||||
if (accessory != null) {
|
||||
accessory.install(fileChooser);
|
||||
}
|
||||
@@ -118,6 +128,8 @@ public class DialogFactory {
|
||||
fileChooser.setCurrentDirectory(lastDirectory);
|
||||
}
|
||||
fileChooser.setSelectedFile(initialFile);
|
||||
if (allowMultiSelect)
|
||||
fileChooser.setMultiSelectionEnabled(true);
|
||||
}
|
||||
|
||||
private File processFileChooserResult(int result, JFileChooser fileChooser, String defaultExtension) {
|
||||
@@ -134,6 +146,17 @@ public class DialogFactory {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
String mail, String htmlContent) {
|
||||
|
||||
@@ -2,7 +2,10 @@ package org.diylc.swing.plugins.cloud;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.AbstractAction;
|
||||
@@ -307,7 +310,8 @@ public class CloudPlugIn implements IPlugIn {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
final UserEditDialog dialog = DialogFactory.getInstance().createUserEditDialog(CloudPresenter.Instance.getUserDetails());
|
||||
final UserEditDialog dialog =
|
||||
DialogFactory.getInstance().createUserEditDialog(CloudPresenter.Instance.getUserDetails());
|
||||
dialog.setVisible(true);
|
||||
if (ButtonDialog.OK.equals(dialog.getSelectedButtonCaption())) {
|
||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||
@@ -389,66 +393,82 @@ public class CloudPlugIn implements IPlugIn {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOG.info("UploadAction triggered");
|
||||
|
||||
final File file =
|
||||
DialogFactory.getInstance().showOpenDialog(FileFilterEnum.DIY.getFilter(), null,
|
||||
FileFilterEnum.DIY.getExtensions()[0], null);
|
||||
if (file != null) {
|
||||
swingUI.executeBackgroundTask(new ITask<String[]>() {
|
||||
final File[] files =
|
||||
DialogFactory.getInstance().showOpenMultiDialog(FileFilterEnum.DIY.getFilter(), null,
|
||||
FileFilterEnum.DIY.getExtensions()[0], null, swingUI.getOwnerFrame());
|
||||
if (files != null && files.length > 0) {
|
||||
List<ITask<String[]>> tasks = new ArrayList<ITask<String[]>>();
|
||||
final ListIterator<ITask<String[]>> taskIterator = tasks.listIterator();
|
||||
|
||||
@Override
|
||||
public String[] doInBackground() throws Exception {
|
||||
LOG.debug("Uploading from " + file.getAbsolutePath());
|
||||
thumbnailPresenter.loadProjectFromFile(file.getAbsolutePath());
|
||||
return CloudPresenter.Instance.getCategories();
|
||||
}
|
||||
for (final File file : files) {
|
||||
taskIterator.add(new ITask<String[]>() {
|
||||
|
||||
@Override
|
||||
public void complete(final String[] result) {
|
||||
final UploadDialog dialog =
|
||||
DialogFactory.getInstance().createUploadDialog(swingUI.getOwnerFrame(), thumbnailPresenter, result,
|
||||
false);
|
||||
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
|
||||
public String[] doInBackground() throws Exception {
|
||||
LOG.debug("Uploading from " + file.getAbsolutePath());
|
||||
thumbnailPresenter.loadProjectFromFile(file.getAbsolutePath());
|
||||
return CloudPresenter.Instance.getCategories();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void doInBackground() throws Exception {
|
||||
CloudPresenter.Instance.uploadProject(dialog.getName(), dialog.getCategory(), dialog.getDescription(),
|
||||
dialog.getKeywords(), plugInPort.getCurrentVersionNumber().toString(), thumbnailFile, file,
|
||||
null);
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void complete(final String[] result) {
|
||||
final UploadDialog dialog =
|
||||
DialogFactory.getInstance().createUploadDialog(swingUI.getOwnerFrame(), thumbnailPresenter, result,
|
||||
false);
|
||||
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
|
||||
public void failed(Exception e) {
|
||||
swingUI.showMessage(e.getMessage(), "Upload Error", IView.ERROR_MESSAGE);
|
||||
}
|
||||
@Override
|
||||
public Void doInBackground() throws Exception {
|
||||
CloudPresenter.Instance.uploadProject(dialog.getName(), dialog.getCategory(), dialog
|
||||
.getDescription(), dialog.getKeywords(), plugInPort.getCurrentVersionNumber().toString(),
|
||||
thumbnailFile, file, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(Void result) {
|
||||
swingUI.showMessage(
|
||||
"The project has been uploaded to the cloud successfully. Thank you for your contribution!",
|
||||
"Upload Success", IView.INFORMATION_MESSAGE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
swingUI.showMessage("Could not prepare temporary files to be uploaded to the cloud.", "Upload Error",
|
||||
IView.ERROR_MESSAGE);
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
swingUI.showMessage(e.getMessage(), "Upload Error", IView.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(Void result) {
|
||||
swingUI
|
||||
.showMessage(
|
||||
"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
|
||||
public void failed(Exception e) {
|
||||
swingUI.showMessage("Could not open file. " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
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