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;
017:
018: import java.awt.BorderLayout;
019: import java.awt.Dimension;
020: import java.awt.Frame;
021: import java.awt.Point;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.awt.image.BufferedImage;
025: import java.io.File;
026: import java.io.FileInputStream;
027: import java.io.FileNotFoundException;
028: import java.io.FileOutputStream;
029: import java.io.IOException;
030: import java.io.InputStream;
031: import java.io.OutputStream;
032: import java.net.MalformedURLException;
033: import java.net.URL;
034: import java.text.ParseException;
035: import java.util.Date;
036:
037: import javax.swing.ImageIcon;
038: import javax.swing.JDialog;
039: import javax.swing.JFileChooser;
040: import javax.swing.JLabel;
041: import javax.swing.JOptionPane;
042: import javax.swing.JScrollPane;
043: import javax.swing.filechooser.FileFilter;
044:
045: import org.xml.sax.SAXException;
046:
047: import com.csa.lgantt.LGanttMain;
048: import com.csa.lgantt.Messages;
049: import com.csa.lgantt.model.Constraint;
050: import com.csa.lgantt.model.GanttException;
051: import com.csa.lgantt.model.GraphColors;
052: import com.csa.lgantt.model.IOManager;
053: import com.csa.lgantt.model.Project;
054: import com.csa.lgantt.model.Task;
055: import com.csa.lgantt.view.adapters.ProjectViewModel;
056: import com.csa.lgantt.view.dialogs.AsignationEditor;
057: import com.csa.lgantt.view.dialogs.ConstraintEditor;
058: import com.csa.lgantt.view.dialogs.GraphColorsEditor;
059: import com.csa.lgantt.view.dialogs.InputDialog;
060: import com.csa.lgantt.view.dialogs.OptionsEditor;
061: import com.csa.lgantt.view.dialogs.ProjectEditor;
062: import com.csa.lgantt.view.dialogs.ResourcesEditor;
063: import com.csa.lgantt.view.dialogs.ResourcesTable;
064: import com.csa.lgantt.view.dialogs.TaskEditor;
065:
066: /**
067: * GanttActionListener, procesa todas las acciones recibidas desde el menu
068: * principal y los menues popup dentro de la aplicacion. Los valores son
069: * constantes para la mayoria de las opciones
070: * <p>
071: * $Date: 2006/09/14 08:14:17 $
072: * </p>
073: *
074: * @version $Revision: 1.1 $
075: * @author Carlos Silva
076: */
077: public class GanttActionListener implements ActionListener {
078: public static final String WND_TITLE = Messages
079: .getString("MainFrame.title");
080:
081: /**
082: * usado para mantener la asociacion de carpetas
083: */
084: JFileChooser chooser = new JFileChooser();
085:
086: // COMANDOS estaticos, definidos en el menu
087:
088: // FILE
089: public static final String CMD_NEW = "new";
090:
091: public static final String CMD_OPEN = "open";
092:
093: public static final String CMD_SAVE = "save";
094:
095: public static final String CMD_SAVE_AS = "saveas";
096:
097: public static final String CMD_EXIT = "exit";
098:
099: // EDIT
100: public static final String CMD_EDIT_UNDO = "undo";
101:
102: public static final String CMD_EDIT_REDO = "redo";
103:
104: public static final String CMD_EDIT_TASK = "task";
105:
106: public static final String CMD_INSERT_TASK = "instask";
107:
108: public static final String CMD_APPEND_TASK = "apptask";
109:
110: public static final String CMD_DELETE_TASK = "deltask";
111:
112: public static final String CMD_EDIT_ASIGNATIONS = "asignations";
113:
114: public static final String CMD_EDIT_RESOURCES = "resources";
115:
116: public static final String CMD_MERGE_PROJECT = "mergeprj";
117:
118: // PROJECT
119: public static final String CMD_PROJ_EDIT = "settings";
120:
121: public static final String CMD_SNAPSHOT = "takesnap";
122:
123: public static final String CMD_REMSNAPSHOT = "removesnap";
124:
125: // TOOLS
126: public static final String CMD_EXPORT_IMG = "export_img";
127:
128: public static final String CMD_RESOURCES_TABLE = "export_res";
129:
130: // OPTIONS
131: public static final String CMD_VIEW_OPTIONS = "viewop";
132:
133: public static final String CMD_GRAPH_COLORS = "graphop";
134:
135: public static final String CMD_USER_GRAPHCOLORS = "loadcolors";
136:
137: public static final String CMD_DEFINE_GRAPHCOLORS = "defcolors";
138:
139: // HELP
140: public static final String CMD_HELP_KBD = "keybd";
141:
142: public static final String CMD_HELP_HINTS = "hints";
143:
144: public static final String CMD_HELP_FEEDBACK = "feedback";
145:
146: public static final String CMD_HELP_ABOUT = "about";
147:
148: // OTHER COMMANDS
149: public static final String CMD_TASK_GRAPHICS = "graphop";
150:
151: public static final String CMD_EDIT_CONSTRAINT = "constraint";
152:
153: public static final String CMD_DELETE_CONSTRAINT = "delconst";
154:
155: private Frame mainWindow;
156:
157: private GanttDisplay ganttDisplay;
158:
159: private ProjectViewModel pvModel;
160:
161: /**
162: * Constructor
163: *
164: * @param pvm
165: * ViewModel
166: */
167: public GanttActionListener(ProjectViewModel pvm) {
168: this .mainWindow = null;
169: this .ganttDisplay = null;
170: this .pvModel = pvm;
171: }
172:
173: /**
174: * Asigna la ventana y el display principal asociado a este objeto.
175: *
176: * @param window
177: * @param display
178: */
179: public void setup(Frame window, GanttDisplay display) {
180: mainWindow = window;
181: ganttDisplay = display;
182: updWindowTitle();
183: }
184:
185: /**
186: * Funcion despachadora
187: */
188: public void actionPerformed(ActionEvent e) {
189: try {
190: String s = e.getActionCommand();
191: // System.out.println("ACTION " + s);
192: if (s.equals(CMD_EXIT)) {
193: cmdExit();
194: } else if (s.equals(CMD_EDIT_UNDO)) {
195: cmdUndo();
196: } else if (s.equals(CMD_EDIT_REDO)) {
197: cmdRedo();
198: } else if (s.equals(CMD_EDIT_TASK)) {
199: cmdEditTask();
200: } else if (s.equals(CMD_INSERT_TASK)) {
201: pvModel.insertTask();
202: } else if (s.equals(CMD_APPEND_TASK)) {
203: pvModel.appendTask();
204: } else if (s.equals(CMD_DELETE_TASK)) {
205: pvModel.deleteCurrentTask();
206: } else if (s.equals(CMD_EDIT_ASIGNATIONS)) {
207: cmdEditAsignations();
208: } else if (s.equals(CMD_EDIT_CONSTRAINT)) {
209: cmdEditConstraint();
210: } else if (s.equals(CMD_DELETE_CONSTRAINT)) {
211: cmdDeleteConstraint();
212: } else if (s.equals(CMD_PROJ_EDIT)) {
213: cmdEditProject();
214: } else if (s.equals(CMD_EDIT_RESOURCES)) {
215: cmdEditResources();
216: } else if (s.equals(CMD_MERGE_PROJECT)) {
217: cmdMergeProject();
218: } else if (s.equals(CMD_SNAPSHOT)) {
219: cmdSnapShot();
220: } else if (s.equals(CMD_REMSNAPSHOT)) {
221: cmdSnapShotRemove();
222: } else if (s.equals(CMD_VIEW_OPTIONS)) {
223: cmdViewOptions();
224: } else if (s.equals(CMD_GRAPH_COLORS)) {
225: cmdGraphColors();
226: } else if (s.equals(CMD_RESOURCES_TABLE)) {
227: cmdResourcesTable();
228: } else if (s.equals(CMD_EXPORT_IMG)) {
229: cmdExportImage();
230: } else if (s.equals(CMD_USER_GRAPHCOLORS)) {
231: cmdLoadUserColors();
232: } else if (s.equals(CMD_DEFINE_GRAPHCOLORS)) {
233: cmdDefineUserColors();
234: } else if (s.equals(CMD_NEW)) {
235: cmdNew();
236: } else if (s.equals(CMD_SAVE)) {
237: cmdSave();
238: } else if (s.equals(CMD_SAVE_AS)) {
239: cmdSaveAs();
240: } else if (s.equals(CMD_OPEN)) {
241: cmdOpen();
242: } else if (s.equals(CMD_HELP_KBD)) {
243: cmdHelpKeyboard();
244: } else if (s.equals(CMD_HELP_FEEDBACK)) {
245: cmdHelpFeedback();
246: } else if (s.equals(CMD_HELP_HINTS)) {
247: cmdHelpHints();
248: } else if (s.equals(CMD_HELP_ABOUT)) {
249: cmdHelpAbout();
250: } else
251: // SOPORTE A COMANDOS ORIGINALMENTE PROVENIENTES DE GANTTDISPLAY
252: if ("movedn".equals(s)) {
253: pvModel.goDownTask();
254: } else if ("moveup".equals(s)) {
255: pvModel.goUpTask();
256: } else if ("indentr".equals(s)) {
257: pvModel.asChildTask();
258: } else if ("indentl".equals(s)) {
259: pvModel.deChildTask();
260: } else if (s.startsWith("lru.")) { // load recently used files
261: int n = Integer.parseInt(s.substring(4)) - 1;
262: File f = (File) LGanttMain.getLastUsed().get(n);
263: if (f.exists()) {
264: // Confirm discard current file
265: pvModel.setProject(IOManager.loadFrom(f), f);
266: updWindowTitle();
267: LGanttMain.addLastUsed(f);
268: }
269: }
270: } catch (Exception ex) {
271: JOptionPane.showMessageDialog(null, ex.getMessage(),
272: "Error", JOptionPane.ERROR_MESSAGE);
273: System.err.println(Messages
274: .getString("MainFrame.error.actionException")); //$NON-NLS-1$
275: ex.printStackTrace(System.err);
276: }
277: }
278:
279: static public void cmdHelpAbout() {
280: new HelpWindow(Messages.getString("MainFrame.help.about.file"))
281: .setVisible(true);
282: }
283:
284: static public void cmdHelpHints() {
285: HelpWindow w = new HelpWindow(Messages
286: .getString("MainFrame.help.hints.file"));
287: w.setSize(380, 210);
288: w.setTitle("Tips");
289: w.setVisible(true);
290: }
291:
292: static public void cmdHelpFeedback() throws MalformedURLException {
293: new HelpWindow(new URL(Messages
294: .getString("MainFrame.help.feedback.url")))
295: .setVisible(true);
296: }
297:
298: static public void cmdHelpKeyboard() {
299: new HelpWindow(Messages.getString("MainFrame.help.keyb.file"))
300: .setVisible(true);
301: }
302:
303: /**
304: * Cerrar el sistema. ejecuta System.exit(0).
305: */
306: public void cmdExit() {
307: if (mainWindow != null) {
308: mainWindow.dispose();
309: System.exit(0);
310: }
311: }
312:
313: /**
314: * Levanta el editor de tareas que apunta a la tarea actual
315: */
316: public void cmdEditTask() {
317: JDialog jf = new JDialog(mainWindow, Messages
318: .getString("MainFrame.TaskEditorFrame.title")); //$NON-NLS-1$
319: ProjectViewModel pvm = (ProjectViewModel) ganttDisplay
320: .getProjectViewModel();
321: jf.getContentPane().add(new TaskEditor(jf, pvm));
322: jf.pack();
323: Point p = mainWindow.getLocation();
324: jf.setLocation(p.x + 100, p.y + 100);
325: jf.setVisible(true);
326: }
327:
328: /**
329: * Edita el constraint actual. El constraint actual se obtiene pidiendo a
330: * GanttDisplay que retorne el objeto seleccionado actualmente. TODO: Mover
331: * la informacion del objeto seleccionado hacia ViewModel.
332: */
333: public void cmdEditConstraint() {
334: JDialog jf = new JDialog(mainWindow, Messages
335: .getString("ConstraintEditorFrame.title"));
336: jf.setModal(true);
337: ProjectViewModel pvm = (ProjectViewModel) ganttDisplay
338: .getProjectViewModel();
339: Constraint c = (Constraint) ganttDisplay.getSelectedObject();
340: jf.getContentPane().add(new ConstraintEditor(c));
341: jf.pack();
342: Point p = mainWindow.getLocation();
343: jf.setLocation(p.x + 100, p.y + 100);
344: jf.setVisible(true);
345: }
346:
347: /**
348: * Borra un constraint
349: */
350: public void cmdDeleteConstraint() {
351: Constraint c = (Constraint) ganttDisplay.getSelectedObject();
352: c.remove();
353: }
354:
355: /**
356: * Edita los recursos existentes.
357: */
358: public void cmdEditResources() {
359: JDialog jf = new JDialog(mainWindow, Messages
360: .getString("ResourcesEditor.title")); //$NON-NLS-1$
361: ProjectViewModel pvm = (ProjectViewModel) ganttDisplay
362: .getProjectViewModel();
363: jf.getContentPane().add(new ResourcesEditor(jf, pvm));
364: jf.pack();
365: jf.setSize(new Dimension(300, 200));
366: Point p = mainWindow.getLocation();
367: jf.setLocation(p.x + 100, p.y + 100);
368: jf.setVisible(true);
369: }
370:
371: /**
372: * Edita las asignaciones de recursos a la tarea actual
373: */
374: public void cmdEditAsignations() {
375: ProjectViewModel pvm = (ProjectViewModel) ganttDisplay
376: .getProjectViewModel();
377: Task task = (Task) pvm.getCurrentTask();
378: if (task == null)
379: return;
380: JDialog jf = new JDialog(mainWindow, Messages
381: .getString("AsignationEditor.title")); //$NON-NLS-1$
382: jf.getContentPane().add(new AsignationEditor(jf, pvm, task));
383: jf.pack();
384: jf.setSize(new Dimension(300, 200));
385: Point p = mainWindow.getLocation();
386: jf.setLocation(p.x + 100, p.y + 100);
387: jf.setVisible(true);
388: }
389:
390: /**
391: * Obtiene una referencia al archivo que contiene los colores de usuario.
392: *
393: * @return referencia al archivo.
394: */
395: File getSettingsFile() {
396: String userDir = System.getProperty("user.home");
397: return new File(userDir, ".lgantt_user_colors");
398: }
399:
400: /**
401: * Carga los colores del usuario
402: */
403: private void cmdLoadUserColors() {
404: // cargar si los hay
405: File source = getSettingsFile();
406: try {
407: InputStream is = new FileInputStream(source);
408: GraphColors gc = IOManager.loadGraphColors(is);
409: // asignar
410: pvModel.getProject().setGraphColors(gc);
411: is.close();
412: mainWindow.repaint();
413: } catch (Exception ex) {
414: ex.printStackTrace();
415: }
416: }
417:
418: /**
419: * graba los colores en un archivo personal
420: */
421: private void cmdDefineUserColors() {
422: // Crear nombre de archivo
423: File source = getSettingsFile();
424: try {
425: OutputStream os = new FileOutputStream(source);
426: IOManager.serialize(pvModel.getProject().getGraphColors(),
427: os);
428: os.close();
429: } catch (Exception ex) {
430: ex.printStackTrace();
431: }
432: }
433:
434: /**
435: * Genera una imagen en formato y la graba en el disco
436: */
437: private void cmdExportImage() {
438: try {
439: BufferedImage img = pvModel.makeImage();
440: JDialog f = new JDialog(mainWindow, "Export Image", true);
441:
442: f.getContentPane().setLayout(new BorderLayout());
443: JLabel imgLabel = new JLabel(new ImageIcon(img));
444: f.getContentPane().add(new JScrollPane(imgLabel),
445: BorderLayout.CENTER);
446: f.pack();
447: f.setVisible(true);
448:
449: JFileChooser imgChooser = getImageFileChooser();
450: if (JFileChooser.APPROVE_OPTION == chooser
451: .showSaveDialog(mainWindow)) {
452: File dest = imgChooser.getSelectedFile();
453:
454: pvModel.exportImage(dest);
455: }
456: f.dispose();
457: } catch (Exception ex) {
458: System.err.println(Messages
459: .getString("MainFrame.error.actionException")); //$NON-NLS-1$
460: ex.printStackTrace(System.err);
461: }
462:
463: }
464:
465: /**
466: * Carga un archivo .lgantt o xml
467: *
468: * @throws ParserConfigurationException
469: * @throws SAXException
470: * @throws IOException
471: * @throws FileNotFoundException
472: * @throws ParseException
473: * @throws GanttException
474: */
475: private void cmdOpen() throws SAXException, IOException,
476: FileNotFoundException, ParseException, GanttException {
477: File f = getOpenFile();
478: if (f != null) {
479: pvModel.setProject(IOManager.loadFrom(f), f);
480: updWindowTitle();
481: LGanttMain.addLastUsed(f);
482: }
483: }
484:
485: /**
486: * retorna una referencia a un archivo seleccionado por el usuario
487: *
488: * @return
489: * @throws ParseException
490: * @throws GanttException
491: * @throws FileNotFoundException
492: * @throws SAXException
493: * @throws IOException
494: */
495: private File getOpenFile() throws ParseException, GanttException,
496: FileNotFoundException, SAXException, IOException {
497: if (JFileChooser.APPROVE_OPTION == chooser
498: .showOpenDialog(mainWindow)) {
499: return chooser.getSelectedFile();
500: }
501: return null;
502: }
503:
504: /**
505: * @throws IOException
506: * Si hay problemas con la lectura del archivo
507: * @throws SAXException
508: * @throws GanttException
509: * @throws ParseException
510: * @throws FileNotFoundException
511: */
512: void cmdMergeProject() throws FileNotFoundException,
513: ParseException, GanttException, SAXException, IOException {
514: File f = getOpenFile();
515: if (f == null)
516: return;
517: Project p = IOManager.loadFrom(f);
518: // copiar las tareas como hijas de la tarea actual
519: Task resumeTask = pvModel.getCurrentTask();
520: if (resumeTask == null)
521: resumeTask = pvModel.getProject().getMainTask();
522: resumeTask.addChild(p);
523: }
524:
525: /**
526: * Crea un nuevo proyecto y lo asigna.
527: */
528: private void cmdNew() {
529: pvModel.setProject(IOManager.createEmptyProject(), null);
530: updWindowTitle();
531: }
532:
533: /**
534: * Graba el proyecto en un archivo con un nombre.
535: *
536: * @throws FileNotFoundException
537: * @throws IOException
538: */
539: private void cmdSaveAs() throws FileNotFoundException, IOException {
540: if (pvModel.getFile() != null)
541: chooser.setCurrentDirectory(pvModel.getFile()
542: .getParentFile());
543: if (JFileChooser.APPROVE_OPTION == chooser
544: .showSaveDialog(mainWindow)) {
545: File dest = chooser.getSelectedFile();
546: IOManager.saveAs(pvModel.getProject(), dest);
547: pvModel.setFile(dest);
548: updWindowTitle();
549: LGanttMain.addLastUsed(dest);
550: }
551: }
552:
553: /**
554: * Graba el contenido del proyecto con el nombre actual.
555: *
556: * @throws FileNotFoundException
557: * @throws IOException
558: */
559: private void cmdSave() throws FileNotFoundException, IOException {
560: if (pvModel.getFile() == null) {
561: cmdSaveAs();
562: } else {
563: IOManager.saveAs(pvModel.getProject(), pvModel.getFile());
564: updWindowTitle();
565: }
566: }
567:
568: /**
569: * Muestra una tabla con los recursos.
570: */
571: private void cmdResourcesTable() {
572: JDialog jf = new JDialog(mainWindow, CMD_RESOURCES_TABLE);
573: ProjectViewModel pvm = (ProjectViewModel) ganttDisplay
574: .getProjectViewModel();
575: jf.getContentPane().add(new ResourcesTable(pvm),
576: BorderLayout.CENTER);
577: jf.pack();
578: jf.setSize(new Dimension(400, 200));
579: Point p = mainWindow.getLocation();
580: jf.setLocation(p.x + 200, p.y + 250);
581: jf.setVisible(true);
582: }
583:
584: /**
585: * Opciones de visualizacion, tamano de la grilla, etc.
586: */
587: private void cmdViewOptions() {
588: JDialog jf = new JDialog(mainWindow, Messages
589: .getString("MainFrame.ViewOptionsFrame.title")); //$NON-NLS-1$
590: jf.getContentPane().add(new OptionsEditor(jf, pvModel));
591: jf.pack();
592: Point p = mainWindow.getLocation();
593: jf.setLocation(p.x + 300, p.y + 80);
594: jf.setVisible(true);
595: }
596:
597: /**
598: * Edita las caracteristicas del proyecto.
599: */
600: private void cmdEditProject() {
601: JDialog jf = new JDialog(mainWindow, Messages
602: .getString("MainFrame.ProjectEditorFrame.title")); //$NON-NLS-1$
603: ProjectViewModel pvm = (ProjectViewModel) ganttDisplay
604: .getProjectViewModel();
605: jf.getContentPane().add(new ProjectEditor(jf, pvm));
606: jf.pack();
607: Point p = mainWindow.getLocation();
608: jf.setLocation(p.x + 150, p.y + 80);
609: jf.setVisible(true);
610: }
611:
612: /**
613: * Edita los colores que se usan en los graficos
614: */
615: private void cmdGraphColors() {
616: JDialog jf = new JDialog(mainWindow, Messages
617: .getString("MainFrame.GraphColors.title"));
618: // ProjectViewModel pvm = (ProjectViewModel)
619: // ganttDisplay.getProjectViewModel();
620: jf.getContentPane().add(new GraphColorsEditor(pvModel));
621: jf.pack();
622: Point p = mainWindow.getLocation();
623: jf.setLocation(p.x + 150, p.y + 80);
624: jf.setVisible(true);
625: }
626:
627: /**
628: * Crea una foto del contenido del proyecto.
629: */
630: public void cmdSnapShot() {
631: String def = "New SnapShot";
632: InputDialog id = new InputDialog("Take SnapShot", def);
633: Point p = mainWindow.getLocation();
634: id.setLocation(p.x + 150, p.y + 80);
635: if (id.execute()) {
636: String title = id.getInputString();
637: if (title != null) {
638: pvModel.getProject().takeSnapshot(title);
639: }
640: }
641: }
642:
643: /**
644: * Remueve el snapshot seleccionado si hay alguno.
645: */
646: public void cmdSnapShotRemove() {
647: Date d = pvModel.getCurrentSnapShot();
648: pvModel.getProject().removeSnapshot(d);
649: }
650:
651: /**
652: * Undo the last action
653: */
654: void cmdUndo() {
655: pvModel.getProject().undo();
656: }
657:
658: /**
659: * Redo the last undoed action
660: */
661: void cmdRedo() {
662: pvModel.getProject().redo();
663: }
664:
665: /**
666: * Cambia el titulo de la ventana
667: */
668: public void updWindowTitle() {
669: if (mainWindow == null)
670: return;
671: ((MainFrame) mainWindow).updWindowTitle();
672: }
673:
674: JFileChooser getImageFileChooser() {
675: // chooser.setCurrentDirectory(pvModel.getFile().getParentFile());
676: chooser.resetChoosableFileFilters();
677: chooser
678: .setFileFilter(new StdFileFilter("Image (*.jpg)",
679: ".jpg"));
680: return chooser;
681: }
682:
683: JFileChooser getLGanttFileChooser() {
684: // chooser.setCurrentDirectory(pvModel.getFile().getParentFile());
685: chooser.resetChoosableFileFilters();
686: FileFilter f1 = new StdFileFilter(
687: "Archivos lGantt (*.lgantt,*.xml)",
688: IOManager.STD_FILE_EXT + " " + IOManager.SEC_FILE_EXT);
689: FileFilter f2 = new StdFileFilter("lGantt standard (*.lgantt)",
690: IOManager.STD_FILE_EXT);
691: FileFilter f3 = new StdFileFilter("lGantt simple (*.xml)",
692: IOManager.SEC_FILE_EXT);
693: chooser.addChoosableFileFilter(f1);
694: chooser.addChoosableFileFilter(f2);
695: chooser.addChoosableFileFilter(f3);
696: chooser.setFileFilter(f1);
697: return chooser;
698: }
699:
700: /**
701: * StdFileFilter
702: *
703: * @author Carlos
704: */
705: static class StdFileFilter extends FileFilter {
706: String ext = null;
707:
708: String des = null;
709:
710: public StdFileFilter(String typeDescription,
711: String comaExtensions) {
712: ext = typeDescription;
713: des = comaExtensions;
714: }
715:
716: public boolean accept(File f) {
717: if (f.isDirectory())
718: return true;
719: String name = f.getName();
720: int i = name.lastIndexOf(".");
721: if (i < 0)
722: return false;
723: String x = name.substring(i);
724: return ext.indexOf(x) >= 0;
725: }
726:
727: public String getDescription() {
728: return des;
729: }
730: }
731: }
|