Lines 17-52
Link Here
|
17 |
import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor; |
17 |
import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor; |
18 |
import javax.swing.*; |
18 |
import javax.swing.*; |
19 |
import javax.swing.border.*; |
19 |
import javax.swing.border.*; |
20 |
|
20 |
import javax.swing.text.JTextComponent; |
|
|
21 |
import java.awt.BorderLayout; |
21 |
/** A custom editor for Strings. |
22 |
/** A custom editor for Strings. |
22 |
* |
23 |
* |
23 |
* @author Ian Formanek |
24 |
* @author Ian Formanek, Tim Boudreau |
24 |
* @version 1.00, Sep 21, 1998 |
25 |
* @version 1.01, Mar 3, 2003 |
25 |
*/ |
26 |
*/ |
26 |
public class StringCustomEditor extends javax.swing.JPanel implements EnhancedCustomPropertyEditor { |
27 |
public class StringCustomEditor extends javax.swing.JPanel implements EnhancedCustomPropertyEditor { |
27 |
|
28 |
|
28 |
static final long serialVersionUID =7348579663907322425L; |
29 |
static final long serialVersionUID =7348579663907322425L; |
29 |
|
30 |
|
|
|
31 |
boolean oneline=false; |
32 |
String instructions = null; |
33 |
//enh 29294, provide one line editor on request |
34 |
StringCustomEditor (String value, boolean editable, boolean oneline, String instructions) { |
35 |
this.oneline = oneline; |
36 |
this.instructions = instructions; |
37 |
initComponents(); |
38 |
init (value, editable); |
39 |
} |
40 |
|
30 |
/** Initializes the Form */ |
41 |
/** Initializes the Form */ |
|
|
42 |
//constructor retained for backward compat (not that anyone should be |
43 |
//using it) |
31 |
public StringCustomEditor(String s, boolean editable) { |
44 |
public StringCustomEditor(String s, boolean editable) { |
32 |
initComponents (); |
45 |
initComponents (); |
33 |
|
46 |
init (s, editable); |
|
|
47 |
} |
48 |
|
49 |
private void init (String s, boolean editable) { |
50 |
//original constructor code |
34 |
textArea.setEditable(editable); |
51 |
textArea.setEditable(editable); |
35 |
textArea.setText (s); |
52 |
textArea.setText (s); |
36 |
textArea.setWrapStyleWord( true ); |
53 |
if (textArea instanceof JTextArea) { |
37 |
textArea.setLineWrap( true ); |
54 |
((JTextArea) textArea).setWrapStyleWord( true ); |
38 |
setBorder (new javax.swing.border.EmptyBorder (new java.awt.Insets(12, 12, 0, 11))); |
55 |
((JTextArea)textArea).setLineWrap( true ); |
39 |
setPreferredSize (new java.awt.Dimension(500, 300)); |
56 |
setPreferredSize (new java.awt.Dimension(500, 300)); |
|
|
57 |
if ( !editable ) { |
58 |
// hack to fix #9219 |
59 |
JTextField hack = new JTextField(); |
60 |
hack.setEditable( false ); |
61 |
textArea.setBackground( hack.getBackground() ); |
62 |
textArea.setForeground( hack.getForeground() ); |
63 |
} |
64 |
} else { |
65 |
textArea.setMinimumSize (new java.awt.Dimension (100, 20)); |
66 |
} |
67 |
setBorder (BorderFactory.createEmptyBorder(12,12,0,11)); |
40 |
|
68 |
|
41 |
textArea.getAccessibleContext().setAccessibleName(NbBundle.getBundle(StringCustomEditor.class).getString("ACS_TextArea")); |
69 |
textArea.getAccessibleContext().setAccessibleName(NbBundle.getBundle(StringCustomEditor.class).getString("ACS_TextArea")); //NOI18N |
42 |
textArea.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(StringCustomEditor.class).getString("ACSD_TextArea")); |
70 |
if (instructions == null) { |
43 |
getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(StringCustomEditor.class).getString("ACSD_CustomStringEditor")); |
71 |
textArea.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(StringCustomEditor.class).getString("ACSD_TextArea")); //NOI18N |
44 |
if ( !editable ) { |
72 |
} else { |
45 |
// hack to fix #9219 |
73 |
textArea.getAccessibleContext().setAccessibleDescription(instructions); |
46 |
JTextField hack = new JTextField(); |
74 |
} |
47 |
hack.setEditable( false ); |
75 |
getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(StringCustomEditor.class).getString("ACSD_CustomStringEditor")); //NOI18N |
48 |
textArea.setBackground( hack.getBackground() ); |
76 |
int prefHeight = textArea.getPreferredSize().height + 8; |
49 |
textArea.setForeground( hack.getForeground() ); |
77 |
|
|
|
78 |
if (instructions != null) { |
79 |
JTextArea jta = new JTextArea(instructions); |
80 |
jta.setEditable (false); |
81 |
java.awt.Color c = UIManager.getColor("control"); //NOI18N |
82 |
if (c != null) { |
83 |
jta.setBackground (c); |
84 |
} else { |
85 |
jta.setBackground (getBackground()); |
86 |
} |
87 |
jta.setLineWrap(true); |
88 |
jta.setWrapStyleWord(true); |
89 |
jta.setFont (getFont()); |
90 |
add (jta, BorderLayout.NORTH); |
91 |
jta.getAccessibleContext().setAccessibleName( |
92 |
NbBundle.getMessage(StringCustomEditor.class, |
93 |
"ACS_Instructions")); //NOI18N |
94 |
jta.getAccessibleContext().setAccessibleDescription( |
95 |
NbBundle.getMessage(StringCustomEditor.class, |
96 |
"ACSD_Instructions")); //NOI18N |
97 |
prefHeight += jta.getPreferredSize().height; |
98 |
} |
99 |
if (textArea instanceof JTextField) { |
100 |
setPreferredSize (new java.awt.Dimension (300, |
101 |
prefHeight)); |
50 |
} |
102 |
} |
51 |
} |
103 |
} |
52 |
|
104 |
|
Lines 61-88
Link Here
|
61 |
|
113 |
|
62 |
/** This method is called from within the constructor to |
114 |
/** This method is called from within the constructor to |
63 |
* initialize the form. |
115 |
* initialize the form. |
64 |
* WARNING: Do NOT modify this code. The content of this method is |
|
|
65 |
* always regenerated by the FormEditor. |
66 |
*/ |
116 |
*/ |
67 |
private void initComponents () {//GEN-BEGIN:initComponents |
117 |
private void initComponents () { |
68 |
setLayout (new java.awt.BorderLayout ()); |
118 |
setLayout (new java.awt.BorderLayout ()); |
|
|
119 |
if (oneline) { |
120 |
textArea = new javax.swing.JTextField(); |
121 |
add (textArea, BorderLayout.CENTER); |
122 |
} else { |
123 |
textAreaScroll = new javax.swing.JScrollPane (); |
124 |
textArea = new javax.swing.JTextArea (); |
125 |
textAreaScroll.setViewportView (textArea); |
126 |
add (textAreaScroll, BorderLayout.CENTER); |
127 |
} |
128 |
} |
69 |
|
129 |
|
70 |
textAreaScroll = new javax.swing.JScrollPane (); |
|
|
71 |
|
72 |
textArea = new javax.swing.JTextArea (); |
73 |
|
74 |
textAreaScroll.setViewportView (textArea); |
75 |
|
76 |
|
77 |
add (textAreaScroll, "Center"); // NOI18N |
78 |
|
79 |
}//GEN-END:initComponents |
80 |
|
81 |
|
82 |
|
83 |
// Variables declaration - do not modify//GEN-BEGIN:variables |
84 |
private javax.swing.JScrollPane textAreaScroll; |
130 |
private javax.swing.JScrollPane textAreaScroll; |
85 |
private javax.swing.JTextArea textArea; |
131 |
private JTextComponent textArea; |
86 |
// End of variables declaration//GEN-END:variables |
|
|
87 |
|
88 |
} |
132 |
} |