001: package newprocess.diagram.edit.policies;
002:
003: import org.eclipse.draw2d.ColorConstants;
004: import org.eclipse.draw2d.Figure;
005: import org.eclipse.draw2d.Graphics;
006: import org.eclipse.draw2d.IFigure;
007: import org.eclipse.draw2d.Label;
008: import org.eclipse.draw2d.RectangleFigure;
009: import org.eclipse.draw2d.geometry.Rectangle;
010: import org.eclipse.gef.editpolicies.SelectionEditPolicy;
011: import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
012:
013: /**
014: * @generated
015: */
016: public class New_processTextSelectionEditPolicy extends
017: SelectionEditPolicy {
018:
019: /**
020: * @generated
021: */
022: private IFigure selectionFeedbackFigure;
023:
024: /**
025: * @generated
026: */
027: private IFigure focusFeedbackFigure;
028:
029: /**
030: * @generated
031: */
032: protected void showPrimarySelection() {
033: if (getHostFigure() instanceof WrapLabel) {
034: ((WrapLabel) getHostFigure()).setSelected(true);
035: ((WrapLabel) getHostFigure()).setFocus(true);
036: } else {
037: showSelection();
038: showFocus();
039: }
040: }
041:
042: /**
043: * @generated
044: */
045: protected void showSelection() {
046: if (getHostFigure() instanceof WrapLabel) {
047: ((WrapLabel) getHostFigure()).setSelected(true);
048: ((WrapLabel) getHostFigure()).setFocus(false);
049: } else {
050: hideSelection();
051: addFeedback(selectionFeedbackFigure = createSelectionFeedbackFigure());
052: refreshSelectionFeedback();
053: hideFocus();
054: }
055: }
056:
057: /**
058: * @generated
059: */
060: protected void hideSelection() {
061: if (getHostFigure() instanceof WrapLabel) {
062: ((WrapLabel) getHostFigure()).setSelected(false);
063: ((WrapLabel) getHostFigure()).setFocus(false);
064: } else {
065: if (selectionFeedbackFigure != null) {
066: removeFeedback(selectionFeedbackFigure);
067: selectionFeedbackFigure = null;
068: }
069: hideFocus();
070: }
071: }
072:
073: /**
074: * @generated
075: */
076: protected void showFocus() {
077: if (getHostFigure() instanceof WrapLabel) {
078: ((WrapLabel) getHostFigure()).setFocus(true);
079: } else {
080: hideFocus();
081: addFeedback(focusFeedbackFigure = createFocusFeedbackFigure());
082: refreshFocusFeedback();
083: }
084: }
085:
086: /**
087: * @generated
088: */
089: protected void hideFocus() {
090: if (getHostFigure() instanceof WrapLabel) {
091: ((WrapLabel) getHostFigure()).setFocus(false);
092: } else {
093: if (focusFeedbackFigure != null) {
094: removeFeedback(focusFeedbackFigure);
095: focusFeedbackFigure = null;
096: }
097: }
098: }
099:
100: /**
101: * @generated
102: */
103: protected Rectangle getFeedbackBounds() {
104: Rectangle bounds;
105: if (getHostFigure() instanceof Label) {
106: bounds = ((Label) getHostFigure()).getTextBounds();
107: bounds.intersect(getHostFigure().getBounds());
108: } else {
109: bounds = getHostFigure().getBounds().getCopy();
110: }
111: getHostFigure().getParent().translateToAbsolute(bounds);
112: getFeedbackLayer().translateToRelative(bounds);
113: return bounds;
114: }
115:
116: /**
117: * @generated
118: */
119: protected IFigure createSelectionFeedbackFigure() {
120: if (getHostFigure() instanceof Label) {
121: Label feedbackFigure = new Label();
122: feedbackFigure.setOpaque(true);
123: feedbackFigure
124: .setBackgroundColor(ColorConstants.menuBackgroundSelected);
125: feedbackFigure
126: .setForegroundColor(ColorConstants.menuForegroundSelected);
127: return feedbackFigure;
128: } else {
129: RectangleFigure feedbackFigure = new RectangleFigure();
130: feedbackFigure.setFill(false);
131: return feedbackFigure;
132: }
133: }
134:
135: /**
136: * @generated
137: */
138: protected IFigure createFocusFeedbackFigure() {
139: return new Figure() {
140:
141: protected void paintFigure(Graphics graphics) {
142: graphics.drawFocus(getBounds().getResized(-1, -1));
143: }
144: };
145: }
146:
147: /**
148: * @generated
149: */
150: protected void updateLabel(Label target) {
151: Label source = (Label) getHostFigure();
152: target.setText(source.getText());
153: target.setTextAlignment(source.getTextAlignment());
154: target.setFont(source.getFont());
155: }
156:
157: /**
158: * @generated
159: */
160: protected void refreshSelectionFeedback() {
161: if (selectionFeedbackFigure != null) {
162: if (selectionFeedbackFigure instanceof Label) {
163: updateLabel((Label) selectionFeedbackFigure);
164: selectionFeedbackFigure.setBounds(getFeedbackBounds());
165: } else {
166: selectionFeedbackFigure.setBounds(getFeedbackBounds()
167: .expand(5, 5));
168: }
169: }
170: }
171:
172: /**
173: * @generated
174: */
175: protected void refreshFocusFeedback() {
176: if (focusFeedbackFigure != null) {
177: focusFeedbackFigure.setBounds(getFeedbackBounds());
178: }
179: }
180:
181: /**
182: * @generated
183: */
184: public void refreshFeedback() {
185: refreshSelectionFeedback();
186: refreshFocusFeedback();
187: }
188: }
|