📄 svgvisualresourcegradientcolorchooserchildwidget.java
字号:
if(resChild!=null){ synchronized(this){isModified=true;} resourceObject.removeChildResource(resChild); } gradientItems.remove(currentItem); setCurrentItem(null); } } public void mousePressed(MouseEvent e) { Point point=getNormalizedPoint(e.getPoint()); if(point!=null){ SVGGradientChooserItem item=getClickedItem(point); if(item!=null){ if(e.getClickCount()==2){ setCurrentItem(item); canDrag=false; }else if(e.getClickCount()==1){ setCurrentItem(item); canDrag=true; } }else{ canDrag=false; //creating a new item SVGVisualResourceObjectChild resChild=resourceObject.createNewChild(); if(resChild!=null){ item=new SVGGradientChooserItem(resChild, arrowsPanelSize, gradientPanelSize); if(item!=null){ //sets the color and position for this item item.setColor(Color.black); item.setXPosition(e.getPoint().x); //adds the item to the gradient items list gradientItems.add(item); setCurrentItem(item); synchronized(this){isModified=true;} } } } } } public void mouseReleased(MouseEvent e) { if(currentItem!=null){ if(e.getClickCount()==2){ Color color=SVGEditor.getColorChooser().showColorChooserDialog(SVGEditor.getColorChooser().getColor()); if(color!=null && currentItem!=null){ colorPanel.setBackground(color); currentItem.setColor(color); SVGEditor.getSVGColorManager().setCurrentColor(color); currentItem.applyChanges(); refresh(); } } synchronized(this){isModified=true;} currentItem.applyChanges(); } } public void mouseDragged(MouseEvent e) { if(currentItem!=null){ Point point=getNormalizedPoint(e.getPoint()); if(point!=null && canDrag){ currentItem.setXPosition(point.x); positionValueTxt.setText(currentItem.getXPositionPercent()+"%"); refresh(); } } } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseMoved(MouseEvent e) { } /** * normalizes the point taken from the event * @param point the point passed by the event * @return the normalized point */ protected Point getNormalizedPoint(Point point){ Point pt=null; if(point!=null){ int x=0, y=0; //sets the x value at the limits if(point.x<0){ x=0; }else if(point.x>arrowsPanelSize.width){ x=(int)arrowsPanelSize.width; }else{ x=point.x; } y=point.y; pt=new Point(x, y); } return pt; } /** * @param point the position of the mouse * @return the corresponding item */ protected SVGGradientChooserItem getClickedItem(Point point){ if(point!=null){ SVGGradientChooserItem item=null; for(int i=gradientItems.size()-1;i>=0;i--){ try{ item=(SVGGradientChooserItem)gradientItems.get(i); }catch (Exception ex){item=null;} if(item!=null && item.belongsToThisItem(point)){ return item; } } } return null; } protected void selectGradientChooserItem(SVGGradientChooserItem gradientChooserItem){ if(gradientChooserItem!=null){ SVGGradientChooserItem item=null; //deselects all the items for(Iterator it=gradientItems.iterator(); it.hasNext();){ try{ item=(SVGGradientChooserItem)it.next(); }catch (Exception ex){item=null;} if(item!=null){ item.setSelected(false); } } //selects the given item gradientChooserItem.setSelected(true); } } /** * disposes the object */ public void dispose(){ currentItem=null; } }; //adds the listener to the mouse events on the arrows panel arrowsPanel.addMouseListener(arrowsListener); arrowsPanel.addMouseMotionListener(arrowsListener); //fills the gradient item list SVGVisualResourceObjectChild resChild=null; for(Iterator it=resourceObject.getChildren().iterator(); it.hasNext();){ try{ resChild=(SVGVisualResourceObjectChild)it.next(); }catch (Exception ex){resChild=null;} if(resChild!=null && arrowsListener!=null){ arrowsListener.createGradientItem(resChild); } } //the listeners to the add button final ActionListener addBtListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { SVGVisualResourceObjectChild resChild=resourceObject.createNewChild(); if(resChild!=null && arrowsListener!=null){ arrowsListener.createGradientItem(resChild); } } }; addBt.addActionListener(addBtListener); //the listeners to the delete button final ActionListener deleteBtListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { if(arrowsListener!=null){ arrowsListener.removeCurrentGradientItem(); } } }; deleteBt.addActionListener(deleteBtListener); //the listener to the color button final ActionListener colorBtListener=new ActionListener(){ public void actionPerformed(ActionEvent e) { Color color=SVGEditor.getColorChooser().showColorChooserDialog(SVGEditor.getColorChooser().getColor()); if(color!=null && arrowsListener!=null && arrowsListener.getCurrentItem()!=null){ colorPanel.setBackground(color); arrowsListener.getCurrentItem().setColor(color); SVGEditor.getSVGColorManager().setCurrentColor(color); arrowsListener.getCurrentItem().applyChanges(); arrowsListener.refresh(); } } }; colorBt.addActionListener(colorBtListener); //the listener to the slider final MouseAdapter sliderListener=new MouseAdapter(){ public void mouseReleased(MouseEvent evt) { arrowsListener.getCurrentItem().setOpacity(((double)slider.getValue())/100); arrowsListener.getCurrentItem().applyChanges(); gradientPanel.repaint(); } }; //adds a listener to the slider slider.addMouseListener(sliderListener); //a listener to modify the displayed value of the slider final ChangeListener sliderChangeListener=new ChangeListener(){ public void stateChanged(ChangeEvent evt) { arrowsListener.getCurrentItem().setOpacity(((double)slider.getValue())/100); displayedValue.setText(slider.getValue()+" %"); gradientPanel.repaint(); } }; //adds a listener to the slider slider.addChangeListener(sliderChangeListener); //dealing with the content panel// //the panel containing the widgets to modify the properties of an item JPanel propPanel=new JPanel(); TitledBorder border=new TitledBorder(stopProperties); border.setTitleFont(theFont); propPanel.setBorder(border); //sets the layout GridBagLayout gridBag0=new GridBagLayout(); propPanel.setLayout(gridBag0); //sets the layout constraints GridBagConstraints c0=new GridBagConstraints(); Insets insetsLbl0=new Insets(0, 0, 2, 2), insets0=new Insets(0, 2, 0, 2); //adding the offset widget c0.gridwidth=1; c0.insets=insetsLbl0; c0.anchor=GridBagConstraints.EAST; c0.fill=GridBagConstraints.NONE; gridBag0.setConstraints(offsetLbl, c0); propPanel.add(offsetLbl); c0.gridwidth=1; c0.insets=insets0; c0.anchor=GridBagConstraints.WEST; c0.fill=GridBagConstraints.NONE; gridBag0.setConstraints(positionValueTxt, c0); propPanel.add(positionValueTxt); //adding the color widget c0.gridwidth=1; c0.insets=insets0; c0.anchor=GridBagConstraints.EAST; c0.fill=GridBagConstraints.NONE; gridBag0.setConstraints(stopColorLbl, c0); propPanel.add(stopColorLbl); c0.gridwidth=GridBagConstraints.REMAINDER; c0.insets=insets0; c0.anchor=GridBagConstraints.WEST; c0.fill=GridBagConstraints.NONE; gridBag0.setConstraints(colorBt, c0); propPanel.add(colorBt); //adding the slider c0.gridwidth=1; c0.insets=insetsLbl0; c0.anchor=GridBagConstraints.EAST; c0.fill=GridBagConstraints.NONE; gridBag0.setConstraints(stopOpacityLbl, c0); propPanel.add(stopOpacityLbl); c0.gridwidth=GridBagConstraints.REMAINDER; c0.insets=insets0; c0.anchor=GridBagConstraints.WEST; c0.fill=GridBagConstraints.NONE; gridBag0.setConstraints(displayAndSlider, c0); propPanel.add(displayAndSlider); //building the main panel// //sets the content's layout GridBagLayout gridBag=new GridBagLayout(); content.setLayout(gridBag); //sets the layout constraints GridBagConstraints c=new GridBagConstraints(); c.fill=GridBagConstraints.NONE; //an empty panel JPanel empty=new JPanel(); c.gridwidth=1; gridBag.setConstraints(empty, c); content.add(empty); //the arrows panel c.gridwidth=GridBagConstraints.REMAINDER; c.anchor=GridBagConstraints.WEST; gridBag.setConstraints(arrowsPanel, c);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -