Skip to content
Merged
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
6 changes: 5 additions & 1 deletion CodenameOne/src/com/codename1/charts/views/BarChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.codename1.charts.renderers.XYSeriesRenderer;
import com.codename1.charts.util.ColorUtil;

import java.util.Collections;
import java.util.List;


Expand Down Expand Up @@ -58,7 +59,7 @@ public class BarChart extends XYChart {
/// The chart type.
protected Type mType = Type.DEFAULT;
/// The previous series Y axis point limits to be used for HEAP type bar charts.
private List<Float> mPreviousSeriesPoints;
private List<Float> mPreviousSeriesPoints = Collections.emptyList();

BarChart() {
}
Expand Down Expand Up @@ -133,6 +134,9 @@ public void drawSeries(Canvas canvas, Paint paint, List<Float> points,
float y = points.get(i + 1);

if (mType == Type.HEAPED && seriesIndex > 0) {
if (mPreviousSeriesPoints.size() <= i + 1) {
throw new IllegalStateException("HEAPED bar series must be drawn in order with matching points");
}
float lastY = mPreviousSeriesPoints.get(i + 1);
y = y + (lastY - yAxisValue);
points.set(i + 1, y);
Expand Down
52 changes: 26 additions & 26 deletions CodenameOne/src/com/codename1/charts/views/CombinedXYChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.codename1.charts.renderers.XYMultipleSeriesRenderer;
import com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation;
import com.codename1.charts.renderers.XYSeriesRenderer;
import com.codename1.io.Log;

import java.util.List;


Expand All @@ -42,11 +40,6 @@ public class CombinedXYChart extends XYChart {
/// The embedded XY charts.
private final XYChart[] mCharts;

/// The supported charts for being combined.
private final Class<?>[] xyChartTypes = new Class<?>[]{TimeChart.class, LineChart.class,
CubicLineChart.class, BarChart.class, BubbleChart.class, ScatterChart.class,
RangeBarChart.class, RangeStackedBarChart.class};

/// Builds a new combined XY chart instance.
///
/// #### Parameters
Expand All @@ -63,11 +56,7 @@ public CombinedXYChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer
int length = chartDefinitions.length;
mCharts = new XYChart[length];
for (int i = 0; i < length; i++) {
try {
mCharts[i] = getXYChart(chartDefinitions[i].getType());
} catch (Exception e) { // PMD Fix: EmptyCatchBlock log exception
Log.e(e);
}
mCharts[i] = createXYChart(chartDefinitions[i].getType());
if (mCharts[i] == null) {
throw new IllegalArgumentException("Unknown chart type " + chartDefinitions[i].getType());
} else {
Expand Down Expand Up @@ -95,21 +84,32 @@ public CombinedXYChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer
///
/// an instance of a chart implementation
///
/// #### Throws
///
/// - `IllegalAccessException`
///
/// - `InstantiationException`
private XYChart getXYChart(String type) throws IllegalAccessException, InstantiationException {
XYChart chart = null;
int length = xyChartTypes.length;
for (int i = 0; i < length && chart == null; i++) {
XYChart newChart = (XYChart) xyChartTypes[i].newInstance();
if (type.equals(newChart.getChartType())) {
chart = newChart;
}
static XYChart createXYChart(String type) {
if (TimeChart.TYPE.equals(type)) {
return new TimeChart();
}
if (LineChart.TYPE.equals(type)) {
return new LineChart();
}
if (CubicLineChart.TYPE.equals(type)) {
return new CubicLineChart();
}
if (BarChart.TYPE.equals(type)) {
return new BarChart();
}
if (BubbleChart.TYPE.equals(type)) {
return new BubbleChart();
}
if (ScatterChart.TYPE.equals(type)) {
return new ScatterChart();
}
if (RangeBarChart.TYPE.equals(type)) {
return new RangeBarChart();
}
if (RangeStackedBarChart.TYPE.equals(type)) {
return new RangeStackedBarChart();
}
return chart;
return null;
}

/// The graphical representation of a series.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CubicLineChart extends LineChart {

private final float mSecondMultiplier;
/// A path measure for retrieving the points on the path.
private PathMeasure mPathMeasure;
private PathMeasure mPathMeasure = new PathMeasure(null, false);

public CubicLineChart() {
// default is to have first control point at about 33% of the distance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@
import com.codename1.ui.TextField;
import com.codename1.ui.geom.Rectangle;
import com.codename1.ui.table.Table;
import com.codename1.ui.util.WeakHashMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/// Builds, caches, diffs, and dispatches actions for the portable semantic tree.
///
Expand All @@ -63,9 +61,6 @@ public final class AccessibilityManager {
public static final int CHANGE_ALL = 0x7fffffff;

private static final AccessibilityManager INSTANCE = new AccessibilityManager();
private final Map<Component, Long> componentIds = new WeakHashMap<Component, Long>();
private final Map<Component, Map<String, Long>> virtualIds =
new WeakHashMap<Component, Map<String, Long>>();
private long nextId = 1;
private long generation;
private boolean dirty = true;
Expand Down Expand Up @@ -142,8 +137,11 @@ public synchronized AccessibilityTreeSnapshot getSnapshot(Form form) {
return snapshot;
}
if (form == null) {
snapshot = new AccessibilityTreeSnapshot(++generation, Collections.<Long>emptyList(),
Collections.<Long, AccessibilityNodeSnapshot>emptyMap());
generation++;
AccessibilityTreeSnapshot emptySnapshot = new AccessibilityTreeSnapshot(
generation, Collections.<Long>emptyList(),
Collections.<Long, AccessibilityNodeSnapshot>emptyMap());
snapshot = emptySnapshot;
snapshotForm = null;
dirty = false;
pendingChanges = 0;
Expand All @@ -156,7 +154,9 @@ public synchronized AccessibilityTreeSnapshot getSnapshot(Form form) {
List<Long> rootIds = new ArrayList<Long>();
LinkedHashMap<Long, AccessibilityNodeSnapshot> nodes = new LinkedHashMap<Long, AccessibilityNodeSnapshot>();
freeze(roots, -1, rootIds, nodes);
snapshot = new AccessibilityTreeSnapshot(++generation, rootIds, nodes);
generation++;
AccessibilityTreeSnapshot updatedSnapshot = new AccessibilityTreeSnapshot(generation, rootIds, nodes);
snapshot = updatedSnapshot;
snapshotForm = form;
dirty = false;
pendingChanges = 0;
Expand Down Expand Up @@ -188,24 +188,21 @@ public void run() {
}

private long idFor(Component component) {
Long id = componentIds.get(component);
if (id == null) {
id = Long.valueOf(nextId++);
componentIds.put(component, id);
AccessibilityNode semantics = component.getSemantics();
long id = semantics.getInternalId();
if (id == 0) {
id = nextId++;
semantics.setInternalId(id);
}
return id.longValue();
return id;
}

private long idForVirtual(Component host, String path) {
Map<String, Long> hostIds = virtualIds.get(host);
if (hostIds == null) {
hostIds = new LinkedHashMap<String, Long>();
virtualIds.put(host, hostIds);
}
Long id = hostIds.get(path);
AccessibilityNode semantics = host.getSemantics();
Long id = semantics.getInternalVirtualId(path);
if (id == null) {
id = Long.valueOf(nextId++);
hostIds.put(path, id);
semantics.putInternalVirtualId(path, id.longValue());
}
return id.longValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import com.codename1.ui.geom.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/// Mutable semantic configuration for a lightweight component or virtual child.
///
Expand All @@ -35,6 +37,12 @@
/// virtual nodes must have a stable {@link #setVirtualKey(java.lang.String) virtual key}.
public class AccessibilityNode {
private Component owner;
// Stable runtime IDs belong to the component-owned semantic node. Keeping
// them here gives them exactly the component's lifetime without relying on
// the weak-value UI cache, whose boxed Long values may be collected while
// the component is still alive.
private long internalId;
private Map<String, Long> internalVirtualIds;
private String virtualKey;
private String identifier;
private String label;
Expand Down Expand Up @@ -94,6 +102,25 @@ private AccessibilityNode changed(int type) {
public Component getOwner() {
return owner;
}

long getInternalId() {
return internalId;
}

void setInternalId(long internalId) {
this.internalId = internalId;
}

Long getInternalVirtualId(String path) {
return internalVirtualIds == null ? null : internalVirtualIds.get(path);
}

void putInternalVirtualId(String path, long id) {
if (internalVirtualIds == null) {
internalVirtualIds = new LinkedHashMap<String, Long>();
}
internalVirtualIds.put(path, Long.valueOf(id));
}
public String getVirtualKey() {
return virtualKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.codename1.ui.Display;
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.events.ActionListener;
import com.sun.org.apache.xml.internal.serializer.ToHTMLStream;

Check warning on line 40 in Ports/JavaScriptPort/src/main/java/com/codename1/impl/html5/HTML5BrowserComponent.java

View workflow job for this annotation

GitHub Actions / javascript-screenshots

ToHTMLStream is internal proprietary API and may be removed in a future release
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -319,6 +319,32 @@

private boolean listenersInstalled;
private List<EventListener> frameListeners;
private ShouldLoadURLCallback navigationCallback;

private void installNavigationCallback() {
if (navigationCallback == null) {
navigationCallback = new ShouldLoadURLCallback() {

@Override
public boolean shouldLoadURL(final String url) {
// The host bridge already invokes this callback
// asynchronously on the worker. BrowserComponent will
// marshal the registered result callback onto the EDT.
parent.fireBrowserNavigationCallbacks(url);

// The callback URL is only a transport from Javascript to Java.
// It must never become a real iframe navigation.
return false;
}
};
}
if (iframe == null) {
installShouldLoadURLCallbackShared(navigationCallback);
} else {
installShouldLoadURLCallback(iframe, navigationCallback);
}
}

private void installFrameListeners() {
if (listenersInstalled) {
return;
Expand Down Expand Up @@ -362,23 +388,7 @@
HTML5Implementation._log("Failed to add event handlers to iframe, probably due to a CORS error");
}

installShouldLoadURLCallback(iframe, new ShouldLoadURLCallback() {

@Override
public boolean shouldLoadURL(final JSObject url) {
new Thread() {
public void run() {

parent.fireBrowserNavigationCallbacks(JS.unwrapString(url));
}
}.start();

// We always return false since this will only be used for
// the javascript bridge and we don't want it to try to
// do a window.location load.
return false;
}
});
installNavigationCallback();
} else {
HTML5Implementation._log("Is cors restricted");
}
Expand Down Expand Up @@ -446,23 +456,7 @@
parent = (BrowserComponent)p;
parent.fireWebEvent("onStart", new ActionEvent(CN.getProperty("browser.window.location.href", "")));
parent.fireWebEvent("onLoad", new ActionEvent(CN.getProperty("browser.window.location.href", "")));
installShouldLoadURLCallbackShared(new ShouldLoadURLCallback() {

@Override
public boolean shouldLoadURL(final JSObject url) {
new Thread() {
public void run() {

parent.fireBrowserNavigationCallbacks(JS.unwrapString(url));
}
}.start();

// We always return false since this will only be used for
// the javascript bridge and we don't want it to try to
// do a window.location load.
return false;
}
});
installNavigationCallback();
}

return;
Expand Down Expand Up @@ -682,6 +676,7 @@
}
WindowExt win = iframe == null ? ((WindowExt)Window.current()) : (WindowExt)iframe.getContentWindow();

installNavigationCallback();
win.eval(javascript);
//Window win = iframe.getContentWindow();
//win.getLocation().assign("javascript:"+javascript);
Expand All @@ -697,6 +692,7 @@
}
//WindowExt win = (WindowExt)iframe.getContentWindow();
Window win = iframe == null ? Window.current() : iframe.getContentWindow();
installNavigationCallback();
return evalStr(win, javascript);
//return win.eval(javascript);
}
Expand Down Expand Up @@ -935,13 +931,16 @@

@JSFunctor
interface ShouldLoadURLCallback extends JSObject {
boolean shouldLoadURL(JSObject url);
boolean shouldLoadURL(String url);
}

@JSBody(params={"iframe","callback"}, script="try {var win=iframe.contentWindow||iframe; win.cn1application = win.cn1application || {}; win.cn1application.shouldNavigate=callback;} catch (e) { console.log('Failed to install shouldNavigate in iframe for browser component.');}")
// Implemented by port.js through a main-thread host call. This must not be
// an @JSBody: ParparVM executes @JSBody code in the worker, where iframe is
// only a host-ref proxy and has no live contentWindow.
native static void installShouldLoadURLCallback(HTMLIFrameElement el, ShouldLoadURLCallback callback);

@JSBody(params={"callback"}, script="try {var win=window; win.cn1application = win.cn1application || {}; win.cn1application.shouldNavigate=callback;} catch (e) { console.log('Failed to install shouldNavigate in iframe for browser component.');}")
// See installShouldLoadURLCallback(). The shared-window variant uses the
// same host bridge and installs on the real browser window.
native static void installShouldLoadURLCallbackShared(ShouldLoadURLCallback callback);

}
Loading
Loading