⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svgvisualresourcevectorcirclechooserattributewidget.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * 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 javax.swing.*;import java.util.*;import java.awt.*;import java.awt.event.*;import java.awt.geom.*;import javax.swing.border.*;import javax.swing.event.*;import fr.itris.glips.svgeditor.*;/** * the class of the widgets that will be displayed in the properties dialog, and enabling to modify the properties * of an attribute (or a group of attributes) of a resource node. *  * @author Jordi SUC */public class SVGVisualResourceVectorCircleChooserAttributeWidget extends SVGVisualResourceAttributeWidget{	/**	 * the constructor of the class	 * @param resourceObjectAttribute the attribute object that will be modified	 */    public SVGVisualResourceVectorCircleChooserAttributeWidget(SVGVisualResourceObjectAttribute resourceObjectAttribute) {        super(resourceObjectAttribute);                buildComponent();    }        /**     * builds the component to be displayed     */    protected void buildComponent(){                if(resourceObjectAttribute!=null){            final SVGEditor svgEditor=resourceObjectAttribute.getModel().getVisualResources().getSVGEditor();            final String type=resourceObjectAttribute.getModel().getType();                        //getting the attributes//            SVGVisualResourceObjectAttribute 	px1Att=null, py1Att=null, px2Att=null, py2Att=null, radiusAtt=null,             														gradientUnitsAtt=null, att=null;                        final String gradientUnitsOther="userSpaceOnUse";            String nm="";                        for(Iterator it=resourceObjectAttribute.getGroupAttributes().iterator();it.hasNext();){                                try{                    att=(SVGVisualResourceObjectAttribute)it.next();                }catch (Exception ex){att=null;}                                if(att!=null){                                        nm=att.getModel().getName();                                        if(nm.equals("x1")){                                                px1Att=att;                                            }else if(nm.equals("cx")){                                                px1Att=att;                                            }else if(nm.equals("y1")){                                                py1Att=att;                                            }else if(nm.equals("cy")){                                                py1Att=att;                                            }else if(nm.equals("x2")){                                                px2Att=att;                                            }else if(nm.equals("fx")){                                                px2Att=att;                                            }else if(nm.equals("y2")){                                                py2Att=att;                                            }else if(nm.equals("fy")){                                                py2Att=att;                                            }else if(nm.equals("r")){                                                radiusAtt=att;                                            }else if(nm.equals("gradientUnits")){                                                gradientUnitsAtt=att;                    }                }            }                        final SVGVisualResourceObjectAttribute 	fpx1Att=px1Att, fpy1Att=py1Att, fpx2Att=px2Att, fpy2Att=py2Att, 																			fradiusAtt=radiusAtt, fgradientUnitsAtt=gradientUnitsAtt;                        //getting the points value//            Point2D.Double point1=new Point2D.Double(0, 0), point2=new Point2D.Double(0, 0);            double radius=0;            Point2D.Double defPoint1=new Point2D.Double(0, 0), defPoint2=new Point2D.Double(0, 0);            double defRadius=0;                        Point2D.Double otherPoint1=new Point2D.Double(0, 0), otherPoint2=new Point2D.Double(0, 0);            double otherRadius=0;            //the object containing the values for this chooser            SVGVectorCircleChooserValues vectChValues=null;                        if(gradientUnitsAtt!=null && px1Att!=null && py1Att!=null && px2Att!=null && py2Att!=null){                                boolean isGradientUnitsDefault=(! gradientUnitsAtt.getValue().equals(gradientUnitsOther));                                point1.x=svgEditor.getSVGToolkit().getDoubleValue(px1Att.getValue(), isGradientUnitsDefault);                point1.y=svgEditor.getSVGToolkit().getDoubleValue(py1Att.getValue(), isGradientUnitsDefault);                point2.x=svgEditor.getSVGToolkit().getDoubleValue(px2Att.getValue(), isGradientUnitsDefault);                point2.y=svgEditor.getSVGToolkit().getDoubleValue(py2Att.getValue(), isGradientUnitsDefault);                                if(radiusAtt!=null){                                        radius=svgEditor.getSVGToolkit().getDoubleValue(radiusAtt.getValue(), isGradientUnitsDefault);                }                if(isGradientUnitsDefault){                                        defPoint1=point1;                    defPoint2=point2;                    defRadius=radius;                }else{                                        otherPoint1=point1;                    otherPoint2=point2;                    otherRadius=radius;                                        defPoint1.x=svgEditor.getSVGToolkit().getDoubleValue(px1Att.getModel().getDefaultValue(), true);                    defPoint1.y=svgEditor.getSVGToolkit().getDoubleValue(py1Att.getModel().getDefaultValue(), true);                    defPoint2.x=svgEditor.getSVGToolkit().getDoubleValue(px2Att.getModel().getDefaultValue(), true);                    defPoint2.y=svgEditor.getSVGToolkit().getDoubleValue(py2Att.getModel().getDefaultValue(), true);                                        if(radiusAtt!=null){                                                defRadius=svgEditor.getSVGToolkit().getDoubleValue(radiusAtt.getModel().getDefaultValue(), true);                    }                }                                vectChValues=new SVGVectorCircleChooserValues(defPoint1, defPoint2, defRadius, otherPoint1, otherPoint2, otherRadius,                 																				isGradientUnitsDefault, type.equals("vectorchooser"));            }                        //the object containing the values for this chooser            final SVGVectorCircleChooserValues fvectChValues=vectChValues;                        if(vectChValues!=null && px1Att!=null && py1Att!=null && px2Att!=null && py2Att!=null){                                //creating the combo used to choose the units//                                //the list of the combo items                final LinkedList itmList=new LinkedList();                //the map of the possible values                final LinkedHashMap possibleValues=gradientUnitsAtt.getModel().getPossibleValues();                SVGComboItem itm=null, selectedItm=null;                nm="";                 String val="", lbl="";                                //an item with an empty string                itm=new SVGComboItem("","");                itmList.add(itm);                                //builds the array of items for the combo                for(Iterator it=possibleValues.keySet().iterator(); it.hasNext();){                    try{                        nm=(String)it.next();                        val=(String)possibleValues.get(nm);                                                //gets the label                        lbl=nm;                                                if(bundle!=null){                                                        lbl=bundle.getString(nm);                        }                                                itm=new SVGComboItem(val, lbl);                                                //checks if the current possible value is equals to the current value of the property                        if(val!=null && val.equals(gradientUnitsAtt.getValue()))selectedItm=itm;                                            }catch (Exception ex){itm=null; nm="";}                                        //adds the item to the list                    if(itm!=null){                                                itmList.add(itm);                    }                }                                Object[] itms=itmList.toArray();                                //the combo box                final JComboBox combo=new JComboBox(itms);                combo.setFont(theFont);                                //sets the selected item                if(selectedItm!=null){                                        combo.setSelectedItem(selectedItm);                }                String gradientUnitsLabel="";                                if(fgradientUnitsAtt!=null){                                        gradientUnitsLabel=fgradientUnitsAtt.getModel().getName();                                        if(bundle!=null){                                                try{                            gradientUnitsLabel=bundle.getString(fgradientUnitsAtt.getModel().getAbsoluteName());                        }catch (Exception ex){}                    }                }                                //the label of the combo                JLabel comboLabel=new JLabel(gradientUnitsLabel.concat(" :"));                comboLabel.setFont(theFont);                                //the panel containing the label and the combo box                final JPanel comboPanel=new JPanel();                comboPanel.setLayout(new BorderLayout(5, 5));                                //adding the elements                comboPanel.add(comboLabel, BorderLayout.WEST);                comboPanel.add(combo, BorderLayout.CENTER);                comboPanel.add(new JSeparator(), BorderLayout.SOUTH);                //the vector chooser//                //the size of the vector panel                final Dimension vectorPanelSize=new Dimension(100, 100);                                //the object managing the vector displayed on the vector panel                final SVGVectorCircleChooserItems items=                    		new SVGVectorCircleChooserItems(	fvectChValues.getDefaultPoint1(), fvectChValues.getDefaultPoint2(),                         															fvectChValues.getDefaultRadius(), vectorPanelSize,                        															fvectChValues.isVectorChooser(), vectChValues);                //the panel used to choose the vector                final JPanel vectorPanel=new JPanel(){                    protected void paintComponent(Graphics g) {                        super.paintComponent(g);                                                //paints the vector                        items.paintVectorOrCircle((Graphics2D)g);                    }                };                                //sets the properties of the panel                vectorPanel.setPreferredSize(vectorPanelSize);                vectorPanel.setBackground(Color.white);                vectorPanel.setBorder(new LineBorder(Color.black, 1));                                //the entries which will be used to manually set the coordinates of the vector                final JTextField 	px1Txt=new JTextField(format.format(point1.x)),                 						py1Txt=new JTextField(format.format(point1.y)),                						px2Txt=new JTextField(format.format(point2.x)),                 						py2Txt=new JTextField(format.format(point2.y)),                						radiusTxt=new JTextField(format.format(radius));                                //sets the properties for the textfields                px1Txt.setFont(theFont);                py1Txt.setFont(theFont);                px2Txt.setFont(theFont);                py2Txt.setFont(theFont);                radiusTxt.setFont(theFont);                                //the labels corresponding to the entries                final JLabel 	px1Lbl=new JLabel(px1Att.getModel().getName().concat("=")),                 					py1Lbl=new JLabel(py1Att.getModel().getName().concat("=")),                					px2Lbl=new JLabel(px2Att.getModel().getName().concat("=")),                 					py2Lbl=new JLabel(py2Att.getModel().getName().concat("=")),                 					radiusLbl=new JLabel();                                if(radiusAtt!=null){                                        radiusLbl.setText(radiusAtt.getModel().getName().concat("="));                }                //sets the properties for the label                px1Lbl.setFont(theFont);                py1Lbl.setFont(theFont);                px2Lbl.setFont(theFont);                py2Lbl.setFont(theFont);                radiusLbl.setFont(theFont);                                //sets the size for the labels                Dimension lblSize=new Dimension(20, 20);                px1Lbl.setPreferredSize(lblSize);                px1Lbl.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);                py1Lbl.setPreferredSize(lblSize);                py1Lbl.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);                px2Lbl.setPreferredSize(lblSize);                px2Lbl.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);                py2Lbl.setPreferredSize(lblSize);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -