Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make YoungAndroidPalettePanel a singleton #3170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Copyright 2011-2019 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

Expand All @@ -10,7 +10,8 @@
import com.google.appinventor.client.editor.FileEditor;
import com.google.appinventor.client.editor.ProjectEditor;
import com.google.appinventor.client.editor.simple.components.MockComponent;
import com.google.appinventor.client.editor.simple.palette.SimplePalettePanel;
import com.google.appinventor.client.editor.simple.palette.DropTargetProvider;
import com.google.appinventor.client.editor.youngandroid.palette.YoungAndroidPalettePanel;
import com.google.appinventor.shared.rpc.project.FileNode;
import com.google.gwt.regexp.shared.MatchResult;
import com.google.gwt.regexp.shared.RegExp;
Expand Down Expand Up @@ -45,21 +46,14 @@ protected SimpleEditor(ProjectEditor projectEditor, FileNode fileNode) {
*/
public abstract Map<String, MockComponent> getComponents();

/*
/**
* Gets a list of the names of component instances. The caller can modify the
* list without affecting the actual properties.
*
* @return a list of the names of component instances
*/
public abstract List<String> getComponentNames();

/**
* Returns the component palette panel
*
* @return component palette panel
*/
public abstract SimplePalettePanel getComponentPalettePanel();

/**
* Returns the non-visible components panel
*
Expand Down Expand Up @@ -135,4 +129,26 @@ public String gensymName(String type, String hint) {
}
return type + (highIndex + 1);
}

/**
* Gets the component database containing the simple components associated
* with the editor.
*
* @return The editor's component database.
*/
public abstract SimpleComponentDatabase getComponentDatabase();

/**
* Gets the drop target provider for the editor.
*
* @return The editor's drop target provider.
*/
public abstract DropTargetProvider getDropTargetProvider();

/**
* Gets the palette filter for the editor.
*
* @return The editor's palette filter.
*/
public abstract YoungAndroidPalettePanel.Filter getPaletteFilter();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Copyright 2011-2019 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0

Expand Down Expand Up @@ -35,10 +35,15 @@ public final class SimpleNonVisibleComponentsPanel extends Composite implements
// Backing mocked Simple form component
private MockForm form;

// Editor that owns this nonvisible components panel
private final SimpleEditor editor;

/**
* Creates new component design panel for non-visible components.
*/
public SimpleNonVisibleComponentsPanel() {
public SimpleNonVisibleComponentsPanel(SimpleEditor editor) {
this.editor = editor;

// Initialize UI
VerticalPanel panel = new VerticalPanel();
panel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
Expand Down Expand Up @@ -119,7 +124,7 @@ public void onDragLeave(DragSource source) {

@Override
public void onDrop(DragSource source, int x, int y, int offsetX, int offsetY) {
MockComponent sourceComponent = ((SimplePaletteItem) source).createMockComponent();
MockComponent sourceComponent = ((SimplePaletteItem) source).createMockComponent(editor);

// Add component to the form
form.addComponent(sourceComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ void initComponent(Widget widget) {
addProperty(PROPERTY_NAME_UUID, "-1", null, null, null, new TextPropertyEditor());
changeProperty(PROPERTY_NAME_UUID, "" + Random.nextInt());

editor.getComponentPalettePanel().configureComponent(this);
PropertiesUtil.populateProperties(this,
COMPONENT_DATABASE.getPropertyDefinitions(getType()), (YaFormEditor) editor);
}

public boolean isPropertyPersisted(String propertyName) {
Expand Down Expand Up @@ -891,22 +892,6 @@ protected String convertImagePropertyValueToUrl(String text) {
return null;
}

// For debugging purposes only
private String describeElement(com.google.gwt.dom.client.Element element) {
if (element == null) {
return "null";
}
if (element == getElement()) {
return "this";
}
try {
return element.getTagName();
} catch (com.google.gwt.core.client.JavaScriptException e) {
// Can get here if the browser throws a permission denied error
return "????";
}
}

/**
* Invoked by GWT whenever a browser event is dispatched to this component.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public final void onDrop(DragSource source, int x, int y, int offsetX, int offse
sourceComponent = (MockComponent) source;
} else if (source instanceof SimplePaletteItem) {
// new component generated by a palette item
sourceComponent = ((SimplePaletteItem) source).createMockComponent();
sourceComponent = ((SimplePaletteItem) source).createMockComponent(editor);
} else {
throw new IllegalArgumentException();
}
Expand Down
Loading