Esempio n. 1
0
 private static void netxsurgery() throws Exception {
   /* Force off NetX codebase classloading. */
   Class<?> nxc;
   try {
     nxc = Class.forName("net.sourceforge.jnlp.runtime.JNLPClassLoader");
   } catch (ClassNotFoundException e1) {
     try {
       nxc = Class.forName("netx.jnlp.runtime.JNLPClassLoader");
     } catch (ClassNotFoundException e2) {
       throw (new Exception("No known NetX on classpath"));
     }
   }
   ClassLoader cl = MainFrame.class.getClassLoader();
   if (!nxc.isInstance(cl)) {
     throw (new Exception("Not running from a NetX classloader"));
   }
   Field cblf, lf;
   try {
     cblf = nxc.getDeclaredField("codeBaseLoader");
     lf = nxc.getDeclaredField("loaders");
   } catch (NoSuchFieldException e) {
     throw (new Exception("JNLPClassLoader does not conform to its known structure"));
   }
   cblf.setAccessible(true);
   lf.setAccessible(true);
   Set<Object> loaders = new HashSet<Object>();
   Stack<Object> open = new Stack<Object>();
   open.push(cl);
   while (!open.empty()) {
     Object cur = open.pop();
     if (loaders.contains(cur)) continue;
     loaders.add(cur);
     Object curl;
     try {
       curl = lf.get(cur);
     } catch (IllegalAccessException e) {
       throw (new Exception("Reflection accessibility not available even though set"));
     }
     for (int i = 0; i < Array.getLength(curl); i++) {
       Object other = Array.get(curl, i);
       if (nxc.isInstance(other)) open.push(other);
     }
   }
   for (Object cur : loaders) {
     try {
       cblf.set(cur, null);
     } catch (IllegalAccessException e) {
       throw (new Exception("Reflection accessibility not available even though set"));
     }
   }
 }
Esempio n. 2
0
  /**
   * Set the object to be edited.
   *
   * @param value The object to be edited.
   */
  public void setObject(Object value) {
    if (!(_type.isInstance(value))) {
      throw new IllegalArgumentException(value.getClass() + " is not of type " + _type);
    }
    _value = value;

    // Disable event generation.
    _squelchChangeEvents = true;

    // Iterate over each property, doing a lookup on the associated editor
    // and setting the editor's value to the value of the property.
    Iterator it = _prop2Editor.keySet().iterator();
    while (it.hasNext()) {
      PropertyDescriptor desc = (PropertyDescriptor) it.next();
      PropertyEditor editor = (PropertyEditor) _prop2Editor.get(desc);
      Method reader = desc.getReadMethod();
      if (reader != null) {
        try {
          Object val = reader.invoke(_value, null);
          editor.setValue(val);
        } catch (IllegalAccessException ex) {
          ex.printStackTrace();
        } catch (InvocationTargetException ex) {
          ex.getTargetException().printStackTrace();
        }
      }
    }

    // Enable event generation.
    _squelchChangeEvents = false;
  }
Esempio n. 3
0
  private void checkForEmptyAndDuplicatedNames(
      MyNode rootNode,
      String prefix,
      String title,
      Class<? extends NamedConfigurable> configurableClass,
      boolean recursively)
      throws ConfigurationException {
    final Set<String> names = new HashSet<String>();
    for (int i = 0; i < rootNode.getChildCount(); i++) {
      final MyNode node = (MyNode) rootNode.getChildAt(i);
      final NamedConfigurable scopeConfigurable = node.getConfigurable();

      if (configurableClass.isInstance(scopeConfigurable)) {
        final String name = scopeConfigurable.getDisplayName();
        if (name.trim().length() == 0) {
          selectNodeInTree(node);
          throw new ConfigurationException("Name should contain non-space characters");
        }
        if (names.contains(name)) {
          final NamedConfigurable selectedConfigurable = getSelectedConfigurable();
          if (selectedConfigurable == null
              || !Comparing.strEqual(selectedConfigurable.getDisplayName(), name)) {
            selectNodeInTree(node);
          }
          throw new ConfigurationException(
              CommonBundle.message("smth.already.exist.error.message", prefix, name), title);
        }
        names.add(name);
      }

      if (recursively) {
        checkForEmptyAndDuplicatedNames(node, prefix, title, configurableClass, true);
      }
    }
  }
Esempio n. 4
0
  @SuppressWarnings("unchecked")
  @Nullable
  public static <T> T getToolWindowElement(
      @NotNull Class<T> clazz,
      @NotNull Project project,
      @NotNull DataKey<T> key,
      @NotNull ProjectSystemId externalSystemId) {
    if (project.isDisposed() || !project.isOpen()) {
      return null;
    }
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    if (toolWindowManager == null) {
      return null;
    }
    final ToolWindow toolWindow = ensureToolWindowContentInitialized(project, externalSystemId);
    if (toolWindow == null) {
      return null;
    }

    final ContentManager contentManager = toolWindow.getContentManager();
    if (contentManager == null) {
      return null;
    }

    for (Content content : contentManager.getContents()) {
      final JComponent component = content.getComponent();
      if (component instanceof DataProvider) {
        final Object data = ((DataProvider) component).getData(key.getName());
        if (data != null && clazz.isInstance(data)) {
          return (T) data;
        }
      }
    }
    return null;
  }
 private static boolean shouldIgnoreAction(@NotNull AnAction action) {
   for (Class<?> actionType : IGNORED_CONSOLE_ACTION_TYPES) {
     if (actionType.isInstance(action)) {
       return true;
     }
   }
   return false;
 }
 public static <T> T assertInstanceOf(Object o, Class<T> aClass) {
   Assert.assertNotNull("Expected instance of: " + aClass.getName() + " actual: " + null, o);
   Assert.assertTrue(
       "Expected instance of: " + aClass.getName() + " actual: " + o.getClass().getName(),
       aClass.isInstance(o));
   @SuppressWarnings("unchecked")
   T t = (T) o;
   return t;
 }
