public void changeLAF(int iLAFIndex) {
    try {
      // Change LAF
      if (iLAFIndex >= marrLaf.length) iLAFIndex = marrLaf.length - 1;
      UIManager.setLookAndFeel(
          (LookAndFeel) Class.forName(marrLaf[iLAFIndex].getClassName()).newInstance());

      // Update UI
      ((JMenuItem) mvtLAFItem.elementAt(iLAFIndex)).setSelected(true);
      SwingUtilities.updateComponentTreeUI(this);
      SwingUtilities.updateComponentTreeUI(mnuMain);
      WindowManager.updateLookAndField();

      // Store config
      try {
        Hashtable prt = Global.loadHashtable(Global.FILE_CONFIG);
        prt.put("LAF", String.valueOf(iLAFIndex));
        Global.storeHashtable(prt, Global.FILE_CONFIG);
      } catch (Exception e) {
      }
    } catch (Exception e) {
      e.printStackTrace();
      MessageBox.showMessageDialog(this, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);
    }
  }
Example #2
0
 /** Quit using a separate thread, hopefully avoiding thread deadlocks. */
 public void run() {
   quitting = true;
   boolean changes = false;
   int[] wList = WindowManager.getIDList();
   if (wList != null) {
     for (int i = 0; i < wList.length; i++) {
       ImagePlus imp = WindowManager.getImage(wList[i]);
       if (imp != null && imp.changes == true) {
         changes = true;
         break;
       }
     }
   }
   Frame[] frames = WindowManager.getNonImageWindows();
   if (frames != null) {
     for (int i = 0; i < frames.length; i++) {
       if (frames[i] != null && (frames[i] instanceof Editor)) {
         if (((Editor) frames[i]).fileChanged()) {
           changes = true;
           break;
         }
       }
     }
   }
   if (windowClosed
       && !changes
       && Menus.window.getItemCount() > Menus.WINDOW_MENU_ITEMS
       && !(IJ.macroRunning() && WindowManager.getImageCount() == 0)) {
     GenericDialog gd = new GenericDialog("ImageJ", this);
     gd.addMessage("Are you sure you want to quit ImageJ?");
     gd.showDialog();
     quitting = !gd.wasCanceled();
     windowClosed = false;
   }
   if (!quitting) return;
   if (!WindowManager.closeAllWindows()) {
     quitting = false;
     return;
   }
   // IJ.log("savePreferences");
   if (applet == null) {
     saveWindowLocations();
     Prefs.savePreferences();
   }
   IJ.cleanup();
   // setVisible(false);
   // IJ.log("dispose");
   dispose();
   if (exitWhenQuitting) System.exit(0);
 }
Example #3
0
 /** Handles CheckboxMenuItem state changes. */
 public void itemStateChanged(ItemEvent e) {
   MenuItem item = (MenuItem) e.getSource();
   MenuComponent parent = (MenuComponent) item.getParent();
   String cmd = e.getItem().toString();
   if ((Menu) parent == Menus.window) WindowManager.activateWindow(cmd, item);
   else doCommand(cmd);
 }
  public void changeDictionary(String strLanguage) {
    // Change dictionary
    MonitorDictionary.setCurrentLanguage(strLanguage);
    DefaultDictionary.setCurrentLanguage(strLanguage);
    ErrorDictionary.setCurrentLanguage(strLanguage);

    // Update UI
    updateLanguage();
    WindowManager.updateLanguage();
    int iIndex = mvtLanguage.indexOf(strLanguage);
    if (iIndex >= 0) {
      JRadioButtonMenuItem mnu = (JRadioButtonMenuItem) mvtLanguageItem.elementAt(iIndex);
      mnu.setSelected(true);
    }

    // Store config
    Hashtable prt = null;
    try {
      prt = Global.loadHashtable(Global.FILE_CONFIG);
    } catch (Exception e) {
      prt = new Hashtable();
    }
    prt.put("Language", strLanguage);
    try {
      Global.storeHashtable(prt, Global.FILE_CONFIG);
    } catch (Exception e) {
    }
  }
 public void changePassword() {
   try {
     DialogChangePassword dlgPass = new DialogChangePassword(this, channel);
     if (dlgPass != null) WindowManager.centeredWindow(dlgPass);
   } catch (Exception e) {
     e.printStackTrace();
     MessageBox.showMessageDialog(this, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);
   }
 }
