Package at.kugel.tool.buildtray.action

Source Code of at.kugel.tool.buildtray.action.OpenBrowserCommand

package at.kugel.tool.buildtray.action;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import at.kugel.tool.buildtray.action.desktop.DesktopOperation;
import at.kugel.tool.buildtray.config.Config;
import at.kugel.tool.buildtray.status.SetStatusAble;

/**
* Open the browser. Invoke Desktip BROWSE.
*
* @author <a href="http://www.code-cop.org/">Peter Kofler</a>
*/
abstract class OpenBrowserCommand extends ActionCommand {

   public OpenBrowserCommand(Config config, SetStatusAble statusDisplay) {
      super(config, statusDisplay);
   }

   @Override
   protected void workTemplate() throws IOException {
      openDesktopBrowser();
   }

   private void openDesktopBrowser() throws IOException {
      new DesktopOperation(Desktop.Action.BROWSE) {
         @Override
         public void runWithDesktop(Desktop deskTop) throws IOException {
            deskTop.browse(createDisplayUri());
         }
      }.run();
   }

   private URI createDisplayUri() throws IOException {
      try {
         return determineDisplayUrl().toURI();
      } catch (URISyntaxException e) {
         throw new IOException(e);
      }
   }

   protected abstract URL determineDisplayUrl();

}
TOP

Related Classes of at.kugel.tool.buildtray.action.OpenBrowserCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.