Esempio n. 1
0
 protected void registerBoundingBoxBuilder() {
   BoundingBoxBuilder bboxbuilder = new BoundingBoxBuilder();
   for (JosmTextField ll : latlon) {
     ll.addFocusListener(bboxbuilder);
     ll.addActionListener(bboxbuilder);
   }
 }
Esempio n. 2
0
    private void build() {
      filter = new JosmTextField(30);
      filter.setColumns(10);
      filter.getDocument().addDocumentListener(this);

      selectionList = new JList<>(data.toArray(new String[0]));
      selectionList.setModel(model = new ProjectionCodeListModel());
      JScrollPane scroll = new JScrollPane(selectionList);
      scroll.setPreferredSize(new Dimension(200, 214));

      this.setLayout(new GridBagLayout());
      this.add(filter, GBC.eol().weight(1.0, 0.0));
      this.add(scroll, GBC.eol());
    }
    protected JPanel buildContentPanel() {
      JPanel pnl = new JPanel(new GridBagLayout());
      GridBagConstraints gc = new GridBagConstraints();

      gc.anchor = GridBagConstraints.NORTHWEST;
      gc.fill = GridBagConstraints.HORIZONTAL;
      gc.weightx = 1.0;
      gc.gridwidth = 2;
      HtmlPanel html = new HtmlPanel();
      html.setText(
          tr(
              "<html>"
                  + "JOSM successfully retrieved a Request Token. "
                  + "JOSM is now launching an authorization page in an external browser. "
                  + "Please login with your OSM username and password and follow the instructions "
                  + "to authorize the Request Token. Then switch back to this dialog and click on "
                  + "<strong>{0}</strong><br><br>"
                  + "If launching the external browser fails you can copy the following authorize URL "
                  + "and paste it into the address field of your browser.</html>",
              tr("Request Access Token")));
      pnl.add(html, gc);

      gc.gridx = 0;
      gc.gridy = 1;
      gc.weightx = 0.0;
      gc.gridwidth = 1;
      pnl.add(new JLabel(tr("Authorize URL:")), gc);

      gc.gridx = 1;
      gc.weightx = 1.0;
      pnl.add(tfAuthoriseUrl = new JosmTextField(), gc);
      tfAuthoriseUrl.setEditable(false);

      return pnl;
    }
Esempio n. 4
0
 public void init(String username, String password) {
   username = username == null ? "" : username;
   password = password == null ? "" : password;
   tfUserName.setText(username);
   tfPassword.setText(password);
   cbSaveCredentials.setSelected(!username.isEmpty() && !password.isEmpty());
 }
Esempio n. 5
0
 protected void check() {
   double value = 0;
   try {
     value = Double.parseDouble(tfLatValue.getText());
   } catch (NumberFormatException ex) {
     setErrorMessage(
         tfLatValue,
         tr("The string ''{0}'' is not a valid double value.", tfLatValue.getText()));
     return;
   }
   if (!LatLon.isValidLat(value)) {
     setErrorMessage(
         tfLatValue, tr("Value for latitude in range [-90,90] required.", tfLatValue.getText()));
     return;
   }
   resetErrorMessage(tfLatValue);
 }
Esempio n. 6
0
  private JPanel buildFilterPanel() {
    // copied from PluginPreference
    JPanel pnl = new JPanel(new GridBagLayout());
    pnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    GridBagConstraints gc = new GridBagConstraints();

    gc.anchor = GridBagConstraints.NORTHWEST;
    gc.fill = GridBagConstraints.HORIZONTAL;
    gc.weightx = 0.0;
    gc.insets = new Insets(0, 0, 0, 5);
    pnl.add(new JLabel(tr("Search:")), gc);

    gc.gridx = 1;
    gc.weightx = 1.0;
    pnl.add(filterField, gc);
    filterField.setToolTipText(tr("Enter a search expression"));
    SelectAllOnFocusGainedDecorator.decorate(filterField);
    filterField.getDocument().addDocumentListener(new FilterFieldAdapter());
    pnl.setMaximumSize(new Dimension(300, 10));
    return pnl;
  }
