Languages.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package ui.view;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. public class Languages {
  7. static int languageVar = 0;
  8. // Language Array Positions:
  9. // ToolBar (0-16)
  10. // Tables (17-24)
  11. // Graph (25-26)
  12. // Warning PopUps (27-30)
  13. // Edit Edges Pop Up (31-34)
  14. // Search/Replace Pop Up (35-45)
  15. // Edit Edges Pop Up (46-55)
  16. // Add PopUp Tree (56-63)
  17. // Add PopUp Element (64-71)
  18. // Info for PropertyTable (72-82)
  19. // Info SimulationMenu (83-87)
  20. // Exit Pop Up (88)
  21. // Simulation ToolTip (89-93)
  22. // Image Size Slider (94)
  23. // Menu - right click on HolonObjt (95-103)
  24. // to add more: increase languageSize and add them to the arrayEN
  25. /**
  26. * Number of different Language Array Positions
  27. */
  28. private static int languageSize = 104;
  29. static String[] arrayEN = {
  30. // ToolBar (0-16)
  31. "File", "New", "Open", "Save", "Edit", "Undo", "Redo", "Find/Replace", "Edit showed Information", "Options",
  32. "Reset Categories", "View", "View Size", "Help", "About Us", "Edit Edges", "Language",
  33. // Tables (17-24)
  34. "Object", "Nr.", "Device", "Energy", "Quantity", "Activated", "Field", "Information",
  35. // Graph (25-26)
  36. "None ", "Reset",
  37. // Warning PopUps (27-30)
  38. "Warning", "Do you want to save your current data?", "Do you really want to delete the Category ",
  39. "Please select a Category or an Object in order to delete something.",
  40. // Edit Edges Pop Up (31-34)
  41. "Edit Showed Informations", "Show Total Energy of Objects", "Show Connection Properties", "Cancel",
  42. // Search/Replace Pop Up (35-45)
  43. "Search for Objects", "Find", "Replace", "Direction", "Forward", "Backward", "Scope", "All", "Single",
  44. "Replace All", "Close",
  45. // Edit Edges Pop Up (46-55)
  46. "Edit Capacities of Edges", "Maximum Capacity:", "Change for all existing Edges only",
  47. "Change for new created Edges only", "Change for all existing and new created Edges", "Cancel",
  48. "Please select one of the options",
  49. "Please enter a number greater or equal 0 in the Field for Maximum Capacity", "Edit Edge Capacities",
  50. "(enter \"infinite\" for infinite Capacity)",
  51. // Add PopUp Tree (56-63)
  52. "Please enter a Name for Category ", "Please select a Category first before adding ", "Add Object Menu",
  53. "Name:", "Browse Image", "Add Element", "Delete Element", "Cancel",
  54. // Add PopUp Element (64-71)
  55. "Add Element to Object", "Element Name:", "Provided Energy:", "Amount:",
  56. "Please enter numbers in the Fields amount and Energy", "No name", "Name already given", "Cancel",
  57. // Info for PropertyTable (72-82)
  58. "Name", "Total Energy", "Manual", "Active", " is connected to", " with ID: ", "Edge: ", " to ",
  59. "Current flow", "Max. Capacity", "Status",
  60. // Info SimulationMenu (83-87)
  61. "Simulate", "Simulation Speed:", "Algorithm:", "non selected", "success",
  62. // Exit Pop Up (88)
  63. "Are you sure you want to exit?",
  64. // Simulation ToolTip (89-93)
  65. "Play", "Reset", "Forward", "Backward", "Time Slider",
  66. // Image Size Slider (94)
  67. "Image Size",
  68. // Menu - right click on HolonObjt (95-102)
  69. "Cut", "Copy", "Paste", "Delete", "Group", "Ungroup", "Track", "Untrack"};
  70. static String[] arrayES = readLanguageFile("Texts"+File.separator+"ES.lang");
  71. static String[] arrayDE = readLanguageFile("Texts"+File.separator+"DE.lang");
  72. static String[] arrayCZ = readLanguageFile("Texts"+File.separator+"CZ.lang");
  73. static String[] arrayZH = readLanguageFile("Texts"+File.separator+"ZH.lang");
  74. public static String[] getLanguage() {
  75. switch (languageVar) {
  76. case 0:
  77. return arrayEN;
  78. case 1:
  79. return arrayES;
  80. case 2:
  81. return arrayDE;
  82. case 3:
  83. return arrayCZ;
  84. case 4:
  85. return arrayZH;
  86. default:
  87. return arrayEN;
  88. }
  89. }
  90. public static void setLanguage(int i) {
  91. languageVar = i;
  92. }
  93. /**
  94. * Reads language file from jar, each line corresponds to
  95. * a position of the {@value #arrayEN}.
  96. * Lines starting with # are ignored as Comments.
  97. * Missing translations will be filled with english text.
  98. * @param path path of the file e.g. "Texts/DE.lang"
  99. * @return Array of translated String as arrayEN
  100. */
  101. private static String[] readLanguageFile(String path){
  102. String[] langArr;
  103. try {
  104. //read File from Jar
  105. FileReader reader = new FileReader(new File(Languages.class.getClassLoader().getResource(path).getFile()));
  106. BufferedReader br = new BufferedReader(reader);
  107. //store Lines in Array
  108. int lineNumber = 0;
  109. langArr = new String[languageSize];
  110. for (String line = br.readLine(); line != null && lineNumber<languageSize; line = br.readLine()) {
  111. //store line in Array, # initializes Comments
  112. if (line.isEmpty() || line.startsWith("#"))
  113. continue;
  114. langArr[lineNumber]=line;
  115. lineNumber++;
  116. }
  117. //missing translations? -> english
  118. while(lineNumber<languageSize){
  119. langArr[lineNumber]=arrayEN[lineNumber];
  120. lineNumber++;
  121. }
  122. reader.close();
  123. return langArr;
  124. } catch (IOException e) {
  125. //default: English
  126. return arrayEN;
  127. }
  128. }
  129. }