Esempio n. 7
0
 /**
  * Removes the property of the given type.
  *
  * @return The property that was just removed.
  * @since 1.279
  */
 public <T extends JobProperty> T removeProperty(Class<T> clazz) throws IOException {
   for (JobProperty<? super JobT> p : properties) {
     if (clazz.isInstance(p)) {
       removeProperty(p);
       return clazz.cast(p);
     }
   }
   return null;
 }
 private Set<Object> doFilter(Set<Object> elements) {
   Set<Object> result = new LinkedHashSet<Object>();
   for (Object o : elements) {
     if (myElementClass.isInstance(o) && getFilter().isAccepted((T) o)) {
       result.add(o);
     }
   }
   return result;
 }
 public <T> T getUserData(final Class<T> userDataClass) {
   if (myUserData != null) {
     for (Object o : myUserData) {
       if (userDataClass.isInstance(o)) {
         //noinspection unchecked
         return (T) o;
       }
     }
   }
   return null;
 }
  public static Component findFirstComponentOfType(Component component, Class nowClass) {
    if (nowClass.isInstance(component)) return component;

    if (component instanceof Container) {
      Container container = (Container) component;
      for (int i = 0; i < container.getComponentCount(); i++) {
        Component firstComponent = findFirstComponentOfType(container.getComponent(i), nowClass);
        if (firstComponent != null) return firstComponent;
      }
    }
    return null;
  }
Esempio n. 11
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;
   }
 }
 @Nullable
 public InnerSearchableConfigurable findSubConfigurable(@NotNull final Class pageClass) {
   if (mySubPanelFactories == null) {
     buildConfigurables();
   }
   for (Map.Entry<ColorAndFontPanelFactory, InnerSearchableConfigurable> entry :
       mySubPanelFactories.entrySet()) {
     if (pageClass.isInstance(entry.getValue().createPanel().getSettingsPage())) {
       return entry.getValue();
     }
   }
   return null;
 }
Esempio n. 13
0
 private static boolean isWindows(LookAndFeel laf) {
   if (laf.getID() == "Windows") {
     return true;
   }
   if (!checkedForWindows) {
     try {
       WINDOWS_CLASS = Class.forName("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
     } catch (ClassNotFoundException e) {
     }
     checkedForWindows = true;
   }
   return (WINDOWS_CLASS != null && WINDOWS_CLASS.isInstance(laf));
 }
Esempio n. 14
0
  /**
   * Convenience method for searching above the given component in the component hierarchy and
   * returns the first object of the given type it finds, or <code>null</code> if no such parent was
   * found.
   *
   * <p>The reason this method exists is for tidyness of the calling code, as no longer a explicit
   * cast is needed.
   *
   * @param aType the type of the parent to find, cannot be <code>null</code>;
   * @param aComponent the component to search in the hierarchy, cannot be <code>null</code>.
   * @return the requested ancestor, or <code>null</code> if not found.
   * @see SwingUtilities#getAncestorOfClass(Class, Component)
   */
  @SuppressWarnings("unchecked")
  public static <T> T getAncestorOfClass(final Class<T> aType, final Component aComponent) {
    if ((aComponent == null) || (aType == null)) {
      return null;
    }

    Container parent = aComponent.getParent();
    while ((parent != null) && !(aType.isInstance(parent))) {
      parent = parent.getParent();
    }

    return (T) parent;
  }
Esempio n. 15
0
 @NotNull
 public static <T> List<T> collectSelectedObjectsOfType(JTree tree, Class<T> clazz) {
   final TreePath[] selections = tree.getSelectionPaths();
   if (selections != null) {
     final ArrayList<T> result = new ArrayList<T>();
     for (TreePath selection : selections) {
       final DefaultMutableTreeNode node =
           (DefaultMutableTreeNode) selection.getLastPathComponent();
       final Object userObject = node.getUserObject();
       if (clazz.isInstance(userObject)) {
         //noinspection unchecked
         result.add((T) userObject);
       }
     }
     return result;
   }
   return Collections.emptyList();
 }
Esempio n. 16
0
 private static boolean isXP() {
   if (!checkedForClassic) {
     try {
       CLASSIC_WINDOWS =
           Class.forName("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
     } catch (ClassNotFoundException e) {
     }
     checkedForClassic = true;
   }
   if (CLASSIC_WINDOWS != null && CLASSIC_WINDOWS.isInstance(UIManager.getLookAndFeel())) {
     return false;
   }
   Toolkit toolkit = Toolkit.getDefaultToolkit();
   Boolean themeActive = (Boolean) toolkit.getDesktopProperty("win.xpstyle.themeActive");
   if (themeActive == null) {
     themeActive = Boolean.FALSE;
   }
   return themeActive.booleanValue();
 }
Esempio n. 17
0
 public boolean canConvert(Class type) {
   return type.isInstance(Color.blue);
 }
Esempio n. 18
0
 /** Gets the specific property, or null if the propert is not configured for this job. */
 public <T extends JobProperty> T getProperty(Class<T> clazz) {
   for (JobProperty p : properties) {
     if (clazz.isInstance(p)) return clazz.cast(p);
   }
   return null;
 }