📄 svgvisualresourcelistspanel.java
字号:
int itemIndex=0; SVGVisualResourceListItem item=null; //invalidating the old resource representation oldResourceId=oldElement.getAttribute("id"); if(oldResourceId!=null && ! oldResourceId.equals("")){ resImgManager.invalidateResourceRepresentation(frame, oldResourceId); } //removes the resource object linked with the old element model.removeVisualResourceObject(oldResourceId); //getting the old list item linked with the resource element item=(SVGVisualResourceListItem)itemListMap.get(oldResourceId); if(item!=null){ //retrieving the index of the list item of the old element that will be removed itemIndex=listModel.indexOf(item); //removes the old item for the JList listModel.removeElement(item); } //removes the old item itemListMap.remove(oldResourceId); //the new resource id resourceId=currentElement.getAttribute("id"); if(! resourceId.equals("")){ //creates a new resource object resObj=model.createVisualResourceObject(currentElement); //creates the list item item=new SVGVisualResourceListItem(frame, resObj); itemListMap.put(resourceId, item); //adding the item to the list listModel.insertElementAt(item, itemIndex); jList.setSelectedIndex(itemIndex); } } } } } visualResources.getSVGEditor().getSVGToolkit().forceReselection(); } /** * removes the cell panel representing the given resource object * @param resObj a resource object */ protected void removeCellPanel(SVGVisualResourceObject resObj){ if(resObj!=null){ JPanel panel=(JPanel)cellPanels.get(resObj); if(panel!=null){ if(panel.getParent()!=null){ panel.getParent().remove(panel); } panel.removeAll(); } cellPanels.remove(resObj); } } /** * removes all the cell panels and disposes them */ protected void removeAllCellPanels(){ JPanel panel=null; for(Iterator it=new LinkedList(cellPanels.values()).iterator(); it.hasNext();){ panel=(JPanel)it.next(); if(panel!=null){ if(panel.getParent()!=null){ panel.getParent().remove(panel); } panel.removeAll(); } } cellPanels.clear(); } /** * sets the selected tab * @param name the tab to be selected */ protected void setSelectedTab(String name){ if(tabPanel!=null){ for(int i=0;i<tabPanel.getTabCount();i++){ if(name!=null && name.equals(tabPanel.getTitleAt(i))){ tabPanel.setSelectedIndex(i); } } } } /** * @return a JTabbedPane containing the widgets allowing to change the values of the visual resources */ protected JTabbedPane createTabbedPane(){ JTabbedPane tabbedPanel=new JTabbedPane(); tabbedPanel.setFont(theFont); //creates the tabs that will be contained in the tabbed panel SVGVisualResourceModel model=null; JPanel panel=null; Iterator it; for(it=new LinkedList(vresourceModels.values()).iterator(); it.hasNext();){ try{ model=(SVGVisualResourceModel)it.next(); }catch (Exception ex){model=null;} if(model!=null){ panel=createTabPanel(model); tabbedPanel.addTab(model.getTabName(), panel); } } return tabbedPanel; } /** * @param vresourceModel a visual resource model * @return a JPanel containing the widgets allowing to modify the visual resources */ protected JPanel createTabPanel(SVGVisualResourceModel vresourceModel){ final Element defs=getVisualResources().getDefs(frame); //the finalised variable final SVGVisualResourceModel fvresourceModel=vresourceModel; //the panel containing the scrollpane JPanel panel=new JPanel(); panel.setLayout(new BorderLayout()); //creates the list of items that will be displayed in the list widget final DefaultListModel listModel=new DefaultListModel(); SVGVisualResourceObject resObj=null; LinkedList resourceObjects=vresourceModel.getResourceObjectsList(); SVGVisualResourceListItem item=null; int i=0, selectedIndex=-1; for(Iterator it=resourceObjects.iterator(); it.hasNext();){ //gets the id and the index for the list item try{ resObj=(SVGVisualResourceObject)it.next(); }catch (Exception ex){resObj=null;} if(resObj!=null){ item=new SVGVisualResourceListItem(frame, resObj); itemListMap.put(resObj.getResourceId(), item); listModel.addElement(item); } } //the list and the scrollpane final JList list=new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setVisibleRowCount(8); list.setFont(theFont); //adding the list to the map listMap.put(vresourceModel.getName(), list); /*********************adding the drag and drop support**************************/ /*//adding a drag gesture listener to the color panel final DragGestureListener dragGestureListener=new DragGestureListener(){ public void dragGestureRecognized(DragGestureEvent evt) { int selectedIndex=list.locationToIndex(evt.getDragOrigin()); final Object obj=list.getModel().getElementAt(selectedIndex); list.setSelectedIndex(selectedIndex); if(obj!=null){ final String resourceId=((SVGVisualResourceListItem)obj).getVisualResourceObject().getResourceId(); //the transferable final Transferable transferable=new Transferable(){ public Object getTransferData(DataFlavor df) throws UnsupportedFlavorException, IOException { if(df!=null && df.isMimeTypeEqual(DataFlavor.stringFlavor)){ return resourceId; } return null; } public DataFlavor[] getTransferDataFlavors() { DataFlavor[] dfs=new DataFlavor[1]; dfs[0]=DataFlavor.stringFlavor; return dfs; } public boolean isDataFlavorSupported(DataFlavor df) { if(df!=null && df.isMimeTypeEqual(DataFlavor.stringFlavor)){ return true; } return false; } }; SVGVisualResourceObject res=((SVGVisualResourceListItem)obj).getVisualResourceObject(); if(res.canBeModified()){ Image cursorImage=getVisualResources().getSVGEditor().getResourceImageManager().getImage(frame, res.getResourceId(), false); DragSource dragSource=SVGEditor.getSVGEditor().getDragSource(); Cursor cursor=SVGEditor.getSVGEditor().getSVGToolkit().createCursorFromImage(cursorImage); dragSource.startDrag(evt, cursor, transferable, null); evt.getTriggerEvent().consume(); } } } }; //adding a drag gesture tokenizer to this component final DragGestureRecognizer dragGestureRecognizer=getVisualResources().getSVGEditor().getDragSource(). createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_COPY, dragGestureListener); disposers.add(new Runnable(){ public void run() { dragGestureRecognizer.removeDragGestureListener(dragGestureListener); dragGestureRecognizer.setComponent(null); list.setDropTarget(null); } });*/ /******************************************************************************/ //setting the list cell renderer list.setCellRenderer(listCellRenderer); //the scroll pane in which the list will be inserted JScrollPane scpanel=new JScrollPane(list); //the labels for the buttons String newLabel="", duplicateLabel="", deleteLabel="", importLabel="", propLabel="", deleteMessage="", deleteTitle="", errorTitle="", cantDeleteMessage=""; ResourceBundle bundle=SVGEditor.getBundle(); if(bundle!=null){ newLabel=bundle.getString("labelnew"); duplicateLabel=bundle.getString("labelduplicate"); deleteLabel=bundle.getString("labeldelete"); importLabel=bundle.getString("labelimport"); propLabel=bundle.getString("labelproperties"); deleteMessage=bundle.getString("vresource_deleteresourcemessage"); deleteTitle=bundle.getString("labeldelete"); errorTitle=bundle.getString("labelerror"); cantDeleteMessage=bundle.getString("vresource_cantdeleteresource"); } final String ferrorTitle=errorTitle, fcantDeleteMessage=cantDeleteMessage; final ImageIcon newIcon=SVGResource.getIcon("New", false), duplIcon=SVGResource.getIcon("Duplicate", false), duplDisIcon=SVGResource.getIcon("Duplicate", true), delIcon=SVGResource.getIcon("Delete", false), delDisIcon=SVGResource.getIcon("Delete", true), impIcon=SVGResource.getIcon("Import", false), impDisIcon=SVGResource.getIcon("Import", true), propIcon=SVGResource.getIcon("Properties", false), propDisIcon=SVGResource.getIcon("Properties", true); //the buttons used to make actions on the resources contained in the tab final JButton newBt=new JButton(newIcon), duplicateBt=new JButton(duplDisIcon), deleteBt=new JButton(delDisIcon), importBt=new JButton(impDisIcon), propBt=new JButton(propDisIcon); //the tool tips newBt.setToolTipText(newLabel); duplicateBt.setToolTipText(duplicateLabel); deleteBt.setToolTipText(deleteLabel); importBt.setToolTipText(importLabel); propBt.setToolTipText(propLabel); Insets buttonInsets=new Insets(1, 1, 1, 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -