package BuildSim; import CollabUtils.*; import java.util.GregorianCalendar; import javax.swing.JFrame; //import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JScrollPane; import javax.swing.JViewport; import java.awt.Container; import java.awt.Color; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Font; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.Point; //import java.awt.Rectangle; import java.text.SimpleDateFormat; /** Create a GUI for the building simulator. * This is based on the one from the Date Investigator. * The window has a text field where the user can type in a date * There is a text area where the results of the investigation are displayed * * @author dickey */ class Proj4GUI extends JFrame { /** number of instances of this class which have been created. */ private static int instanceCount = 0; /** //place text to display here. note protected access. */ JTextArea outputArea; //BuildingModel buildMod; private IApplicationIdentification owner; /** do little in the constructor */ Proj4GUI(IApplicationIdentification owner) { super(owner.getApplicationDescription()); instanceCount++; assert owner != null; this.owner = owner; this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.addWindowListener(new WindowAdapter() { public void windowClosing(ActionEvent ev) { System.out.println("GUI got window closing event."); System.exit(0); //not working?? } }); buildUI(); //build the GUI components } //end constructor /** build the GUI frame and display it */ private void buildUI() { Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screensize = tk.getScreenSize(); int windowWidth = (screensize.width - 20) / 2; int windowHeight = screensize.height - 100; this.setSize(windowWidth, windowHeight); Container contents = this.getContentPane(); contents.removeAll(); //in case the method is called more than once //use a border layout (should be the default anyway) contents.setLayout(new BorderLayout()); //create a textarea to hold program information, place it at the top String instructions = owner.getApplicationDescription() + " by " + owner.getApplicationAuthor(); GregorianCalendar g = owner.getApplicationDate(); instructions += " " + (new SimpleDateFormat()).format(g.getTime()); instructions += "\n" + owner.getApplicationDescriptionDetails(); instructions += "\n" + owner.getUsageInformation(); //Use a JTextArea instead of a JLabel, so that '\n' will work. JTextArea labelArea = new JTextArea("basic info"); labelArea.setEnabled(false); //no typing allowed. labelArea.setText(instructions); labelArea.setBackground(new Color(250,255,200)); //create a big output textarea outputArea = new JTextArea("Results will appear here"); outputArea.setEnabled(false); //don't let user type in outputArea.setBackground(new Color(230,230,255)); Font origFont = outputArea.getFont(); outputArea.setFont(origFont.deriveFont(Font.BOLD)); this.show(); /** Can't know location until after frame is visible. */ Dimension paneSize = contents.getSize(); Point screenLoc = this.getLocationOnScreen(); int xLoc = screenLoc.x + (Proj4GUI.instanceCount-1) * windowWidth; this.setLocation(xLoc, screenLoc.y); //Now that we know the size of the content pane, resize the components. final int w1 = paneSize.width; final int h1 = paneSize.height / 5; Dimension labelSize = new Dimension(w1, h1); //labelArea.setPreferredSize(labelSize); JScrollPane infoPane = new JScrollPane(labelArea); infoPane.setPreferredSize(labelSize); contents.add(infoPane, BorderLayout.NORTH); final int w2 = w1; final int h2 = paneSize.height - h1 - 2; final Dimension areaSize = new Dimension(w2, h2); //this.outputArea.setPreferredSize(areaSize); JScrollPane outputPane = new JScrollPane(outputArea); outputPane.setPreferredSize(areaSize); contents.add(outputPane, BorderLayout.SOUTH); this.show(); } //end buildUI //end Proj4GUI }