xmlbasiclistpanel.java
来自「jawe的最新版本,基于Java的图形化工作流编辑器。图形化工作流编辑器 。使用」· Java 代码 · 共 521 行 · 第 1/2 页
JAVA
521 行
return; } } JaWEManager.getInstance().getXPDLElementEditor().editXPDLElement(editElement); } } }; protected Action deleteElementAction = new AbstractAction(JaWEActions.DELETE_ACTION) { public void actionPerformed(ActionEvent ae) { XMLElement deleteElement = getSelectedElement(); if (deleteElement != null) { JaWEController jc = JaWEManager.getInstance().getJaWEController(); List sel=new ArrayList(); sel.add(deleteElement.getParent()); if (jc.confirmDelete(sel, deleteElement)) { XMLCollection parent = (XMLCollection)getOwner(); jc.startUndouableChange(); parent.remove(deleteElement); jc.endUndouableChange(sel); ipc.getPanelSettings().adjustActions(); adjustActions(); } } } }; protected Action moveUpAction = new AbstractAction("MoveUp") { public void actionPerformed(ActionEvent ae) { moveItem(0); adjustActions(); } }; protected Action moveDownAction = new AbstractAction("MoveDown") { public void actionPerformed(ActionEvent ae) { moveItem(1); adjustActions(); } }; protected JList createList() { DefaultListModel listModel = new DefaultListModel(); JList l = new JList(listModel); Color bkgCol=new Color(245,245,245); if (ipc.getSettings() instanceof PanelSettings) { bkgCol=((PanelSettings)ipc.getSettings()).getBackgroundColor(); } l.setBackground(bkgCol); return l; } protected void setupList(final boolean enableEditing) { allParam.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); allParam.setAlignmentX(Component.LEFT_ALIGNMENT); allParam.setAlignmentY(Component.TOP_ALIGNMENT); final XMLCollection col = (XMLCollection) getOwner(); final boolean canRepos = JaWEManager.getInstance().getJaWEController().canRepositionElement(col, null); // mouse listener for editing on double-click and dragging list items allParam.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { // implement some action only if editing is enabled if (enableEditing && me.getClickCount() > 1) { editElementAction.actionPerformed(null); } } /** Marks the object which place within the list will be changed. */ public void mousePressed(MouseEvent me) { if (!getOwner().isReadOnly() && canRepos) { dragging = true; } movingElement = null; movingElementPosition = -1; try { movingElementPosition = allParam.getSelectedIndex(); if (movingElementPosition >= 0) { movingElement = (XMLElementView) allParam.getSelectedValue(); adjustActions(); } } catch (Exception ex) { } if (changing) { changing = false; return; } } /** Just indicates that dragging is over. */ public void mouseReleased(MouseEvent me) { dragging = false; } }); /** Changes position of object within the list. */ if (!myOwner.isReadOnly() && canRepos) { allParam.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent lse) { if (dragging && !changing) { newMovingElementPosition = -1; try { newMovingElementPosition = allParam.getSelectedIndex(); } catch (Exception ex) { } moveItem(); } adjustActions(); } }); } if (enableEditing) { allParam.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), "edit"); allParam.getActionMap().put("edit", editElementAction); allParam.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false), "delete"); allParam.getActionMap().put("delete", deleteElementAction); } if (!getOwner().isReadOnly() && canRepos) { allParam.setToolTipText(ResourceManager.getLanguageDependentString("MessageDragItemToChangeItsPosition")); } } protected void fillListContent(List elementsToShow) { // fills list DefaultListModel listModel = (DefaultListModel) allParam.getModel(); Iterator it = elementsToShow.iterator(); while (it.hasNext()) { XMLElement elem = (XMLElement) it.next(); XMLElementView ev = getRow(elem); listModel.addElement(ev); } } protected XMLElementView getRow(XMLElement el) { // if (el instanceof XMLComplexElement) { return new XMLElementView(ipc, el, XMLElementView.TONAME); // } else { // return new XMLElementView( el, XMLElementView.TOVALUE); // } } protected JPanel createToolbar() { JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); JButton buttonNew = PanelUtilities.createToolbarButton(ipc.getSettings(), newElementAction); buttonNew.setRolloverEnabled(true); JButton buttonEdit = PanelUtilities.createToolbarButton(ipc.getSettings(), editElementAction); buttonEdit.setRolloverEnabled(true); JButton buttonDelete = PanelUtilities.createToolbarButton(ipc.getSettings(), deleteElementAction); buttonDelete.setRolloverEnabled(true); panel.add(buttonNew); panel.add(Box.createRigidArea(new Dimension(3, 3))); panel.add(buttonEdit); panel.add(Box.createRigidArea(new Dimension(3, 3))); panel.add(buttonDelete); panel.add(Box.createHorizontalGlue()); return panel; } protected JPanel createArrowPanel() { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); XMLCollection col = (XMLCollection) getOwner(); boolean canRepos = JaWEManager.getInstance().getJaWEController().canRepositionElement(col, null); JButton buttonUp = new JButton(); buttonUp.setIcon(ipc.getPanelSettings().getArrowUpImageIcon()); buttonUp.setPreferredSize(new Dimension(16, 16)); buttonUp.setEnabled(!myOwner.isReadOnly() && canRepos); buttonUp.addActionListener(moveUpAction); JButton buttonDown = new JButton(); buttonDown.setIcon(ipc.getPanelSettings().getArrowDownImageIcon()); buttonDown.setPreferredSize(new Dimension(16, 16)); buttonDown.setEnabled(!myOwner.isReadOnly() && canRepos); buttonDown.addActionListener(moveDownAction); p.add(buttonUp); p.add(Box.createVerticalGlue()); p.add(buttonDown); return p; } protected void adjustActions() { JaWEController jc = JaWEManager.getInstance().getJaWEController(); XMLElement selEl=getSelectedElement(); newElementAction.setEnabled(jc.canCreateElement((XMLCollection) getOwner())); editElementAction.setEnabled((selEl != null && XMLUtil.getPackage(selEl)!=null)); deleteElementAction.setEnabled((selEl != null && jc.canRemoveElement((XMLCollection)getOwner(), selEl))); boolean canRepos = JaWEManager.getInstance().getJaWEController().canRepositionElement((XMLCollection) getOwner(), null); moveUpAction.setEnabled(selEl != null && allParam.getSelectedIndex() > 0 && canRepos); moveDownAction.setEnabled(selEl != null && allParam.getSelectedIndex() < allParam.getModel().getSize() - 1 && canRepos); } public void xmlElementChanged(XMLElementChangeInfo info) { if (info.getAction() == XMLElementChangeInfo.REMOVED) { Iterator it = info.getChangedSubElements().iterator(); while (it.hasNext()) { XMLElement el = (XMLElement) it.next(); removeElement(el); } } else if (info.getAction() == XMLElementChangeInfo.INSERTED) { Iterator it = info.getChangedSubElements().iterator(); while (it.hasNext()) { XMLElement el = (XMLElement) it.next(); addElement(el); } } } public void addElement(XMLElement el) { DefaultListModel listModel = (DefaultListModel) allParam.getModel(); XMLElementView ev = getRow(el); listModel.addElement(ev); } public void removeElement(XMLElement el) { DefaultListModel listModel = (DefaultListModel) allParam.getModel(); XMLElementView ev = getRow(el); if (ev != null) listModel.removeElement(ev); } public void cleanup() { myOwner.removeListener(this); allParam = null; } public boolean isEmpty () { return allParam.getModel().getSize()==0; } public boolean validateEntry () { if (isEmpty() && getOwner().isRequired() && !getOwner().isReadOnly()) { XMLBasicPanel.defaultErrorMessage(this.getWindow(),getTitle()+": "); allParam.requestFocus(); return false; } return true; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?