1 19 20 package org.netbeans.modules.tasklist.usertasks; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Image ; 24 import java.awt.Point ; 25 import java.awt.event.InputEvent ; 26 import java.awt.event.KeyEvent ; 27 import java.beans.PropertyChangeEvent ; 28 import java.beans.PropertyChangeListener ; 29 import java.io.File ; 30 import java.io.FileOutputStream ; 31 import java.io.IOException ; 32 import java.io.InputStream ; 33 import java.io.ObjectInput ; 34 import java.io.ObjectOutput ; 35 import java.io.OutputStream ; 36 import java.io.Serializable ; 37 import java.net.URL ; 38 import java.util.HashMap ; 39 import java.util.Map ; 40 import java.util.logging.Level ; 41 import javax.swing.Action ; 42 import javax.swing.ActionMap ; 43 import javax.swing.JComponent ; 44 import javax.swing.JPanel ; 45 import javax.swing.JScrollPane ; 46 import javax.swing.JToolBar ; 47 import javax.swing.KeyStroke ; 48 import javax.swing.SwingUtilities ; 49 import javax.swing.border.EmptyBorder ; 50 import javax.swing.tree.TreePath ; 51 import org.netbeans.modules.tasklist.core.export.ExportImportFormat; 52 import org.netbeans.modules.tasklist.core.export.ExportImportProvider; 53 import org.netbeans.modules.tasklist.core.filter.Filter; 54 import org.netbeans.modules.tasklist.core.filter.FilterAction; 55 import org.netbeans.modules.tasklist.core.filter.FilterRepository; 56 import org.netbeans.modules.tasklist.core.filter.FilteredTopComponent; 57 import org.netbeans.modules.tasklist.core.filter.RemoveFilterAction; 58 import org.netbeans.modules.tasklist.core.util.RightSideBorder; 59 import org.netbeans.modules.tasklist.usertasks.actions.GoToUserTaskAction; 60 import org.netbeans.modules.tasklist.usertasks.actions.MoveDownAction; 61 import org.netbeans.modules.tasklist.usertasks.actions.MoveLeftAction; 62 import org.netbeans.modules.tasklist.usertasks.actions.MoveRightAction; 63 import org.netbeans.modules.tasklist.usertasks.actions.MoveUpAction; 64 import org.netbeans.modules.tasklist.usertasks.actions.NewTaskAction; 65 import org.netbeans.modules.tasklist.usertasks.actions.PauseAction; 66 import org.netbeans.modules.tasklist.usertasks.actions.StartTaskAction; 67 import org.netbeans.modules.tasklist.usertasks.actions.UTCopyAction; 68 import org.netbeans.modules.tasklist.usertasks.actions.UTCutAction; 69 import org.netbeans.modules.tasklist.usertasks.actions.UTDeleteAction; 70 import org.netbeans.modules.tasklist.usertasks.actions.UTPasteAction; 71 import org.netbeans.modules.tasklist.usertasks.actions.UTSaveAction; 72 import org.netbeans.modules.tasklist.usertasks.filter.UserTaskFilter; 73 import org.netbeans.modules.tasklist.usertasks.model.StartedUserTask; 74 import org.netbeans.modules.tasklist.usertasks.options.Settings; 75 import org.netbeans.modules.tasklist.usertasks.translators.HistoryTextExportFormat; 76 import org.netbeans.modules.tasklist.usertasks.translators.HtmlExportFormat; 77 import org.netbeans.modules.tasklist.usertasks.translators.ICalExportFormat; 78 import org.netbeans.modules.tasklist.usertasks.translators.ICalImportFormat; 79 import org.netbeans.modules.tasklist.usertasks.translators.TextExportFormat; 80 import org.netbeans.modules.tasklist.usertasks.translators.XmlExportFormat; 81 import org.netbeans.modules.tasklist.core.table.ChooseColumnsPanel; 82 import org.netbeans.modules.tasklist.usertasks.actions.ClearCompletedAction; 83 import org.netbeans.modules.tasklist.usertasks.actions.PurgeTasksAction; 84 import org.netbeans.modules.tasklist.usertasks.actions.ShowTaskAction; 85 import org.netbeans.modules.tasklist.usertasks.actions.UTPasteAtTopLevelAction; 86 import org.netbeans.modules.tasklist.usertasks.actions.UTPropertiesAction; 87 import org.netbeans.modules.tasklist.usertasks.treetable.TreeTableModel; 88 import org.netbeans.modules.tasklist.usertasks.util.AWTThreadAnnotation; 89 import org.netbeans.modules.tasklist.usertasks.util.UTUtils; 90 import org.openide.actions.FindAction; 91 import org.openide.cookies.InstanceCookie; 92 import org.openide.filesystems.FileChangeListener; 93 import org.openide.filesystems.FileEvent; 94 import org.openide.filesystems.FileObject; 95 import org.openide.filesystems.FileSystem; 96 import org.openide.filesystems.FileUtil; 97 import org.openide.filesystems.Repository; 98 import org.openide.filesystems.URLMapper; 99 import org.openide.loaders.DataObject; 100 import org.openide.loaders.DataObjectNotFoundException; 101 import org.openide.util.HelpCtx; 102 import org.openide.util.NbBundle; 103 import org.openide.util.Utilities; 104 import org.openide.util.actions.SystemAction; 105 import org.openide.util.lookup.Lookups; 106 import org.openide.windows.Mode; 107 import org.openide.windows.TopComponent; 108 import org.openide.windows.WindowManager; 109 import org.netbeans.modules.tasklist.usertasks.model.UserTask; 110 import org.netbeans.modules.tasklist.usertasks.model.UserTaskList; 111 import org.netbeans.modules.tasklist.usertasks.treetable.TreeTable; 112 import org.openide.DialogDisplayer; 113 import org.openide.NotifyDescriptor; 114 import org.openide.cookies.SaveCookie; 115 116 122 public class UserTaskView extends TopComponent implements ExportImportProvider, 123 FileChangeListener, FilteredTopComponent { 124 private final static String USER_CATEGORY = "usertasks"; 127 private static final String DEFAULT_FILTER_NAME = 128 NbBundle.getMessage(UserTaskView.class, 129 "default-filter-name"); 131 private static final long serialVersionUID = 1; 132 133 private static final Image ICON = Utilities.loadImage( 134 "org/netbeans/modules/tasklist/usertasks/actions/taskView.gif"); 136 static { 137 141 Settings.getDefault().addPropertyChangeListener( 145 new PropertyChangeListener () { 146 public void propertyChange(PropertyChangeEvent e) { 147 String n = e.getPropertyName(); 148 if (n == Settings.PROP_WORKING_DAY_END || 149 n == Settings.PROP_WORKING_DAY_END || 150 n == Settings.PROP_PAUSE_START || 151 n == Settings.PROP_PAUSE_END || 152 n == Settings.PROP_WORKING_DAYS) { 153 UserTaskView[] all; 154 synchronized(UserTaskView.class) { 155 all = UserTaskViewRegistry. 156 getInstance().getAll(); 157 } 158 for (int i = 0; i < all.length; i++) { 159 all[i].repaint(); 160 } 161 } 162 } 163 } 164 ); 165 } 166 167 173 public static FileObject getDefaultFile() throws IOException { 174 String name = Settings.getDefault().getExpandedFilename(); 175 File f = FileUtil.normalizeFile(new File (name)); 176 177 FileObject fo = FileUtil.toFileObject(f); 178 if (fo == null) { 179 File dir = f.getParentFile(); 180 if (!dir.exists() && !dir.mkdirs()) { 181 throw new IOException ( 182 NbBundle.getMessage(UserTaskList.class, 183 "CannotCreateDir", dir.getAbsolutePath())); } 185 OutputStream os = new FileOutputStream (f); 186 try { 187 InputStream is = UserTaskList.class.getResourceAsStream( 188 "/org/netbeans/modules/tasklist/usertasks/tasklist.ics"); try { 190 UTUtils.copyStream(is, os); 191 } finally { 192 is.close(); 193 } 194 } finally { 195 os.close(); 196 } 197 fo = FileUtil.toFileObject(f); 198 } 199 return fo; 200 } 201 202 private UserTasksTreeTable tt; 203 private JScrollPane scrollPane; 204 private boolean initialized = false; 205 private UserTaskList tasklist = null; 206 private FilterRepository filters = null; 207 private Filter activeFilter = null; 208 private boolean default_; 209 210 211 public MoveUpAction moveUpAction; 212 213 214 public MoveDownAction moveDownAction; 215 216 217 public MoveLeftAction moveLeftAction; 218 219 220 public MoveRightAction moveRightAction; 221 222 223 public PurgeTasksAction purgeTasksAction; 224 225 226 public ClearCompletedAction clearCompletedAction; 227 228 229 public NewTaskAction newTaskAction; 230 231 232 public ShowTaskAction showTaskAction; 233 234 235 public UTPropertiesAction propertiesAction; 236 237 238 public UTSaveAction saveAction; 239 240 241 public UTPasteAtTopLevelAction pasteAtTopLevelAction; 242 243 private FileObject file; 244 245 250 public UserTaskView() { 251 } 252 253 259 @AWTThreadAnnotation 260 public UserTaskView(FileObject fo, boolean default_) { 261 init(fo, default_); 262 } 263 264 269 public FileObject getFile() { 270 return file; 271 } 272 273 public boolean canClose() { 274 if (!super.canClose()) 275 return false; 276 DataObject do_; 277 try { 278 do_ = DataObject.find(file); 279 } catch (DataObjectNotFoundException e) { 280 UTUtils.LOGGER.log(Level.SEVERE, e.getMessage(), e); 281 return false; 282 } 283 SaveCookie sc = do_.getCookie(SaveCookie.class); 284 if (sc == null) 285 return true; 286 287 String save = NbBundle.getMessage(UserTaskView.class, "Save"); 288 String discard = NbBundle.getMessage(UserTaskView.class, "Discard"); 289 String cancel = NbBundle.getMessage(UserTaskView.class, "Cancel"); 290 291 NotifyDescriptor d = new NotifyDescriptor( 292 NbBundle.getMessage(UserTaskView.class, 293 "FileWasModified", FileUtil.getFileDisplayName(file)), 295 NbBundle.getMessage(UserTaskView.class, 296 "Question"), NotifyDescriptor.YES_NO_CANCEL_OPTION, 298 NotifyDescriptor.QUESTION_MESSAGE, 299 new Object [] {save, discard, cancel}, save); 300 Object ret = DialogDisplayer.getDefault().notify(d); 301 if (ret.equals(save)) { 302 try { 303 sc.save(); 304 return true; 305 } catch (IOException e) { 306 UTUtils.LOGGER.log(Level.SEVERE, e.getMessage(), e); 307 return false; 308 } 309 } else if (ret.equals(discard)) { 310 do_.setModified(false); 311 return true; 312 } else { 313 return false; 314 } 315 } 316 317 322 public UserTasksTreeTable getTreeTable() { 323 return tt; 324 } 325 326 331 public Action [] getToolBarActions() { 332 return new Action [] { 333 saveAction, 334 newTaskAction, 335 new GoToUserTaskAction(this), 336 null, 337 SystemAction.get(FilterAction.class), 338 SystemAction.get(RemoveFilterAction.class), 339 null, 340 new StartTaskAction(this), 341 PauseAction.getInstance(), 342 null, 343 moveUpAction, 344 moveDownAction, 345 }; 347 } 348 349 public void componentActivated() { 350 super.componentActivated(); 351 352 RemoveFilterAction removeFilter = 353 (RemoveFilterAction) SystemAction.get(RemoveFilterAction.class); 354 removeFilter.enable(); 355 UserTaskViewRegistry.getInstance().setLastActivated(this); 356 } 357 358 366 public void readExternalCore(ObjectInput objectInput) throws IOException , 367 java.lang.ClassNotFoundException { 368 372 int ver = objectInput.read(); 373 374 objectInput.readObject(); 376 if (ver == 4) 377 return; 378 379 int sortingColumn = objectInput.read(); 380 int sortAscendingInt = objectInput.read(); 381 int numVisible = objectInput.read(); 382 383 if (sortingColumn == 255) { 385 sortingColumn = -1; 386 } 387 388 if (numVisible > 0) { 389 String [] columns = new String [0]; 390 int numColumns = columns.length; 391 boolean[] columnVisible = new boolean[numColumns]; 392 for (int i = 0; i < numColumns; i++) { 393 columnVisible[i] = false; 394 } 395 for (int i = 0; i < numVisible; i++) { 396 int uid = objectInput.read(); 397 } 398 } 399 400 if (ver >= 2) { 401 objectInput.readObject(); objectInput.readObject(); int persistentInt = objectInput.read(); 404 } 405 } 406 407 415 public void readExternal(ObjectInput objectInput) throws IOException , 416 java.lang.ClassNotFoundException { 417 readExternalCore(objectInput); 418 int ver = objectInput.read(); 419 420 if (ver >= 2) { 421 String urlString = (String )objectInput.readObject(); 423 424 if (urlString != null) { 425 URL url = new URL (urlString); 426 file = URLMapper.findFileObject(url); 427 if (file != null && file.isValid()) { 428 init(file, false); 429 } else { 430 Runnable r = new Runnable () { 431 public void run() { 432 close(); 433 } 434 }; 435 SwingUtilities.invokeLater(r); 436 } 437 } else { 438 init(getDefaultFile(), true); 439 UserTaskViewRegistry.getInstance().setDefaultView(this); 440 } 441 } 442 if (ver >= 3) { 443 objectInput.readObject(); 446 } 447 if (ver >= 4) { 448 objectInput.readObject(); 451 } 452 if (ver >= 5) { 453 String uid = (String ) objectInput.readObject(); 454 455 if (StartedUserTask.getInstance().getStarted() == null && uid != null) { 457 UserTask ut = tasklist.findItem( 458 tasklist.getSubtasks().iterator(), uid); 459 if (ut != null) 460 ut.start(); 461 } 462 } 463 if (ver >= 6) { 464 Map m = (Map ) objectInput.readObject(); 466 Point p = (Point ) m.get("scrollPosition"); if (p != null) { 468 scrollPane.getVerticalScrollBar().setValue(p.y); 469 scrollPane.getHorizontalScrollBar().setValue(p.x); 470 } 471 472 TreeTable.ColumnsConfig cc = (TreeTable.ColumnsConfig) m.get("columns"); if (cc != null) { 475 tt.setColumnsConfig(cc); 476 } 477 478 String filter = (String ) m.get("filter"); if (filter != null) { 481 Filter f = getFilters().getFilterByName(filter); 482 setFilter(f); 483 } 484 485 Object expn = m.get("expandedNodes"); if (expn != null) { 488 tt.setExpandedNodes(tt.readResolveExpandedNodes(expn)); 489 } 490 491 Object seln = m.get("selectedNodes"); if (seln != null) { 494 tt.select(tt.readResolveExpandedNodes(seln)); 495 } 496 } 497 } 498 499 507 public void writeExternal(ObjectOutput objectOutput) throws IOException { 508 514 521 527 objectOutput.write(4); 530 objectOutput.writeObject(null); 533 objectOutput.write(6); 539 UserTaskList tl = getUserTaskList(); 540 if (!default_) { 541 URL url = URLMapper.findURL(file, URLMapper.EXTERNAL); 543 String urlString = url.toExternalForm(); 544 objectOutput.writeObject(urlString); 545 } else { 546 objectOutput.writeObject(null); 547 } 548 549 objectOutput.writeObject(null); 552 553 objectOutput.writeObject(null); 556 557 if (StartedUserTask.getInstance().getStarted() != null && 559 StartedUserTask.getInstance().getStarted().getList() == tasklist) { 560 objectOutput.writeObject(StartedUserTask.getInstance(). 561 getStarted().getUID()); 562 StartedUserTask.getInstance().start(null); 563 } else { 564 objectOutput.writeObject(null); 565 } 566 567 Map <String , Serializable > m = new HashMap <String , Serializable >(); 568 569 Point p = new Point ( 571 scrollPane.getHorizontalScrollBar().getValue(), 572 scrollPane.getVerticalScrollBar().getValue()); 573 m.put("scrollPosition", p); 575 Serializable cc = tt.getColumnsConfig(); 577 m.put("columns", cc); 579 if (getFilter() != null) 581 m.put("filter", getFilter().getName()); 583 m.put("expandedNodes", tt.writeReplaceExpandedNodes(tt.getExpandedNodes())); 586 m.put("selectedNodes", tt.writeReplaceExpandedNodes(tt.getSelectedPaths())); 589 objectOutput.writeObject(m); 590 } 591 592 596 private void updateNameAndToolTip() { 597 setToolTipText(FileUtil.getFileDisplayName(file)); 598 if (!default_) { 599 setName(file.getNameExt()); 600 } else { 601 setName(NbBundle.getMessage(UserTaskView.class, "TaskViewName")); } 603 } 604 605 public String toString() { 606 return "UserTaskView(" + getName() + ", " + getUserTaskList() + ")"; } 608 609 614 public org.netbeans.modules.tasklist.core.filter.Filter createFilter() { 615 return new UserTaskFilter("Simple"); } 617 618 protected java.lang.String preferredID() { 619 return "org.netbeans.modules.tasklist.usertasks.Window"; } 621 622 protected void setFiltered() { 623 if (getFilter() != null) { 624 ((RemoveFilterAction) SystemAction.get( 625 RemoveFilterAction.class)).enable(); 626 } 627 628 TreeTableModel ttm = tt.getTreeTableModel(); 629 if (ttm instanceof UserTasksTreeTableModel) { 630 ((UserTasksTreeTableModel) ttm).destroy(); 631 } 632 tt.setTreeTableModel(new UserTasksTreeTableModel((UserTaskList) getUserTaskList(), 633 tt.getSortingModel(), getFilter())); 634 } 635 636 642 public void select(UserTask task) { 643 if (isShowing() == false) return; 644 645 assert tt != null : "tt == null"; TreePath tp = tt.findPath(task); 647 648 if (tp != null) { 650 tt.expandPath(tp.getParentPath()); 651 tt.select(tp); 652 } 653 } 654 655 660 public void scrollTo(UserTask task) { 661 if (isShowing() == false) 662 return; 663 664 TreePath tp = tt.findPath(task); 665 tt.scrollTo(tp); 666 } 667 668 public int getPersistenceType() { 669 return TopComponent.PERSISTENCE_ONLY_OPENED; 670 } 671 672 public org.openide.util.HelpCtx getHelpCtx() { 673 return new HelpCtx( 674 "org.netbeans.modules.tasklist.usertasks.HOMEID"); } 676 677 public ExportImportFormat[] getExportFormats() { 678 return new ExportImportFormat[] { 679 new TextExportFormat(), 680 new XmlExportFormat(), 681 new HtmlExportFormat(), 682 new ICalExportFormat(), 683 new HistoryTextExportFormat() 684 }; 685 } 686 687 public ExportImportFormat[] getImportFormats() { 688 return new ExportImportFormat[] { 689 new ICalImportFormat() 690 }; 691 } 692 693 698 @AWTThreadAnnotation 699 private void init(FileObject file, boolean default_) { 700 assert SwingUtilities.isEventDispatchThread(); 701 702 TaskListDataObject do_ = null; 703 try { 704 do_ = (TaskListDataObject) DataObject.find(file); 705 } catch (DataObjectNotFoundException e) { 706 UTUtils.LOGGER.log(Level.SEVERE, e.getMessage(), e); 707 return; 708 } 709 710 this.file = file; 711 this.default_ = default_; 712 713 try { 714 tasklist = do_.getUserTaskList(); 715 } catch (IOException e) { 716 NotifyDescriptor nd = new NotifyDescriptor.Message( 717 NbBundle.getMessage(TaskListDataObject.class, 718 "ErrorReadingFile", e.getMessage())); DialogDisplayer.getDefault().notify(nd); 720 } 721 722 updateNameAndToolTip(); 723 724 new DueTasksNotifier(tasklist); 725 726 file.addFileChangeListener(this); 727 728 setIcon(ICON); 729 730 setLayout(new BorderLayout ()); 731 732 JPanel centerPanel = new JPanel (); 733 centerPanel.setLayout(new BorderLayout ()); 734 735 tt = new UserTasksTreeTable(this, getUserTaskList(), getFilter()); 736 737 associateLookup(Lookups.fixed(do_, do_.getNodeDelegate(), 738 getActionMap())); 739 740 configureActions(); 741 742 scrollPane = new JScrollPane (tt, 743 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 744 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 745 scrollPane.setBorder(new EmptyBorder (0, 0, 0, 0)); 746 747 ChooseColumnsPanel.installChooseColumnsButton(scrollPane); 748 749 centerPanel.add(scrollPane, BorderLayout.CENTER); 750 add(centerPanel, BorderLayout.CENTER); 751 752 Action [] actions = getToolBarActions(); 753 JToolBar toolbar = UTUtils.createToolbarPresenter(actions); 754 toolbar.setFloatable(false); 755 toolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); toolbar.setOrientation(JToolBar.VERTICAL); 757 toolbar.setBorder(new RightSideBorder()); 758 add(toolbar, BorderLayout.WEST); 759 760 if (tt.getRowCount() > 0) 761 tt.getSelectionModel().setSelectionInterval(0, 0); 762 } 763 764 767 protected void loadFilters() { 768 FileSystem fs = Repository.getDefault().getDefaultFileSystem(); 769 FileObject fo = fs.findResource("TaskList/" + USER_CATEGORY + "/filters.settings"); assert fo != null : "Missing config TaskList/" + USER_CATEGORY + "/filters.settings"; 774 try { 775 DataObject dobj = DataObject.find(fo); 776 InstanceCookie ic = (InstanceCookie) dobj.getCookie(InstanceCookie.class); 777 filters = (FilterRepository) ic.instanceCreate(); 778 779 filters.setActive(null); 788 789 if (filters.size() == 0) { 791 Filter f = createFilter(); 792 f.setName(DEFAULT_FILTER_NAME); 793 filters.add(f); 794 } 795 796 } catch (ClassNotFoundException e) { 797 UTUtils.LOGGER.log(Level.WARNING, "", e); } catch (DataObjectNotFoundException e) { 799 UTUtils.LOGGER.log(Level.WARNING, "", e); } catch (IOException e) { 801 UTUtils.LOGGER.log(Level.WARNING, "", e); } 803 } 804 805 808 protected void componentOpened() { 809 UserTaskViewRegistry.getInstance().viewOpened(this); 810 if (initialized) { 811 return; 812 } 813 initialized = true; 814 815 UserTaskViewRegistry.getInstance().setLastActivated(this); 816 } 817 818 819 822 protected void componentClosed() { 823 UserTask started = StartedUserTask.getInstance().getStarted(); 824 if (started != null && started.getList() == getUserTaskList()) 825 started.stop(); 826 827 getUserTaskList().destroy(); 828 829 UserTaskViewRegistry.getInstance().viewClosed(this); 830 831 try { 832 TaskListDataObject do_ = (TaskListDataObject) DataObject.find(file); 833 do_.release(); 834 } catch (DataObjectNotFoundException e) { 835 UTUtils.LOGGER.log(Level.SEVERE, e.getMessage(), e); 836 } 837 } 838 839 842 public void showInMode() { 843 if (!isOpened()) { 844 Mode mode = WindowManager.getDefault().findMode("output"); if (mode != null) { 846 mode.dockInto(UserTaskView.this); 847 } 848 } 849 open(); 850 requestVisible(); 851 requestActive(); 852 } 853 854 859 public UserTaskList getUserTaskList() { 860 return this.tasklist; 861 } 862 863 869 public final Filter getFilter() { 870 return activeFilter; 871 } 872 873 877 public FilterRepository getFilters() { 878 if (filters == null) loadFilters(); 879 assert filters != null : "Missing FilterRepository"; 881 return filters; 882 } 883 884 885 public final boolean isFiltered() { 886 return getFilter() != null; 887 } 888 889 893 public void setFilter(Filter filter) { 894 if (filter == null || getFilters().contains(filter)) { 895 getFilters().setActive(filter); 896 } 897 898 this.activeFilter = filter; 899 setFiltered(); 900 } 901 902 public void requestActive() { 903 super.requestActive(); 904 if (tt != null) { 905 tt.requestFocusInWindow(); 906 } 907 } 908 909 public void fileRenamed(org.openide.filesystems.FileRenameEvent fe) { 910 SwingUtilities.invokeLater(new Runnable () { 911 public void run() { 912 UserTaskView.this.updateNameAndToolTip(); 913 } 914 }); 915 } 916 917 public void fileAttributeChanged(org.openide.filesystems.FileAttributeEvent fe) { 918 } 919 920 public void fileFolderCreated(FileEvent fe) { 921 } 922 923 public void fileDeleted(FileEvent fe) { 924 SwingUtilities.invokeLater(new Runnable () { 925 public void run() { 926 UserTaskView.this.close(); 927 } 928 }); 929 } 930 931 public void fileDataCreated(FileEvent fe) { 932 } 933 934 public void fileChanged(FileEvent fe) { 935 } 936 937 940 941 979 980 983 private void configureActions() { 984 moveUpAction = new MoveUpAction(this); 985 moveDownAction = new MoveDownAction(this); 986 moveLeftAction = new MoveLeftAction(this); 987 moveRightAction = new MoveRightAction(this); 988 purgeTasksAction = new PurgeTasksAction(this); 989 clearCompletedAction = new ClearCompletedAction(this); 990 newTaskAction = new NewTaskAction(this); 991 showTaskAction = new ShowTaskAction(this); 992 propertiesAction = new UTPropertiesAction(this); 993 pasteAtTopLevelAction = new UTPasteAtTopLevelAction(this); 994 995 try { 996 saveAction = new UTSaveAction(DataObject.find(file)); 997 } catch (DataObjectNotFoundException e) { 998 UTUtils.LOGGER.log(Level.SEVERE, e.getMessage(), e); 999 return; 1000 } 1001 1002 getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT). 1003 put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 1004 InputEvent.CTRL_MASK), "moveUp"); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT). 1006 put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 1007 InputEvent.CTRL_MASK), "moveDown"); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT). 1009 put((KeyStroke ) newTaskAction.getValue(Action.ACCELERATOR_KEY), 1010 "newTask"); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT). 1012 put((KeyStroke ) saveAction.getValue(Action.ACCELERATOR_KEY), 1013 "save"); 1015 ActionMap map = getActionMap(); 1016 map.put(javax.swing.text.DefaultEditorKit.copyAction, 1017 new UTCopyAction(this)); 1018 map.put(javax.swing.text.DefaultEditorKit.cutAction, 1019 new UTCutAction(this)); 1020 map.put(javax.swing.text.DefaultEditorKit.pasteAction, 1021 new UTPasteAction(this)); 1022 1023 map.put("delete", new UTDeleteAction(tt)); map.put("moveUp", moveUpAction); map.put("moveDown", moveDownAction); map.put("newTask", newTaskAction); map.put("save", saveAction); 1029 FindAction find = (FindAction) FindAction.get(FindAction.class); 1030 FilterAction filter = (FilterAction) 1031 FilterAction.get(FilterAction.class); 1032 map.put(find.getActionMapKey(), filter); 1033 } 1034} 1035 | Popular Tags |