Commit 4366d61b authored by halatmit's avatar halatmit

Disable Horizontal/Vertical and Alignment properties for HorizontalArrangement and

Vertical Arrangment in designer when width/length is automatic.  Disable Vertical
Alignment for Screen when Scrollable is set.
Added BadProprtyEditorException
Moved arrangement editor getters to utilities file

Change-Id: I300f734ed2cc2bd8ba5acf224d38fa6b4597170d
parent 08e20cd6
......@@ -1153,4 +1153,11 @@ public interface OdeMessages extends Messages {
@DefaultMessage("No upgrade strategy exists for {0} from version {1} to {2}.")
@Description("Exception message used when a component was not upgraded")
String noUpgradeStrategyException(String componentType, int srcCompVersion, int sysCompVersion);
// Used in client/editor/simple/components/MockHVarrangement.java
@DefaultMessage("System error: bad alignmnet property editor for horizontal or vertical arrangement.")
@Description("System error message for a bad alignment property editor")
String badAlignmentPropertyEditorForArrangement();
}
......@@ -206,7 +206,9 @@ public abstract class MockComponent extends Composite implements PropertyChangeL
protected boolean expanded;
// Properties of the component
private final EditableProperties properties;
// Expose these to individual component subclasses, which might need to
// check properties fpr UI manipulation. One example is MockHorizontalArrangement
protected final EditableProperties properties;
private DragSourceSupport dragSourceSupport;
......
......@@ -5,12 +5,18 @@
package com.google.appinventor.client.editor.simple.components;
import static com.google.appinventor.client.Ode.MESSAGES;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import com.google.appinventor.client.editor.simple.SimpleEditor;
import com.google.appinventor.client.editor.simple.components.utils.PropertiesUtil;
import com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidLengthPropertyEditor;
import com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidVerticalAlignmentChoicePropertyEditor;
import com.google.appinventor.client.output.OdeLog;
import com.google.appinventor.client.properties.BadPropertyEditorException;
import com.google.appinventor.shared.settings.SettingsConstants;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
......@@ -36,6 +42,8 @@ public final class MockForm extends MockContainer {
*/
private class TitleBar extends Composite {
private static final int HEIGHT = 24;
// UI elements
private Label title;
......@@ -132,9 +140,15 @@ public final class MockForm extends MockContainer {
private static int verticalScrollbarWidth;
private MockFormLayout myLayout;
// flag to control attempting to enable/disable vertical
// alignment when scrollable property is changed
private boolean initialized = false;
private YoungAndroidVerticalAlignmentChoicePropertyEditor myVAlignmentPropertyEditor;
private static final String PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "AlignHorizontal";
private static final String PROPERTY_NAME_VERTICAL_ALIGNMENT = "AlignVertical";
public static final String PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "AlignHorizontal";
public static final String PROPERTY_NAME_VERTICAL_ALIGNMENT = "AlignVertical";
/**
* Creates a new MockForm component.
......@@ -174,6 +188,17 @@ public final class MockForm extends MockContainer {
resizePanels();
initComponent(formWidget);
// Set up the initial state of the vertical alignment property editor and its
// dropdowns
try {
myVAlignmentPropertyEditor = PropertiesUtil.getVAlignmentEditor(properties);
} catch (BadPropertyEditorException e) {
OdeLog.log(MESSAGES.badAlignmentPropertyEditorForArrangement());
return;
};
enableAndDisableDropdowns();
initialized = true;
}
/*
......@@ -581,6 +606,7 @@ public final class MockForm extends MockContainer {
setScreenOrientationProperty(newValue);
} else if (propertyName.equals(PROPERTY_NAME_SCROLLABLE)) {
setScrollableProperty(newValue);
adjustAlignmentDropdowns();
} else if (propertyName.equals(PROPERTY_NAME_TITLE)) {
titleBar.changeTitle(newValue);
} else if (propertyName.equals(PROPERTY_NAME_ICON)) {
......@@ -596,6 +622,21 @@ public final class MockForm extends MockContainer {
} else if (propertyName.equals(PROPERTY_NAME_VERTICAL_ALIGNMENT)) {
myLayout.setVAlignmentFlags(newValue);
refreshForm();
}
}
// enableAndDisable It should not be called until the component is initialized.
// Otherwise, we'll get NPEs in trying to use myAlignmentPropertyEditor.
private void adjustAlignmentDropdowns() {
if (initialized) enableAndDisableDropdowns();
}
// Don't forget to call this on initialization!!!
// If scrollable is True, the selector for vertical alignment should be disabled.
private void enableAndDisableDropdowns() {
String scrollable = properties.getProperty(PROPERTY_NAME_SCROLLABLE).getValue();
if (scrollable.equals("True")) {
myVAlignmentPropertyEditor.disable();
} else myVAlignmentPropertyEditor.enable();
}
}
......@@ -5,7 +5,17 @@
package com.google.appinventor.client.editor.simple.components;
import static com.google.appinventor.client.Ode.MESSAGES;
import com.google.appinventor.client.editor.simple.SimpleEditor;
import com.google.appinventor.client.editor.simple.components.utils.PropertiesUtil;
import com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidHorizontalAlignmentChoicePropertyEditor;
import com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidLengthPropertyEditor;
import com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidVerticalAlignmentChoicePropertyEditor;
import com.google.appinventor.client.output.OdeLog;
import com.google.appinventor.client.properties.BadPropertyEditorException;
import com.google.appinventor.client.properties.Property;
import com.google.appinventor.client.widgets.properties.EditableProperty;
import com.google.appinventor.client.widgets.properties.PropertyEditor;
import com.google.appinventor.components.common.ComponentConstants;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.AbsolutePanel;
......@@ -16,19 +26,24 @@ import com.google.gwt.user.client.ui.AbsolutePanel;
*
* @author markf@google.com (Mark Friedman)
* @author sharon@google.com (Sharon Perl)
* @author hal@mit.edu (Hal Abelson) (added adjust alignment dropdowns)
*/
public abstract class MockHVArrangement extends MockContainer {
public class MockHVArrangement extends MockContainer {
//!!! why was this abstract?
// Form UI components
protected final AbsolutePanel layoutWidget;
private MockHVLayout myLayout;
private static final String PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "AlignHorizontal";
private static final String PROPERTY_NAME_VERTICAL_ALIGNMENT = "AlignVertical";
private YoungAndroidHorizontalAlignmentChoicePropertyEditor myHAlignmentPropertyEditor;
private YoungAndroidVerticalAlignmentChoicePropertyEditor myVAlignmentPropertyEditor;
private boolean initialized = false;
/**
* Creates a new MockHVArrangement component.
*/
......@@ -43,7 +58,7 @@ public abstract class MockHVArrangement extends MockContainer {
// next instruction. Note that the Helper methods are synchronized to avoid possible
// future problems if we ever have threads creating arrangements in parallel.
myLayout = MockHVArrangementHelper.getLayout();
if (orientation != ComponentConstants.LAYOUT_ORIENTATION_VERTICAL &&
orientation != ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL) {
throw new IllegalArgumentException("Illegal orientation: " + orientation);
......@@ -56,12 +71,20 @@ public abstract class MockHVArrangement extends MockContainer {
layoutWidget.add(rootPanel);
initComponent(layoutWidget);
try {
myHAlignmentPropertyEditor = PropertiesUtil.getHAlignmentEditor(properties);
myVAlignmentPropertyEditor = PropertiesUtil.getVAlignmentEditor(properties);
} catch (BadPropertyEditorException e) {
OdeLog.log(MESSAGES.badAlignmentPropertyEditorForArrangement());
return;
};
enableAndDisableDropdowns();
initialized = true;
}
@Override
public void onPropertyChange(String propertyName, String newValue) {
// Note(hal): Is it necessary to call super here?
super.onPropertyChange(propertyName, newValue);
if (propertyName.equals(PROPERTY_NAME_HORIZONTAL_ALIGNMENT)) {
myLayout.setHAlignmentFlags(newValue);
......@@ -69,6 +92,33 @@ public abstract class MockHVArrangement extends MockContainer {
} else if (propertyName.equals(PROPERTY_NAME_VERTICAL_ALIGNMENT)) {
myLayout.setVAlignmentFlags(newValue);
refreshForm();
} else {
if (propertyName.equals(PROPERTY_NAME_WIDTH) || propertyName.equals(PROPERTY_NAME_HEIGHT)) {
adjustAlignmentDropdowns();
refreshForm();
}
}
}
}
// enableAndDisable It should not be called until the component is initialized.
// Otherwise, we'll get NPEs in trying to use myAlignmentPropertyEditor.
private void adjustAlignmentDropdowns() {
if (initialized) enableAndDisableDropdowns();
}
// If the width is automatic, the selector for horizontal alignment should be disabled.
// If the length is automatic, the selector for vertical alignment should be disabled.
private void enableAndDisableDropdowns() {
String width = properties.getProperty(MockVisibleComponent.PROPERTY_NAME_WIDTH).getValue();
if (width.equals(YoungAndroidLengthPropertyEditor.CONST_AUTOMATIC)) {
myHAlignmentPropertyEditor.disable();
} else myHAlignmentPropertyEditor.enable();
String height = properties.getProperty(MockVisibleComponent.PROPERTY_NAME_HEIGHT).getValue();
if (height.equals(YoungAndroidLengthPropertyEditor.CONST_AUTOMATIC)) {
myVAlignmentPropertyEditor.disable();
} else myVAlignmentPropertyEditor.enable();
}
}
......@@ -19,7 +19,7 @@ public final class MockHorizontalArrangement extends MockHVArrangement {
* Component type name.
*/
public static final String TYPE = "HorizontalArrangement";
/**
* Creates a new MockHorizontalArrangement component.
*
......@@ -29,4 +29,8 @@ public final class MockHorizontalArrangement extends MockHVArrangement {
super(editor, TYPE, images.horizontal(),
ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL);
}
}
}
\ No newline at end of file
......@@ -29,4 +29,5 @@ public final class MockVerticalArrangement extends MockHVArrangement {
super(editor, TYPE, images.vertical(),
ComponentConstants.LAYOUT_ORIENTATION_VERTICAL);
}
}
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the MIT License https://raw.github.com/mit-cml/app-inventor/master/mitlicense.txt
package com.google.appinventor.client.editor.simple.components.utils;
import com.google.appinventor.client.editor.simple.components.MockForm;
import com.google.appinventor.client.editor.
youngandroid.properties.YoungAndroidHorizontalAlignmentChoicePropertyEditor;
import com.google.appinventor.client.editor.youngandroid.properties.
YoungAndroidVerticalAlignmentChoicePropertyEditor;
import com.google.appinventor.client.properties.BadPropertyEditorException;
import com.google.appinventor.client.properties.Property;
import com.google.appinventor.client.widgets.properties.EditableProperties;
import com.google.appinventor.client.widgets.properties.EditableProperty;
import com.google.appinventor.client.widgets.properties.PropertyEditor;
/**
* Provides utility functions for dealing with the UI for component properties
*
* @author hal@mit.edu (Hal Abelson)
*/
public class PropertiesUtil {
/**
* Prevent instantiation.
*/
private PropertiesUtil() {
}
// Use individual methods for each property since we can't write the generic
// getExstingPropertyEditor below
// retrieve the property editor for Horizontal Alignment
public static YoungAndroidHorizontalAlignmentChoicePropertyEditor
getHAlignmentEditor(EditableProperties properties)
throws BadPropertyEditorException {
PropertyEditor propEditor= null;
Property prop = properties.getProperty(MockForm.PROPERTY_NAME_HORIZONTAL_ALIGNMENT);
if (! (prop == null)) {
if (prop instanceof EditableProperty) {
propEditor = ((EditableProperty) prop).getEditor();
if (! (propEditor == null)) {
if (! (propEditor instanceof YoungAndroidHorizontalAlignmentChoicePropertyEditor))
throw new BadPropertyEditorException("Bad property editor");
}
}
}
return (YoungAndroidHorizontalAlignmentChoicePropertyEditor)propEditor;
}
// retrieve the property editor for Vertical Alignment
public static YoungAndroidVerticalAlignmentChoicePropertyEditor
getVAlignmentEditor(EditableProperties properties)
throws BadPropertyEditorException {
PropertyEditor propEditor= null;
Property prop = properties.getProperty(MockForm.PROPERTY_NAME_VERTICAL_ALIGNMENT);
if (! (prop == null)) {
if (prop instanceof EditableProperty) {
propEditor = ((EditableProperty) prop).getEditor();
if (! (propEditor == null)) {
if (! (propEditor instanceof YoungAndroidVerticalAlignmentChoicePropertyEditor))
throw new BadPropertyEditorException("Bad property editor");
}
}
}
return (YoungAndroidVerticalAlignmentChoicePropertyEditor)propEditor;
}
// TODO(hal): The individual property methods above should be replaced by a single generic
// method getExistingPropertyEditor that
// retrieves the property editor for the named property and checks its type. Here's how the
// code should go. While this compiles in Java, it sadly
// does not compile in GWT, which has not yet implemented type-safe generic casting.
// Sigh. Well, maybe someday.
// /**
// * Returns the existing property editor for the given name.
// *
// * @throws IllegalStateException if no such property editor exists, or if
// * the editor does not have the required class
// * @param name property name
// * @param C the required class of class of the property editor
// */
// public <T extends PropertyEditor>T getExistingPropertyEditor(String name, Class<T> C)
// throws BadPropertyEditorException {
// PropertyEditor propEditor= null;
// Property prop = getProperty(name);
// if (! (prop == null)) {
// if (prop instanceof EditableProperty) {
// propEditor = ((EditableProperty) prop).getEditor();
// if (! (propEditor == null)) {
// if (! (C.isAssignableFrom(propEditor.getClass()))) {
// throw new BadPropertyEditorException("Bad property editor");
// }
// }
// }
// }
// return C.cast(propEditor);
// }
}
......@@ -8,11 +8,8 @@ import static com.google.appinventor.client.Ode.MESSAGES;
import com.google.appinventor.client.widgets.properties.ChoicePropertyEditor;
import com.google.appinventor.components.common.ComponentConstants;
// cludge for now. mimic how this is done for button shape
/**
* Property editor for button shape.
* Property editor for horizontal alignment choice.
*
* @author hal@mit.edu (Hal Abelson)
*/
......
......@@ -25,8 +25,8 @@ import com.google.gwt.user.client.ui.VerticalPanel;
*
*/
public class YoungAndroidLengthPropertyEditor extends AdditionalChoicePropertyEditor {
private static final String CONST_AUTOMATIC = "" + MockVisibleComponent.LENGTH_PREFERRED;
private static final String CONST_FILL_PARENT = "" + MockVisibleComponent.LENGTH_FILL_PARENT;
public static final String CONST_AUTOMATIC = "" + MockVisibleComponent.LENGTH_PREFERRED;
public static final String CONST_FILL_PARENT = "" + MockVisibleComponent.LENGTH_FILL_PARENT;
private static int uniqueIdSeed = 0;
......
......@@ -13,7 +13,7 @@ import com.google.appinventor.components.common.ComponentConstants;
/**
* Property editor for button shape.
* Property editor for vertical alignment choice.
*
* @author hal@mit.edu (Hal Abelson)
*/
......
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the MIT License https://raw.github.com/mit-cml/app-inventor/master/mitlicense.txt
package com.google.appinventor.client.properties;
/**
* Exception used when getinng property editors
* @author hal@mit.edu (Hal Abelson)
*/
public class BadPropertyEditorException extends IllegalStateException {
public BadPropertyEditorException(String message) {
super(message);
}
}
......@@ -6,6 +6,8 @@
package com.google.appinventor.client.properties;
import com.google.appinventor.client.output.OdeLog;
import com.google.appinventor.client.widgets.properties.EditableProperty;
import com.google.appinventor.client.widgets.properties.PropertyEditor;
import com.google.appinventor.shared.properties.json.JSONObject;
import com.google.appinventor.shared.properties.json.JSONValue;
......@@ -202,7 +204,7 @@ public class Properties<T extends Property> implements Iterable<T> {
*
* @throws IllegalStateException if no such property exists
*/
private T getExistingProperty(String name) {
public T getExistingProperty(String name) {
T property = getProperty(name);
if (property == null) {
throw new IllegalStateException("no such property: " + name);
......
......@@ -111,6 +111,20 @@ public class ChoicePropertyEditor extends PropertyEditor implements ChangeHandle
}
}
}
/**
* Enables the dropdown selector for this property
*/
public void enable() {
listbox.setEnabled(true);
}
/**
* Disables the dropdown selector for this property
*/
public void disable() {
listbox.setEnabled(false);
}
// ChangeHandler implementation
......
......@@ -119,7 +119,7 @@ public final class EditableProperty extends Property {
*
* @return property editor
*/
final PropertyEditor getEditor() {
public final PropertyEditor getEditor() {
return editor;
}
......
......@@ -479,6 +479,10 @@ body {
.ode-PropertyEditor {
}
select.ode-PropertyEditor[disabled] {
background-color: #aaa;
}
.ode-MultipleChoicePropertyEditor {
min-width: 150px;
background-color: white;
......
......@@ -120,7 +120,7 @@ public class HVArrangement extends AndroidViewComponent implements Component, Co
category = PropertyCategory.APPEARANCE,
description = "A number that encodes how contents of the arrangement are aligned " +
" horizontally. The choices are: 1 = left aligned, 2 = horizontally centered, " +
" 3 = right aligned. Alignment has no effect with the arrangement's width is " +
" 3 = right aligned. Alignment has no effect if the arrangement's width is " +
"automatic.")
public int AlignHorizontal() {
return horizontalAlignment;
......
......@@ -343,7 +343,7 @@ public final class ErrorMessages {
"are 1, 2, or 3.");
errorMessages.put(ERROR_BAD_VALUE_FOR_VERTICAL_ALIGNMENT,
"The value -- %s -- provided for VerticalAlignment was bad. The only legal values " +
"are 1 or 2.");
"are 1, 2, or 3.");
errorMessages.put(ERROR_NO_SCANNER_FOUND,
"Your device does not have a scanning application installed.");
errorMessages.put(ERROR_CANNOT_SAVE_IMAGE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment