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

📄 editableomtext.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                llp1 = projection.inverse(gpc.getX(), gpc.getY());                text.setLat(llp1.getLatitude());                text.setLon(llp1.getLongitude());                // text.setNeedToRegenerate set            }        }        boolean settingOffset = getStateMachine().getState() instanceof GraphicSetOffsetState                && movingPoint == gpo;        // If the center point is moving, the offset distance changes        if (renderType == OMGraphic.RENDERTYPE_OFFSET) {            llp1 = projection.inverse(gpo.getX(), gpo.getY());            text.setLat(llp1.getLatitude());            text.setLon(llp1.getLongitude());            if (settingOffset || movingPoint == gpc) {                // Don't call point.setLocation because we only want                // to                // setNeedToRegenerate if !settingOffset.                text.setX(gpc.getX() - gpo.getX());                text.setY(gpc.getY() - gpo.getY());            }            if (!settingOffset) {                text.setX(gpc.getX() - gpo.getX());                text.setY(gpc.getY() - gpo.getY());            }            // Set Location has reset the rendertype, but provides            // the convenience of setting the max and min values            // for us.            text.setRenderType(OMGraphic.RENDERTYPE_OFFSET);        }        // Do the point height and width for XY and OFFSET render        // types.        if (renderType == OMGraphic.RENDERTYPE_XY) {            if (movingPoint == gpc) {                text.setX(gpc.getX());                text.setY(gpc.getY());            }        }        if (projection != null) {            regenerate(projection);        }    }    /**     * Get whether a graphic can be manipulated by its edges, rather     * than just by its grab points.     */    public boolean getCanGrabGraphic() {        return false;    }    /**     * Called to set the OffsetGrabPoint to the current mouse     * location, and update the OffsetGrabPoint with all the other     * GrabPoint locations, so everything can shift smoothly. Should     * also set the OffsetGrabPoint to the movingPoint. Should be     * called only once at the beginning of the general movement, in     * order to set the movingPoint. After that, redraw(e) should just     * be called, and the movingPoint will make the adjustments to the     * graphic that are needed.     */    public void move(java.awt.event.MouseEvent e) {}    /**     * Use the current projection to place the graphics on the screen.     * Has to be called to at least assure the graphics that they are     * ready for rendering. Called when the graphic position changes.     *      * @param proj com.bbn.openmap.proj.Projection     * @return true     */    public boolean generate(Projection proj) {        if (text != null)            text.regenerate(proj);        for (int i = 0; i < gPoints.length; i++) {            GrabPoint gp = gPoints[i];            if (gp != null) {                gp.generate(proj);            }        }        return true;    }    /**     * Given a new projection, the grab points may need to be     * repositioned off the current position of the graphic. Called     * when the projection changes.     */    public void regenerate(Projection proj) {        if (text != null)            text.regenerate(proj);        setGrabPoints(text);        generate(proj);    }    /**     * Draw the EditableOMtext parts into the java.awt.Graphics     * object. The grab points are only rendered if the point machine     * state is TextSelectedState.TEXT_SELECTED.     *      * @param graphics java.awt.Graphics.     */    public void render(java.awt.Graphics graphics) {        State state = getStateMachine().getState();        if (!(state instanceof GraphicUndefinedState)) {            if (text != null) {                text.setVisible(true);                text.render(graphics);                text.setVisible(false);            } else {                Debug.message("eomg", "EditableOMText.render: null point.");            }            int renderType = text.getRenderType();            if (state instanceof GraphicSelectedState                    || state instanceof GraphicEditState) {                for (int i = 0; i < gPoints.length; i++) {                    GrabPoint gp = gPoints[i];                    if (gp != null) {                        if ((i == OFFSET_POINT_INDEX                                && renderType == OMGraphic.RENDERTYPE_OFFSET && movingPoint == gpo)                                ||                                (state instanceof GraphicSelectedState && ((i != OFFSET_POINT_INDEX && renderType != OMGraphic.RENDERTYPE_OFFSET) || (renderType == OMGraphic.RENDERTYPE_OFFSET)))                        ) {                            gp.setVisible(true);                            gp.render(graphics);                            gp.setVisible(false);                        }                    }                }            }        }    }    /**     * If this EditableOMGraphic has parameters that can be     * manipulated that are independent of other EditableOMGraphic     * types, then you can provide the widgets to control those     * parameters here. By default, returns the GraphicAttributes GUI     * widgets. If you don't want a GUI to appear when a widget is     * being created/edited, then don't call this method from the     * EditableOMGraphic implementation, and return a null Component     * from getGUI.     *      * @param graphicAttributes the GraphicAttributes to use to get     *        the GUI widget from to control those parameters for this     *        EOMG.     * @return java.awt.Component to use to control parameters for     *         this EOMG.     */    public java.awt.Component getGUI(GraphicAttributes graphicAttributes) {        Debug.message("eomg", "EditableOMPoly.getGUI");        if (graphicAttributes != null) {            Component gaGUI = graphicAttributes.getGUI();            ((JComponent) gaGUI).add(getTextGUI());            return gaGUI;        } else {            return getTextGUI();        }    }    JComboBox sizesFont;    JToggleButton boldFont;    JToggleButton italicFont;    /** Command for text string adjustments. */    public final static String TextFieldCommand = "TextField";    public final static String TextFontCommand = "TextFont";    public final static String TextRotationCommand = "TextRotation";    protected java.awt.Component getTextGUI() {        javax.swing.Box attributeBox = javax.swing.Box.createHorizontalBox();        attributeBox.setAlignmentX(Component.CENTER_ALIGNMENT);        attributeBox.setAlignmentY(Component.CENTER_ALIGNMENT);        String textString = "Text";        if (text != null) {            textString = text.getData();        }        JTextField textField = new JTextField(textString, 25);        textField.setActionCommand(TextFieldCommand);        textField.addActionListener(this);        textField.setMargin(new Insets(0, 1, 0, 1));        textField.setMinimumSize(new java.awt.Dimension(100, 20));        textField.setPreferredSize(new java.awt.Dimension(100, 20));        attributeBox.add(textField);        // JPanel palette =        // PaletteHelper.createHorizontalPanel("Rotation");        javax.swing.Box palette = javax.swing.Box.createHorizontalBox();        textField = new JTextField(Integer.toString((int) (text.getRotationAngle() * 180 / Math.PI)), 5);        textField.setActionCommand(TextRotationCommand);        textField.setToolTipText(i18n.get(EditableOMText.class,                "textField",                I18n.TOOLTIP,                "Text rotation in degrees"));        textField.setMargin(new Insets(0, 1, 0, 1));        textField.addActionListener(this);        textField.setMinimumSize(new java.awt.Dimension(30, 20));        textField.setPreferredSize(new java.awt.Dimension(30, 20));        palette.add(textField);        palette.add(new JLabel("\u00b0 "));        attributeBox.add(palette);        String[] sizesStrings = { "3", "5", "8", "10", "12", "14", "18", "20",                "24", "36", "48" };        sizesFont = new JComboBox(sizesStrings);        sizesFont.setToolTipText(i18n.get(EditableOMText.class,                "sizesFont",                I18n.TOOLTIP,                "Font Size"));        sizesFont.setSelectedItem("" + (text.getFont()).getSize());        sizesFont.setActionCommand(TextFontCommand);        sizesFont.addActionListener(this);        int textButtonWidth = 10;        int textButtonHeight = 15;        boldFont = new JToggleButton();        boldFont.setIcon(getTextAccentToggleButtonImage(textButtonWidth,                textButtonHeight,                new Font(boldFont.getFont().getName(), Font.BOLD, boldFont.getFont()                        .getSize()),                "B"));        // Too wide margins for 1 letter look unnatural        Insets insets = boldFont.getInsets();        insets.left = insets.left / 2;        insets.right = insets.right / 2;        boldFont.setMargin(insets);        boldFont.setSelected(text.getFont().isBold());        boldFont.setToolTipText(i18n.get(EditableOMText.class,                "boldFont",                I18n.TOOLTIP,                "Bold Font"));        boldFont.setActionCommand(TextFontCommand);        boldFont.addActionListener(this);        italicFont = new JToggleButton();        italicFont.setIcon(getTextAccentToggleButtonImage(textButtonWidth,                textButtonHeight,                new Font(italicFont.getFont().getName(), Font.ITALIC, italicFont.getFont()                        .getSize()),                "I"));        italicFont.setMargin(insets);        italicFont.setSelected(text.getFont().isItalic());        italicFont.setToolTipText(i18n.get(EditableOMText.class,                "italicFont",                I18n.TOOLTIP,                "Italic Font"));        italicFont.setActionCommand(TextFontCommand);        italicFont.addActionListener(this);        attributeBox.add(sizesFont);        attributeBox.add(boldFont);        attributeBox.add(italicFont);        return attributeBox;    }    private ImageIcon getTextAccentToggleButtonImage(int width, int height,                                                     Font f, String s) {        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);        Graphics g = bi.getGraphics();        g.setFont(f);        g.setColor(Color.black);        FontMetrics fm = g.getFontMetrics();        int stringWidth = fm.stringWidth(s);        int stringHeight = f.getSize() - 2;        g.drawString(s, (width - stringWidth) / 2, height - (height - stringHeight) / 2);        return new ImageIcon(bi);    }    public void actionPerformed(ActionEvent e) {        Object source = e.getSource();        String command = e.getActionCommand();        if (command == TextFontCommand) {            String FontString = OMText.fontToXFont(text.getFont());            FontString = FontString.substring(0, FontString.indexOf("-", 3));            StringBuffer ret = new StringBuffer(FontString);            if (boldFont.isSelected())                ret.append("-bold");            else                ret.append("-normal");            if (italicFont.isSelected())                ret.append("-i");            else                ret.append("-o");            ret.append("-normal");            ret.append("--" + sizesFont.getSelectedItem());            ret.append("-*-*-*-*-*-*");            ret.toString();            text.setFont(OMText.rebuildFont(ret.toString()));            repaint();        } else if (command == TextFieldCommand) {            text.setData(((JTextField) source).getText());            text.regenerate(projection);            repaint();        } else if (command == TextRotationCommand) {            Integer rotation = new Integer(((JTextField) source).getText());            text.setRotationAngle(Math.PI / 180 * (rotation.intValue() % 360));            text.regenerate(projection);            repaint();        }    }}

⌨️ 快捷键说明

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