822 * is no keymap entry. There is a variation across
823 * different VM's in what gets sent as a <em>key typed</em>
824 * event, and this action tries to filter out the undesired
825 * events. This filters the control characters and those
826 * with the ALT modifier. It allows Control-Alt sequences
827 * through as these form legitimate unicode characters on
828 * some PC keyboards.
829 * <p>
830 * If the event doesn't get filtered, it will try to insert
831 * content into the text editor. The content is fetched
832 * from the command string of the ActionEvent. The text
833 * entry is done through the <code>replaceSelection</code>
834 * method on the target text component. This is the
835 * action that will be fired for most text entry tasks.
836 * <p>
837 * <strong>Warning:</strong>
838 * Serialized objects of this class will not be compatible with
839 * future Swing releases. The current serialization support is
840 * appropriate for short term storage or RMI between applications running
841 * the same version of Swing. As of 1.4, support for long term storage
842 * of all JavaBeans™
843 * has been added to the <code>java.beans</code> package.
844 * Please see {@link java.beans.XMLEncoder}.
845 *
846 * @see DefaultEditorKit#defaultKeyTypedAction
847 * @see DefaultEditorKit#getActions
848 * @see Keymap#setDefaultAction
849 * @see Keymap#getDefaultAction
850 */
851 @SuppressWarnings("serial") // Same-version serialization only
852 public static class DefaultKeyTypedAction extends TextAction {
853
854 /**
855 * Creates this object with the appropriate identifier.
856 */
857 public DefaultKeyTypedAction() {
858 super(defaultKeyTypedAction);
859 }
860
861 /**
862 * The operation to perform when this action is triggered.
881 char c = content.charAt(0);
882 if ((isPrintableMask && (c >= 0x20) && (c != 0x7F)) ||
883 (!isPrintableMask && (c >= 0x200C) && (c <= 0x200D))) {
884 target.replaceSelection(content);
885 }
886 }
887 }
888 }
889 }
890
891 /**
892 * Places content into the associated document.
893 * If there is a selection, it is removed before
894 * the new content is added.
895 * <p>
896 * <strong>Warning:</strong>
897 * Serialized objects of this class will not be compatible with
898 * future Swing releases. The current serialization support is
899 * appropriate for short term storage or RMI between applications running
900 * the same version of Swing. As of 1.4, support for long term storage
901 * of all JavaBeans™
902 * has been added to the <code>java.beans</code> package.
903 * Please see {@link java.beans.XMLEncoder}.
904 *
905 * @see DefaultEditorKit#insertContentAction
906 * @see DefaultEditorKit#getActions
907 */
908 @SuppressWarnings("serial") // Same-version serialization only
909 public static class InsertContentAction extends TextAction {
910
911 /**
912 * Creates this object with the appropriate identifier.
913 */
914 public InsertContentAction() {
915 super(insertContentAction);
916 }
917
918 /**
919 * The operation to perform when this action is triggered.
920 *
921 * @param e the action event
930 String content = e.getActionCommand();
931 if (content != null) {
932 target.replaceSelection(content);
933 } else {
934 UIManager.getLookAndFeel().provideErrorFeedback(target);
935 }
936 }
937 }
938 }
939
940 /**
941 * Places a line/paragraph break into the document.
942 * If there is a selection, it is removed before
943 * the break is added.
944 * <p>
945 * <strong>Warning:</strong>
946 * Serialized objects of this class will not be compatible with
947 * future Swing releases. The current serialization support is
948 * appropriate for short term storage or RMI between applications running
949 * the same version of Swing. As of 1.4, support for long term storage
950 * of all JavaBeans™
951 * has been added to the <code>java.beans</code> package.
952 * Please see {@link java.beans.XMLEncoder}.
953 *
954 * @see DefaultEditorKit#insertBreakAction
955 * @see DefaultEditorKit#getActions
956 */
957 @SuppressWarnings("serial") // Same-version serialization only
958 public static class InsertBreakAction extends TextAction {
959
960 /**
961 * Creates this object with the appropriate identifier.
962 */
963 public InsertBreakAction() {
964 super(insertBreakAction);
965 }
966
967 /**
968 * The operation to perform when this action is triggered.
969 *
970 * @param e the action event
973 JTextComponent target = getTextComponent(e);
974 if (target != null) {
975 if ((! target.isEditable()) || (! target.isEnabled())) {
976 UIManager.getLookAndFeel().provideErrorFeedback(target);
977 return;
978 }
979 target.replaceSelection("\n");
980 }
981 }
982 }
983
984 /**
985 * Places a tab character into the document. If there
986 * is a selection, it is removed before the tab is added.
987 * <p>
988 * <strong>Warning:</strong>
989 * Serialized objects of this class will not be compatible with
990 * future Swing releases. The current serialization support is
991 * appropriate for short term storage or RMI between applications running
992 * the same version of Swing. As of 1.4, support for long term storage
993 * of all JavaBeans™
994 * has been added to the <code>java.beans</code> package.
995 * Please see {@link java.beans.XMLEncoder}.
996 *
997 * @see DefaultEditorKit#insertTabAction
998 * @see DefaultEditorKit#getActions
999 */
1000 @SuppressWarnings("serial") // Same-version serialization only
1001 public static class InsertTabAction extends TextAction {
1002
1003 /**
1004 * Creates this object with the appropriate identifier.
1005 */
1006 public InsertTabAction() {
1007 super(insertTabAction);
1008 }
1009
1010 /**
1011 * The operation to perform when this action is triggered.
1012 *
1013 * @param e the action event
1255 *
1256 * @param e the action event
1257 */
1258 public void actionPerformed(ActionEvent e) {
1259 JTextComponent target = getTextComponent(e);
1260 if (target != null) {
1261 target.setEditable(true);
1262 }
1263 }
1264 }
1265
1266 /**
1267 * Cuts the selected region and place its contents
1268 * into the system clipboard.
1269 * <p>
1270 * <strong>Warning:</strong>
1271 * Serialized objects of this class will not be compatible with
1272 * future Swing releases. The current serialization support is
1273 * appropriate for short term storage or RMI between applications running
1274 * the same version of Swing. As of 1.4, support for long term storage
1275 * of all JavaBeans™
1276 * has been added to the <code>java.beans</code> package.
1277 * Please see {@link java.beans.XMLEncoder}.
1278 *
1279 * @see DefaultEditorKit#cutAction
1280 * @see DefaultEditorKit#getActions
1281 */
1282 @SuppressWarnings("serial") // Same-version serialization only
1283 public static class CutAction extends TextAction {
1284
1285 /** Create this object with the appropriate identifier. */
1286 public CutAction() {
1287 super(cutAction);
1288 }
1289
1290 /**
1291 * The operation to perform when this action is triggered.
1292 *
1293 * @param e the action event
1294 */
1295 public void actionPerformed(ActionEvent e) {
1296 JTextComponent target = getTextComponent(e);
1297 if (target != null) {
1298 target.cut();
1299 }
1300 }
1301 }
1302
1303 /**
1304 * Copies the selected region and place its contents
1305 * into the system clipboard.
1306 * <p>
1307 * <strong>Warning:</strong>
1308 * Serialized objects of this class will not be compatible with
1309 * future Swing releases. The current serialization support is
1310 * appropriate for short term storage or RMI between applications running
1311 * the same version of Swing. As of 1.4, support for long term storage
1312 * of all JavaBeans™
1313 * has been added to the <code>java.beans</code> package.
1314 * Please see {@link java.beans.XMLEncoder}.
1315 *
1316 * @see DefaultEditorKit#copyAction
1317 * @see DefaultEditorKit#getActions
1318 */
1319 @SuppressWarnings("serial") // Same-version serialization only
1320 public static class CopyAction extends TextAction {
1321
1322 /** Create this object with the appropriate identifier. */
1323 public CopyAction() {
1324 super(copyAction);
1325 }
1326
1327 /**
1328 * The operation to perform when this action is triggered.
1329 *
1330 * @param e the action event
1331 */
1332 public void actionPerformed(ActionEvent e) {
1333 JTextComponent target = getTextComponent(e);
1334 if (target != null) {
1335 target.copy();
1336 }
1337 }
1338 }
1339
1340 /**
1341 * Pastes the contents of the system clipboard into the
1342 * selected region, or before the caret if nothing is
1343 * selected.
1344 * <p>
1345 * <strong>Warning:</strong>
1346 * Serialized objects of this class will not be compatible with
1347 * future Swing releases. The current serialization support is
1348 * appropriate for short term storage or RMI between applications running
1349 * the same version of Swing. As of 1.4, support for long term storage
1350 * of all JavaBeans™
1351 * has been added to the <code>java.beans</code> package.
1352 * Please see {@link java.beans.XMLEncoder}.
1353 *
1354 * @see DefaultEditorKit#pasteAction
1355 * @see DefaultEditorKit#getActions
1356 */
1357 @SuppressWarnings("serial") // Same-version serialization only
1358 public static class PasteAction extends TextAction {
1359
1360 /** Create this object with the appropriate identifier. */
1361 public PasteAction() {
1362 super(pasteAction);
1363 }
1364
1365 /**
1366 * The operation to perform when this action is triggered.
1367 *
1368 * @param e the action event
1369 */
1370 public void actionPerformed(ActionEvent e) {
1371 JTextComponent target = getTextComponent(e);
1372 if (target != null) {
1373 target.paste();
1374 }
1375 }
1376 }
1377
1378 /**
1379 * Creates a beep.
1380 * <p>
1381 * <strong>Warning:</strong>
1382 * Serialized objects of this class will not be compatible with
1383 * future Swing releases. The current serialization support is
1384 * appropriate for short term storage or RMI between applications running
1385 * the same version of Swing. As of 1.4, support for long term storage
1386 * of all JavaBeans™
1387 * has been added to the <code>java.beans</code> package.
1388 * Please see {@link java.beans.XMLEncoder}.
1389 *
1390 * @see DefaultEditorKit#beepAction
1391 * @see DefaultEditorKit#getActions
1392 */
1393 @SuppressWarnings("serial") // Same-version serialization only
1394 public static class BeepAction extends TextAction {
1395
1396 /** Create this object with the appropriate identifier. */
1397 public BeepAction() {
1398 super(beepAction);
1399 }
1400
1401 /**
1402 * The operation to perform when this action is triggered.
1403 *
1404 * @param e the action event
1405 */
1406 public void actionPerformed(ActionEvent e) {
|
822 * is no keymap entry. There is a variation across
823 * different VM's in what gets sent as a <em>key typed</em>
824 * event, and this action tries to filter out the undesired
825 * events. This filters the control characters and those
826 * with the ALT modifier. It allows Control-Alt sequences
827 * through as these form legitimate unicode characters on
828 * some PC keyboards.
829 * <p>
830 * If the event doesn't get filtered, it will try to insert
831 * content into the text editor. The content is fetched
832 * from the command string of the ActionEvent. The text
833 * entry is done through the <code>replaceSelection</code>
834 * method on the target text component. This is the
835 * action that will be fired for most text entry tasks.
836 * <p>
837 * <strong>Warning:</strong>
838 * Serialized objects of this class will not be compatible with
839 * future Swing releases. The current serialization support is
840 * appropriate for short term storage or RMI between applications running
841 * the same version of Swing. As of 1.4, support for long term storage
842 * of all JavaBeans
843 * has been added to the <code>java.beans</code> package.
844 * Please see {@link java.beans.XMLEncoder}.
845 *
846 * @see DefaultEditorKit#defaultKeyTypedAction
847 * @see DefaultEditorKit#getActions
848 * @see Keymap#setDefaultAction
849 * @see Keymap#getDefaultAction
850 */
851 @SuppressWarnings("serial") // Same-version serialization only
852 public static class DefaultKeyTypedAction extends TextAction {
853
854 /**
855 * Creates this object with the appropriate identifier.
856 */
857 public DefaultKeyTypedAction() {
858 super(defaultKeyTypedAction);
859 }
860
861 /**
862 * The operation to perform when this action is triggered.
881 char c = content.charAt(0);
882 if ((isPrintableMask && (c >= 0x20) && (c != 0x7F)) ||
883 (!isPrintableMask && (c >= 0x200C) && (c <= 0x200D))) {
884 target.replaceSelection(content);
885 }
886 }
887 }
888 }
889 }
890
891 /**
892 * Places content into the associated document.
893 * If there is a selection, it is removed before
894 * the new content is added.
895 * <p>
896 * <strong>Warning:</strong>
897 * Serialized objects of this class will not be compatible with
898 * future Swing releases. The current serialization support is
899 * appropriate for short term storage or RMI between applications running
900 * the same version of Swing. As of 1.4, support for long term storage
901 * of all JavaBeans
902 * has been added to the <code>java.beans</code> package.
903 * Please see {@link java.beans.XMLEncoder}.
904 *
905 * @see DefaultEditorKit#insertContentAction
906 * @see DefaultEditorKit#getActions
907 */
908 @SuppressWarnings("serial") // Same-version serialization only
909 public static class InsertContentAction extends TextAction {
910
911 /**
912 * Creates this object with the appropriate identifier.
913 */
914 public InsertContentAction() {
915 super(insertContentAction);
916 }
917
918 /**
919 * The operation to perform when this action is triggered.
920 *
921 * @param e the action event
930 String content = e.getActionCommand();
931 if (content != null) {
932 target.replaceSelection(content);
933 } else {
934 UIManager.getLookAndFeel().provideErrorFeedback(target);
935 }
936 }
937 }
938 }
939
940 /**
941 * Places a line/paragraph break into the document.
942 * If there is a selection, it is removed before
943 * the break is added.
944 * <p>
945 * <strong>Warning:</strong>
946 * Serialized objects of this class will not be compatible with
947 * future Swing releases. The current serialization support is
948 * appropriate for short term storage or RMI between applications running
949 * the same version of Swing. As of 1.4, support for long term storage
950 * of all JavaBeans
951 * has been added to the <code>java.beans</code> package.
952 * Please see {@link java.beans.XMLEncoder}.
953 *
954 * @see DefaultEditorKit#insertBreakAction
955 * @see DefaultEditorKit#getActions
956 */
957 @SuppressWarnings("serial") // Same-version serialization only
958 public static class InsertBreakAction extends TextAction {
959
960 /**
961 * Creates this object with the appropriate identifier.
962 */
963 public InsertBreakAction() {
964 super(insertBreakAction);
965 }
966
967 /**
968 * The operation to perform when this action is triggered.
969 *
970 * @param e the action event
973 JTextComponent target = getTextComponent(e);
974 if (target != null) {
975 if ((! target.isEditable()) || (! target.isEnabled())) {
976 UIManager.getLookAndFeel().provideErrorFeedback(target);
977 return;
978 }
979 target.replaceSelection("\n");
980 }
981 }
982 }
983
984 /**
985 * Places a tab character into the document. If there
986 * is a selection, it is removed before the tab is added.
987 * <p>
988 * <strong>Warning:</strong>
989 * Serialized objects of this class will not be compatible with
990 * future Swing releases. The current serialization support is
991 * appropriate for short term storage or RMI between applications running
992 * the same version of Swing. As of 1.4, support for long term storage
993 * of all JavaBeans
994 * has been added to the <code>java.beans</code> package.
995 * Please see {@link java.beans.XMLEncoder}.
996 *
997 * @see DefaultEditorKit#insertTabAction
998 * @see DefaultEditorKit#getActions
999 */
1000 @SuppressWarnings("serial") // Same-version serialization only
1001 public static class InsertTabAction extends TextAction {
1002
1003 /**
1004 * Creates this object with the appropriate identifier.
1005 */
1006 public InsertTabAction() {
1007 super(insertTabAction);
1008 }
1009
1010 /**
1011 * The operation to perform when this action is triggered.
1012 *
1013 * @param e the action event
1255 *
1256 * @param e the action event
1257 */
1258 public void actionPerformed(ActionEvent e) {
1259 JTextComponent target = getTextComponent(e);
1260 if (target != null) {
1261 target.setEditable(true);
1262 }
1263 }
1264 }
1265
1266 /**
1267 * Cuts the selected region and place its contents
1268 * into the system clipboard.
1269 * <p>
1270 * <strong>Warning:</strong>
1271 * Serialized objects of this class will not be compatible with
1272 * future Swing releases. The current serialization support is
1273 * appropriate for short term storage or RMI between applications running
1274 * the same version of Swing. As of 1.4, support for long term storage
1275 * of all JavaBeans
1276 * has been added to the <code>java.beans</code> package.
1277 * Please see {@link java.beans.XMLEncoder}.
1278 *
1279 * @see DefaultEditorKit#cutAction
1280 * @see DefaultEditorKit#getActions
1281 */
1282 @SuppressWarnings("serial") // Same-version serialization only
1283 public static class CutAction extends TextAction {
1284
1285 /** Create this object with the appropriate identifier. */
1286 public CutAction() {
1287 super(cutAction);
1288 }
1289
1290 /**
1291 * The operation to perform when this action is triggered.
1292 *
1293 * @param e the action event
1294 */
1295 public void actionPerformed(ActionEvent e) {
1296 JTextComponent target = getTextComponent(e);
1297 if (target != null) {
1298 target.cut();
1299 }
1300 }
1301 }
1302
1303 /**
1304 * Copies the selected region and place its contents
1305 * into the system clipboard.
1306 * <p>
1307 * <strong>Warning:</strong>
1308 * Serialized objects of this class will not be compatible with
1309 * future Swing releases. The current serialization support is
1310 * appropriate for short term storage or RMI between applications running
1311 * the same version of Swing. As of 1.4, support for long term storage
1312 * of all JavaBeans
1313 * has been added to the <code>java.beans</code> package.
1314 * Please see {@link java.beans.XMLEncoder}.
1315 *
1316 * @see DefaultEditorKit#copyAction
1317 * @see DefaultEditorKit#getActions
1318 */
1319 @SuppressWarnings("serial") // Same-version serialization only
1320 public static class CopyAction extends TextAction {
1321
1322 /** Create this object with the appropriate identifier. */
1323 public CopyAction() {
1324 super(copyAction);
1325 }
1326
1327 /**
1328 * The operation to perform when this action is triggered.
1329 *
1330 * @param e the action event
1331 */
1332 public void actionPerformed(ActionEvent e) {
1333 JTextComponent target = getTextComponent(e);
1334 if (target != null) {
1335 target.copy();
1336 }
1337 }
1338 }
1339
1340 /**
1341 * Pastes the contents of the system clipboard into the
1342 * selected region, or before the caret if nothing is
1343 * selected.
1344 * <p>
1345 * <strong>Warning:</strong>
1346 * Serialized objects of this class will not be compatible with
1347 * future Swing releases. The current serialization support is
1348 * appropriate for short term storage or RMI between applications running
1349 * the same version of Swing. As of 1.4, support for long term storage
1350 * of all JavaBeans
1351 * has been added to the <code>java.beans</code> package.
1352 * Please see {@link java.beans.XMLEncoder}.
1353 *
1354 * @see DefaultEditorKit#pasteAction
1355 * @see DefaultEditorKit#getActions
1356 */
1357 @SuppressWarnings("serial") // Same-version serialization only
1358 public static class PasteAction extends TextAction {
1359
1360 /** Create this object with the appropriate identifier. */
1361 public PasteAction() {
1362 super(pasteAction);
1363 }
1364
1365 /**
1366 * The operation to perform when this action is triggered.
1367 *
1368 * @param e the action event
1369 */
1370 public void actionPerformed(ActionEvent e) {
1371 JTextComponent target = getTextComponent(e);
1372 if (target != null) {
1373 target.paste();
1374 }
1375 }
1376 }
1377
1378 /**
1379 * Creates a beep.
1380 * <p>
1381 * <strong>Warning:</strong>
1382 * Serialized objects of this class will not be compatible with
1383 * future Swing releases. The current serialization support is
1384 * appropriate for short term storage or RMI between applications running
1385 * the same version of Swing. As of 1.4, support for long term storage
1386 * of all JavaBeans
1387 * has been added to the <code>java.beans</code> package.
1388 * Please see {@link java.beans.XMLEncoder}.
1389 *
1390 * @see DefaultEditorKit#beepAction
1391 * @see DefaultEditorKit#getActions
1392 */
1393 @SuppressWarnings("serial") // Same-version serialization only
1394 public static class BeepAction extends TextAction {
1395
1396 /** Create this object with the appropriate identifier. */
1397 public BeepAction() {
1398 super(beepAction);
1399 }
1400
1401 /**
1402 * The operation to perform when this action is triggered.
1403 *
1404 * @param e the action event
1405 */
1406 public void actionPerformed(ActionEvent e) {
|