package com.ubigrate.tutorial.flex; import java.io.FileWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.Marshaller; import com.adobe._2006.mxml.CtApplication; import com.adobe._2006.mxml.CtButton; import com.adobe._2006.mxml.CtHBox; import com.adobe._2006.mxml.CtPanel; import com.adobe._2006.mxml.CtVBox; import com.adobe._2006.mxml.ObjectFactory; public class MXMLGenerator { private JAXBElement applicationWrapper; public void createMXMLApplication() { ObjectFactory mxmlFactory = new ObjectFactory(); CtApplication application = mxmlFactory.createCtApplication(); applicationWrapper = mxmlFactory.createApplication(application); CtVBox vBox = mxmlFactory.createCtVBox(); JAXBElement vBoxWrapper = mxmlFactory.createVBox(vBox); application.getContent().add(vBoxWrapper); CtPanel panel1 = mxmlFactory.createCtPanel(); JAXBElement panel1Wrapper = mxmlFactory.createPanel(panel1); vBox.getContent().add(panel1Wrapper); panel1.setId("p1"); panel1.setTitle("Panel 1"); CtPanel panel2 = mxmlFactory.createCtPanel(); JAXBElement panel2Wrapper = mxmlFactory.createPanel(panel2); vBox.getContent().add(panel2Wrapper); panel2.setId("p2"); panel2.setTitle("Panel 2"); CtPanel panel3 = mxmlFactory.createCtPanel(); JAXBElement panel3Wrapper = mxmlFactory.createPanel(panel3); vBox.getContent().add(panel3Wrapper); panel3.setId("p3"); panel3.setTitle("Panel 3"); CtHBox hBox = mxmlFactory.createCtHBox(); JAXBElement hBoxWrapper = mxmlFactory.createHBox(hBox); application.getContent().add(hBoxWrapper); CtButton button1 = mxmlFactory.createCtButton(); JAXBElement button1Wrapper = mxmlFactory.createButton(button1); hBox.getContent().add(button1Wrapper); button1.setLabel("Toggle Panel 2 Visible"); button1.setClick("{p2.visible=!p2.visible;}"); CtButton button2 = mxmlFactory.createCtButton(); JAXBElement button2Wrapper = mxmlFactory.createButton(button2); hBox.getContent().add(button2Wrapper); button2.setLabel("Toggle Panel 2 in Layout"); button2.setClick("{p2.includeInLayout=!p2.includeInLayout;}"); } public void marshalApplication() { try { JAXBContext mxmlContext = JAXBContext.newInstance("com.adobe._2006.mxml", this.getClass().getClassLoader()); Marshaller marshaller = mxmlContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(applicationWrapper, new FileWriter("app.mxml")); System.out.println("Marshalling done."); } catch(Exception e) { throw new RuntimeException(e); } } }