@Override public org.lgna.croquet.edits.Edit perform( org.lgna.croquet.history.CompletionStep<?> step, org.lgna.croquet.AbstractComposite.InternalActionOperation source) throws org.lgna.croquet.CancelException { boolean isAbleToRunWinsatDirectly; try { StringBuilder sb = new StringBuilder(); int result = edu.cmu.cs.dennisc.java.lang.ProcessUtilities .startAndDrainStandardOutAndStandardError( new ProcessBuilder("winsat", "-?"), sb); edu.cmu.cs.dennisc.java.util.logging.Logger.outln("result:", result); edu.cmu.cs.dennisc.java.util.logging.Logger.outln(sb.toString()); isAbleToRunWinsatDirectly = result == 0; } catch (edu.cmu.cs.dennisc.java.lang.ProcessStartException pse) { // User Account Control? pse.printStackTrace(); isAbleToRunWinsatDirectly = false; } catch (java.io.IOException ioe) { ioe.printStackTrace(); isAbleToRunWinsatDirectly = false; } // isAbleToRunWinsatDirectly = false; ProcessBuilder[] processBuilders; if (isAbleToRunWinsatDirectly) { processBuilders = new ProcessBuilder[] { new ProcessBuilder("winsat", "dwm"), new ProcessBuilder("winsat", "d3d") }; } else { // try { // java.io.File tempFile = java.io.File.createTempFile( "fixGraphics", ".bat" ); // tempFile.deleteOnExit(); // StringBuilder sb = new StringBuilder(); // sb.append( "winsat dwm\n" ); // sb.append( "winsat d3d\n" ); // edu.cmu.cs.dennisc.java.io.TextFileUtilities.write( tempFile, sb.toString() // ); // processBuilders = new ProcessBuilder[] { // new ProcessBuilder( "cmd", "/C", "start", tempFile.getAbsolutePath() ) // }; // } catch( java.io.IOException ioe ) { // throw new RuntimeException( "cannot create temp file", ioe ); // } processBuilders = new ProcessBuilder[] { new ProcessBuilder("cmd", "/c", "winsat.exe dwm & winsat.exe d3d") }; } final javax.swing.text.AttributeSet attributeSet = null; edu.cmu.cs.dennisc.worker.process.ProcessWorker processWorker = new edu.cmu.cs.dennisc.worker.process.ProcessWorker(processBuilders) { private void appendText(String s) { javax.swing.text.Document document = stardardOutAndStandardErrorState.getSwingModel().getDocument(); try { document.insertString(document.getLength(), s, attributeSet); } catch (javax.swing.text.BadLocationException ble) { ble.printStackTrace(); } } @Override protected void handleStart_onEventDispatchThread() { // this.appendText( "start\n" ); } @Override protected void handleStartProcess_onEventDispatchThread(int i) { this.appendText( "start process " + this.getProcessBuilders()[i].command() + "\n"); } @Override protected void handleProcessStandardOutAndStandardError_onEventDispatchThread( String s) { this.appendText(s); } @Override protected void handleDone_onEventDispatchThread(Integer value) { this.appendText("done."); } }; processWorker.execute(); return null; }
public AbstractNode decode( org.w3c.dom.Element xmlElement, java.util.Map<Integer, AbstractDeclaration> map) { AbstractNode rv; if (xmlElement.hasAttribute(CodecConstants.TYPE_ATTRIBUTE)) { String clsName = getClassName(xmlElement); if (clsName.equals(JavaType.class.getName())) { rv = JavaType.getInstance(decodeType(xmlElement, "type")); } else if (clsName.equals(UserArrayType.class.getName())) { rv = decodeUserArrayType(xmlElement, map); } else if (clsName.equals(JavaConstructor.class.getName())) { rv = JavaConstructor.getInstance(decodeConstructor(xmlElement, "constructor")); } else if (clsName.equals(JavaMethod.class.getName())) { MethodReflectionProxy methodReflectionProxy = decodeMethod(xmlElement, "method"); MethodReflectionProxy varArgsReplacement = MethodReflectionProxy.getReplacementIfNecessary(methodReflectionProxy); if (varArgsReplacement != null) { edu.cmu.cs.dennisc.java.util.logging.Logger.errln( "replacing", methodReflectionProxy, "with", varArgsReplacement); methodReflectionProxy = varArgsReplacement; } rv = JavaMethod.getInstance(methodReflectionProxy); } else if (clsName.equals(Getter.class.getName()) || clsName.equals(Setter.class.getName())) { org.w3c.dom.Node xmlFirstChild = xmlElement.getFirstChild(); if (xmlFirstChild instanceof org.w3c.dom.Element) { org.w3c.dom.Element xmlFirstChildElement = (org.w3c.dom.Element) xmlFirstChild; if (xmlFirstChildElement.hasAttribute(CodecConstants.UNIQUE_KEY_ATTRIBUTE)) { int getterOrSetterUniqueKey = getUniqueKey(xmlElement); int fieldUniqueKey = getUniqueKey(xmlFirstChildElement); java.util.Map<Integer, Integer> mapToFieldKey; if (clsName.equals(Getter.class.getName())) { mapToFieldKey = EPIC_HACK_mapGetterKeyToFieldKey; } else { mapToFieldKey = EPIC_HACK_mapSetterKeyToFieldKey; } mapToFieldKey.put(getterOrSetterUniqueKey, fieldUniqueKey); } } org.w3c.dom.NodeList nodeList = xmlElement.getChildNodes(); assert nodeList.getLength() == 1; org.w3c.dom.Element xmlField = (org.w3c.dom.Element) nodeList.item(0); UserField field = (UserField) decode(xmlField, map); if (clsName.equals(Getter.class.getName())) { rv = field.getGetter(); } else { rv = field.getSetter(); } } else if (clsName.equals(SetterParameter.class.getName())) { org.w3c.dom.NodeList nodeList = xmlElement.getChildNodes(); assert nodeList.getLength() == 1; org.w3c.dom.Element xmlSetter = (org.w3c.dom.Element) nodeList.item(0); Setter setter = (Setter) decode(xmlSetter, map); rv = setter.getRequiredParameters().get(0); } else if (clsName.equals(JavaField.class.getName())) { rv = JavaField.getInstance(decodeField(xmlElement, "field")); } else if (clsName.equals(AnonymousUserConstructor.class.getName())) { rv = decodeAnonymousConstructor(xmlElement, map); } else if (clsName.equals(JavaConstructorParameter.class.getName())) { org.w3c.dom.NodeList nodeList = xmlElement.getChildNodes(); assert nodeList.getLength() == 2; org.w3c.dom.Element xmlConstructor = (org.w3c.dom.Element) nodeList.item(0); JavaConstructor constructorDeclaredInJava = (JavaConstructor) decodeValue(xmlConstructor, map); org.w3c.dom.Element xmlIndex = (org.w3c.dom.Element) nodeList.item(1); int index = Integer.parseInt(xmlIndex.getTextContent()); final int REQUIRED_N = constructorDeclaredInJava.getRequiredParameters().size(); if (index < REQUIRED_N) { rv = constructorDeclaredInJava.getRequiredParameters().get(index); } else { if (index == REQUIRED_N) { rv = constructorDeclaredInJava.getVariableLengthParameter(); if (rv != null) { // pass; } else { rv = constructorDeclaredInJava.getKeyedParameter(); } } else { rv = null; } } } else if (clsName.equals(JavaMethodParameter.class.getName())) { org.w3c.dom.NodeList nodeList = xmlElement.getChildNodes(); assert nodeList.getLength() == 2; org.w3c.dom.Element xmlMethod = (org.w3c.dom.Element) nodeList.item(0); JavaMethod methodDeclaredInJava = (JavaMethod) decodeValue(xmlMethod, map); org.w3c.dom.Element xmlIndex = (org.w3c.dom.Element) nodeList.item(1); int index = Integer.parseInt(xmlIndex.getTextContent()); final int REQUIRED_N = methodDeclaredInJava.getRequiredParameters().size(); if (index < REQUIRED_N) { rv = methodDeclaredInJava.getRequiredParameters().get(index); } else { if (index == REQUIRED_N) { rv = methodDeclaredInJava.getVariableLengthParameter(); if (rv != null) { // pass; } else { rv = methodDeclaredInJava.getKeyedParameter(); } } else { rv = null; } } } else { rv = (AbstractNode) newInstance(xmlElement); assert rv != null; } if (rv instanceof AbstractDeclaration) { map.put(getUniqueKey(xmlElement), (AbstractDeclaration) rv); } rv.decodeNode(this, xmlElement, map); if (xmlElement.hasAttribute(CodecConstants.ID_ATTRIBUTE)) { if (this.policy.isIdPreserved()) { rv.setId(java.util.UUID.fromString(xmlElement.getAttribute(CodecConstants.ID_ATTRIBUTE))); } } } else { int key = getUniqueKey(xmlElement); rv = map.get(key); if (rv != null) { // pass } else { if (EPIC_HACK_mapArrayTypeKeyToLeafTypeKey.containsKey(key)) { int leafTypeKey = EPIC_HACK_mapArrayTypeKeyToLeafTypeKey.get(key); AbstractDeclaration leafDeclaration = map.get(leafTypeKey); if (leafDeclaration instanceof UserType<?>) { UserType<?> leafType = (UserType<?>) leafDeclaration; edu.cmu.cs.dennisc.java.util.logging.Logger.outln(leafTypeKey, leafType); rv = leafType.getArrayType(); } else { assert false : leafDeclaration; } } else if (EPIC_HACK_mapGetterKeyToFieldKey.containsKey(key)) { int fieldKey = EPIC_HACK_mapGetterKeyToFieldKey.get(key); AbstractDeclaration fieldDeclaration = map.get(fieldKey); if (fieldDeclaration instanceof UserField) { UserField userField = (UserField) fieldDeclaration; rv = userField.getGetter(); } } else if (EPIC_HACK_mapSetterKeyToFieldKey.containsKey(key)) { int fieldKey = EPIC_HACK_mapSetterKeyToFieldKey.get(key); AbstractDeclaration fieldDeclaration = map.get(fieldKey); if (fieldDeclaration instanceof UserField) { UserField userField = (UserField) fieldDeclaration; rv = userField.getSetter(); } } else { assert false : Integer.toHexString(key) + " " + map; } } } return rv; }