Search in sources :

Example 1 with OsmBoundsFilter

use of net.osmand.osm.io.OsmBoundsFilter in project OsmAnd-tools by osmandapp.

the class OsmExtractionUI method fillMenuWithActions.

public void fillMenuWithActions(final JMenuBar bar) {
    // $NON-NLS-1$
    JMenu menu = new JMenu(Messages.getString("OsmExtractionUI.MENU_FILE"));
    bar.add(menu);
    // $NON-NLS-1$
    JMenuItem loadFile = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_SELECT_FILE"));
    menu.add(loadFile);
    // $NON-NLS-1$
    JMenuItem loadSpecifiedAreaFile = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_SELECT_OSM_FILE_AREA"));
    menu.add(loadSpecifiedAreaFile);
    // $NON-NLS-1$
    JMenuItem specifyWorkingDir = new JMenuItem(Messages.getString("OsmExtractionUI.SPECIFY_WORKING_DIR"));
    menu.add(specifyWorkingDir);
    menu.addSeparator();
    // $NON-NLS-1$
    JMenuItem exitMenu = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_EXIT"));
    menu.add(exitMenu);
    // JMenu tileSource = new JMenu(Messages.getString("OsmExtractionUI.MENU_MAPS")); //$NON-NLS-1$MapPanel.getMenuToChooseSource(mapPanel);
    // $NON-NLS-1$
    final JMenuItem sqliteDB = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_CREATE_SQLITE"));
    // tileSource.addSeparator();
    // tileSource.add(sqliteDB);
    JMenu tileSource = MapPanel.getMenuToChooseSource(mapPanel);
    tileSource.addSeparator();
    tileSource.add(sqliteDB);
    bar.add(tileSource);
    // $NON-NLS-1$
    menu = new JMenu(Messages.getString("OsmExtractionUI.MENU_WINDOW"));
    bar.add(menu);
    // $NON-NLS-1$
    JMenuItem settings = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_SETTINGS"));
    menu.add(settings);
    menu.addSeparator();
    // $NON-NLS-1$
    JMenuItem openLogFile = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_OPEN_LOG"));
    menu.add(openLogFile);
    // $NON-NLS-1$
    menu = new JMenu(Messages.getString("OsmExtractionUI.MENU_ABOUT"));
    bar.add(menu);
    // $NON-NLS-1$
    JMenuItem aboutApplication = new JMenuItem(Messages.getString("OsmExtractionUI.MENU_ABOUT_2"));
    menu.add(aboutApplication);
    aboutApplication.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(frame, MapCreatorVersion.APP_MAP_CREATOR_FULL_NAME);
        }
    });
    openLogFile.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            File file = new File(OsmExtractionUI.LOG_PATH);
            if (file != null && file.exists()) {
                if (System.getProperty("os.name").startsWith("Windows")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    try {
                        // $NON-NLS-1$
                        Runtime.getRuntime().exec(new String[] { "notepad.exe", file.getAbsolutePath() });
                    } catch (IOException es) {
                        // $NON-NLS-1$
                        ExceptionHandler.handle(Messages.getString("OsmExtractionUI.UNABLE_OPEN_FILE"), es);
                    }
                } else {
                    // $NON-NLS-1$
                    JOptionPane.showMessageDialog(frame, Messages.getString("OsmExtractionUI.OPEN_LOG_FILE_MANUALLY") + LOG_PATH);
                }
            } else {
                // $NON-NLS-1$
                ExceptionHandler.handle(Messages.getString("OsmExtractionUI.LOG_FILE_NOT_FOUND"));
            }
        }
    });
    sqliteDB.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // $NON-NLS-1$
            final String regionName = OsmExtractionUI.this.regionName == null ? Messages.getString("OsmExtractionUI.REGION") : OsmExtractionUI.this.regionName;
            final ITileSource map = mapPanel.getMap();
            if (map != null) {
                try {
                    // $NON-NLS-1$
                    final ProgressDialog dlg = new ProgressDialog(frame, Messages.getString("OsmExtractionUI.CREATING_INDEX"));
                    dlg.setRunnable(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                SQLiteBigPlanetIndex.createSQLiteDatabase(DataExtractionSettings.getSettings().getTilesDirectory(), regionName, map);
                            } catch (SQLException e1) {
                                throw new IllegalArgumentException(e1);
                            } catch (IOException e1) {
                                throw new IllegalArgumentException(e1);
                            }
                        }
                    });
                    dlg.run();
                } catch (InterruptedException e1) {
                    // $NON-NLS-1$
                    log.error("Interrupted", e1);
                } catch (InvocationTargetException e1) {
                    // $NON-NLS-1$
                    ExceptionHandler.handle("Can't create big planet sqlite index", e1.getCause());
                }
            }
        }
    });
    exitMenu.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            frame.setVisible(false);
            exit();
        }
    });
    settings.addActionListener(new ActionListener() {

        private void applySettings() {
            mapPanel.applySettings();
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            OsmExtractionPreferencesDialog dlg = new OsmExtractionPreferencesDialog(frame);
            dlg.showDialog();
            applySettings();
        }
    });
    specifyWorkingDir.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new JFileChooser();
            // $NON-NLS-1$
            fc.setDialogTitle(Messages.getString("OsmExtractionUI.CHOOSE_WORKING_DIR"));
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            File workingDir = DataExtractionSettings.getSettings().getDefaultWorkingDir();
            if (workingDir != null) {
                fc.setCurrentDirectory(workingDir);
            }
            if (fc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null && fc.getSelectedFile().isDirectory()) {
                DataExtractionSettings.getSettings().saveDefaultWorkingDir(fc.getSelectedFile());
                mapPanel.setTilesLocation(DataExtractionSettings.getSettings().getTilesDirectory());
                // $NON-NLS-1$
                statusBarLabel.setText(Messages.getString("OsmExtractionUI.WORKING_DIR") + fc.getSelectedFile().getAbsolutePath());
                JMenu tileSource = MapPanel.getMenuToChooseSource(mapPanel);
                tileSource.add(sqliteDB);
                bar.remove(1);
                bar.add(tileSource, 1);
            }
        }
    });
    loadSpecifiedAreaFile.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = getOsmFileChooser();
            int answer = fc.showOpenDialog(frame);
            if (answer == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null) {
                final JDialog dlg = new JDialog(frame, true);
                // $NON-NLS-1$
                dlg.setTitle(Messages.getString("OsmExtractionUI.SELECT_AREA_TO_FILTER"));
                MapPanel panel = new MapPanel(DataExtractionSettings.getSettings().getTilesDirectory());
                panel.setLatLon(mapPanel.getLatitude(), mapPanel.getLongitude());
                panel.setZoom(mapPanel.getZoom());
                final StringBuilder res = new StringBuilder();
                panel.getLayer(MapInformationLayer.class).setAreaActionHandler(new // $NON-NLS-1$
                AbstractAction(// $NON-NLS-1$
                Messages.getString("OsmExtractionUI.SELECT_AREA")) {

                    private static final long serialVersionUID = -3452957517341961969L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        res.append(true);
                        dlg.setVisible(false);
                    }
                });
                dlg.add(panel);
                JMenuBar bar = new JMenuBar();
                bar.add(MapPanel.getMenuToChooseSource(panel));
                dlg.setJMenuBar(bar);
                dlg.setSize(512, 512);
                double x = frame.getBounds().getCenterX();
                double y = frame.getBounds().getCenterY();
                dlg.setLocation((int) x - dlg.getWidth() / 2, (int) y - dlg.getHeight() / 2);
                dlg.setVisible(true);
                if (res.length() > 0 && panel.getSelectionArea().isVisible()) {
                    MapSelectionArea area = panel.getSelectionArea();
                    IOsmStorageFilter filter = new OsmBoundsFilter(area.getLat1(), area.getLon1(), area.getLat2(), area.getLon2());
                    loadCountry(fc.getSelectedFile(), filter);
                }
            }
        }
    });
    loadFile.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = getOsmFileChooser();
            int answer = fc.showOpenDialog(frame);
            if (answer == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null) {
                loadCountry(fc.getSelectedFile(), null);
            }
        }
    });
}
Also used : SQLException(java.sql.SQLException) ActionEvent(java.awt.event.ActionEvent) OsmBoundsFilter(net.osmand.osm.io.OsmBoundsFilter) MapSelectionArea(net.osmand.swing.MapPanel.MapSelectionArea) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) IOsmStorageFilter(net.osmand.osm.io.IOsmStorageFilter) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ITileSource(net.osmand.map.ITileSource) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) JMenu(javax.swing.JMenu) JDialog(javax.swing.JDialog) JMenuBar(javax.swing.JMenuBar)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SQLException (java.sql.SQLException)1 AbstractAction (javax.swing.AbstractAction)1 JDialog (javax.swing.JDialog)1 JFileChooser (javax.swing.JFileChooser)1 JMenu (javax.swing.JMenu)1 JMenuBar (javax.swing.JMenuBar)1 JMenuItem (javax.swing.JMenuItem)1 ITileSource (net.osmand.map.ITileSource)1 IOsmStorageFilter (net.osmand.osm.io.IOsmStorageFilter)1 OsmBoundsFilter (net.osmand.osm.io.OsmBoundsFilter)1 MapSelectionArea (net.osmand.swing.MapPanel.MapSelectionArea)1