?? drawingattributes.java
字號:
for (int i = 0; i < menus.length; i++) { menu = menus[i]; if (menu != null) { popup.add(menu); } } } popup.show(button, button.getWidth(), 0); } }); tmpbse.setLaunchButton(lineButton); toolbar.add(new JLabel(" ")); toolbar.add(lineButton); } } return palette; } /** * Get the JButton used to bring up the line menu. */ protected JButton getLineButton() { return lineButton; } /** * Get the menu that adjusts the line type. DrawingAttributes * doesn't know about this, but GraphicAttributes, the subclass, * does. */ public JMenu getLineTypeMenu() { return null; } /** * 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 (lineColorButton != null) { lineColorButton.setIcon(getIconForPaint(getLinePaint(), false)); } else { lineColorButton = new JButton(getIconForPaint(getLinePaint(), false)); lineColorButton.setActionCommand(LineColorCommand); lineColorButton.addActionListener(this); interString = i18n.get(DrawingAttributes.class, "lineColorButton", I18n.TOOLTIP, "Change Edge Color (true/opaque)"); lineColorButton.setToolTipText(interString); } if (fillColorButton != null) { fillColorButton.setIcon(getIconForPaint(getFillPaint(), true)); } else { fillColorButton = new JButton(getIconForPaint(getFillPaint(), true)); fillColorButton.setActionCommand(FillColorCommand); fillColorButton.addActionListener(this); interString = i18n.get(DrawingAttributes.class, "fillColorButton", I18n.TOOLTIP, "Change Fill Color (true/opaque)"); fillColorButton.setToolTipText(interString); } if (selectColorButton != null) { selectColorButton.setIcon(getIconForPaint(getSelectPaint(), false)); } else { selectColorButton = new JButton(getIconForPaint(getSelectPaint(), false)); selectColorButton.setActionCommand(SelectColorCommand); selectColorButton.addActionListener(this); interString = i18n.get(DrawingAttributes.class, "selectColorButton", I18n.TOOLTIP, "Change Highlight Edge Color (true/opaque)"); selectColorButton.setToolTipText(interString); } if (mattingColorButton != null) { mattingColorButton.setIcon(getMattingIconForPaint()); } else { mattingColorButton = new JButton(getMattingIconForPaint()); mattingColorButton.setActionCommand(MattingColorCommand); mattingColorButton.addActionListener(this); interString = i18n.get(DrawingAttributes.class, "mattingColorButton", I18n.TOOLTIP, "Change Matted Edge Color (true/opaque)"); mattingColorButton.setToolTipText(interString); } if (mattedCheckBox != null) { mattedCheckBox.setIcon(getMattedIcon()); mattedCheckBox.setSelected(matted); } else { mattedCheckBox = new JToggleButton(getMattedIcon(), isMatted()); mattedCheckBox.setActionCommand(MattedCommand); mattedCheckBox.addActionListener(this); interString = i18n.get(DrawingAttributes.class, "mattedCheckBox", I18n.TOOLTIP, "Enable/Disable Matting on Edge"); mattedCheckBox.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); // textPaint = // PropUtils.parseColorFromProperties( // props, realPrefix + textPaintProperty, // textPaint); fillPaint = PropUtils.parseColorFromProperties(props, realPrefix + fillPaintProperty, fillPaint); matted = PropUtils.booleanFromProperties(props, realPrefix + mattedProperty, matted); pointRadius = PropUtils.intFromProperties(props, realPrefix + PointRadiusProperty, pointRadius); pointOval = PropUtils.booleanFromProperties(props, realPrefix + PointOvalProperty, pointOval); float lineWidth; boolean basicStrokeDefined = false; if (stroke != null && stroke instanceof BasicStroke) { basicStrokeDefined = true; } lineWidth = PropUtils.floatFromProperties(props, realPrefix + lineWidthProperty, (basicStrokeDefined ? ((BasicStroke) stroke).getLineWidth() : defaultLineWidth)); baseScale = PropUtils.floatFromProperties(props, realPrefix + baseScaleProperty, baseScale); // Look for a dash pattern properties to come up with a stroke String dPattern = props.getProperty(realPrefix + dashPatternProperty); if (basicStrokeDefined && dPattern != null && !dPattern.equals("")) { float dashPhase; float[] lineDash; // OK, it exists, come up with a stroke. try { StringTokenizer t = new StringTokenizer(dPattern); int arraySize = t.countTokens(); lineDash = new float[arraySize]; int dashCount = 0; while (t.hasMoreTokens()) { String segment = t.nextToken(); lineDash[dashCount++] = Float.parseFloat(segment); if (Debug.debugging("drawingattributes")) { Debug.output("read " + segment); } } } catch (NoSuchElementException nsee) { Debug.error("DrawingAttributes.init: dash pattern attributes wrong - should be dashPattern=(number pixels on) (number pixels off)"); lineDash = null; } catch (NumberFormatException nfe) { Debug.error("DrawingAttributes.init: Number format exception for dashPattern"); lineDash = null; } catch (NullPointerException npe) { Debug.error("DrawingAttributes.init: Caught null pointer exception - probably resulting from non-float number format exception for dashPattern"); lineDash = null; } if (lineDash == null) { if (basicStrokeDefined) { lineDash = ((BasicStroke) stroke).getDashArray(); } else { lineDash = new float[2]; lineDash[0] = defaultDashLength; lineDash[1] = defaultDashLength; } } int dashCount = 0; for (int x = 0; x < lineDash.length; x++) { dashCount += lineDash[x]; } if (dashCount == 0) { lineDash = null; } String dPhase = props.getProperty(realPrefix + dashPhaseProperty); if (dPhase != null && !dPhase.equals("")) { try { dashPhase = Float.valueOf(dPhase).floatValue(); } catch (NumberFormatException nfe) { Debug.error("DrawingAttributes.init: Number format exception for dashPhase"); dashPhase = defaultDashPhase; } } else { if (basicStrokeDefined) { dashPhase = ((BasicStroke) stroke).getDashPhase(); } else { dashPhase = defaultDashPhase; } } setStroke(new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, lineDash, dashPhase)); } else if (basicStrokeDefined) { setStroke(new BasicStroke(lineWidth)); } // OK, Fill pattern next... fPattern = props.getProperty(realPrefix + fillPatternProperty); if (fPattern != null && !fPattern.equals("")) { try {
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -