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: ElementPropertyTitle.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: import javax.swing.*;
013:
014: import com.uwyn.rife.gui.Rife;
015: import com.uwyn.rife.gui.old.DynamicMenuBuilder;
016: import com.uwyn.rife.swing.JDialogError;
017: import com.uwyn.rife.swing.MouseMotionEventTranslator;
018: import com.uwyn.rife.tools.Localization;
019:
020: class ElementPropertyTitle extends ElementProperty {
021: public ElementPropertyTitle(Element element, String name) {
022: super (element, name);
023: }
024:
025: public boolean isValidName(String name) {
026: Component[] components = getElement().getParent()
027: .getComponents();
028:
029: Element element = null;
030: ElementPropertyTitle element_title = null;
031:
032: for (Component component : components) {
033: if (component instanceof Element
034: && component != getElement()) {
035: element = (Element) component;
036: element_title = (ElementPropertyTitle) element
037: .getTitle();
038: if (element_title.getName().equals(name)) {
039: return false;
040: }
041: }
042: }
043: return true;
044: }
045:
046: public void draw(Graphics2D g2d) {
047: Rectangle clip = g2d.getClipBounds();
048: if (clip == null || clip.intersects(getNameBounds())) {
049: g2d.setColor(getColor());
050: g2d.setFont(getDrawFont());
051: g2d
052: .drawString(
053: getName(),
054: (int) (getNameBounds().getX()),
055: (int) (getNameBounds().getY()
056: + getNameBounds().getHeight() - getElement()
057: .getElementStyleScaled().mTitleFontLineMetrics
058: .getDescent()));
059: }
060: }
061:
062: public Color getColor() {
063: return getElement().getElementStyleScaled().mTitleTextColor;
064: }
065:
066: public Font getDrawFont() {
067: return getElement().getElementStyleScaled().mTitleFont;
068: }
069:
070: public Font getEditFont() {
071: return getElement().getElementStyleScaled().mTitleFont;
072: }
073:
074: public int getEditAlignment() {
075: return JTextField.CENTER;
076: }
077:
078: public Rectangle getEditRectangle(Point clickedPoint) {
079: Rectangle2D hotspot_bounds = getHotSpot().getBounds2D();
080: ElementStyle element_style = getElement()
081: .getElementStyleScaled();
082: int title_width = (int) (Math.floor(hotspot_bounds.getWidth()) - Math
083: .ceil(element_style.mElementBorderWidth) * 2);
084: int title_height = (int) (Math
085: .floor(hotspot_bounds.getHeight()) - Math
086: .ceil(element_style.mElementBorderWidth) * 2);
087: int title_x = (int) (Math.floor(hotspot_bounds.getX()) + Math
088: .ceil(element_style.mElementBorderWidth));
089: int title_y = (int) (Math.floor(hotspot_bounds.getY()) + Math
090: .ceil(element_style.mElementBorderWidth));
091: return new Rectangle(title_x, title_y, title_width,
092: title_height);
093: }
094:
095: public JDialogError getUnicityErrorDialog() {
096: return new JDialogError(Rife.getMainFrame(),
097: "rife.dialog.titleexists.title", Localization
098: .getString("rife.dialog.titleexists.message"));
099: }
100:
101: protected void showPopupMenuReal(JPopupMenu popupMenu,
102: Point clickedPoint) {
103: DynamicMenuBuilder menu_builder = new DynamicMenuBuilder();
104: MouseMotionEventTranslator event_translator = new MouseMotionEventTranslator(
105: getElement());
106: JMenuItem menu_item = null;
107:
108: popupMenu.addMouseMotionListener(event_translator);
109: menu_item = menu_builder
110: .addMenuItem(
111: popupMenu,
112: Localization
113: .getString("rife.element.property.popupmenu.edit"),
114: new Edit(clickedPoint),
115: Localization
116: .getChar("rife.element.property.popupmenu.edit.mnemonic"));
117: menu_item.addMouseMotionListener(event_translator);
118: }
119: }
|