drawingattributes.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,803 行 · 第 1/5 页
JAVA
1,803 行
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 // Old settings, with a button being added for each parameter. Now these // are adjusted on the popup menu. // toolbar.add(lineColorButton); // toolbar.add(fillColorButton); // toolbar.add(selectColorButton); // toolbar.add(mattingColorButton); // toolbar.add(new JLabel(" ")); // toolbar.add(mattedCheckBox); lineButton = new JButton(getDrawingAttributesIcon(this, icon_width, icon_height, true)); lineButton.setToolTipText(i18n.get(DrawingAttributes.class, "drawingAttributesButton", I18n.TOOLTIP, "Modify Drawing Parameters")); lineButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JButton button = getLineButton(); JPopupMenu popup = new JPopupMenu(); setPreStrokeMenuOptions(popup); setStrokeMenuOptions(popup); setPostStrokeMenuOptions(popup); popup.show(button, button.getWidth(), 0); } }); toolbar.add(lineButton); return palette; } /** * Callout method to add stuff to popup menu before the stroke editor is * consulted for additions. Adds colors and line menu additions (arrowhead * controls for lines, for instance). * * @param popup */ protected void setPreStrokeMenuOptions(JPopupMenu popup) { popup.add(getColorMenu()); JMenu[] menus = getLineMenuAdditions(); if (menus != null) { for (int i = 0; i < menus.length; i++) { JMenu menu = menus[i]; if (menu != null) { popup.add(menu); } } } } /** * Calls the editor for strokes to get popup menu addition for stroke * editing. * * @param popup */ protected void setStrokeMenuOptions(JPopupMenu popup) { if (stroke instanceof BasicStroke) { BasicStrokeEditorMenu tmpbse = getBasicStrokeEditor(); if (tmpbse != null) { tmpbse.setGUI(popup); } } } /** * Callout method to add stuff to menu after the stroke menus. * * @param popup */ protected void setPostStrokeMenuOptions(JPopupMenu popup) { // Nothing to add here... } /** * Get the JButton used to bring up the line menu. */ protected JButton getLineButton() { return lineButton; } /** * Gets the JMenu that has the color control options. * * @return */ public JMenu getColorMenu() { JMenu colorMenu = null; colorMenu = new JMenu(i18n.get(GraphicAttributes.class, "Color", "Color")); colorMenu.add(lineColorItem); colorMenu.add(fillColorItem); colorMenu.add(selectColorItem); colorMenu.add(mattingColorItem); colorMenu.add(new JSeparator()); colorMenu.add(mattedEnabledItem); fillColorItem.setEnabled(enableFillPaintChoice); return colorMenu; } /** * A hook to add to the line menu brought up in the GUI for the * DrawingAttributes. */ public void setLineMenuAdditions(JMenu[] lma) { lineMenuAdditions = lma; } public JMenu[] getLineMenuAdditions() { return lineMenuAdditions; } /** * Updates the color and line stroke control buttons to match the current * settings. */ public void resetGUI() { String interString; if (lineColorItem != null) { // lineColorButton.setIcon(getIconForPaint(getLinePaint(), false)); } else { // lineColorButton = new JButton(getIconForPaint(getLinePaint(), // false)); interString = i18n.get(DrawingAttributes.class, "lineColorItem", "Change Edge Color"); lineColorItem = new JMenuItem(interString); lineColorItem.setActionCommand(LineColorCommand); lineColorItem.addActionListener(this); interString = i18n.get(DrawingAttributes.class, "lineColorItem", I18n.TOOLTIP, "Change edge color for rendering."); lineColorItem.setToolTipText(interString); } if (fillColorItem != null) { // fillColorButton.setIcon(getIconForPaint(getFillPaint(), true)); } else { // fillColorButton = new JButton(getIconForPaint(getFillPaint(), // true)); interString = i18n.get(DrawingAttributes.class, "fillColorItem", "Change Fill Color"); fillColorItem = new JMenuItem(interString); fillColorItem.setActionCommand(FillColorCommand); fillColorItem.addActionListener(this); interString = i18n.get(DrawingAttributes.class, "fillColorItem", I18n.TOOLTIP, "Change fill color for rendering."); fillColorItem.setToolTipText(interString); } if (selectColorItem != null) { // selectColorButton.setIcon(getIconForPaint(getSelectPaint(), // false)); } else { // selectColorButton = new JButton(getIconForPaint(getSelectPaint(), // false)); interString = i18n.get(DrawingAttributes.class, "selectColorItem", "Change Highlight Edge Color"); selectColorItem = new JMenuItem(interString); selectColorItem.setActionCommand(SelectColorCommand); selectColorItem.addActionListener(this); interString = i18n.get(DrawingAttributes.class, "selectColorItem", I18n.TOOLTIP, "Change highlight edge color rendered during selection."); selectColorItem.setToolTipText(interString); } if (mattingColorItem != null) { // mattingColorButton.setIcon(getMattingIconForPaint()); } else { // mattingColorButton = new JButton(getMattingIconForPaint()); interString = i18n.get(DrawingAttributes.class, "mattingColorItem", "Change Matted Edge Color"); mattingColorItem = new JMenuItem(interString); mattingColorItem.setActionCommand(MattingColorCommand); mattingColorItem.addActionListener(this); interString = i18n.get(DrawingAttributes.class, "mattingColorItem", I18n.TOOLTIP, "Change the color of the border around the edge."); mattingColorItem.setToolTipText(interString); } if (mattedCheckBox != null) { // mattedCheckBox.setIcon(getMattedIcon(mattingPaint)); // mattedCheckBox.setSelected(matted); } else { // mattedCheckBox = new JToggleButton(getMattedIcon(mattingPaint), // isMatted()); interString = i18n.get(DrawingAttributes.class, "mattedEnableItem", "Enable Matting on Edge"); mattedEnabledItem = new JCheckBoxMenuItem(interString, matted); mattedEnabledItem.setActionCommand(MattedCommand); mattedEnabledItem.addActionListener(this); interString = i18n.get(DrawingAttributes.class, "mattedEnableItem", I18n.TOOLTIP, "Enable/Disable matting on edge."); mattedEnabledItem.setToolTipText(interString); } if (stroke instanceof BasicStroke) { BasicStrokeEditorMenu tmpbse = getBasicStrokeEditor(); if (tmpbse != null) { tmpbse.setBasicStroke((BasicStroke) stroke); } } } /** * Create an ImageIcon from a java.awt.Paint. * * @param paint java.awt.Paint * @param width icon pixel width * @param height icon pixel height */ public static ImageIcon getPaletteIcon(Paint paint, int width, int height) { BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics(); graphics.setPaint(paint); graphics.fillRect(0, 0, width, height); return new ImageIcon(bufferedImage); } /** * Get the PropertyChangeSupport object to register anything that is * interested in finding out when some parameter has changed. */ public PropertyChangeSupport getPropertyChangeSupport() { return propertyChangeSupport; } public void setPropertyChangeSupport(PropertyChangeSupport support) { propertyChangeSupport = support; } public static Color calculateTextColor(Color color) { if (alwaysSetTextToBlack) // Mac OS X return Color.black; int red = color.getRed(); int green = color.getGreen(); int blue = color.getBlue(); int alpha = color.getAlpha(); if (alpha < 128) return Color.black; int newred, newgreen, newblue; newred = normalizeOn128(red); newgreen = normalizeOn128(green); newblue = normalizeOn128(blue); return new Color(newred, newgreen, newblue); } public static int normalizeOn128(int value) { if (value >= 255) return 0; else if (value <= 0) return 255; else if (value <= 128) return 192; return 64; } /** * Sets the properties for the <code>DrawingAttributes</code>. This * particular method assumes that the marker name is not needed, because all * of the contents of this Properties object are to be used for this object, * and scoping the properties with a prefix is unnecessary. * * @param props the <code>Properties</code> object. */ public void setProperties(java.util.Properties props) { setProperties(getPropertyPrefix(), props); } public BasicStrokeEditorMenu getBasicStrokeEditor() { if (bse == null && stroke instanceof BasicStroke) { try { bse = new BasicStrokeEditorMenu((BasicStroke) getStroke()); bse.getPropertyChangeSupport().addPropertyChangeListener(this); } catch (Exception e) { // This happens if a java Toolkit is not available. bse = null; } } return bse; } /** * Sets the properties for the <code>DrawingAttributes</code>. Part of * the PropertyConsumer interface. DrawingAttributess which override this * method should do something like: * * <code><pre> * public void setProperties(String prefix, Properties props) { * super.setProperties(prefix, props); * // do local stuff * } * </pre></code> * * If the addToBeanContext property is not defined, it is set to false here. * * @param prefix the token to prefix the property names * @param props the <code>Properties</code> object */ public void setProperties(String prefix, Properties props) { propertyChangeSupport = new PropertyChangeSupport(this); setPropertyPrefix(prefix); if (props == null) { return; } String realPrefix = PropUtils.getScopedPropertyPrefix(prefix); // Set up the drawing attributes. linePaint = PropUtils.parseColorFromProperties(props, realPrefix + linePaintProperty, linePaint); selectPaint = PropUtils.parseColorFromProperties(props, realPrefix + selectPaintProperty, selectPaint); mattingPaint = PropUtils.parseColorFromProperties(props, realPrefix + mattingPaintProperty, mattingPaint);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?