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

📄 svgvisualresourcepatternsizechooserattributewidget.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                val=svgEditor.getSVGToolkit().getDoubleValue(xTxt.getText(), fpatternChValues.isDefaultPatternUnits());                                fxAtt.setValue(format.format(val));                                fpatternChValues.getOtherBounds().x=val;                                                              }                                                    }else if(evt.getSource().equals(yTxt)){                            if(fpatternChValues.isDefaultPatternUnits()){                                                                val=svgEditor.getSVGToolkit().getDoubleValue(yTxt.getText().concat("%"), fpatternChValues.isDefaultPatternUnits());                                fpatternChValues.getDefBounds().y=val;                                fyAtt.setValue(format.format(val)+"%");                                                                                     }else{                                                                val=svgEditor.getSVGToolkit().getDoubleValue(yTxt.getText(), fpatternChValues.isDefaultPatternUnits());                                fyAtt.setValue(format.format(val));                                fpatternChValues.getOtherBounds().y=val;                                                              }                                                    }else if(evt.getSource().equals(wTxt)){                            if(fpatternChValues.isDefaultPatternUnits()){                                                                val=svgEditor.getSVGToolkit().getDoubleValue(wTxt.getText().concat("%"), fpatternChValues.isDefaultPatternUnits());                                fpatternChValues.getDefBounds().width=val;                                fwAtt.setValue(format.format(val)+"%");                                                                                     }else{                                                                val=svgEditor.getSVGToolkit().getDoubleValue(wTxt.getText(), fpatternChValues.isDefaultPatternUnits());                                fwAtt.setValue(format.format(val));                                fpatternChValues.getOtherBounds().width=val;                                                              }                                                    }else if(evt.getSource().equals(hTxt)){                            if(fpatternChValues.isDefaultPatternUnits()){                                                                val=svgEditor.getSVGToolkit().getDoubleValue(hTxt.getText().concat("%"), fpatternChValues.isDefaultPatternUnits());                                fpatternChValues.getDefBounds().height=val;                                fhAtt.setValue(format.format(val)+"%");                                                            }else{                                                                val=svgEditor.getSVGToolkit().getDoubleValue(hTxt.getText(), fpatternChValues.isDefaultPatternUnits());                                fhAtt.setValue(format.format(val));                                fpatternChValues.getOtherBounds().height=val;                                                              }                        }                    }                };                                //adds the listener to the textfields                xTxt.addCaretListener(textfieldsListener);                yTxt.addCaretListener(textfieldsListener);                wTxt.addCaretListener(textfieldsListener);                hTxt.addCaretListener(textfieldsListener);    			                //the panel containing the textfields                final JPanel textfields=new JPanel();                //sets the layout                textfields.setLayout(new BoxLayout(textfields, BoxLayout.Y_AXIS));                textfields.setBorder(new EmptyBorder(0, 0, 0, 5));    			//adding the elements for x                JPanel xPanel=new JPanel();                xPanel.setLayout(new BorderLayout(2, 2));                xPanel.add(xLbl, BorderLayout.WEST);                xPanel.add(xTxt, BorderLayout.CENTER);                xPanel.add(xUnitLbl, BorderLayout.EAST);                textfields.add(xPanel);    			//adding the elements for y                JPanel yPanel=new JPanel();                yPanel.setLayout(new BorderLayout(2, 2));                yPanel.add(yLbl, BorderLayout.WEST);                yPanel.add(yTxt, BorderLayout.CENTER);                yPanel.add(yUnitLbl, BorderLayout.EAST);                textfields.add(yPanel);    			    			//adding the elements for w                JPanel wPanel=new JPanel();                wPanel.setLayout(new BorderLayout(2, 2));                wPanel.add(wLbl, BorderLayout.WEST);                wPanel.add(wTxt, BorderLayout.CENTER);                wPanel.add(wUnitLbl, BorderLayout.EAST);                textfields.add(wPanel);    			    			//adding the elements for h                JPanel hPanel=new JPanel();                hPanel.setLayout(new BorderLayout(2, 2));                hPanel.add(hLbl, BorderLayout.WEST);                hPanel.add(hTxt, BorderLayout.CENTER);                hPanel.add(hUnitLbl, BorderLayout.EAST);                textfields.add(hPanel);    			//the panel containing the vector panel and the textfields panel    			final JPanel widgetPanel=new JPanel();    			widgetPanel.setLayout(new BorderLayout(0, 5));    			    			//adds the combo box panel    			widgetPanel.add(comboPanel, BorderLayout.NORTH);    			    			//adds the vector chooser panel    			widgetPanel.add(textfields, BorderLayout.CENTER);                //the listener to the combo box                final ActionListener comboListener=new ActionListener(){                                        public void actionPerformed(ActionEvent evt) {                                                String val="";                                                if(combo.getSelectedItem()!=null){                                                        val=((SVGComboItem)combo.getSelectedItem()).getValue();                        }                        //modifies the widgetValue of the property item                        if(val!=null && ! val.equals("")){                                                        //saving the values for the current state                            Rectangle2D.Double bounds=new Rectangle2D.Double(0, 0, 0, 0);                                                        String 	xStr=xTxt.getText(),                             			yStr=yTxt.getText(),                            			wStr=wTxt.getText(),                            			hStr=hTxt.getText();                                                        if(fpatternChValues.isDefaultPatternUnits()){                                                                xStr=xStr.concat("%");                                yStr=yStr.concat("%");                                wStr=wStr.concat("%");                                hStr=hStr.concat("%");                            }                            bounds.x=svgEditor.getSVGToolkit().getDoubleValue(xStr, fpatternChValues.isDefaultPatternUnits());                            bounds.y=svgEditor.getSVGToolkit().getDoubleValue(yStr, fpatternChValues.isDefaultPatternUnits());                            bounds.width=svgEditor.getSVGToolkit().getDoubleValue(wStr, fpatternChValues.isDefaultPatternUnits());                            bounds.height=svgEditor.getSVGToolkit().getDoubleValue(hStr, fpatternChValues.isDefaultPatternUnits());                            if(fpatternChValues.isDefaultPatternUnits()){                                                                fpatternChValues.setDefBounds(bounds);                            }else{                                                                fpatternChValues.setOtherBounds(bounds);                            }                                                        //setting the new attribute value                            fpatternUnitsAtt.setValue(val);                            fpatternChValues.setDefaultPatternUnits(! fpatternUnitsAtt.getValue().equals(patternUnitsOther));                                                        //sets the label for the units                            String unitSign=fpatternChValues.getUnitSign();                            xUnitLbl.setText(unitSign);                            yUnitLbl.setText(unitSign);                            wUnitLbl.setText(unitSign);                            hUnitLbl.setText(unitSign);                                                        if(fpatternChValues.isDefaultPatternUnits()){                                xStr=format.format(fpatternChValues.getDefBounds().x);                                yStr=format.format(fpatternChValues.getDefBounds().y);                                wStr=format.format(fpatternChValues.getDefBounds().width);                                hStr=format.format(fpatternChValues.getDefBounds().height);                                xTxt.setText(xStr);                                yTxt.setText(yStr);                                wTxt.setText(wStr);                                hTxt.setText(hStr);                                xStr=xStr.concat("%");                                yStr=yStr.concat("%");                                wStr=wStr.concat("%");                                hStr=hStr.concat("%");                            }else{                                                                xStr=format.format(fpatternChValues.getOtherBounds().x);                                yStr=format.format(fpatternChValues.getOtherBounds().y);                                wStr=format.format(fpatternChValues.getOtherBounds().width);                                hStr=format.format(fpatternChValues.getOtherBounds().height);                                xTxt.setText(xStr);                                yTxt.setText(yStr);                                wTxt.setText(wStr);                                hTxt.setText(hStr);                            }                                                        //setting the value of the attributes                            fxAtt.setValue(xStr);                            fyAtt.setValue(yStr);                            fwAtt.setValue(wStr);                            fhAtt.setValue(hStr);                        }                    }                };                                //adds a listener to the combo box                combo.addActionListener(comboListener);    			                component=widgetPanel;                                Runnable disposer=new Runnable(){	                public void run() {                        //removes the listener to the textfields                        xTxt.removeCaretListener(textfieldsListener);                        yTxt.removeCaretListener(textfieldsListener);                        wTxt.removeCaretListener(textfieldsListener);                        hTxt.removeCaretListener(textfieldsListener);                                                //removes the listener from the combo box                        combo.removeActionListener(comboListener);                                                itmList.clear();	                }                 };            }        }    }        /**     * the class used to store information for the pattern size chooser     *      * @author Jordi SUC     */    protected class SVGPatternSizeChooserValues{       /**        * the default bounds        */        private Rectangle2D.Double defBounds=new Rectangle2D.Double(0, 0, 0, 0);                /**         * the other bounds         */        private Rectangle2D.Double otherBounds=new Rectangle2D.Double(0, 0, 0, 0);                /**         * the boolean telling if the default units are used or not         */        private boolean isDefaultPatternUnits=true;                /**         * the constructor of the class         * @param defBounds the default bounds of the pattern         * @param otherBounds the other bounds of the pattern         * @param isDefaultPatternUnits the boolean telling if the default units are used or not         */        protected SVGPatternSizeChooserValues(Rectangle2D.Double defBounds, Rectangle2D.Double otherBounds,boolean isDefaultPatternUnits){                        if(defBounds!=null){                                this.defBounds=defBounds;            }                        if(otherBounds!=null){                                this.otherBounds=otherBounds;            }                        this.isDefaultPatternUnits=isDefaultPatternUnits;        }                /**         * @return a unit sign         */        protected String getUnitSign(){                        String unitSign="";                        if(isDefaultPatternUnits()){                                unitSign="%";                            }else{                               unitSign="px";            }                        return unitSign;        }	    protected Rectangle2D.Double getDefBounds() {	        return defBounds;	    }	    	    protected void setDefBounds(Rectangle2D.Double defBounds) {	        this.defBounds=defBounds;	    }	            protected Rectangle2D.Double getOtherBounds() {            return otherBounds;        }                protected void setOtherBounds(Rectangle2D.Double otherBounds) {            this.otherBounds=otherBounds;        }                protected boolean isDefaultPatternUnits() {            return isDefaultPatternUnits;        }                protected void setDefaultPatternUnits(boolean isDefaultPatternUnits) {            this.isDefaultPatternUnits=isDefaultPatternUnits;        }    }}

⌨️ 快捷键说明

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