1 20 21 import java.awt.*; 22 import java.awt.event.*; 23 import javax.swing.*; 24 import javax.swing.border.*; 25 import javax.swing.event.*; 26 import javax.swing.tree.*; 27 import javax.swing.table.TableColumn ; 28 29 import java.net.URL ; 30 import java.net.MalformedURLException ; 31 import java.util.ArrayList ; 32 import java.util.List ; 33 import java.util.Iterator ; 34 import java.io.IOException ; 35 import java.io.File ; 36 37 import org.jdesktop.jdic.desktop.*; 38 39 40 47 public class FileExplorer extends JPanel { 48 public static ImageIcon computerIcon; 49 public static ImageIcon driverIcon; 50 public static ImageIcon folderIcon; 51 public static ImageIcon fileIcon; 52 public static ImageIcon browseIcon; 53 54 public static String MY_COMPUTER_FOLDER_PATH = System.getProperty("java.io.tmpdir") 55 + File.separator + "My Computer"; 56 57 public static MyTreeNode selectedTreeNode = null; 59 File selectedFile = null; 61 62 BorderLayout borderLayout1 = new BorderLayout(); 63 JPopupMenu jDesktopPopupMenu = new JPopupMenu(); 64 JMenuItem jMenuItemOpen = new JMenuItem(); 65 JMenuItem jMenuItemEdit = new JMenuItem(); 66 JMenuItem jMenuItemPrint = new JMenuItem(); 67 JMenuItem jMenuItemBrowse = new JMenuItem(); 68 JMenuItem jMenuItemMail = new JMenuItem(); 69 70 JSplitPane jSplitPane = new JSplitPane(); 71 JTree jTreeDisk = new JTree(createTreeModel()); 72 73 JScrollPane tableScrollPane = new JScrollPane(); 74 MyTableModel tableModel = new MyTableModel(); 75 MyTable jTable = new MyTable(); 76 77 JPanel jAddressPanel = new JPanel(); 78 JLabel jAddressLabel = new JLabel(); 79 JTextField jAddressTextField = new JTextField(); 80 JButton jBrowseButton = new JButton(); 81 82 MyStatusBar statusBar = new MyStatusBar(); 83 84 public FileExplorer() { 85 try { 86 System.setSecurityManager(null); 87 jbInit(); 88 } catch (Exception e) { 89 e.printStackTrace(); 90 } 91 } 92 93 public static void main(String [] args) { 94 try { 95 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 96 } catch (Exception e) {} 97 98 JFrame frame = new JFrame("JDIC API Demo - FileExplorer"); 99 100 Container contentPane = frame.getContentPane(); 101 102 contentPane.setLayout(new GridLayout(1, 1)); 103 contentPane.add(new FileExplorer()); 104 105 frame.addWindowListener(new WindowAdapter() { 106 public void windowClosing(WindowEvent e) { 107 System.exit(0); 108 } 109 }); 110 111 frame.pack(); 112 frame.setVisible(true); 113 } 114 115 private void jbInit() throws Exception { 116 try { 117 computerIcon = new ImageIcon(FileExplorer.class.getResource("images/Computer.gif")); 118 driverIcon = new ImageIcon(FileExplorer.class.getResource("images/Driver.gif")); 119 folderIcon = new ImageIcon(FileExplorer.class.getResource("images/Folder.gif")); 120 fileIcon = new ImageIcon(FileExplorer.class.getResource("images/File.gif")); 121 browseIcon = new ImageIcon(FileExplorer.class.getResource("images/Right.gif")); 122 } catch (Exception e) { 123 System.out.println("ERROR loading image files !"); 124 } 125 126 this.setLayout(borderLayout1); 127 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 128 129 this.setPreferredSize(new Dimension(screenSize.width * 4 / 5, 130 screenSize.height * 7 / 10)); 131 132 jMenuItemOpen.setText("Open"); 133 jMenuItemOpen.addActionListener(new 134 FileExplorer_jMenuItemOpen_actionAdapter(this)); 135 jMenuItemEdit.setText("Edit"); 136 jMenuItemEdit.addActionListener(new 137 FileExplorer_jMenuItemEdit_actionAdapter(this)); 138 jMenuItemPrint.setText("Print"); 139 jMenuItemPrint.addActionListener(new 140 FileExplorer_jMenuItemPrint_actionAdapter(this)); 141 jMenuItemBrowse.setText("Browse"); 142 jMenuItemBrowse.addActionListener(new 143 FileExplorer_jMenuItemBrowse_actionAdapter(this)); 144 jMenuItemMail.setText("Mail to ..."); 145 jMenuItemMail.addActionListener(new 146 FileExplorer_jMenuItemMail_actionAdapter(this)); 147 148 jTreeDisk.addTreeExpansionListener(new 149 FileExplorer_jTreeDisk_treeExpansionAdapter(this)); 150 jAddressLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4)); 151 jAddressLabel.setToolTipText(""); 152 jAddressLabel.setText("Address"); 153 154 jBrowseButton.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(0, 155 2, 0, 2), 156 new EtchedBorder())); 157 jBrowseButton.setToolTipText("Browse the given URL with system default browser"); 158 jBrowseButton.setIcon(browseIcon); 159 jBrowseButton.setText("Browse "); 160 jBrowseButton.addActionListener(new 161 FileExplorer_jBrowseButton_actionAdapter(this)); 162 jAddressPanel.setLayout(new BorderLayout()); 163 164 jAddressTextField.addActionListener(new 165 FileExplorer_jAddressTextField_actionAdapter(this)); 166 167 jAddressPanel.add(jAddressLabel, BorderLayout.WEST); 168 jAddressPanel.add(jAddressTextField, BorderLayout.CENTER); 169 jAddressPanel.add(jBrowseButton, BorderLayout.EAST); 170 jAddressPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0)); 171 172 jTreeDisk.addMouseListener(new FileExplorer_jTreeDisk_mouseAdapter(this)); 173 jTreeDisk.addTreeWillExpandListener(new 174 FileExplorer_jTreeDisk_treeWillExpandAdapter(this)); 175 jTreeDisk.setCellRenderer(new MyTreeRenderer()); 176 jTreeDisk.getSelectionModel().setSelectionMode 177 (TreeSelectionModel.SINGLE_TREE_SELECTION); 178 jTreeDisk.setSelectionRow(0); 179 jTreeDisk.setBackground(Color.white); 180 jTreeDisk.setAlignmentX((float) 0.5); 181 jTreeDisk.setShowsRootHandles(false); 182 jTreeDisk.addTreeSelectionListener(new 183 FileExplorer_jTreeDisk_treeSelectionAdapter(this)); 184 185 jTable.setBorder(null); 186 jTable.setModel(tableModel); 187 TableColumn column = jTable.getColumnModel().getColumn(0); 188 189 column.setCellRenderer(new MyTableRenderer()); 190 column = jTable.getColumnModel().getColumn(1); 191 column.setCellRenderer(new MyTableRenderer()); 192 193 jTable.setShowHorizontalLines(false); 194 jTable.setShowVerticalLines(false); 195 jTable.addMouseListener(new FileExplorer_jTable_mouseAdapter(this)); 196 197 tableScrollPane.setViewportView(jTable); 198 199 jSplitPane.setBorder(null); 200 jSplitPane.add(new JScrollPane(jTreeDisk), JSplitPane.LEFT); 201 jSplitPane.add(tableScrollPane, JSplitPane.RIGHT); 202 203 statusBar.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); 204 statusBar.lblDesc.setText("JDIC API Demo - FileExplorer"); 205 206 this.add(jAddressPanel, BorderLayout.NORTH); 207 this.add(jSplitPane, BorderLayout.CENTER); 208 this.add(statusBar, BorderLayout.SOUTH); 209 } 210 211 212 private DefaultTreeModel createTreeModel() { 213 MyTreeNode rootNode = null; 215 216 String osName = System.getProperty("os.name").toLowerCase(); 217 218 if (osName.startsWith("windows")) { 219 File MY_COMPUTER_FOLDER_FILE = new File (MY_COMPUTER_FOLDER_PATH); 221 222 MY_COMPUTER_FOLDER_FILE.mkdirs(); 223 MY_COMPUTER_FOLDER_FILE.deleteOnExit(); 225 226 rootNode = new MyTreeNode(MY_COMPUTER_FOLDER_FILE); 227 228 MyTreeNode parent; 229 File [] roots = MyUtility.getRoots(); 230 231 int readfirst = 0; 235 236 if (roots[readfirst].getPath().toLowerCase().startsWith("a:")) { 237 readfirst = 1; 238 } 239 for (int i = readfirst; i < roots.length; i++) { 240 parent = new MyTreeNode(roots[i]); 241 242 parent.explore(); 243 244 rootNode.add(parent); 245 } 246 247 selectedTreeNode = rootNode; 249 selectedFile = null; 250 } else if (osName.startsWith("linux") || osName.startsWith("sunos") 251 || osName.startsWith("freebsd") || osName.startsWith("mac os")) { 252 File rootFile = new File ("/"); 253 254 rootNode = new MyTreeNode(rootFile); 255 256 rootNode.explore(); 257 selectedTreeNode = (MyTreeNode) rootNode; 258 selectedFile = selectedTreeNode.getFile(); 259 } else { 260 throw new UnsupportedOperationException ("The demo is not " 261 + "supported on this platform."); 262 } 263 264 return new DefaultTreeModel(rootNode); 265 } 266 267 void jTreeDisk_valueChanged(TreeSelectionEvent e) { 268 selectedTreeNode = (MyTreeNode) 269 jTreeDisk.getLastSelectedPathComponent(); 270 271 selectedFile = null; 272 273 if (selectedTreeNode != null) { 275 File selectedDir = (File ) selectedTreeNode.getUserObject(); 276 277 updateStatusInfo(); 279 } 280 281 tableModel.setColumnNames(); 283 tableModel.setTableData(); 284 jTable.repaint(); 285 286 tableScrollPane.revalidate(); 289 } 290 291 void jTreeDisk_treeExpanded(TreeExpansionEvent e) { 292 DefaultTreeModel treeModel = (DefaultTreeModel) jTreeDisk.getModel(); 293 TreePath newPath = new TreePath(treeModel.getPathToRoot(selectedTreeNode)); 294 295 jTreeDisk.setSelectionPath(newPath); 296 jTreeDisk.scrollPathToVisible(newPath); 297 } 298 299 void jTreeDisk_mouseClicked(MouseEvent e) { 300 TreePath curTreePath = jTreeDisk.getClosestPathForLocation(e.getX(), 303 e.getY()); 304 305 jTreeDisk.clearSelection(); 306 jTreeDisk.addSelectionPath(curTreePath); 307 } 308 309 void jTreeDisk_treeWillExpand(TreeExpansionEvent e) throws 310 ExpandVetoException { 311 312 TreePath path = e.getPath(); 313 MyTreeNode selectedNode = (MyTreeNode) path.getLastPathComponent(); 314 315 if (!selectedNode.isExplored()) { 316 selectedNode.explore(); 317 } 318 } 319 320 324 private void exploreDirectory(MyTreeNode parentTreeNode, 325 File selectedSubDir) { 326 if (!parentTreeNode.isExplored()) { 327 parentTreeNode.explore(); 328 } 329 330 int count = jTreeDisk.getModel().getChildCount(parentTreeNode); 331 332 for (int i = 0; i < count; i++) { 333 Object oneChild = jTreeDisk.getModel().getChild(parentTreeNode, i); 334 335 if (oneChild instanceof MyTreeNode) { 336 File file = (File ) ((MyTreeNode) oneChild).getUserObject(); 337 338 if (file.equals(selectedSubDir)) { 339 selectedTreeNode = (MyTreeNode) oneChild; 340 break; 341 } 342 } 343 } 344 345 TreePath newPath = new TreePath(selectedTreeNode.getPath()); 346 347 if (jTreeDisk.isExpanded(newPath)) { 348 jTreeDisk.setSelectionPath(newPath); 350 jTreeDisk.scrollPathToVisible(newPath); 351 } else { 352 jTreeDisk.expandPath(newPath); 353 } 354 } 355 356 359 private void expandPaths(JTree tree, List paths) { 360 Iterator iter = paths.iterator(); 361 362 if (!iter.hasNext()) { 363 return; 364 } 365 366 MyTreeNode parentNode = (MyTreeNode) tree.getModel().getRoot(); 367 368 if (!parentNode.isExplored()) { 369 parentNode.explore(); 370 } 371 372 File parentFile = (File ) ((MyTreeNode) parentNode).getUserObject(); 378 379 if (parentFile.equals(new File (FileExplorer.MY_COMPUTER_FOLDER_PATH))) { 380 int count = jTreeDisk.getModel().getChildCount(parentNode); 381 boolean pathNotFound = true; 382 383 for (int i = 0; i < count; i++) { 384 Object oneChild = jTreeDisk.getModel().getChild(parentNode, i); 385 String onePath = ((MyTreeNode) oneChild).toString(); 386 387 if (onePath.equalsIgnoreCase((String ) iter.next())) { 388 parentNode = (MyTreeNode) oneChild; 389 pathNotFound = false; 390 break; 391 } 392 } 393 } else { 394 if (!parentFile.equals((String ) iter.next())) { 395 return; 396 } 397 } 398 399 boolean pathNotFound = false; 400 401 while (iter.hasNext() && !pathNotFound) { 402 if (!parentNode.isExplored()) { 403 parentNode.explore(); 404 } 405 406 String nextPath = (String ) iter.next(); 407 408 pathNotFound = true; 409 int count = jTreeDisk.getModel().getChildCount(parentNode); 410 411 for (int i = 0; i < count; i++) { 412 Object oneChild = jTreeDisk.getModel().getChild(parentNode, i); 413 String onePath = ((MyTreeNode) oneChild).toString(); 414 415 if (onePath.equalsIgnoreCase(nextPath)) { 416 parentNode = (MyTreeNode) oneChild; 417 pathNotFound = false; 418 break; 419 } 420 } 421 } 422 423 if (pathNotFound) { 424 return; 425 } else { 426 selectedTreeNode = parentNode; 427 TreePath newPath = new TreePath(selectedTreeNode.getPath()); 428 429 if (jTreeDisk.isExpanded(newPath)) { 430 jTreeDisk.setSelectionPath(newPath); 432 jTreeDisk.scrollPathToVisible(newPath); 433 } else { 434 jTreeDisk.expandPath(newPath); 435 } 436 } 437 } 438 439 443 private void exploreDirectory(File selectedDir) { 444 List paths = new ArrayList (); 446 String selectedAbsPath = selectedDir.getAbsolutePath(); 447 int beginIndex = 0; 448 int endIndex = selectedAbsPath.indexOf(File.separator); 449 450 paths.add(selectedAbsPath.substring(beginIndex, endIndex + 1)); 453 beginIndex = endIndex + 1; 454 endIndex = selectedAbsPath.indexOf(File.separator, beginIndex); 455 while (endIndex != -1) { 456 paths.add(selectedAbsPath.substring(beginIndex, endIndex)); 458 beginIndex = endIndex + 1; 459 endIndex = selectedAbsPath.indexOf(File.separator, beginIndex); 460 } 461 String lastPath = selectedAbsPath.substring(beginIndex, 462 selectedAbsPath.length()); 463 464 if ((lastPath != null) && (lastPath.length() != 0)) { 465 paths.add(lastPath); 466 } 467 468 expandPaths(jTreeDisk, paths); 469 } 470 471 479 private void updateStatusInfo() { 480 File selectedDir = (File ) selectedTreeNode.getUserObject(); 481 482 if (selectedDir.equals(new File (FileExplorer.MY_COMPUTER_FOLDER_PATH))) { 483 if (selectedFile == null) { 487 jAddressTextField.setText(""); 488 statusBar.lblObject.setText(selectedTreeNode.getChildrenCount() 489 + " object(s)"); 490 } else { 491 jAddressTextField.setText(selectedFile.getPath()); 492 statusBar.lblObject.setText("1 object(s) selected"); 493 } 494 495 statusBar.lblSize.setText("0 Bytes"); 496 } else { 497 if (selectedFile == null) { 498 jAddressTextField.setText(selectedDir.getPath()); 499 500 statusBar.lblObject.setText(selectedTreeNode.getChildrenCount() 501 + " object(s)"); 502 statusBar.lblSize.setText(MyUtility.length2KB(selectedTreeNode.getSize())); 503 } else { 504 jAddressTextField.setText(selectedFile.getPath()); 505 506 statusBar.lblObject.setText("1 object(s) selected"); 507 statusBar.lblSize.setText(MyUtility.length2KB(selectedFile.length())); 508 } 509 } 510 } 511 512 void jTable_maybePopUpMenu(MouseEvent e) { 513 if (e.isPopupTrigger() == false || selectedFile == null) { 514 return; 515 } 516 517 if (!selectedFile.isDirectory()) { 518 jDesktopPopupMenu.removeAll(); 521 jDesktopPopupMenu.add(jMenuItemOpen); 522 jDesktopPopupMenu.add(jMenuItemEdit); 523 jDesktopPopupMenu.add(jMenuItemPrint); 524 jDesktopPopupMenu.addSeparator(); 525 jDesktopPopupMenu.add(jMenuItemBrowse); 526 jDesktopPopupMenu.addSeparator(); 527 jDesktopPopupMenu.add(jMenuItemMail); 528 529 if (Desktop.isEditable(selectedFile)) { 530 jMenuItemEdit.setEnabled(true); 531 } else { 532 jMenuItemEdit.setEnabled(false); 533 } 534 535 if (Desktop.isPrintable(selectedFile)) { 536 jMenuItemPrint.setEnabled(true); 537 } else { 538 jMenuItemPrint.setEnabled(false); 539 } 540 541 jDesktopPopupMenu.show((Component) jTable, e.getX(), e.getY()); 542 } else { 543 jDesktopPopupMenu.removeAll(); 546 jDesktopPopupMenu.add(jMenuItemOpen); 547 jDesktopPopupMenu.addSeparator(); 548 jDesktopPopupMenu.add(jMenuItemBrowse); 549 550 jDesktopPopupMenu.show((Component) jTable, e.getX(), e.getY()); 551 } 552 } 553 554 void jTable_mouseClicked(MouseEvent e) { 555 int curRow = jTable.rowAtPoint(new Point(e.getX(), e.getY())); 556 557 if (curRow == -1) { 558 selectedFile = null; 559 updateStatusInfo(); 560 jTable.clearSelection(); 561 return; 562 } 563 564 if (SwingUtilities.isRightMouseButton(e)) { 565 curRow = jTable.rowAtPoint(new Point(e.getX(), e.getY())); 568 jTable.clearSelection(); 569 jTable.addRowSelectionInterval(curRow, curRow); 570 } 571 572 ListSelectionModel lsm = jTable.getSelectionModel(); 573 int selectedRow = lsm.getMinSelectionIndex(); 574 575 DiskObject selectedObject = (DiskObject) tableModel.getValueAt(selectedRow, 576 0); 577 File selectedDir = (File ) selectedTreeNode.getUserObject(); 578 579 if (selectedDir.equals(new File (FileExplorer.MY_COMPUTER_FOLDER_PATH))) { 580 selectedFile = new File (selectedObject.name); 584 } else { 585 selectedFile = new File (selectedDir.toString() + File.separator 586 + selectedObject.name); 587 } 588 589 updateStatusInfo(); 591 592 if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) { 593 if (!selectedFile.isDirectory()) { 598 try { 599 Desktop.open(selectedFile); 600 } catch (DesktopException de) { 601 JOptionPane.showMessageDialog(this, de.getMessage(), "Error", 602 JOptionPane.ERROR_MESSAGE); 603 } 604 } else { 605 exploreDirectory(selectedTreeNode, selectedFile); 607 } 608 } 609 } 610 611 void jMenuItemOpen_actionPerformed(ActionEvent e) { 612 if (!selectedFile.isDirectory()) { 613 try { 614 Desktop.open(selectedFile); 615 } catch (DesktopException de) { 616 JOptionPane.showMessageDialog(this, de.getMessage(), "Error", 617 JOptionPane.ERROR_MESSAGE); 618 } 619 } else { 620 exploreDirectory(selectedTreeNode, selectedFile); 622 } 623 } 624 625 void jMenuItemEdit_actionPerformed(ActionEvent e) { 626 try { 627 Desktop.edit(selectedFile); 628 } catch (DesktopException de) { 629 JOptionPane.showMessageDialog(this, de.getMessage(), "Error", 630 JOptionPane.ERROR_MESSAGE); 631 } 632 } 633 634 void jMenuItemPrint_actionPerformed(ActionEvent e) { 635 try { 636 Desktop.print(selectedFile); 637 } catch (DesktopException de) { 638 JOptionPane.showMessageDialog(this, de.getMessage(), "Error", 639 JOptionPane.ERROR_MESSAGE); 640 } 641 } 642 643 void jMenuItemBrowse_actionPerformed(ActionEvent e) { 644 URL fileURL = null; 645 646 try { 647 fileURL = selectedFile.toURL(); 648 } catch (MalformedURLException mue) { 649 JOptionPane.showMessageDialog(this, mue.getMessage(), "Error", 650 JOptionPane.ERROR_MESSAGE); 651 } 652 653 try { 654 Desktop.browse(fileURL); 655 } catch (DesktopException de) { 656 JOptionPane.showMessageDialog(this, de.getMessage(), "Error", 657 JOptionPane.ERROR_MESSAGE); 658 } 659 } 660 661 void jMenuItemMail_actionPerformed(ActionEvent e) { 662 Message msg = new Message(); 663 List attachList = new ArrayList (); 664 665 attachList.add(selectedFile.getPath()); 666 try { 667 msg.setAttachments(attachList); 668 } catch (IOException ioe) { 669 JOptionPane.showMessageDialog(this, ioe.getMessage(), "Error", 670 JOptionPane.ERROR_MESSAGE); 671 } 672 673 try { 674 Desktop.mail(msg); 675 } catch (DesktopException de) { 676 JOptionPane.showMessageDialog(this, de.getMessage(), "Error", 677 JOptionPane.ERROR_MESSAGE); 678 } 679 } 680 681 void jBrowseButton_actionPerformed(ActionEvent e) { 682 String addrValue = jAddressTextField.getText(); 683 String addrValueTrim; 684 685 if ((addrValue != null) && addrValue.trim() != null) { 686 addrValueTrim = addrValue.trim(); 687 688 URL addressURL = address2URL(addrValueTrim); 689 690 if (addressURL == null) { 691 JOptionPane.showMessageDialog(this, 692 "Cannot find '" + addrValueTrim 693 + "'. Make sure the path or Internet address is correct.", 694 "Error", 695 JOptionPane.ERROR_MESSAGE); 696 } else { 697 try { 698 Desktop.browse(addressURL); 699 } catch (DesktopException de) { 700 JOptionPane.showMessageDialog(this, de.getMessage(), "Error", 701 JOptionPane.ERROR_MESSAGE); 702 } 703 } 704 } 705 } 706 707 File address2LocalFile(String address) { 710 File localFile = null; 713 File [] roots = MyUtility.getRoots(); 714 715 for (int i = 0; i < roots.length; i++) { 716 if (address.toLowerCase().startsWith(roots[i].toString().toLowerCase())) { 717 localFile = new File (address); 718 break; 719 } 720 } 721 722 return localFile; 723 } 724 725 URL address2URL(String address) { 728 URL tempUrl = null; 729 730 try { 731 File localFile = address2LocalFile(address); 732 733 if (localFile != null) { 734 tempUrl = localFile.toURL(); 735 } else { 736 try { 738 tempUrl = new URL (address); 739 } catch (MalformedURLException e) { 740 if (address.toLowerCase().startsWith("ftp.")) { 741 tempUrl = new URL ("ftp://" + address); 742 } else if (address.toLowerCase().startsWith("gopher.")) { 743 tempUrl = new URL ("gopher://" + address); 744 } else { 745 tempUrl = new URL ("http://" + address); 746 } 747 } 748 } 749 } catch (MalformedURLException mue) {} 750 751 return tempUrl; 752 } 753 754 void jAddressTextField_actionPerformed(ActionEvent e) { 755 String addrValue = jAddressTextField.getText(); 756 757 if ((addrValue == null) || addrValue.trim() == null) { 758 return; 759 } 760 761 String addrValueTrim = addrValue.trim(); 762 763 File localFile = address2LocalFile(addrValueTrim); 765 766 if (localFile != null) { 767 if (localFile.isFile()) { 768 try { 770 Desktop.open(localFile); 771 } catch (DesktopException de) { 772 JOptionPane.showMessageDialog(this, de.getMessage(), "Error", 773 JOptionPane.ERROR_MESSAGE); 774 } 775 } else if (localFile.isDirectory()) { 776 exploreDirectory(localFile); 777 } else { 778 JOptionPane.showMessageDialog(this, 779 "Cannot find '" + addrValue 780 + "'. Make sure the path or Internet address is correct.", 781 "Error", 782 JOptionPane.ERROR_MESSAGE); 783 } 784 } else { 785 URL tempUrl = address2URL(addrValueTrim); 787 788 if (tempUrl == null) { 789 JOptionPane.showMessageDialog(this, 790 "Cannot find '" + addrValue 791 + "'. Make sure the path or Internet address is correct.", 792 "Error", 793 JOptionPane.ERROR_MESSAGE); 794 } else { 795 try { 796 Desktop.browse(tempUrl); 797 } catch (DesktopException de) { 798 JOptionPane.showMessageDialog(this, de.getMessage(), "Error", 799 JOptionPane.ERROR_MESSAGE); 800 } 801 } 802 } 803 } 804 } 805 806 807 class FileExplorer_jTreeDisk_treeSelectionAdapter 808 implements javax.swing.event.TreeSelectionListener { 809 FileExplorer adaptee; 810 811 FileExplorer_jTreeDisk_treeSelectionAdapter(FileExplorer adaptee) { 812 this.adaptee = adaptee; 813 } 814 815 public void valueChanged(TreeSelectionEvent e) { 816 adaptee.jTreeDisk_valueChanged(e); 817 } 818 } 819 820 821 class FileExplorer_jTable_mouseAdapter extends java.awt.event.MouseAdapter { 822 FileExplorer adaptee; 823 824 FileExplorer_jTable_mouseAdapter(FileExplorer adaptee) { 825 this.adaptee = adaptee; 826 } 827 828 public void mouseClicked(MouseEvent e) { 829 adaptee.jTable_mouseClicked(e); 830 } 831 832 public void mousePressed(MouseEvent e) { 833 adaptee.jTable_maybePopUpMenu(e); 834 } 835 836 public void mouseReleased(MouseEvent e) { 837 adaptee.jTable_maybePopUpMenu(e); 838 } 839 } 840 841 842 class FileExplorer_jTreeDisk_treeExpansionAdapter implements javax.swing.event.TreeExpansionListener { 843 FileExplorer adaptee; 844 845 FileExplorer_jTreeDisk_treeExpansionAdapter(FileExplorer adaptee) { 846 this.adaptee = adaptee; 847 } 848 849 public void treeExpanded(TreeExpansionEvent e) { 850 adaptee.jTreeDisk_treeExpanded(e); 851 } 852 853 public void treeCollapsed(TreeExpansionEvent e) {} 854 } 855 856 857 class FileExplorer_jMenuItemOpen_actionAdapter implements java.awt.event.ActionListener { 858 FileExplorer adaptee; 859 860 FileExplorer_jMenuItemOpen_actionAdapter(FileExplorer adaptee) { 861 this.adaptee = adaptee; 862 } 863 864 public void actionPerformed(ActionEvent e) { 865 adaptee.jMenuItemOpen_actionPerformed(e); 866 } 867 } 868 869 870 class FileExplorer_jMenuItemEdit_actionAdapter implements java.awt.event.ActionListener { 871 FileExplorer adaptee; 872 873 FileExplorer_jMenuItemEdit_actionAdapter(FileExplorer adaptee) { 874 this.adaptee = adaptee; 875 } 876 877 public void actionPerformed(ActionEvent e) { 878 adaptee.jMenuItemEdit_actionPerformed(e); 879 } 880 } 881 882 883 class FileExplorer_jMenuItemPrint_actionAdapter implements java.awt.event.ActionListener { 884 FileExplorer adaptee; 885 886 FileExplorer_jMenuItemPrint_actionAdapter(FileExplorer adaptee) { 887 this.adaptee = adaptee; 888 } 889 890 public void actionPerformed(ActionEvent e) { 891 adaptee.jMenuItemPrint_actionPerformed(e); 892 } 893 } 894 895 896 class FileExplorer_jMenuItemBrowse_actionAdapter implements java.awt.event.ActionListener { 897 FileExplorer adaptee; 898 899 FileExplorer_jMenuItemBrowse_actionAdapter(FileExplorer adaptee) { 900 this.adaptee = adaptee; 901 } 902 903 public void actionPerformed(ActionEvent e) { 904 adaptee.jMenuItemBrowse_actionPerformed(e); 905 } 906 } 907 908 909 class FileExplorer_jMenuItemMail_actionAdapter implements java.awt.event.ActionListener { 910 FileExplorer adaptee; 911 912 FileExplorer_jMenuItemMail_actionAdapter(FileExplorer adaptee) { 913 this.adaptee = adaptee; 914 } 915 916 public void actionPerformed(ActionEvent e) { 917 adaptee.jMenuItemMail_actionPerformed(e); 918 } 919 } 920 921 922 class FileExplorer_jBrowseButton_actionAdapter implements java.awt.event.ActionListener { 923 FileExplorer adaptee; 924 925 FileExplorer_jBrowseButton_actionAdapter(FileExplorer adaptee) { 926 this.adaptee = adaptee; 927 } 928 929 public void actionPerformed(ActionEvent e) { 930 adaptee.jBrowseButton_actionPerformed(e); 931 } 932 } 933 934 935 class FileExplorer_jTreeDisk_mouseAdapter extends java.awt.event.MouseAdapter { 936 FileExplorer adaptee; 937 938 FileExplorer_jTreeDisk_mouseAdapter(FileExplorer adaptee) { 939 this.adaptee = adaptee; 940 } 941 942 public void mouseClicked(MouseEvent e) { 943 adaptee.jTreeDisk_mouseClicked(e); 944 } 945 } 946 947 948 class FileExplorer_jTreeDisk_treeWillExpandAdapter implements javax.swing.event.TreeWillExpandListener { 949 FileExplorer adaptee; 950 951 FileExplorer_jTreeDisk_treeWillExpandAdapter(FileExplorer adaptee) { 952 this.adaptee = adaptee; 953 } 954 955 public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException { 956 adaptee.jTreeDisk_treeWillExpand(e); 957 } 958 959 public void treeWillCollapse(TreeExpansionEvent e) {} 960 } 961 962 963 967 class MyTable extends JTable implements Scrollable { 968 public boolean getScrollableTracksViewportHeight() { 969 Component parent = getParent(); 970 971 if (parent instanceof JViewport) { 972 return parent.getHeight() > getPreferredSize().height; 973 } 974 975 return false; 976 } 977 } 978 979 980 class FileExplorer_jAddressTextField_actionAdapter implements java.awt.event.ActionListener { 981 FileExplorer adaptee; 982 983 FileExplorer_jAddressTextField_actionAdapter(FileExplorer adaptee) { 984 this.adaptee = adaptee; 985 } 986 987 public void actionPerformed(ActionEvent e) { 988 adaptee.jAddressTextField_actionPerformed(e); 989 } 990 } 991
| Popular Tags
|