aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java80
-rw-r--r--assetstudio/src/images/clipart/big/android.pngbin0 -> 4156 bytes
-rw-r--r--assetstudio/src/images/clipart/small/android.pngbin0 -> 802 bytes
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ConfigureAssetSetPage.java128
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/CreateAssetSetWizard.java32
5 files changed, 232 insertions, 8 deletions
diff --git a/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java b/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java
index e53f0ab..902b21d 100644
--- a/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java
+++ b/assetstudio/src/com/android/assetstudiolib/GraphicGenerator.java
@@ -19,8 +19,19 @@ package com.android.assetstudiolib;
import com.android.resources.Density;
import java.awt.image.BufferedImage;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.security.ProtectionDomain;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
import javax.imageio.ImageIO;
@@ -49,4 +60,73 @@ public class GraphicGenerator {
InputStream is = GraphicGenerator.class.getResourceAsStream(relativePath);
return ImageIO.read(is);
}
+
+ /**
+ * Returns the icon (32x32) for a given clip art image.
+ *
+ * @param name the name of the image to be loaded (which can be looked up via
+ * {@link #getClipartNames()})
+ * @return the icon image
+ * @throws IOException if the image cannot be loaded
+ */
+ public static BufferedImage getClipartIcon(String name) throws IOException {
+ InputStream is = GraphicGenerator.class.getResourceAsStream(
+ "/images/clipart/small/" + name);
+ return ImageIO.read(is);
+ }
+
+ /**
+ * Returns the full size clip art image for a given image name.
+ *
+ * @param name the name of the image to be loaded (which can be looked up via
+ * {@link #getClipartNames()})
+ * @return the clip art image
+ * @throws IOException if the image cannot be loaded
+ */
+ public static BufferedImage getClipartImage(String name) throws IOException {
+ InputStream is = GraphicGenerator.class.getResourceAsStream(
+ "/images/clipart/big/" + name);
+ return ImageIO.read(is);
+ }
+
+ /**
+ * Returns the names of available clip art images which can be obtained by passing the
+ * name to {@link #getClipartIcon(String)} or
+ * {@link GraphicGenerator#getClipartImage(String)}
+ *
+ * @return an iterator for the available image names
+ */
+ public static Iterator<String> getClipartNames() {
+ List<String> names = new ArrayList<String>(80);
+ try {
+ String pathPrefix = "images/clipart/big/"; //$NON-NLS-1$
+ ProtectionDomain protectionDomain = GraphicGenerator.class.getProtectionDomain();
+ URL url = protectionDomain.getCodeSource().getLocation();
+ File file;
+ try {
+ file = new File(url.toURI());
+ } catch (URISyntaxException e) {
+ file = new File(url.getPath());
+ }
+ final ZipFile zipFile = new JarFile(file);
+ Enumeration<? extends ZipEntry> enumeration = zipFile.entries();
+ while (enumeration.hasMoreElements()) {
+ ZipEntry zipEntry = enumeration.nextElement();
+ String name = zipEntry.getName();
+ if (!name.startsWith(pathPrefix) || !name.endsWith(".png")) { //$NON-NLS-1$
+ continue;
+ }
+
+ int lastSlash = name.lastIndexOf('/');
+ if (lastSlash != -1) {
+ name = name.substring(lastSlash + 1);
+ }
+ names.add(name);
+ }
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+
+ return names.iterator();
+ }
}
diff --git a/assetstudio/src/images/clipart/big/android.png b/assetstudio/src/images/clipart/big/android.png
new file mode 100644
index 0000000..d966fae
--- /dev/null
+++ b/assetstudio/src/images/clipart/big/android.png
Binary files differ
diff --git a/assetstudio/src/images/clipart/small/android.png b/assetstudio/src/images/clipart/small/android.png
new file mode 100644
index 0000000..acbfafd
--- /dev/null
+++ b/assetstudio/src/images/clipart/small/android.png
Binary files differ
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ConfigureAssetSetPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ConfigureAssetSetPage.java
index 07a15d0..8804a47 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ConfigureAssetSetPage.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ConfigureAssetSetPage.java
@@ -24,6 +24,7 @@ import com.android.assetstudiolib.GraphicGeneratorContext;
import com.android.assetstudiolib.LauncherIconGenerator;
import com.android.assetstudiolib.LauncherIconGenerator.Options.Style;
import com.android.assetstudiolib.TextRenderUtil;
+import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.ImageControl;
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.ImageUtils;
import com.android.ide.eclipse.adt.internal.editors.layout.gle2.SwtUtils;
@@ -35,19 +36,22 @@ import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
@@ -69,6 +73,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -112,9 +117,12 @@ public class ConfigureAssetSetPage extends WizardPage implements SelectionListen
private RGB mBgColor;
private RGB mFgColor;
private Text mText;
+ private String mSelectedClipart;
/** Most recently set image path: preserved across wizard sessions */
private static String sImagePath;
+ private Button mChooseClipart;
+ private Composite mClipartPreviewPanel;
/**
* Create the wizard.
@@ -172,7 +180,7 @@ public class ConfigureAssetSetPage extends WizardPage implements SelectionListen
mImageRadio.setText("Image");
mClipartRadio = new Button(foregroundComposite, SWT.FLAT | SWT.TOGGLE);
- mClipartRadio.setEnabled(false);
+ //mClipartRadio.setEnabled(false);
mClipartRadio.setText("Clipart");
mClipartRadio.addSelectionListener(this);
@@ -204,8 +212,20 @@ public class ConfigureAssetSetPage extends WizardPage implements SelectionListen
mPickImageButton.setText("Browse...");
mPickImageButton.addSelectionListener(this);
- mClipartForm = new Composite(mForegroundArea, SWT.V_SCROLL);
- mClipartForm.setLayout(new FillLayout(SWT.HORIZONTAL));
+ mClipartForm = new Composite(mForegroundArea, SWT.NONE);
+ mClipartForm.setLayout(new GridLayout(2, false));
+
+ mChooseClipart = new Button(mClipartForm, SWT.FLAT);
+ mChooseClipart.setText("Choose...");
+ mChooseClipart.addSelectionListener(this);
+
+ mClipartPreviewPanel = new Composite(mClipartForm, SWT.NONE);
+ RowLayout rlClipartPreviewPanel = new RowLayout(SWT.HORIZONTAL);
+ rlClipartPreviewPanel.marginBottom = 0;
+ rlClipartPreviewPanel.marginTop = 0;
+ rlClipartPreviewPanel.center = true;
+ mClipartPreviewPanel.setLayout(rlClipartPreviewPanel);
+ mClipartPreviewPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
mTextForm = new Composite(mForegroundArea, SWT.NONE);
mTextForm.setLayout(new GridLayout(2, false));
@@ -433,7 +453,11 @@ public class ConfigureAssetSetPage extends WizardPage implements SelectionListen
error = "Enter text";
}
} else {
- error = "Clipart not yet implemented";
+ //error = "Clipart not yet implemented";
+ assert mClipartRadio.getSelection();
+ if (mSelectedClipart == null) {
+ error = "Select clip art";
+ }
}
setPageComplete(error == null);
@@ -513,6 +537,91 @@ public class ConfigureAssetSetPage extends WizardPage implements SelectionListen
mFancyRadio.setSelection(false);
}
+ if (source == mChooseClipart) {
+ MessageDialog dialog = new MessageDialog(mChooseClipart.getShell(),
+ "Choose Clip Art",
+ null, "Choose Clip Art Image:", MessageDialog.NONE,
+ new String[] { "Close" }, 0) {
+ @Override
+ protected Control createCustomArea(Composite parent) {
+ // Outer form which just establishes a width for the inner form which
+ // wraps in a RowLayout
+ Composite outer = new Composite(parent, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ outer.setLayout(gridLayout);
+
+ Composite chooserForm = new Composite(outer, SWT.NONE);
+ GridData gd = new GridData();
+ gd.grabExcessVerticalSpace = true;
+ gd.widthHint = 450;
+ chooserForm.setLayoutData(gd);
+ RowLayout clipartFormLayout = new RowLayout(SWT.HORIZONTAL);
+ clipartFormLayout.center = true;
+ clipartFormLayout.wrap = true;
+ chooserForm.setLayout(clipartFormLayout);
+
+ MouseAdapter clickListener = new MouseAdapter() {
+ @SuppressWarnings("unused")
+ @Override
+ public void mouseDown(MouseEvent event) {
+ // Clicked on some of the sample art
+ if (event.widget instanceof ImageControl) {
+ ImageControl image = (ImageControl) event.widget;
+ mSelectedClipart = (String) image.getData();
+ close();
+
+ for (Control c : mClipartPreviewPanel.getChildren()) {
+ c.dispose();
+ }
+ if (mClipartPreviewPanel.getChildren().length == 0) {
+ try {
+ BufferedImage icon =
+ GraphicGenerator.getClipartIcon(mSelectedClipart);
+ if (icon != null) {
+ Display display = mClipartForm.getDisplay();
+ Image swtImage = SwtUtils.convertToSwt(display, icon,
+ false, -1);
+ new ImageControl(mClipartPreviewPanel,
+ SWT.NONE, swtImage);
+ }
+ } catch (IOException e1) {
+ AdtPlugin.log(e1, null);
+ }
+ mClipartPreviewPanel.pack();
+ mClipartPreviewPanel.layout();
+ }
+
+ updatePreview();
+ }
+ }
+ };
+ Display display = chooserForm.getDisplay();
+ Color hoverColor = display.getSystemColor(SWT.COLOR_RED);
+ Iterator<String> clipartImages = GraphicGenerator.getClipartNames();
+ while (clipartImages.hasNext()) {
+ String name = clipartImages.next();
+ try {
+ BufferedImage icon = GraphicGenerator.getClipartIcon(name);
+ if (icon != null) {
+ Image swtImage = SwtUtils.convertToSwt(display, icon, false, -1);
+ ImageControl img = new ImageControl(chooserForm,
+ SWT.NONE, swtImage);
+ img.setData(name);
+ img.setHoverColor(hoverColor);
+ img.addMouseListener(clickListener);
+ }
+ } catch (IOException e1) {
+ AdtPlugin.log(e1, null);
+ }
+ }
+ outer.pack();
+ outer.layout();
+ return outer;
+ }
+ };
+ dialog.open();
+ }
+
if (source == mBgButton) {
ColorDialog dlg = new ColorDialog(mBgButton.getShell());
dlg.setRGB(mBgColor);
@@ -681,8 +790,13 @@ public class ConfigureAssetSetPage extends WizardPage implements SelectionListen
sourceImage = TextRenderUtil.renderTextImage(text, options);
} else {
assert mClipartRadio.getSelection();
- // Not yet supported
- return imageMap;
+ assert mSelectedClipart != null;
+ try {
+ sourceImage = GraphicGenerator.getClipartImage(mSelectedClipart);
+ } catch (IOException e) {
+ AdtPlugin.log(e, null);
+ return imageMap;
+ }
}
LauncherIconGenerator.Options options = new LauncherIconGenerator.Options();
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/CreateAssetSetWizard.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/CreateAssetSetWizard.java
index 4aa67fa..4057824 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/CreateAssetSetWizard.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/CreateAssetSetWizard.java
@@ -38,11 +38,13 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.SWT;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IViewPart;
@@ -91,6 +93,7 @@ public class CreateAssetSetWizard extends Wizard implements INewWizard {
IProject project = getProject();
// Write out the images into the project
+ boolean yesToAll = false;
List<IFile> createdFiles = new ArrayList<IFile>();
for (Map.Entry<String, BufferedImage> entry : previews.entrySet()) {
String id = entry.getKey();
@@ -99,7 +102,34 @@ public class CreateAssetSetWizard extends Wizard implements INewWizard {
+ id + WS_SEP + name + DOT_PNG);
IFile file = project.getFile(dest);
if (file.exists()) {
- // TODO: Warn that the file already exists and ask the user what to do?
+ // Warn that the file already exists and ask the user what to do
+ if (!yesToAll) {
+ MessageDialog dialog = new MessageDialog(null, "File Already Exists", null,
+ String.format("%1$s already exists.\nWould you like to replace it?",
+ file.getProjectRelativePath().toOSString()),
+ MessageDialog.QUESTION, new String[] {
+ // Yes will be moved to the end because it's the default
+ "Yes", "No", "Cancel", "Yes to All"
+ }, 0);
+ int result = dialog.open();
+ switch (result) {
+ case 0:
+ // Yes
+ break;
+ case 3:
+ // Yes to all
+ yesToAll = true;
+ break;
+ case 1:
+ // No
+ continue;
+ case SWT.DEFAULT:
+ case 2:
+ // Cancel
+ return false;
+ }
+ }
+
try {
file.delete(true, new NullProgressMonitor());
} catch (CoreException e) {