Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- OpenJump - Menü from CSV
- */
- import com.vividsolutions.jump.*;
- import com.vividsolutions.jump.workbench.ui.*;
- import com.vividsolutions.jump.workbench.ui.plugin.*;
- import org.openjump.core.ui.plugin.customize.*;
- import java.util.*;
- import java.nio.charset.*;
- import java.nio.file.*;
- import java.io.*;
- class MenuItemListener implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- print( "'" + getKorzet(tables, e.getActionCommand()) + "' & '" + e.getActionCommand() + "' has been clicked.");
- //showMessageDialog( null, getKorzet(e.getActionCommand())+"\\"+e.getActionCommand() );
- //dialog = new MultiInputDialog(wc.workbench.frame, "...", true);
- //dialog.addSubTitle(getKorzet(e.getActionCommand())+"\\"+e.getActionCommand());
- }
- }
- MenuItemListener menuItemListener = new MenuItemListener();
- ArrayList readToStringList(String fileName) throws IOException {
- ArrayList wholeFile = new ArrayList();
- fileReader = new FileReader(fileName);
- bufferReader = new BufferedReader(fileReader);
- while( (line=bufferReader.readLine()) != null ) {
- if ( line.length()==0 || line.equals("") || line.startsWith("#") ) { continue; }
- wholeFile.add(line.trim());
- };
- fileReader.close();
- bufferReader.close();
- wholeFile.trimToSize();
- return wholeFile;
- }
- String getKorzet(LinkedHashMap tables, String telepules) {
- for (String key : tables.keySet() ) {
- for (String item : tables.get(key) ) {
- if(item==telepules) return key;
- }
- }
- return "";
- }
- void listMenuBarEntries(){
- for (int i=0; i<menuBar.getComponents().length; i++){
- print(i+" "+menuBar.getComponent(i).text);
- }
- }
- void removeMenuBarEntry(String name){
- for (int i=0; i<menuBar.getComponents().length; i++){
- if(menuBar.getComponent(i).text==name){
- menuBar.remove(i);
- menuBar.revalidate();
- }
- }
- }
- myDate = new Date();
- myTime = myDate.getHours()+":"+myDate.getMinutes()+":"+myDate.getSeconds();
- applicationDir = new File(".").getCanonicalPath();
- context = wc.createPlugInContext();
- featureInstaller = context.getFeatureInstaller();
- menuBar = featureInstaller.menuBar();
- listMenuBarEntries();
- removeMenuBarEntry("DAT+");
- menu = new JMenu("DAT+");
- menu1 = new JMenu("Térképek (SHP)");
- menuItem2 = new JMenuItem("Térképek (PostGIS)");
- menuItem2.setEnabled(false);
- menuItem3 = new JMenuItem("DAT fájl megnyitása");
- menuBar.add(menu);
- menu.add(menu1);
- menu.add(menuItem2);
- menu.addSeparator();
- menu.add(menuItem3);
- menu1.addActionListener(menuItemListener);
- menuItem2.addActionListener(menuItemListener);
- menuItem3.addActionListener(menuItemListener);
- menu.revalidate();
- tables = new LinkedHashMap();
- for ( String line: readToStringList(applicationDir+"\\beanshell\\korzet-telepules.csv") ){
- String[] words = line.trim().split(";");
- if(!tables.containsKey(words[0])){
- tables.put(words[0],new ArrayList());
- }
- tables{words[0]}.add(words[1]);
- }
- for (String key : tables.keySet() ) {
- menu1x = new JMenu(key);
- menu1.add(menu1x);
- for (String item : tables.get(key) ) {
- menuItemX = new JMenuItem(item);
- menuItemX.addActionListener(menuItemListener);
- menu1x.add(menuItemX);
- }
- }
- /*
- [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
- menuCustom = featureInstaller.menuBarMenu(I18N.get(MenuNames.CUSTOMIZE));
- menuCustom.add(myTime); print( myTime );
- */
- // Reinitialize the plugin
- plugin = new BeanToolsPlugIn();
- plugin.initialize(context);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement