Guest User

Untitled

a guest
Jan 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1.  
  2. package plugins.adufour.tutorial;
  3.  
  4. import icy.gui.frame.progress.AnnounceFrame;
  5. import plugins.adufour.ezplug.*;
  6.  
  7. /**
  8. * Tutorial on how to use the EzPlug library to write plugins fast and efficiently
  9. *
  10. * @author Alexandre Dufour
  11. *
  12. */
  13. public class EzPlugTutorial extends EzPlug implements EzStoppable
  14. {
  15. private enum SomeEnumeration
  16. {
  17. CHOICE_1, CHOICE_2, CHOICE_3, SOME_other_CHOICE,
  18. }
  19.  
  20. // declare here the variables you wish to use
  21. // in this tutorial I will use one of each
  22.  
  23. EzVarBoolean varBoolean;
  24. EzVarDouble varDouble;
  25. EzVarDoubleArray varDoubleA;
  26. EzVarEnum<SomeEnumeration> varEnum;
  27. EzVarFile varFile;
  28. EzVarFileArray varFileA;
  29. EzVarFolder varFolder;
  30. EzVarInteger varInt;
  31. EzVarIntegerArray varIntA;
  32. EzVarSequence varSequence;
  33. EzVarText varText;
  34.  
  35. // some other data
  36. boolean stopFlag;
  37.  
  38. @Override
  39. protected void initialize()
  40. {
  41. // 1) variables must be initialized
  42.  
  43. varBoolean = new EzVarBoolean("boolean var.", false);
  44. varDouble = new EzVarDouble("double with free input");
  45. varDoubleA = new EzVarDoubleArray("double array without input", new Double[][] { new Double[] { 2.2, 4.4, 6.6 }, new Double[] { 1.1, 3.3, 5.5 } }, false);
  46. varEnum = new EzVarEnum<SomeEnumeration>("enumeration", SomeEnumeration.values(), SomeEnumeration.SOME_other_CHOICE);
  47. varFile = new EzVarFile("some file", null);
  48. varFileA = new EzVarFileArray("some files", null);
  49. varFolder = new EzVarFolder("a folder", null);
  50. varInt = new EzVarInteger("bounded integer", 4, -34, 28, 2);
  51. varIntA = new EzVarIntegerArray("int array with input", new Integer[0][0], true);
  52. varSequence = new EzVarSequence("Input sequence");
  53. varText = new EzVarText("Some text", new String[] { "yes", "no", "maybe?" }, 2, true);
  54.  
  55. // 2) and added to the interface in the desired order
  56.  
  57. super.addEzComponent(varText);
  58. super.addEzComponent(varEnum);
  59.  
  60. // let's group other variables per type
  61.  
  62. EzGroup groupNumeric = new EzGroup("Numeric variables", varDouble, varInt, varDoubleA, varIntA);
  63. super.addEzComponent(groupNumeric);
  64.  
  65. EzGroup groupFiles = new EzGroup("File choosers", varFile, varFileA, varFolder);
  66. super.addEzComponent(groupFiles);
  67.  
  68. // let's add a description label
  69. EzLabel label = new EzLabel("Check above to show/hide a variable");
  70. EzGroup groupSequence = new EzGroup("Sequence group", varBoolean, label, varSequence);
  71. super.addEzComponent(groupSequence);
  72.  
  73. // now let's add a trigger that shows varSequence when varBoolean is checked...
  74. varBoolean.addVisibilityTriggerTo(varSequence, true);
  75. // or when varEnum is on "CHOICE_2" or "CHOICE_3"
  76. varEnum.addVisibilityTriggerTo(varSequence, SomeEnumeration.CHOICE_2, SomeEnumeration.CHOICE_3);
  77. }
  78.  
  79. @Override
  80. protected void execute()
  81. {
  82. // main plugin code goes here, and runs in a separate thread
  83.  
  84. System.out.println(varBoolean.name + " = " + varBoolean.getValue());
  85. System.out.println(varDouble.name + " = " + varDouble.getValue());
  86. System.out.println(varDoubleA.name + " = " + varDoubleA.getValue());
  87. System.out.println(varEnum.name + " = " + varEnum.getValue().name());
  88. System.out.println(varFile.name + " = " + varFile.getValue());
  89. System.out.println(varSequence.name + " = " + varSequence.getValue());
  90. new AnnounceFrame(varText.getValue());
  91.  
  92. stopFlag = false;
  93.  
  94. super.getUI().setProgressBarMessage("Waiting...");
  95.  
  96. int cpt = 0;
  97. while (!stopFlag)
  98. {
  99. cpt++;
  100. if (cpt % 10 == 0) super.getUI().setProgressBarValue((cpt % 5000000) / 5000000.0);
  101. Thread.yield();
  102. }
  103. }
  104.  
  105. @Override
  106. public void clean()
  107. {
  108. // use this method to clean local variables or input streams (if any) to avoid memory leaks
  109.  
  110. }
  111.  
  112. @Override
  113. public void stopExecution()
  114. {
  115. // this method is from the EzStoppable interface
  116. // if this interface is implemented, a "stop" button is displayed
  117. // and this method is called when the user hits the "stop" button
  118. stopFlag = true;
  119. }
  120.  
  121. }
Add Comment
Please, Sign In to add comment