Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
f473a758
Commit
f473a758
authored
Jan 30, 2020
by
Evan W. Patton
Committed by
Jeffrey Schiller
Jan 31, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix automatic sizing of mock toggle components
Change-Id: If974657cfe9b5d44768779a465580a29034f352a
parent
d2357d1b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
57 deletions
+49
-57
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockCheckBox.java
...nventor/client/editor/simple/components/MockCheckBox.java
+1
-24
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockComponentsUtil.java
...r/client/editor/simple/components/MockComponentsUtil.java
+33
-6
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockSwitch.java
...pinventor/client/editor/simple/components/MockSwitch.java
+1
-22
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockToggleBase.java
...entor/client/editor/simple/components/MockToggleBase.java
+11
-2
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockWrapper.java
...inventor/client/editor/simple/components/MockWrapper.java
+3
-3
No files found.
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockCheckBox.java
View file @
f473a758
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 201
8
MIT, All rights reserved
// Copyright 201
1-2020
MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
package
com.google.appinventor.client.editor.simple.components
;
import
com.google.appinventor.client.editor.simple.SimpleEditor
;
import
com.google.gwt.user.client.DOM
;
import
com.google.gwt.user.client.ui.CheckBox
;
import
com.google.gwt.user.client.ui.Widget
;
/**
* Mock CheckBox component, inherited from MockToggleBase
...
...
@@ -34,27 +32,6 @@ public final class MockCheckBox extends MockToggleBase<CheckBox> {
initWrapper
(
toggleWidget
);
}
/**
* Class that extends CheckBox so we can use a protected constructor.
*
* <p/>The purpose of this class is to create a clone of the CheckBox
* passed to the constructor. It will be used to determine the preferred size
* of the CheckBox, without having the size constrained by its parent,
* since the cloned CheckBox won't have a parent.
*/
static
class
ClonedCheckBox
extends
CheckBox
{
ClonedCheckBox
(
CheckBox
ptb
)
{
// Get the Element from the CheckBox.
// Call DOM.clone to make a deep clone of that element.
// Pass that cloned element to the super constructor.
super
(
DOM
.
clone
(
ptb
.
getElement
().
getFirstChildElement
(),
true
));
}
}
protected
Widget
createClonedWidget
()
{
return
new
ClonedCheckBox
(
toggleWidget
);
}
/*
* Sets the checkbox's Text property to a new value.
*/
...
...
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockComponentsUtil.java
View file @
f473a758
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-20
17
MIT, All rights reserved
// Copyright 2011-20
20
MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
package
com.google.appinventor.client.editor.simple.components
;
// import com.google.gwt.event.dom.client.LoadEvent;
// import com.google.gwt.event.dom.client.LoadHandler;
import
com.google.gwt.event.shared.GwtEvent.Type
;
import
com.google.gwt.user.client.DOM
;
import
com.google.gwt.user.client.Element
;
import
com.google.gwt.user.client.Timer
;
...
...
@@ -280,7 +277,10 @@ public final class MockComponentsUtil {
* 0 and height at index 1.
*/
static
String
[]
clearSizeStyle
(
Widget
w
)
{
Element
element
=
w
.
getElement
();
return
clearSizeStyle
(
w
.
getElement
());
}
static
String
[]
clearSizeStyle
(
Element
element
)
{
String
widthStyle
=
DOM
.
getStyleAttribute
(
element
,
"width"
);
String
heightStyle
=
DOM
.
getStyleAttribute
(
element
,
"height"
);
String
lineHeightStyle
=
DOM
.
getStyleAttribute
(
element
,
"lineHeight"
);
...
...
@@ -304,7 +304,10 @@ public final class MockComponentsUtil {
* and height at index 1.
*/
static
void
restoreSizeStyle
(
Widget
w
,
String
[]
style
)
{
Element
element
=
w
.
getElement
();
restoreSizeStyle
(
w
.
getElement
(),
style
);
}
static
void
restoreSizeStyle
(
Element
element
,
String
[]
style
)
{
if
(
style
[
0
]
!=
null
)
{
DOM
.
setStyleAttribute
(
element
,
"width"
,
style
[
0
]);
}
...
...
@@ -368,6 +371,30 @@ public final class MockComponentsUtil {
return
new
int
[]
{
width
,
height
};
}
/**
* Returns the preferred size of the specified DOM element in an array of the
* form {@code [width, height]}.
*
* @see #getPreferredSizeOfDetachedWidget(Widget)
* @param element the DOM element to compute the size for
* @return the natural width and height of the element
*/
public
static
int
[]
getPreferredSizeOfElement
(
Element
element
)
{
Element
root
=
RootPanel
.
get
().
getElement
();
root
.
appendChild
(
element
);
String
[]
style
=
clearSizeStyle
(
element
);
int
width
=
element
.
getOffsetWidth
()
+
4
;
int
height
=
element
.
getOffsetHeight
()
+
6
;
if
(
height
<
26
)
{
height
=
26
;
}
restoreSizeStyle
(
element
,
style
);
root
.
removeChild
(
element
);
return
new
int
[]
{
width
,
height
};
}
static
void
setEnabled
(
MockComponent
component
,
String
value
)
{
// Can't disable GWT control because then you wouldn't be able to select it anymore because it
// would not receive any browser events.
...
...
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockSwitch.java
View file @
f473a758
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2018 MIT, All rights reserved
// Copyright 2018
-2020
MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
...
...
@@ -12,7 +12,6 @@ import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import
com.google.gwt.user.client.ui.HasVerticalAlignment
;
import
com.google.gwt.user.client.ui.InlineHTML
;
import
com.google.gwt.user.client.ui.HorizontalPanel
;
import
com.google.gwt.user.client.ui.Widget
;
/**
* Mock Switch component, inherited from MockToggleBase
...
...
@@ -53,26 +52,6 @@ public final class MockSwitch extends MockToggleBase<HorizontalPanel> {
initWrapper
(
toggleWidget
);
}
/**
* Class that extends Widget so we can use a protected constructor.
*
* <p/>The purpose of this class is to create a clone of the Switch
* passed to the constructor. It will be used to determine the preferred size
* of the Switch, without having the size constrained by its parent,
* since the cloned Switch won't have a parent.
*/
static
class
ClonedSwitch
extends
InlineHTML
{
ClonedSwitch
(
HorizontalPanel
ptb
)
{
super
(
DOM
.
clone
(
ptb
.
getWidget
(
0
).
getElement
(),
true
));
}
}
@Override
protected
Widget
createClonedWidget
()
{
return
new
ClonedSwitch
(
toggleWidget
);
}
/**
* Draw the SVG graphic of the toggle switch. It can be drawn in either checked or
* unchecked positions, each with their own colors.
...
...
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockToggleBase.java
View file @
f473a758
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2016-20
18
MIT, All rights reserved
// Copyright 2016-20
20
MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
...
...
@@ -7,6 +7,7 @@ package com.google.appinventor.client.editor.simple.components;
import
com.google.appinventor.client.editor.simple.SimpleEditor
;
import
com.google.gwt.resources.client.ImageResource
;
import
com.google.gwt.user.client.DOM
;
import
com.google.gwt.user.client.ui.Widget
;
import
static
com
.
google
.
appinventor
.
client
.
Ode
.
MESSAGES
;
...
...
@@ -25,7 +26,10 @@ abstract class MockToggleBase<T extends Widget> extends MockWrapper {
super
(
editor
,
type
,
icon
);
}
abstract
protected
Widget
createClonedWidget
();
protected
final
Widget
createClonedWidget
()
{
// We override updatePreferredSize directly, so this shouldn't be called.
throw
new
UnsupportedOperationException
();
}
@Override
public
void
onCreateFromPalette
()
{
...
...
@@ -136,4 +140,9 @@ abstract class MockToggleBase<T extends Widget> extends MockWrapper {
setTextColorProperty
(
newValue
);
}
}
protected
void
updatePreferredSize
()
{
preferredSize
=
MockComponentsUtil
.
getPreferredSizeOfElement
(
DOM
.
clone
(
toggleWidget
.
getElement
(),
true
));
}
}
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockWrapper.java
View file @
f473a758
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-20
12
MIT, All rights reserved
// Copyright 2011-20
20
MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
...
...
@@ -26,7 +26,7 @@ import com.google.gwt.user.client.ui.Widget;
*/
abstract
class
MockWrapper
extends
MockVisibleComponent
{
private
final
SimplePanel
wrapper
;
pr
ivate
int
[]
preferredSize
;
pr
otected
int
[]
preferredSize
;
MockWrapper
(
SimpleEditor
editor
,
String
type
,
ImageResource
icon
)
{
super
(
editor
,
type
,
icon
);
...
...
@@ -55,7 +55,7 @@ abstract class MockWrapper extends MockVisibleComponent {
*/
protected
abstract
Widget
createClonedWidget
();
protected
final
void
updatePreferredSize
()
{
protected
void
updatePreferredSize
()
{
preferredSize
=
MockComponentsUtil
.
getPreferredSizeOfDetachedWidget
(
createClonedWidget
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment