public Flexible copyToGroup(String group) { String newName; if (group.equals(nullString)) newName = Group.substractObjectName(getName()); else newName = group + Constants.GROUP_SEPARATOR + Group.substractObjectName(getName()); // object with new name already exists, add suffix ///!!! while (Group.getRoot().findObject(newName, true) != null) newName = StringUtils.incrementName(newName, Constants.COPY_SUFFIX); Box grBox = new Box( newName, null, startVertex.getX(), startVertex.getY(), endVertex.getX(), endVertex.getY()); grBox.setColor(getColor()); Group.getRoot().addSubObject(newName, grBox, true); // ViewState view = ViewState.getInstance(); // grBox.move(20 - view.getRx(), 20 - view.getRy()); unconditionalValidation(); return grBox; }
// // Build scene // public Group buildScene() { // Get the current color Color3f color = (Color3f) colors[currentColor].value; float front = ((Float) fronts[currentFront].value).floatValue(); float back = ((Float) backs[currentBack].value).floatValue(); // Turn off the example headlight setHeadlightEnable(false); // Default to walk navigation setNavigationType(Walk); // Create the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere worldBounds = new BoundingSphere( new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the fog color, front & back distances, and // its influencing bounds fog = new LinearFog(); fog.setColor(color); fog.setFrontDistance(front); fog.setBackDistance(back); fog.setCapability(Fog.ALLOW_COLOR_WRITE); fog.setCapability(LinearFog.ALLOW_DISTANCE_WRITE); fog.setInfluencingBounds(worldBounds); scene.addChild(fog); // END EXAMPLE TOPIC // Set the background color and its application bounds // Usually, the background color should match the fog color // or the results look odd. background = new Background(); background.setColor(color); background.setApplicationBounds(worldBounds); background.setCapability(Background.ALLOW_COLOR_WRITE); scene.addChild(background); // Build foreground geometry scene.addChild(new ColumnScene(this)); return scene; }
public boolean rename(String newName) { String newObjName = Group.substractObjectName(newName); String oldObjName = Group.substractObjectName(getName()); if (!oldObjName.equals(newObjName)) { getParent().removeObject(oldObjName); String fullName = StringUtils.replaceEnding(getName(), oldObjName, newObjName); name = fullName; getParent().addSubObject(newObjName, this); } // move if needed moveToGroup(Group.substractParentName(newName)); return true; }
public void destroy() { super.destroy(); if (getParent() != null) getParent().removeObject(Group.substractObjectName(name)); if (!startVertex.isDestroyed()) startVertex.destroy(); if (!endVertex.isDestroyed()) endVertex.destroy(); }
public boolean moveToGroup(String group) { String currentParent = Group.substractParentName(getName()); if (group.equals(currentParent)) return false; // String oldName = getName(); String newName; if (group.equals(nullString)) newName = Group.substractObjectName(getName()); else newName = group + Constants.GROUP_SEPARATOR + Group.substractObjectName(getName()); // object with new name already exists, add suffix // !!! Object obj; boolean renameNeeded = false; while ((obj = Group.getRoot().findObject(newName, true)) != null) { if (obj == this) // it's me :) already moved, fix data { name = newName; return true; } else { renameNeeded = true; newName = StringUtils.incrementName(newName, Constants.MOVE_SUFFIX); } } if (renameNeeded) return rename(newName); getParent().removeObject(Group.substractObjectName(getName())); setParent(null); Group.getRoot().addSubObject(newName, this, true); name = newName; unconditionalValidation(); return true; }
private Group[] conflicting(int ish, Color[] groupToColor) { ArrayList<Group> touchers = new ArrayList<Group>(); Group g = groups[ish]; Space[] gSpaces = g.getSpaces(); for (int i = 0; i < gSpaces.length; i++) { Space current = gSpaces[i]; for (int k = -1; k < 2; k++) { int curSX = current.getX(); int curSY = current.getY(); curSX += k; curSY += k; if (curSX < 0) { curSX = 0; } if (curSX > spaces.length - 1) { curSX = spaces.length - 1; } if (curSY < 0) { curSY = 0; } if (curSY > spaces.length - 1) { curSY = spaces.length - 1; } Space[] comparison = new Space[2]; comparison[0] = game.getSpaceAt(curSX, current.getY()); comparison[1] = game.getSpaceAt(current.getX(), curSY); int mod = groupToColor.length; for (int j = 0; j < comparison.length; j++) { if ((comparison[j].getGroup().groupIDX != g.groupIDX) && groupToColor[comparison[j].getGroup().groupIDX % mod] == groupToColor[current.getGroup().groupIDX % mod] && !touchers.contains(comparison[j].getGroup())) { touchers.add(comparison[j].getGroup()); } } } } return touchers.toArray(new Group[touchers.size()]); }
public Box(String parName, Group parentGroup, int posX, int posY, int posX2, int posY2) { super(parentGroup); startVertex = new Vertex(this, posX, posY); endVertex = new Vertex(this, posX2, posY2); revalidatePosition(); // for move rectangle setWidth(Constants.CONNECTOR_WIDTH); setHeight(Constants.CONNECTOR_HEIGHT); setColor(currentColor); dashed = currentIsDashed; if (parName == null) { hashId = getAvailableHashId(); if (parentGroup.getAbsoluteName().length() > 0) name = parentGroup.getAbsoluteName() + Constants.GROUP_SEPARATOR + hashId; else name = hashId; } else name = parName; }
public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equals("Add User")) { jta.append("\n" + userId.getText()); User user = new User(userId.getText()); } else if (ae.getActionCommand().equals("Add Group")) { jta.append("\n" + groupId.getText()); Group group = new Group(groupId.getText()); } else if (ae.getActionCommand().equals("Open User View")) { try { if (!jta.getSelectedText().equals("null")) { userView.setVisible(true); } } catch (Exception e) { JOptionPane.showMessageDialog( frame, "Nothing selected", "Error", JOptionPane.ERROR_MESSAGE); } } else if (ae.getActionCommand().equals("Show User Total")) { JOptionPane.showMessageDialog(frame, User.getUserTotal()); } else if (ae.getActionCommand().equals("Show Group Total")) { JOptionPane.showMessageDialog(frame, Group.getGroupTotal()); } else if (ae.getActionCommand().equals("Show Messages Total")) { JOptionPane.showMessageDialog(frame, User.getMessageTotal()); } else if (ae.getActionCommand().equals("Show Positive Percentage")) { String[] newsFeed = User.getNewsFeed(); int positive = 0; int i = 0; while (!(newsFeed[i] == null)) { if (newsFeed[i].contains("good") || newsFeed[i].contains("great") || newsFeed[i].contains("excellent")) positive++; i++; } JOptionPane.showMessageDialog(frame, positive * 100.0 / i + "%"); } else if (ae.getActionCommand().equals("Follow User")) { following.append("\n" + userId2.getText()); } else if (ae.getActionCommand().equals("Post Tweet")) { User.postTweet(tweet.getText()); newsFeed.append("\n" + jta.getSelectedText() + ": " + tweet.getText()); } }
/** Updates all UI controls */ private void updatePreviewAndConflicts() { if (myButton == -1 || myModifiers == -1) { return; } myTarConflicts.setText(null); // Set text into preview area // empty string should have same height myLblPreview.setText( KeymapUtil.getMouseShortcutText(myButton, myModifiers, myRbSingleClick.isSelected() ? 1 : 2) + " "); // Detect conflicts final MouseShortcut mouseShortcut; if (myRbSingleClick.isSelected()) { mouseShortcut = new MouseShortcut(myButton, myModifiers, 1); } else { mouseShortcut = new MouseShortcut(myButton, myModifiers, 2); } StringBuilder buffer = new StringBuilder(); String[] actionIds = myKeymap.getActionIds(mouseShortcut); for (String actionId : actionIds) { if (actionId.equals(myActionId)) { continue; } String actionPath = myMainGroup.getActionQualifiedPath(actionId); // actionPath == null for editor actions having corresponding $-actions if (actionPath == null) { continue; } Shortcut[] shortcuts = myKeymap.getShortcuts(actionId); for (Shortcut shortcut1 : shortcuts) { if (!(shortcut1 instanceof MouseShortcut)) { continue; } MouseShortcut shortcut = (MouseShortcut) shortcut1; if (shortcut.getButton() != mouseShortcut.getButton() || shortcut.getModifiers() != mouseShortcut.getModifiers()) { continue; } if (buffer.length() > 1) { buffer.append('\n'); } buffer.append('['); buffer.append(actionPath); buffer.append(']'); break; } } if (buffer.length() == 0) { myTarConflicts.setForeground(UIUtil.getTextAreaForeground()); myTarConflicts.setText(KeyMapBundle.message("mouse.shortcut.dialog.no.conflicts.area")); } else { myTarConflicts.setForeground(Color.red); myTarConflicts.setText( KeyMapBundle.message("mouse.shortcut.dialog.assigned.to.area", buffer.toString())); } }
/** Setup the basic scene which consists of a quad and a viewpoint */ private void setupSceneGraph() { // View group Viewpoint vp = new Viewpoint(); Vector3f trans = new Vector3f(0, 0, 1); Matrix4f mat = new Matrix4f(); mat.setIdentity(); mat.setTranslation(trans); TransformGroup tx = new TransformGroup(); tx.addChild(vp); tx.setTransform(mat); Group scene_root = new Group(); scene_root.addChild(tx); // Flat panel that has the viewable object as the demo float[] coord = {0, 0, -1, 0.25f, 0, -1, 0, 0.25f, -1}; float[] normal = {0, 0, 1, 0, 0, 1, 0, 0, 1}; TriangleArray geom = new TriangleArray(); geom.setValidVertexCount(3); geom.setVertices(TriangleArray.COORDINATE_3, coord); geom.setNormals(normal); Material material = new Material(); material.setDiffuseColor(new float[] {0, 0, 1}); material.setEmissiveColor(new float[] {0, 0, 1}); material.setSpecularColor(new float[] {1, 1, 1}); material.setTransparency(0.5f); Appearance app = new Appearance(); app.setMaterial(material); Shape3D shape = new Shape3D(); shape.setGeometry(geom); shape.setAppearance(app); TransformGroup tg = new TransformGroup(); Matrix4f transform = new Matrix4f(); transform.setIdentity(); transform.setTranslation(new Vector3f(0.15f, 0, -1)); tg.setTransform(transform); Shape3D backShape = new Shape3D(); Material material2 = new Material(); material2.setDiffuseColor(new float[] {1, 0, 0}); material2.setEmissiveColor(new float[] {1, 0, 0}); material2.setSpecularColor(new float[] {1, 1, 1}); Appearance app2 = new Appearance(); app2.setMaterial(material2); backShape.setGeometry(geom); backShape.setAppearance(app2); tg.addChild(backShape); scene_root.addChild(tg); scene_root.addChild(shape); SimpleScene scene = new SimpleScene(); scene.setRenderedGeometry(scene_root); scene.setActiveView(vp); // Then the basic layer and viewport at the top: SimpleViewport view = new SimpleViewport(); view.setDimensions(0, 0, 500, 500); view.setScene(scene); SimpleLayer layer = new SimpleLayer(); layer.setViewport(view); Layer[] layers = {layer}; displayManager.setLayers(layers, 1); }
// // Build scene // public Group buildScene() { // Turn off the example headlight setHeadlightEnable(false); // Build the scene group Group scene = new Group(); // Build foreground geometry into two groups. We'll // create three directional lights below, one each with // scope to cover the first geometry group only, the // second geometry group only, or both geometry groups. content1 = new SphereGroup( 0.25f, // radius of spheres 1.5f, // x spacing 0.75f, // y spacing 3, // number of spheres in X 5, // number of spheres in Y null); // appearance scene.addChild(content1); content2 = new SphereGroup( 0.25f, // radius of spheres 1.5f, // x spacing 0.75f, // y spacing 2, // number of spheres in X 5, // number of spheres in Y null); // appearance scene.addChild(content2); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere worldBounds = new BoundingSphere( new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Add three directional lights whose scopes are set // to cover one, the other, or both of the shape groups // above. Also set the lights' color and aim direction. // Light #1 with content1 scope light1 = new DirectionalLight(); light1.setEnable(light1OnOff); light1.setColor(Red); light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light1.setInfluencingBounds(worldBounds); light1.addScope(content1); light1.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(light1); // Light #2 with content2 scope light2 = new DirectionalLight(); light2.setEnable(light2OnOff); light2.setColor(Blue); light2.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light2.setInfluencingBounds(worldBounds); light2.addScope(content2); light2.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(light2); // Light #3 with universal scope (the default) light3 = new DirectionalLight(); light3.setEnable(light3OnOff); light3.setColor(White); light3.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light3.setInfluencingBounds(worldBounds); light3.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(light3); // Add an ambient light to dimly illuminate the rest of // the shapes in the scene to help illustrate that the // directional lights are being scoped... otherwise it looks // like we're just removing shapes from the scene AmbientLight ambient = new AmbientLight(); ambient.setEnable(true); ambient.setColor(White); ambient.setInfluencingBounds(worldBounds); scene.addChild(ambient); // END EXAMPLE TOPIC return scene; }