Exemplo n.º 1
0
  /** Determine whether the current user has Windows administrator privileges. */
  public static boolean isWinAdmin() {
    if (!isWinPlatform()) return false;
    //    for (String group : new com.sun.security.auth.module.NTSystem().getGroupIDs()) {
    //      if (group.equals("S-1-5-32-544")) return true; // "S-1-5-32-544" is a well-known
    // security identifier in Windows. If the current user has it then he/she/it is an
    // administrator.
    //    }
    //    return false;

    try {
      Class<?> ntsys = Class.forName("com.sun.security.auth.module.NTSystem");
      if (ntsys != null) {
        Object groupObj =
            SystemUtils.invoke(
                ntsys.newInstance(), ntsys.getDeclaredMethod("getGroupIDs"), (Object[]) null);
        if (groupObj instanceof String[]) {
          for (String group : (String[]) groupObj) {
            if (group.equals("S-1-5-32-544"))
              return true; // "S-1-5-32-544" is a well-known security identifier in Windows. If the
                           // current user has it then he/she/it is an administrator.
          }
        }
      }
    } catch (ReflectiveOperationException e) {
      System.err.println(e);
    }
    return false;
  }
Exemplo n.º 2
0
 public static void invoke(String aClass, String aMethod, Class[] params, Object[] args)
     throws Exception {
   Class c = Class.forName(aClass);
   Constructor constructor = c.getConstructor(params);
   Method m = c.getDeclaredMethod(aMethod, params);
   Object i = constructor.newInstance(args);
   Object r = m.invoke(i, args);
 }
  private String invokeDecrypter(Class<?> decrypterclass, String name, String arg)
      throws Exception {
    try {
      Method decryptermethod = decrypterclass.getDeclaredMethod(name, String.class);

      decryptermethod.setAccessible(true);
      return (String) decryptermethod.invoke(null, arg);

    } catch (Exception e) {
      log("Could not invoke decrypter method: " + name + " of class " + decrypterclass.getName());
      throw e;
    }
  }
 private static Method findMethod(
     Class<? extends Object> aClass, String methodName, Class[] params) {
   try {
     final Method method = aClass.getDeclaredMethod(methodName, params);
     method.setAccessible(true);
     return method;
   } catch (NoSuchMethodException ignored) {
   }
   final Class<?> parent = aClass.getSuperclass();
   if (parent == null) {
     return null;
   }
   return findMethod(parent, methodName, params);
 }
Exemplo n.º 5
0
    private static void fixPopupSize(final Popup popup, final Component contents) {
      if (!UIUtil.isUnderGTKLookAndFeel() || !(contents instanceof JPopupMenu)) return;

      for (Class<?> aClass = popup.getClass();
          aClass != null && Popup.class.isAssignableFrom(aClass);
          aClass = aClass.getSuperclass()) {
        try {
          final Method getComponent = aClass.getDeclaredMethod("getComponent");
          getComponent.setAccessible(true);
          final Object component = getComponent.invoke(popup);
          if (component instanceof JWindow) {
            ((JWindow) component).setSize(new Dimension(0, 0));
          }
          break;
        } catch (Exception ignored) {
        }
      }
    }
Exemplo n.º 6
0
 public static void openURL(final String url) {
   final Configuration.OperatingSystem os = Configuration.getCurrentOperatingSystem();
   try {
     if (os == Configuration.OperatingSystem.MAC) {
       final Class<?> fileMgr = Class.forName("com.apple.eio.FileManager");
       final Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
       openURL.invoke(null, url);
     } else if (os == Configuration.OperatingSystem.WINDOWS) {
       Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
     } else {
       final String[] browsers = {
         "firefox",
         "opera",
         "konqueror",
         "epiphany",
         "mozilla",
         "netscape",
         "google-chrome",
         "chromium-browser"
       };
       String browser = null;
       for (int count = 0; count < browsers.length && browser == null; count++) {
         if (Runtime.getRuntime().exec(new String[] {"which", browsers[count]}).waitFor() == 0) {
           browser = browsers[count];
         }
       }
       if (browser == null) {
         throw new Exception("Could not find web browser");
       } else {
         Runtime.getRuntime().exec(new String[] {browser, url});
       }
     }
   } catch (final Exception e) {
     log.warning("Unable to open " + url);
   }
 }
