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

📄 svgvisualresourcegradientcolorchooserchildwidget.java

📁 完全基于java开发的svg矢量绘图工具
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            return opacity;        }                /***          * @return the color computed from the attribute value         */        protected Color computeColor(){                        Color color=Color.black;                        if(styleResAttribute!=null){                                String val=styleResAttribute.getValue();                                //normalizing the string                if(val==null){                                        val="";                }                                val=val.replaceAll("\\s*[;]\\s*", ";");                val=val.replaceAll("\\s*[:]\\s*", ":");                                String prop="stop-color";                int ind=val.indexOf(prop);                                if(ind!=-1){                                        //getting the value of the color among the style string                    val=val.substring(ind, val.length());                    val=val.substring(val.indexOf(":")+1, val.indexOf(";"));                                        SVGEditor editor=resChild.getChildModel().getVisualResources().getSVGEditor();                    SVGFrame frame=editor.getFrameManager().getCurrentFrame();                                        color=editor.getColorChooser().getColor(frame, val);                }            }                        return color;        }                /***          * @return the opacity of the color computed from the attribute value         */        protected double computeOpacity(){                        double op=1;                        if(styleResAttribute!=null){                                String val=styleResAttribute.getValue();                                //normalizing the string                if(val==null){                                        val="";                }                                val=val.replaceAll("\\s*[;]\\s*", ";");                val=val.replaceAll("\\s*[:]\\s*", ":");                                String prop="stop-opacity";                int ind=val.indexOf(prop);                                if(ind!=-1){                                        //getting the value of the color among the style string                    val=val.substring(ind, val.length());                    val=val.substring(val.indexOf(":")+1, val.indexOf(";"));                                        op=resChild.getChildModel().getVisualResources().getSVGEditor().getSVGToolkit().getDoubleValue(val, true)/100;                }            }                        return op;        }                /**         * sets the color of this item         * @param color a color         */        protected synchronized void setColor(Color color){                        if(color==null){                                this.color=Color.black;                            }else{                                this.color=color;            }        }                /**         * sets the opacity of the color of this item         * @param opacity the value for the opacity a double in the [0..1] interval         */        protected synchronized void setOpacity(double opacity){                        if(opacity<0){                                opacity=0;            }                        if(opacity>1){                                opacity=1;            }            this.opacity=opacity;        }                /**         * sets the value of the color in the style attribute         */        protected void applyColor(){                        if(color!=null && styleResAttribute!=null){                                String val=styleResAttribute.getValue();                                //normalizing the string                if(val==null){                                        val="";                }                                val=val.replaceAll("\\s*[;]\\s*", ";");                val=val.replaceAll("\\s*[:]\\s*", ":");                                String prop="stop-color";                int ind=val.indexOf(prop);                                if(ind!=-1){                                        //getting the value of the color among the style string                    String val1=val1=val.substring(0, ind), val2=val.substring(ind, val.length());                    //removes the previous value if it exists                    int ind2=val2.indexOf(";");                                        if(ind2!=-1){                                                val2=val2.substring(ind2+1, val2.length());                        val=val1.concat(val2);                                                if(val.length()>0 && ! val.endsWith(";")){                                                        val=val.concat(";");                        }                                            }else{                                                val=val1;                    }                }                //creating the new value of the style attribute                val=val.concat(prop.concat(":".concat(SVGEditor.getColorChooser().getColorString(color)).concat(";")));                                //sets the attribute                styleResAttribute.setValue(val);            }	                }                /**         * sets the value of the opacity of the color in the style attribute         */        protected void applyOpacity(){                        if(styleResAttribute!=null){                                String val=styleResAttribute.getValue();                                //normalizing the string                if(val==null){                                        val="";                }                                val=val.replaceAll("\\s*[;]\\s*", ";");                val=val.replaceAll("\\s*[:]\\s*", ":");                                String prop="stop-opacity";                int ind=val.indexOf(prop);                                if(ind!=-1){                                        //getting the value of the opacity among the style string                    String val1="", val2="";                    val1=val.substring(0, ind);                    val2=val.substring(ind, val.length());                    //removes the previous value if it exists                    int ind2=val2.indexOf(";");                                        if(ind2!=-1){                                                val2=val2.substring(ind2+1, val2.length());                        val=val1.concat(val2);                                                if(val.length()>0 && ! val.endsWith(";")){                                                        val=val.concat(";");                        }                                            }else{                                                val=val1;                    }                }                                //creating the new value of the style attribute                val=val.concat(prop.concat(":".concat(format.format(opacity)).concat(";")));                                //sets the attribute                styleResAttribute.setValue(val);            }	                }                /**         * applies the changes made on the offset and the color          */        protected void applyChanges(){                        applyXPosition();            applyColor();            applyOpacity();        }                /**         * @param point th position of the mouse         * @return true if the x position of the mouse is contained in the item interval         */        protected boolean belongsToThisItem(Point point){                        if(point!=null){                                //computes the bounds of the arrow                AffineTransform af=AffineTransform.getTranslateInstance(xPosition, yPosition-1);                Shape shape=path.createTransformedShape(af);                Shape rect=colorRect.createTransformedShape(af);                Rectangle shapeBounds=shape.getBounds(), rectBounds=rect.getBounds(),                 				allBounds=new Rectangle(shapeBounds.x, rectBounds.y, rectBounds.width, rectBounds.height+shapeBounds.height);                //test if the point is contained in the bounds                if(allBounds.contains(point.x, point.y)){                                        return true;                }            }                        return false;        }                /**         * @return true if the item is selected         */        protected boolean isSelected(){                        return isSelected;        }                /**         * sets the item as selected or not selected         * @param select true to select the item         */        protected synchronized void setSelected(boolean select){                        this.isSelected=select;        }                /**         * paints the item with the gievn graphics         * @param g a graphics         */        protected void paintArrow(Graphics2D g){                        //transforms the shapes            AffineTransform af=AffineTransform.getTranslateInstance(xPosition, yPosition-1);            Shape shape=path.createTransformedShape(af);            Shape rect=colorRect.createTransformedShape(af);                        //sets the colors an draws the shape            if(isSelected){                                g.setColor(ITEM_SELECTED_FILL_COLOR);                            }else{                                g.setColor(ITEM_FILL_COLOR);            }                        g.fill(shape);                        if(isSelected){                                g.setColor(ITEM_SELECTED_COLOR);                            }else{                                g.setColor(ITEM_COLOR);            }                        g.draw(shape);                        //getting the bounds of the color rectangle            Rectangle bounds=rect.getBounds();                        //painting the color rectangle            g.setColor(color);            g.fillRect(bounds.x+2, bounds.y+2, 10, 8);            //painting the border            g.setColor(BORDER_SHADOW_COLOR);            g.drawLine(bounds.x, bounds.y, bounds.x, bounds.y+bounds.height);            g.drawLine(bounds.x, bounds.y, bounds.x+bounds.width, bounds.y);            g.drawLine(bounds.x+bounds.width-1, bounds.y, bounds.x+bounds.width-1, bounds.y+bounds.height-1);            g.drawLine(bounds.x+1, bounds.y+bounds.height-1, bounds.x+bounds.width-1, bounds.y+bounds.height-1);                        g.setColor(BORDER_HIGHLIGHT_COLOR);            g.drawLine(bounds.x+1, bounds.y+1, bounds.x+1, bounds.y+bounds.height-1);            g.drawLine(bounds.x+1, bounds.y+1, bounds.x+bounds.width-1, bounds.y+1);            g.drawLine(bounds.x+bounds.width, bounds.y, bounds.x+bounds.width, bounds.y+bounds.height);            g.drawLine(bounds.x, bounds.y+bounds.height, bounds.x+bounds.width, bounds.y+bounds.height);        }                /**         * paints the item with the given graphics         * @param g a graphics         * @param previousItem the item previously displayed on the gradient panel         * @param hasNextItem true if another item takes place after this current one in the gradient items list         */        protected void paintGradient(Graphics2D g, SVGGradientChooserItem previousItem, boolean hasNextItem){                        //getting the values of the gradient            int preXPosition=itemWidth/2;            Color preColor=null, tColor=null;                        if(color!=null){                                preColor=new Color(color.getRed(), color.getGreen(), color.getBlue(), (int)(opacity*255));                tColor=new Color(color.getRed(), color.getGreen(), color.getBlue(), (int)(opacity*255));            }            if(previousItem!=null){                                preXPosition=previousItem.getXPosition();                Color pc=previousItem.getColor();                                if(pc!=null){                                        preColor=new Color(pc.getRed(), pc.getGreen(), pc.getBlue(), (int)(previousItem.getOpacity()*255));                }            }                        if(gradientPanelSize!=null && preColor!=null && tColor!=null){                //drawing the gradient                GradientPaint gradient=new GradientPaint(preXPosition, 0, preColor, xPosition, 0, tColor);                g.setPaint(gradient);                g.fillRect(preXPosition, 0, xPosition-preXPosition, gradientPanelSize.height);                                //if the current item is the last item in the gradient items list                if(! hasNextItem){                                        g.setColor(tColor);                    g.fillRect(xPosition, 0, (gradientPanelSize.width-itemWidth)-xPosition+itemWidth/2, gradientPanelSize.height);                }            }        }                /**         * @return the resource child         */        protected SVGVisualResourceObjectChild getResourceObjectChild(){                        return resChild;        }    }}

⌨️ 快捷键说明

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