📄 svgvisualresourcelistspanel.java
字号:
/* * Created on 26 août 2004 * ============================================= GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 ============================================= GLIPS Graffiti Editor, a SVG Editor Copyright (C) 2003 Jordi SUC, Philippe Gil, SARL ITRIS This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact : jordi.suc@itris.fr; philippe.gil@itris.fr ============================================= */package fr.itris.glips.svgeditor.visualresources;import java.awt.*;import java.awt.datatransfer.*;import java.awt.dnd.*;import java.awt.event.*;import java.io.*;import java.util.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import javax.swing.plaf.metal.*;import org.w3c.dom.*;import fr.itris.glips.svgeditor.*;import fr.itris.glips.svgeditor.canvas.*;import fr.itris.glips.svgeditor.undoredo.*;import fr.itris.glips.svgeditor.resources.*;/** * the class of the panel displayed in the dialog * * @author Jordi SUC */public class SVGVisualResourceListsPanel extends JPanel{ /** * the constant describing the creation of a new resource */ private static final int RESOURCE_NEW=0; /** * the constant describing the modification of a resource */ private static final int RESOURCE_MODIFIED=1; /** * the constant describing the suppression of a resource */ private static final int RESOURCE_DELETED=2; /** * the map associating the name of a model to a visual resource models */ private final Map vresourceModels=Collections.synchronizedMap(new LinkedHashMap()); /** * the tab panel */ private JTabbedPane tabPanel=null; /** * a small font */ private static final Font smallFont=new Font("smallFont", Font.ROMAN_BASELINE, 9); /** * the font */ private static final Font theFont=new Font("theFont", Font.ROMAN_BASELINE, 10); /** * the runnables enabling to dispose this panel */ private final LinkedList<Runnable> disposers=new LinkedList<Runnable>(); /** * the listener to the changes of the selection of the tabs */ private ChangeListener changeListener=null; /** * the visual resources module */ private SVGVisualResources visualResources=null; /** * the map associating the type of a resource to a JList */ private Map listMap=Collections.synchronizedMap(new Hashtable()); /** * the map associating the id of a resource to its list item */ private Map itemListMap=Collections.synchronizedMap(new Hashtable()); /** * the cell renderer */ private ListCellRenderer listCellRenderer=new SVGVisualResourcesListCellRenderer(); /** * the resource state object */ private SVGVisualResourceState resourceState=null; /** * the map associating the id of a resource to the panel representing this resource in the list */ private Map<SVGVisualResourceObject, JComponent> cellPanels=Collections.synchronizedMap( new HashMap<SVGVisualResourceObject, JComponent>()); /** * the current frame */ private SVGFrame frame=null; /** * the constructor of the class * @param visualResources the visual resources module * @param vresourceModels the list of the visual resource items */ public SVGVisualResourceListsPanel(SVGVisualResources visualResources, LinkedList vresourceModels){ this.visualResources=visualResources; this.frame=visualResources.getSVGEditor().getFrameManager().getCurrentFrame(); this.resourceState=visualResources.getResourceState(frame); //fills the map of the resource models if(vresourceModels!=null){ SVGVisualResourceModel model=null; for(Iterator it=vresourceModels.iterator(); it.hasNext();){ model=(SVGVisualResourceModel)it.next(); if(model!=null){ this.vresourceModels.put(model.getName(), model); } } } setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); //getting the tab panel tabPanel=createTabbedPane(); if(tabPanel!=null){ //the listener to the changes of the tab changeListener=new ChangeListener(){ public void stateChanged(ChangeEvent arg0) { if(tabPanel!=null){ resourceState.setSelectedTabId(tabPanel.getTitleAt(tabPanel.getSelectedIndex())); } } }; tabPanel.addChangeListener(changeListener); if(resourceState!=null) { setSelectedTab(resourceState.getSelectedTabId()); } add(tabPanel); } setBorder(new EmptyBorder(0, 0, 1, 0)); } /** * @return Returns the visualResources. */ protected SVGVisualResources getVisualResources() { return visualResources; } /** * removes all the listeners */ public void dispose(){ if(tabPanel!=null && changeListener!=null){ //removes the change listener tabPanel.removeChangeListener(changeListener); //runs all the disposers Runnable disposer=null; for(Iterator it=disposers.iterator(); it.hasNext();){ try{disposer=(Runnable)it.next();}catch(Exception ex){disposer=null;} if(disposer!=null){ disposer.run(); } } //clears the maps vresourceModels.clear(); disposers.clear(); listMap.clear(); itemListMap.clear(); for(SVGVisualResourceObject obj : cellPanels.keySet()){ JComponent cmp=cellPanels.get(obj); cmp.removeAll(); } cellPanels.clear(); tabPanel.removeAll(); frame=null; removeAll(); } } /** * refreshes the resource objects and the lists containing them * @param type the type of the action that has triggered this action to be called * @param resourceType the type of the resource * @param currentElement the resource element that is currently used * @param oldElement a resource element that has been removed or modified */ public void refreshResources(int type, String resourceType, Element currentElement, Element oldElement){ if(resourceType!=null && ! resourceType.equals("")){ //getting the map associating the id of a resource to the resource node LinkedList resourcesNames=new LinkedList(); resourcesNames.add(resourceType); String resourceId="", oldResourceId=""; SVGVisualResourceModel model=(SVGVisualResourceModel)vresourceModels.get(resourceType); SVGResourceImageManager resImgManager=frame.getSVGEditor().getResourceImageManager(); SVGVisualResourceObject resObj=null; if(model!=null){ //retrieving the list corresponding to the model JList jList=(JList)listMap.get(model.getName()); DefaultListModel listModel=null; if(jList!=null){ listModel=((DefaultListModel)jList.getModel()); } if(listModel!=null){ if(type==RESOURCE_NEW && currentElement!=null){ resourceId=currentElement.getAttribute("id"); if(! resourceId.equals("")){ //creates a new resource object resObj=model.createVisualResourceObject(currentElement); //creates the list item SVGVisualResourceListItem item=new SVGVisualResourceListItem(frame, resObj); itemListMap.put(resourceId, item); //adding the item to the list listModel.insertElementAt(item, 0); jList.setSelectedIndex(0); } }else if(type==RESOURCE_DELETED && oldElement!=null){ 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 list item linked with the resource element item=(SVGVisualResourceListItem)itemListMap.get(oldResourceId); if(item!=null){ //removes the item for the JList listModel.removeElement(item); } //removes the item itemListMap.remove(oldResourceId); if(listModel.size()>0){ jList.setSelectedIndex(0); } }else if(type==RESOURCE_MODIFIED && currentElement!=null && oldElement!=null){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -