private EntityData.Entity serializeEntityDelta(EntityRef entityRef, Prefab prefab) { EntityData.Entity.Builder entity = EntityData.Entity.newBuilder(); entity.setId(entityRef.getId()); entity.setParentPrefab(prefab.getName()); for (Component component : entityRef.iterateComponents()) { if (component.getClass().equals(EntityInfoComponent.class)) continue; Component prefabComponent = prefab.getComponent(component.getClass()); EntityData.Component componentData; if (prefabComponent == null) { componentData = serializeComponent(component); } else { componentData = serializeComponent(prefabComponent, component); } if (componentData != null) { entity.addComponent(componentData); } } for (Component prefabComponent : prefab.listComponents()) { if (!entityRef.hasComponent(prefabComponent.getClass())) { entity.addRemovedComponent(ComponentUtil.getComponentClassName(prefabComponent.getClass())); } } return entity.build(); }
@SuppressWarnings({"HardCodedStringLiteral"}) private Element writePanel(final JPanel panel) { final Component comp = panel.getComponent(0); if (comp instanceof Splitter) { final Splitter splitter = (Splitter) comp; final Element res = new Element("splitter"); res.setAttribute("split-orientation", splitter.getOrientation() ? "vertical" : "horizontal"); res.setAttribute("split-proportion", Float.toString(splitter.getProportion())); final Element first = new Element("split-first"); first.addContent(writePanel((JPanel) splitter.getFirstComponent())); final Element second = new Element("split-second"); second.addContent(writePanel((JPanel) splitter.getSecondComponent())); res.addContent(first); res.addContent(second); return res; } else if (comp instanceof JBTabs) { final Element res = new Element("leaf"); final EditorWindow window = findWindowWith(comp); writeWindow(res, window); return res; } else if (comp instanceof EditorWindow.TCompForTablessMode) { final EditorWithProviderComposite composite = ((EditorWindow.TCompForTablessMode) comp).myEditor; final Element res = new Element("leaf"); writeComposite(res, composite.getFile(), composite, false, composite); return res; } else { LOG.error(comp != null ? comp.getClass().getName() : null); return null; } }
@Override public EntityRef deserializeEntity(EntityData.Entity entityData) { EntityRef entity = entityManager.createEntityRefWithId(entityData.getId()); if (entityData.hasParentPrefab() && !entityData.getParentPrefab().isEmpty() && prefabManager.exists(entityData.getParentPrefab())) { Prefab prefab = prefabManager.getPrefab(entityData.getParentPrefab()); for (Component component : prefab.listComponents()) { String componentName = ComponentUtil.getComponentClassName(component.getClass()); if (!containsIgnoreCase(componentName, entityData.getRemovedComponentList())) { entity.addComponent(componentLibrary.copy(component)); } } entity.addComponent(new EntityInfoComponent(entityData.getParentPrefab())); } for (EntityData.Component componentData : entityData.getComponentList()) { Class<? extends Component> componentClass = getComponentClass(componentData); if (componentClass == null) continue; if (!entity.hasComponent(componentClass)) { entity.addComponent(deserializeComponent(componentData)); } else { deserializeComponentOnto(entity.getComponent(componentClass), componentData); } } return entity; }
/** ErrorOccurred event handler. */ @SimpleEvent( description = "Event raised when an error occurs. Only some errors will " + "raise this condition. For those errors, the system will show a notification " + "by default. You can use this event handler to prescribe an error " + "behavior different than the default.") public void ErrorOccurred( Component component, String functionName, int errorNumber, String message) { String componentType = component.getClass().getName(); componentType = componentType.substring(componentType.lastIndexOf(".") + 1); Log.e( LOG_TAG, "Form " + formName + " ErrorOccurred, errorNumber = " + errorNumber + ", componentType = " + componentType + ", functionName = " + functionName + ", messages = " + message); if ((!(EventDispatcher.dispatchEvent( this, "ErrorOccurred", component, functionName, errorNumber, message))) && screenInitialized) { // If dispatchEvent returned false, then no user-supplied error handler was run. // If in addition, the screen initializer was run, then we assume that the // user did not provide an error handler. In this case, we run a default // error handler, namely, showing a notification to the end user of the app. // The app writer can override this by providing an error handler. new Notifier(this).ShowAlert("Error " + errorNumber + ": " + message); } }
@Override public Component getPreviousComponent() { // get the component before the start of the parallel circuit Component component = prevs.get(0).getConnectedComponent(this); while (component.getClass() != ParallelNodeStart.class) { component = component.getPreviousComponent(); } return component.getPreviousComponent(); }
/** * Add {@link Component}. Note that only one Component can be added per class. * * @param component Component * @return {@code true} if Successfully added. Otherwise {@code false}. */ public boolean add(Component component) { final Class<? extends Component> componentClass = component.getClass(); if (!components.containsKey(componentClass)) { component.setEntity(this); component.onAttach(this); components.put(componentClass, component); return true; } return false; }
/** * Returns all component by class. * * @param clazz the class to match * @return the list of matching components */ @SuppressWarnings("unchecked") public <X extends Component> List<X> get(Class<?> clazz) { List<X> temp = new ArrayList<X>(); for (Component c : map.values()) { if (c.getClass() == clazz) { temp.add((X) c); } } return temp; }
public static String getPortTypeOfComponentsPort( Component comp, Port port /*, String inport_outport*/) throws SecurityException, IllegalArgumentException { Class<?> c = comp.getClass(); // System.out.println("class: " + c.getName()); Field[] fields = c.getDeclaredFields(); ArrayList<Field> allFields = new ArrayList<>(); for (Field f : fields) allFields.add(f); // add fields from superclasses (required in the case of multi-level inheriting classes, e.g., // Merge8x1) Class<?> currSuperClass = c.getSuperclass(); while (currSuperClass != null) { Field[] superfields = currSuperClass.getDeclaredFields(); for (Field f : superfields) allFields.add(f); currSuperClass = currSuperClass.getSuperclass(); } for (Field f : allFields) // (Field f : fields) { if (f.getType().getSimpleName().equals("InPort") || f.getType() .getSimpleName() .equals("OutPort")) { // f.getType().getSimpleName().equals(inport_outport) // System.out.println(f.getName() + ": " + f.getType()); f.setAccessible(true); try { if (f.get(comp).equals(port)) { // System.out.println("generic type: " + f.getGenericType().getTypeName()); String portType = f.getGenericType() .getTypeName(); // ch.alari.sacre.OutPort<ch.alari.sacre.TextToken> // extract <...> int beg = portType.lastIndexOf('<'); String tokenType = "java.lang.Object"; if (beg != -1) // ch.alari.sacre.OutPort, may be defined as such. then // tokenType="java.lang.Object" tokenType = portType.substring(beg + 1, portType.lastIndexOf('>')); return tokenType; // PortType anno = f.getAnnotation(PortType.class); // if(anno!=null) // { // System.out.println("anno: " + anno.value()); // return anno.value(); // } // else // return null; } } catch (IllegalAccessException iae) { iae.printStackTrace(); } } } return null; }
/** * Faster adding of components into the entity. * * <p>Not necessary to use this, but in some cases you might need the extra performance. * * @param component the component to add * @param type the type of the component * @return this EntityEdit for chaining * @see #createComponent(Class) */ public EntityEdit add(Component component, ComponentType type) { if (type.getTaxonomy() != Taxonomy.BASIC) { throw new InvalidComponentException( component.getClass(), "Use Entity#createComponent for adding non-basic component types"); } world.getComponentManager().addComponent(entity, type, component); componentBits.set(type.getIndex()); return this; }
/** * Attempts to find a component. * * @param target the element or inner element of the component * @param clazz the class the component should have * @return the matching component or null if no match */ @SuppressWarnings("unchecked") public <X extends Component> X find(Element target, Class<X> clazz) { while (target != null) { Component c = map.get(target.getId()); if (c != null && (clazz == null || c.getClass().equals(clazz))) { return (X) c; } else { target = (Element) target.getParentElement(); } } return null; }
private EntityData.Component serializeComponent(Component base, Component delta) { ComponentMetadata<?> componentMetadata = componentLibrary.getMetadata(base.getClass()); if (componentMetadata == null) { logger.log(Level.SEVERE, "Unregistered component type: " + base.getClass()); return null; } EntityData.Component.Builder componentMessage = EntityData.Component.newBuilder(); if (useLookupTables) { componentMessage.setTypeIndex(componentIdTable.inverse().get(base.getClass())); } else { componentMessage.setType(ComponentUtil.getComponentClassName(delta)); } boolean changed = false; for (FieldMetadata field : componentMetadata.iterateFields()) { try { Object origValue = field.getValue(base); Object deltaValue = field.getValue(delta); if (!Objects.equal(origValue, deltaValue)) { EntityData.Value value = field.serialize(deltaValue); componentMessage.addField( EntityData.NameValue.newBuilder().setName(field.getName()).setValue(value).build()); changed = true; } } catch (IllegalAccessException e) { logger.log( Level.SEVERE, "Exception during serializing component type: " + base.getClass(), e); } catch (InvocationTargetException e) { logger.log( Level.SEVERE, "Exception during serializing component type: " + base.getClass(), e); } } if (changed) { return componentMessage.build(); } return null; }
private EntityData.Entity serializeEntityFull(EntityRef entityRef) { EntityData.Entity.Builder entity = EntityData.Entity.newBuilder(); entity.setId(entityRef.getId()); for (Component component : entityRef.iterateComponents()) { if (component.getClass().equals(EntityInfoComponent.class)) continue; EntityData.Component componentData = serializeComponent(component); if (componentData != null) { entity.addComponent(componentData); } } return entity.build(); }
@Override public EntityData.Component serializeComponent(Component component) { ComponentMetadata<?> componentMetadata = componentLibrary.getMetadata(component.getClass()); if (componentMetadata == null) { logger.log(Level.SEVERE, "Unregistered component type: " + component.getClass()); return null; } EntityData.Component.Builder componentMessage = EntityData.Component.newBuilder(); if (useLookupTables) { componentMessage.setTypeIndex(componentIdTable.inverse().get(component.getClass())); } else { componentMessage.setType(ComponentUtil.getComponentClassName(component)); } for (FieldMetadata field : componentMetadata.iterateFields()) { try { Object rawValue = field.getValue(component); if (rawValue == null) continue; EntityData.Value value = field.serialize(rawValue); if (value == null) continue; componentMessage.addField( EntityData.NameValue.newBuilder().setName(field.getName()).setValue(value).build()); } catch (IllegalAccessException e) { logger.log( Level.SEVERE, "Exception during serializing component type: " + component.getClass(), e); } catch (InvocationTargetException e) { logger.log( Level.SEVERE, "Exception during serializing component type: " + component.getClass(), e); } } return componentMessage.build(); }
private Component deserializeOnto( Component component, EntityData.Component componentData, ComponentMetadata componentMetadata) { try { for (EntityData.NameValue field : componentData.getFieldList()) { FieldMetadata fieldInfo = componentMetadata.getField(field.getName()); if (fieldInfo == null) continue; Object value = fieldInfo.deserialize(field.getValue()); if (value == null) continue; fieldInfo.setValue(component, value); } return component; } catch (InvocationTargetException e) { logger.log( Level.SEVERE, "Exception during serializing component type: " + component.getClass(), e); } catch (IllegalAccessException e) { logger.log( Level.SEVERE, "Exception during serializing component type: " + component.getClass(), e); } return null; }
/** * @param aContainer * @param aComponentClass * @return */ private static Component findComponent( final Container aContainer, final Class<? extends Component> aComponentClass) { Component result = null; final int cnt = aContainer.getComponentCount(); for (int i = 0; (result == null) && (i < cnt); i++) { final Component comp = aContainer.getComponent(i); if (aComponentClass.equals(comp.getClass())) { result = comp; } else if (comp instanceof Container) { result = findComponent((Container) comp, aComponentClass); } } return result; }
private static Method getBRBIMethod(Component component) { Class klass = component.getClass(); while (klass != null) { if (BRB_I_MAP.containsKey(klass)) { Method method = (Method) BRB_I_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 ("getBaselineResizeBehaviorInt".equals(method.getName())) { Class[] params = method.getParameterTypes(); if (params.length == 0) { BRB_I_MAP.put(klass, method); return method; } } } BRB_I_MAP.put(klass, null); return null; }
@SuppressWarnings("HardCodedStringLiteral") private Element writePanel(final JPanel panel) { final Component comp = panel.getComponent(0); if (comp instanceof Splitter) { final Splitter splitter = (Splitter) comp; final Element res = new Element("splitter"); res.setAttribute("split-orientation", splitter.getOrientation() ? "vertical" : "horizontal"); res.setAttribute("split-proportion", Float.toString(splitter.getProportion())); final Element first = new Element("split-first"); first.addContent(writePanel((JPanel) splitter.getFirstComponent())); final Element second = new Element("split-second"); second.addContent(writePanel((JPanel) splitter.getSecondComponent())); res.addContent(first); res.addContent(second); return res; } else if (comp instanceof JBTabs) { final Element res = new Element("leaf"); Integer limit = UIUtil.getClientProperty( ((JBTabs) comp).getComponent(), JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY); if (limit != null) { res.setAttribute(JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY.toString(), String.valueOf(limit)); } writeWindow(res, findWindowWith(comp)); return res; } else if (comp instanceof EditorWindow.TCompForTablessMode) { EditorWithProviderComposite composite = ((EditorWindow.TCompForTablessMode) comp).myEditor; Element res = new Element("leaf"); res.addContent(writeComposite(composite.getFile(), composite, false, composite)); return res; } else { LOG.error(comp != null ? comp.getClass().getName() : null); return null; } }
private static boolean isDiagramViewComponent(Component c) { return c != null && "y.view.Graph2DView".equals(c.getClass().getName()); }
/** * Removes the component from this entity. * * @param component the component to remove from this entity. * @return this EntityEdit for chaining */ public EntityEdit remove(Component component) { return remove(component.getClass()); }
/** * Remove {@link Component}. * * @param component Component. * @return {@code true} if Successfully removed. Otherwise {@code false}. */ public boolean remove(Component component) { return remove(component.getClass()); }
/** * Add a component to this entity. * * @param component the component to add to this entity * @return this EntityEdit for chaining * @see {@link #createComponent(Class)} */ public EntityEdit add(Component component) { ComponentTypeFactory tf = world.getComponentManager().typeFactory; return add(component, tf.getTypeFor(component.getClass())); }
/** * Add a component to this entity. * * @param component to add to this entity * @return this entity for chaining. */ public Entity addComponent(Component component) { addComponent(component, ComponentType.getTypeFor(component.getClass())); return this; }
/** * Removes the component from this entity. * * @param component to remove from this entity. * @return this entity for chaining. */ public Entity removeComponent(Component component) { removeComponent(component.getClass()); return this; }
void doTest() throws Exception { ArrayList<Component> components = new ArrayList(); components.add(button); components.add(buttonLW); components.add(textField); components.add(textArea); components.add(list); components.add(listLW); int keys[]; String OS = System.getProperty("os.name").toLowerCase(); System.out.println(OS); if (OS.contains("os x") || OS.contains("sunos")) { keys = new int[] {KeyEvent.VK_SHIFT, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_META}; } else { keys = new int[] {KeyEvent.VK_SHIFT, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT}; } for (Component c : components) { System.out.print(c.getClass().getName() + ": "); Point origin = c.getLocationOnScreen(); int xc = origin.x + c.getWidth() / 2; int yc = origin.y + c.getHeight() / 2; Point center = new Point(xc, yc); robot.delay(robotDelay); robot.glide(origin, center); robot.click(); robot.delay(robotDelay); for (int k = 0; k < keys.length; ++k) { keyPressReceived = false; keyCode = keys[k]; robot.type(keyCode); robot.delay(robotDelay); if (!keyPressReceived) { synchronized (lock) { try { lock.wait(waitDelay); } catch (InterruptedException e) { } } } assertTrue(keyPressReceived, "key press event was not received"); } System.out.println("passed"); } robot.waitForIdle(); frame.dispose(); }