📄 svgproperties.java
字号:
/* * Created on 2 juin 2004 * ============================================= GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 =============================================GLIPS Graffiti Editor, a SVG EditorCopyright (C) 2004 Jordi SUC, Philippe Gil, SARL ITRISThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 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 ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USAContact : jordi.suc@itris.fr; philippe.gil@itris.fr ============================================= */package fr.itris.glips.svgeditor.properties;import fr.itris.glips.svgeditor.*;import fr.itris.glips.svgeditor.canvas.*;import fr.itris.glips.svgeditor.resources.*;import fr.itris.glips.svgeditor.selection.*;import javax.swing.*;import javax.swing.border.*;import java.awt.*;import java.awt.event.*;import java.util.*;import org.w3c.dom.*;import fr.itris.glips.svgeditor.menutool.*;/** * @author Jordi SUC * * the class allowing to change the properties of a node by modifying its attributes and style elements */public class SVGProperties extends SVGModuleAdapter{ /** * the ids of the module */ final private String idproperties="Properties"; /** * the labels */ private String labelproperties=""; /** * the editor */ private SVGEditor editor=null; /** * the document of the properties */ private Document docProperties=null; /** * the font */ public final Font theFont=new Font("theFont", Font.ROMAN_BASELINE, 10); /** * the nodes that are currently selected */ private final LinkedList selectedNodes=new LinkedList(); /** * the bundle used to get labels */ private ResourceBundle bundle=null; /** * the panel in which the widgets panel will be inserted */ private JPanel propertiesPanel=new JPanel(); /** * the panel displaying the properties */ private SVGPropertiesWidgetsPanel widgetsPanel=null; /** * the frame into which the properties panel will be inserted */ private SVGToolFrame propertiesFrame; /** * the name of the last selected tab */ private String tabId=""; /** * the constructor of the class * @param editor the editor */ public SVGProperties(SVGEditor editor) { this.editor=editor; //gets the labels from the resources bundle=SVGEditor.getBundle(); if(bundle!=null){ try{ labelproperties=bundle.getString("label_properties"); }catch (Exception ex){} } //a listener that listens to the changes of the SVGFrames final ActionListener svgframeListener=new ActionListener(){ /** * a listener on the selection changes */ private ActionListener selectionListener=null; /** * the current selection module */ private SVGSelection selection=null; public void actionPerformed(ActionEvent e) { //removes the widgets panel if(widgetsPanel!=null){ propertiesPanel.removeAll(); widgetsPanel.dispose(); widgetsPanel=null; } //clears the list of the selected items selectedNodes.clear(); final SVGFrame frame=getSVGEditor().getFrameManager().getCurrentFrame(); //if a selection listener is already registered on a selection module, it is removed if(selection!=null && selectionListener!=null){ selection.removeSelectionListener(selectionListener); } //gets the current selection module if(frame!=null){ selection=getSVGEditor().getSVGSelection(); } if(frame!=null && selection!=null){ manageSelection(); //the listener of the selection changes selectionListener=new ActionListener(){ public void actionPerformed(ActionEvent evt) { manageSelection(); } }; //adds the selection listener if(selectionListener!=null){ selection.addSelectionListener(selectionListener); } }else if(propertiesPanel.isVisible()){ handleProperties(null); } } /** * updates the selected items and the state of the menu items */ protected void manageSelection(){ LinkedList list=null; //gets the currently selected nodes list if(selection!=null){ list=selection.getCurrentSelection(getSVGEditor().getFrameManager().getCurrentFrame()); } selectedNodes.clear(); //refresh the selected nodes list if(list!=null){ selectedNodes.addAll(list); } if(selectedNodes.size()>=1){ if(propertiesPanel.isVisible()){ handleProperties(selectedNodes); } }else if(propertiesPanel.isVisible()){ handleProperties(null); } } }; //adds the SVGFrame change listener editor.getFrameManager().addSVGFrameChangedListener(svgframeListener); //setting the layout for the properties panel propertiesPanel.setLayout(new BoxLayout(propertiesPanel, BoxLayout.X_AXIS)); //creating the document docProperties=SVGResource.getXMLDocument("properties.xml"); docProperties=normalizeXMLProperties(docProperties); //creating the internal frame containing the properties panel propertiesFrame=new SVGToolFrame(editor, idproperties, labelproperties, propertiesPanel); //setting the visibility changes handler Runnable visibilityRunnable=new Runnable(){ public void run() { if(selectedNodes.size()>=1){ handleProperties(selectedNodes); }else{ handleProperties(null); } } }; this.propertiesFrame.setVisibilityChangedRunnable(visibilityRunnable); } /** * @return the editor */ public SVGEditor getSVGEditor(){ return editor; } @Override public Hashtable<String, JMenuItem> getMenuItems() { Hashtable<String, JMenuItem> menuItems=new Hashtable<String, JMenuItem>(); menuItems.put("ToolFrame_"+this.idproperties, propertiesFrame.getMenuItem()); return menuItems; } @Override public SVGToolFrame getToolFrame() { return propertiesFrame; } /** * @return Returns the selectedNodes. */ protected LinkedList getSelectedNodes() { return selectedNodes; } /** * @return Returns the tabId. */ protected String getTabId() { return tabId; } /** * @param tabId The tabId to set. */ protected void setTabId(String tabId) { this.tabId = tabId; } /** * the method that manages the changes of the properties for the given nodes * @param list a list of nodes */ protected void handleProperties(LinkedList list){ //removes the widgets panel if(widgetsPanel!=null){ propertiesPanel.removeAll(); widgetsPanel.dispose(); widgetsPanel=null; } final SVGFrame frame=editor.getFrameManager().getCurrentFrame(); if(frame!=null && list!=null && list.size()>0){ LinkedList snodes=new LinkedList(list); //gets the accurate subtree given the list of nodes Node treeProperties=getXMLProperties(snodes); if(treeProperties!=null){ //the map associating a tab to its label and the map associating a tab to a list of property item objects LinkedHashMap tabMap=new LinkedHashMap(), propertyItemsMap=new LinkedHashMap(); if(treeProperties!=null){ String name="", label=""; LinkedList propertyItemsList=null; //builds the list of the tabs for(Node cur=treeProperties.getFirstChild(); cur!=null; cur=cur.getNextSibling()){ if(cur.getNodeName().equals("tab")){ name=((Element)cur).getAttribute("name"); if(name!=null && ! name.equals("")){ //gets the label of the tab and puts it into the map if(bundle!=null){ try{label=bundle.getString(name);}catch (Exception ex){label=null;} } if(label==null || (label!=null && label.equals(""))){ label=name; } tabMap.put(name, label); //gets the property items list and puts it into the map propertyItemsList=getPropertyList(snodes, cur); propertyItemsMap.put(name, propertyItemsList); } } } //creates the panel if(tabMap!=null && propertyItemsMap!=null && tabMap.size()>0 && propertyItemsMap.size()>0){ if(widgetsPanel!=null){ widgetsPanel.dispose(); } widgetsPanel=new SVGPropertiesWidgetsPanel(this, tabMap, propertyItemsMap); } //adds the property panel into the container and displays it if(propertiesPanel!=null && widgetsPanel!=null){ propertiesPanel.removeAll(); propertiesPanel.add(widgetsPanel); propertiesFrame.revalidate(); return; } } } } if(bundle!=null){ //initializes the value of the last selected tab tabId=""; String message=""; try{ if(selectedNodes.size()<1){ message=bundle.getString("property_empty_dialog_none"); }else if(selectedNodes.size()==1){ message=bundle.getString("property_empty_dialog_one"); }else if(selectedNodes.size()>1){ message=bundle.getString("property_empty_dialog_many"); } }catch (Exception ex){} JLabel label=new JLabel(message); label.setBorder(new EmptyBorder(5, 5, 5, 5)); label.setFont(theFont); propertiesPanel.removeAll(); propertiesPanel.add(label); propertiesFrame.revalidate(); } } /** * normalizes the xml document * @param doc the raw xml document * @return the normalized document */ public Document normalizeXMLProperties(Document doc){ //modifies the document to resolve the links within the dom //each tab node is appended to the node which have declared having a child whose type is like one of the predefined tabs if(doc!=null){ Node root=doc.getDocumentElement(); if(root!=null){ //the map associating the name attributes of a tab to its tab node Hashtable tabMap=new Hashtable(); //the list of the "define" nodes LinkedList defineList=new LinkedList(); //finds the node that contains the predefined node tabs, and adds all its children to the tab map Node cur=null, tab=null; String name=""; for(cur=root.getFirstChild(); cur!=null; cur=cur.getNextSibling()){ if(cur.getNodeName().equals("define")){ //adds the "define" node to the list
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -