use of com.codename1.ui.Display in project CodenameOne by codenameone.
the class JavaSEPort method init.
/**
* @inheritDoc
*/
public void init(Object m) {
inInit = true;
File updater = new File(System.getProperty("user.home") + File.separator + ".codenameone" + File.separator + "UpdateCodenameOne.jar");
if (!updater.exists()) {
System.out.println("******************************************************************************");
System.out.println("* It seems that you are using an old plugin version please upate to the latest plugin and invoke Codename One -> Codename One Settings -> Basic -> Update Client Libs");
System.out.println("******************************************************************************");
}
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
boolean desktopSkin = pref.getBoolean("desktopSkin", false);
if (desktopSkin && m == null) {
Toolkit tk = Toolkit.getDefaultToolkit();
setDefaultPixelMilliRatio(tk.getScreenResolution() / 25.4 * getRetinaScale());
pixelMilliRatio = getDefaultPixelMilliRatio();
JPanel panel = new javax.swing.JPanel();
panel.setLayout(new BorderLayout());
JPanel bottom = new javax.swing.JPanel();
panel.setOpaque(false);
bottom.setLayout(new FlowLayout(FlowLayout.RIGHT));
widthLabel = new JLabel("Width: ");
heightLabel = new JLabel(" Height: ");
bottom.add(widthLabel);
bottom.add(heightLabel);
panel.add(bottom, BorderLayout.SOUTH);
JFrame frame = new JFrame();
// frame.addWindowListener(new WindowListener() {
//
// });
frame.setLayout(new BorderLayout());
frame.add(panel, BorderLayout.CENTER);
frame.setSize(new Dimension(300, 400));
m = panel;
window = frame;
}
setInvokePointerHover(desktopSkin || invokePointerHover);
// this is essential for push and other things to work in the simulator
Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
String user = p.get("user", null);
if (user != null) {
Display d = Display.getInstance();
d.setProperty("built_by_user", user);
String mainClass = System.getProperty("MainClass");
if (mainClass != null) {
mainClass = mainClass.substring(0, mainClass.lastIndexOf('.'));
d.setProperty("package_name", mainClass);
}
}
try {
Class.forName("javafx.embed.swing.JFXPanel");
Platform.setImplicitExit(false);
fxExists = true;
} catch (Throwable ex) {
}
String hide = System.getProperty("hideMenu", "false");
if (hide != null && hide.equals("true")) {
showMenu = false;
}
URLConnection.setDefaultAllowUserInteraction(true);
HttpURLConnection.setFollowRedirects(false);
if (!blockMonitors && pref.getBoolean("NetworkMonitor", false)) {
showNetworkMonitor();
}
if (!blockMonitors && pref.getBoolean("PushSimulator", false)) {
pushSimulation = new PushSimulator();
pushSimulation.setVisible(true);
}
if (!blockMonitors && pref.getBoolean("PerformanceMonitor", false)) {
showPerformanceMonitor();
}
if (defaultInitTarget != null && m == null) {
m = defaultInitTarget;
}
if (canvas.getParent() != null) {
canvas.getParent().remove(canvas);
}
if (m != null && m instanceof java.awt.Container) {
java.awt.Container cnt = (java.awt.Container) m;
if (cnt.getLayout() instanceof java.awt.BorderLayout) {
cnt.add(java.awt.BorderLayout.CENTER, canvas);
} else {
cnt.add(canvas);
}
} else {
window = new JFrame();
window.setLayout(new java.awt.BorderLayout());
hSelector = new JScrollBar(Scrollbar.HORIZONTAL);
vSelector = new JScrollBar(Scrollbar.VERTICAL);
hSelector.addAdjustmentListener(canvas);
vSelector.addAdjustmentListener(canvas);
scrollableSkin = pref.getBoolean("Scrollable", true);
if (scrollableSkin) {
window.add(java.awt.BorderLayout.SOUTH, hSelector);
window.add(java.awt.BorderLayout.EAST, vSelector);
}
window.add(java.awt.BorderLayout.CENTER, canvas);
}
if (window != null) {
java.awt.Image large = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/application64.png"));
java.awt.Image small = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/application48.png"));
try {
// setIconImages is only available in JDK 1.6
window.setIconImages(Arrays.asList(new java.awt.Image[] { large, small }));
} catch (Throwable err) {
window.setIconImage(small);
}
window.addWindowListener(new WindowListener() {
public void windowOpened(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
Display.getInstance().exitApplication();
}
public void windowClosed(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
});
window.setLocationByPlatform(true);
android6PermissionsFlag = pref.getBoolean("Android6Permissions", false);
alwaysOnTop = pref.getBoolean("AlwaysOnTop", false);
window.setAlwaysOnTop(alwaysOnTop);
String reset = System.getProperty("resetSkins");
if (reset != null && reset.equals("true")) {
System.setProperty("resetSkins", "");
pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.put("skins", DEFAULT_SKINS);
}
if (hasSkins()) {
if (m == null) {
String f = System.getProperty("skin");
if (f != null) {
loadSkinFile(f, window);
} else {
String d = System.getProperty("dskin");
f = pref.get("skin", d);
loadSkinFile(f, window);
}
} else {
try {
installMenu(window, true);
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
Resources.setRuntimeMultiImageEnabled(true);
window.setUndecorated(true);
window.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
window.pack();
if (getSkin() != null && !scrollableSkin) {
float w1 = ((float) canvas.getWidth() * (float) retinaScale) / ((float) getSkin().getWidth());
float h1 = ((float) canvas.getHeight() * (float) retinaScale) / ((float) getSkin().getHeight());
zoomLevel = Math.min(h1, w1);
}
portrait = pref.getBoolean("Portrait", true);
if (!portrait && getSkin() != null) {
canvas.setForcedSize(new java.awt.Dimension((int) (getSkin().getWidth() / retinaScale), (int) (getSkin().getHeight() / retinaScale)));
window.setSize(new java.awt.Dimension((int) (getSkin().getWidth() / retinaScale), (int) (getSkin().getHeight() / retinaScale)));
}
window.setVisible(true);
}
if (useNativeInput) {
Display.getInstance().setDefaultVirtualKeyboard(null);
}
float factor = ((float) getDisplayHeight()) / 480.0f;
if (factor > 0 && autoAdjustFontSize && getSkin() != null) {
// set a reasonable default font size
setFontSize((int) (15.0f * factor), (int) (11.0f * factor), (int) (19.0f * factor));
}
if (m instanceof Runnable) {
Display.getInstance().callSerially((Runnable) m);
}
inInit = false;
}
use of com.codename1.ui.Display in project CodenameOne by codenameone.
the class JavaSEPort method getProperty.
/**
* @inheritDoc
*/
public String getProperty(String key, String defaultValue) {
if (key.equalsIgnoreCase("cn1_push_prefix") || key.equalsIgnoreCase("cellId") || key.equalsIgnoreCase("IMEI") || key.equalsIgnoreCase("UDID") || key.equalsIgnoreCase("MSISDN")) {
if (!checkForPermission("android.permission.READ_PHONE_STATE", "This is required to get the phone state")) {
return "";
}
return defaultValue;
}
if ("OS".equals(key)) {
return "SE";
}
if ("AppName".equals(key)) {
File f = new File("codenameone_settings.properties");
if (f.exists()) {
try {
Properties p = new Properties();
p.load(new FileInputStream(f));
return p.getProperty("codename1.displayName");
} catch (IOException ex) {
ex.printStackTrace();
}
}
return defaultValue;
}
if ("AppVersion".equals(key)) {
File f = new File("codenameone_settings.properties");
if (f.exists()) {
try {
Properties p = new Properties();
p.load(new FileInputStream(f));
return p.getProperty("codename1.version");
} catch (IOException ex) {
ex.printStackTrace();
}
}
return defaultValue;
}
String s = System.getProperty(key);
if (key.equals("built_by_user")) {
Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
String user = p.get("user", null);
Display d = Display.getInstance();
if (user == null) {
JPanel pnl = new JPanel();
JTextField tf = new JTextField(20);
pnl.add(new JLabel("E-Mail For Push"));
pnl.add(tf);
int val = JOptionPane.showConfirmDialog(canvas, pnl, "Please Enter Build Email Account", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (val != JOptionPane.OK_OPTION) {
return null;
}
user = tf.getText();
// p.put("user", user);
}
d.setProperty("built_by_user", user);
return user;
}
if (key.equals("package_name")) {
String mainClass = System.getProperty("MainClass");
if (mainClass != null) {
mainClass = mainClass.substring(0, mainClass.lastIndexOf('.'));
Display.getInstance().setProperty("package_name", mainClass);
}
return mainClass;
}
if (s == null) {
return defaultValue;
}
return s;
}
use of com.codename1.ui.Display in project CodenameOne by codenameone.
the class Oauth2 method authenticate.
/**
* This method preforms the actual authentication, this method is a blocking
* method that will display the user the html authentication pages.
*
* @return the method if passes authentication will return the access token
* or null if authentication failed.
*
* @throws IOException the method will throw an IOException if something
* went wrong in the communication.
* @deprecated use createAuthComponent or showAuthentication which work
* asynchronously and adapt better to different platforms
*/
public String authenticate() {
if (token == null) {
login = new Dialog();
boolean i = Dialog.isAutoAdjustDialogSize();
Dialog.setAutoAdjustDialogSize(false);
login.setLayout(new BorderLayout());
login.setScrollable(false);
Component html = createLoginComponent(null, null, null, null);
login.addComponent(BorderLayout.CENTER, html);
login.setScrollable(false);
login.setDialogUIID("Container");
login.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 300));
login.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 300));
login.show(0, 0, 0, 0, false, true);
Dialog.setAutoAdjustDialogSize(i);
}
return token;
}
use of com.codename1.ui.Display in project CodenameOne by codenameone.
the class MenuBar method showMenuDialog.
/*private void fixCommandAlignment() {
if (left != null) {
if (parent.isRTL()) {
left.setAlignment(Label.RIGHT);
right.setAlignment(Label.LEFT);
} else {
left.setAlignment(Label.LEFT);
right.setAlignment(Label.RIGHT);
}
if(main != null && main != left && main != right) {
main.setAlignment(CENTER);
}
}
}*/
/**
* A menu is implemented as a dialog, this method allows you to override dialog
* display in order to customize the dialog menu in various ways
*
* @param menu a dialog containing menu options that can be customized
* @return the command selected by the user in the dialog (not menu) Select
* or Cancel
*/
protected Command showMenuDialog(Dialog menu) {
UIManager manager = parent.getUIManager();
boolean pref = manager.isThemeConstant("menuPrefSizeBool", false);
int height;
int marginLeft;
int marginRight = 0;
if (pref) {
Container dialogContentPane = menu.getDialogComponent();
marginLeft = parent.getWidth() - (dialogContentPane.getPreferredW() + menu.getStyle().getHorizontalPadding());
marginLeft = Math.max(0, marginLeft);
if (parent.getSoftButtonCount() > 1) {
height = parent.getHeight() - parent.getSoftButton(0).getParent().getPreferredH() - dialogContentPane.getPreferredH();
} else {
height = parent.getHeight() - dialogContentPane.getPreferredH();
}
height = Math.max(0, height);
} else {
float menuWidthPercent = 1 - Float.parseFloat(manager.getThemeConstant("menuWidthPercent", "75")) / 100;
float menuHeightPercent = 1 - Float.parseFloat(manager.getThemeConstant("menuHeightPercent", "50")) / 100;
height = (int) (parent.getHeight() * menuHeightPercent);
marginLeft = (int) (parent.getWidth() * menuWidthPercent);
}
if (isReverseSoftButtons()) {
marginRight = marginLeft;
marginLeft = 0;
}
if (getCommandBehavior() == Display.COMMAND_BEHAVIOR_ICS) {
menu.setTransitionOutAnimator(transitionIn);
menu.setTransitionInAnimator(transitionOut);
int th = getTitleAreaContainer().getHeight();
return menu.show(th, height - th, marginLeft, marginRight, true);
} else {
if (manager.getLookAndFeel().isTouchMenus() && manager.isThemeConstant("PackTouchMenuBool", true)) {
return menu.showPacked(BorderLayout.SOUTH, true);
} else {
return menu.show(height, 0, marginLeft, marginRight, true);
}
}
}
use of com.codename1.ui.Display in project CodenameOne by codenameone.
the class Toolbar method showOverflowMenu.
/*
* A Overflow Menu is implemented as a dialog, this method allows you to
* override the dialog display in order to customize the dialog menu in
* various ways
*
* @param menu a dialog containing Overflow Menu options that can be
* customized
* @return the command selected by the user in the dialog
*/
protected Command showOverflowMenu(Dialog menu) {
Form parent = sideMenu.getParentForm();
int height;
int marginLeft;
int marginRight = 0;
Container dialogContentPane = menu.getDialogComponent();
marginLeft = parent.getWidth() - (dialogContentPane.getPreferredW() + menu.getStyle().getHorizontalPadding());
marginLeft = Math.max(0, marginLeft);
if (parent.getSoftButtonCount() > 1) {
height = parent.getHeight() - parent.getSoftButton(0).getParent().getPreferredH() - dialogContentPane.getPreferredH();
} else {
height = parent.getHeight() - dialogContentPane.getPreferredH();
}
height = Math.max(0, height);
int th = getHeight();
Transition transitionIn;
Transition transitionOut;
UIManager manager = parent.getUIManager();
LookAndFeel lf = manager.getLookAndFeel();
if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
transitionIn = lf.getDefaultMenuTransitionIn();
if (transitionIn instanceof BubbleTransition) {
((BubbleTransition) transitionIn).setComponentName("OverflowButton");
}
transitionOut = lf.getDefaultMenuTransitionOut();
} else {
transitionIn = CommonTransitions.createEmpty();
transitionOut = CommonTransitions.createEmpty();
}
menu.setTransitionInAnimator(transitionIn);
menu.setTransitionOutAnimator(transitionOut);
if (isRTL()) {
marginRight = marginLeft;
marginLeft = 0;
}
int tint = parent.getTintColor();
parent.setTintColor(0x00FFFFFF);
parent.tint = false;
boolean showBelowTitle = manager.isThemeConstant("showMenuBelowTitleBool", true);
int topPadding = 0;
Component statusBar = ((BorderLayout) getLayout()).getNorth();
if (statusBar != null) {
topPadding = statusBar.getAbsoluteY() + statusBar.getHeight();
}
if (showBelowTitle) {
topPadding = th;
}
Command r = menu.show(topPadding, Math.max(topPadding, height - topPadding), marginLeft, marginRight, true);
parent.setTintColor(tint);
return r;
}
Aggregations