aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio
diff options
context:
space:
mode:
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/AssetType.java88
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ChooseAssetTypePage.java225
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ConfigureAssetSetPage.java1251
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/CreateAssetSetWizard.java312
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/CreateAssetSetWizardState.java258
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/OpenCreateAssetSetWizardAction.java58
6 files changed, 0 insertions, 2192 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/AssetType.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/AssetType.java
deleted file mode 100644
index 5cfeebb4b..000000000
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/AssetType.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.eclipse.org/org/documents/epl-v10.php
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.ide.eclipse.adt.internal.assetstudio;
-
-/**
- * The type of asset to create: launcher icon, menu icon, etc.
- */
-public enum AssetType {
- /** Launcher icon to be shown in the application list */
- LAUNCHER("Launcher Icons", "ic_launcher"), //$NON-NLS-2$
-
- /** Icons shown in the action bar */
- ACTIONBAR("Action Bar and Tab Icons (Android 3.0+)", "ic_action_%s"), //$NON-NLS-2$
-
- /** Icons shown in a notification message */
- NOTIFICATION("Notification Icons", "ic_stat_%s"), //$NON-NLS-2$
-
- /** Icons shown as part of tabs */
- TAB("Pre-Android 3.0 Tab Icons", "ic_tab_%s"), //$NON-NLS-2$
-
- /** Icons shown in menus */
- MENU("Pre-Android 3.0 Menu Icons", "ic_menu_%s"); //$NON-NLS-2$
-
- /** Display name to show to the user in the asset type selection list */
- private final String mDisplayName;
-
- /** Default asset name format */
- private String mDefaultNameFormat;
-
- AssetType(String displayName, String defaultNameFormat) {
- mDisplayName = displayName;
- mDefaultNameFormat = defaultNameFormat;
- }
-
- /**
- * Returns the display name of this asset type to show to the user in the
- * asset wizard selection page etc
- */
- String getDisplayName() {
- return mDisplayName;
- }
-
- /**
- * Returns the default format to use to suggest a name for the asset
- */
- String getDefaultNameFormat() {
- return mDefaultNameFormat;
- }
-
- /** Whether this asset type configures foreground scaling */
- boolean needsForegroundScaling() {
- return this == LAUNCHER;
- }
-
- /** Whether this asset type needs a shape parameter */
- boolean needsShape() {
- return this == LAUNCHER;
- }
-
- /** Whether this asset type needs foreground and background color parameters */
- boolean needsColors() {
- return this == LAUNCHER;
- }
-
- /** Whether this asset type needs an effects parameter */
- boolean needsEffects() {
- return this == LAUNCHER;
- }
-
- /** Whether this asset type needs a theme parameter */
- boolean needsTheme() {
- return this == ACTIONBAR;
- }
-}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ChooseAssetTypePage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ChooseAssetTypePage.java
deleted file mode 100644
index a26a22e49..000000000
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ChooseAssetTypePage.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.eclipse.org/org/documents/epl-v10.php
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.ide.eclipse.adt.internal.assetstudio;
-
-import com.android.ide.eclipse.adt.internal.project.ProjectChooserHelper;
-import com.android.ide.eclipse.adt.internal.project.ProjectChooserHelper.ProjectCombo;
-import com.android.ide.eclipse.adt.internal.resources.ResourceNameValidator;
-import com.android.resources.ResourceFolderType;
-
-import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.dnd.Clipboard;
-import org.eclipse.swt.dnd.TextTransfer;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-
-/** Page for choosing the type of asset to create, as well as the target project */
-public class ChooseAssetTypePage extends WizardPage implements SelectionListener, ModifyListener {
- private final CreateAssetSetWizardState mValues;
- private ProjectCombo mProjectButton;
- private Button mClipboardButton;
- private Text mNameText;
- private boolean mNameModified;
- private Label mResourceName;
-
- /**
- * Create the wizard.
- */
- public ChooseAssetTypePage(CreateAssetSetWizardState values) {
- super("chooseAssetTypePage");
- mValues = values;
- setTitle("Choose Icon Set Type");
- setDescription("Select the type of icon set to create:");
- }
-
- /**
- * Create contents of the wizard.
- *
- * @param parent the parent composite
- */
- @Override
- public void createControl(Composite parent) {
- Composite container = new Composite(parent, SWT.NULL);
-
- setControl(container);
- container.setLayout(new GridLayout(3, false));
-
- for (AssetType type : AssetType.values()) {
- Button button = new Button(container, SWT.RADIO);
- button.setData(type);
- button.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
- button.setSelection(type == mValues.type);
- button.setText(type.getDisplayName());
- button.addSelectionListener(this);
- }
-
- Label separator = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
- GridData gdSeparator = new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1);
- gdSeparator.heightHint = 20;
- separator.setLayoutData(gdSeparator);
-
- Label projectLabel = new Label(container, SWT.NONE);
- projectLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- projectLabel.setText("Project:");
-
- ProjectChooserHelper helper =
- new ProjectChooserHelper(getShell(), null /* filter */);
- mProjectButton = new ProjectCombo(helper, container, mValues.project);
- mProjectButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- mProjectButton.addSelectionListener(this);
-
- Label assetLabel = new Label(container, SWT.NONE);
- assetLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- assetLabel.setText("Icon Name:");
-
- mNameText = new Text(container, SWT.BORDER);
- mNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- mNameText.addModifyListener(this);
-
- Label resourceLabel = new Label(container, SWT.NONE);
- resourceLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- resourceLabel.setText("Resource:");
-
- mResourceName = new Label(container, SWT.NONE);
- mResourceName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
-
- mClipboardButton = new Button(container, SWT.FLAT);
- mClipboardButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- mClipboardButton.setText("Copy Name to Clipboard");
-
- mClipboardButton.addSelectionListener(this);
-
- updateAssetType();
- validatePage();
- parent.getDisplay().asyncExec(new Runnable() {
- @Override
- public void run() {
- mNameText.setFocus();
- }
- });
- }
-
- private void updateAssetType() {
- if (!mNameModified) {
- // Default name suggestion, possibly as a suffix, e.g. "ic_menu_<name>"
- String replace = "name";
- String suggestedName = String.format(mValues.type.getDefaultNameFormat(), replace);
- mNameText.setText(suggestedName);
- mValues.outputName = suggestedName;
-
- updateResourceLabel();
- mNameModified = false;
- int start = suggestedName.indexOf(replace);
- if (start != -1) {
- mNameText.setSelection(start, start + replace.length());
- } else {
- mNameText.selectAll();
- }
- } else {
- mNameText.selectAll();
- }
- }
-
- private void updateResourceLabel() {
- mResourceName.setText("@drawable/" + getOutputName()); //$NON-NLS-1$
- }
-
- @Override
- public boolean canFlipToNextPage() {
- return mValues.project != null;
- }
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- Object source = e.getSource();
- if (source == mProjectButton) {
- mValues.project = mProjectButton.getSelectedProject();
- validatePage();
- } else if (source == mClipboardButton) {
- Clipboard clipboard = new Clipboard(getShell().getDisplay());
- TextTransfer textTransfer = TextTransfer.getInstance();
- clipboard.setContents(
- new Object[] { mResourceName.getText() },
- new Transfer[] { textTransfer });
- clipboard.dispose();
- } else if (source instanceof Button) {
- // User selected a different asset type to be created
- Object data = ((Button) source).getData();
- if (data instanceof AssetType) {
- mValues.type = (AssetType) data;
- CreateAssetSetWizardState.sLastType = mValues.type;
- updateAssetType();
- }
- }
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- @Override
- public void modifyText(ModifyEvent e) {
- Object source = e.getSource();
- if (source == mNameText) {
- mNameModified = true;
- mValues.outputName = mNameText.getText().trim();
- updateResourceLabel();
- }
-
- validatePage();
- }
-
- private String getOutputName() {
- return mNameText.getText().trim();
- }
-
- private void validatePage() {
- String error = null;
-
- if (mValues.project == null) {
- error = "Please select an Android project.";
- } else {
- String outputName = getOutputName();
- if (outputName == null || outputName.length() == 0) {
- error = "Please enter a name";
- } else {
- ResourceNameValidator validator =
- ResourceNameValidator.create(true, ResourceFolderType.DRAWABLE);
- error = validator.isValid(outputName);
- }
- }
-
- setPageComplete(error == null);
- if (error != null) {
- setMessage(error, IMessageProvider.ERROR);
- } else {
- setErrorMessage(null);
- setMessage(null);
- }
- }
-}
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
deleted file mode 100644
index 17336ad2d..000000000
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/ConfigureAssetSetPage.java
+++ /dev/null
@@ -1,1251 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.eclipse.org/org/documents/epl-v10.php
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.ide.eclipse.adt.internal.assetstudio;
-
-import static com.android.ide.eclipse.adt.internal.wizards.templates.NewProjectWizard.DEFAULT_LAUNCHER_ICON;
-import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
-
-import com.android.annotations.NonNull;
-import com.android.annotations.Nullable;
-import com.android.assetstudiolib.ActionBarIconGenerator;
-import com.android.assetstudiolib.GraphicGenerator;
-import com.android.assetstudiolib.GraphicGenerator.Shape;
-import com.android.assetstudiolib.LauncherIconGenerator;
-import com.android.assetstudiolib.MenuIconGenerator;
-import com.android.assetstudiolib.NotificationIconGenerator;
-import com.android.assetstudiolib.TabIconGenerator;
-import com.android.assetstudiolib.TextRenderUtil;
-import com.android.assetstudiolib.Util;
-import com.android.ide.eclipse.adt.AdtPlugin;
-import com.android.ide.eclipse.adt.AdtUtils;
-import com.android.ide.eclipse.adt.internal.assetstudio.CreateAssetSetWizardState.SourceType;
-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;
-import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo;
-import com.android.utils.Pair;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-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.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.layout.RowData;
-import org.eclipse.swt.layout.RowLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.ColorDialog;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.FontDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Slider;
-import org.eclipse.swt.widgets.Text;
-
-import java.awt.Paint;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.imageio.ImageIO;
-
-/**
- * This is normally page 2 of a Create New Asset Set wizard, unless we can offer actions
- * to create a specific asset type, in which case we skip page 1. On this page the user
- * gets to configure the parameters of the asset, and see a preview.
- */
-public class ConfigureAssetSetPage extends WizardPage implements SelectionListener,
- ModifyListener {
- private final CreateAssetSetWizardState mValues;
-
- private static final int PREVIEW_AREA_WIDTH = 144;
-
- private boolean mShown;
-
- private Composite mConfigurationArea;
- private Button mImageRadio;
- private Button mClipartRadio;
- private Button mTextRadio;
- private Button mPickImageButton;
- private Button mTrimCheckBox;
- private Slider mPaddingSlider;
- private Label mPercentLabel;
- private Button mCropRadio;
- private Button mCenterRadio;
- private Button mNoShapeRadio;
- private Button mSquareRadio;
- private Button mCircleButton;
- private Button mBgButton;
- private Button mFgButton;
- private Composite mPreviewArea;
- private Button mFontButton;
- private Composite mForegroundArea;
- private Composite mImageForm;
- private Composite mClipartForm;
- private Composite mTextForm;
- private Text mImagePathText;
-
- private boolean mTimerPending;
- private RGB mBgColor;
- private RGB mFgColor;
- private Text mText;
-
- /** Most recently set image path: preserved across wizard sessions */
- private static String sImagePath;
- private Button mChooseClipart;
- private Composite mClipartPreviewPanel;
- private Label mThemeLabel;
- private Composite mThemeComposite;
- private Button mHoloLightRadio;
- private Button mHoloDarkRadio;
- private Label mScalingLabel;
- private Composite mScalingComposite;
- private Label mShapeLabel;
- private Composite mShapeComposite;
- private Label mBgColorLabel;
- private Label mFgColorLabel;
-
- private boolean mIgnore;
- private SourceType mShowingType;
-
- /**
- * Create the wizard.
- *
- * @param values the wizard state
- */
- public ConfigureAssetSetPage(CreateAssetSetWizardState values) {
- super("configureAssetPage");
- mValues = values;
-
- setTitle("Configure Icon Set");
- setDescription("Configure the attributes of the icon set");
- }
-
- /**
- * Create contents of the wizard.
- *
- * @param parent the parent widget
- */
- @Override
- @SuppressWarnings("unused") // Don't warn about unassigned "new Label(.)": has side-effect
- public void createControl(Composite parent) {
- Composite container = new Composite(parent, SWT.NULL);
-
- setControl(container);
- GridLayout glContainer = new GridLayout(2, false);
- glContainer.marginWidth = 0;
- glContainer.horizontalSpacing = 0;
- glContainer.marginHeight = 0;
- glContainer.verticalSpacing = 0;
- container.setLayout(glContainer);
-
- ScrolledComposite configurationScrollArea = new ScrolledComposite(container, SWT.V_SCROLL);
- configurationScrollArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
- configurationScrollArea.setExpandHorizontal(true);
- configurationScrollArea.setExpandVertical(true);
-
- mConfigurationArea = new Composite(configurationScrollArea, SWT.NONE);
- GridLayout glConfigurationArea = new GridLayout(3, false);
- glConfigurationArea.horizontalSpacing = 0;
- glConfigurationArea.marginRight = 15;
- glConfigurationArea.marginWidth = 0;
- glConfigurationArea.marginHeight = 0;
- mConfigurationArea.setLayout(glConfigurationArea);
-
- Label foregroundLabel = new Label(mConfigurationArea, SWT.NONE);
- foregroundLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- foregroundLabel.setText("Foreground:");
-
- Composite foregroundComposite = new Composite(mConfigurationArea, SWT.NONE);
- foregroundComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
- GridLayout glForegroundComposite = new GridLayout(5, false);
- glForegroundComposite.horizontalSpacing = 0;
- foregroundComposite.setLayout(glForegroundComposite);
-
- mImageRadio = new Button(foregroundComposite, SWT.FLAT | SWT.TOGGLE);
- mImageRadio.setSelection(false);
- mImageRadio.addSelectionListener(this);
- mImageRadio.setText("Image");
-
- mClipartRadio = new Button(foregroundComposite, SWT.FLAT | SWT.TOGGLE);
- mClipartRadio.setText("Clipart");
- mClipartRadio.addSelectionListener(this);
-
- mTextRadio = new Button(foregroundComposite, SWT.FLAT | SWT.TOGGLE);
- mTextRadio.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
- mTextRadio.setText("Text");
- mTextRadio.addSelectionListener(this);
- new Label(mConfigurationArea, SWT.NONE);
-
- mForegroundArea = new Composite(mConfigurationArea, SWT.NONE);
- mForegroundArea.setLayout(new StackLayout());
- mForegroundArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
-
- mImageForm = new Composite(mForegroundArea, SWT.NONE);
- mImageForm.setLayout(new GridLayout(3, false));
-
- Label fileLabel = new Label(mImageForm, SWT.NONE);
- fileLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- fileLabel.setText("Image File:");
-
- mImagePathText = new Text(mImageForm, SWT.BORDER);
- GridData pathLayoutData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
- pathLayoutData.widthHint = 200;
- mImagePathText.setLayoutData(pathLayoutData);
- mImagePathText.addSelectionListener(this);
- mImagePathText.addModifyListener(this);
-
- mPickImageButton = new Button(mImageForm, SWT.FLAT);
- mPickImageButton.setText("Browse...");
- mPickImageButton.addSelectionListener(this);
-
- 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));
-
- Label textLabel = new Label(mTextForm, SWT.NONE);
- textLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- textLabel.setText("Text:");
-
- mText = new Text(mTextForm, SWT.BORDER);
- mText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- mText.addModifyListener(this);
-
- Label fontLabel = new Label(mTextForm, SWT.NONE);
- fontLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- fontLabel.setText("Font:");
-
- mFontButton = new Button(mTextForm, SWT.FLAT);
- mFontButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
- mFontButton.addSelectionListener(this);
- mFontButton.setText("Choose Font...");
- new Label(mConfigurationArea, SWT.NONE);
-
- mTrimCheckBox = new Button(mConfigurationArea, SWT.CHECK);
- mTrimCheckBox.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
- mTrimCheckBox.setSelection(false);
- mTrimCheckBox.setText("Trim Surrounding Blank Space");
- mTrimCheckBox.addSelectionListener(this);
- new Label(mConfigurationArea, SWT.NONE);
-
- Label paddingLabel = new Label(mConfigurationArea, SWT.NONE);
- paddingLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
- paddingLabel.setText("Additional Padding:");
- new Label(mConfigurationArea, SWT.NONE);
-
- mPaddingSlider = new Slider(mConfigurationArea, SWT.NONE);
- mPaddingSlider.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- // This doesn't work right -- not sure why. For now just use a plain slider
- // and subtract 10 from it to get the real range.
- //mPaddingSlider.setValues(0, -10, 50, 0, 1, 10);
- //mPaddingSlider.setSelection(10 + 15);
- mPaddingSlider.addSelectionListener(this);
-
- mPercentLabel = new Label(mConfigurationArea, SWT.NONE);
- mPercentLabel.setText(" 15%"); // Enough available space for -10%
- mScalingLabel = new Label(mConfigurationArea, SWT.NONE);
- mScalingLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- mScalingLabel.setText("Foreground Scaling:");
-
- mScalingComposite = new Composite(mConfigurationArea, SWT.NONE);
- mScalingComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
- GridLayout gl_mScalingComposite = new GridLayout(5, false);
- gl_mScalingComposite.horizontalSpacing = 0;
- mScalingComposite.setLayout(gl_mScalingComposite);
-
- mCropRadio = new Button(mScalingComposite, SWT.FLAT | SWT.TOGGLE);
- mCropRadio.setSelection(true);
- mCropRadio.setText("Crop");
- mCropRadio.addSelectionListener(this);
-
- mCenterRadio = new Button(mScalingComposite, SWT.FLAT | SWT.TOGGLE);
- mCenterRadio.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
- mCenterRadio.setText("Center");
- mCenterRadio.addSelectionListener(this);
-
- mShapeLabel = new Label(mConfigurationArea, SWT.NONE);
- mShapeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- mShapeLabel.setText("Shape");
-
- mShapeComposite = new Composite(mConfigurationArea, SWT.NONE);
- mShapeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
- GridLayout gl_mShapeComposite = new GridLayout(6, false);
- gl_mShapeComposite.horizontalSpacing = 0;
- mShapeComposite.setLayout(gl_mShapeComposite);
-
- mNoShapeRadio = new Button(mShapeComposite, SWT.FLAT | SWT.TOGGLE);
- mNoShapeRadio.setText("None");
- mNoShapeRadio.addSelectionListener(this);
-
- mSquareRadio = new Button(mShapeComposite, SWT.FLAT | SWT.TOGGLE);
- mSquareRadio.setSelection(true);
- mSquareRadio.setText("Square");
- mSquareRadio.addSelectionListener(this);
-
- mCircleButton = new Button(mShapeComposite, SWT.FLAT | SWT.TOGGLE);
- mCircleButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
- mCircleButton.setText("Circle");
- mCircleButton.addSelectionListener(this);
-
- mThemeLabel = new Label(mConfigurationArea, SWT.NONE);
- mThemeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- mThemeLabel.setText("Theme");
-
- mThemeComposite = new Composite(mConfigurationArea, SWT.NONE);
- mThemeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- GridLayout gl_mThemeComposite = new GridLayout(2, false);
- gl_mThemeComposite.horizontalSpacing = 0;
- mThemeComposite.setLayout(gl_mThemeComposite);
-
- mHoloLightRadio = new Button(mThemeComposite, SWT.FLAT | SWT.TOGGLE);
- mHoloLightRadio.setText("Holo Light");
- mHoloLightRadio.setSelection(true);
- mHoloLightRadio.addSelectionListener(this);
-
- mHoloDarkRadio = new Button(mThemeComposite, SWT.FLAT | SWT.TOGGLE);
- mHoloDarkRadio.setText("Holo Dark");
- mHoloDarkRadio.addSelectionListener(this);
-
- mBgColorLabel = new Label(mConfigurationArea, SWT.NONE);
- mBgColorLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- mBgColorLabel.setText("Background Color:");
-
- mBgButton = new Button(mConfigurationArea, SWT.FLAT);
- mBgButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
- mBgButton.addSelectionListener(this);
- mBgButton.setAlignment(SWT.CENTER);
-
- mFgColorLabel = new Label(mConfigurationArea, SWT.NONE);
- mFgColorLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- mFgColorLabel.setText("Foreground Color:");
-
- mFgButton = new Button(mConfigurationArea, SWT.FLAT);
- mFgButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
- mFgButton.setAlignment(SWT.CENTER);
- mFgButton.addSelectionListener(this);
-
- configurationScrollArea.setContent(mConfigurationArea);
- configurationScrollArea.setMinSize(mConfigurationArea.computeSize(SWT.DEFAULT,
- SWT.DEFAULT));
-
- Label previewLabel = new Label(container, SWT.NONE);
- previewLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
- previewLabel.setText("Preview:");
-
- mPreviewArea = new Composite(container, SWT.BORDER);
-
- RowLayout rlPreviewAreaPreviewArea = new RowLayout(SWT.HORIZONTAL);
- rlPreviewAreaPreviewArea.wrap = true;
- rlPreviewAreaPreviewArea.pack = true;
- rlPreviewAreaPreviewArea.center = true;
- rlPreviewAreaPreviewArea.spacing = 0;
- rlPreviewAreaPreviewArea.marginBottom = 0;
- rlPreviewAreaPreviewArea.marginTop = 0;
- rlPreviewAreaPreviewArea.marginRight = 0;
- rlPreviewAreaPreviewArea.marginLeft = 0;
- mPreviewArea.setLayout(rlPreviewAreaPreviewArea);
- GridData gdMPreviewArea = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
- gdMPreviewArea.widthHint = PREVIEW_AREA_WIDTH;
- mPreviewArea.setLayoutData(gdMPreviewArea);
-
- // Initial color
- Display display = parent.getDisplay();
- updateColor(display, mValues.background, true /*background*/);
- updateColor(display, mValues.foreground, false /*background*/);
-
- setSourceType(mValues.sourceType);
-
- new Label(mConfigurationArea, SWT.NONE);
- new Label(mConfigurationArea, SWT.NONE);
- new Label(mConfigurationArea, SWT.NONE);
-
- validatePage();
- }
-
- void configureAssetType(AssetType type) {
- if (mValues.sourceType != mShowingType) {
- mShowingType = mValues.sourceType;
- showGroup(type.needsForegroundScaling(), mScalingLabel, mScalingComposite);
- showGroup(type.needsShape(), mShapeLabel, mShapeComposite);
- showGroup(type.needsTheme(), mThemeLabel, mThemeComposite);
- showGroup(type.needsColors(), mBgColorLabel, mBgButton);
- showGroup(type.needsColors() && mValues.sourceType != SourceType.IMAGE,
- mFgColorLabel, mFgButton);
-
- Composite parent = mScalingLabel.getParent();
- parent.pack();
- parent.layout();
- }
- }
-
- private static void showGroup(boolean show, Control control1, Control control2) {
- showControl(show, control1);
- showControl(show, control2);
- }
-
- private static void showControl(boolean show, Control control) {
- Object data = control.getLayoutData();
- if (data instanceof GridData) {
- GridData gridData = (GridData) data;
- gridData.exclude = !show;
- }
- control.setVisible(show);
- }
-
- @Override
- public void setVisible(boolean visible) {
- super.setVisible(visible);
-
- // We update the image selection here rather than in {@link #createControl} because
- // that method is called when the wizard is created, and we want to wait until the
- // user has chosen a project before attempting to look up the right default image to use
- if (visible) {
- mShown = true;
-
- // Clear out old previews - important if the user goes back to page one, changes
- // asset type and steps into page 2 - at that point we arrive here and we might
- // display the old previews for a brief period until the preview delay timer expires.
- for (Control c : mPreviewArea.getChildren()) {
- c.dispose();
- }
- mPreviewArea.layout(true);
-
- // Update asset type configuration: will show/hide parameter controls depending
- // on which asset type is chosen
- AssetType type = mValues.type;
- assert type != null;
- configureAssetType(type);
-
- // Initial image - use the most recently used image, or the default launcher
- // icon created in our default projects, if there
- if (mValues.imagePath != null) {
- sImagePath = mValues.imagePath.getPath();
- }
- if (sImagePath == null) {
- IProject project = mValues.project;
- if (project != null) {
- IResource icon = project.findMember("res/drawable-hdpi/icon.png"); //$NON-NLS-1$
- if (icon != null) {
- IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot();
- IPath workspacePath = workspace.getLocation();
- sImagePath = workspacePath.append(icon.getFullPath()).toOSString();
- }
- }
- }
- if (sImagePath != null) {
- mValues.imagePath = new File(sImagePath);
- mImagePathText.setText(sImagePath);
- }
-
- try {
- mIgnore = true;
-
- mTrimCheckBox.setSelection(mValues.trim);
-
- // This doesn't work right -- not sure why. For now just use a plain slider
- // and subtract 10 from it to get the real range.
- //mPaddingSlider.setValues(0, -10, 50, 0, 1, 10);
- //mPaddingSlider.setSelection(10 + 15);
- mPaddingSlider.setSelection(mValues.padding + 10);
- mPercentLabel.setText(Integer.toString(mValues.padding) + '%');
-
- if (mValues.imagePath != null) {
- mImagePathText.setText(mValues.imagePath.getPath());
- }
-
- if (mValues.text != null) {
- mText.setText(mValues.text);
- }
-
- setSourceType(mValues.sourceType);
-
- // Shape=NONE does not apply for notification icons; it's needed for API < 9
- if (mValues.shape == Shape.NONE && mValues.type == AssetType.NOTIFICATION) {
- mValues.shape = Shape.SQUARE;
- }
-
- setShape(mValues.shape);
- mNoShapeRadio.setEnabled(mValues.type != AssetType.NOTIFICATION);
-
- if (mValues.sourceType == SourceType.CLIPART
- && mValues.clipartName != null) {
- updateClipartPreview();
- }
-
- // Initial color
- Display display = mPreviewArea.getDisplay();
- //updateColor(display, new RGB(0xa4, 0xc6, 0x39), true /*background*/);
- updateColor(display, mValues.background, true /*background*/);
- updateColor(display, mValues.foreground, false /*background*/);
-
- updateTrimOptions();
- } finally {
- mIgnore = false;
- }
-
- validatePage();
-
- requestUpdatePreview(true /*quickly*/);
-
- if (mTextRadio.getSelection()) {
- mText.setFocus();
- }
- }
- }
-
- private void setSourceType(CreateAssetSetWizardState.SourceType sourceType) {
- if (sourceType == CreateAssetSetWizardState.SourceType.IMAGE) {
- chooseForegroundTab(mImageRadio, mImageForm);
- } else if (sourceType == CreateAssetSetWizardState.SourceType.CLIPART) {
- chooseForegroundTab(mClipartRadio, mClipartForm);
- mChooseClipart.setFocus();
- } else if (sourceType == CreateAssetSetWizardState.SourceType.TEXT) {
- updateFontLabel();
- chooseForegroundTab(mTextRadio, mTextForm);
- mText.setFocus();
- }
- }
-
- private void updateTrimOptions() {
- // Trimming and padding is not available for clipart images; padding etc is
- // predefined to work well with action bar icons
- if (mValues.sourceType == SourceType.CLIPART
- && mValues.type == AssetType.ACTIONBAR) {
- mTrimCheckBox.setEnabled(false);
- mPaddingSlider.setEnabled(false);
- mValues.trim = false;
- } else if (!mTrimCheckBox.isEnabled()) {
- mTrimCheckBox.setEnabled(true);
- mPaddingSlider.setEnabled(true);
- }
- }
-
- private boolean validatePage() {
- String error = null;
- //String warning = null;
-
- if (mImageRadio.getSelection()) {
- String path = mValues.imagePath != null ? mValues.imagePath.getPath() : null;
- if (path == null || path.length() == 0) {
- error = "Select an image";
- } else if (path.equals(DEFAULT_LAUNCHER_ICON)) {
- // Silent
- } else if (!(new File(path).exists())) {
- error = String.format("%1$s does not exist", path);
- } else {
- // Preserve across wizard sessions
- sImagePath = path;
- }
- } else if (mTextRadio.getSelection()) {
- if (mValues.text.length() == 0) {
- error = "Enter text";
- }
- } else {
- assert mClipartRadio.getSelection();
- if (mValues.clipartName == null) {
- error = "Select clip art";
- }
- }
-
- setPageComplete(error == null);
- if (error != null) {
- setMessage(error, IMessageProvider.ERROR);
- //} else if (warning != null) {
- // setMessage(warning, IMessageProvider.WARNING);
- } else {
- setErrorMessage(null);
- setMessage(null);
- }
-
- return error == null;
- }
-
- @Override
- public boolean isPageComplete() {
- // Force user to reach second page before hitting Finish
- return mShown;
- }
-
- // ---- Implements ModifyListener ----
-
- @Override
- public void modifyText(ModifyEvent e) {
- if (mIgnore) {
- return;
- }
-
- if (e.getSource() == mImagePathText) {
- mValues.imagePath = new File(mImagePathText.getText().trim());
- requestUpdatePreview(false);
- } else if (e.getSource() == mText) {
- mValues.text = mText.getText().trim();
- requestUpdatePreview(false);
- }
-
- validatePage();
- }
-
- // ---- Implements SelectionListener ----
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- // Nothing to do
- }
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- if (mIgnore) {
- return;
- }
-
- Object source = e.getSource();
- boolean updateQuickly = true;
-
- // Tabs
- if (source == mImageRadio) {
- mValues.sourceType = CreateAssetSetWizardState.SourceType.IMAGE;
- chooseForegroundTab((Button) source, mImageForm);
- configureAssetType(mValues.type);
- updateTrimOptions();
- } else if (source == mClipartRadio) {
- mValues.sourceType = CreateAssetSetWizardState.SourceType.CLIPART;
- chooseForegroundTab((Button) source, mClipartForm);
- configureAssetType(mValues.type);
- updateTrimOptions();
- } else if (source == mTextRadio) {
- mValues.sourceType = CreateAssetSetWizardState.SourceType.TEXT;
- updateFontLabel();
- chooseForegroundTab((Button) source, mTextForm);
- configureAssetType(mValues.type);
- mText.setFocus();
- updateTrimOptions();
- }
-
- // Choose image file
- if (source == mPickImageButton) {
- FileDialog dialog = new FileDialog(mPickImageButton.getShell(), SWT.OPEN);
-
- String curLocation = mImagePathText.getText().trim();
- if (!curLocation.isEmpty()) {
- dialog.setFilterPath(curLocation);
- }
-
- String file = dialog.open();
- if (file != null) {
- mValues.imagePath = new File(file);
- mImagePathText.setText(file);
- }
- }
-
- // Enforce Radio Groups
- if (source == mCropRadio) {
- mCropRadio.setSelection(true); // Ensure that you can't toggle it off
- mCenterRadio.setSelection(false);
- mValues.crop = true;
- } else if (source == mCenterRadio) {
- mCenterRadio.setSelection(true);
- mCropRadio.setSelection(false);
- mValues.crop = false;
- }
- if (source == mSquareRadio) {
- mValues.shape = GraphicGenerator.Shape.SQUARE;
- setShape(mValues.shape);
- } else if (source == mCircleButton) {
- mValues.shape = GraphicGenerator.Shape.CIRCLE;
- setShape(mValues.shape);
- } else if (source == mNoShapeRadio) {
- mValues.shape = GraphicGenerator.Shape.NONE;
- setShape(mValues.shape);
- }
-
- if (source == mTrimCheckBox) {
- mValues.trim = mTrimCheckBox.getSelection();
- }
-
- if (source == mHoloDarkRadio) {
- mHoloDarkRadio.setSelection(true);
- mHoloLightRadio.setSelection(false);
- mValues.holoDark = true;
- } else if (source == mHoloLightRadio) {
- mHoloLightRadio.setSelection(true);
- mHoloDarkRadio.setSelection(false);
- mValues.holoDark = 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() {
- @Override
- public void mouseDown(MouseEvent event) {
- // Clicked on some of the sample art
- if (event.widget instanceof ImageControl) {
- ImageControl image = (ImageControl) event.widget;
- mValues.clipartName = (String) image.getData();
- close();
-
- updateClipartPreview();
- 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, true, -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);
- dlg.setText("Choose a new Background Color");
- RGB rgb = dlg.open();
- if (rgb != null) {
- // Dispose the old color, create the
- // new one, and set into the label
- mValues.background = rgb;
- updateColor(mBgButton.getDisplay(), rgb, true /*background*/);
- }
- } else if (source == mFgButton) {
- ColorDialog dlg = new ColorDialog(mFgButton.getShell());
- dlg.setRGB(mFgColor);
- dlg.setText("Choose a new Foreground Color");
- RGB rgb = dlg.open();
- if (rgb != null) {
- // Dispose the old color, create the
- // new one, and set into the label
- mValues.foreground = rgb;
- updateColor(mFgButton.getDisplay(), rgb, false /*background*/);
- }
- }
-
- if (source == mFontButton) {
- FontDialog dialog = new FontDialog(mFontButton.getShell());
- FontData[] fontList;
- if (mFontButton.getData() == null) {
- fontList = mFontButton.getDisplay().getFontList(
- mValues.getTextFont().getFontName(), true /*scalable*/);
- } else {
- fontList = mFontButton.getFont().getFontData();
- }
- dialog.setFontList(fontList);
- FontData data = dialog.open();
- if (data != null) {
- Font font = new Font(mFontButton.getDisplay(), dialog.getFontList());
- mFontButton.setFont(font);
- mFontButton.setData(font);
-
- // Always use a large font for the rendering, even though user is typically
- // picking small font sizes in the font chooser
- //int dpi = mFontButton.getDisplay().getDPI().y;
- //int height = (int) Math.round(fontData.getHeight() * dpi / 72.0);
- int fontHeight = new TextRenderUtil.Options().fontSize;
- FontData fontData = font.getFontData()[0];
- int awtStyle = java.awt.Font.PLAIN;
- int swtStyle = fontData.getStyle();
- if ((swtStyle & SWT.ITALIC) != 0) {
- awtStyle |= java.awt.Font.ITALIC;
- }
- if ((swtStyle & SWT.BOLD) != 0) {
- awtStyle = java.awt.Font.BOLD;
- }
- mValues.setTextFont(new java.awt.Font(fontData.getName(), awtStyle, fontHeight));
-
- updateFontLabel();
- mFontButton.getParent().pack();
- }
- }
-
- if (source == mPaddingSlider) {
- mValues.padding = getPadding();
- mPercentLabel.setText(Integer.toString(getPadding()) + '%');
-
- // When dragging the slider, only do periodic updates
- updateQuickly = false;
- }
-
- requestUpdatePreview(updateQuickly);
- }
-
- @SuppressWarnings("unused") // SWT constructors have side effects and are not unused
- private void updateClipartPreview() {
- for (Control c : mClipartPreviewPanel.getChildren()) {
- c.dispose();
- }
- if (mClipartPreviewPanel.getChildren().length == 0) {
- try {
- BufferedImage icon = GraphicGenerator.getClipartIcon(
- mValues.clipartName);
- if (icon != null) {
- Display display = mClipartForm.getDisplay();
- Image swtImage = SwtUtils.convertToSwt(display, icon,
- true, -1);
- new ImageControl(mClipartPreviewPanel,
- SWT.NONE, swtImage);
- }
- } catch (IOException e1) {
- AdtPlugin.log(e1, null);
- }
- mClipartPreviewPanel.pack();
- mClipartPreviewPanel.layout();
- }
- }
-
- private void setShape(GraphicGenerator.Shape shape) {
- if (shape == GraphicGenerator.Shape.SQUARE) {
- mSquareRadio.setSelection(true);
- mCircleButton.setSelection(false);
- mNoShapeRadio.setSelection(false);
- } else if (shape == GraphicGenerator.Shape.CIRCLE) {
- mCircleButton.setSelection(true);
- mSquareRadio.setSelection(false);
- mNoShapeRadio.setSelection(false);
- } else if (shape == GraphicGenerator.Shape.NONE) {
- mNoShapeRadio.setSelection(true);
- mCircleButton.setSelection(false);
- mSquareRadio.setSelection(false);
- } else {
- assert false : shape;
- }
- }
-
- private void updateFontLabel() {
- mFontButton.setText(mValues.getTextFont().getFontName());
- }
-
- private int getPadding() {
- // Shifted - see comment for mPaddingSlider construction for an explanation
- return mPaddingSlider.getSelection() - 10;
- }
-
- private void chooseForegroundTab(Button newButton, Composite newArea) {
- if (newButton.getSelection()) {
- mImageRadio.setSelection(false);
- mClipartRadio.setSelection(false);
- mTextRadio.setSelection(false);
- newButton.setSelection(true);
- StackLayout stackLayout = (StackLayout) mForegroundArea.getLayout();
- stackLayout.topControl = newArea;
- mForegroundArea.layout();
- } else {
- // Treat it as a radio button: you can't click to turn it off, you have to
- // click on one of the other buttons
- newButton.setSelection(true);
- }
- }
-
- /**
- * Delay updates of the preview, to ensure that the SWT UI acts immediately (to handle
- * radio group selections etc).
- *
- * @param quickly if true, update the previews soon, otherwise schedule one a bit later
- */
- private void requestUpdatePreview(boolean quickly) {
- if (mTimerPending) {
- return;
- }
- mTimerPending = true;
-
- final Runnable timer = new Runnable() {
- @Override
- public void run() {
- mTimerPending = false;
- updatePreview();
- }
- };
-
- mPreviewArea.getDisplay().timerExec(quickly ? 10 : 250, timer);
- }
-
- private void updatePreview() {
- Display display = mPreviewArea.getDisplay();
-
- for (Control c : mPreviewArea.getChildren()) {
- c.dispose();
- }
-
- if (!validatePage()) {
- return;
- }
-
- Map<String, Map<String, BufferedImage>> map = generateImages(mValues,
- true /*previewOnly*/, this);
- for (Entry<String, Map<String, BufferedImage>> categoryEntry : map.entrySet()) {
- String category = categoryEntry.getKey();
- if (category.length() > 0) {
- Label nameLabel = new Label(mPreviewArea, SWT.NONE);
- nameLabel.setText(String.format("%1$s:", category));
- RowData rowData = new RowData();
- nameLabel.setLayoutData(rowData);
- // Ensure these get their own rows
- rowData.width = PREVIEW_AREA_WIDTH;
- }
-
- Map<String, BufferedImage> images = categoryEntry.getValue();
- for (Entry<String, BufferedImage> entry : images.entrySet()) {
- BufferedImage image = entry.getValue();
- Image swtImage = SwtUtils.convertToSwt(display, image, true, -1);
- if (swtImage != null) {
- @SuppressWarnings("unused") // Has side effect
- ImageControl imageControl = new ImageControl(mPreviewArea, SWT.NONE, swtImage);
- }
- }
- }
-
- mPreviewArea.layout(true);
- }
-
- /**
- * Generate images using the given wizard state
- *
- * @param mValues the state to use
- * @param previewOnly whether we are only generating previews
- * @param page if non null, a wizard page to write error messages to
- * @return a map of image objects
- */
- public static Map<String, Map<String, BufferedImage>> generateImages(
- @NonNull CreateAssetSetWizardState mValues,
- boolean previewOnly,
- @Nullable WizardPage page) {
- // Map of ids to images: Preserve insertion order (the densities)
- Map<String, Map<String, BufferedImage>> categoryMap =
- new LinkedHashMap<String, Map<String, BufferedImage>>();
-
- AssetType type = mValues.type;
- boolean trim = mValues.trim;
-
- BufferedImage sourceImage = null;
- switch (mValues.sourceType) {
- case IMAGE: {
- // Load the image
- // TODO: Only do this when the source image type is image
- String path = mValues.imagePath != null ? mValues.imagePath.getPath() : "";
- if (path.length() == 0) {
- if (page != null) {
- page.setErrorMessage("Enter a filename");
- }
- return Collections.emptyMap();
- }
- if (!path.equals(DEFAULT_LAUNCHER_ICON)) {
- File file = new File(path);
- if (!file.isFile()) {
- if (page != null) {
- page.setErrorMessage(String.format("%1$s does not exist", file.getPath()));
- }
- return Collections.emptyMap();
- }
- }
-
- if (page != null) {
- page.setErrorMessage(null);
- }
- try {
- sourceImage = mValues.getCachedImage(path, false);
- if (sourceImage != null) {
- if (trim) {
- sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB);
- }
- if (mValues.padding != 0) {
- sourceImage = Util.paddedImage(sourceImage, mValues.padding);
- }
- }
- } catch (IOException ioe) {
- if (page != null) {
- page.setErrorMessage(ioe.getLocalizedMessage());
- }
- }
- break;
- }
- case CLIPART: {
- try {
- sourceImage = GraphicGenerator.getClipartImage(mValues.clipartName);
-
- boolean isActionBar = mValues.type == AssetType.ACTIONBAR;
- if (trim && !isActionBar) {
- sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB);
- }
-
- if (type.needsColors()) {
- RGB fg = mValues.foreground;
- int color = 0xFF000000 | (fg.red << 16) | (fg.green << 8) | fg.blue;
- Paint paint = new java.awt.Color(color);
- sourceImage = Util.filledImage(sourceImage, paint);
- }
-
- int padding = mValues.padding;
- if (padding != 0 && !isActionBar) {
- sourceImage = Util.paddedImage(sourceImage, padding);
- }
- } catch (IOException e) {
- AdtPlugin.log(e, null);
- return categoryMap;
- }
- break;
- }
- case TEXT: {
- String text = mValues.text;
- TextRenderUtil.Options options = new TextRenderUtil.Options();
- options.font = mValues.getTextFont();
- int color;
- if (type.needsColors()) {
- RGB fg = mValues.foreground;
- color = 0xFF000000 | (fg.red << 16) | (fg.green << 8) | fg.blue;
- } else {
- color = 0xFFFFFFFF;
- }
- options.foregroundColor = color;
- sourceImage = TextRenderUtil.renderTextImage(text, mValues.padding, options);
-
- if (trim) {
- sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB);
- }
-
- int padding = mValues.padding;
- if (padding != 0) {
- sourceImage = Util.paddedImage(sourceImage, padding);
- }
- break;
- }
- }
-
- GraphicGenerator generator = null;
- GraphicGenerator.Options options = null;
- switch (type) {
- case LAUNCHER: {
- generator = new LauncherIconGenerator();
- LauncherIconGenerator.LauncherOptions launcherOptions =
- new LauncherIconGenerator.LauncherOptions();
- launcherOptions.shape = mValues.shape;
- launcherOptions.crop = mValues.crop;
- launcherOptions.style = GraphicGenerator.Style.SIMPLE;
-
- RGB bg = mValues.background;
- int color = (bg.red << 16) | (bg.green << 8) | bg.blue;
- launcherOptions.backgroundColor = color;
- // Flag which tells the generator iterator to include a web graphic
- launcherOptions.isWebGraphic = !previewOnly;
- options = launcherOptions;
-
- break;
- }
- case MENU:
- generator = new MenuIconGenerator();
- options = new GraphicGenerator.Options();
- break;
- case ACTIONBAR: {
- generator = new ActionBarIconGenerator();
- ActionBarIconGenerator.ActionBarOptions actionBarOptions =
- new ActionBarIconGenerator.ActionBarOptions();
- actionBarOptions.theme = mValues.holoDark
- ? ActionBarIconGenerator.Theme.HOLO_DARK
- : ActionBarIconGenerator.Theme.HOLO_LIGHT;
- actionBarOptions.sourceIsClipart = (mValues.sourceType == SourceType.CLIPART);
-
- options = actionBarOptions;
- break;
- }
- case NOTIFICATION: {
- generator = new NotificationIconGenerator();
- options = new NotificationIconGenerator.NotificationOptions();
- break;
- }
- case TAB:
- generator = new TabIconGenerator();
- options = new TabIconGenerator.TabOptions();
- break;
- default:
- AdtPlugin.log(IStatus.ERROR, "Unsupported asset type: %1$s", type);
- return categoryMap;
- }
-
- options.sourceImage = sourceImage;
-
- IProject project = mValues.project;
- if (mValues.minSdk != -1) {
- options.minSdk = mValues.minSdk;
- } else {
- Pair<Integer, Integer> v = ManifestInfo.computeSdkVersions(project);
- options.minSdk = v.getFirst();
- }
-
- String baseName = mValues.outputName;
- generator.generate(null, categoryMap, mValues, options, baseName);
-
- return categoryMap;
- }
-
- /**
- * Generate custom icons into the project based on the asset studio wizard
- * state
- *
- * @param newProject the project to write into
- * @param values the wizard state to read configuration settings from
- * @param previewOnly whether we are only generating a preview. For example,
- * the launcher icons won't generate a huge 512x512 web graphic
- * in preview mode
- * @param page a wizard page to write error messages to, or null
- */
- public static void generateIcons(final IProject newProject,
- @NonNull CreateAssetSetWizardState values,
- boolean previewOnly,
- @Nullable WizardPage page) {
- // Generate the custom icons
- Map<String, Map<String, BufferedImage>> categories = generateImages(values,
- false /*previewOnly*/, page);
- for (Map<String, BufferedImage> previews : categories.values()) {
- for (Map.Entry<String, BufferedImage> entry : previews.entrySet()) {
- String relativePath = entry.getKey();
- IPath dest = new Path(relativePath);
- IFile file = newProject.getFile(dest);
-
- // In case template already created icons (should remove that)
- // remove them first
- if (file.exists()) {
- try {
- file.delete(true, new NullProgressMonitor());
- } catch (CoreException e) {
- AdtPlugin.log(e, null);
- }
- }
- AdtUtils.createWsParentDirectory(file.getParent());
- BufferedImage image = entry.getValue();
-
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- try {
- ImageIO.write(image, "PNG", stream); //$NON-NLS-1$
- byte[] bytes = stream.toByteArray();
- InputStream is = new ByteArrayInputStream(bytes);
- file.create(is, true /*force*/, null /*progress*/);
- } catch (IOException e) {
- AdtPlugin.log(e, null);
- } catch (CoreException e) {
- AdtPlugin.log(e, null);
- }
-
- try {
- file.getParent().refreshLocal(1, new NullProgressMonitor());
- } catch (CoreException e) {
- AdtPlugin.log(e, null);
- }
- }
- }
- }
-
- private void updateColor(Display display, RGB color, boolean isBackground) {
- // Button.setBackgroundColor does not work (at least not on OSX) so
- // we instead have to use Button.setImage with an image of the given
- // color
- BufferedImage coloredImage = ImageUtils.createColoredImage(60, 20, color);
- Image image = SwtUtils.convertToSwt(display, coloredImage, false, -1);
-
- if (isBackground) {
- mBgColor = color;
- mBgButton.setImage(image);
- } else {
- mFgColor = color;
- mFgButton.setImage(image);
- }
- }
-}
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
deleted file mode 100644
index 6b1001253..000000000
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/CreateAssetSetWizard.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.eclipse.org/org/documents/epl-v10.php
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.ide.eclipse.adt.internal.assetstudio;
-
-import com.android.ide.eclipse.adt.AdtConstants;
-import com.android.ide.eclipse.adt.AdtPlugin;
-import com.android.ide.eclipse.adt.AdtUtils;
-import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor;
-import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
-import com.android.utils.Pair;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IPath;
-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;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPartSite;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.FileEditorInput;
-
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.imageio.ImageIO;
-
-/**
- * Wizard for creating a new icon set
- */
-public class CreateAssetSetWizard extends Wizard implements INewWizard {
- private ChooseAssetTypePage mChooseAssetPage;
- private ConfigureAssetSetPage mConfigureAssetPage;
- private IProject mInitialProject;
- private List<IResource> mCreatedFiles;
- private CreateAssetSetWizardState mValues = new CreateAssetSetWizardState();
-
- /** Creates a new asset set wizard */
- public CreateAssetSetWizard() {
- setWindowTitle("Create Asset Set");
- }
-
- @Override
- public void addPages() {
- mValues.project = mInitialProject;
-
- mChooseAssetPage = new ChooseAssetTypePage(mValues);
- mConfigureAssetPage = new ConfigureAssetSetPage(mValues);
-
- addPage(mChooseAssetPage);
- addPage(mConfigureAssetPage);
- }
-
- @Override
- public boolean performFinish() {
- Map<String, Map<String, BufferedImage>> categories =
- ConfigureAssetSetPage.generateImages(mValues, false, null);
-
- IProject project = mValues.project;
-
- // Write out the images into the project
- boolean yesToAll = false;
- mCreatedFiles = new ArrayList<IResource>();
-
- for (Map<String, BufferedImage> previews : categories.values()) {
- for (Map.Entry<String, BufferedImage> entry : previews.entrySet()) {
- String relativePath = entry.getKey();
- IPath dest = new Path(relativePath);
- IFile file = project.getFile(dest);
- if (file.exists()) {
- // 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) {
- AdtPlugin.log(e, null);
- }
- }
-
- AdtUtils.createWsParentDirectory(file.getParent());
- BufferedImage image = entry.getValue();
-
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- try {
- ImageIO.write(image, "PNG", stream); //$NON-NLS-1$
- byte[] bytes = stream.toByteArray();
- InputStream is = new ByteArrayInputStream(bytes);
- file.create(is, true /*force*/, null /*progress*/);
- mCreatedFiles.add(file);
- } catch (IOException e) {
- AdtPlugin.log(e, null);
- } catch (CoreException e) {
- AdtPlugin.log(e, null);
- }
-
- try {
- file.getParent().refreshLocal(1, new NullProgressMonitor());
- } catch (CoreException e) {
- AdtPlugin.log(e, null);
- }
- }
- }
-
- // Finally select the files themselves
- selectFiles(project, mCreatedFiles);
-
- return true;
- }
-
- private void selectFiles(IProject project, List<? extends IResource> createdFiles) {
- // Attempt to select the newly created files in the Package Explorer
- IWorkbench workbench = AdtPlugin.getDefault().getWorkbench();
- IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
- IViewPart viewPart = page.findView(JavaUI.ID_PACKAGES);
- if (viewPart != null) {
- IWorkbenchPartSite site = viewPart.getSite();
- IJavaProject javaProject = null;
- try {
- javaProject = BaseProjectHelper.getJavaProject(project);
- } catch (CoreException e) {
- AdtPlugin.log(e, null);
- }
- final ISelectionProvider provider = site.getSelectionProvider();
- if (provider != null) {
- List<TreePath> pathList = new ArrayList<TreePath>();
- for (IResource file : createdFiles) {
- // Create a TreePath for the given file,
- // which should be the JavaProject, followed by the folders down to
- // the final file.
- List<Object> segments = new ArrayList<Object>();
- segments.add(file);
- IContainer folder = file.getParent();
- if (folder != null && !(folder instanceof IProject)) {
- segments.add(folder);
- // res folder
- folder = folder.getParent();
- if (folder != null && !(folder instanceof IProject)) {
- segments.add(folder);
- }
- }
- // project
- segments.add(javaProject);
-
- Collections.reverse(segments);
- TreePath path = new TreePath(segments.toArray());
- pathList.add(path);
-
- // IDEA: Maybe normalize the files backwards (IFile objects aren't unique)
- // by maybe using the package explorer icons instead
- }
-
- TreePath[] paths = pathList.toArray(new TreePath[pathList.size()]);
- final TreeSelection selection = new TreeSelection(paths);
-
- provider.setSelection(selection);
-
- // Workaround: The above doesn't always work; it will frequently select
- // some siblings of the real files. I've tried a number of workarounds:
- // normalizing the IFile objects by looking up the canonical ones via
- // their relative paths from the project; deferring execution with
- // Display.asyncRun; first calling select on the parents, etc.
- // However, it turns out a simple workaround works best: Calling this
- // method TWICE. The first call seems to expand all the necessary parents,
- // and the second call ensures that the correct children are selected!
- provider.setSelection(selection);
-
- viewPart.setFocus();
- }
- }
- }
-
- /** Sets the initial project to be used by the wizard */
- void setProject(IProject project) {
- mInitialProject = project;
- mValues.project = project;
- }
-
- @Override
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- setHelpAvailable(false);
-
- mInitialProject = guessProject(selection);
- mValues.project = mInitialProject;
- }
-
- private IProject guessProject(IStructuredSelection selection) {
- if (selection == null) {
- return null;
- }
-
- for (Object element : selection.toList()) {
- if (element instanceof IAdaptable) {
- IResource res = (IResource) ((IAdaptable) element).getAdapter(IResource.class);
- IProject project = res != null ? res.getProject() : null;
-
- // Is this an Android project?
- try {
- if (project == null || !project.hasNature(AdtConstants.NATURE_DEFAULT)) {
- continue;
- }
- } catch (CoreException e) {
- // checking the nature failed, ignore this resource
- continue;
- }
-
- return project;
- } else if (element instanceof Pair<?, ?>) {
- // Pair of Project/String
- @SuppressWarnings("unchecked")
- Pair<IProject, String> pair = (Pair<IProject, String>) element;
- return pair.getFirst();
- }
- }
-
- // Try to figure out the project from the active editor
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if (window != null) {
- IWorkbenchPage page = window.getActivePage();
- if (page != null) {
- IEditorPart activeEditor = page.getActiveEditor();
- if (activeEditor instanceof AndroidXmlEditor) {
- Object input = ((AndroidXmlEditor) activeEditor).getEditorInput();
- if (input instanceof FileEditorInput) {
- FileEditorInput fileInput = (FileEditorInput) input;
- return fileInput.getFile().getProject();
- }
- }
- }
- }
-
- IJavaProject[] projects = AdtUtils.getOpenAndroidProjects();
- if (projects != null && projects.length == 1) {
- return projects[0].getProject();
- }
-
- return null;
- }
-
- /**
- * Returns the list of files created by the wizard. This method will return
- * null if {@link #performFinish()} has not yet been called.
- *
- * @return a list of files created by the wizard, or null
- */
- List<IResource> getCreatedFiles() {
- return mCreatedFiles;
- }
-}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/CreateAssetSetWizardState.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/CreateAssetSetWizardState.java
deleted file mode 100644
index d3a0f42e9..000000000
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/CreateAssetSetWizardState.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.eclipse.org/org/documents/epl-v10.php
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.ide.eclipse.adt.internal.assetstudio;
-
-import static com.android.ide.eclipse.adt.internal.wizards.templates.NewProjectWizard.DEFAULT_LAUNCHER_ICON;
-
-import com.android.annotations.NonNull;
-import com.android.assetstudiolib.GraphicGenerator;
-import com.android.assetstudiolib.GraphicGenerator.Shape;
-import com.android.assetstudiolib.GraphicGeneratorContext;
-import com.android.ide.eclipse.adt.AdtPlugin;
-import com.android.ide.eclipse.adt.internal.wizards.templates.TemplateManager;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.swt.graphics.RGB;
-
-import java.awt.Font;
-import java.awt.GraphicsEnvironment;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.imageio.ImageIO;
-
-/**
- * Value object for the AssetStudio wizard. These values are both set by the
- * wizard as well as read by the wizard initially, so passing in a configured
- * {@link CreateAssetSetWizardState} to the icon generator is possible.
- */
-public class CreateAssetSetWizardState implements GraphicGeneratorContext {
- /**
- * The type of asset being created. This field is static such that when you
- * bring up the wizard repeatedly (for example to create multiple
- * notification icons) you don't have to keep selecting the same type over
- * and over.
- */
- public static AssetType sLastType = AssetType.LAUNCHER;
-
- /** The type of asset to be created */
- public AssetType type = sLastType;
-
- /** The base name to use for the created icons */
- public String outputName;
-
- /** The minimum SDK being targeted */
- public int minSdk = -1;
-
- /** The project to create the icons into */
- public IProject project;
-
- /** Whether empty space around the source image should be trimmed */
- public boolean trim = true;
-
- /** The type of source the icon is being created from */
- public SourceType sourceType = SourceType.TEXT;
-
- /** If {@link #sourceType} is a {@link SourceType#CLIPART}, the name of the clipart image */
- public String clipartName;
-
- /** If {@link #sourceType} is a {@link SourceType#IMAGE}, the path to the input image */
- public File imagePath;
-
- /** If {@link #sourceType} is a {@link SourceType#TEXT}, the text to render */
- public String text = "aA";
-
- /** The amount of padding to add around the source image */
- public int padding = 15;
-
- /** The background shape */
- public Shape shape = Shape.SQUARE;
-
- /** Whether the image should be cropped */
- public boolean crop;
-
- /** Whether to use Holo Dark for action bar icons */
- public boolean holoDark;
-
- /** The background color to use for the shape (unless the shape is {@link Shape#NONE} */
- public RGB background = new RGB(0xff, 0x00, 0x00);
-
- /** The background color to use for the text or clipart (unless shape is {@link Shape#NONE} */
- public RGB foreground = new RGB(0x00, 0x00, 0x00);
-
- /** If {@link #sourceType} is a {@link SourceType#TEXT}, the font of the text to render */
- private Font mTextFont;
-
- private Map<String, BufferedImage> mImageCache = null;
-
- /**
- * Gets the text font to be used for text rendering if the
- * {@link #sourceType} is a {@link SourceType#TEXT}
- *
- * @return the text font
- */
- @NonNull
- public Font getTextFont() {
- if (mTextFont == null) {
- GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
- String[] fontNames = env.getAvailableFontFamilyNames();
- for (String familyName : fontNames) {
- if (familyName.equals("Helvetica")) {
- mTextFont = new java.awt.Font(familyName, java.awt.Font.BOLD, 512);
- break;
- }
- }
- if (mTextFont == null) {
- for (String familyName : fontNames) {
- if (familyName.equals("Arial")) {
- mTextFont = new java.awt.Font(familyName, java.awt.Font.BOLD, 512);
- break;
- }
- }
-
- if (mTextFont == null) {
- mTextFont = new java.awt.Font("SansSerif", java.awt.Font.BOLD, 512);
- }
- }
- }
-
- return mTextFont;
- }
-
- /**
- * Sets the text font to be used for text rendering if the
- * {@link #sourceType} is a {@link SourceType#TEXT}
- *
- * @param textFont the font to use
- */
- public void setTextFont(@NonNull Font textFont) {
- mTextFont = textFont;
- }
-
- /** Types of sources that the asset studio can use to generate icons from */
- public enum SourceType {
- /** Generate the icon using the image pointed to by {@link #imagePath} */
- IMAGE,
-
- /** Generate the icon using the clipart named by {@link #clipartName} */
- CLIPART,
-
- /** Generate the icon using the text in {@link #text} */
- TEXT
- }
-
- // ---- Implements GraphicGeneratorContext ----
-
- @Override
- public BufferedImage loadImageResource(String relativeName) {
- try {
- return getCachedImage(relativeName, true);
- } catch (IOException e) {
- AdtPlugin.log(e, null);
- return null;
- }
- }
-
- BufferedImage getCachedImage(String path, boolean isPluginRelative)
- throws IOException {
- BufferedImage image = mImageCache != null ? mImageCache.get(path) : null;
- if (image == null) {
- image = getImage(path, isPluginRelative);
- if (mImageCache == null) {
- mImageCache = new HashMap<String, BufferedImage>();
- }
- mImageCache.put(path, image);
- }
-
- return image;
- }
-
- @NonNull
- static BufferedImage getImage(@NonNull String path, boolean isPluginRelative)
- throws IOException {
- BufferedImage image = null;
- if (isPluginRelative) {
- image = GraphicGenerator.getStencilImage(path);
- } else {
- if (path.equals(DEFAULT_LAUNCHER_ICON)) {
- File file = TemplateManager.getTemplateLocation(
- "projects/NewAndroidApplication/root/res/drawable-xhdpi/ic_launcher.png"); //$NON-NLS-1$
- if (file != null) {
- path = file.getPath();
- } else {
- image = GraphicGenerator.getStencilImage("user.png");
- }
- }
-
- File file = new File(path);
-
- // Requires Batik
- //if (file.getName().endsWith(DOT_SVG)) {
- // image = loadSvgImage(file);
- //}
-
- if (image == null) {
- image = ImageIO.read(file);
- }
- }
-
- if (image == null) {
- image = new BufferedImage(1,1, BufferedImage.TYPE_INT_ARGB);
- }
-
- return image;
- }
-
- // This requires Batik for SVG rendering
- //
- //public static BufferedImage loadSvgImage(File file) {
- // BufferedImageTranscoder transcoder = new BufferedImageTranscoder();
- //
- // String svgURI = file.toURI().toString();
- // TranscoderInput input = new TranscoderInput(svgURI);
- //
- // try {
- // transcoder.transcode(input, null);
- // } catch (TranscoderException e) {
- // e.printStackTrace();
- // return null;
- // }
- //
- // return transcoder.decodedImage;
- //}
- //
- ///**
- // * A dummy implementation of an {@link ImageTranscoder} that simply stores the {@link
- // * BufferedImage} generated by the SVG library.
- // */
- //private static class BufferedImageTranscoder extends ImageTranscoder {
- // public BufferedImage decodedImage;
- //
- // @Override
- // public BufferedImage createImage(int w, int h) {
- // return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
- // }
- //
- // @Override
- // public void writeImage(BufferedImage image, TranscoderOutput output)
- // throws TranscoderException {
- // this.decodedImage = image;
- // }
- //}
-}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/OpenCreateAssetSetWizardAction.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/OpenCreateAssetSetWizardAction.java
deleted file mode 100644
index 09cc32512..000000000
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/assetstudio/OpenCreateAssetSetWizardAction.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.eclipse.org/org/documents/epl-v10.php
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.ide.eclipse.adt.internal.assetstudio;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.ui.actions.AbstractOpenWizardAction;
-import org.eclipse.ui.INewWizard;
-
-import java.util.List;
-
-/** An action for opening the Create Icon Set wizard */
-public class OpenCreateAssetSetWizardAction extends AbstractOpenWizardAction {
- private IProject mProject;
- private CreateAssetSetWizard mWizard;
-
- /**
- * Creates a new {@link #OpenCreateAssetSetWizardAction} instance
- *
- * @param project the initial project to associate with the wizard
- */
- public OpenCreateAssetSetWizardAction(IProject project) {
- mProject = project;
- }
-
-
- @Override
- protected INewWizard createWizard() throws CoreException {
- mWizard = new CreateAssetSetWizard();
- mWizard.setProject(mProject);
- return mWizard;
- }
-
- /**
- * Returns the list of files created by the wizard. Must only be called
- * after this action's {@link #run()} method has been called. May return
- * null if the user cancels out of the wizard.
- *
- * @return a list of files created by the wizard, or null
- */
- public List<IResource> getCreatedFiles() {
- return mWizard.getCreatedFiles();
- }
-}