📄 svgvisualresourcelistspanel.java
字号:
newBt.setMargin(buttonInsets); duplicateBt.setMargin(buttonInsets); deleteBt.setMargin(buttonInsets); importBt.setMargin(buttonInsets); propBt.setMargin(buttonInsets); duplicateBt.setEnabled(false); deleteBt.setEnabled(false); importBt.setEnabled(false); propBt.setEnabled(false); //the panel containing the buttons JPanel buttons=new JPanel(); buttons.setLayout(new FlowLayout(FlowLayout.RIGHT)); buttons.add(newBt); buttons.add(duplicateBt); buttons.add(propBt); buttons.add(importBt); buttons.add(deleteBt); //the selection listener final ListSelectionListener listSelectionListener=new ListSelectionListener(){ public void valueChanged(ListSelectionEvent e) { SVGVisualResourceListItem item=null; SVGVisualResourceObject resObj=null; //getting the list item if(list.getModel().getSize()>0){ try{ item=(SVGVisualResourceListItem)list.getSelectedValue(); }catch (Exception ex){} } //enables or disables the buttons if(item!=null){ //sets the new current item name if(resObj!=null){ resourceState.setSelectedItemId(resObj.getResourceModel().getName(), resObj.getResourceId()); } duplicateBt.setEnabled(false); duplicateBt.setIcon(duplDisIcon); deleteBt.setEnabled(false); deleteBt.setIcon(delDisIcon); importBt.setEnabled(false); importBt.setIcon(impDisIcon); propBt.setEnabled(false); propBt.setIcon(propDisIcon); resObj=item.getVisualResourceObject(); if(resObj!=null && resObj.canBeModified()){ duplicateBt.setEnabled(true); duplicateBt.setIcon(duplIcon); deleteBt.setEnabled(true); deleteBt.setIcon(delIcon); propBt.setEnabled(true); propBt.setIcon(propIcon); }else if(resObj!=null && ! resObj.canBeModified()){ importBt.setEnabled(true); importBt.setIcon(impIcon); } } } }; //the listener to the new button final ActionListener newBtListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { createNewResource(defs, fvresourceModel); } }; //the listener to the duplicate button final ActionListener duplicateBtListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { SVGVisualResourceListItem item=(SVGVisualResourceListItem)list.getSelectedValue(); if(item!=null){ duplicateResource(item.getVisualResourceObject()); } } }; final String fdeleteMessage=deleteMessage, fdeleteTitle=deleteTitle; //the listener to the delete button final ActionListener deleteBtListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { SVGVisualResourceListItem item=(SVGVisualResourceListItem)list.getSelectedValue(); SVGVisualResourceObject resObj= item.getVisualResourceObject(); //if the resource is not used by shapes on the canvas if(resObj!=null && ! frame.isResourceUsed(resObj.getResourceId())) { int returnVal=JOptionPane.showConfirmDialog(SVGEditor.getParent(), fdeleteMessage, fdeleteTitle, JOptionPane.YES_NO_OPTION); if(returnVal==JOptionPane.YES_OPTION){ removeResource(resObj); } }else{ //if the resource is used by other elements JOptionPane.showMessageDialog(SVGEditor.getParent(), fcantDeleteMessage, ferrorTitle, JOptionPane.ERROR_MESSAGE); } } }; //the listener to the import button final ActionListener importBtListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { SVGVisualResourceListItem item=(SVGVisualResourceListItem)list.getSelectedValue(); SVGVisualResourceObject resObj=null; if(frame!=null && defs!=null && item!=null){ resObj=item.getVisualResourceObject(); //exports the resource node to the "defs" node if it is contained in the resource store if(resObj!=null){ importResource(defs, resObj); } } } }; //the listener to the properties button final ActionListener propBtListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { SVGVisualResourceListItem item=(SVGVisualResourceListItem)list.getSelectedValue(); SVGVisualResourceObject resObj=null; if(item!=null){ modifyProperties(item.getVisualResourceObject()); } } }; //a mouse listener to hande double clicks final MouseListener doubleClickOnListListener=new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount()==2) { propBt.doClick(); } } }; list.addMouseListener(doubleClickOnListListener); //adds the listener to the "new" button newBt.addActionListener(newBtListener); //adds the listener to the "duplicate" button duplicateBt.addActionListener(duplicateBtListener); //adds the listener to the "delete" button deleteBt.addActionListener(deleteBtListener); //adds the listener to the "import" button importBt.addActionListener(importBtListener); //adds the listener to the "properties" button propBt.addActionListener(propBtListener); //adds the listener to the list selection list.addListSelectionListener(listSelectionListener); disposers.add(new Runnable(){ public void run() { newBt.removeActionListener(newBtListener); duplicateBt.removeActionListener(duplicateBtListener); deleteBt.removeActionListener(deleteBtListener); importBt.removeActionListener(importBtListener); propBt.removeActionListener(propBtListener); list.removeListSelectionListener(listSelectionListener); list.removeMouseListener(doubleClickOnListListener); } }); //sets the selected index for the list if(selectedIndex>=0){ list.setSelectedIndex(selectedIndex); }else{ list.setSelectedIndex(0); } //adds the widgets panel.add(scpanel, BorderLayout.CENTER); panel.add(buttons, BorderLayout.SOUTH); return panel; } /** * creates a new resource node * @param parentElement the parent of the created resource * @param vresourceModel a resource model */ protected void createNewResource(Element parentElement, SVGVisualResourceModel vresourceModel){ if(frame!=null && parentElement!=null && vresourceModel!=null){ final Element fparentElement=parentElement; final String name=vresourceModel.getName(); String shapeId=""; //if the resource contains shape nodes as children, the id of the shape node is returned by a chooser if(vresourceModel.isShapedResource()){ shapeId=SVGVisualResourceShapeIdChooser.showShapeChooserIdDialog(frame); } if(! vresourceModel.isShapedResource() || (vresourceModel.isShapedResource() && shapeId!=null && ! shapeId.equals(""))){ final String fshapeId=shapeId; frame.enqueue(new Runnable(){ public void run() { //creating the new resource node final Element newElement=getVisualResources().getVisualResourcesToolkit().createVisualResource(frame, fparentElement, name, fshapeId); if(newElement!=null){ final String id=newElement.getAttribute("id"); //appending the newly created resource node to its parent node getVisualResources().getVisualResourcesToolkit().appendVisualResource(frame, fparentElement, newElement); //create the undo/redo action and insert it into the undo/redo stack if(getVisualResources().getSVGEditor().getUndoRedo()!=null){ SVGUndoRedoAction action=new SVGUndoRedoAction(getVisualResources().undoredoresourcesnew){ public void undo(){ getVisualResources().getVisualResourcesToolkit().removeVisualResource(frame, newElement); resourceState.setSelectedItemId(name, ""); refreshResources(RESOURCE_DELETED, name, null, newElement); } public void redo(){ getVisualResources().getVisualResourcesToolkit().appendVisualResource(frame, fparentElement, newElement); resourceState.setSelectedItemId(name, id); refreshResources(RESOURCE_NEW, name, newElement, null); } }; SVGUndoRedoActionList actionlist=new SVGUndoRedoActionList(action.getName()); actionlist.add(action); getVisualResources().getSVGEditor().getUndoRedo().addActionList(frame, actionlist); } resourceState.setSelectedItemId(name, id); frame.setModified(true); refreshResources(RESOURCE_NEW, name, newElement, null); } } }); } } } /** * duplicate the resource node corresponding to the given resource object * @param resourceObject a resource object */ protected void duplicateResource(SVGVisualResourceObject resourceObject){ if(frame!=null && resourceObject!=null && resourceObject.canBeModified() && resourceObject.getParentNode()!=null){ final Element fparentElement=(Element)resourceObject.getParentNode(), resourceNode=resourceObject.getInitialNode(); final String name=resourceObject.getResourceModel().getName(); frame.enqueue(new Runnable(){ public void run() { final Element newElement=getVisualResources().getVisualResourcesToolkit().duplicateVisualResource(frame, resourceNode); if(newElement!=null){ final String id=newElement.getAttribute("id"); //appending the newly created resource node to its parent node getVisualResources().getVisualResourcesToolkit().appendVisualResource(frame, fparentElement, newElement); //create the undo/redo action and insert it into the undo/redo stack if(getVisualResources().getSVGEditor().getUndoRedo()!=null){ SVGUndoRedoAction action=new SVGUndoRedoAction(getVisualResources().undoredoresources){ public void undo(){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -