001: /**
002: * Copyright 2004 Carlos Silva A.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: */package com.csa.lgantt.view.dialogs;
017:
018: import java.awt.BorderLayout;
019: import java.awt.Window;
020: import java.awt.event.ActionEvent;
021: import java.awt.event.ActionListener;
022: import java.awt.event.FocusEvent;
023: import java.awt.event.FocusListener;
024: import java.util.Date;
025:
026: import javax.swing.JLabel;
027: import javax.swing.JPanel;
028: import javax.swing.JScrollPane;
029: import javax.swing.JTabbedPane;
030: import javax.swing.JTextArea;
031: import javax.swing.JTextField;
032: import javax.swing.SwingConstants;
033: import javax.swing.border.TitledBorder;
034:
035: import com.csa.lgantt.Messages;
036: import com.csa.lgantt.model.Project;
037: import com.csa.lgantt.model.Task;
038: import com.csa.lgantt.view.LabeledPairLayout;
039: import com.csa.lgantt.view.adapters.ProjectViewModel;
040: import com.csa.lgantt.view.adapters.ProjectViewModelChange;
041: import com.csa.lgantt.view.adapters.ProjectViewModelListener;
042: import com.csa.lib.swing.DateField;
043:
044: /**
045: * TaskEditor edita una tarea Task.
046: *
047: * @version $Header: /cvs/java/App_JGantt/source/com/csa/lgantt/view/dialogs/TaskEditor.java,v 1.2 2006/10/10 02:47:57 csilva Exp $
048: * @author Carlos Silva
049: */
050: public class TaskEditor extends JTabbedPane implements ActionListener,
051: ProjectViewModelListener {
052: private static final long serialVersionUID = 3257845493651814197L;
053: TitledBorder border;
054: JTextField taskName;
055: JTextField taskLength;
056: DateField taskNotBefore;
057: JTextField taskComments;
058: JTextField taskCompleted;
059:
060: JTextArea taskNotes;
061:
062: Project project = null;
063: ProjectViewModel pvModel;
064:
065: /**
066: * Constructor for TaskEditor
067: */
068: public TaskEditor(Window parent, ProjectViewModel model) {
069: super ();
070:
071: assignViewModel(model);
072: pvModel.addListener(this );
073:
074: addTab(
075: Messages.getString("TaskEditor.tab.main.label"), null, makePrincipalPanel(), Messages.getString("TaskEditor.tab.main.hint")); //$NON-NLS-1$ //$NON-NLS-2$
076: addTab(
077: Messages.getString("TaskEditor.tab.notes.label"), null, makeNotesPanel(), Messages.getString("TaskEditor.tab.notes.hint")); //$NON-NLS-1$ //$NON-NLS-2$
078:
079: currentTaskChanged(pvModel.getCurrentTask(), null);
080: if (parent != null)
081: new RemoveObservers(parent, pvModel, this , null);
082: }
083:
084: /**
085: * Panel de notas
086: * @return
087: */
088: JPanel makeNotesPanel() {
089: JPanel panel = new JPanel();
090:
091: panel.setLayout(new BorderLayout());
092: taskNotes = new JTextArea(5, 30);
093: panel.add(new JScrollPane(taskNotes));
094: taskNotes.addFocusListener(new FocusListener() {
095: public void focusGained(FocusEvent arg0) {
096: }
097:
098: public void focusLost(FocusEvent arg0) {
099: Task task = pvModel.getCurrentTask();
100: task.setNotes(taskNotes.getText());
101: }
102: });
103: return panel;
104: }
105:
106: /**
107: * Panel principal
108: * @return
109: */
110: JPanel makePrincipalPanel() {
111: JPanel panel = new JPanel();
112: panel.setLayout(new LabeledPairLayout());
113: panel
114: .add(
115: new JLabel(
116: Messages
117: .getString("TaskEditor.taskName.label"), SwingConstants.RIGHT), LabeledPairLayout.LABEL); //$NON-NLS-1$
118: panel
119: .add(
120: new JLabel(
121: Messages
122: .getString("TaskEditor.length.label"), SwingConstants.RIGHT), LabeledPairLayout.LABEL); //$NON-NLS-1$
123: panel
124: .add(
125: new JLabel(
126: Messages
127: .getString("TaskEditor.dontStart.label"), SwingConstants.RIGHT), LabeledPairLayout.LABEL); //$NON-NLS-1$
128: panel
129: .add(
130: new JLabel(
131: Messages
132: .getString("TaskEditor.comments.label"), SwingConstants.RIGHT), LabeledPairLayout.LABEL); //$NON-NLS-1$
133: panel
134: .add(
135: new JLabel(
136: Messages
137: .getString("TaskEditor.completed.label"), SwingConstants.RIGHT), LabeledPairLayout.LABEL); //$NON-NLS-1$
138:
139: taskName = new JTextField(15);
140: taskLength = new JTextField(5);
141: taskNotBefore = new DateField(
142: project.getViewOptions().editDateFormat);
143: taskComments = new JTextField(15);
144: taskCompleted = new JTextField(5);
145:
146: panel.add(taskName, LabeledPairLayout.FIELD);
147: panel.add(taskLength, LabeledPairLayout.FIELD);
148: panel.add(taskNotBefore, LabeledPairLayout.FIELD);
149: panel.add(taskComments, LabeledPairLayout.FIELD);
150: panel.add(taskCompleted, LabeledPairLayout.FIELD);
151:
152: taskName.addActionListener(this );
153: taskLength.addActionListener(this );
154: taskComments.addActionListener(this );
155: taskCompleted.addActionListener(this );
156: taskNotBefore.addActionListener(this );
157: return panel;
158: }
159:
160: /**
161: * cambios en los controles.
162: */
163: public void actionPerformed(ActionEvent event) {
164: //System.out.println("inputMethodTextChanged source="+event.getSource().getClass().getName());
165: Object src = event.getSource();
166: Task task = pvModel.getCurrentTask();
167: //System.out.println("actionPerformed " + event.getSource());
168: if (src == taskName) {
169: task.setName(taskName.getText());
170: } else if (src == taskLength) {
171: try {
172: task.setHumanReadableWorkLength(taskLength.getText());
173: taskLength.setText(task.getHumanReadableWorkLength());
174: } catch (Exception e) {
175: }
176: } else if (src == taskCompleted) {
177: try {
178: task.setCompleted(Integer.parseInt(taskCompleted
179: .getText()));
180: } catch (Exception e) {
181: }
182: } else if (src == taskNotBefore) {
183: try {
184: task.setNotBeforeDate(taskNotBefore.getDate());
185: } catch (Exception e) {
186: System.out.println("setfecha nop:" + e);
187: }
188: }
189: if (src == taskComments) {
190: task.setComments(taskComments.getText());
191: }
192: }
193:
194: public void currentTaskChanged(Task currentTask, Task oldTask) {
195: if (currentTask == null)
196: return;
197: //System.out.println(getClass().getName()+"::currentTaskChanged");
198: taskName.setText(currentTask.getName());
199: taskLength.setText(currentTask.getHumanReadableWorkLength());
200: taskCompleted.setText("" + currentTask.getCompleted());
201: taskComments.setText("" + currentTask.getComments());
202:
203: taskNotes.setText(currentTask.getNotes());
204:
205: taskLength.setEnabled(!currentTask.isResume());
206: taskNotBefore.setEnabled(!currentTask.isResume());
207:
208: Date d = currentTask.getNotBeforeDate();
209: if (d != null) {
210: taskNotBefore.setDate(d);
211: } else
212: taskNotBefore.setDate(null);
213: }
214:
215: /**
216: * Atiende nuevos proyectos cargados
217: */
218: public void assignViewModel(ProjectViewModel pvm) {
219: pvModel = pvm;
220: project = pvm.getProject();
221: }
222:
223: /**
224: * Eventos del modelo
225: * @see com.csa.lgantt.view.adapters.ProjectViewModelListener#projectChanged(com.csa.lgantt.view.adapters.ProjectViewModelChange)
226: */
227: public void viewModelChanged(ProjectViewModelChange c) {
228: switch (c.getId()) {
229: case ProjectViewModelChange.NEW_PROJECT_LOADED:
230: assignViewModel(c.getProjectViewModel());
231: // fall into current Task Changed
232: case ProjectViewModelChange.CURRENT_TASK_CHANGED:
233: currentTaskChanged(pvModel.getCurrentTask(), null);
234: }
235: }
236:
237: }
|