Example #6
0
 void saveWindowLocations() {
   Frame frame = WindowManager.getFrame("B&C");
   if (frame != null) Prefs.saveLocation(ContrastAdjuster.LOC_KEY, frame.getLocation());
   frame = WindowManager.getFrame("Threshold");
   if (frame != null) Prefs.saveLocation(ThresholdAdjuster.LOC_KEY, frame.getLocation());
   frame = WindowManager.getFrame("Results");
   if (frame != null) {
     Prefs.saveLocation(TextWindow.LOC_KEY, frame.getLocation());
     Dimension d = frame.getSize();
     Prefs.set(TextWindow.WIDTH_KEY, d.width);
     Prefs.set(TextWindow.HEIGHT_KEY, d.height);
   }
   frame = WindowManager.getFrame("Log");
   if (frame != null) {
     Prefs.saveLocation(TextWindow.LOG_LOC_KEY, frame.getLocation());
     Dimension d = frame.getSize();
     Prefs.set(TextWindow.LOG_WIDTH_KEY, d.width);
     Prefs.set(TextWindow.LOG_HEIGHT_KEY, d.height);
   }
 }
Example #7
0
 private boolean ignoreArrowKeys(ImagePlus imp) {
   Frame frame = WindowManager.getFrontWindow();
   String title = frame.getTitle();
   if (title != null && title.equals("ROI Manager")) return true;
   // Control Panel?
   if (frame != null && frame instanceof javax.swing.JFrame) return true;
   ImageWindow win = imp.getWindow();
   // LOCI Data Browser window?
   if (imp.getStackSize() > 1 && win != null && win.getClass().getName().startsWith("loci"))
     return true;
   return false;
 }
Example #8
0
 void saveWindowLocations() {
   Window win = WindowManager.getWindow("B&C");
   if (win != null) Prefs.saveLocation(ContrastAdjuster.LOC_KEY, win.getLocation());
   win = WindowManager.getWindow("Threshold");
   if (win != null) Prefs.saveLocation(ThresholdAdjuster.LOC_KEY, win.getLocation());
   win = WindowManager.getWindow("Results");
   if (win != null) {
     Prefs.saveLocation(TextWindow.LOC_KEY, win.getLocation());
     Dimension d = win.getSize();
     Prefs.set(TextWindow.WIDTH_KEY, d.width);
     Prefs.set(TextWindow.HEIGHT_KEY, d.height);
   }
   win = WindowManager.getWindow("Log");
   if (win != null) {
     Prefs.saveLocation(TextWindow.LOG_LOC_KEY, win.getLocation());
     Dimension d = win.getSize();
     Prefs.set(TextWindow.LOG_WIDTH_KEY, d.width);
     Prefs.set(TextWindow.LOG_HEIGHT_KEY, d.height);
   }
   win = WindowManager.getWindow("ROI Manager");
   if (win != null) Prefs.saveLocation(RoiManager.LOC_KEY, win.getLocation());
 }
