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: ElementPropertyExit.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 ElementPropertyExit extends ElementProperty {
021: public ElementPropertyExit(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: g2d.setColor(getColor());
029: g2d.setFont(getDrawFont());
030: g2d
031: .drawString(
032: getName(),
033: (int) (getNameBounds().getX()),
034: (int) (getNameBounds().getY()
035: + getNameBounds().getHeight() - getElement()
036: .getElementStyleScaled().mExitFontLineMetrics
037: .getDescent()));
038: }
039: }
040:
041: public Color getColor() {
042: return getElement().getElementStyleScaled().mExitTextColor;
043: }
044:
045: public Font getDrawFont() {
046: return getElement().getElementStyleScaled().mExitFont;
047: }
048:
049: public Font getEditFont() {
050: return getElement().getElementStyleScaled().mExitFont;
051: }
052:
053: public int getEditAlignment() {
054: return JTextField.RIGHT;
055: }
056:
057: public Rectangle getEditRectangle(Point clickedPoint) {
058: Rectangle2D hotspot_bounds = getHotSpot().getBounds2D();
059: ElementStyle element_style = getElement()
060: .getElementStyleScaled();
061: int exit_width = (int) (Math.ceil(hotspot_bounds.getWidth()) - Math
062: .ceil(element_style.mElementBorderWidth));
063: int exit_height = (int) (Math.floor(hotspot_bounds.getHeight()) - Math
064: .ceil(element_style.mElementBorderWidth * 2));
065: int exit_x = (int) (Math.floor(hotspot_bounds.getX()));
066: int exit_y = (int) (Math.floor(hotspot_bounds.getY()) + Math
067: .floor(element_style.mElementBorderWidth));
068: return new Rectangle(exit_x, exit_y, exit_width, exit_height);
069: }
070:
071: public JDialogError getUnicityErrorDialog() {
072: return new JDialogError(Rife.getMainFrame(),
073: "rife.dialog.exitexists.title", Localization
074: .getString("rife.dialog.exitexists.message"));
075: }
076:
077: protected void showPopupMenuReal(JPopupMenu popupMenu,
078: Point clickedPoint) {
079: DynamicMenuBuilder menu_builder = new DynamicMenuBuilder();
080: MouseMotionEventTranslator event_translator = new MouseMotionEventTranslator(
081: getElement());
082: JMenuItem menu_item = null;
083:
084: popupMenu.addMouseMotionListener(event_translator);
085: menu_item = menu_builder
086: .addMenuItem(
087: popupMenu,
088: Localization
089: .getString("rife.element.property.popupmenu.edit"),
090: new Edit(clickedPoint),
091: Localization
092: .getChar("rife.element.property.popupmenu.edit.mnemonic"));
093: menu_item.addMouseMotionListener(event_translator);
094: menu_item = menu_builder
095: .addMenuItem(
096: popupMenu,
097: Localization
098: .getString("rife.element.property.popupmenu.delete"),
099: new Delete(),
100: Localization
101: .getChar("rife.element.property.popupmenu.delete.mnemonic"));
102: menu_item.addMouseMotionListener(event_translator);
103: }
104: }
|