public void stop() { current = Display.getInstance().getCurrent(); if (current instanceof Dialog) { ((Dialog) current).dispose(); current = Display.getInstance().getCurrent(); } }
/** * This is the style the Label object uses. It changes padding depending on the the resolution of * the display. */ public void style() { int height = Display.getInstance().getDisplayHeight(); int width = Display.getInstance().getDisplayWidth(); this.getUnselectedStyle().setFgColor(ColorUtil.BLUE); if (height <= 641 && width <= 960) this.getAllStyles().setPadding(1, 0, 2, 2); else if (height <= 640 && width <= 1136) this.getAllStyles().setPadding(1, 0, 2, 2); else if (height <= 1136 && width <= 640) this.getAllStyles().setPadding(1, 0, 2, 2); else this.getAllStyles().setPadding(1, 1, 2, 5); }
private void arrangeForConcentrate(Container c) { int w = Display.getInstance().getDisplayWidth(); int h = Display.getInstance().getDisplayHeight(); int[] positionX = {-100, w / 2, w + 100, w + 100, w + 100, w / 2, -100, -100}; int[] positionY = {-100, -100, -100, h / 2, h + 100, h + 100, h + 100, h / 2}; for (int iter = 0; iter < c.getComponentCount(); iter++) { Component cmp = c.getComponentAt(iter); cmp.setY(positionY[iter % positionY.length]); cmp.setX(positionX[iter % positionX.length]); } }
private void arrangeForFall(Container c) { int w = Display.getInstance().getDisplayWidth(); for (int iter = 0; iter < c.getComponentCount(); iter++) { Component cmp = c.getComponentAt(iter); cmp.setY(-c.getHeight()); } }
public com.codename1.ui.Button findButton() { com.codename1.ui.Button cmp = (com.codename1.ui.Button) findByName("Button", Display.getInstance().getCurrent()); if (cmp == null && aboutToShowThisContainer != null) { cmp = (com.codename1.ui.Button) findByName("Button", aboutToShowThisContainer); } return cmp; }
public com.codename1.ui.Label findLabel() { com.codename1.ui.Label cmp = (com.codename1.ui.Label) findByName("Label", Display.getInstance().getCurrent()); if (cmp == null && aboutToShowThisContainer != null) { cmp = (com.codename1.ui.Label) findByName("Label", aboutToShowThisContainer); } return cmp; }
public Dimension calcPreferredSize() { Component c = renderer.getCellRendererComponent( ContainerList.this, model, model.getItemAt(offset), offset, hasFocus()); if (getWidth() <= 0) { c.setWidth(Display.getInstance().getDisplayWidth()); c.setHeight(Display.getInstance().getDisplayHeight()); } else { c.setWidth(getWidth()); c.setHeight(getHeight()); } if (c instanceof Container) { ((Container) c).revalidate(); } Dimension d = c.getPreferredSize(); return d; }
public com.codename1.ui.TextArea findTextArea() { com.codename1.ui.TextArea cmp = (com.codename1.ui.TextArea) findByName("TextArea", Display.getInstance().getCurrent()); if (cmp == null && aboutToShowThisContainer != null) { cmp = (com.codename1.ui.TextArea) findByName("TextArea", aboutToShowThisContainer); } return cmp; }
public com.codename1.ui.Container findContainer() { com.codename1.ui.Container cmp = (com.codename1.ui.Container) findByName("Container", Display.getInstance().getCurrent()); if (cmp == null && aboutToShowThisContainer != null) { cmp = (com.codename1.ui.Container) findByName("Container", aboutToShowThisContainer); } return cmp; }
public com.codename1.ui.Tabs findTabs1() { com.codename1.ui.Tabs cmp = (com.codename1.ui.Tabs) findByName("Tabs1", Display.getInstance().getCurrent()); if (cmp == null && aboutToShowThisContainer != null) { cmp = (com.codename1.ui.Tabs) findByName("Tabs1", aboutToShowThisContainer); } return cmp; }
public com.codename1.maps.MapComponent findMapComponent() { com.codename1.maps.MapComponent cmp = (com.codename1.maps.MapComponent) findByName("MapComponent", Display.getInstance().getCurrent()); if (cmp == null && aboutToShowThisContainer != null) { cmp = (com.codename1.maps.MapComponent) findByName("MapComponent", aboutToShowThisContainer); } return cmp; }
public void init(Object context) { try { Resources theme = Resources.openLayered("/theme"); UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0])); Display.getInstance().setCommandBehavior(Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION); UIManager.getInstance().getLookAndFeel().setMenuBarClass(SideMenuBar.class); } catch (IOException e) { e.printStackTrace(); } }
public com.codename1.components.MultiButton findMultiButton3() { com.codename1.components.MultiButton cmp = (com.codename1.components.MultiButton) findByName("MultiButton3", Display.getInstance().getCurrent()); if (cmp == null && aboutToShowThisContainer != null) { cmp = (com.codename1.components.MultiButton) findByName("MultiButton3", aboutToShowThisContainer); } return cmp; }
private void arrangeForInterlace(Container c) { int w = Display.getInstance().getDisplayWidth(); for (int iter = 0; iter < c.getComponentCount(); iter++) { Component cmp = c.getComponentAt(iter); if (iter % 2 == 0) { cmp.setX(-w); } else { cmp.setX(w); } } }
public void authenticate(final Form currentForm) { if (onLoadAccessToken() == true) { return; } final Form backForm = (currentForm == null) ? Display.getInstance().getCurrent() : currentForm; RequestTokenRequest rtr = new RequestTokenRequest(serviceProvider, requestSigner, callback); if (errorListener != null) { rtr.addResponseCodeListener(errorListener); } // Retrieve (and wait) for the request token NetworkManager.getInstance().addToQueueAndWait(rtr); RequestToken requestToken = rtr.getToken(); if (requestToken == null) { return; } // Use the request token to retrieve an access token for the authorizing user. final ObservableWebBrowser wb = new ObservableWebBrowser(); wb.addErrorListener(errorListener); AccessTokenRequest atr = new AccessTokenRequest(serviceProvider, signer, requestToken); atr.addReceiveTokenListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { Log.p("onAccessToken()", Log.DEBUG); AccessToken at = (AccessToken) evt.getSource(); onReceiveAccessToken(at); onSaveAccessToken(at); onDisposeLogin(backForm, wb); onAuthenticated(); } }); atr.addDeniedListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { onDisposeLogin(backForm, wb); } }); wb.addStartListener(atr); String url = serviceProvider.getAuthenticateUrl(requestToken); wb.setURL(url); onDisplayLogin(backForm, wb); }
/** @inheritDoc */ public Component getCellRendererComponent( Component list, Object model, T value, int index, boolean isSelected) { if (!alwaysRenderSelection && !Display.getInstance().shouldRenderSelection(list)) { isSelected = false; } setFocus(isSelected); if (showNumbers) { String text = "" + value; Map<String, String> t = UIManager.getInstance().getBundle(); if (t != null && value != null) { Object o = t.get(value.toString()); if (o != null) { text = (String) o; } } if (isRTL()) { setText(text + " ." + (index + 1)); } else { setText("" + (index + 1) + ". " + text); } } else { if (value != null) { String v = value.toString(); setText(v); if (isRightAlignNumbers()) { char c = v.charAt(0); Style s = getStyle(); if (c >= '0' && c <= '9') { s.setAlignment(RIGHT); } else { s.setAlignment(LEFT); } } } else { setText("null"); } } if (value instanceof Command) { setIcon(((Command) value).getIcon()); setEnabled(((Command) value).isEnabled()); } return this; }
/** {@inheritDoc} */ public void keyReleased(int keyCode) { super.keyReleased(keyCode); if (Display.getInstance().getGameAction(keyCode) == Display.GAME_FIRE) { fireActionEvent(new ActionEvent(ContainerList.this, keyCode)); } }
/** * Triggers the event to the listeners * * @param evt the event to fire */ protected void fireActionEvent(ActionEvent evt) { if (isEnabled() && !Display.getInstance().hasDragOccured()) { dispatcher.fireActionEvent(evt); } }
/** * This is the base class for all XY data * * @author nathan */ public abstract class DataViewChart { protected L10NManager formatter = Display.getInstance().getLocalizationManager(); protected XYMultipleSeriesDataset buildDataset(String[] titles, List<double[]> xyValues) { XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); XYSeries series = getXYSeries(titles[0], xyValues.get(0), xyValues.get(1)); dataset.addSeries(series); // we may have trend line data as well if (titles.length == 2 && xyValues.size() == 3) { series = getXYSeries(titles[1], xyValues.get(0), xyValues.get(2)); dataset.addSeries(series); } return dataset; } /** * Method to return an xy series for the line chart * * @param title * @param xV * @param yV * @return */ protected XYSeries getXYSeries(String title, double[] xV, double[] yV) { XYSeries series = new XYSeries(title); int seriesLength = xV.length; for (int i = 0; i < seriesLength; i++) { series.add(xV[i], yV[i]); } return series; } /** * Builds an XY multiple series renderer. * * @param colors the series rendering color * @param styles the series point style * @return the XY multiple series renderer */ protected XYMultipleSeriesRenderer buildRenderer(int[] colors, PointStyle[] styles) { XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer(); renderer.setAxisTitleTextSize(25); renderer.setChartTitleTextSize(25); renderer.setLabelsTextSize(25); renderer.setLegendTextSize(25); renderer.setPointSize(10f); renderer.setBackgroundColor(ColorUtil.BLACK); renderer.setApplyBackgroundColor(true); renderer.setMargins(new int[] {20, 30, 15, 20}); for (int i = 0; i < colors.length; i++) { renderer.addSeriesRenderer(getXYSeriesRenderer(colors[i], styles[i])); } return renderer; } /** * Get the XYSeriesRenderer * * @param color * @param style * @return */ protected XYSeriesRenderer getXYSeriesRenderer(int color, PointStyle style) { XYSeriesRenderer renderer = new XYSeriesRenderer(); renderer.setColor(color); renderer.setPointStyle(style); renderer.setFillPoints(true); renderer.setLineWidth(8f); return renderer; } /** * Builds a bar multiple series renderer to use the provided colors. * * @param colors the series renderers colors * @return the bar multiple series renderer */ protected XYMultipleSeriesRenderer buildBarRenderer(int[] colors) { XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer(); renderer.setAxisTitleTextSize(25); renderer.setChartTitleTextSize(25); renderer.setLabelsTextSize(25); renderer.setLegendTextSize(25); renderer.setBackgroundColor(ColorUtil.BLACK); renderer.setApplyBackgroundColor(true); int length = colors.length; for (int i = 0; i < length; i++) { XYSeriesRenderer r = new XYSeriesRenderer(); r.setColor(colors[i]); renderer.addSeriesRenderer(r); } return renderer; } /** * Builds a bar multiple series dataset using the provided values. * * @param titles the series titles * @param values the values * @return the XY multiple bar dataset */ protected XYMultipleSeriesDataset buildBarDataset(String[] titles, List<double[]> values) { XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); int length = titles.length; for (int i = 0; i < length; i++) { CategorySeries series = new CategorySeries(titles[i]); double[] v = values.get(i); int seriesLength = v.length; for (int k = 0; k < seriesLength; k++) { series.add(v[k]); } dataset.addSeries(series.toXYSeries()); } return dataset; } /** * Sets a few of the series renderer settings. * * @param renderer the renderer to set the properties to * @param title the chart title * @param xTitle the title for the X axis * @param yTitle the title for the Y axis * @param xMin the minimum value on the X axis * @param xMax the maximum value on the X axis * @param yMin the minimum value on the Y axis * @param yMax the maximum value on the Y axis * @param axesColor the axes color * @param labelsColor the labels color */ protected void setChartSettings( XYMultipleSeriesRenderer renderer, String title, String xTitle, String yTitle, double xMin, double xMax, double yMin, double yMax, int axesColor, int labelsColor) { renderer.setChartTitle(title); renderer.setXTitle(xTitle); renderer.setYTitle(yTitle); renderer.setXAxisMin(xMin); renderer.setXAxisMax(xMax); renderer.setYAxisMin(yMin); renderer.setYAxisMax(yMax); renderer.setAxesColor(axesColor); renderer.setLabelsColor(labelsColor); } /** * Method to return the data as a list in which position 0 are the x values and position 1 are the * y values * * @param xydata * @return */ protected List<double[]> getDataAsList(String[][] xydata) { ArrayList<double[]> dataList = new ArrayList<double[]>(); int length = xydata.length - 1; double[] xdata = new double[length]; double[] ydata = new double[length]; // lets assume we have a header information in position 0 for (int i = 1; i <= length; i++) { xdata[i - 1] = Double.parseDouble(xydata[i][0]); ydata[i - 1] = Double.parseDouble(xydata[i][1]); } dataList.add(xdata); dataList.add(ydata); return dataList; } /** * Method to get the x and y min and max * * @param xdata * @param ydata * @return */ protected double[] getXYLimits(double[] xdata, double[] ydata) { double xmin = 1000000; double xmax = -1000000; double ymin = 1000000; double ymax = -1000000; for (int i = 0; i < xdata.length; i++) { if (xdata[i] < xmin) { xmin = xdata[i]; } if (ydata[i] < ymin) { ymin = ydata[i]; } if (xdata[i] > xmax) { xmax = xdata[i]; } if (ydata[i] > ymax) { ymax = ydata[i]; } } double[] limits = {xmin, xmax, ymin, ymax}; return limits; } /** * This formats a double which would be displayed as scientific values * * @param value * @param dp the decimal places * @return */ protected String formatScientificNumber(double value, int dp) { // first get the scientific notation format String sn = Double.toString(value); // now split into two parts String[] sa = Util.split(sn, "E"); String part1 = "" + round(Double.parseDouble(sa[0]), dp); String part2 = ""; if (sa.length == 2) { part2 = "E" + sa[1]; } return part1 + part2; } /** * This is used to round a double to certain number of decimal places * * @param valueToRound * @param numberOfDecimalPlaces * @return */ protected double round(double valueToRound, int numberOfDecimalPlaces) { double multipicationFactor = MathUtil.pow(10, numberOfDecimalPlaces); double interestedInZeroDPs = valueToRound * multipicationFactor; return Math.round(interestedInZeroDPs) / multipicationFactor; } /** * Method to return a form which will contain the chart or multiple charts in a tab * * @param title * @param c * @return */ protected Form wrap(String title, Component c) { Form f = new Form(title); f.setLayout(new BorderLayout()); f.addComponent(BorderLayout.CENTER, c); return f; } /** * Method to take an array of chart components, place them in a tab then return a form that wraps * everything up * * @param formTitle The title of the form * @param titles contains the titles of the tabs * @param components the tab components * @return Form containing the tab */ protected Form wrap(String formTitle, String[] titles, Component[] components) { Tabs tabs = new Tabs(); for (int i = 0; i < titles.length; i++) { tabs.addTab(titles[i], components[i]); } return wrap(formTitle, tabs); } public abstract Form getChart(XYData xyData); }
public void stop() { current = Display.getInstance().getCurrent(); }
private void checkForPushMessages() { final String pushReceivedInBackgroundError = Preferences.get(StateMachine.KEY_APP_IN_BACKGROUND_PUSH_ERROR, null); if (pushReceivedInBackgroundError != null) { Logger.getInstance() .error( "Apparently an error occurred while processing a push message " + "received while the app was in background:\n\n" + pushReceivedInBackgroundError); Display.getInstance() .callSerially( new Runnable() { public void run() { Dialog.show( "Error", "Apparently an error occurred while processing a push message " + "received while the app was in background:\n\n" + pushReceivedInBackgroundError, Dialog.TYPE_ERROR, null, "OK", null); Preferences.set(StateMachine.KEY_APP_IN_BACKGROUND_PUSH_ERROR, null); } }); } else { final String pushReceivedInBackground = Preferences.get(StateMachine.KEY_APP_IN_BACKGROUND_PUSH_PAYLOAD, null); if (pushReceivedInBackground != null) { Logger.getInstance() .info( "The following push messages were " + "received while the app was in background:\n\n" + pushReceivedInBackground); Display.getInstance() .callSerially( new Runnable() { public void run() { Dialog.show( "Push received (background)", "The following push messages were received while the app was in background:\n\n" + pushReceivedInBackground, "OK", null); Preferences.set(StateMachine.KEY_APP_IN_BACKGROUND_PUSH_PAYLOAD, null); } }); } } if (ParsePush.isAppOpenedViaPushNotification()) { Logger.getInstance().info("App opened via push notification"); try { final JSONObject pushPayload = ParsePush.getPushDataUsedToOpenApp(); Display.getInstance() .callSerially( new Runnable() { public void run() { Dialog.show( "App opened via push", "The app was opened via clicking a push notification with payload:\n\n" + pushPayload.toString(), "OK", null); ParsePush.resetPushDataUsedToOpenApp(); } }); } catch (final ParseException ex) { Display.getInstance() .callSerially( new Runnable() { public void run() { Dialog.show( "Error", "An error occured while trying to retrieve " + "push payload used to open app.\n\n" + "Error: " + ex.getMessage(), Dialog.TYPE_ERROR, null, "OK", null); } }); } } else { Logger.getInstance().info("App opened normally"); } if (ParsePush.isUnprocessedPushDataAvailable()) { Logger.getInstance().info("Unprocessed push data available"); try { final JSONArray pushPayload = ParsePush.getUnprocessedPushData(); Display.getInstance() .callSerially( new Runnable() { public void run() { Dialog.show( "Unprocessed push data", "The following unprocessed push message(s) were " + "possibly received while the app was not running:\n\n" + pushPayload.toString(), "OK", null); ParsePush.resetUnprocessedPushData(); } }); } catch (final ParseException ex) { Display.getInstance() .callSerially( new Runnable() { public void run() { Dialog.show( "Error", "An error occured while trying to retrieve " + "unprocessed push payload.\n\n" + "Error: " + ex.getMessage(), Dialog.TYPE_ERROR, null, "OK", null); } }); } } else { Logger.getInstance().info("No unprocessed push data found"); } }