Esempio n. 7
0
  /** Saves the values to the preferences */
  public void saveToPreferences() {
    String old_url = Main.pref.get("osm-server.url", null);
    if (cbUseDefaultServerUrl.isSelected()) {
      Main.pref.put("osm-server.url", null);
    } else if (tfOsmServerUrl.getText().trim().equals(OsmApi.DEFAULT_API_URL)) {
      Main.pref.put("osm-server.url", null);
    } else {
      Main.pref.put("osm-server.url", tfOsmServerUrl.getText().trim());
    }
    String new_url = Main.pref.get("osm-server.url", null);

    // When API URL changes, re-initialize API connection so we may adjust
    // server-dependent settings.
    if ((old_url == null && new_url != null) || (old_url != null && !old_url.equals(new_url))) {
      try {
        OsmApi.getOsmApi().initialize(null);
      } catch (Exception x) {
        // ignore;
      }
    }
  }
Esempio n. 8
0
  protected void build() {
    setLayout(new GridBagLayout());
    GridBagConstraints gc = new GridBagConstraints();

    // the checkbox for the default UL
    gc.fill = GridBagConstraints.HORIZONTAL;
    gc.anchor = GridBagConstraints.NORTHWEST;
    gc.weightx = 1.0;
    gc.insets = new Insets(0, 0, 0, 0);
    gc.gridwidth = 4;
    add(buildDefultServerUrlPanel(), gc);

    // the input field for the URL
    gc.gridx = 0;
    gc.gridy = 1;
    gc.gridwidth = 1;
    gc.weightx = 0.0;
    gc.insets = new Insets(0, 0, 0, 3);
    add(lblApiUrl = new JLabel(tr("OSM Server URL:")), gc);

    gc.gridx = 1;
    gc.weightx = 1.0;
    add(tfOsmServerUrl = new JosmTextField(), gc);
    SelectAllOnFocusGainedDecorator.decorate(tfOsmServerUrl);
    valOsmServerUrl = new ApiUrlValidator(tfOsmServerUrl);
    valOsmServerUrl.validate();
    ApiUrlPropagator propagator = new ApiUrlPropagator();
    tfOsmServerUrl.addActionListener(propagator);
    tfOsmServerUrl.addFocusListener(propagator);

    gc.gridx = 2;
    gc.weightx = 0.0;
    add(lblValid = new JLabel(), gc);

    gc.gridx = 3;
    gc.weightx = 0.0;
    ValidateApiUrlAction actTest = new ValidateApiUrlAction();
    tfOsmServerUrl.getDocument().addDocumentListener(actTest);
    add(btnTest = new SideButton(actTest), gc);
  }
Esempio n. 9
0
 /** Initializes the configuration panel with values from the preferences */
 public void initFromPreferences() {
   String url = Main.pref.get("osm-server.url", null);
   if (url == null) {
     cbUseDefaultServerUrl.setSelected(true);
     firePropertyChange(API_URL_PROP, null, OsmApi.DEFAULT_API_URL);
   } else if (url.trim().equals(OsmApi.DEFAULT_API_URL)) {
     cbUseDefaultServerUrl.setSelected(true);
     firePropertyChange(API_URL_PROP, null, OsmApi.DEFAULT_API_URL);
   } else {
     cbUseDefaultServerUrl.setSelected(false);
     tfOsmServerUrl.setText(url);
     firePropertyChange(API_URL_PROP, null, url);
   }
 }
Esempio n. 10
0
 private void updateFilter() {
   filteredData.clear();
   String filterTxt = filter.getText().trim().toLowerCase(Locale.ENGLISH);
   for (String code : data) {
     if (code.toLowerCase(Locale.ENGLISH).contains(filterTxt)) {
       filteredData.add(code);
     }
   }
   model.fireContentsChanged();
   int idx = filteredData.indexOf(lastCode);
   if (idx == -1) {
     selectionList.clearSelection();
     if (selectionList.getModel().getSize() > 0) {
       selectionList.ensureIndexIsVisible(0);
     }
   } else {
     selectionList.setSelectedIndex(idx);
     selectionList.ensureIndexIsVisible(idx);
   }
 }
