2 * Copyright 2000-2007 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.ui
;
18 import com
.intellij
.openapi
.ui
.TextFieldWithBrowseButton
;
21 import javax
.swing
.event
.DocumentEvent
;
22 import java
.awt
.event
.ActionListener
;
24 public class FieldPanel
extends AbstractFieldPanel
{
25 private final JTextField myTextField
;
28 this(new JTextField(30));
31 protected FieldPanel(JTextField textField
) {
33 myTextField
= textField
;
37 public FieldPanel(String labelText
, final String viewerDialogTitle
, ActionListener browseButtonActionListener
, final Runnable documentListener
) {
38 this(new JTextField(30), labelText
, viewerDialogTitle
, browseButtonActionListener
, documentListener
);
41 public FieldPanel(JTextField textField
, String labelText
, final String viewerDialogTitle
, ActionListener browseButtonActionListener
, final Runnable documentListener
) {
42 super(textField
, labelText
, viewerDialogTitle
, browseButtonActionListener
, documentListener
);
43 myTextField
= textField
;
47 public void createComponent() {
48 super.createComponent();
49 TextFieldWithBrowseButton
.MyDoClickAction doClickAction
= getDoClickAction();
50 if (doClickAction
!= null) {
51 doClickAction
.registerShortcut(getTextField());
54 myTextField
.getDocument().addDocumentListener(new DocumentAdapter() {
55 public void textChanged(DocumentEvent event
) {
56 if (getChangeListener() != null) {
57 getChangeListener().run();
63 public String
getText() {
64 return myTextField
.getText();
67 public void setText(String text
) {
68 myTextField
.setText(text
);
71 public JTextField
getTextField() {
75 public static FieldPanel
create(String labelText
, String viewerDialogTitle
) {
76 return create(labelText
, viewerDialogTitle
, null, null);
79 public static FieldPanel
withPaths(String labelText
, String viewerDialogTitle
) {
80 return withPaths(labelText
, viewerDialogTitle
, null, null);
83 public static FieldPanel
withPaths(String labelText
, String viewerDialogTitle
, ActionListener browseButtonActionListener
, Runnable documentListener
) {
84 FieldPanel fieldPanel
= create(labelText
, viewerDialogTitle
, browseButtonActionListener
, documentListener
);
85 InsertPathAction
.addTo(fieldPanel
.myTextField
);
89 private static FieldPanel
create(String labelText
, String viewerDialogTitle
, ActionListener browseButtonActionListener
, Runnable documentListener
) {
90 return new FieldPanel(labelText
, viewerDialogTitle
, browseButtonActionListener
, documentListener
);
93 public void setEditable(boolean editable
) {
94 myTextField
.setEditable(editable
);
95 for (int i
= 0; i
< myButtons
.size(); i
++) {
96 JButton button
= (JButton
)myButtons
.get(i
);
97 button
.setEnabled(editable
);