Example #9
0
  /** @param context */
  public static void showDiagnosticInfo(final Context context) {
    try {
      DBG.m("  Build.VERSION.SDK_INT: " + Build.VERSION.SDK_INT);
      DBG.m("  Build.VERSION.CODENAME: " + Build.VERSION.CODENAME);
      DBG.m("  Build.DEVICE: " + android.os.Build.DEVICE);
      DBG.m("  Build.MODEL: " + android.os.Build.MODEL);
      DBG.m("  Build.PRODUCT: " + android.os.Build.PRODUCT);

      final DisplayMetrics displaymetrics = new DisplayMetrics();
      final WindowManager windowmanager =
          (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
      windowmanager.getDefaultDisplay().getMetrics(displaymetrics);
      DBG.m("  DisplayMetrics.density: " + displaymetrics.density);
      DBG.m("  DisplayMetrics.densityDpi: " + displaymetrics.densityDpi);
      DBG.m("  DisplayMetrics.heightPixels: " + displaymetrics.heightPixels);
      DBG.m("  DisplayMetrics.widthPixels: " + displaymetrics.widthPixels);
      DBG.m("  DisplayMetrics.scaledDensity: " + displaymetrics.scaledDensity);
      DBG.m("  DisplayMetrics.xdpi: " + displaymetrics.xdpi);
      DBG.m("  DisplayMetrics.ydpi: " + displaymetrics.ydpi);
    } catch (Exception x) {
      DBG.m(x);
    }
  }
 public void manageThreads() {
   try {
     DDTP request = new DDTP();
     request.setRequestID(String.valueOf(System.currentTimeMillis()));
     DDTP response = channel.sendRequest("ThreadProcessor", "manageThreadsLoad", request);
     if (response != null) {
       DialogThreadManager dlg =
           new DialogThreadManager(this, channel, response.getVector("vtTableData"));
       dlg.setComboStartupType(response.getVector("vtStartupType"), "");
       WindowManager.centeredWindow(dlg);
     }
   } catch (Exception e) {
     e.printStackTrace();
     MessageBox.showMessageDialog(this, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);
   }
 }
  private synchronized void closeAll() {
    try {
      // Close all child window
      WindowManager.closeAll();

      // Remove all child component
      pnlThread.setVisible(false);
      pnlUser.setVisible(false);
      pnlThread.removeAll();
      clearAll(txtBoard);
      tblUser.setData(new Vector());
      Thread.sleep(500);
    } catch (Exception e) {
      e.printStackTrace();
      MessageBox.showMessageDialog(this, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);
    }
  }
Example #12
0
 void checkForCalibrationConflict(ImagePlus imp, Calibration cal) {
   Calibration gcal = imp.getGlobalCalibration();
   if (gcal == null || !showConflictMessage || IJ.isMacro()) return;
   if (cal.pixelWidth == gcal.pixelWidth && cal.getUnit().equals(gcal.getUnit())) return;
   GenericDialog gd = new GenericDialog(imp.getTitle());
   gd.addMessage("The calibration of this image conflicts\nwith the current global calibration.");
   gd.addCheckbox("Disable_Global Calibration", true);
   gd.addCheckbox("Disable_these Messages", false);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   boolean disable = gd.getNextBoolean();
   if (disable) {
     imp.setGlobalCalibration(null);
     imp.setCalibration(cal);
     WindowManager.repaintImageWindows();
   }
   boolean dontShow = gd.getNextBoolean();
   if (dontShow) showConflictMessage = false;
 }
Example #13
0
  public void keyPressed(KeyEvent e) {
    // if (e.isConsumed()) return;
    int keyCode = e.getKeyCode();
    IJ.setKeyDown(keyCode);
    hotkey = false;
    if (keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT) return;
    char keyChar = e.getKeyChar();
    int flags = e.getModifiers();
    if (IJ.debugMode)
      IJ.log(
          "keyPressed: code="
              + keyCode
              + " ("
              + KeyEvent.getKeyText(keyCode)
              + "), char=\""
              + keyChar
              + "\" ("
              + (int) keyChar
              + "), flags="
              + KeyEvent.getKeyModifiersText(flags));
    boolean shift = (flags & KeyEvent.SHIFT_MASK) != 0;
    boolean control = (flags & KeyEvent.CTRL_MASK) != 0;
    boolean alt = (flags & KeyEvent.ALT_MASK) != 0;
    boolean meta = (flags & KeyEvent.META_MASK) != 0;
    String cmd = null;
    ImagePlus imp = WindowManager.getCurrentImage();
    boolean isStack = (imp != null) && (imp.getStackSize() > 1);

    if (imp != null
        && !control
        && ((keyChar >= 32 && keyChar <= 255) || keyChar == '\b' || keyChar == '\n')) {
      Roi roi = imp.getRoi();
      if (roi instanceof TextRoi) {
        if ((flags & KeyEvent.META_MASK) != 0 && IJ.isMacOSX()) return;
        if (alt) {
          switch (keyChar) {
            case 'u':
            case 'm':
              keyChar = IJ.micronSymbol;
              break;
            case 'A':
              keyChar = IJ.angstromSymbol;
              break;
            default:
          }
        }
        ((TextRoi) roi).addChar(keyChar);
        return;
      }
    }

    // Handle one character macro shortcuts
    if (!control && !meta) {
      Hashtable macroShortcuts = Menus.getMacroShortcuts();
      if (macroShortcuts.size() > 0) {
        if (shift) cmd = (String) macroShortcuts.get(new Integer(keyCode + 200));
        else cmd = (String) macroShortcuts.get(new Integer(keyCode));
        if (cmd != null) {
          // MacroInstaller.runMacroCommand(cmd);
          commandName = cmd;
          MacroInstaller.runMacroShortcut(cmd);
          return;
        }
      }
    }

    if ((!Prefs.requireControlKey || control || meta) && keyChar != '+') {
      Hashtable shortcuts = Menus.getShortcuts();
      if (shift) cmd = (String) shortcuts.get(new Integer(keyCode + 200));
      else cmd = (String) shortcuts.get(new Integer(keyCode));
    }

    if (cmd == null) {
      switch (keyChar) {
        case '<':
        case ',':
          if (isStack) cmd = "Previous Slice [<]";
          break;
        case '>':
        case '.':
        case ';':
          if (isStack) cmd = "Next Slice [>]";
          break;
        case '+':
        case '=':
          cmd = "In [+]";
          break;
        case '-':
          cmd = "Out [-]";
          break;
        case '/':
          cmd = "Reslice [/]...";
          break;
        default:
      }
    }

    if (cmd == null) {
      switch (keyCode) {
        case KeyEvent.VK_TAB:
          WindowManager.putBehind();
          return;
        case KeyEvent.VK_BACK_SPACE: // delete
          if (deleteOverlayRoi(imp)) return;
          cmd = "Clear";
          hotkey = true;
          break;
          // case KeyEvent.VK_BACK_SLASH: cmd=IJ.altKeyDown()?"Animation Options...":"Start
          // Animation"; break;
        case KeyEvent.VK_EQUALS:
          cmd = "In [+]";
          break;
        case KeyEvent.VK_MINUS:
          cmd = "Out [-]";
          break;
        case KeyEvent.VK_SLASH:
        case 0xbf:
          cmd = "Reslice [/]...";
          break;
        case KeyEvent.VK_COMMA:
        case 0xbc:
          if (isStack) cmd = "Previous Slice [<]";
          break;
        case KeyEvent.VK_PERIOD:
        case 0xbe:
          if (isStack) cmd = "Next Slice [>]";
          break;
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_UP:
        case KeyEvent.VK_DOWN: // arrow keys
          if (imp == null) return;
          Roi roi = imp.getRoi();
          if (IJ.shiftKeyDown() && imp == Orthogonal_Views.getImage()) return;
          boolean stackKey = imp.getStackSize() > 1 && (roi == null || IJ.shiftKeyDown());
          boolean zoomKey = roi == null || IJ.shiftKeyDown() || IJ.controlKeyDown();
          if (stackKey && keyCode == KeyEvent.VK_RIGHT) cmd = "Next Slice [>]";
          else if (stackKey && keyCode == KeyEvent.VK_LEFT) cmd = "Previous Slice [<]";
          else if (zoomKey
              && keyCode == KeyEvent.VK_DOWN
              && !ignoreArrowKeys(imp)
              && Toolbar.getToolId() < Toolbar.SPARE6) cmd = "Out [-]";
          else if (zoomKey
              && keyCode == KeyEvent.VK_UP
              && !ignoreArrowKeys(imp)
              && Toolbar.getToolId() < Toolbar.SPARE6) cmd = "In [+]";
          else if (roi != null) {
            if ((flags & KeyEvent.ALT_MASK) != 0) roi.nudgeCorner(keyCode);
            else roi.nudge(keyCode);
            return;
          }
          break;
        case KeyEvent.VK_ESCAPE:
          abortPluginOrMacro(imp);
          return;
        case KeyEvent.VK_ENTER:
          WindowManager.toFront(this);
          return;
        default:
          break;
      }
    }

    if (cmd != null && !cmd.equals("")) {
      commandName = cmd;
      if (cmd.equals("Fill") || cmd.equals("Draw")) hotkey = true;
      if (cmd.charAt(0) == MacroInstaller.commandPrefix) MacroInstaller.runMacroShortcut(cmd);
      else {
        doCommand(cmd);
        keyPressedTime = System.currentTimeMillis();
        lastKeyCommand = cmd;
      }
    }
  }
Example #14
0
 public void mousePressed(MouseEvent e) {
   Undo.reset();
   if (!Prefs.noClickToGC) System.gc();
   IJ.showStatus(version() + IJ.freeMemory());
   if (IJ.debugMode) IJ.log("Windows: " + WindowManager.getWindowCount());
 }
  public void login() {
    mbAutoLogIn = false;
    while (!mbAutoLogIn) {
      try {
        // Confirm logout
        if (isOpen()) {
          if (MessageBox.showConfirmDialog(
                  this,
                  MonitorDictionary.getString("Confirm.Exit"),
                  Global.APP_NAME,
                  MessageBox.YES_NO_OPTION)
              == MessageBox.NO_OPTION) return;

          // Disconnect from server
          disconnect();
        }

        // Login
        DialogLogin dlgLogin = new DialogLogin(this);
        WindowManager.centeredWindow(dlgLogin);

        if (dlgLogin.miReturn == JOptionPane.OK_OPTION) {
          // Update UI
          SwingUtilities.updateComponentTreeUI(pnlUser);
          SwingUtilities.updateComponentTreeUI(pnlThread);

          // Request to connect
          Socket sck = new Socket(dlgLogin.mstrHost, Integer.parseInt(dlgLogin.mstrPort));
          sck.setSoLinger(true, 0);

          // Start up a channel thread that reads messages from the server
          channel =
              new SocketTransmitter(sck) {
                public void close() {
                  if (msckMain != null) {
                    super.close();
                    closeAll();
                    if (mbAutoLogIn) login();
                  }
                }
              };
          channel.setUserName(dlgLogin.mstrUserName);
          channel.setPackage("com.fss.thread.");
          channel.start();

          // Request to Server
          DDTP request = new DDTP();
          request.setRequestID(String.valueOf(System.currentTimeMillis()));
          request.setString("UserName", dlgLogin.mstrUserName);
          request.setString("Password", dlgLogin.mstrPassword);

          // Response from Server
          DDTP response = channel.sendRequest("ThreadProcessor", "login", request);
          mstrThreadAppName = response.getString("strThreadAppName");
          mstrThreadAppVersion = response.getString("strThreadAppVersion");
          mstrAppName = response.getString("strAppName");
          mstrAppVersion = response.getString("strAppVersion");
          if (response != null) {
            if (response.getString("PasswordExpired") != null) {
              DialogChangePassword frm = new DialogChangePassword(this, channel);
              WindowManager.centeredWindow(frm);
              if (frm.miReturnValue != JOptionPane.OK_OPTION) throw new AppException("FSS-10003");
            }
            String strLog = StringUtil.nvl(response.getString("strLog"), "");
            showResult(txtBoard, strLog);
            Vector vtThread = response.getVector("vtThread");
            updateTabBar(vtThread);

            mstrChannel = response.getString("strChannel");
            if (mstrChannel != null) removeUser(mstrChannel);
          }
          btnRefresh.doClick();
          pnlThread.setVisible(true);
          pnlUser.setVisible(true);
          setResizeWeight(1);
          setDividerLocation((int) (getSize().getHeight() - 160));
        }
        mbAutoLogIn = true;
        updateLanguage();
      } catch (Exception e) {
        e.printStackTrace();
        MessageBox.showMessageDialog(this, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);

        // Disconnect from server
        mstrChannel = null;
        disconnect();
      }
    }
  }
  public void onCreate() {
    int flags, screenLightVal = 1;
    Sensor mSensor;
    List<Sensor> sensors;

    if (scanData == null) return; // no ScanData, not possible to run correctly...

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    try {
      screenLightVal = Integer.parseInt(SP.getString("screenLight", "2"));
    } catch (NumberFormatException nfe) {
    }
    if (screenLightVal == 1) flags = PowerManager.PARTIAL_WAKE_LOCK;
    else if (screenLightVal == 3) flags = PowerManager.FULL_WAKE_LOCK;
    else flags = PowerManager.SCREEN_DIM_WAKE_LOCK;
    wl = pm.newWakeLock(flags, "OpenWLANMap");
    wl.acquire();
    while (myWLocate == null) {
      try {
        myWLocate = new MyWLocate(this);
        break;
      } catch (IllegalArgumentException iae) {
        myWLocate = null;
      }
      try {
        Thread.sleep(100);
      } catch (InterruptedException ie) {
      }
    }

    try {
      scanData.setUploadThres(Integer.parseInt(SP.getString("autoUpload", "0")));
    } catch (NumberFormatException nfe) {
    }
    try {
      scanData.setNoGPSExitInterval(
          Integer.parseInt(SP.getString("noGPSExitInterval", "0")) * 60 * 1000);
    } catch (NumberFormatException nfe) {
    }

    Intent intent = new Intent(this, OWMapAtAndroid.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0);

    notification =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setContentTitle(getResources().getText(R.string.app_name))
            .setContentText("")
            .setContentIntent(pendIntent)
            .build();

    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(1703, notification);

    getScanData().setService(this);
    getScanData().setmView(new HUDView(this));
    getScanData().getmView().setValue(getScanData().incStoredValues());
    WindowManager.LayoutParams params =
        new WindowManager.LayoutParams(
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.LEFT | Gravity.BOTTOM;
    params.setTitle("Load Average");
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    wm.addView(getScanData().getmView(), params);

    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    sensorManager.registerListener(
        this,
        sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
        SensorManager.SENSOR_DELAY_GAME);
    sensorManager.registerListener(
        this,
        sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
        SensorManager.SENSOR_DELAY_GAME);
    sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
    mSensor = sensors.get(0);
    getScanData().getTelemetryData().setAccelMax(mSensor.getMaximumRange());
    telemetryDir = Environment.getExternalStorageDirectory().getPath() + "/telemetry/";
    File dir = new File(telemetryDir);
    dir.mkdir();

    connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
  }