Esempio n. 11
0
 /** Show only shortcuts with descriptions coontaing given substring */
 public void filter(String substring) {
   filterField.setText(substring);
 }
Esempio n. 12
0
  @Override
  public JPanel getExportPanel() {
    final JPanel p = new JPanel(new GridBagLayout());
    JPanel topRow = new JPanel(new GridBagLayout());
    export = new JCheckBox();
    export.setSelected(true);
    final JLabel lbl = new JLabel(layer.getName(), layer.getIcon(), SwingConstants.LEFT);
    lbl.setToolTipText(layer.getToolTipText());

    JLabel lblData = new JLabel(tr("Data:"));
    /* I18n: Refer to a OSM data file in session file */ link = new JRadioButton(tr("local file"));
    link.putClientProperty("actionname", "link");
    link.setToolTipText(tr("Link to a OSM data file on your local disk."));
    /* I18n: Include OSM data in session file */ include = new JRadioButton(tr("include"));
    include.setToolTipText(tr("Include OSM data in the .joz session file."));
    include.putClientProperty("actionname", "include");
    ButtonGroup group = new ButtonGroup();
    group.add(link);
    group.add(include);

    JPanel cardLink = new JPanel(new GridBagLayout());
    final File file = layer.getAssociatedFile();
    final LayerSaveAction saveAction = new LayerSaveAction();
    final JButton save = new JButton(saveAction);
    if (file != null) {
      JosmTextField tf = new JosmTextField();
      tf.setText(file.getPath());
      tf.setEditable(false);
      cardLink.add(tf, GBC.std());
      save.setMargin(new Insets(0, 0, 0, 0));
      cardLink.add(save, GBC.eol().insets(2, 0, 0, 0));
    } else {
      cardLink.add(new JLabel(tr("No file association")), GBC.eol());
    }

    JPanel cardInclude = new JPanel(new GridBagLayout());
    JLabel lblIncl = new JLabel(tr("OSM data will be included in the session file."));
    lblIncl.setFont(lblIncl.getFont().deriveFont(Font.PLAIN));
    cardInclude.add(lblIncl, GBC.eol().fill(GBC.HORIZONTAL));

    final CardLayout cl = new CardLayout();
    final JPanel cards = new JPanel(cl);
    cards.add(cardLink, "link");
    cards.add(cardInclude, "include");

    if (file != null) {
      link.setSelected(true);
    } else {
      link.setEnabled(false);
      link.setToolTipText(tr("No file association"));
      include.setSelected(true);
      cl.show(cards, "include");
    }

    link.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cl.show(cards, "link");
          }
        });
    include.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cl.show(cards, "include");
          }
        });

    topRow.add(export, GBC.std());
    topRow.add(lbl, GBC.std());
    topRow.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
    p.add(topRow, GBC.eol().fill(GBC.HORIZONTAL));
    p.add(lblData, GBC.std().insets(10, 0, 0, 0));
    p.add(link, GBC.std());
    p.add(include, GBC.eol());
    p.add(cards, GBC.eol().insets(15, 0, 3, 3));

    export.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.DESELECTED) {
              GuiHelper.setEnabledRec(p, false);
              export.setEnabled(true);
            } else {
              GuiHelper.setEnabledRec(p, true);
              save.setEnabled(saveAction.isEnabled());
              link.setEnabled(file != null);
            }
          }
        });
    return p;
  }
 public void setAuthoriseUrl(String url) {
   tfAuthoriseUrl.setText(url);
 }
Esempio n. 14
0
 public void setApiUrlInputEnabled(boolean enabled) {
   lblApiUrl.setEnabled(enabled);
   tfOsmServerUrl.setEnabled(enabled);
   lblValid.setEnabled(enabled);
   btnTest.setEnabled(enabled);
 }
