001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.widgets; 003 004import javax.swing.JTextArea; 005import javax.swing.text.Document; 006 007/** 008 * Subclass of {@link JTextArea} that adds a "native" context menu (cut/copy/paste/select all). 009 * @since 5886 010 */ 011public class JosmTextArea extends JTextArea { 012 013 /** 014 * Constructs a new {@code JosmTextArea}. A default model is set, the initial string 015 * is null, and rows/columns are set to 0. 016 */ 017 public JosmTextArea() { 018 this(null, null, 0, 0); 019 } 020 021 /** 022 * Constructs a new {@code JosmTextArea} with the specified text displayed. 023 * A default model is created and rows/columns are set to 0. 024 * 025 * @param text the text to be displayed, or null 026 */ 027 public JosmTextArea(String text) { 028 this(null, text, 0, 0); 029 } 030 031 /** 032 * Constructs a new {@code JosmTextArea} with the given document model, and defaults 033 * for all of the other arguments (null, 0, 0). 034 * 035 * @param doc the model to use 036 */ 037 public JosmTextArea(Document doc) { 038 this(doc, null, 0, 0); 039 } 040 041 /** 042 * Constructs a new empty {@code JosmTextArea} with the specified number of 043 * rows and columns. A default model is created, and the initial 044 * string is null. 045 * 046 * @param rows the number of rows >= 0 047 * @param columns the number of columns >= 0 048 * @exception IllegalArgumentException if the rows or columns 049 * arguments are negative. 050 */ 051 public JosmTextArea(int rows, int columns) { 052 this(null, null, rows, columns); 053 } 054 055 /** 056 * Constructs a new {@code JosmTextArea} with the specified text and number 057 * of rows and columns. A default model is created. 058 * 059 * @param text the text to be displayed, or null 060 * @param rows the number of rows >= 0 061 * @param columns the number of columns >= 0 062 * @exception IllegalArgumentException if the rows or columns 063 * arguments are negative. 064 */ 065 public JosmTextArea(String text, int rows, int columns) { 066 this(null, text, rows, columns); 067 } 068 069 /** 070 * Constructs a new {@code JosmTextArea} with the specified number of rows 071 * and columns, and the given model. All of the constructors 072 * feed through this constructor. 073 * 074 * @param doc the model to use, or create a default one if null 075 * @param text the text to be displayed, null if none 076 * @param rows the number of rows >= 0 077 * @param columns the number of columns >= 0 078 * @exception IllegalArgumentException if the rows or columns 079 * arguments are negative. 080 */ 081 public JosmTextArea(Document doc, String text, int rows, int columns) { 082 super(doc, text, rows, columns); 083 TextContextualPopupMenu.enableMenuFor(this); 084 } 085}