package cruise.ui.jfx.templates.impl; import cruise.model.abstractObjects.IGenerator; import java.util.*; import cruise.model.abstractObjects.BackingObject; import cruise.umple.compiler.*; import cruise.ui.jfx.*; public class DialogUtils implements IGenerator { protected static String nl; public static synchronized DialogUtils create(String lineSeparator) { nl = lineSeparator; DialogUtils result = new DialogUtils(); nl = null; return result; } public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; protected final String TEXT_1 = "package "; protected final String TEXT_2 = ".components;" + NL + "" + NL + "/*" + NL + "Code from JavaFX Samples and Widgets - Rakesh Menontor." + NL + " */" + NL + "" + NL + "import java.awt.AWTEvent;" + NL + "import java.awt.Color;" + NL + "import java.awt.Point;" + NL + "import java.awt.Toolkit;" + NL + "import java.awt.event.AWTEventListener;" + NL + "import java.awt.event.ContainerEvent;" + NL + "import java.awt.event.MouseAdapter;" + NL + "import java.awt.event.MouseEvent;" + NL + "import java.awt.event.MouseMotionListener;" + NL + "import java.awt.event.WindowAdapter;" + NL + "import java.awt.event.WindowEvent;" + NL + "import javafx.lang.FX;" + NL + "import javax.swing.JDialog;" + NL + "import javax.swing.JFrame;" + NL + "" + NL + "/**" + NL + " *" + NL + " * @author Rakesh Menon" + NL + " */" + NL + "" + NL + "public class DialogUtils extends MouseAdapter" + NL + " implements AWTEventListener, MouseMotionListener {" + NL + "" + NL + " private JDialog dialog = null;" + NL + "" + NL + " private Point startPoint = null;" + NL + " private int startX = 0;" + NL + " private int startY = 0;" + NL + "" + NL + " public DialogUtils() {" + NL + " // Listen to ComponentEvent" + NL + " Toolkit.getDefaultToolkit().addAWTEventListener(" + NL + " this, AWTEvent.COMPONENT_EVENT_MASK);" + NL + " }" + NL + "" + NL + " public JDialog getDialog() {" + NL + " return dialog;" + NL + " }" + NL + "" + NL + " public void eventDispatched(AWTEvent event) {" + NL + "" + NL + " if(event.getID() == ContainerEvent.COMPONENT_RESIZED) {" + NL + "" + NL + " if(event.getSource() instanceof JFrame) {" + NL + "" + NL + " // Remove AWT Event Listener" + NL + " Toolkit.getDefaultToolkit().removeAWTEventListener(this);" + NL + "" + NL + " if(dialog == null) {" + NL + "" + NL + " // Get instance of Stage - Frame" + NL + " JFrame frame = (JFrame) event.getSource();" + NL + " frame.dispose();" + NL + "" + NL + " // Create Dialog instance" + NL + " dialog = new JDialog((JFrame)null, frame.getTitle(), false);" + NL + " dialog.addWindowListener(new WindowAdapter() {" + NL + " @Override" + NL + " public void windowClosing(WindowEvent we) {" + NL + " FX.exit();" + NL + " }" + NL + " });" + NL + "" + NL + " // Set dialog attributes" + NL + " dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);" + NL + " dialog.setAlwaysOnTop(true);" + NL + " dialog.setSize(frame.getSize());" + NL + " dialog.setLocation(frame.getLocation());" + NL + " // dialog.setUndecorated(true);" + NL + " dialog.setBackground(Color.BLACK);" + NL + "" + NL + " dialog.setContentPane(frame.getContentPane());" + NL + " dialog.getContentPane().addMouseListener(this);" + NL + " dialog.getContentPane().addMouseMotionListener(this);" + NL + "" + NL + " dialog.setVisible(true);" + NL + " }" + NL + " }" + NL + " }" + NL + " }" + NL + "" + NL + " public void mousePressed(MouseEvent me) {" + NL + " startPoint = dialog.getLocationOnScreen();" + NL + " startX = me.getX();" + NL + " startY = me.getY();" + NL + " }" + NL + "" + NL + " public void mouseDragged(MouseEvent me) {" + NL + " startPoint.translate(me.getX() - startX, me.getY() - startY);" + NL + " dialog.setLocation(startPoint);" + NL + " }" + NL + "" + NL + " public void mouseMoved(MouseEvent me) {" + NL + "" + NL + " }" + NL + "}" + NL; protected final String TEXT_3 = NL; public String generate(Object argument) { final StringBuffer stringBuffer = new StringBuffer(); List clazzez=(List)argument; String preffix=JFXProvider.properties.getProperty(cruise.model.Constants.PACKAGE_PREFIX); stringBuffer.append(TEXT_1); stringBuffer.append(preffix); stringBuffer.append(TEXT_2); stringBuffer.append(TEXT_3); return stringBuffer.toString(); } }