// File: DefaultPanel.java // Classes: DefaultPanel // Author: Kedar Patankar package edu.neu.ccs.demeter.tools.apstudio.graphedit; import java.awt.Panel; import java.awt.TextArea; import java.awt.TextField; import java.awt.Color; import java.awt.event.ActionListener; import java.awt.event.FocusListener; import java.awt.event.ActionEvent; import java.awt.event.FocusEvent; import java.awt.event.TextEvent; import java.awt.event.TextListener; import edu.neu.ccs.demeter.tools.apstudio.ui.PropsGridLayout; /* Purpose : This class shows package and import statements */ public class DefaultPanel extends Panel implements ActionListener,FocusListener { private Editor _editor; private String _preamble,_package; private TextField _packageText; private TextArea _preambleText; private PropertyWindow _pw; public DefaultPanel(Editor editor, PropertyWindow parent) { _editor = editor; _pw = parent; setLayout( new PropsGridLayout(5,5)); TextField packageLabel,preambleLabel; packageLabel = new TextField("Package"); _packageText = new TextField(); _packageText.addActionListener(this); _packageText.addFocusListener(this); preambleLabel = new TextField("Import Statements"); _preambleText = new TextArea(); _preambleText.addFocusListener(this); packageLabel.setEditable(false); preambleLabel.setEditable(false); add(packageLabel); add(_packageText); add(preambleLabel); add(_preambleText); setBackground(Color.lightGray); } public void setValues(Document d) { JavaCode j = d.get_preamble(); if(j!=null) { _preamble = d.get_preamble().get_code().toString().trim(); _preambleText.setText(_preamble); } else { _preamble = ""; _preambleText.setText(""); } Package p = d.get_pkg(); if(p == null) { _package=""; _packageText.setText(""); } else { String ps = p.get_packagename().toString(); _package = ps; _packageText.setText(ps); } } public void actionPerformed(ActionEvent event) { String _packageString = _packageText.getText().trim(); if(_package.equals(_packageString)) return; if(!_packageString.equals("")) { Package p; try{p = Package.parse("package "+_packageString+" ;");} catch(RuntimeException re) { _pw.showMessage("Not a valid package name."); _packageText.select(0,_packageString.length()); _packageText.requestFocus(); return; } _editor.curDocument().set_pkg(p); _package = _packageString; _editor.curDocument().cdNeedsSaving(true); } else { _editor.curDocument().set_pkg(null); _package = null; _editor.curDocument().cdNeedsSaving(true); } _pw.setDefaultMessage(); _package = _packageString; } public void focusGained(FocusEvent event){} public void focusLost(FocusEvent event) { Object source = event.getSource(); if(source == _packageText) _packageText.setText(_package); else { String s = _preambleText.getText().trim(); if(_preamble.equals(s)) return; if(s.equals("")) _editor.curDocument().set_preamble(null); else { JavaCode j = JavaCode.parse("(@ "+s+" @)"); _editor.curDocument().set_preamble(j); } _preamble = s; _editor.curDocument().cdNeedsSaving(true); } } } /* end class DefaultPanel */