Пример #1
0
  private void setSelectedDevice(Boolean refreshRequired) {
    final Device device =
        commonPreferences.getDevices().get(specificPreferences.getSelectedDeviceId());
    if (device == null) {
      skin.getShell().close();
    } else {
      Class<? extends BrowserSimSkin> newSkinClass =
          BrowserSimUtil.getSkinClass(device, specificPreferences.getUseSkins());
      String oldSkinUrl = null;
      if (newSkinClass != skin.getClass()) {
        oldSkinUrl = skin.getBrowser().getUrl();
        Point currentLocation = skin.getShell().getLocation();
        skin.getBrowser().removeProgressListener(progressListener);
        skin.getBrowser().getShell().dispose();
        initSkin(newSkinClass, currentLocation);
        fireSkinChangeEvent();
      }
      setOrientation(specificPreferences.getOrientationAngle(), device);

      skin.getBrowser().setDefaultUserAgent(device.getUserAgent());

      if (oldSkinUrl != null) {
        skin.getBrowser().setUrl(oldSkinUrl); // skin (and browser instance) is changed
      } else if (!Boolean.FALSE.equals(refreshRequired)) {
        getBrowser()
            .refresh(); // only user agent and size of the browser is changed and orientation is not
                        // changed
      }

      skin.getShell().open();
    }
  }
Пример #2
0
  public void open(SpecificPreferences sp, String url) {
    if (url == null) {
      url = homeUrl;
    }

    specificPreferences = sp;
    initObservers();
    Device defaultDevice =
        commonPreferences.getDevices().get(specificPreferences.getSelectedDeviceId());
    if (defaultDevice == null) {
      System.out.println("Could not find selected device in devices list");
      String id;
      try {
        id = commonPreferences.getDevices().keySet().iterator().next();
      } catch (NoSuchElementException e) {
        commonPreferences = CommonPreferencesStorage.INSTANCE.loadDefault();
        id = commonPreferences.getDevices().keySet().iterator().next();
      }
      specificPreferences.setSelectedDeviceId(id);
      defaultDevice = commonPreferences.getDevices().get(id);
    }

    initSkin(
        BrowserSimUtil.getSkinClass(defaultDevice, specificPreferences.getUseSkins()),
        specificPreferences.getLocation());
    setSelectedDevice(null);
    controlHandler.goToAddress(url);

    instances.add(BrowserSim.this);
    skin.getShell().open();
  }
Пример #3
0
 public void reinitSkin() {
   final Device device =
       commonPreferences.getDevices().get(specificPreferences.getSelectedDeviceId());
   Class<? extends BrowserSimSkin> newSkinClass =
       BrowserSimUtil.getSkinClass(device, specificPreferences.getUseSkins());
   String oldSkinUrl = skin.getBrowser().getUrl();
   Point currentLocation = skin.getShell().getLocation();
   skin.getBrowser().removeProgressListener(progressListener);
   skin.getBrowser().getShell().dispose();
   initSkin(newSkinClass, currentLocation);
   setOrientation(specificPreferences.getOrientationAngle(), device);
   skin.getBrowser().setDefaultUserAgent(device.getUserAgent());
   skin.getBrowser().setUrl(oldSkinUrl);
   skin.getShell().open();
 }
Пример #4
0
 private void initObservers() {
   commonPreferencesObserver =
       new Observer() {
         @Override
         public void update(Observable o, Object refreshRequired) {
           setSelectedDeviceAsync((Boolean) refreshRequired);
         }
       };
   commonPreferences.addObserver(commonPreferencesObserver);
   specificPreferences.addObserver(
       new Observer() {
         public void update(Observable o, Object refreshRequired) {
           setSelectedDeviceAsync((Boolean) refreshRequired);
         }
       });
 }