Esempio n. 15
0
 protected final String getImageryName() {
   return sanitize(name.getText());
 }
Esempio n. 16
0
 protected void resetErrorMessage(JosmTextField tf) {
   tf.setBorder(UIManager.getBorder("TextField.border"));
   tf.setToolTipText(null);
 }
Esempio n. 17
0
    @Override
    public void actionPerformed(ActionEvent arg0) {
      SimpleDateFormat dateFormat =
          (SimpleDateFormat) DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM);

      panel = new JPanel(new BorderLayout());
      panel.add(
          new JLabel(
              tr(
                  "<html>Take a photo of your GPS receiver while it displays the time.<br>"
                      + "Display that photo here.<br>"
                      + "And then, simply capture the time you read on the photo and select a timezone<hr></html>")),
          BorderLayout.NORTH);

      imgDisp = new ImageDisplay();
      imgDisp.setPreferredSize(new Dimension(300, 225));
      panel.add(imgDisp, BorderLayout.CENTER);

      JPanel panelTf = new JPanel(new GridBagLayout());

      GridBagConstraints gc = new GridBagConstraints();
      gc.gridx = gc.gridy = 0;
      gc.gridwidth = gc.gridheight = 1;
      gc.weightx = gc.weighty = 0.0;
      gc.fill = GridBagConstraints.NONE;
      gc.anchor = GridBagConstraints.WEST;
      panelTf.add(new JLabel(tr("Photo time (from exif):")), gc);

      lbExifTime = new JLabel();
      gc.gridx = 1;
      gc.weightx = 1.0;
      gc.fill = GridBagConstraints.HORIZONTAL;
      gc.gridwidth = 2;
      panelTf.add(lbExifTime, gc);

      gc.gridx = 0;
      gc.gridy = 1;
      gc.gridwidth = gc.gridheight = 1;
      gc.weightx = gc.weighty = 0.0;
      gc.fill = GridBagConstraints.NONE;
      gc.anchor = GridBagConstraints.WEST;
      panelTf.add(new JLabel(tr("Gps time (read from the above photo): ")), gc);

      tfGpsTime = new JosmTextField(12);
      tfGpsTime.setEnabled(false);
      tfGpsTime.setMinimumSize(new Dimension(155, tfGpsTime.getMinimumSize().height));
      gc.gridx = 1;
      gc.weightx = 1.0;
      gc.fill = GridBagConstraints.HORIZONTAL;
      panelTf.add(tfGpsTime, gc);

      gc.gridx = 2;
      gc.weightx = 0.2;
      panelTf.add(new JLabel(" [" + dateFormat.toLocalizedPattern() + ']'), gc);

      gc.gridx = 0;
      gc.gridy = 2;
      gc.gridwidth = gc.gridheight = 1;
      gc.weightx = gc.weighty = 0.0;
      gc.fill = GridBagConstraints.NONE;
      gc.anchor = GridBagConstraints.WEST;
      panelTf.add(new JLabel(tr("I am in the timezone of: ")), gc);

      String[] tmp = TimeZone.getAvailableIDs();
      List<String> vtTimezones = new ArrayList<>(tmp.length);

      for (String tzStr : tmp) {
        TimeZone tz = TimeZone.getTimeZone(tzStr);

        String tzDesc =
            new StringBuilder(tzStr)
                .append(" (")
                .append(formatTimezone(tz.getRawOffset() / 3600000.0))
                .append(')')
                .toString();
        vtTimezones.add(tzDesc);
      }

      Collections.sort(vtTimezones);

      cbTimezones = new JosmComboBox<>(vtTimezones.toArray(new String[0]));

      String tzId = Main.pref.get("geoimage.timezoneid", "");
      TimeZone defaultTz;
      if (tzId.isEmpty()) {
        defaultTz = TimeZone.getDefault();
      } else {
        defaultTz = TimeZone.getTimeZone(tzId);
      }

      cbTimezones.setSelectedItem(
          new StringBuilder(defaultTz.getID())
              .append(" (")
              .append(formatTimezone(defaultTz.getRawOffset() / 3600000.0))
              .append(')')
              .toString());

      gc.gridx = 1;
      gc.weightx = 1.0;
      gc.gridwidth = 2;
      gc.fill = GridBagConstraints.HORIZONTAL;
      panelTf.add(cbTimezones, gc);

      panel.add(panelTf, BorderLayout.SOUTH);

      JPanel panelLst = new JPanel(new BorderLayout());

      imgList =
          new JList<>(
              new AbstractListModel<String>() {
                @Override
                public String getElementAt(int i) {
                  return yLayer.data.get(i).getFile().getName();
                }

                @Override
                public int getSize() {
                  return yLayer.data != null ? yLayer.data.size() : 0;
                }
              });
      imgList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      imgList
          .getSelectionModel()
          .addListSelectionListener(
              new ListSelectionListener() {

                @Override
                public void valueChanged(ListSelectionEvent arg0) {
                  int index = imgList.getSelectedIndex();
                  Integer orientation = null;
                  try {
                    orientation = ExifReader.readOrientation(yLayer.data.get(index).getFile());
                  } catch (Exception e) {
                    Main.warn(e);
                  }
                  imgDisp.setImage(yLayer.data.get(index).getFile(), orientation);
                  Date date = yLayer.data.get(index).getExifTime();
                  if (date != null) {
                    DateFormat df =
                        DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM);
                    lbExifTime.setText(df.format(date));
                    tfGpsTime.setText(df.format(date));
                    tfGpsTime.setCaretPosition(tfGpsTime.getText().length());
                    tfGpsTime.setEnabled(true);
                    tfGpsTime.requestFocus();
                  } else {
                    lbExifTime.setText(tr("No date"));
                    tfGpsTime.setText("");
                    tfGpsTime.setEnabled(false);
                  }
                }
              });
      panelLst.add(new JScrollPane(imgList), BorderLayout.CENTER);

      JButton openButton = new JButton(tr("Open another photo"));
      openButton.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
              AbstractFileChooser fc =
                  DiskAccessAction.createAndOpenFileChooser(
                      true,
                      false,
                      null,
                      JpgImporter.FILE_FILTER_WITH_FOLDERS,
                      JFileChooser.FILES_ONLY,
                      "geoimage.lastdirectory");
              if (fc == null) return;
              File sel = fc.getSelectedFile();

              Integer orientation = null;
              try {
                orientation = ExifReader.readOrientation(sel);
              } catch (Exception e) {
                Main.warn(e);
              }
              imgDisp.setImage(sel, orientation);

              Date date = null;
              try {
                date = ExifReader.readTime(sel);
              } catch (Exception e) {
                Main.warn(e);
              }
              if (date != null) {
                lbExifTime.setText(
                    DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM).format(date));
                tfGpsTime.setText(DateUtils.getDateFormat(DateFormat.SHORT).format(date) + ' ');
                tfGpsTime.setEnabled(true);
              } else {
                lbExifTime.setText(tr("No date"));
                tfGpsTime.setText("");
                tfGpsTime.setEnabled(false);
              }
            }
          });
      panelLst.add(openButton, BorderLayout.PAGE_END);

      panel.add(panelLst, BorderLayout.LINE_START);

      boolean isOk = false;
      while (!isOk) {
        int answer =
            JOptionPane.showConfirmDialog(
                Main.parent,
                panel,
                tr("Synchronize time from a photo of the GPS receiver"),
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (answer == JOptionPane.CANCEL_OPTION) return;

        long delta;

        try {
          delta =
              dateFormat.parse(lbExifTime.getText()).getTime()
                  - dateFormat.parse(tfGpsTime.getText()).getTime();
        } catch (ParseException e) {
          JOptionPane.showMessageDialog(
              Main.parent,
              tr("Error while parsing the date.\n" + "Please use the requested format"),
              tr("Invalid date"),
              JOptionPane.ERROR_MESSAGE);
          continue;
        }

        String selectedTz = (String) cbTimezones.getSelectedItem();
        int pos = selectedTz.lastIndexOf('(');
        tzId = selectedTz.substring(0, pos - 1);
        String tzValue = selectedTz.substring(pos + 1, selectedTz.length() - 1);

        Main.pref.put("geoimage.timezoneid", tzId);
        tfOffset.setText(Long.toString(delta / 1000));
        tfTimezone.setText(tzValue);

        isOk = true;
      }
      statusBarUpdater.updateStatusBar();
      yLayer.updateBufferAndRepaint();
    }
