📄 svgvisualresourcepatternsizechooserattributewidget.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 javax.swing.*;import java.util.*;import java.awt.event.*;import javax.swing.border.*;import javax.swing.event.*;import fr.itris.glips.svgeditor.*;import java.awt.*;import java.awt.geom.*;/** * the class of the widgets that will be displayed in the properties dialog, and enabling to modify the properties (with a combo) * of an attribute (or a group of attributes) of a resource node. * * @author Jordi SUC */public class SVGVisualResourcePatternSizeChooserAttributeWidget extends SVGVisualResourceAttributeWidget{ /** * the constructor of the class * @param resourceObjectAttribute the attribute object that will be modified */ public SVGVisualResourcePatternSizeChooserAttributeWidget(SVGVisualResourceObjectAttribute resourceObjectAttribute) { super(resourceObjectAttribute); buildComponent(); } /** * builds the component to be displayed */ protected void buildComponent(){ if(resourceObjectAttribute!=null){ final SVGEditor svgEditor=resourceObjectAttribute.getModel().getVisualResources().getSVGEditor(); //getting the attributes// SVGVisualResourceObjectAttribute xAtt=null, yAtt=null, wAtt=null, hAtt=null, patternUnitsAtt=null, att=null; final String patternUnitsOther="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("x")){ xAtt=att; }else if(nm.equals("y")){ yAtt=att; }else if(nm.equals("width")){ wAtt=att; }else if(nm.equals("height")){ hAtt=att; }else if(nm.equals("patternUnits")){ patternUnitsAtt=att; } } } final SVGVisualResourceObjectAttribute fxAtt=xAtt, fyAtt=yAtt, fwAtt=wAtt, fhAtt=hAtt, fpatternUnitsAtt=patternUnitsAtt, fatt=null; //getting the bounds values// Rectangle2D.Double bounds=new Rectangle2D.Double(0, 0, 0, 0), defBounds=new Rectangle2D.Double(0, 0, 0, 0), otherBounds=new Rectangle2D.Double(0, 0, 0, 0); //the object containing the values for this chooser SVGPatternSizeChooserValues patternChValues=null; if(patternUnitsAtt!=null && xAtt!=null && yAtt!=null && wAtt!=null && hAtt!=null){ boolean isPatternUnitsDefault=(! patternUnitsAtt.getValue().equals(patternUnitsOther)); bounds.x=svgEditor.getSVGToolkit().getDoubleValue(xAtt.getValue(), isPatternUnitsDefault); bounds.y=svgEditor.getSVGToolkit().getDoubleValue(yAtt.getValue(), isPatternUnitsDefault); bounds.width=svgEditor.getSVGToolkit().getDoubleValue(wAtt.getValue(), isPatternUnitsDefault); bounds.height=svgEditor.getSVGToolkit().getDoubleValue(hAtt.getValue(), isPatternUnitsDefault); if(isPatternUnitsDefault){ defBounds=bounds; }else{ otherBounds=bounds; defBounds=new Rectangle2D.Double( svgEditor.getSVGToolkit().getDoubleValue(xAtt.getModel().getDefaultValue(), true), svgEditor.getSVGToolkit().getDoubleValue(yAtt.getModel().getDefaultValue(), true), svgEditor.getSVGToolkit().getDoubleValue(wAtt.getModel().getDefaultValue(), true), svgEditor.getSVGToolkit().getDoubleValue(hAtt.getModel().getDefaultValue(), true)); } patternChValues=new SVGPatternSizeChooserValues(defBounds, otherBounds, isPatternUnitsDefault); } //the object containing the values for this chooser final SVGPatternSizeChooserValues fpatternChValues=patternChValues; if(patternChValues!=null && xAtt!=null && yAtt!=null && wAtt!=null && hAtt!=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=patternUnitsAtt.getModel().getPossibleValues(); SVGComboItem itm=null, selectedItm=null; String val="", lbl=""; //adding 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(patternUnitsAtt.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 patternUnitsLabel=""; if(fpatternUnitsAtt!=null){ patternUnitsLabel=fpatternUnitsAtt.getModel().getName(); if(bundle!=null){ try{ patternUnitsLabel=bundle.getString(fpatternUnitsAtt.getModel().getAbsoluteName()); }catch (Exception ex){} } } //the label of the combo JLabel comboLabel=new JLabel(patternUnitsLabel.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 entries which will be used to manually set the coordinates of the vector final JTextField xTxt=new JTextField(format.format(bounds.x)), yTxt=new JTextField(format.format(bounds.y)), wTxt=new JTextField(format.format(bounds.width)), hTxt=new JTextField(format.format(bounds.height)); //sets the properties for the textfields xTxt.setFont(theFont); yTxt.setFont(theFont); wTxt.setFont(theFont); hTxt.setFont(theFont); //getting the labels String strX=xAtt.getModel().getName(), strY=yAtt.getModel().getName(), strW=wAtt.getModel().getName(), strH=hAtt.getModel().getName(); if(bundle!=null){ try{ strX=bundle.getString("vresource_".concat(strX)); strY=bundle.getString("vresource_".concat(strY)); strW=bundle.getString("vresource_".concat(strW)); strH=bundle.getString("vresource_".concat(strH)); }catch (Exception ex){} } //the labels corresponding to the entries final JLabel xLbl=new JLabel(strX.concat("=")), yLbl=new JLabel(strY.concat("=")), wLbl=new JLabel(strW.concat("=")), hLbl=new JLabel(strH.concat("=")); //sets the properties for the label xLbl.setFont(theFont); yLbl.setFont(theFont); wLbl.setFont(theFont); hLbl.setFont(theFont); //sets the size for the labels Dimension lblSize=new Dimension(70, 20); xLbl.setPreferredSize(lblSize); xLbl.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); yLbl.setPreferredSize(lblSize); yLbl.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); wLbl.setPreferredSize(lblSize); wLbl.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); hLbl.setPreferredSize(lblSize); hLbl.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); //the label for the units String unitSign=patternChValues.getUnitSign(); final JLabel xUnitLbl=new JLabel(unitSign), yUnitLbl=new JLabel(unitSign), wUnitLbl=new JLabel(unitSign), hUnitLbl=new JLabel(unitSign); //sets the properties for the label xUnitLbl.setFont(theFont); yUnitLbl.setFont(theFont); wUnitLbl.setFont(theFont); hUnitLbl.setFont(theFont); //the listener to the textfields final CaretListener textfieldsListener=new CaretListener(){ public void caretUpdate(CaretEvent evt) { Point point=new Point(0, 0); double val=0; //setting the attributes values if(evt.getSource().equals(xTxt)){ if(fpatternChValues.isDefaultPatternUnits()){ val=svgEditor.getSVGToolkit().getDoubleValue(xTxt.getText().concat("%"), fpatternChValues.isDefaultPatternUnits()); fpatternChValues.getDefBounds().x=val; fxAtt.setValue(format.format(val)+"%"); }else{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -