diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalEditorPart.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalEditorPart.java index 45a42e283..3504fe741 100755 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalEditorPart.java +++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/GraphicalEditorPart.java @@ -58,12 +58,12 @@ import org.eclipse.gef.ui.parts.SelectionSynchronizer; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; -import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.PartInitException; @@ -112,7 +112,8 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE private ConfigurationComposite mConfigComposite; /** The sash that splits the palette from the canvas. */ - private SashForm mSash; + private SashForm mSashPalette; + private SashForm mSashError; /** The palette displayed on the left of the sash. */ private PaletteComposite mPalette; @@ -120,6 +121,8 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE /** The layout canvas displayed o the right of the sash. */ private LayoutCanvas mLayoutCanvas; + private StyledText mErrorLabel; + /** The {@link FolderConfiguration} being edited. */ private FolderConfiguration mEditedConfig; @@ -135,14 +138,9 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE private ConfigListener mConfigListener; - private Composite mCanvasOrErrorStack; - - private StackLayout mCanvasOrErrorStackLayout; - - private Label mErrorLabel; - private ReloadListener mReloadListener; + public GraphicalEditorPart(LayoutEditor layoutEditor) { mLayoutEditor = layoutEditor; setPartName("Graphical Layout"); @@ -202,7 +200,8 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE @Override public void createPartControl(Composite parent) { - mClipboard = new Clipboard(parent.getDisplay()); + Display d = parent.getDisplay(); + mClipboard = new Clipboard(d); GridLayout gl = new GridLayout(1, false); parent.setLayout(gl); @@ -213,33 +212,28 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE mConfigComposite = new ConfigurationComposite(mConfigListener, parent, SWT.BORDER); mConfigComposite.updateUIFromResources(); - mSash = new SashForm(parent, SWT.HORIZONTAL); - mSash.setLayoutData(new GridData(GridData.FILL_BOTH)); + mSashPalette = new SashForm(parent, SWT.HORIZONTAL); + mSashPalette.setLayoutData(new GridData(GridData.FILL_BOTH)); - mPalette = new PaletteComposite(mSash); + mPalette = new PaletteComposite(mSashPalette); - mCanvasOrErrorStack = new Composite(mSash, SWT.NONE); - mCanvasOrErrorStackLayout = new StackLayout(); - mCanvasOrErrorStack.setLayout(mCanvasOrErrorStackLayout); + mSashError = new SashForm(mSashPalette, SWT.VERTICAL | SWT.BORDER); + mSashError.setLayoutData(new GridData(GridData.FILL_BOTH)); - mLayoutCanvas = new LayoutCanvas(mCanvasOrErrorStack); - mErrorLabel = new Label(mCanvasOrErrorStack, SWT.NONE); - mCanvasOrErrorStackLayout.topControl = mLayoutCanvas; + mLayoutCanvas = new LayoutCanvas(mSashError, SWT.NONE); + mErrorLabel = new StyledText(mSashError, SWT.READ_ONLY); + mErrorLabel.setEditable(false); + mErrorLabel.setBackground(d.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + mErrorLabel.setForeground(d.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); - mSash.setWeights(new int[] { 20, 80 }); + mSashPalette.setWeights(new int[] { 20, 80 }); + mSashError.setWeights(new int[] { 80, 20 }); + mSashError.setMaximizedControl(mLayoutCanvas); // Initialize the state reloadPalette(); } - /** Switches the stack to display the canvas and hide the error label. */ - private void displayCanvas() { - if (mCanvasOrErrorStackLayout.topControl != mLayoutCanvas) { - mCanvasOrErrorStackLayout.topControl = mLayoutCanvas; - mCanvasOrErrorStack.layout(); - } - } - /** * Switches the stack to display the error label and hide the canvas. * @param errorFormat The new error to display if not null. @@ -249,10 +243,12 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE if (errorFormat != null) { mErrorLabel.setText(String.format(errorFormat, parameters)); } - if (mCanvasOrErrorStackLayout.topControl != mErrorLabel) { - mCanvasOrErrorStackLayout.topControl = mErrorLabel; - mCanvasOrErrorStack.layout(); - } + mSashError.setMaximizedControl(null); + } + + /** Displays the canvas and hides the error label. */ + private void hideError() { + mSashError.setMaximizedControl(mLayoutCanvas); } @Override @@ -275,6 +271,10 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE super.dispose(); } + /** + * Listens to changes from the Configuration UI banner and triggers layout rendering when + * changed. Also provide the Configuration UI with the list of resources/layout to display. + */ private class ConfigListener implements IConfigListener { /** @@ -542,6 +542,9 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE } } + /** + * Listens to target changed in the current project, to trigger a new layout rendering. + */ private class TargetListener implements ITargetChangeListener { public void onProjectTargetChange(IProject changedProject) { @@ -861,19 +864,13 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE configuredProjectRes, frameworkResources, mProjectCallback, mLogger); + mLayoutCanvas.setResult(result); + // update the UiElementNode with the layout info. if (result.getSuccess() == ILayoutResult.SUCCESS) { - - // Update the image and make sure we're displaying the canvas. - mLayoutCanvas.setImage(result.getImage()); - displayCanvas(); - - updateNodeWithBounds(result.getRootView()); + hideError(); } else { displayError(result.getErrorMessage()); - - // Reset the edit data for all the nodes. - resetNodeBounds(model); } model.refreshUi(); @@ -957,6 +954,7 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE return mConfigComposite.getScreenBounds(); } + /** @deprecated for GLE2 */ private void resetNodeBounds(UiElementNode node) { node.setEditData(null); @@ -966,6 +964,7 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE } } + /** @deprecated for GLE2 */ private void updateNodeWithBounds(ILayoutViewInfo r) { if (r != null) { // update the node itself, as the viewKey is the XML node in this implementation. diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutCanvas.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutCanvas.java index 976554c71..0ce381d5c 100755 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutCanvas.java +++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutCanvas.java @@ -16,11 +16,8 @@ package com.android.ide.eclipse.adt.internal.editors.layout; -import java.awt.image.BufferedImage; -import java.awt.image.DataBufferInt; -import java.awt.image.Raster; +import com.android.layoutlib.api.ILayoutResult; -import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.GC; @@ -30,6 +27,10 @@ import org.eclipse.swt.graphics.PaletteData; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; +import java.awt.image.BufferedImage; +import java.awt.image.DataBufferInt; +import java.awt.image.Raster; + /** * Displays the image rendered by the {@link GraphicalEditorPart} and handles * the interaction with the widgets. @@ -50,8 +51,8 @@ public class LayoutCanvas extends Canvas { private Image mImage; - public LayoutCanvas(Composite parent) { - super(parent, SWT.BORDER); + public LayoutCanvas(Composite parent, int style) { + super(parent, style); addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { @@ -60,7 +61,13 @@ public class LayoutCanvas extends Canvas { }); } - public void setImage(BufferedImage awtImage) { + public void setResult(ILayoutResult result) { + if (result.getSuccess() == ILayoutResult.SUCCESS) { + setImage(result.getImage()); + } + } + + private void setImage(BufferedImage awtImage) { // Convert the AWT image into an SWT image. int width = awtImage.getWidth(); int height = awtImage.getHeight(); diff --git a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java index 0ff4dfc15..dc8aef894 100644 --- a/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java +++ b/tools/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/uimodel/UiElementNode.java @@ -73,12 +73,12 @@ import java.util.Map.Entry; * an element is selected. The {@link AttributeDescriptor} are used property descriptors. */ public class UiElementNode implements IPropertySource { - + /** List of prefixes removed from android:id strings when creating short descriptions. */ private static String[] ID_PREFIXES = { "@android:id/", //$NON-NLS-1$ "@+id/", "@id/", "@+", "@" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - + /** The element descriptor for the node. Always present, never null. */ private ElementDescriptor mDescriptor; /** The parent element node in the UI model. It is null for a root element or until @@ -117,17 +117,17 @@ public class UiElementNode implements IPropertySource { private boolean mHasError; /** Temporary data used by the editors. This data is not sync'ed with the XML */ private Object mEditData; - + /** * Creates a new {@link UiElementNode} described by a given {@link ElementDescriptor}. - * + * * @param elementDescriptor The {@link ElementDescriptor} for the XML node. Cannot be null. */ public UiElementNode(ElementDescriptor elementDescriptor) { mDescriptor = elementDescriptor; clearContent(); } - + /** * Clears the {@link UiElementNode} by resetting the children list and * the {@link UiAttributeNode}s list. @@ -168,7 +168,7 @@ public class UiElementNode implements IPropertySource { *
* When the descriptor derives from ViewElementDescriptor, this list depends on the * current UiParent node. - * + * * @return A new set of {@link UiAttributeNode} that matches the expected * attributes for this node. */ @@ -190,7 +190,7 @@ public class UiElementNode implements IPropertySource { * Computes a short string describing the UI node suitable for tree views. * Uses the element's attribute "android:name" if present, or the "android:label" one * followed by the element's name. - * + * * @return A short string describing the UI node suitable for tree views. */ public String getShortDescription() { @@ -200,7 +200,7 @@ public class UiElementNode implements IPropertySource { // so we don't bother trying to differentiate their strings and we fall back to // just using the UI name below. Element elem = (Element) mXmlNode; - + String attr = elem.getAttributeNS(SdkConstants.NS_RESOURCES, AndroidManifestDescriptors.ANDROID_NAME_ATTR); if (attr == null || attr.length() == 0) { @@ -234,11 +234,11 @@ public class UiElementNode implements IPropertySource { return String.format("%1$s", mDescriptor.getUiName()); } - + /** * Computes a "breadcrumb trail" description for this node. * It will look something like "Manifest > Application > .myactivity (Activity) > Intent-Filter" - * + * * @param include_root Whether to include the root (e.g. "Manifest") or not. Has no effect * when called on the root node itself. * @return The "breadcrumb trail" description for this node. @@ -254,15 +254,15 @@ public class UiElementNode implements IPropertySource { } sb.insert(0, String.format("%1$s > ", ui_node.getShortDescription())); //$NON-NLS-1$ } - + return sb.toString(); } - + /** * Sets the XML {@link Document}. * * The XML {@link Document} is initially null. The XML {@link Document} must be set only on the - * UI root element node (this method takes care of that.) + * UI root element node (this method takes care of that.) */ public void setXmlDocument(Document xml_doc) { if (mUiParent == null) { @@ -277,7 +277,7 @@ public class UiElementNode implements IPropertySource { * * The value is initially null until the UI node is attached to its UI parent -- the value * of the document is then propagated. - * + * * @return the XML {@link Document} or the parent's XML {@link Document} or null. */ public Document getXmlDocument() { @@ -295,7 +295,7 @@ public class UiElementNode implements IPropertySource { * Some {@link ElementDescriptor} are declared as being "mandatory". This means the * corresponding UI node will exist even if there is no corresponding XML node. Such structure * is created and enforced by the parent of the tree, not the element themselves. However - * such nodes will likely not have an XML node associated, so getXmlNode() can return null. + * such nodes will likely not have an XML node associated, so getXmlNode() can return null. * * @return The associated XML node. Can be null for mandatory nodes. */ @@ -317,7 +317,7 @@ public class UiElementNode implements IPropertySource { * Returns the {@link AttributeDescriptor} array for the descriptor of this node. * * Use this instead of getDescriptor().getAttributes() -- derived classes can override - * this to manipulate the attribute descriptor list depending on the current UI node. + * this to manipulate the attribute descriptor list depending on the current UI node. */ public AttributeDescriptor[] getAttributeDescriptors() { return mDescriptor.getAttributes(); @@ -337,7 +337,7 @@ public class UiElementNode implements IPropertySource { for (AttributeDescriptor attr_desc : getAttributeDescriptors()) { if (attr_desc instanceof XmlnsAttributeDescriptor) { mCachedHiddenAttributes.put( - ((XmlnsAttributeDescriptor) attr_desc).getXmlNsName(), + ((XmlnsAttributeDescriptor) attr_desc).getXmlNsName(), attr_desc); } } @@ -362,7 +362,7 @@ public class UiElementNode implements IPropertySource { public UiElementNode getUiParent() { return mUiParent; } - + /** * Returns The root {@link UiElementNode}. */ @@ -371,13 +371,13 @@ public class UiElementNode implements IPropertySource { while (root.mUiParent != null) { root = root.mUiParent; } - + return root; } /** * Returns the previous UI sibling of this UI node. - * If the node does not have a previous sibling, returns null. + * If the node does not have a previous sibling, returns null. */ public UiElementNode getUiPreviousSibling() { if (mUiParent != null) { @@ -392,7 +392,7 @@ public class UiElementNode implements IPropertySource { /** * Returns the next UI sibling of this UI node. - * If the node does not have a next sibling, returns null. + * If the node does not have a next sibling, returns null. */ public UiElementNode getUiNextSibling() { if (mUiParent != null) { @@ -426,13 +426,13 @@ public class UiElementNode implements IPropertySource { * * The value is initially null until the node is attached to its parent -- the value * of the root node is then propagated. - * + * * @return The embedding {@link AndroidEditor} or null. */ public AndroidEditor getEditor() { return mUiParent == null ? mEditor : mUiParent.getEditor(); } - + /** * Returns the Android target data for the file being edited. */ @@ -467,7 +467,7 @@ public class UiElementNode implements IPropertySource { public Collectionnull if none has been set.
@@ -1116,14 +1119,14 @@ public class UiElementNode implements IPropertySource {
public Object getEditData() {
return mEditData;
}
-
+
public void refreshUi() {
invokeUiUpdateListeners(UiUpdateState.ATTR_UPDATED);
}
-
+
// ------------- Helpers
-
+
/**
* Helper method to commit a single attribute value to XML.
*
@@ -1133,9 +1136,9 @@ public class UiElementNode implements IPropertySource {
*
* Note that the caller MUST ensure that modifying the underlying XML model is
* safe and must take care of marking the model as dirty if necessary.
- *
+ *
* @see AndroidEditor#editXmlModel(Runnable)
- *
+ *
* @param uiAttr The attribute node to commit. Must be a child of this UiElementNode.
* @param newValue The new value to set.
* @return True if the XML attribute was modified or removed, false if nothing changed.
@@ -1146,7 +1149,7 @@ public class UiElementNode implements IPropertySource {
if (element != null && uiAttr != null) {
String attrLocalName = uiAttr.getDescriptor().getXmlLocalName();
String attrNsUri = uiAttr.getDescriptor().getNamespaceUri();
-
+
NamedNodeMap attrMap = element.getAttributes();
if (newValue == null || newValue.length() == 0) {
// Remove attribute if it's empty
@@ -1155,7 +1158,7 @@ public class UiElementNode implements IPropertySource {
return true;
}
} else {
- // Add or replace an attribute
+ // Add or replace an attribute
Document doc = element.getOwnerDocument();
if (doc != null) {
Attr attr = doc.createAttributeNS(attrNsUri, attrLocalName);
@@ -1179,16 +1182,16 @@ public class UiElementNode implements IPropertySource {
*
* Note that the caller MUST ensure that modifying the underlying XML model is
* safe and must take care of marking the model as dirty if necessary.
- *
+ *
* @see AndroidEditor#editXmlModel(Runnable)
- *
+ *
* @return True if one or more values were actually modified or removed,
* false if nothing changed.
*/
public boolean commitDirtyAttributesToXml() {
boolean result = false;
HashMap