Esempio n. 18
0
 public String getUserName() {
   return tfUserName.getText();
 }
Esempio n. 19
0
 public void startUserInput() {
   tfUserName.requestFocusInWindow();
 }
Esempio n. 20
0
    protected void build() {
      tfUserName = new JosmTextField(20);
      tfPassword = new JosmPasswordField(20);
      tfUserName.addFocusListener(new SelectAllOnFocusHandler());
      tfPassword.addFocusListener(new SelectAllOnFocusHandler());
      tfUserName.addKeyListener(new TFKeyListener(owner, tfUserName, tfPassword));
      tfPassword.addKeyListener(new TFKeyListener(owner, tfPassword, tfUserName));
      cbSaveCredentials =
          new JCheckBox(owner != null ? owner.saveUsernameAndPasswordCheckboxText : "");

      setLayout(new GridBagLayout());
      GridBagConstraints gc = new GridBagConstraints();
      gc.gridwidth = 2;
      gc.gridheight = 1;
      gc.fill = GridBagConstraints.HORIZONTAL;
      gc.weightx = 1.0;
      gc.weighty = 0.0;
      gc.insets = new Insets(0, 0, 10, 0);
      add(lblHeading, gc);

      gc.gridx = 0;
      gc.gridy = 1;
      gc.gridwidth = 1;
      gc.gridheight = 1;
      gc.fill = GridBagConstraints.HORIZONTAL;
      gc.weightx = 0.0;
      gc.weighty = 0.0;
      gc.insets = new Insets(0, 0, 10, 10);
      add(new JLabel(tr("Username")), gc);
      gc.gridx = 1;
      gc.gridy = 1;
      gc.weightx = 1.0;
      add(tfUserName, gc);
      gc.gridx = 0;
      gc.gridy = 2;
      gc.weightx = 0.0;
      add(new JLabel(tr("Password")), gc);

      gc.gridx = 1;
      gc.gridy = 2;
      gc.weightx = 0.0;
      add(tfPassword, gc);

      gc.gridx = 0;
      gc.gridy = 3;
      gc.gridwidth = 2;
      gc.gridheight = 1;
      gc.fill = GridBagConstraints.BOTH;
      gc.weightx = 1.0;
      gc.weighty = 0.0;
      lblWarning.setFont(lblWarning.getFont().deriveFont(Font.ITALIC));
      add(lblWarning, gc);

      gc.gridx = 0;
      gc.gridy = 4;
      gc.weighty = 0.0;
      add(cbSaveCredentials, gc);

      // consume the remaining space
      gc.gridx = 0;
      gc.gridy = 5;
      gc.weighty = 1.0;
      add(new JPanel(), gc);
    }
