📄 conceptapl.java
字号:
});
frame.setVisible(true);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of javax.swing.JApplet");
exception.printStackTrace(System.out);
}
}
/**
* Called when the mouse has been clicked.
* @param e the received event
*/
public void mouseClicked(MouseEvent e) {
System.out.println("mouseClicked");
lastclickx = e.getX();
lastclicky = e.getY();
}
/**
* Called when the mouse has been dragged.
* @param e the received event
*/
public void mouseDragged(MouseEvent e) {
System.out.println("mouseDragged");
}
/**
* Called when the mouse has entered a window.
* @param e the received event
*/
public void mouseEntered(MouseEvent e) {
System.out.println("mouseEntered");
}
/**
* Called when the mouse has exited a window.
* @param e the received event
*/
public void mouseExited(MouseEvent e) {
System.out.println("mouseExited");
}
/**
* Called when the mouse has been moved.
* @param e the received event
*/
public void mouseMoved(MouseEvent e) {
System.out.println("mouseMoved");
}
/**
* Called when a mouse button has been pressed.
* @param e the received event
*/
public void mousePressed(MouseEvent e) {
System.out.println("mousePressed");
if ((e.getComponent()!=getConceptTablePanel())&&(getConceptTablePanel().getEditRight()==true)) {
displayServerResponse("Warning", "You have not finished the edit action. Click SAVE or CANCEL.");
}
}
/**
* Called when a mouse button has been released.
* @param e the received event
*/
public void mouseReleased(MouseEvent e) {
System.out.println("mouseReleased");
}
/**
* Pads a string w/ extra spaces if it is shorter than the COLUMN_WIDTH
*/
protected String padString(String text) {
StringBuffer result = null;
System.out.println(text.length());
System.out.println("----------");
if (text.length() < COLUMN_WIDTH) {
int count = COLUMN_WIDTH - text.length();
result = new StringBuffer(text);
for (int i=0; i < count; i++) {
result.append(" ");
}
}
else {
result = new StringBuffer(text.substring(0, COLUMN_WIDTH));
}
return result.toString();
}
/**
* Paints the applet.
* If the applet does not need to be painted (e.g. if it is only a container for other
* awt components) then this method can be safely removed.
*
* @param g the specified Graphics window
* @see #update
*/
public void paint(Graphics g) {
super.paint(g);
// insert code to paint the applet here
}
/**
* Read the input from the servlet. <b>
*
* The servlet will return a serialized vector containing
* concept entries.
*
*/
protected Vector readConceptVector(ObjectInputStream theInputFromServlet) {
Vector theConceptVector = null;
ConceptstrModel cstrmdl = null;
try {
// read the serialized vector of concepts objects from
// the servlet
//
log("Reading data...");
theConceptVector = (Vector) theInputFromServlet.readObject();
//cstrmdl = (ConceptstrModel) theInputFromServlet.readObject();
//Vector theCstrVector = (Vector) theInputFromServlet.readObject();
while (cstrmdl!=null) {
log("OBJECT READ" + cstrmdl.getName()+ "get conceptlist...");
//cstrmdl = (ConceptstrModel)theCstrVector.get(0);
//theConceptVector = new Vector(cstrmdl.getConceptlist());
}
log("Finished reading data. " + theConceptVector.size() + " concepts returned");
theInputFromServlet.close();
}
catch (IOException e) {
log(e.toString());
}
catch (ClassNotFoundException e) {
log(e.toString());
}
catch (Exception e) {
System.out.println(e);
}
return theConceptVector;
}
/**
* Reads a response from the servlet.
*/
protected String readServletResponse(URLConnection servletConnection) {
BufferedReader inFromServlet = null;
try {
// now, let's read the response from the servlet.
// this is simply a confirmation string
inFromServlet = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
String str ="";
String line;
while (null != ((line = inFromServlet.readLine()))) {
log("Reading servlet response: " + line + "; ");
str= str + line;
}
inFromServlet.close();
return str;
}
catch (IOException e) {
log(e.toString());
}
return "NO Response";
//return "OK";
}
private URLConnection getConnectiontoServer(String connection) {
try{
log("Connecting to servlet...");
URL connectionURL = new URL( connection );
URLConnection servletConnection = connectionURL.openConnection();
log("Connected");
// inform the connection that we will send output and accept input
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
// Don't used a cached version of URL connection.
servletConnection.setUseCaches(false);
log("SET REQUEST PROPERTY");
// Specify the content type that we will send binary data
servletConnection.setRequestProperty
("Content-Type", "application/octet-stream");
return servletConnection;
}
catch (Exception ex) {
System.out.println(ex);
}
return null;
}
/**
* Register a new concept.
*
* This is accomplished by showing a registration dialog box. The user
* enters conceptname, e-mail, proposestakeholder, etc. This information is
*/
public void displayServerResponse(String title, String content) {
Displaydlg displayDialog = new Displaydlg(new javax.swing.JFrame(), true);
displayDialog.setLocation(lastclickx, lastclicky);
displayDialog.setMsgTitle(title);
displayDialog.setMsgContent(content);
displayDialog.setVisible(true);
displayDialog.setResizable(false);
}
// this class is the centrol communication point toward the server
protected void editConcept(String conceptstrID, String aconceptID, int operation) {
if((getConceptTablePanel().getCurrentconceptID()).equals(" ")) {
return;
}
ConceptModel theConcept = null;
if((operation!=ConceptEvent.UPDATE_CONCEPT)&&(operation!=ConceptEvent.CREATE_CONCEPT)) {
theConcept = conceptTablePanel.getConceptModel();
System.out.println("get concept model from table");
}
URLConnection theCon = null;
int lastIDint = Integer.valueOf(lastID).intValue();
String newconceptID = String.valueOf(lastIDint+1);
System.out.println("Conceptapl: The last ID" + lastIDint);
// enable the concept table to edit
switch (operation) {
case ConceptEvent.CREATE_CONCEPT: { //check permission,
try {
System.out.println("Checking permittion");
if (conceptTablePanel.getEditRight()!=true) {
theCon = getConnectiontoServer(webServerConceptStr);
if (aconceptID.equals("new")) //check whether someone else is also creating data
{
sendConceptToServlet(theCon, createAddConceptEvent(conceptstrID, newconceptID));
log("send concept to servlet to check permittion: new ID " +newconceptID);
String res = readServletResponse(theCon);
System.out.println("permittion result: " + res);
if (!res.equals("OK")) {
displayServerResponse("Warning", res+" Please Reload After A While");
return;
}
else {
// permittion obtained
conceptTablePanel.setEditRight(true);
}
}
System.out.println("create concept ");
}
}
catch (Exception e) {
log(e.toString());
System.out.println(e.toString());
}
} break;
case ConceptEvent.CREATE_CONCEPT_DATA: {
try {
if ((conceptTablePanel.getEditRight()==true)&&(theConcept!=null)) {
theCon = getConnectiontoServer(webServerConceptStr);
theConcept.setConceptID(newconceptID);
System.out.println("CREATE_CONCEPT_DATA: "+ newconceptID);
sendConceptToServlet(theCon, createAddConceptDataEvent(conceptstrID, theConcept));
log("create concept...");
displayServerResponse("Create Concept", readServletResponse(theCon));
conceptTablePanel.setEditRight(false);
}
}
catch (Exception e) {
log(e.toString());
System.out.println(e.toString());
}
} break;
case ConceptEvent.UPDATE_CONCEPT: { //check permission, this case should be CHECKPERMIT
try {
System.out.println("Checking permittion");
if (conceptTablePanel.getEditRight()!=true) {
theCon = getConnectiontoServer(webServerConceptStr);
if (aconceptID!="new") //check whether someone else is also creating data
{
sendConceptToServlet(theCon, createUpdateConceptEvent(conceptstrID, aconceptID));
}
else {
sendConceptToServlet(theCon, createUpdateConceptEvent(conceptstrID, newconceptID));
}
log("send concept to servlet to check permittion");
String res = readServletResponse(theCon);
System.out.println("permittion result: " + res);
if (!res.equals("OK")) {
displayServerResponse("Warning", res+" Please Reload After A While");
return;
}
else {
// permittion obtained
conceptTablePanel.setEditRight(true);
}
System.out.println("update servlet");
}
}
catch (Exception e) {
log(e.toString());
System.out.println(e.toString());
}
} break;
case ConceptEvent.UPDATE_CONCEPT_DATA: {
if ((conceptTablePanel.getEditRight()==true)&&(theConcept!=null)) {
theCon = getConnectiontoServer(webServerConceptStr );
sendConceptToServlet(theCon, createUpdateConceptDataEvent(conceptstrID, theConcept));
log("update to servlet");
displayServerResponse("Update Concept", readServletResponse(theCon));
System.out.println("update concept str");
}
conceptTablePanel.setEditRight(false);
} break;
case ConceptEvent.DELETE_CONCEPT: {
theCon = getConnectiontoServer(webServerConceptStr );
if (theConcept.getShared().equals("Shared")) {
displayServerResponse("Warning", "The Concept is a Shared Concept, Please ask the manger to mark it NOTSHARED and then delete.");
return;
}
sendConceptToServlet(theCon, createDeleteConceptEvent(conceptstrID, aconceptID));
log("delete concept...");
String res = readServletResponse(theCon);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -