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

📄 svgvisualresourcevectorcirclechooserattributewidget.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                py2Lbl.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);                radiusLbl.setPreferredSize(lblSize);                radiusLbl.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);                                if(vectChValues.isDefaultGradientUnits()){                                        //sets the color for the labels                    px1Lbl.setForeground(vectChValues.getPoint1Color());                    py1Lbl.setForeground(vectChValues.getPoint1Color());                    px2Lbl.setForeground(vectChValues.getPoint2Color());                    py2Lbl.setForeground(vectChValues.getPoint2Color());                    radiusLbl.setForeground(vectChValues.getRadiusColor());                }                //the label for the units                String unitSign=vectChValues.getUnitSign();                final JLabel 	px1UnitLbl=new JLabel(unitSign),                					py1UnitLbl=new JLabel(unitSign),                					px2UnitLbl=new JLabel(unitSign),                					py2UnitLbl=new JLabel(unitSign),                					radiusUnitLbl=new JLabel(unitSign);                                //sets the properties for the label                px1UnitLbl.setFont(theFont);                py1UnitLbl.setFont(theFont);                px2UnitLbl.setFont(theFont);                py2UnitLbl.setFont(theFont);                radiusUnitLbl.setFont(theFont);			                    //the listener to the mouse events on the vector panel                final SVGVectorCirclePanelListener vectorPanelListener=new SVGVectorCirclePanelListener(){                                        /**                     * the integer describing the point on which a click has been done                     */                    private int currentPoint=SVGVectorCircleChooserItems.NO_POINT;                                        /**                     * refreshes the display of the vector in the panel                     */                    public void refresh(){                                                vectorPanel.repaint();                    }                                        public void mousePressed(MouseEvent e){                                                currentPoint=items.hasHitAPoint(e.getPoint());                    }                                        public void mouseDragged(MouseEvent e){                                                if(vectorPanelSize!=null){                                                        //if a point of the vector has been hit, sets the new value while dragging                            if(		currentPoint==SVGVectorCircleChooserItems.POINT1 ||                                     currentPoint==SVGVectorCircleChooserItems.POINT2 ||                                    currentPoint==SVGVectorCircleChooserItems.CIRCLE){                                                                Point2D.Double point=new Point2D.Double(0, 0);                                point.x=100*e.getPoint().x/vectorPanelSize.width;                                point.y=100*e.getPoint().y/vectorPanelSize.height;                                //sets the new values in the textfields                                if(currentPoint==SVGVectorCircleChooserItems.POINT1){                                                                        items.setPoint(point, currentPoint);                                                                        Point2D.Double point1=items.getPoint1();                                                                        px1Txt.setText(format.format(point1.x));                                    py1Txt.setText(format.format(point1.y));                                                                        fvectChValues.setDefaultPoint1(point1);                                }else if(currentPoint==SVGVectorCircleChooserItems.POINT2){                                                                        items.setPoint(point, currentPoint);                                                                        Point2D.Double point2=items.getPoint2();                                                                        px2Txt.setText(format.format(point2.x));                                    py2Txt.setText(format.format(point2.y));                                                                        fvectChValues.setDefaultPoint2(point2);                                                                    }else if(currentPoint==SVGVectorCircleChooserItems.CIRCLE){                                                                        Point2D.Double point1=items.getPoint1();                                                                        if(point1!=null){                                                                                double cy=100*point.y/vectorPanelSize.height;                                        double rad=Math.abs(point1.y-cy);                                                                                    items.setRadius(rad);                                                                                radiusTxt.setText(format.format(items.getRadius()));                                        fvectChValues.setDefaultRadius(items.getRadius());                                    }                                }                                refresh();                            }                        }                    }                    public void mouseReleased(MouseEvent e) {                                                //applies the changes                        if(		currentPoint==SVGVectorCircleChooserItems.POINT1 ||                                 currentPoint==SVGVectorCircleChooserItems.POINT2 ||                                currentPoint==SVGVectorCircleChooserItems.CIRCLE){                                                    applyChanges();                        }                    }                    public void mouseClicked(MouseEvent e) {                    }                    public void mouseEntered(MouseEvent e) {                    }                    public void mouseExited(MouseEvent e) {                    }                    public void mouseMoved(MouseEvent e) {                    }                                        /**                     * applies the changes made on the values of the attributes to the attributes                     */                    protected void applyChanges(){                        if(items!=null && fvectChValues.isDefaultGradientUnits){                                                        Point2D.Double point1=items.getPoint1(), point2=items.getPoint2();                                                        fpx1Att.setValue(format.format(point1.x)+"%");                            fpy1Att.setValue(format.format(point1.y)+"%");                            fpx2Att.setValue(format.format(point2.x)+"%");                            fpy2Att.setValue(format.format(point2.y)+"%");                                                        if(fradiusAtt!=null){                                                                fradiusAtt.setValue(format.format(items.getRadius())+"%");                            }                        }                    }                };                                //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(px1Txt)){                            if(fvectChValues.isDefaultGradientUnits()){                                                                val=svgEditor.getSVGToolkit().getDoubleValue(px1Txt.getText().concat("%"), fvectChValues.isDefaultGradientUnits());                                fvectChValues.getDefaultPoint1().x=val;                                items.setPoint(fvectChValues.getDefaultPoint1(), SVGVectorCircleChooserItems.POINT1);                                fpx1Att.setValue(format.format(val)+"%");                                                                       vectorPanelListener.refresh();                                                            }else{                                                                val=svgEditor.getSVGToolkit().getDoubleValue(px1Txt.getText(), fvectChValues.isDefaultGradientUnits());                                fpx1Att.setValue(format.format(val));                                fvectChValues.getOtherPoint1().x=val;                                                              }                                                    }else if(evt.getSource().equals(py1Txt)){                            if(fvectChValues.isDefaultGradientUnits()){                                                                val=svgEditor.getSVGToolkit().getDoubleValue(py1Txt.getText().concat("%"), fvectChValues.isDefaultGradientUnits());                                fvectChValues.getDefaultPoint1().y=val;                                items.setPoint(fvectChValues.getDefaultPoint1(), SVGVectorCircleChooserItems.POINT1);                                fpy1Att.setValue(format.format(val)+"%");                                                         vectorPanelListener.refresh();                                                            }else{                                                                val=svgEditor.getSVGToolkit().getDoubleValue(py1Txt.getText(), fvectChValues.isDefaultGradientUnits());                                fpy1Att.setValue(format.format(val));                                fvectChValues.getOtherPoint1().y=val;                                                              }                                                    }else if(evt.getSource().equals(px2Txt)){                            if(fvectChValues.isDefaultGradientUnits()){                                                                val=svgEditor.getSVGToolkit().getDoubleValue(px2Txt.getText().concat("%"), fvectChValues.isDefaultGradientUnits());                                fvectChValues.getDefaultPoint2().x=val;                                items.setPoint(fvectChValues.getDefaultPoint2(), SVGVectorCircleChooserItems.POINT2);                                fpx2Att.setValue(format.format(val)+"%");                                                         vectorPanelListener.refresh();                                                            }else{                                                                val=svgEditor.getSVGToolkit().getDoubleValue(px2Txt.getText(), fvectChValues.isDefaultGradientUnits());                                fpx2Att.setValue(format.format(val));                                fvectChValues.getOtherPoint2().x=val;                                                              }                                                    }else if(evt.getSource().equals(py2Txt)){                            if(fvectChValues.isDefaultGradientUnits()){                                                                val=svgEditor.getSVGToolkit().getDoubleValue(py2Txt.getText().concat("%"), fvectChValues.isDefaultGradientUnits());                                fvectChValues.getDefaultPoint2().y=val;                                items.setPoint(fvectChValues.getDefaultPoint2(), SVGVectorCircleChooserItems.POINT2);                                fpy2Att.setValue(format.format(val)+"%");                                                                vectorPanelListener.refresh();                                                            }else{                                                                val=svgEditor.getSVGToolkit().getDoubleValue(py2Txt.getText(), fvectChValues.isDefaultGradientUnits());                                fpy2Att.setValue(format.format(val));                                fvectChValues.getOtherPoint2().y=val;                                                              }                                                    }else if(evt.getSource().equals(radiusTxt) && fradiusAtt!=null){                            if(fvectChValues.isDefaultGradientUnits()){                                                                val=svgEditor.getSVGToolkit().getDoubleValue(radiusTxt.getText().concat("%"), fvectChValues.isDefaultGradientUnits());                                fvectChValues.setDefaultRadius(val);                                items.setRadius(fvectChValues.getDefaultRadius());                                fradiusAtt.setValue(format.format(val)+"%");                                 vectorPanelListener.refresh();                                                            }else{                                                                val=svgEditor.getSVGToolkit().getDoubleValue(radiusTxt.getText(), fvectChValues.isDefaultGradientUnits());                                fradiusAtt.setValue(format.format(val));                                fvectChValues.setOtherRadius(val);                                                              }                        }					}                };                //adds the listener to the textfields                px1Txt.addCaretListener(textfieldsListener);                py1Txt.addCaretListener(textfieldsListener);                px2Txt.addCaretListener(textfieldsListener);                py2Txt.addCaretListener(textfieldsListener);                radiusTxt.addCaretListener(textfieldsListener);    			final JPanel vectChooserPanel=new JPanel();    			vectChooserPanel.setLayout(new BoxLayout(vectChooserPanel, BoxLayout.X_AXIS));    			vectChooserPanel.setBorder(new EmptyBorder(0, 2, 5, 0));    			                //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 px1                JPanel px1Panel=new JPanel();                px1Panel.setLayout(new BorderLayout(2, 2));                px1Panel.add(px1Lbl, BorderLayout.WEST);                px1Panel.add(px1Txt, BorderLayout.CENTER);                px1Panel.add(px1UnitLbl, BorderLayout.EAST);                textfields.add(px1Panel);    			    			//adding the elements for py1                JPanel py1Panel=new JPanel();                py1Panel.setLayout(new BorderLayout(2, 2));                py1Panel.add(py1Lbl, BorderLayout.WEST);                py1Panel.add(py1Txt, BorderLayout.CENTER);                py1Panel.add(py1UnitLbl, BorderLayout.EAST);                textfields.add(py1Panel);    			    			//adding the elements for px2                JPanel px2Panel=new JPanel();                px2Panel.setLayout(new BorderLayout(2, 2));                px2Panel.add(px2Lbl, BorderLayout.WEST);                px2Panel.add(px2Txt, BorderLayout.CENTER);                px2Panel.add(px2UnitLbl, BorderLayout.EAST);                textfields.add(px2Panel);    			    			//adding the elements for py2                JPanel py2Panel=new JPanel();                py2Panel.setLayout(new BorderLayout(2, 2));                py2Panel.add(py2Lbl, BorderLayout.WEST);                py2Panel.add(py2Txt, BorderLayout.CENTER);                py2Panel.add(py2UnitLbl, BorderLayout.EAST);                textfields.add(py2Panel);                                if(! vectChValues.isVectorChooser()){                            			//adding the elements for radius                    JPanel radiusPanel=new JPanel();                    radiusPanel.setLayout(new BorderLayout(2, 2));                    radiusPanel.add(radiusLbl, BorderLayout.WEST);                    radiusPanel.add(radiusTxt, BorderLayout.CENTER);                    radiusPanel.add(radiusUnitLbl, BorderLayout.EAST);                    textfields.add(radiusPanel);                                    }else{                                        JPanel empty=new JPanel();                    empty.setPreferredSize(lblSize);                    textfields.add(empty);                }                //adding the panel to the widget panel                vectChooserPanel.add(textfields);                vectChooserPanel.add(vectorPanel);                if(vectChValues.isDefaultGradientUnits()){                    //adds the listener to the vector panel                    vectorPanel.addMouseListener(vectorPanelListener);                    vectorPanel.addMouseMotionListener(vectorPanelListener);                                    }else{                    //disables the vector chooser panel                    items.setEnabled(false);                    vectorPanel.setVisible(false);                }                    			//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);

⌨️ 快捷键说明

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