Esempio n. 21
0
  @Override
  public void actionPerformed(ActionEvent arg0) {
    // Construct the list of loaded GPX tracks
    Collection<Layer> layerLst = Main.map.mapView.getAllLayers();
    GpxDataWrapper defaultItem = null;
    for (Layer cur : layerLst) {
      if (cur instanceof GpxLayer) {
        GpxLayer curGpx = (GpxLayer) cur;
        GpxDataWrapper gdw =
            new GpxDataWrapper(curGpx.getName(), curGpx.data, curGpx.data.storageFile);
        gpxLst.add(gdw);
        if (cur == yLayer.gpxLayer) {
          defaultItem = gdw;
        }
      }
    }
    for (GpxData data : loadedGpxData) {
      gpxLst.add(new GpxDataWrapper(data.storageFile.getName(), data, data.storageFile));
    }

    if (gpxLst.isEmpty()) {
      gpxLst.add(new GpxDataWrapper(tr("<No GPX track loaded yet>"), null, null));
    }

    JPanel panelCb = new JPanel();

    panelCb.add(new JLabel(tr("GPX track: ")));

    cbGpx = new JosmComboBox<>(gpxLst.toArray(new GpxDataWrapper[0]));
    if (defaultItem != null) {
      cbGpx.setSelectedItem(defaultItem);
    }
    cbGpx.addActionListener(statusBarUpdaterWithRepaint);
    panelCb.add(cbGpx);

    JButton buttonOpen = new JButton(tr("Open another GPX trace"));
    buttonOpen.addActionListener(new LoadGpxDataActionListener());
    panelCb.add(buttonOpen);

    JPanel panelTf = new JPanel(new GridBagLayout());

    String prefTimezone = Main.pref.get("geoimage.timezone", "0:00");
    if (prefTimezone == null) {
      prefTimezone = "0:00";
    }
    try {
      timezone = parseTimezone(prefTimezone);
    } catch (ParseException e) {
      timezone = 0;
    }

    tfTimezone = new JosmTextField(10);
    tfTimezone.setText(formatTimezone(timezone));

    try {
      delta = parseOffset(Main.pref.get("geoimage.delta", "0"));
    } catch (ParseException e) {
      delta = 0;
    }
    delta = delta / 1000; // milliseconds -> seconds

    tfOffset = new JosmTextField(10);
    tfOffset.setText(Long.toString(delta));

    JButton buttonViewGpsPhoto =
        new JButton(
            tr("<html>Use photo of an accurate clock,<br>" + "e.g. GPS receiver display</html>"));
    buttonViewGpsPhoto.setIcon(ImageProvider.get("clock"));
    buttonViewGpsPhoto.addActionListener(new SetOffsetActionListener());

    JButton buttonAutoGuess = new JButton(tr("Auto-Guess"));
    buttonAutoGuess.setToolTipText(tr("Matches first photo with first gpx point"));
    buttonAutoGuess.addActionListener(new AutoGuessActionListener());

    JButton buttonAdjust = new JButton(tr("Manual adjust"));
    buttonAdjust.addActionListener(new AdjustActionListener());

    JLabel labelPosition = new JLabel(tr("Override position for: "));

    int numAll = getSortedImgList(true, true).size();
    int numExif = numAll - getSortedImgList(false, true).size();
    int numTagged = numAll - getSortedImgList(true, false).size();

    cbExifImg =
        new JCheckBox(tr("Images with geo location in exif data ({0}/{1})", numExif, numAll));
    cbExifImg.setEnabled(numExif != 0);

    cbTaggedImg =
        new JCheckBox(tr("Images that are already tagged ({0}/{1})", numTagged, numAll), true);
    cbTaggedImg.setEnabled(numTagged != 0);

    labelPosition.setEnabled(cbExifImg.isEnabled() || cbTaggedImg.isEnabled());

    boolean ticked = yLayer.thumbsLoaded || Main.pref.getBoolean("geoimage.showThumbs", false);
    cbShowThumbs = new JCheckBox(tr("Show Thumbnail images on the map"), ticked);
    cbShowThumbs.setEnabled(!yLayer.thumbsLoaded);

    int y = 0;
    GBC gbc = GBC.eol();
    gbc.gridx = 0;
    gbc.gridy = y++;
    panelTf.add(panelCb, gbc);

    gbc = GBC.eol().fill(GBC.HORIZONTAL).insets(0, 0, 0, 12);
    gbc.gridx = 0;
    gbc.gridy = y++;
    panelTf.add(new JSeparator(SwingConstants.HORIZONTAL), gbc);

    gbc = GBC.std();
    gbc.gridx = 0;
    gbc.gridy = y;
    panelTf.add(new JLabel(tr("Timezone: ")), gbc);

    gbc = GBC.std().fill(GBC.HORIZONTAL);
    gbc.gridx = 1;
    gbc.gridy = y++;
    gbc.weightx = 1.;
    panelTf.add(tfTimezone, gbc);

    gbc = GBC.std();
    gbc.gridx = 0;
    gbc.gridy = y;
    panelTf.add(new JLabel(tr("Offset:")), gbc);

    gbc = GBC.std().fill(GBC.HORIZONTAL);
    gbc.gridx = 1;
    gbc.gridy = y++;
    gbc.weightx = 1.;
    panelTf.add(tfOffset, gbc);

    gbc = GBC.std().insets(5, 5, 5, 5);
    gbc.gridx = 2;
    gbc.gridy = y - 2;
    gbc.gridheight = 2;
    gbc.gridwidth = 2;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 0.5;
    panelTf.add(buttonViewGpsPhoto, gbc);

    gbc = GBC.std().fill(GBC.BOTH).insets(5, 5, 5, 5);
    gbc.gridx = 2;
    gbc.gridy = y++;
    gbc.weightx = 0.5;
    panelTf.add(buttonAutoGuess, gbc);

    gbc.gridx = 3;
    panelTf.add(buttonAdjust, gbc);

    gbc = GBC.eol().fill(GBC.HORIZONTAL).insets(0, 12, 0, 0);
    gbc.gridx = 0;
    gbc.gridy = y++;
    panelTf.add(new JSeparator(SwingConstants.HORIZONTAL), gbc);

    gbc = GBC.eol();
    gbc.gridx = 0;
    gbc.gridy = y++;
    panelTf.add(labelPosition, gbc);

    gbc = GBC.eol();
    gbc.gridx = 1;
    gbc.gridy = y++;
    panelTf.add(cbExifImg, gbc);

    gbc = GBC.eol();
    gbc.gridx = 1;
    gbc.gridy = y++;
    panelTf.add(cbTaggedImg, gbc);

    gbc = GBC.eol();
    gbc.gridx = 0;
    gbc.gridy = y++;
    panelTf.add(cbShowThumbs, gbc);

    final JPanel statusBar = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    statusBar.setBorder(BorderFactory.createLoweredBevelBorder());
    statusBarText = new JLabel(" ");
    statusBarText.setFont(statusBarText.getFont().deriveFont(8));
    statusBar.add(statusBarText);

    tfTimezone.addFocusListener(repaintTheMap);
    tfOffset.addFocusListener(repaintTheMap);

    tfTimezone.getDocument().addDocumentListener(statusBarUpdater);
    tfOffset.getDocument().addDocumentListener(statusBarUpdater);
    cbExifImg.addItemListener(statusBarUpdaterWithRepaint);
    cbTaggedImg.addItemListener(statusBarUpdaterWithRepaint);

    statusBarUpdater.updateStatusBar();

    outerPanel = new JPanel(new BorderLayout());
    outerPanel.add(statusBar, BorderLayout.PAGE_END);

    if (!GraphicsEnvironment.isHeadless()) {
      syncDialog =
          new ExtendedDialog(
              Main.parent,
              tr("Correlate images with GPX track"),
              new String[] {tr("Correlate"), tr("Cancel")},
              false);
      syncDialog.setContent(panelTf, false);
      syncDialog.setButtonIcons(new String[] {"ok", "cancel"});
      syncDialog.setupDialog();
      outerPanel.add(syncDialog.getContentPane(), BorderLayout.PAGE_START);
      syncDialog.setContentPane(outerPanel);
      syncDialog.pack();
      syncDialog.addWindowListener(new SyncDialogWindowListener());
      syncDialog.showDialog();
    }
  }
Esempio n. 22
0
 protected void setErrorMessage(JosmTextField tf, String msg) {
   tf.setBorder(errorBorder);
   tf.setToolTipText(msg);
 }