List of usage examples for java.awt Point move
public void move(int x, int y)
From source file:MainClass.java
public static void main(String[] args) { Point aPoint = new Point(); // Initialize to 0,0 Point bPoint = new Point(50, 25); Point cPoint = new Point(bPoint); System.out.println("aPoint is located at: " + aPoint); aPoint.move(100, 50); // Change to position 100,50 bPoint.x = 110;/*from w w w. ja v a2s. c o m*/ bPoint.y = 70; aPoint.translate(10, 20); // Move by 10 in x and 20 in y System.out.println("aPoint is now at: " + aPoint); if (aPoint.equals(bPoint)) System.out.println("aPoint and bPoint are at the same location."); }
From source file:Main.java
public static void main(String[] args) { Point aPoint = new Point(); Point bPoint = new Point(50, 25); Point cPoint = new Point(bPoint); System.out.println("cPoint is located at: " + cPoint); System.out.println("aPoint is located at: " + aPoint); aPoint.move(100, 50); bPoint.x = 110;// w w w. j av a 2 s . c o m bPoint.y = 70; aPoint.translate(10, 20); System.out.println("aPoint is now at: " + aPoint); if (aPoint.equals(bPoint)) System.out.println("aPoint and bPoint are at the same location."); }
From source file:com.redsqirl.workflow.server.Workflow.java
public String aggregateElements(List<String> componentIds, String subworkflowName, Map<String, Entry<String, String>> inputs, Map<String, Entry<String, String>> outputs) throws RemoteException { String error = null;//from w ww .j a v a 2s.c o m Workflow copy = null; // Replace elements by the subworkflow Point positionSuperAction = new Point(0, 0); try { copy = (Workflow) clone(); } catch (Exception e) { error = "Fail to clone the workflow"; logger.error(error, e); return error; } // Remove elements that are in the SuperAction logger.debug("Elements before aggregating: " + getComponentIds()); try { Iterator<String> itToDel = componentIds.iterator(); while (itToDel.hasNext()) { String id = itToDel.next(); positionSuperAction.move((int) positionSuperAction.getX() + getElement(id).getX(), (int) positionSuperAction.getY() + getElement(id).getY()); removeElement(id); } } catch (Exception e) { error = "Fail to remove an element"; logger.error(error, e); return error; } // Calculate the position of the new SuperAction positionSuperAction.move((int) positionSuperAction.getX() / componentIds.size(), (int) positionSuperAction.getY() / componentIds.size()); // Add the new element String idSA = null; try { idSA = addElement(subworkflowName); } catch (Exception e) { error = "Fail to create the super action " + subworkflowName; logger.error(error, e); return error; } // Add the new input links DataFlowElement newSA = getElement(idSA); newSA.setPosition((int) positionSuperAction.getX(), (int) positionSuperAction.getY()); logger.debug("Elements after aggregating: " + getComponentIds()); Iterator<String> entries = inputs.keySet().iterator(); while (entries.hasNext() && error == null) { String inputName = entries.next(); if (logger.isDebugEnabled()) { logger.debug("link " + inputs.get(inputName).getKey() + "," + inputs.get(inputName).getValue() + "->" + inputName + "," + idSA); } error = addLink(inputs.get(inputName).getValue(), inputs.get(inputName).getKey(), inputName, idSA); } // Add the new output links logger.debug("Old elements: " + copy.getComponentIds()); entries = outputs.keySet().iterator(); while (entries.hasNext() && error == null) { String outputName = entries.next(); logger.debug( "Get element " + outputs.get(outputName).getKey() + "," + outputs.get(outputName).getValue()); Map<String, List<DataFlowElement>> outEls = copy.getElement(outputs.get(outputName).getKey()) .getOutputComponent(); if (outEls != null && outEls.containsKey(outputs.get(outputName).getValue()) && outEls.get(outputs.get(outputName).getValue()) != null) { Iterator<DataFlowElement> it = outEls.get(outputs.get(outputName).getValue()).iterator(); while (it.hasNext()) { DataFlowElement curEl = it.next(); if (getElement(curEl.getComponentId()) != null) { if (logger.isDebugEnabled()) { logger.debug("link " + outputName + "," + idSA + "->" + copy.getElement(outputs.get(outputName).getKey()).getInputNamePerOutput() .get(outputs.get(outputName).getValue()).get(curEl.getComponentId()) + "," + curEl.getComponentId()); } error = addLink(outputName, idSA, copy.getElement(outputs.get(outputName).getKey()).getInputNamePerOutput() .get(outputs.get(outputName).getValue()).get(curEl.getComponentId()), curEl.getComponentId()); if (error == null) { String newAlias = getElement(curEl.getComponentId()).getAliasesPerComponentInput() .get(idSA).getKey(); String oldAlias = curEl.getAliasesPerComponentInput() .get(outputs.get(outputName).getKey()).getKey(); getElement(curEl.getComponentId()).replaceInAllInteraction( "([_ \\W]|^)(" + Pattern.quote(oldAlias) + ")([_ \\W]|$)", "$1" + newAlias + "$3", true); } } } } } { //Generate name for all the outputs Map<String, DFEOutput> mapOutput = newSA.getDFEOutput(); Iterator<String> outputNameIt = mapOutput.keySet().iterator(); while (outputNameIt.hasNext()) { String dataName = outputNameIt.next(); if (mapOutput.get(dataName).getSavingState() != SavingState.RECORDED && (mapOutput.get(dataName).getPath() == null || !mapOutput.get(dataName).isPathAutoGeneratedForUser(idSA, dataName))) { mapOutput.get(dataName).generatePath(idSA, dataName); } } } if (error != null) { this.element = copy.element; } return error; }
From source file:com.redsqirl.workflow.server.Workflow.java
public SubDataFlow createSA(List<String> componentIds, String subworkflowName, String subworkflowComment, Map<String, Entry<String, String>> inputs, Map<String, Entry<String, String>> outputs) throws Exception { logger.debug("To aggregate: " + componentIds); int posIncr = 150; String error = null;/* ww w . j a v a 2 s .c om*/ // Create subworkflow object SubWorkflow sw = new SubWorkflow(subworkflowName); DataFlowCoordinatorVariables subWfVars = new WfCoordVariables(); // Copy Elements Workflow copy = null; try { copy = (Workflow) clone(); } catch (Exception e) { error = "Fail to clone the workflow"; logger.error(error, e); } if (error == null) { Iterator<String> idIt = copy.getComponentIds().iterator(); try { while (idIt.hasNext()) { String cur = idIt.next(); if (!componentIds.contains(cur)) { logger.debug("To remove: " + cur); copy.removeElement(cur); } else { DataFlowElement curEl = getElement(cur); curEl.cleanDataOut(); //curEl.setPosition(curEl.getX() + posIncr, curEl.getY()); Set<String> varRequired = curEl.getRequiredVariables(); if (varRequired != null && !varRequired.isEmpty()) { DataFlowCoordinatorVariables coordVars = copy.getCoordinator(curEl.getCoordinatorName()) .getVariables(); Iterator<String> varIt = varRequired.iterator(); while (varIt.hasNext()) { String varCur = varIt.next(); subWfVars.addVariable(coordVars.getVariable(varCur)); } } } } } catch (Exception e) { error = "Fail to remove an element"; logger.error(error, e); } } if (error == null) { String coordinatorName = null; Iterator<String> idIt = componentIds.iterator(); while (idIt.hasNext()) { String cur = idIt.next(); DataFlowElement newEl = copy.getElement(cur); logger.debug("To copy: " + cur); if (coordinatorName == null) { coordinatorName = newEl.getCoordinatorName(); } sw.addElement(newEl, coordinatorName); } DataFlowCoordinator coordinatorSW = sw.getCoordinator(coordinatorName); try { // Create Action inputs Iterator<String> entries = inputs.keySet().iterator(); Map<String, DFEOutput> inputsForHelp = new HashMap<String, DFEOutput>(); while (entries.hasNext() && error == null) { String inputName = entries.next(); // Get the DFEOutput from which we copy the constraint DFEOutput constraint = this.getElement(inputs.get(inputName).getKey()).getDFEOutput() .get(inputs.get(inputName).getValue()); inputsForHelp.put(inputName, constraint); sw.addElement((new SubWorkflowInput()).getName(), inputName, coordinatorSW); if (error == null) { // Update Data Type SubWorkflowInput input = (SubWorkflowInput) sw.getElement(inputName); input.update(input.getInteraction(Source.key_datatype)); Tree<String> dataTypeTree = input.getInteraction(Source.key_datatype).getTree(); dataTypeTree.getFirstChild("list").getFirstChild("output").add(constraint.getBrowserName()); logger.debug("Update Data Type"); // Update Data SubType input.update(input.getInteraction(Source.key_datasubtype)); ((ListInteraction) input.getInteraction(Source.key_datasubtype)) .setValue(constraint.getTypeName()); logger.debug("Update Data SubType"); if (PathType.MATERIALIZED.equals(constraint.getPathType())) { List<String> vals = new LinkedList<String>(); vals.add(LanguageManagerWF.getText("superactioninput.allow_materialized")); ((AppendListInteraction) input.getInteraction(SubWorkflowInput.key_materialized)) .setValues(vals); } // Update header input.update(input.getInteraction(SubWorkflowInput.key_headerInt)); InputInteraction header = (InputInteraction) input .getInteraction(SubWorkflowInput.key_headerInt); header.setValue(constraint.getFields().mountStringHeader()); input.update(input.getInteraction(SubWorkflowInput.key_fieldDefInt)); input.updateOut(); logger.debug("Update Out"); Iterator<DataFlowElement> toLinkIt = this.getElement(inputs.get(inputName).getKey()) .getOutputComponent().get(inputs.get(inputName).getValue()).iterator(); Point positionSuperActionInput = new Point(0, 0); int numberOfInput = 0; while (toLinkIt.hasNext()) { DataFlowElement curEl = toLinkIt.next(); if (componentIds.contains(curEl.getComponentId())) { // Create link sw.addLink(SubWorkflowInput.out_name, inputName, getElement(inputs.get(inputName).getKey()).getInputNamePerOutput() .get(inputs.get(inputName).getValue()).get(curEl.getComponentId()), curEl.getComponentId()); String newAlias = sw.getElement(curEl.getComponentId()) .getAliasesPerComponentInput().get(inputName).getKey(); String oldAlias = curEl.getAliasesPerComponentInput() .get(inputs.get(inputName).getKey()).getKey(); sw.getElement(curEl.getComponentId()).replaceInAllInteraction( "([_ \\W]|^)(" + Pattern.quote(oldAlias) + ")([_ \\W]|$)", "$1" + newAlias + "$3", true); positionSuperActionInput.move((int) positionSuperActionInput.getX() + curEl.getX(), (int) positionSuperActionInput.getY() + curEl.getY()); ++numberOfInput; } } input.setPosition((int) (positionSuperActionInput.getX() / numberOfInput) - posIncr, (int) (positionSuperActionInput.getY() / numberOfInput)); } } logger.debug("Create Action"); // Create Action outputs entries = outputs.keySet().iterator(); Map<String, DFEOutput> outputsForHelp = new HashMap<String, DFEOutput>(); while (entries.hasNext() && error == null) { String outputName = entries.next(); sw.addElement((new SubWorkflowOutput()).getName(), outputName, coordinatorSW); if (error == null) { sw.addLink(outputs.get(outputName).getValue(), outputs.get(outputName).getKey(), SubWorkflowOutput.input_name, outputName); DataFlowElement in = sw.getElement(outputs.get(outputName).getKey()); sw.getElement(outputName).setPosition(in.getX() + posIncr, in.getY()); outputsForHelp.put(outputName, in.getDFEOutput().get(outputs.get(outputName).getValue())); } } logger.debug("createSA " + error); sw.getCoordinator(coordinatorName).getVariables().addAll(subWfVars); sw.setComment(generateHelp(RedSqirlModel.getModelAndSW(subworkflowName)[1], subworkflowComment, inputsForHelp, outputsForHelp, subWfVars)); } catch (Exception e) { error = "Fail to create an input or output super action"; logger.error(error, e); } } if (error != null) { throw new Exception(error); } sw.moveToTopRightCorner(50, 50); return sw; }
From source file:org.apache.log4j.chainsaw.LogUI.java
/** * Shutsdown by ensuring the Appender gets a chance to close. *///w w w . ja v a2s. c o m public boolean shutdown() { if (getApplicationPreferenceModel().isConfirmExit()) { if (JOptionPane.showConfirmDialog(LogUI.this, "Are you sure you want to exit Chainsaw?", "Confirm Exit", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) != JOptionPane.YES_OPTION) { return false; } } final JWindow progressWindow = new JWindow(); final ProgressPanel panel = new ProgressPanel(1, 3, "Shutting down"); progressWindow.getContentPane().add(panel); progressWindow.pack(); Point p = new Point(getLocation()); p.move((int) getSize().getWidth() >> 1, (int) getSize().getHeight() >> 1); progressWindow.setLocation(p); progressWindow.setVisible(true); Runnable runnable = new Runnable() { public void run() { try { int progress = 1; final int delay = 25; handler.close(); panel.setProgress(progress++); Thread.sleep(delay); pluginRegistry.stopAllPlugins(); panel.setProgress(progress++); Thread.sleep(delay); panel.setProgress(progress++); Thread.sleep(delay); } catch (Exception e) { e.printStackTrace(); } fireShutdownEvent(); performShutdownAction(); progressWindow.setVisible(false); } }; if (OSXIntegration.IS_OSX) { /** * or OSX we do it in the current thread because otherwise returning * will exit the process before it's had a chance to save things * */ runnable.run(); } else { new Thread(runnable).start(); } return true; }