List of usage examples for com.badlogic.gdx.math Rectangle setWidth
public Rectangle setWidth(float width)
From source file:com.laex.cg2d.screeneditor.ScreenEditor.java
License:Open Source License
/** * Sets the up entity resource listener. * * @param input the new up entity resource listener * @throws CoreException the core exception *//*from w ww . jav a 2 s .c o m*/ private void setupEntityResourceListener(final IEditorInput input) throws CoreException { ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceListener, IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE); // if there are any changes in the entities, load em up in the editor resourceListener.addEntityChangeListener(new EntityChangeListener() { @Override public void entityChanged(final IResource resource) { /* * It is important to execute pallete creation safely because it * accesses GEF UI thread */ SafeRunnable.run(new ISafeRunnable() { @Override public void run() throws Exception { // Check if the resource is valid entity or not. String entityPath = resource.getFullPath().toOSString(); Entity e = EntityManager.entityManager().findEntity(entityPath); boolean isValid = ModelValidatorFactory.getValidator(Entity.class, e).isValid(); if (!isValid) { removeDeletedOrInvalidEntities(resource); return; } /* * Recompute the frame for entities that might have changed * Essentially, were re-creating a new shape by copying the old one. * Following are the considerations for this: 1. The id for the new * shape should be same as the old one 2. The rectagle bounds for * the new shape should reflect the new image */ CompoundCommand cc = new CompoundCommand(); for (Shape sh : model.getDiagram().getChildren()) { if (!sh.getEditorShapeType().isEntity()) { continue; } boolean isEntityUsed = entityPath.equals(sh.getEntityResourceFile().getResourceFile()); if (isEntityUsed) { ShapeCopier copier = new ShapeCopier(); Shape newShape = (Shape) copier.copy(sh); newShape.setId(sh.getId()); /* We use the same id */ /* update bounds */ Rectangle r = newShape.getBounds(); r.setWidth(e.getDefaultFrame().getBounds().width); r.setHeight(e.getDefaultFrame().getBounds().height); newShape.setBounds(r); /* end update bounds */ ShapeDeleteCommand sdc = new ShapeDeleteCommand(model.getDiagram(), sh, DeleteCommandType.NON_UNDOABLE); ShapeCreateCommand scc = new ShapeCreateCommand(newShape, model.getDiagram()); cc.add(sdc); cc.add(scc); } } getCommandStack().execute(cc); } @Override public void handleException(Throwable exception) { exception.printStackTrace(); } }); } @Override public void entityRemoved(final IResource resource) { /* * Important: entity Removed is called in resource listener. Resource * listener might be run in whatever thread it was triggered in. So in * order to remove the entities from the pallette, we need to asyncExec * deletion. This will prevent invalid thread access error. */ getSite().getShell().getDisplay().asyncExec(new Runnable() { @Override public void run() { removeDeletedOrInvalidEntities(resource); /* Also remove this entity from the map */ EntityManager.entityManager().removeEntity(resource.getFullPath().toOSString()); } }); } }); }
From source file:de.cubicvoxel.openspacebox.ingame.object.Station.java
License:Open Source License
private static Rectangle createShape(StationType stationType) { Rectangle rectangle = new Rectangle(); rectangle.setWidth((float) stationType.getSize().getWidth()); rectangle.setHeight((float) stationType.getSize().getHeight()); return rectangle; }