예제 #1
0
 /** Return the control based on a control type for the PlugIn. */
 public Object getControl(String controlType) {
   try {
     Class cls = Class.forName(controlType);
     Object cs[] = getControls();
     for (int i = 0; i < cs.length; i++) {
       if (cls.isInstance(cs[i])) return cs[i];
     }
     return null;
   } catch (Exception e) { // no such controlType or such control
     return null;
   }
 }
예제 #2
0
  private /*synchronized*/ StructureType assignStructureType(String structType)
      throws VisualizerLoadException {

    if (debug) System.out.println("In assignStructureType with " + structType);

    // Handle objects whose constructors require args separately
    if ((structType.toUpperCase().compareTo("BAR") == 0)
        || (structType.toUpperCase().compareTo("SCAT") == 0))
      return (new BarScat(structType.toUpperCase()));
    else if ((structType.toUpperCase().compareTo("GRAPH") == 0)
        || (structType.toUpperCase().compareTo("NETWORK") == 0))
      return (new Graph_Network(structType.toUpperCase()));
    else { // Constructor for object does not require args

      try {
        return ((StructureType)
            ((Class.forName(insure_text_case_correct_for_legacy_scripts(structType)))
                .newInstance()));
      } catch (InstantiationException e) {
        System.out.println(e);
        throw (new VisualizerLoadException(structType + " is invalid structure type"));
      } catch (IllegalAccessException e) {
        System.out.println(e);
        throw (new VisualizerLoadException(structType + " is invalid structure type"));
      } catch (ClassNotFoundException e) {
        System.out.println(e);
        throw (new VisualizerLoadException(structType + " is invalid structure type"));
      }
    }
  }
예제 #3
0
 private static boolean classExists(final ClassLoader classLoader, final String clazzName) {
   try {
     return Class.forName(clazzName, false, classLoader) != null;
   } catch (final Throwable ignored) {
   }
   return false;
 }
예제 #4
0
 @Override
 T getInstance() {
   try {
     ReflectUtil.checkPackageAccess(clazz);
     return clazz.newInstance();
   } catch (InstantiationException | IllegalAccessException ignored) {
   }
   return null;
 }
예제 #5
0
  /**
   * Returns an instance of the default toolkit. The default toolkit is the subclass of <code>
   * Toolkit</code> specified in the system property <code>awt.toolkit</code>, or <code>
   * gnu.java.awt.peer.gtk.GtkToolkit</code> if the property is not set.
   *
   * @return An instance of the system default toolkit.
   * @error AWTError If the toolkit cannot be loaded.
   */
  public static Toolkit getDefaultToolkit() {
    if (toolkit != null) return (toolkit);

    String toolkit_name = System.getProperty("awt.toolkit", default_toolkit_name);

    try {
      Class cls = Class.forName(toolkit_name);
      Object obj = cls.newInstance();

      if (!(obj instanceof Toolkit))
        throw new AWTError(toolkit_name + " is not a subclass of " + "java.awt.Toolkit");

      toolkit = (Toolkit) obj;
      return (toolkit);
    } catch (Exception e) {
      throw new AWTError("Cannot load AWT toolkit: " + e.getMessage());
    }
  }
 /** Creates a new instance. */
 public QuaquaPantherFileChooserLAF() {
   String targetClassName = "apple.laf.AquaLookAndFeel";
   try {
     setTarget((LookAndFeel) Class.forName(targetClassName).newInstance());
   } catch (Exception e) {
     throw new InternalError(
         "Unable to instanciate target Look and Feel \""
             + targetClassName
             + "\". "
             + e.getMessage());
   }
 }
