001: /*
002: * Created on Sep 30, 2004
003: *
004: * @author ctaylor
005: *
006: */
007: package com.pk.script.ui;
008:
009: import java.awt.Color;
010: import java.awt.GridBagConstraints;
011: import java.awt.GridBagLayout;
012: import java.awt.Insets;
013: import java.awt.event.ActionListener;
014: import java.util.List;
015:
016: import javax.swing.BorderFactory;
017: import javax.swing.BoxLayout;
018: import javax.swing.JButton;
019: import javax.swing.JCheckBox;
020: import javax.swing.JLabel;
021: import javax.swing.JPanel;
022: import javax.swing.JScrollPane;
023: import javax.swing.JTextArea;
024: import javax.swing.JTextField;
025:
026: import com.pk.CodeDocument;
027: import com.pk.script.ScriptCommand;
028:
029: /**
030: * @author ctaylor
031: *
032: */
033: public class DetailPanel extends JPanel {
034: /**
035: *
036: */
037: private static final long serialVersionUID = -7157415547408675119L;
038: private JTextArea commandText;
039: private JTextField statusField;
040: private JButton applyButton;
041: private JButton showErrorButton;
042: private JButton removeCommandButton;
043: private ActionListener actionListener;
044: private JCheckBox runCheckBox;
045: private ScriptCommand selectedScriptCommand = null;
046:
047: public DetailPanel(ActionListener argActionListener,
048: List argKeywords) {
049: actionListener = argActionListener;
050: if (argKeywords != null) {
051: CodeDocument codeDocument = new CodeDocument();
052: codeDocument.setKeywords(argKeywords);
053: commandText = new JTextArea(codeDocument, "", 12, 45);
054: } else {
055: commandText = new JTextArea("", 12, 45);
056: }
057: JScrollPane sqlScrollPane = new JScrollPane(commandText);
058: runCheckBox = new JCheckBox("Run");
059: applyButton = new JButton("Apply");
060: applyButton
061: .setToolTipText("Applies changes to currently selected command");
062: applyButton.addActionListener(actionListener);
063: this .setLayout(new GridBagLayout());
064: GridBagConstraints gbc = new GridBagConstraints();
065: gbc.anchor = GridBagConstraints.WEST;
066: gbc.insets = new Insets(6, 15, 6, 15);
067: statusField = new JTextField(10);
068: statusField.setEditable(false);
069: statusField.setBorder(BorderFactory
070: .createLineBorder(Color.black));
071:
072: gbc.gridx = 0;
073: gbc.gridy = 0;
074: this .add(sqlScrollPane, gbc);
075:
076: gbc.gridx = 1;
077:
078: JPanel panel = new JPanel();
079: BoxLayout layout = new BoxLayout(panel, BoxLayout.Y_AXIS);
080: panel.setLayout(layout);
081: panel.add(runCheckBox);
082: panel.add(new JLabel(" "));
083: panel.add(statusField);
084: panel.add(new JLabel(" "));
085: showErrorButton = new JButton("Show Error");
086: showErrorButton.setEnabled(false);
087: showErrorButton.addActionListener(actionListener);
088: panel.add(showErrorButton);
089: panel.add(new JLabel(" "));
090: removeCommandButton = new JButton("Remove");
091: removeCommandButton.addActionListener(actionListener);
092: panel.add(removeCommandButton);
093: panel.add(new JLabel(" "));
094: panel.add(applyButton);
095: this .add(panel, gbc);
096: gbc.gridx = 2;
097: gbc.gridy = 0;
098: //this.add(applyButton,gbc);
099: this .setBorder(BorderFactory.createLineBorder(Color.black));
100:
101: }
102:
103: /**
104: * @return Returns the applyButton.
105: */
106: public JButton getApplyButton() {
107: return applyButton;
108: }
109:
110: /**
111: * @return Returns the commandText.
112: */
113: public JTextArea getCommandText() {
114: return commandText;
115: }
116:
117: /**
118: * @return Returns the statusField.
119: */
120: public JTextField getStatusField() {
121: return statusField;
122: }
123:
124: /**
125: * @return Returns the showErrorButton.
126: */
127: public JButton getShowErrorButton() {
128: return showErrorButton;
129: }
130:
131: /**
132: * @return Returns the selectedScriptCommand.
133: */
134: public ScriptCommand getSelectedScriptCommand() {
135: return selectedScriptCommand;
136: }
137:
138: /**
139: * @param selectedScriptCommand The selectedScriptCommand to set.
140: */
141: public void setSelectedScriptCommand(
142: ScriptCommand argSelectedScriptCommand) {
143: if (argSelectedScriptCommand == null) {
144: commandText.setText("");
145: statusField.setText("");
146: runCheckBox.setSelected(false);
147: showErrorButton.setEnabled(false);
148:
149: } else {
150: commandText.setText(argSelectedScriptCommand.getCommand());
151: statusField.setText(argSelectedScriptCommand.getStatus());
152: runCheckBox.setSelected(argSelectedScriptCommand.isRun());
153: if (argSelectedScriptCommand.getErrorMessage() != null) {
154: showErrorButton.setEnabled(true);
155: } else {
156: showErrorButton.setEnabled(false);
157: }
158: }
159: this .selectedScriptCommand = argSelectedScriptCommand;
160: }
161:
162: /**
163: * @return Returns the runCheckBox.
164: */
165: public JCheckBox getRunCheckBox() {
166: return runCheckBox;
167: }
168:
169: /**
170: * @return Returns the removeCommand.
171: */
172: public JButton getRemoveCommandButton() {
173: return removeCommandButton;
174: }
175:
176: /**
177: * @param removeCommand The removeCommand to set.
178: */
179: public void setRemoveCommandButton(JButton removeCommand) {
180: this .removeCommandButton = removeCommand;
181: }
182:
183: public void setKeywords(List argKeywords) {
184: if (argKeywords != null) {
185: CodeDocument codeDocument = new CodeDocument();
186: codeDocument.setKeywords(argKeywords);
187: commandText.setDocument(codeDocument);
188: }
189: }
190: }
|