private boolean isSynthIcon(Icon icon) { if (_synthIconMap == null) { _synthIconMap = new HashMap<String, Boolean>(); } Class<?> aClass = icon.getClass(); java.util.List<String> classNamesToPut = new ArrayList<String>(); boolean isSynthIcon = false; while (aClass != null) { String name = aClass.getCanonicalName(); if (name != null) { Boolean value = _synthIconMap.get(name); if (value != null) { return value; } classNamesToPut.add(name); if (isSynthIconClassName(name)) { isSynthIcon = true; break; } } aClass = aClass.getSuperclass(); } for (String name : classNamesToPut) { _synthIconMap.put(name, isSynthIcon); } return isSynthIcon; }
/** * @return an instanciation of the given content-type class name, or null if class wasn't found */ public static ContentType getContentTypeFromClassName(String contentTypeClassName) { if (contentTypeClassName == null) contentTypeClassName = getAvailableContentTypes()[DEFAULT_CONTENT_TYPE_INDEX]; ContentType ct = null; try { Class clazz = Class.forName(contentTypeClassName); ct = (ContentType) clazz.newInstance(); } catch (ClassNotFoundException cnfex) { if (jpicedt.Log.DEBUG) cnfex.printStackTrace(); JPicEdt.getMDIManager() .showMessageDialog( "The pluggable content-type you asked for (class " + cnfex.getLocalizedMessage() + ") isn't currently installed, using default instead...", Localizer.currentLocalizer().get("msg.LoadingContentTypeClass"), JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { if (jpicedt.Log.DEBUG) ex.printStackTrace(); JPicEdt.getMDIManager() .showMessageDialog( ex.getLocalizedMessage(), Localizer.currentLocalizer().get("msg.LoadingContentTypeClass"), JOptionPane.ERROR_MESSAGE); } return ct; }
/** * Create the given ViewManager * * @param viewDescriptor Identifies the VM * @param properties Property string to pass * @return The new one */ public ViewManager createViewManager(ViewDescriptor viewDescriptor, String properties) { synchronized (viewManagers) { try { ViewManager viewManager = null; if (viewDescriptor == null) { viewDescriptor = new ViewDescriptor(); } if (viewDescriptor.getClassNames().size() > 0) { Class viewManagerClass = Misc.findClass((String) viewDescriptor.getClassNames().get(0)); Constructor ctor = Misc.findConstructor( viewManagerClass, new Class[] {IntegratedDataViewer.class, ViewDescriptor.class, String.class}); if (ctor == null) { throw new IllegalArgumentException( "cannot create ViewManager:" + viewManagerClass.getName()); } viewManager = (ViewManager) ctor.newInstance(new Object[] {getIdv(), viewDescriptor, properties}); } else { viewManager = new MapViewManager(getIdv(), viewDescriptor, properties); } addViewManager(viewManager); return viewManager; } catch (Throwable e) { logException("In getViewManager", e); return null; } } }
public static void createCanvas(String appClass) { AppSettings settings = new AppSettings(true); settings.setWidth(640); settings.setHeight(480); try { Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(appClass); app = clazz.newInstance(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } catch (InstantiationException ex) { ex.printStackTrace(); } catch (IllegalAccessException ex) { ex.printStackTrace(); } app.setPauseOnLostFocus(false); app.setSettings(settings); app.createCanvas(); app.startCanvas(); context = (JmeCanvasContext) app.getContext(); canvas = context.getCanvas(); canvas.setSize(settings.getWidth(), settings.getHeight()); }
public static void drawStringUnderlineCharAt( JComponent c, Graphics g, String text, int underlinedIndex, int x, int y) { Graphics2D g2D = (Graphics2D) g; Object savedRenderingHint = null; if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) { savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2D.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint()); } if (getJavaVersion() >= 1.6) { try { Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2"); Class classParams[] = { JComponent.class, Graphics.class, String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE }; Method m = swingUtilities2Class.getMethod("drawStringUnderlineCharAt", classParams); Object methodParams[] = { c, g, text, new Integer(underlinedIndex), new Integer(x), new Integer(y) }; m.invoke(null, methodParams); } catch (Exception ex) { BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y); } } else if (getJavaVersion() >= 1.4) { BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, underlinedIndex, x, y); } else { BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y); } if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) { g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint); } }
private static Method getBaselineMethod(JComponent component) { if (COMPONENT_BASELINE_METHOD != null) { return COMPONENT_BASELINE_METHOD; } Class klass = component.getClass(); while (klass != null) { if (BASELINE_MAP.containsKey(klass)) { Method method = (Method) BASELINE_MAP.get(klass); return method; } klass = klass.getSuperclass(); } klass = component.getClass(); Method[] methods = klass.getMethods(); for (int i = methods.length - 1; i >= 0; i--) { Method method = methods[i]; if ("getBaseline".equals(method.getName())) { Class[] params = method.getParameterTypes(); if (params.length == 2 && params[0] == int.class && params[1] == int.class) { BASELINE_MAP.put(klass, method); return method; } } } BASELINE_MAP.put(klass, null); return null; }
/** 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; }
public void testIdeadev14081() throws Exception { // NOTE: That doesn't really reproduce the bug as it's dependent on a particular instrumentation // sequence used during form preview // (the nested form is instrumented with a new AsmCodeGenerator instance directly in the middle // of instrumentation of the current form) final String testDataPath = PluginPathManager.getPluginHomePath("ui-designer") + File.separatorChar + "testData" + File.separatorChar + File.separatorChar + "formEmbedding" + File.separatorChar + "Ideadev14081" + File.separatorChar; AsmCodeGenerator embeddedClassGenerator = initCodeGenerator("Embedded.form", "Embedded", testDataPath); byte[] embeddedPatchedData = getVerifiedPatchedData(embeddedClassGenerator); myClassFinder.addClassDefinition("Embedded", embeddedPatchedData); myNestedFormLoader.registerNestedForm("Embedded.form", testDataPath + "Embedded.form"); AsmCodeGenerator mainClassGenerator = initCodeGenerator("Main.form", "Main", testDataPath); byte[] mainPatchedData = getVerifiedPatchedData(mainClassGenerator); /* FileOutputStream fos = new FileOutputStream("C:\\yole\\FormPreview27447\\MainPatched.class"); fos.write(mainPatchedData); fos.close(); */ myClassFinder.addClassDefinition("Main", mainPatchedData); final Class mainClass = myClassFinder.getLoader().loadClass("Main"); Object instance = mainClass.newInstance(); assert instance != null : mainClass; }
@Override public void actionPerformed(AnActionEvent anActionEvent) { KevoreeEditorComponent.getInstance(null); if (KevoreeEditorComponent.keveditorCL != null) { try { final Class clazz = KevoreeEditorComponent.keveditorCL.loadClass("org.kevoree.tools.ui.editor.runner.App"); final Method meth = clazz.getMethod("main", String[].class); // TODO inject the selected file SwingUtilities.invokeLater( new Runnable() { @Override public void run() { String[] params = new String[0]; try { meth.invoke(null, (Object) params); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } } else { com.intellij.openapi.diagnostic.Logger.getInstance(this.getClass()) .error("Editor Jar not resolved"); } }
private XmlUIElement getXmlUIElementFor(String typeArg) { if (typeToClassMappingProp == null) { setUpMappingsHM(); } String clsName = (String) typeToClassMappingProp.get(typeArg); if ((clsName != null) && !(clsName.equals("*NOTFOUND*")) && !(clsName.equals("*EXCEPTION*"))) { try { Class cls = Class.forName(clsName); return (XmlUIElement) cls.newInstance(); } catch (Throwable th) { typeToClassMappingProp.put(typeArg, "*EXCEPTION*"); showErrorMessage( MessageFormat.format( ProvClientUtils.getString( "{0} occurred when trying to get the XmlUIElement for type : {1}"), new Object[] {th.getClass().getName(), typeArg})); th.printStackTrace(); return null; } } else if (clsName == null) { typeToClassMappingProp.put(typeArg, "*NOTFOUND*"); showErrorMessage( MessageFormat.format( ProvClientUtils.getString( "The type {0} does not have the corresponding XMLUIElement specified in the TypeToUIElementMapping.txt file"), new Object[] {typeArg})); } return null; }
public void testChainedConstructor() throws Exception { Class cls = loadAndPatchClass("TestChainedConstructor.form", "ChainedConstructorTest"); Field scrollPaneField = cls.getField("myScrollPane"); Object instance = cls.newInstance(); JScrollPane scrollPane = (JScrollPane) scrollPaneField.get(instance); assertNotNull(scrollPane.getViewport().getView()); }
public void startNGameCycles(Runnable finalAction, int nrOfRuns) { Class currWhitePlayer = whitePlayer.getClass(); Class currBlackPlayer = blackPlayer.getClass(); new Thread( () -> { for (int i = 0; i < nrOfRuns; i++) { progressOfNGames = OptionalDouble.of((double) i / nrOfRuns); GipfBoardState gipfBoardStateCopy = new GipfBoardState( getGipfBoardState(), gipfBoardState.getPieceMap(), gipfBoardState.players); Game copyOfGame = new BasicGame(); try { copyOfGame.whitePlayer = (ComputerPlayer) currWhitePlayer.newInstance(); copyOfGame.blackPlayer = (ComputerPlayer) currBlackPlayer.newInstance(); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } copyOfGame.loadState(gipfBoardStateCopy); GameLoopThread gameLoopThread = new GameLoopThread(copyOfGame, finalAction); gameLoopThread.start(); try { gameLoopThread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } progressOfNGames = OptionalDouble.empty(); }) .start(); }
/** * Get the appropriate editor for the given property. * * @param prop Property to get editor for. * @return Editor to use, or null if none found. */ private PropertyEditor getEditorForProperty(PropertyDescriptor prop) { PropertyEditor retval = null; Class type = prop.getPropertyEditorClass(); if (type != null) { try { retval = (PropertyEditor) type.newInstance(); } catch (Exception ex) { ex.printStackTrace(); } } // Handle case where there is no special editor // associated with the property. In that case we ask the // PropertyEditor manager for the editor registered for the // given property type. if (retval == null) { Class t = prop.getPropertyType(); if (t != null) { retval = PropertyEditorManager.findEditor(t); } } // In the worse case we resort to the generic editor for Object types. if (retval == null) { retval = PropertyEditorManager.findEditor(Object.class); } return retval; }
public static FontMetrics getFontMetrics(JComponent c, Graphics g, Font f) { FontMetrics fm = null; if (getJavaVersion() >= 1.6) { try { Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2"); Class classParams[] = {JComponent.class, Graphics.class, Font.class}; Method m = swingUtilities2Class.getMethod("getFontMetrics", classParams); Object methodParams[] = {c, g, f}; fm = (FontMetrics) m.invoke(null, methodParams); } catch (Exception ex) { // Nothing to do } } if (fm == null) { if (g == null) { if (c != null) { g = c.getGraphics(); } } if (g != null) { if (f != null) { fm = g.getFontMetrics(f); } else { fm = g.getFontMetrics(); } } else if (c != null) { if (f != null) { fm = c.getFontMetrics(f); } else { fm = c.getFontMetrics(c.getFont()); } } } return fm; }
/** * Load a class specified by a file- or entry-name * * @param name name of a file or entry * @return class file that was denoted by the name, null if no class or does not contain a main * method */ private Class load(String name) { if (name.endsWith(".class") && name.indexOf("Test") >= 0 && name.indexOf('$') < 0) { String classname = name.substring(0, name.length() - ".class".length()); if (classname.startsWith("/")) { classname = classname.substring(1); } classname = classname.replace('/', '.'); try { final Class<?> cls = Class.forName(classname); cls.getMethod("main", new Class[] {String[].class}); if (!getClass().equals(cls)) { return cls; } } catch (NoClassDefFoundError e) { // class has unresolved dependencies return null; } catch (ClassNotFoundException e) { // class not in classpath return null; } catch (NoSuchMethodException e) { // class does not have a main method return null; } catch (UnsupportedClassVersionError e) { // unsupported version return null; } } return null; }
/** @since 3.0.5 */ public static void showDBResults(StartupParameters params) { // System.err.println("not implemented full yet"); // We want to do this, but because we don't know if structure-gui.jar is in the classpath we use // reflection to hide the calls UserConfiguration config = UserConfiguration.fromStartupParams(params); String tableClass = "org.biojava.nbio.structure.align.gui.DBResultTable"; try { Class<?> c = Class.forName(tableClass); Object table = c.newInstance(); Method show = c.getMethod("show", new Class[] {File.class, UserConfiguration.class}); show.invoke(table, new File(params.getShowDBresult()), config); } catch (Exception e) { e.printStackTrace(); System.err.println( "Probably structure-gui.jar is not in the classpath, can't show results..."); } // DBResultTable table = new DBResultTable(); // table.show(new File(params.getShowDBresult()),config); }
/** * Creates a new entity enumeration icon chooser. * * @param enumeration the enumeration to display in this combo box */ public EnumerationIconChooser(Class<E> enumeration) { super(); this.enumeration = enumeration; try { this.icons = (ImageIcon[]) enumeration.getMethod("getIcons").invoke(null); for (int i = 0; i < icons.length; i++) { addItem(icons[i]); } } catch (NoSuchMethodException ex) { System.err.println( "The method 'getIcons()' is missing in enumeration " + enumeration.getName()); ex.printStackTrace(); System.exit(1); } catch (IllegalAccessException ex) { System.err.println( "Cannot access method 'getIcons()' in enumeration " + enumeration.getName() + ": ex.getMessage()"); ex.printStackTrace(); System.exit(1); } catch (InvocationTargetException ex) { ex.getCause().printStackTrace(); System.exit(1); } }
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); }
public void testMethodCallInSuper() throws Exception { // todo[yole] make this test work in headless if (!GraphicsEnvironment.isHeadless()) { Class cls = loadAndPatchClass("TestMethodCallInSuper.form", "MethodCallInSuperTest"); JDialog instance = (JDialog) cls.newInstance(); assertEquals(1, instance.getContentPane().getComponentCount()); } }
private boolean isValidType(final Class<?>[] validTypes, final Object type) { for (final Class<?> t : validTypes) { if (t.isInstance(type)) { return true; } } return false; }
private static boolean shouldIgnoreAction(@NotNull AnAction action) { for (Class<?> actionType : IGNORED_CONSOLE_ACTION_TYPES) { if (actionType.isInstance(action)) { return true; } } return false; }
private JComponent getInstrumentedRootComponent(final String formFileName, final String className) throws Exception { Class cls = loadAndPatchClass(formFileName, className); Field rootComponentField = cls.getField("myRootComponent"); rootComponentField.setAccessible(true); Object instance = cls.newInstance(); return (JComponent) rootComponentField.get(instance); }
/** * A utility function that layers on top of the LookAndFeel's isSupportedLookAndFeel() method. * Returns true if the LookAndFeel is supported. Returns false if the LookAndFeel is not supported * and/or if there is any kind of error checking if the LookAndFeel is supported. * * <p>The L&F menu will use this method to detemine whether the various L&F options should be * active or inactive. */ protected boolean isAvailableLookAndFeel(String laf) { try { Class lnfClass = Class.forName(laf); LookAndFeel newLAF = (LookAndFeel) (lnfClass.newInstance()); return newLAF.isSupportedLookAndFeel(); } catch (Exception e) { // If ANYTHING weird happens, return false return false; } }
protected static Object newInstance(String name) { try { Class clazz = Class.forName(name); return clazz.newInstance(); } catch (Exception e) { Logger().severe("Cannot extatiate class " + name + ": " + e.getMessage()); return null; } }
private Action tryEmptyConstructor(final Class aClass) throws Exception { for (final Constructor constructor : aClass.getConstructors()) { final Class[] types = constructor.getParameterTypes(); if (types == null || types.length == 0) { return (Action) aClass.newInstance(); } } return null; }
@SuppressWarnings({"rawtypes", "unchecked"}) public static void showAlignmentGUI() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { // proxy for AlignmentGui.getInstance(); Class c = Class.forName(alignmentGUI); Method m = c.getMethod("getInstance", (Class[]) null); m.invoke(c, (Object[]) null); }
public static Object loadFrame( JopSession session, String className, String instance, boolean scrollbar) throws ClassNotFoundException { if (className.indexOf(".pwg") != -1) { GrowFrame frame = new GrowFrame( className, session.getGdh(), instance, new GrowFrameCb(session), session.getRoot()); frame.validate(); frame.setVisible(true); } else { Object frame; if (instance == null) instance = ""; JopLog.log( "JopSpider.loadFrame: Loading frame \"" + className + "\" instance \"" + instance + "\""); try { Class clazz = Class.forName(className); try { Class argTypeList[] = new Class[] {session.getClass(), instance.getClass(), boolean.class}; Object argList[] = new Object[] {session, instance, new Boolean(scrollbar)}; System.out.println("JopSpider.loadFrame getConstructor"); Constructor constructor = clazz.getConstructor(argTypeList); try { frame = constructor.newInstance(argList); } catch (Exception e) { System.out.println( "Class instanciation error: " + className + " " + e.getMessage() + " " + constructor); return null; } // frame = clazz.newInstance(); JopLog.log("JopSpider.loadFrame openFrame"); openFrame(frame); return frame; } catch (NoSuchMethodException e) { System.out.println("NoSuchMethodException: Unable to get frame constructor " + className); } catch (Exception e) { System.out.println( "Exception: Unable to get frame class " + className + " " + e.getMessage()); } } catch (ClassNotFoundException e) { System.out.println("Class not found: " + className); throw new ClassNotFoundException(); } return null; } return null; }
public static Object getInstance(String clsName) { try { // 创建指定类对应的Class对象 Class cls = Class.forName(clsName); // 返回使用该Class对象所创建的实例 return cls.newInstance(); } catch (Exception e) { e.printStackTrace(); return null; } }
public ShapeGuiBase( int index, JsonObject jsonObject, Class<? extends IShape> shape, StructureTypeGui callback, HashMap<String, String> typeMap) { super(index, shape.getSimpleName(), jsonObject, typeMap); this.callback = callback; if (!data.has(BLOCKDATA_KEY)) data.add(BLOCKDATA_KEY, new JsonArray()); if (!data.has(Shapes.SHAPE_KEY)) data.addProperty(Shapes.SHAPE_KEY, shape.getSimpleName()); }
/** * Find the class for the projection * * @param proj projection * @return corresponding ProjectionClass (or null if not found) */ private ProjectionClass findProjectionClass(Projection proj) { Class want = proj.getClass(); ComboBoxModel projClassList = projClassCB.getModel(); for (int i = 0; i < projClassList.getSize(); i++) { ProjectionClass pc = (ProjectionClass) projClassList.getElementAt(i); if (want.equals(pc.projClass)) { return pc; } } return null; }