001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: ElementPropertyParameter.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.gui.old;
009:
010: import java.awt.*;
011: import java.awt.geom.Rectangle2D;
012:
013: import javax.swing.JMenuItem;
014: import javax.swing.JPopupMenu;
015: import javax.swing.JTextField;
016:
017: import com.uwyn.rife.swing.MouseMotionEventTranslator;
018: import com.uwyn.rife.tools.Localization;
019:
020: abstract class ElementPropertyParameter extends ElementProperty {
021: public ElementPropertyParameter(Element element, String name) {
022: super (element, name);
023: }
024:
025: public void draw(Graphics2D g2d) {
026: Rectangle clip = g2d.getClipBounds();
027: if (clip == null || clip.intersects(getNameBounds())) {
028: Color backgroundColor = null;
029: ElementStyle element_style = getElement()
030: .getElementStyleScaled();
031: if (getElement().isSelected()) {
032: backgroundColor = element_style.mBodyBackgroundColorSelected;
033: } else {
034: backgroundColor = element_style.mBodyBackgroundColor;
035: }
036: element_style
037: .drawParameterText(
038: g2d,
039: getName(),
040: backgroundColor,
041: (int) (getNameBounds().getX()
042: + getNameBounds().getWidth() - element_style.mParamFontLineMetrics
043: .getDescent()),
044: (int) (getNameBounds().getY() + getNameBounds()
045: .getHeight()));
046: }
047: }
048:
049: public Color getColor() {
050: return getElement().getElementStyleScaled().mParamTextColor;
051: }
052:
053: public Font getDrawFont() {
054: return getElement().getElementStyleScaled().mParamFont;
055: }
056:
057: public Font getEditFont() {
058: return getElement().getElementStyleScaled().mParamFont;
059: }
060:
061: public int getEditAlignment() {
062: return JTextField.CENTER;
063: }
064:
065: public Rectangle getEditRectangle(Point clickedPoint) {
066: ElementStyle element_style = getElement()
067: .getElementStyleScaled();
068: Rectangle2D title_rect_outside_bounds = getElement()
069: .getTitleRectangleOutside().getBounds2D();
070: int parameter_width = (int) (Math
071: .floor(title_rect_outside_bounds.getX()
072: + title_rect_outside_bounds.getWidth()) - Math
073: .ceil(element_style.mElementBorderWidth) * 2);
074: int parameter_height = (int) (getEditFont().getLineMetrics("M",
075: element_style.mFontRenderContext).getHeight());
076: int parameter_x = (int) Math
077: .ceil(element_style.mElementBorderWidth);
078: int parameter_y = (int) (clickedPoint.getY() - parameter_height / 2);
079: return new Rectangle(parameter_x, parameter_y, parameter_width,
080: parameter_height);
081: }
082:
083: protected void showPopupMenuReal(JPopupMenu popupMenu,
084: Point clickedPoint) {
085: DynamicMenuBuilder menu_builder = new DynamicMenuBuilder();
086: MouseMotionEventTranslator event_translator = new MouseMotionEventTranslator(
087: getElement());
088: JMenuItem menu_item = null;
089:
090: popupMenu.addMouseMotionListener(event_translator);
091: menu_item = menu_builder
092: .addMenuItem(
093: popupMenu,
094: Localization
095: .getString("rife.element.property.popupmenu.edit"),
096: new Edit(clickedPoint),
097: Localization
098: .getChar("rife.element.property.popupmenu.edit.mnemonic"));
099: menu_item.addMouseMotionListener(event_translator);
100: menu_item = menu_builder
101: .addMenuItem(
102: popupMenu,
103: Localization
104: .getString("rife.element.property.popupmenu.delete"),
105: new Delete(),
106: Localization
107: .getChar("rife.element.property.popupmenu.delete.mnemonic"));
108: menu_item.addMouseMotionListener(event_translator);
109: }
110: }
|