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

📄 drawingattributes.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * Set the pixel radius given to OMPoint objects.     */    public void setPointRadius(int radius) {        pointRadius = radius;    }    /**     * 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) {        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();        }        // Don't want to call this here, it is CPU intensive.        // resetGUI should be called only when the GUI needs to be        // updated.        //      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) {        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);        }    }    /**     * 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);            }        } 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);            }        } 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);            }        } else if (command == MattedCommand) {            JToggleButton check = (JToggleButton) e.getSource();            setMatted(check.isSelected());        } 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();            palette.setLayout(gridbag);            toolbar = new GridBagToolBar();            gridbag.setConstraints(toolbar, c);        }        resetGUI();        palette.removeAll(); // Remove cruft from past OMGraphics        toolbar.removeAll(); // Remove cruft from past OMGraphics        palette.add(toolbar); // Add back the basic toolbar        toolbar.add(lineColorButton);        toolbar.add(fillColorButton);        toolbar.add(selectColorButton);        toolbar.add(mattingColorButton);        toolbar.add(new JLabel(" "));        toolbar.add(mattedCheckBox);        if (stroke instanceof BasicStroke) {            BasicStrokeEditorMenu tmpbse = getBasicStrokeEditor();            if (tmpbse != null) {                ImageIcon icon = BasicStrokeEditorMenu.createIcon(tmpbse.getBasicStroke(),                        50,                        icon_height,                        true);                lineButton = new JButton(icon);                lineButton.setToolTipText(i18n.get(DrawingAttributes.class,                        "lineButton",                        I18n.TOOLTIP,                        "Modify Line Parameters"));                lineButton.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent ae) {                        JButton button = getLineButton();                        JPopupMenu popup = new JPopupMenu();                        JMenu menu = getLineTypeMenu();                        if (menu != null) {                            popup.add(menu);                        }                        getBasicStrokeEditor().setGUI(popup);                        JMenu[] menus = getLineMenuAdditions();                        if (menus != null) {

⌨️ 快捷键说明

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