예제 #7
0
 public static String constname(Class<?> cl, int val) {
   String ret = null;
   for (java.lang.reflect.Field f : cl.getFields()) {
     if (((f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
         && ((f.getModifiers() & java.lang.reflect.Modifier.PUBLIC) != 0)
         && (f.getType() == Integer.TYPE)) {
       int v;
       try {
         v = f.getInt(null);
       } catch (IllegalAccessException e) {
         continue;
       }
       if (v == val) {
         if (ret == null) ret = f.getName();
         else ret = ret + " or " + f.getName();
       }
     }
   }
   if (ret == null) return (Integer.toString(val));
   return (ret);
 }
예제 #8
0
  // constructor
  //
  public CutPanelView(int viewEnum, String viewName, Object parentObject) {
    super(parentObject);
    this.viewEnum = viewEnum;
    this.viewName = viewName;
    cim = new ChangeableInfoMgr();
    filterConstraintsMgr = new FilterConstraintsManager(this);
    SemaphoreFilter sfilter = new SemaphoreFilter(this);
    fdm = sfilter;

    // define the custom cursors
    Toolkit tk = this.getToolkit();

    // arrow
    // Image cursImage =
    // Toolkit.getDefaultToolkit().createImage(getClass().getResource(arrowcursorgif));
    // Point hotSpot = new Point(13, 10);
    // arrow = tk.createCustomCursor(cursImage, hotSpot, "ARROW_CURSOR");

    try {
      if (!Constants.ISMAC) {
        // open cross
        Image cursImage =
            Toolkit.getDefaultToolkit()
                .createImage(Class.forName("ndEdit.NdEdit").getResource(crosscursorgif));

        Point hotSpot = new Point(15, 15);
        cross = tk.createCustomCursor(cursImage, hotSpot, "CROSS_CURSOR");

        // section
        Image cursImage2 =
            Toolkit.getDefaultToolkit()
                .createImage(Class.forName("ndEdit.NdEdit").getResource(sectioncursorgif));
        hotSpot = new Point(15, 15);
        section = tk.createCustomCursor(cursImage2, hotSpot, "SECTION_CURSOR");

        // zoom in
        Image cursImage3 =
            Toolkit.getDefaultToolkit()
                .createImage(Class.forName("ndEdit.NdEdit").getResource(zoomincursorgif));
        hotSpot = new Point(14, 14);
        zoomIn = tk.createCustomCursor(cursImage3, hotSpot, "ZOOMIN_CURSOR");

        // zoom out
        Image cursImage4 =
            Toolkit.getDefaultToolkit()
                .createImage(Class.forName("ndEdit.NdEdit").getResource(zoomoutcursorgif));
        hotSpot = new Point(14, 14);
        zoomOut = tk.createCustomCursor(cursImage4, hotSpot, "ZOOMOUT_CURSOR");
      } else {
        // open cross
        Image cursImage =
            Toolkit.getDefaultToolkit()
                .createImage(Class.forName("ndEdit.NdEdit").getResource(crosscursorgifX));
        Point hotSpot = new Point(8, 8);
        cross = tk.createCustomCursor(cursImage, hotSpot, "CROSS_CURSOR");

        // section
        Image cursImage2 =
            Toolkit.getDefaultToolkit()
                .createImage(Class.forName("ndEdit.NdEdit").getResource(sectioncursorgifX));
        hotSpot = new Point(4, 8);
        section = tk.createCustomCursor(cursImage2, hotSpot, "SECTION_CURSOR");

        // zoom in
        Image cursImage3 =
            Toolkit.getDefaultToolkit()
                .createImage(Class.forName("ndEdit.NdEdit").getResource(zoomincursorgifX));
        hotSpot = new Point(6, 6);
        zoomIn = tk.createCustomCursor(cursImage3, hotSpot, "ZOOMIN_CURSOR");

        // zoom out
        Image cursImage4 =
            Toolkit.getDefaultToolkit()
                .createImage(Class.forName("ndEdit.NdEdit").getResource(zoomoutcursorgifX));
        hotSpot = new Point(6, 6);
        zoomOut = tk.createCustomCursor(cursImage4, hotSpot, "ZOOMOUT_CURSOR");
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.out.println("CutPanelView:ctor");
    }
  }
예제 #9
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);
  }