drawingattributes.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,803 行 · 第 1/5 页
JAVA
1,803 行
} /** * Get the pixel radius given to OMPoint objects. */ public int getPointRadius() { return pointRadius; } /** * Set the oval setting given to OMPoint objects. */ public void setPointOval(boolean value) { pointOval = value; } /** * Get the oval setting given to OMPoint objects. */ public boolean isPointOval() { return pointOval; } /** * Set the DrawingAttributes parameters based on the current settings of an * OMGraphic. */ public void setFrom(OMGraphic graphic) { setFrom(graphic, false); } /** * Set the DrawingAttributes parameters based on the current settings of an * OMGraphic, and reset the GUI of the DrawingAttributes object if desired. */ public void setFrom(OMGraphic graphic, boolean resetGUI) { if (graphic == null) return; matted = graphic.isMatted(); mattingPaint = graphic.getMattingPaint(); linePaint = graphic.getLinePaint(); selectPaint = graphic.getSelectPaint(); fillPaint = graphic.getFillPaint(); fillPattern = graphic.getTextureMask(); // Need to put this in to keep the gui up to date. Calling // setStroke fires off a propertyChange reaction that // potentially harms other parameters, like renderType. stroke = graphic.getStroke(); if (graphic instanceof OMPoint) { pointRadius = ((OMPoint) graphic).getRadius(); pointOval = ((OMPoint) graphic).isOval(); } enableFillPaintChoice = !(graphic instanceof NonRegional); // Don't want to call this here, it is CPU intensive. // resetGUI should be called only when the GUI needs to be // updated. if (resetGUI) { resetGUI(); } if (propertyChangeSupport != null) { propertyChangeSupport.firePropertyChange("all", true, true); } } /** * Set all the attributes for the graphic that are contained within this * DrawingAttributes class. * <P> * * If the fillPattern is set to a TexturePaint, and the fillPaint is null or * clear, then the fillPattern will be set as the fill paint. Otherwise, the * fillPaint will be set in the OMGraphic, and the fillPattern will be set * too. If the OMGraphic.textureMask is != null, then it will get painted on * top of the fillPaint. Makes for effects if the fillPattern has some * transparent spots. * * @param graphic OMGraphic. */ public void setTo(OMGraphic graphic) { setTo(graphic, false); } /** * Set all the attributes for the graphic that are contained within this * DrawingAttributes class. * <P> * * If the fillPattern is set to a TexturePaint, and the fillPaint is null or * clear, then the fillPattern will be set as the fill paint. Otherwise, the * fillPaint will be set in the OMGraphic, and the fillPattern will be set * too. If the OMGraphic.textureMask is != null, then it will get painted on * top of the fillPaint. Makes for effects if the fillPattern has some * transparent spots. * * @param graphic OMGraphic. * @param resetGUI reset the GUI if desired, set the enableFillPaintChoice * option if OMGraphic allows it. */ public void setTo(OMGraphic graphic, boolean resetGUI) { if (graphic == null) return; setOMGraphicEdgeAttributes(graphic); // If the fillPattern is set to a TexturePaint, and the // fillPaint is null or clear, then the fillPattern will be // set as the fill paint. Otherwise, the fillPaint will be // set in the OMGraphic, and the fillPattern will be set too. // If the OMGraphic.textureMask is != null, then it will get // painted on top of the fillPaint. Makes for effects if the // fillPattern has some transparent spots. if (fillPattern != null && (fillPaint == null || OMGraphic.isClear(fillPaint))) { graphic.setFillPaint(fillPattern); } else { graphic.setFillPaint(fillPaint); graphic.setTextureMask(fillPattern); } graphic.setMatted(matted); graphic.setMattingPaint(mattingPaint); if (graphic instanceof OMPoint) { ((OMPoint) graphic).setRadius(pointRadius); ((OMPoint) graphic).setOval(pointOval); } // The GraphicAttribute might be rendering options for this graphic, // needs to know if fill paint choices are available. if (resetGUI) { enableFillPaintChoice = !(graphic instanceof NonRegional); resetGUI(); } } /** * Set the graphic attributes that only pertain to boundaries. This is good * for polylines, where setting the fill paint will close up the polyline * making it a polygon. So if you want to paint edge data, use this * function. Sets line paint, line width, and stroke if graphic is a * OMGraphic * * @param graphic OMGraphic */ public void setOMGraphicEdgeAttributes(OMGraphic graphic) { graphic.setLinePaint(linePaint); graphic.setSelectPaint(selectPaint); if (stroke != null) { graphic.setStroke(stroke); } else { graphic.setStroke(OMGraphic.BASIC_STROKE); } } /** * Set all the attributes for the graphic that are contained within this * DrawingAttributes class. Get the TexturePaint for these attributes, and * scale it for the scale compaired to the base scale set. If the base scale * equals NONE, the fill pattern is not changed with relation to scale. * * @param graphic OMGraphic. * @param scale scale to compare to the base scale. */ public void setOMGraphicAttributesForScale(OMGraphic graphic, float scale) { setOMGraphicEdgeAttributesForScale(graphic, scale); graphic.setFillPaint(getFillPaintForScale(scale)); } /** * Set the graphic attributes that only pertain to boundaries. This is good * for polylines, where setting the fill paint will close up the polyline * making it a polygon. So if you want to paint edge data, use this * function. Sets line paint, line width, and stroke if graphic is a * OMGraphic The stroke, if the base scale is set, is adjusted accordingly. * * @param graphic OMGraphic. * @param scale scale to compare to the base scale. */ public void setOMGraphicEdgeAttributesForScale(OMGraphic graphic, float scale) { graphic.setLinePaint(linePaint); graphic.setSelectPaint(selectPaint); if (stroke != null) { graphic.setStroke(getStrokeForScale(scale)); } else { graphic.setStroke(OMGraphic.BASIC_STROKE); } } /** * A lock to use to limit the number of JColorChoosers that can pop up for a * given DrawingAttributes GUI. */ private boolean colorChooserLock = false; /** * Get the lock to use a JColorChooser. Returns true if you got the lock, * false if you didn't. */ protected synchronized boolean getLock() { if (colorChooserLock == false) { colorChooserLock = true; return colorChooserLock; } else { return false; } } /** * Release the lock on the JColorChooser. */ protected synchronized void releaseLock() { colorChooserLock = false; } /** * The DrawingAttributes method for handling ActionEvents. Used to handle * the GUI actions, like changing the colors, line widths, etc. */ public void actionPerformed(ActionEvent e) { Object source = e.getSource(); String command = e.getActionCommand(); String interString; Paint tmpPaint; if (command == LineColorCommand && linePaint instanceof Color) { interString = i18n.get(DrawingAttributes.class, "chooseLineColor", "Choose Line Color"); tmpPaint = getNewPaint((Component) source, interString, (Color) linePaint); if (tmpPaint != null) { setLinePaint(tmpPaint); lineButton.setIcon(getDrawingAttributesIcon(this, icon_width, icon_height, true)); } } else if (command == FillColorCommand && fillPaint instanceof Color) { interString = i18n.get(DrawingAttributes.class, "chooseFillColor", "Choose Fill Color"); tmpPaint = getNewPaint((Component) source, interString, (Color) fillPaint); if (tmpPaint != null) { setFillPaint(tmpPaint); lineButton.setIcon(getDrawingAttributesIcon(this, icon_width, icon_height, true)); } } else if (command == SelectColorCommand && selectPaint instanceof Color) { interString = i18n.get(DrawingAttributes.class, "chooseSelectColor", "Choose Select Color"); tmpPaint = getNewPaint((Component) source, interString, (Color) selectPaint); if (tmpPaint != null) { setSelectPaint(tmpPaint); } } else if (command == MattingColorCommand && mattingPaint instanceof Color) { interString = i18n.get(DrawingAttributes.class, "chooseMattingColor", "Choose Matting Color"); tmpPaint = getNewPaint((Component) source, interString, (Color) mattingPaint); if (tmpPaint != null) { setMattingPaint(tmpPaint); lineButton.setIcon(getDrawingAttributesIcon(this, icon_width, icon_height, true)); } } else if (command == MattedCommand) { setMatted(mattedEnabledItem.getState()); lineButton.setIcon(getDrawingAttributesIcon(this, icon_width, icon_height, true)); } else { if (Debug.debugging("drawingattributes")) { Debug.output("DrawingAttributes.actionPerformed: unrecognized command > " + command); } } } /** * A convenience method to get a color from a JColorChooser. Null will be * returned if the JColorChooser lock is in place, or if something else is * done where the JColorChooser would normally return null. * * @param source the source component for the JColorChooser. * @param title the String to label the JColorChooser window. * @param startingColor the color to give to the JColorChooser to start * with. Returned if the cancel button is pressed. * @return Color chosen from the JColorChooser, null if lock for chooser * can't be sequired. */ protected Color getNewPaint(Component source, String title, Color startingColor) { Color newPaint = null; if (getLock()) { newPaint = OMColorChooser.showDialog(source, title, startingColor); releaseLock(); } return newPaint; } protected JPanel palette = null; protected JToolBar toolbar = null; /** * Get the GUI components that control the DrawingAttributes. This method * gets the color and line toolbar and embeds it into a JPanel. */ public Component getGUI() { if (Debug.debugging("drawingattributes")) { Debug.output("DrawingAttributes: creating palette."); } return getColorAndLineGUI(); } /** * Gets the JToolBar that contains controls for changing the colors and line * stroke. You get the toolbar, so any additions to this tend to be a little * permanent. You might want to wrap this in a JPanel if you just want to * enhance the GUI, and add stuff to the panel instead. */ protected JPanel getColorAndLineGUI() { if (palette == null || toolbar == null) { palette = new JPanel(); if (Debug.debugging("layout")) { palette.setBorder(BorderFactory.createLineBorder(Color.red)); } GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?