📄 xmlbasiclistpanel.java
字号:
package org.enhydra.jawe.base.panel.panels;import java.awt.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.event.ActionEvent;import java.awt.event.KeyEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.DefaultListModel;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JList;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.KeyStroke;import javax.swing.ListSelectionModel;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import org.enhydra.jawe.JaWEManager;import org.enhydra.jawe.ResourceManager;import org.enhydra.jawe.base.controller.JaWEActions;import org.enhydra.jawe.base.controller.JaWEController;import org.enhydra.jawe.base.editor.StandardXPDLElementEditor;import org.enhydra.jawe.base.panel.InlinePanel;import org.enhydra.jawe.base.panel.PanelSettings;import org.enhydra.shark.xpdl.XMLCollection;import org.enhydra.shark.xpdl.XMLElement;import org.enhydra.shark.xpdl.XMLElementChangeInfo;import org.enhydra.shark.xpdl.XMLElementChangeListener;import org.enhydra.shark.xpdl.XMLUtil;/** * Creates a list panel. * * @author Sasa Bojanic * @author Zoran Milakovic * @author Miroslav Popov * */public class XMLBasicListPanel extends XMLBasicPanel implements XMLElementChangeListener { protected static Dimension minimalDimension = new Dimension(250, 60); protected static Dimension listDimension = new Dimension(450, 150); /** * Object which we are replacing from one place to another within the list by dragging it. */ protected XMLElementView movingElement; /** * Index of the object which we are replacing from one place to another within the list by * dragging it. */ protected int movingElementPosition; /** * The new index of the object which we are replacing from one place to another within the list * by dragging it. */ protected int newMovingElementPosition; /** Indicates if object is being dragged. */ protected boolean dragging = false; /** * Indicates if the code for changing object position within the list is executed. */ protected boolean changing = false; protected JList allParam; protected JPanel toolbox; protected InlinePanel ipc; public XMLBasicListPanel(InlinePanel ipc, XMLCollection myOwner, List elementsToShow, String title, boolean hasBorder, boolean hasEmptyBorder, final boolean enableEditing, boolean minDimension) { super(ipc, myOwner, title, true, hasBorder, hasEmptyBorder); this.ipc=ipc; myOwner.addListener(this); myOwner.setNotifyListeners(true); allParam = createList(); setupList(enableEditing); fillListContent(elementsToShow); JScrollPane scrollParam = new JScrollPane(); scrollParam.setAlignmentX(Component.LEFT_ALIGNMENT); //scrollParam.setAlignmentY(Component.TOP_ALIGNMENT); scrollParam.setViewportView(allParam); if (!minDimension) { scrollParam.setPreferredSize(new Dimension(listDimension)); } else { scrollParam.setPreferredSize(new Dimension(minimalDimension)); } toolbox = createToolbar(); JPanel paneAndArrows = new JPanel(); paneAndArrows.setLayout(new BoxLayout(paneAndArrows, BoxLayout.X_AXIS)); paneAndArrows.add(scrollParam);// JPanel p = createArrowPanel();// paneAndArrows.add(Box.createRigidArea(new Dimension(5, 0)));// paneAndArrows.add(p); add(toolbox); add(Box.createVerticalStrut(3)); add(paneAndArrows); adjustActions(); } public boolean isItemChangingPosition() { return (changing || dragging); } public JList getList() { return allParam; } public XMLElement getSelectedElement() { if (allParam.getSelectedIndex() == -1) return null; return ((XMLElementView) allParam.getSelectedValue()).getElement(); } public boolean setSelectedElement(XMLElement el) { int selIndex = -1; XMLElementView ev = getRow(el); for (int i = 0; i < allParam.getModel().getSize(); i++) { XMLElementView elat = (XMLElementView) allParam.getModel().getElementAt(i); if (ev.equals(elat)) { selIndex = i; break; } } if (selIndex != -1) { allParam.setSelectedIndex(selIndex); } return (selIndex!=-1); } protected void moveItem(int upOrDown) { newMovingElementPosition = movingElementPosition; if (newMovingElementPosition == -1) { return; } else if (upOrDown == 0) { newMovingElementPosition--; } else { newMovingElementPosition++; } moveItem(); } protected void moveItem() { changing = true; DefaultListModel listModel = (DefaultListModel) allParam.getModel(); XMLCollection owncol = (XMLCollection) getOwner(); int rowCnt = listModel.getSize(); if (movingElement == null || movingElementPosition == -1 || newMovingElementPosition == -1 || newMovingElementPosition == movingElementPosition || (rowCnt - 1) < movingElementPosition || (rowCnt - 1) < newMovingElementPosition || !owncol.contains(movingElement.getElement())) { changing = false; return; } XMLCollection col = (XMLCollection) getOwner(); if (JaWEManager.getInstance().getJaWEController().canRepositionElement(col, movingElement.getElement())) { XMLElement currentElementAtPosition = ((XMLElementView) listModel.getElementAt(newMovingElementPosition)) .getElement(); int newpos = owncol.indexOf(currentElementAtPosition); listModel.remove(movingElementPosition); listModel.add(newMovingElementPosition, movingElement); JaWEController jc = JaWEManager.getInstance().getJaWEController(); jc.startUndouableChange(); owncol.reposition(movingElement.getElement(), newpos); List toSelect = new ArrayList(); toSelect.add(movingElement.getElement()); jc.endUndouableChange(toSelect); try { allParam.setSelectedIndex(newMovingElementPosition); } catch (Exception ex) { } movingElementPosition = newMovingElementPosition; } changing = false; } protected Action newElementAction = new AbstractAction(JaWEActions.NEW_ACTION) { public void actionPerformed(ActionEvent ae) { JaWEController jc = JaWEManager.getInstance().getJaWEController(); XMLCollection col = (XMLCollection) getOwner(); XMLElement newEl = JaWEManager.getInstance().getXPDLObjectFactory().createXPDLObject(col, null, false); boolean isForModal=PanelUtilities.isForModalDialog(newEl); if (!isForModal && ipc.isModified()) { int sw=ipc.showModifiedWarning(); if(sw == JOptionPane.CANCEL_OPTION || (sw==JOptionPane.YES_OPTION && ipc.isModified())) { return; } } boolean updInProg=false; if (isForModal) { StandardXPDLElementEditor ed = new StandardXPDLElementEditor(); ed.editXPDLElement(newEl); boolean statOK=(ed.getStatus()==StandardXPDLElementEditor.STATUS_OK); boolean canIns=true; if (statOK) { canIns=jc.canInsertElement(col, newEl); } if (!statOK || !canIns) { if (!canIns) { jc.getJaWEFrame().message(ed.getLanguageDependentString("WarningCannotInsertElement"),JOptionPane.WARNING_MESSAGE); } return; } updInProg=true; } jc.startUndouableChange(); col.add(newEl); List temp = new ArrayList(); temp.add(newEl); jc.endUndouableChange(temp); if (updInProg) { setSelectedElement(newEl); } adjustActions(); } }; protected Action editElementAction = new AbstractAction(JaWEActions.EDIT_PROPERTIES_ACTION) { public void actionPerformed(ActionEvent ae) { XMLElement editElement = getSelectedElement(); if (editElement != null) { if (ipc.isModified()) { int sw=ipc.showModifiedWarning(); if( sw == JOptionPane.CANCEL_OPTION || (sw==JOptionPane.YES_OPTION && ipc.isModified())) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -