Example #1
0
  public void getSavedLocations() {
    // System.out.println("inside getSavedLocations");				//CONSOLE * * * * * * * * * * * * *
    loc.clear(); // clear locations.  helps refresh the list when reprinting all the locations
    BufferedWriter f = null; // just in case file has not been created yet
    BufferedReader br = null;
    try {
      // attempt to open the locations file if it doesn't exist, create it
      f =
          new BufferedWriter(
              new FileWriter("savedLocations.txt", true)); // evaluated true if file does not exist
      br = new BufferedReader(new FileReader("savedLocations.txt"));

      String line; // each line is one index of the list
      loc.add("Saved Locations");
      // loop and read a line from the file as long as we don't get null
      while ((line = br.readLine()) != null)
        // add the read word to the wordList
        loc.add(line);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        // attempt the close the file

        br.close(); // close bufferedwriter
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
  }
Example #2
0
  private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner non-commercial license
    dialogPane = new JPanel();
    contentPanel = new JPanel();
    panel1 = new JPanel();
    label2 = new JLabel();
    ttfSizeW = new JTextField();
    label4 = new JLabel();
    ttfLongi = new JTextField();
    btnGetMap = new JButton();
    label3 = new JLabel();
    ttfSizeH = new JTextField();
    label5 = new JLabel();
    ttfLati = new JTextField();
    btnQuit = new JButton();
    label1 = new JLabel();
    ttfLicense = new JTextField();
    label6 = new JLabel();
    ttfZoom = new JTextField();
    // ComboBox for Saved Locations
    ttfSave = new JComboBox();
    scrollPane1 = new JScrollPane();
    ttaStatus = new JTextArea();
    panel2 = new JPanel();
    panel3 = new JPanel();
    checkboxRecvStatus = new JCheckBox();
    checkboxSendStatus = new JCheckBox();
    ttfProgressMsg = new JTextField();
    progressBar = new JProgressBar();
    lblProgressStatus = new JLabel();

    // ======== this ========
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setTitle("Google Static Maps");
    setIconImage(null);
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    // ======== dialogPane ========
    {
      dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
      dialogPane.setOpaque(false);
      dialogPane.setLayout(new BorderLayout());

      // ======== contentPanel ========
      {
        contentPanel.setOpaque(false);
        contentPanel.setLayout(
            new TableLayout(
                new double[][] {
                  {TableLayout.FILL},
                  {TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED}
                }));
        ((TableLayout) contentPanel.getLayout()).setHGap(5);
        ((TableLayout) contentPanel.getLayout()).setVGap(5);

        // ======== panel1 ========
        {
          panel1.setOpaque(false);
          panel1.setBorder(
              new CompoundBorder(
                  new TitledBorder("Configure the inputs to Google Static Maps"),
                  Borders.DLU2_BORDER));
          panel1.setLayout(
              new TableLayout(
                  new double[][] {
                    {0.17, 0.17, 0.17, 0.17, 0.05, TableLayout.FILL},
                    {TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED}
                  }));
          ((TableLayout) panel1.getLayout()).setHGap(5);
          ((TableLayout) panel1.getLayout()).setVGap(5);

          // ---- label2 ----
          label2.setText("Size Width");
          label2.setHorizontalAlignment(SwingConstants.RIGHT);
          panel1.add(
              label2,
              new TableLayoutConstraints(
                  0, 0, 0, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- ttfSizeW ----
          ttfSizeW.setText("512");
          panel1.add(
              ttfSizeW,
              new TableLayoutConstraints(
                  1, 0, 1, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- label4 ----
          label4.setText("Latitude");
          label4.setHorizontalAlignment(SwingConstants.RIGHT);
          panel1.add(
              label4,
              new TableLayoutConstraints(
                  2, 0, 2, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- ttfLongi ----
          ttfLongi.setText("38.931099");
          panel1.add(
              ttfLongi,
              new TableLayoutConstraints(
                  3, 0, 3, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- btnGetMap ----
          btnGetMap.setText("Get Map");
          btnGetMap.setHorizontalAlignment(SwingConstants.LEFT);
          btnGetMap.setMnemonic('G');
          btnGetMap.addActionListener(
              new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  startTaskAction();
                  if (Integer.parseInt(ttfZoom.getText()) < 14) { // coding for zoom values under 14
                    for (int i = 0; i < 14; i++) {
                      if (Integer.parseInt(ttfZoom.getText()) == i) {
                        countThis = 14 - i; // gets difference
                        do {
                          counter = counter * 2; // found out code zooms in powers of 2.
                          pixelX =
                              0.000084525
                                  * counter; // Values per Latitude, trial and error method used to
                                             // find these numbers.
                          pixelY = 0.00006725 * counter; // Values per Longitude
                          counter1++;
                        } while (counter1 != countThis); // loops the amount of differences
                      }
                      counter = 1; // Resetters
                      counter1 = 0;
                    }
                  } else if (Integer.parseInt(ttfZoom.getText())
                      > 14) { // coding for zoom values over 14
                    for (int i = 14; i < 19; i++) {
                      if (Integer.parseInt(ttfZoom.getText()) == i) {
                        countThis = i - 14; // gets difference
                        do {
                          counter = counter * 2;
                          pixelX = 0.000084525 / counter; // Values per Latitude
                          pixelY = 0.00006725 / counter; // Values per Longitude	            	
                          counter1++;
                        } while (counter1 != countThis); // loops amount of differences
                      }
                      counter = 1; // Resetters
                      counter1 = 0;
                    }
                  } else { // coding for zoom default value of 14.
                    pixelX = 0.000084525;
                    pixelY = 0.00006725;
                  }

                  BigDecimal sendPixelX = new BigDecimal(pixelX);
                  BigDecimal sendPixelY = new BigDecimal(pixelY);

                  pixelX =
                      (sendPixelX.setScale(6, BigDecimal.ROUND_HALF_UP))
                          .doubleValue(); // allows for bigger decimal zoom variables
                  pixelY =
                      (sendPixelY.setScale(6, BigDecimal.ROUND_HALF_UP))
                          .doubleValue(); // Won't reach zoom 1-5 without these!
                }
              });
          panel1.add(
              btnGetMap,
              new TableLayoutConstraints(
                  5, 0, 5, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- label3 ----
          label3.setText("Size Height");
          label3.setHorizontalAlignment(SwingConstants.RIGHT);
          panel1.add(
              label3,
              new TableLayoutConstraints(
                  0, 1, 0, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- ttfSizeH ----
          ttfSizeH.setText("512");
          panel1.add(
              ttfSizeH,
              new TableLayoutConstraints(
                  1, 1, 1, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- label5 ----
          label5.setText("Longitude");
          label5.setHorizontalAlignment(SwingConstants.RIGHT);
          panel1.add(
              label5,
              new TableLayoutConstraints(
                  2, 1, 2, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- ttfLati ----
          ttfLati.setText("-77.3489");
          panel1.add(
              ttfLati,
              new TableLayoutConstraints(
                  3, 1, 3, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- btnQuit ----
          btnQuit.setText("Quit");
          btnQuit.setMnemonic('Q');
          btnQuit.setHorizontalAlignment(SwingConstants.LEFT);
          btnQuit.setHorizontalTextPosition(SwingConstants.RIGHT);
          btnQuit.addActionListener(
              new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  quitProgram();
                }
              });
          panel1.add(
              btnQuit,
              new TableLayoutConstraints(
                  5, 1, 5, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- label1 ----
          label1.setText("License Key");
          label1.setHorizontalAlignment(SwingConstants.RIGHT);
          panel1.add(
              label1,
              new TableLayoutConstraints(
                  0, 2, 0, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- ttfLicense ----
          ttfLicense.setToolTipText("Enter your own URI for a file to download in the background");
          panel1.add(
              ttfLicense,
              new TableLayoutConstraints(
                  1, 2, 1, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- label6 ----
          label6.setText("Zoom");
          label6.setHorizontalAlignment(SwingConstants.RIGHT);
          panel1.add(
              label6,
              new TableLayoutConstraints(
                  2, 2, 2, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- ttfZoom ----
          ttfZoom.setText("14");
          panel1.add(
              ttfZoom,
              new TableLayoutConstraints(
                  3, 2, 3, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- ttfSave ----
          ttfSave.removeAllItems();
          // JComboBox ttfSave = new JComboBox();
          getSavedLocations(); // grabs a new list
          for (int i = 0; i < loc.size(); i++) // populates this list using a arrayList
          ttfSave.addItem(loc.get(i));

          ttfSave.setSelectedIndex(0);
          panel1.add(
              ttfSave,
              new TableLayoutConstraints(
                  5, 2, 5, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));
          // Action Listener to update the coordinates on selected Location
          ttfSave.addActionListener(
              new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  if (mapIsUp == 0) {
                    Object contents = ttfSave.getSelectedItem(); // grabs users selection
                    System.out.println(contents);
                    if (contents != null) {
                      stringCoords = contents.toString();
                      setCoords = stringCoords.split("\\s+");
                      ttfLongi.setText(
                          setCoords[
                              1]); // sets the texts in the longitude and latitude fields to
                                   // coordinates selected
                      ttfLati.setText(setCoords[0]);
                    }
                  }
                }
              });
        }
        contentPanel.add(
            panel1,
            new TableLayoutConstraints(
                0, 0, 0, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

        // ======== scrollPane1 ========
        {
          scrollPane1.setBorder(
              new TitledBorder("System.out - displays all status and progress messages, etc."));
          scrollPane1.setOpaque(false);

          // ---- ttaStatus ----
          ttaStatus.setBorder(Borders.createEmptyBorder("1dlu, 1dlu, 1dlu, 1dlu"));
          ttaStatus.setToolTipText(
              "<html>Task progress updates (messages) are displayed here,<br>along with any other output generated by the Task.<html>");
          scrollPane1.setViewportView(ttaStatus);
        }
        contentPanel.add(
            scrollPane1,
            new TableLayoutConstraints(
                0, 1, 0, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

        // ======== panel2 ========
        {
          panel2.setOpaque(false);
          panel2.setBorder(
              new CompoundBorder(
                  new TitledBorder("Status - control progress reporting"), Borders.DLU2_BORDER));
          panel2.setLayout(
              new TableLayout(
                  new double[][] {
                    {0.45, TableLayout.FILL, 0.45},
                    {TableLayout.PREFERRED, TableLayout.PREFERRED}
                  }));
          ((TableLayout) panel2.getLayout()).setHGap(5);
          ((TableLayout) panel2.getLayout()).setVGap(5);

          // ======== panel3 ========
          {
            panel3.setOpaque(false);
            panel3.setLayout(new GridLayout(1, 2));

            // ---- checkboxRecvStatus ----
            checkboxRecvStatus.setText("Enable \"Recieve\"");
            checkboxRecvStatus.setOpaque(false);
            checkboxRecvStatus.setToolTipText("Task will fire \"send\" status updates");
            checkboxRecvStatus.setSelected(true);
            panel3.add(checkboxRecvStatus);

            // ---- checkboxSendStatus ----
            checkboxSendStatus.setText("Enable \"Send\"");
            checkboxSendStatus.setOpaque(false);
            checkboxSendStatus.setToolTipText("Task will fire \"recieve\" status updates");
            panel3.add(checkboxSendStatus);
          }
          panel2.add(
              panel3,
              new TableLayoutConstraints(
                  0, 0, 0, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- ttfProgressMsg ----
          ttfProgressMsg.setText("Loading map from Google Static Maps");
          ttfProgressMsg.setToolTipText("Set the task progress message here");
          panel2.add(
              ttfProgressMsg,
              new TableLayoutConstraints(
                  2, 0, 2, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- progressBar ----
          progressBar.setStringPainted(true);
          progressBar.setString("progress %");
          progressBar.setToolTipText("% progress is displayed here");
          panel2.add(
              progressBar,
              new TableLayoutConstraints(
                  0, 1, 0, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));

          // ---- lblProgressStatus ----
          lblProgressStatus.setText("task status listener");
          lblProgressStatus.setHorizontalTextPosition(SwingConstants.LEFT);
          lblProgressStatus.setHorizontalAlignment(SwingConstants.LEFT);
          lblProgressStatus.setToolTipText(
              "Task status messages are displayed here when the task runs");
          panel2.add(
              lblProgressStatus,
              new TableLayoutConstraints(
                  2, 1, 2, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));
        }
        contentPanel.add(
            panel2,
            new TableLayoutConstraints(
                0, 2, 0, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL));
      }
      dialogPane.add(contentPanel, BorderLayout.CENTER);
    }
    contentPane.add(dialogPane, BorderLayout.CENTER);
    setSize(675, 485);
    setLocationRelativeTo(null);
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
  }