Advertisement
kijato

OpenJump - Menü from CSV

Jan 17th, 2020
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.56 KB | None | 0 0
  1. /*
  2.     OpenJump - Menü from CSV
  3. */
  4.  
  5. import com.vividsolutions.jump.*;
  6. import com.vividsolutions.jump.workbench.ui.*;
  7. import com.vividsolutions.jump.workbench.ui.plugin.*;
  8. import org.openjump.core.ui.plugin.customize.*;
  9.  
  10. import java.util.*;  
  11. import java.nio.charset.*;  
  12. import java.nio.file.*;  
  13. import java.io.*;
  14.  
  15. class MenuItemListener implements ActionListener {
  16.   public void actionPerformed(ActionEvent e) {            
  17.     print( "'" + getKorzet(tables, e.getActionCommand()) + "' & '" + e.getActionCommand() + "' has been clicked.");
  18.     //showMessageDialog( null, getKorzet(e.getActionCommand())+"\\"+e.getActionCommand() );
  19.     //dialog = new MultiInputDialog(wc.workbench.frame, "...", true);
  20.     //dialog.addSubTitle(getKorzet(e.getActionCommand())+"\\"+e.getActionCommand());
  21.  
  22.   }    
  23. }
  24. MenuItemListener menuItemListener = new MenuItemListener();
  25.  
  26. ArrayList readToStringList(String fileName) throws IOException {
  27.     ArrayList wholeFile = new ArrayList();
  28.     fileReader = new FileReader(fileName);
  29.     bufferReader = new BufferedReader(fileReader);
  30.     while( (line=bufferReader.readLine()) != null ) {
  31.         if ( line.length()==0 || line.equals("") || line.startsWith("#") ) { continue; }
  32.         wholeFile.add(line.trim());
  33.     };
  34.     fileReader.close();
  35.     bufferReader.close();
  36.     wholeFile.trimToSize();
  37.     return wholeFile;
  38. }
  39.  
  40. String getKorzet(LinkedHashMap tables, String telepules) {
  41.   for (String key : tables.keySet() ) {
  42.     for (String item : tables.get(key) ) {
  43.       if(item==telepules) return key;
  44.     }
  45.   }
  46.   return "";
  47. }
  48.  
  49. void listMenuBarEntries(){
  50.   for (int i=0; i<menuBar.getComponents().length; i++){
  51.     print(i+" "+menuBar.getComponent(i).text);
  52.   }
  53. }
  54.  
  55. void removeMenuBarEntry(String name){
  56.   for (int i=0; i<menuBar.getComponents().length; i++){
  57.     if(menuBar.getComponent(i).text==name){
  58.       menuBar.remove(i);
  59.       menuBar.revalidate();
  60.     }
  61.   }
  62. }
  63.  
  64. myDate = new Date();
  65. myTime = myDate.getHours()+":"+myDate.getMinutes()+":"+myDate.getSeconds();
  66.  
  67. applicationDir = new File(".").getCanonicalPath();
  68.  
  69. context = wc.createPlugInContext();
  70. featureInstaller = context.getFeatureInstaller();
  71. menuBar = featureInstaller.menuBar();
  72. listMenuBarEntries();
  73. removeMenuBarEntry("DAT+");
  74. menu = new JMenu("DAT+");
  75. menu1 = new JMenu("Térképek (SHP)");
  76. menuItem2 = new JMenuItem("Térképek (PostGIS)");
  77. menuItem2.setEnabled(false);
  78. menuItem3 = new JMenuItem("DAT fájl megnyitása");
  79. menuBar.add(menu);
  80. menu.add(menu1);
  81. menu.add(menuItem2);
  82. menu.addSeparator();
  83. menu.add(menuItem3);
  84. menu1.addActionListener(menuItemListener);
  85. menuItem2.addActionListener(menuItemListener);
  86. menuItem3.addActionListener(menuItemListener);
  87. menu.revalidate();
  88.  
  89. tables = new LinkedHashMap();
  90. for ( String line: readToStringList(applicationDir+"\\beanshell\\korzet-telepules.csv") ){
  91.     String[] words = line.trim().split(";");
  92.     if(!tables.containsKey(words[0])){
  93.         tables.put(words[0],new ArrayList());
  94.     }
  95.     tables{words[0]}.add(words[1]);
  96. }
  97.  
  98. for (String key : tables.keySet() ) {
  99.   menu1x = new JMenu(key);
  100.   menu1.add(menu1x);
  101.   for (String item : tables.get(key) ) {
  102.     menuItemX = new JMenuItem(item);
  103.     menuItemX.addActionListener(menuItemListener);
  104.     menu1x.add(menuItemX);
  105.   }
  106. }
  107.  
  108. /*
  109. [WARN] 07:59:01.726 Can't find resource for bundle java.util.PropertyResourceBundle, key Testreszabßs no default value, the resource key is used: Testreszabßs
  110.     menuCustom = featureInstaller.menuBarMenu(I18N.get(MenuNames.CUSTOMIZE));
  111.     menuCustom.add(myTime); print( myTime );
  112. */
  113.  
  114. // Reinitialize the plugin
  115. plugin = new BeanToolsPlugIn();
  116. plugin.initialize(context);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement