001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.lib.client.components;
015:
016: import org.jetbrains.annotations.NotNull;
017: import org.pentaho.reportdesigner.crm.report.IconLoader;
018: import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
019:
020: import javax.swing.*;
021: import javax.swing.text.JTextComponent;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.MouseAdapter;
024: import java.awt.event.MouseEvent;
025:
026: /**
027: * User: Martin
028: * Date: 23.02.2006
029: * Time: 13:19:01
030: */
031: public class TextComponentHelper {
032: private TextComponentHelper() {
033: }
034:
035: public static void installDefaultPopupMenu(@NotNull
036: final JTextComponent textComponent) {
037: textComponent.addMouseListener(new MouseAdapter() {
038: public void mouseClicked(@NotNull
039: MouseEvent e) {
040: popup(e);
041: }
042:
043: public void mousePressed(@NotNull
044: MouseEvent e) {
045: popup(e);
046: }
047:
048: public void mouseReleased(@NotNull
049: MouseEvent e) {
050: popup(e);
051: }
052:
053: private void popup(@NotNull
054: final MouseEvent me) {
055: if (me.isPopupTrigger()) {
056: JPopupMenu popupMenu = new JPopupMenu();
057: AbstractAction cutAction = new AbstractAction(
058: TranslationManager
059: .getInstance()
060: .getTranslation(
061: TranslationManager.COMMON_BUNDLE_PREFIX,
062: "CutCommand.Text"),
063: IconLoader.getInstance().getCutIcon()) {
064: public void actionPerformed(@NotNull
065: ActionEvent e) {
066: textComponent.cut();
067: }
068: };
069: popupMenu.add(cutAction);
070: AbstractAction copyAction = new AbstractAction(
071: TranslationManager
072: .getInstance()
073: .getTranslation(
074: TranslationManager.COMMON_BUNDLE_PREFIX,
075: "CopyCommand.Text"),
076: IconLoader.getInstance().getCopyIcon()) {
077: public void actionPerformed(@NotNull
078: ActionEvent e) {
079: textComponent.copy();
080: }
081: };
082: popupMenu.add(copyAction);
083: AbstractAction pasteAction = new AbstractAction(
084: TranslationManager
085: .getInstance()
086: .getTranslation(
087: TranslationManager.COMMON_BUNDLE_PREFIX,
088: "PasteCommand.Text"),
089: IconLoader.getInstance().getPasteIcon()) {
090: public void actionPerformed(@NotNull
091: ActionEvent e) {
092: textComponent.paste();
093: }
094: };
095: popupMenu.add(pasteAction);
096:
097: cutAction.setEnabled(textComponent.isEditable());
098: pasteAction.setEnabled(textComponent.isEditable());
099:
100: popupMenu.show(textComponent, me.getX(), me.getY());
101: }
102: }
103: });
104: }
105: }
|