Exemplo n.º 7
0
  /** @param arg */
  public static void main(String arg[]) {
    TestApp af = new TestApp();

    SourceImage sImg = null;

    int imagesPerRow = 0;
    int imagesPerCol = 0;

    int imgMin = 65536;
    int imgMax = 0;

    boolean signed = false;
    boolean inverted = false;
    boolean hasPad = false;
    int padValue = 0;

    if (arg.length == 6) {
      // do it with raw file
      int w = 0;
      int h = 0;
      int d = 0;
      try {
        w = Integer.valueOf(arg[1]).intValue();
        h = Integer.valueOf(arg[2]).intValue();
        d = Integer.valueOf(arg[3]).intValue();
        imagesPerRow = Integer.valueOf(arg[4]).intValue();
        imagesPerCol = Integer.valueOf(arg[5]).intValue();
      } catch (Exception e) {
        System.err.println(e);
        System.exit(0);
      }

      try {
        FileInputStream i = new FileInputStream(arg[0]);
        sImg = new SourceImage(i, w, h, d);
      } catch (Exception e) {
        System.err.println(e);
        System.exit(0);
      }
    } else {
      // do it with DICOM file

      if (arg.length > 2) {
        try {
          imagesPerRow = Integer.valueOf(arg[1]).intValue();
          imagesPerCol = Integer.valueOf(arg[2]).intValue();
        } catch (Exception e) {
          System.err.println(e);
          e.printStackTrace(System.err);
          System.exit(0);
        }
      } else {
        imagesPerRow = 1;
        imagesPerCol = 1;
      }

      try {
        DicomInputStream i = new DicomInputStream(new FileInputStream(arg[0]));
        sImg = new SourceImage(i);
      } catch (Exception e) {
        System.err.println(e);
        e.printStackTrace(System.err);
        System.exit(0);
      }
    }

    try {
      // com.apple.cocoa.application.NSMenu.setMenuBarVisible(false);							// Won't compile on
      // other platforms
      // Class classToUse =
      // ClassLoader.getSystemClassLoader().loadClass("com.apple.cocoa.application.NSMenu");	//
      // Needs "/System/Library/Java" in classpath
      Class classToUse =
          new java.net.URLClassLoader(new java.net.URL[] {new File("/System/Library/Java").toURL()})
              .loadClass("com.apple.cocoa.application.NSMenu");
      Class[] parameterTypes = {Boolean.TYPE};
      java.lang.reflect.Method methodToUse =
          classToUse.getDeclaredMethod("setMenuBarVisible", parameterTypes);
      Object[] args = {Boolean.FALSE};
      methodToUse.invoke(null /*since static*/, args);
    } catch (Exception e) { // ClassNotFoundException,NoSuchMethodException,IllegalAccessException
      e.printStackTrace(System.err);
    }

    java.awt.Dimension d = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    int frameWidth = (int) d.getWidth();
    int frameHeight = (int) d.getHeight();
    System.err.println("frameWidth=" + frameWidth);
    System.err.println("frameHeight=" + frameHeight);
    af.setUndecorated(true);
    af.setLocation(0, 0);
    af.setSize(frameWidth, frameHeight);

    JPanel multiPanel = new JPanel();
    multiPanel.setLayout(new GridLayout(imagesPerCol, imagesPerRow));
    multiPanel.setBackground(Color.black);

    SingleImagePanel imagePanel[] = new SingleImagePanel[imagesPerRow * imagesPerCol];

    int singleWidth = frameWidth / imagesPerRow;
    int singleHeight = frameHeight / imagesPerCol;
    System.err.println("singleWidth=" + singleWidth);
    System.err.println("singleHeight=" + singleHeight);

    for (int x = 0; x < imagesPerCol; ++x) {
      for (int y = 0; y < imagesPerRow; ++y) {
        SingleImagePanel ip = new SingleImagePanel(sImg);
        // ip.setPreferredSize(new Dimension(img.getWidth(),img.getHeight()));
        // ip.setPreferredSize(new Dimension(sImg.getWidth(),sImg.getHeight()));
        ip.setPreferredSize(new Dimension(singleWidth, singleHeight));
        multiPanel.add(ip);
        imagePanel[x * imagesPerRow + y] = ip;
      }
    }

    // multiPanel.setSize(img.getWidth()*imagesPerRow,img.getHeight()*imagesPerRow);

    // JScrollPane scrollPane = new JScrollPane(multiPanel);

    Container content = af.getContentPane();
    content.setLayout(new GridLayout(1, 1));
    // content.add(scrollPane);
    content.add(multiPanel);

    af.pack();
    af.setVisible(true);
  }