?? contacteditwindow.java
字號:
,GridBagConstraints.EAST, GridBagConstraints.NONE, defaultInsets, 0, 0)); main.add(textHomeCountry, new GridBagConstraints(1, 14, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); main.add(new JLabel("Home Postcode"), new GridBagConstraints(2, 14, 1, 1, 0.0, 0.0 ,GridBagConstraints.EAST, GridBagConstraints.NONE, defaultInsets, 0, 0)); main.add(textHomePostcode, new GridBagConstraints(3, 14, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); main.add(new JLabel("Gender"), new GridBagConstraints(0, 15, 1, 1, 0.0, 0.0 ,GridBagConstraints.EAST, GridBagConstraints.NONE, defaultInsets, 0, 0)); main.add(comboGender, new GridBagConstraints(1, 15, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); main.add(new JLabel("Birth Date"), new GridBagConstraints(2, 15, 1, 1, 0.0, 0.0 ,GridBagConstraints.EAST, GridBagConstraints.NONE, defaultInsets, 0, 0)); main.add(textBirthDate, new GridBagConstraints(3, 15, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, defaultInsets, 0, 0)); //main.setMinimumSize(new Dimension(300, 374)); //main.setPreferredSize(new Dimension(scrollPane.getWidth() - 35, 374)); // force the screen to be refreshed after adding all these new things (required otherwise it doesn't update the screen main.revalidate(); } public void resetFields() { Contact tmp_contact = contact; if (panelType == PANEL_TYPE_ADD || tmp_contact == null) { tmp_contact = new Contact(); tmp_contact.setHomeState(StateCode.STATE_LIST[0]); tmp_contact.setWorkState(StateCode.STATE_LIST[0]); tmp_contact.setGender(GenderCode.MALE); tmp_contact.setTitle(ContactType.TITLE_LIST[0]); } textFirstName.setText(tmp_contact.getFirstName()); textLastName.setText(tmp_contact.getLastName()); textHomePhone.setText(tmp_contact.getHomePhone()); textHomeFax.setText(tmp_contact.getHomeFax()); textHomeAddress.setText(tmp_contact.getHomeAddress()); textHomeSuburb.setText(tmp_contact.getHomeSuburb()); textHomePostcode.setText(tmp_contact.getHomePostCode()); textHomeCountry.setText(tmp_contact.getHomeCountry()); comboHomeState.setSelectedItem(tmp_contact.getHomeState()); ContactIdentifiresTypeCode cType = tmp_contact.getContactIdentifier(); if (cType != null) { contactIdentifier.setSelectedItem(ContactIdentifiresTypeCode.getForCode(cType.getCode())); } textEmail.setText(tmp_contact.getEmail()); textWWW.setText(tmp_contact.getWWW()); comboTitle.setSelectedItem(tmp_contact.getTitle()); textPosition.setText(tmp_contact.getPosition()); locationComponent.setSelected(tmp_contact.getLocationID()); textWorkPhone.setText(tmp_contact.getWorkPhone()); textWorkOtherPhone.setText(tmp_contact.getWorkOtherPhone()); textWorkFax.setText(tmp_contact.getWorkFax()); textWorkMobile.setText(tmp_contact.getWorkMobile()); textWorkAddress.setText(tmp_contact.getWorkAddress()); textWorkSuburb.setText(tmp_contact.getWorkSuburb()); textWorkPostcode.setText(tmp_contact.getWorkPostCode()); textWorkCountry.setText(tmp_contact.getWorkCountry()); textBirthDate.setText(tmp_contact.getBirthDate()); comboWorkState.setSelectedItem(tmp_contact.getWorkState()); genderModel.setSelectedItem(tmp_contact.getGender()); if (company != null) { textCompany.setText(company.getCompanyName()); btnViewCompany.setEnabled(true); } else { btnViewCompany.setEnabled(false); } System.out.println("Setting notes to: " + tmp_contact.getNotes()); //textNote.setText(tmp_contact.getNotes()); } public void securePanel() { if (entityPermission != null && !entityPermission.canWrite()) { setEditable(false); buttonAdd.setVisible(false); buttonReset.setVisible(false); } if (entityPermission != null && entityPermission.canDelete() && contact != null) { buttonDelete.setVisible(true); } else { buttonDelete.setVisible(false); } //utilityToolbar.setEntityPermission(entityPermission); } public void setEditable(boolean editable) { textFirstName.setEditable(editable); textLastName.setEditable(editable); textHomePhone.setEditable(editable); textHomeFax.setEditable(editable); textHomeAddress.setEditable(editable); textHomeSuburb.setEditable(editable); textHomePostcode.setEditable(editable); textCompany.setEditable(editable); companySearchButton.setEnabled(editable); textWorkPhone.setEditable(editable); textWorkOtherPhone.setEditable(editable); textWorkFax.setEditable(editable); textWorkMobile.setEditable(editable); textWorkAddress.setEditable(editable); textWorkSuburb.setEditable(editable); textWorkPostcode.setEditable(editable); textBirthDate.setEnabled(editable); comboGender.setEnabled(editable); textEmail.setEditable(editable); textWWW.setEditable(editable); textPosition.setEditable(editable); textHomeCountry.setEditable(editable); textWorkCountry.setEditable(editable); // editable not appropriate for combo-type boxes, use enabled instead contactIdentifier.setEnabled(editable); comboWorkState.setEnabled(editable); comboHomeState.setEnabled(editable); comboTitle.setEnabled(editable); locationComponent.setSelectable(editable); } public void deleteContact() { Server server = ServerFactory.getInstance().getServer(); ServerCommand command = null; command = new ServerCommand(ContactModule.CONTACT_DELETE); command.setParameter(ContactModule.PARAM_CONTACT_ID, String.valueOf(contact.getContactID())); server.sendCommand(command); if (callback != null) callback.callback(this, CB_REFRESH, null); dispose(); } public boolean updateContact() { ServerCommand command = null; if (panelType != PANEL_TYPE_EDIT) { command = new ServerCommand(ContactModule.CONTACT_ADD_SUBMIT); } else { command = new ServerCommand(ContactModule.CONTACT_EDIT_SUBMIT); command.setParameter(ContactModule.PARAM_CONTACT_ID, String.valueOf(contact.getContactID())); } if (company != null) { command.setParameter(ContactModule.PARAM_CONTACT_COMPANY_ID, String.valueOf(company.getCompanyID())); } else { command.setParameter(ContactModule.PARAM_CONTACT_COMPANY_ID, "-1"); } command.setParameter(ContactModule.PARAM_CONTACT_GENDER, (GenderCode) genderModel.getSelectedItem()); command.setParameter(ContactModule.PARAM_CONTACT_BIRTHDATE, textBirthDate.getText()); command.setParameter(ContactModule.PARAM_CONTACT_FIRST_NAME, textFirstName.getText()); command.setParameter(ContactModule.PARAM_CONTACT_LAST_NAME, textLastName.getText()); if (selected_location != null) { command.setParameter(ContactModule.PARAM_CONTACT_LOCATION, new Integer(selected_location.getID())); } command.setParameter(ContactModule.PARAM_CONTACT_HOME_PHONE, textHomePhone.getText()); command.setParameter(ContactModule.PARAM_CONTACT_HOME_FAX, textHomeFax.getText()); command.setParameter(ContactModule.PARAM_CONTACT_HOME_ADDRESS, textHomeAddress.getText()); command.setParameter(ContactModule.PARAM_CONTACT_HOME_SUBURB, textHomeSuburb.getText()); command.setParameter(ContactModule.PARAM_CONTACT_HOME_STATE, comboHomeState.getSelectedItem()); command.setParameter(ContactModule.PARAM_CONTACT_HOME_POSTCODE, textHomePostcode.getText()); command.setParameter(ContactModule.PARAM_CONTACT_HOME_COUNTRY, textHomeCountry.getText()); command.setParameter(ContactModule.PARAM_CONTACT_WORK_PHONE, textWorkPhone.getText()); command.setParameter(ContactModule.PARAM_CONTACT_WORK_OTHER_PHONE, textWorkOtherPhone.getText()); command.setParameter(ContactModule.PARAM_CONTACT_WORK_FAX, textWorkFax.getText()); command.setParameter(ContactModule.PARAM_CONTACT_WORK_MOBILE, textWorkMobile.getText()); command.setParameter(ContactModule.PARAM_CONTACT_WORK_ADDRESS, textWorkAddress.getText()); command.setParameter(ContactModule.PARAM_CONTACT_WORK_SUBURB, textWorkSuburb.getText()); command.setParameter(ContactModule.PARAM_CONTACT_WORK_COUNTRY, textWorkCountry.getText()); command.setParameter(ContactModule.PARAM_CONTACT_WORK_STATE, comboWorkState.getSelectedItem()); command.setParameter(ContactModule.PARAM_CONTACT_WORK_POSTCODE, textWorkPostcode.getText()); ContactIdentifiresTypeCode role = (ContactIdentifiresTypeCode)contactIdentifierModel.getSelectedItem(); command.setParameter(ContactModule.PARAM_CONTACT_IDENTIFIER, role); command.setParameter(ContactModule.PARAM_CONTACT_TITLE, comboTitle.getSelectedItem()); command.setParameter(ContactModule.PARAM_CONTACT_POSITION, textPosition.getText()); command.setParameter(ContactModule.PARAM_CONTACT_EMAIL, textEmail.getText()); command.setParameter(ContactModule.PARAM_CONTACT_WWW, textWWW.getText()); //command.setParameter(ContactModule.PARAM_CONTACT_NOTES, textNote.getText()); Server server = ServerFactory.getInstance().getServer(); ServerResponse sr = server.sendCommand(command); if (sr != null) { Integer newContactID = (Integer)sr.getPart("new-contact-id"); if (newContactID != null) { int contactID = ((Integer)sr.getPart("new-contact-id")).intValue(); contact = new Contact(); contact.setContactID(contactID); } } return true; } public boolean validateForm() { boolean valid = true; StringBuffer buf = new StringBuffer(); if (textFirstName.getText().trim().length() == 0 && textLastName.getText().trim().length() == 0) { valid = false; buf.append("- Please enter the contact's name\n"); } String email = textEmail.getText(); if (email != null && email.trim().length() > 0 && (email.indexOf("@") < 0 || email.indexOf(".") < 0)) { valid = false; buf.append("- Please ensure the email address entered is valid."); } if (!valid) { buf.insert(0, "There were errors on the form you have submitted:\n\n"); buf.append("\n"); JOptionPane.showMessageDialog(this, buf.toString(),"Invalid Form Data", JOptionPane.ERROR_MESSAGE); } return valid; } /** * Main class * * @param args */ public static void main(String[] args) { JFrame frame = new JFrame("Utillity Bar"); ContactEditWindow window = new ContactEditWindow(); window.display(); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -