// Path: src/main/java/org/weasis/dicom/google/explorer/Messages.java
// public class Messages {
//     private static final String BUNDLE_NAME = "org.weasis.dicom.google.explorer.messages"; //$NON-NLS-1$
// 
//     private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
// 
//     private Messages() {
//     }
// 
//     public static String getString(String key) {
//         try {
//             return RESOURCE_BUNDLE.getString(key);
//         } catch (MissingResourceException e) {
//             return '!' + key + '!';
//         }
//     }
// }


import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.util.Preconditions;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.IOException;
import java.net.URI;
import java.awt.Toolkit;
import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.awt.datatransfer.StringSelection;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.weasis.dicom.google.explorer.Messages;
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.weasis.dicom.google.api.ui;







/**
 * OAuth2 authorization browser that copies the authorization URL to the clipboard and shows the
 * notification dialog if there is no default browser configured or an error occurred while opening
 * the default browser.
 * 
 * @author Mikhail Ukhlin
 * @see AuthorizationCodeInstalledApp
 */
public class OAuth2Browser implements AuthorizationCodeInstalledApp.Browser {
  
  private static final Logger LOGGER =
      Logger.getLogger(OAuth2Browser.class.getName());

  /**
   * Single instance of this browser.
   */
  public static final AuthorizationCodeInstalledApp.Browser INSTANCE = new OAuth2Browser();
  
  /**
   * Do not allow more than one instance.
   */
  private OAuth2Browser() {
    super();
  }
  
  /**
   * Opens a browser at the given URL using {@link Desktop} if available, or alternatively copies
   * authorization URL to clipboard and shows notification dialog.
   * 
   * @param url URL to browse.
   * @throws IOException if an IO error occurred.
   * @see AuthorizationCodeInstalledApp#browse(String)
   */
  @Override
  public void browse(String url) throws IOException {
    Preconditions.checkNotNull(url);
    // Ask user to open in their browser using copy-paste
    System.out.println("Please open the following address in your browser:");
    System.out.println("  " + url);
    // Attempt to open it in the browser
    try {
// Path: src/main/java/org/weasis/dicom/google/explorer/Messages.java
// public class Messages {
//     private static final String BUNDLE_NAME = "org.weasis.dicom.google.explorer.messages"; //$NON-NLS-1$
// 
//     private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
// 
//     private Messages() {
//     }
// 
//     public static String getString(String key) {
//         try {
//             return RESOURCE_BUNDLE.getString(key);
//         } catch (MissingResourceException e) {
//             return '!' + key + '!';
//         }
//     }
// }


// Path: src/main/java/org/weasis/dicom/google/api/ui/OAuth2Browser.java
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.util.Preconditions;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.IOException;
import java.net.URI;
import java.awt.Toolkit;
import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.awt.datatransfer.StringSelection;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.weasis.dicom.google.explorer.Messages;

// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.weasis.dicom.google.api.ui;







/**
 * OAuth2 authorization browser that copies the authorization URL to the clipboard and shows the
 * notification dialog if there is no default browser configured or an error occurred while opening
 * the default browser.
 * 
 * @author Mikhail Ukhlin
 * @see AuthorizationCodeInstalledApp
 */
public class OAuth2Browser implements AuthorizationCodeInstalledApp.Browser {
  
  private static final Logger LOGGER =
      Logger.getLogger(OAuth2Browser.class.getName());

  /**
   * Single instance of this browser.
   */
  public static final AuthorizationCodeInstalledApp.Browser INSTANCE = new OAuth2Browser();
  
  /**
   * Do not allow more than one instance.
   */
  private OAuth2Browser() {
    super();
  }
  
  /**
   * Opens a browser at the given URL using {@link Desktop} if available, or alternatively copies
   * authorization URL to clipboard and shows notification dialog.
   * 
   * @param url URL to browse.
   * @throws IOException if an IO error occurred.
   * @see AuthorizationCodeInstalledApp#browse(String)
   */
  @Override
  public void browse(String url) throws IOException {
    Preconditions.checkNotNull(url);
    // Ask user to open in their browser using copy-paste
    System.out.println("Please open the following address in your browser:");
    System.out.println("  " + url);
    // Attempt to open it in the browser
    try {
      if (Desktop.isDesktopSupported()) {