Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. package com.codename1.tests.textediting;
  2.  
  3.  
  4. import com.codename1.ui.Command;
  5. import com.codename1.ui.Display;
  6. import com.codename1.ui.Form;
  7. import com.codename1.ui.Label;
  8. import com.codename1.ui.TextField;
  9. import com.codename1.ui.Toolbar;
  10. import com.codename1.ui.events.ActionEvent;
  11. import com.codename1.ui.layouts.BorderLayout;
  12. import com.codename1.ui.layouts.BoxLayout;
  13. import com.codename1.ui.plaf.UIManager;
  14. import com.codename1.ui.util.Resources;
  15. import java.io.IOException;
  16.  
  17.  
  18. public class IOSTextEditing {
  19.  
  20. private Form current;
  21. private Resources theme;
  22.  
  23. public void init(Object context) {
  24. theme = UIManager.initFirstTheme("/theme");
  25.  
  26. // Pro users - uncomment this code to get crash reports sent to you automatically
  27. /*Display.getInstance().addEdtErrorHandler(new ActionListener() {
  28. public void actionPerformed(ActionEvent evt) {
  29. evt.consume();
  30. Log.p("Exception in AppName version " + Display.getInstance().getProperty("AppVersion", "Unknown"));
  31. Log.p("OS " + Display.getInstance().getPlatformName());
  32. Log.p("Error " + evt.getSource());
  33. Log.p("Current Form " + Display.getInstance().getCurrent().getName());
  34. Log.e((Throwable)evt.getSource());
  35. Log.sendLog();
  36. }
  37. });*/
  38. }
  39.  
  40. private void createToolbar(Form f) {
  41. Toolbar tb = new Toolbar();
  42. f.setToolBar(tb);
  43. tb.addCommandToSideMenu(new Command("Legacy Test") {
  44.  
  45. @Override
  46. public void actionPerformed(ActionEvent evt) {
  47. showLegacyTestForm();
  48. }
  49.  
  50. });
  51. tb.addCommandToSideMenu(new Command("Async Test") {
  52.  
  53. @Override
  54. public void actionPerformed(ActionEvent evt) {
  55. showAsyncTestForm();
  56. }
  57.  
  58. });
  59. tb.addCommandToSideMenu(new Command("Bottom Padding") {
  60.  
  61. @Override
  62. public void actionPerformed(ActionEvent evt) {
  63. showBottomPaddingTestForm();
  64. }
  65.  
  66. });
  67.  
  68. }
  69.  
  70. public void start() {
  71. if(current != null){
  72. current.show();
  73. return;
  74. }
  75. Form hi = new Form("Hi World");
  76. createToolbar(hi);
  77. hi.addComponent(new Label("Hi World"));
  78. hi.show();
  79. }
  80.  
  81. private void showLegacyTestForm() {
  82. Form hi = new Form("Legacy Test");
  83. createToolbar(hi);
  84. hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
  85. for (int i=0; i<30; i++) {
  86. hi.addComponent(new TextField("Field "+i));
  87. }
  88. hi.setScrollableY(false);
  89. hi.show();
  90. }
  91.  
  92. private void showBottomPaddingTestForm() {
  93. Form hi = new Form("Bottom Padding");
  94. createToolbar(hi);
  95. hi.setFormBottomPaddingEditingMode(true);
  96. hi.setLayout(new BorderLayout());
  97. hi.addComponent(BorderLayout.SOUTH, new TextField("Some text"));
  98. hi.show();
  99.  
  100. }
  101.  
  102. private void showAsyncTestForm() {
  103. Form hi = new Form("Async Test");
  104. createToolbar(hi);
  105. hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
  106. for (int i=0; i<30; i++) {
  107. hi.addComponent(new TextField("Field "+i));
  108. }
  109. hi.setScrollableY(true);
  110. hi.show();
  111. }
  112.  
  113. public void stop() {
  114. current = Display.getInstance().getCurrent();
  115. }
  116.  
  117. public void destroy() {
  118. }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement