?? globalvalueeditpane.java
字號:
package com.sutternow.swingkar.gui;import com.gargoylesoftware.base.gui.TableLayout;import com.sutternow.swingkar.ConfigManager;//import com.sutternow.swingkar.gui.PropertyTableModel;import com.sutternow.misc.Utils;import net.sf.easylayouts.RowLayout;import org.dom4j.Element;import org.dom4j.Node;import javax.swing.*;import javax.swing.table.AbstractTableModel;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.util.*;import java.util.List;/** * Created by IntelliJ IDEA. * User: Matthew Payne * Date: Jan 18, 2003 * Time: 1:01:50 AM * To change this template use Options | File Templates. */public class GlobalValueEditPane implements SimpleForm, ActionListener, MouseListener { public String Title = "Global Value"; public GlobalValueEditPane(ConfigManager _cm) { cm = _cm; props = new HashMap(); } public String getTitle() { return Title; } public JPanel getEditForm() { final TableLayout layout = new TableLayout(); // Border etched = BorderFactory.createEtchedBorder(); final JPanel panel = new JPanel(); //final JPanel topPanel = new JPanel(new TableLayout()); final JPanel bottomPanel = new JPanel(); RowLayout rowLayout = new RowLayout(panel, 1, 10); rowLayout.add(new JLabel("Global Value Name:"), 0); globalObjName = new JTextField(25); rowLayout.add(globalObjName, 0); rowLayout.add(new JLabel("Key:"), 1); displayName = new JTextField(12); rowLayout.add(displayName, 1); rowLayout.add(new JLabel("Value:"), 1); itemValue = new JTextField(12); rowLayout.add(itemValue, 1); addItem = new JButton("Add"); addItem.addActionListener(this); rowLayout.add(addItem, 1); propModel = new PropertyModel(props.entrySet()); propertyTable = new JTable(propModel); propertyTable.addMouseListener(this); /* TableColumn col = propertyTable.getColumnModel().getColumn(1); col.setPreferredWidth(propertyTable.getColumnModel().getColumn(0).getWidth() * 4);*/ JScrollPane jsp = new JScrollPane(propertyTable); // jsp.setSize(80, 90); jsp.setMinimumSize(new Dimension(90, 80)); jsp.setMaximumSize(new Dimension(320, 260)); jsp.setPreferredSize(new Dimension(300, 240)); rowLayout.add(jsp, 2); // popup menu popmenu = new JPopupMenu(); editEntry = new JMenuItem("Edit"); editEntry.addActionListener(this); popmenu.add(editEntry); delEntry = new JMenuItem("Delete"); delEntry.addActionListener(this); popmenu.add(delEntry); /*cmdSave = new JButton("Save"); cmdCancel = new JButton("Cancel"); cmdSave.addActionListener(this); cmdCancel.addActionListener(this); bottomPanel.add(cmdSave); bottomPanel.add(cmdCancel);*/ layout.setColumnExpandable(0, true); layout.setColumnExpandable(1, true); rowLayout.add(bottomPanel, 3); return panel; } public void setValues(Element gvNode) { this.clearForm(); globalVElement = gvNode; String relPath = gvNode.getUniquePath(); globalObjName.setText(Utils.parseNull(gvNode.valueOf(relPath + "/name"))); List choices = gvNode.selectNodes(relPath + "/choice"); for (Iterator iter = choices.listIterator(); iter.hasNext();) { String code = ""; String display = ""; Element element = (Element) iter.next(); System.out.println(element.getName()); System.out.println(element.elementText("code")); code = element.elementText("code"); display = element.elementText("display"); props.put(display, code); } propModel.requestRefresh(); } private void makeResponse() { Element e = globalVElement; // DocumentHelper.createElement("global-value-ref"); e.clearContent(); e.addElement("name").addText(globalObjName.getText()); Iterator iter = props.keySet().iterator(); while (iter.hasNext()) { String key = (String) iter.next(); Element choice = e.addElement("choice"); choice.addElement("display").addText(key); choice.addElement("code").addText((String) props.get(key)); } //return e; } public void actionPerformed(ActionEvent ae) { Object src = ae.getSource(); if (src == delEntry) { deleteRow(); } else if (src == addItem) { if (itemValue.getText().length() > 0 && displayName.getText().length() > 0) { props.put(displayName.getText(), itemValue.getText()); displayName.setText(""); itemValue.setText(""); propModel.requestRefresh(); } } else if (src == editEntry) { int i = propertyTable.getSelectedRow(); displayName.setText((String) propertyTable.getValueAt(i, 0)); itemValue.setText((String) propertyTable.getValueAt(i, 1)); } } //{{{ deleteRow() method private void deleteRow() { // Deletes a row from the Table: int targetRow; String keyCol; if (propertyTable.getSelectedRowCount() > 0) { targetRow = propertyTable.getSelectedRow(); keyCol = (String) propertyTable.getValueAt(targetRow, 0); props.remove(keyCol); propModel.requestRefresh(); } } //}}} private void clearForm() { globalObjName.setText(""); displayName.setText(""); itemValue.setText(""); props.clear(); } public void doSave() { this.makeResponse(); cm.saveChanges(); System.out.println(this.Title + " Saved"); // cm.addAntScript(this.makeResponse()); } //{{{ Mouse Listener Interface Implementation private void handleMouseEvent(MouseEvent evt) { if (evt.isPopupTrigger()) { if (popmenu.isVisible()) { popmenu.setVisible(false); } else { popmenu.show((Component) evt.getSource(), evt.getX(), evt.getY()); } } } public void mousePressed(MouseEvent evt) { handleMouseEvent(evt); } public void mouseReleased(MouseEvent evt) { handleMouseEvent(evt); } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } private JTextField globalObjName; private JTextField displayName; private JTextField itemValue; private JTable propertyTable; private PropertyModel propModel; JPopupMenu popmenu; JMenuItem delEntry; JMenuItem editEntry; private JButton addItem; // private JButton cmdSave; // private JButton cmdCancel; private ConfigManager cm; private Map props; private Element globalVElement;//{{{ AppModel class private static class PropertyModel extends AbstractTableModel { /** * Constructs an AppList table model. * @param _appSet the collection of extentions and associations */ public PropertyModel(Set _appSet) { appSet = _appSet; } public int getRowCount() { return appSet.size(); } public void requestRefresh() { /* Used to refresh the table */ super.fireTableDataChanged(); } public int getColumnCount() { return 2; } public Object getValueAt(int r, int c) { Iterator iter = appSet.iterator(); int iCurrentRow = 0; while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); if (iCurrentRow == r) switch (c) { case 0: return entry.getKey(); case 1: return entry.getValue(); } iCurrentRow++; } return "no value dude"; } public String getColumnName(int c) { return (c == 0) ? "Name" : "Value"; } private Set appSet; } //}}}}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -