From: <sim...@us...> - 2002-07-30 02:26:20
|
Update of /cvsroot/cdchamber/CDChamber/src/org/cdchamber/gui In directory usw-pr-cvs1:/tmp/cvs-serv17019/src/org/cdchamber/gui Modified Files: CDCMainFrame.java CDCMainFrameController.java CDChamber.java Added Files: AboutDialog.java DirTreeCellRenderer.java FilesTable.java TypeIconCellRenderer.java Log Message: Beautify the GUI --- NEW FILE: AboutDialog.java --- /* * User: Simon * $Id: AboutDialog.java,v 1.1 2002/07/30 02:26:17 simon_lei Exp $ */ package org.cdchamber.gui; import org.cdchamber.util.DirPath; import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.io.StringReader; import java.io.IOException; public class AboutDialog extends JDialog implements ActionListener { String product = "CDChamber $Revision: 1.1 $"; String copyright = "Simon & Crystal Copyright (c) 2002"; String comments = "The CDChamber, manage your cdroms. <br>Contact us at <br><a href=\"http://www.sourceforge.net/projects/cdchamber/\">http://www.sourceforge.net/projects/cdchamber/</a>"; public AboutDialog(Frame parent) { super(parent); init(); pack(); } private void init() { JLabel imageLabel= new JLabel( new ImageIcon( DirPath.getIconPath( "about.jpg"))); JTextPane textPane = new JTextPane(); try { textPane.setContentType("text/html"); StringBuffer sb = new StringBuffer( "<html><body>"); sb.append( product).append( "<br>"); sb.append( copyright).append( "<br>"); sb.append( comments); sb.append( "</body></html>"); textPane.read( new StringReader( sb.toString()), "About CDChamber"); } catch ( IOException e) { e.printStackTrace(); } textPane.setEnabled( false); this.setTitle("About CDChamber"); this.setModal( true); this.setResizable(false); JButton okButton = new JButton( "Ok"); okButton.addActionListener( this); this.getRootPane().setDefaultButton( okButton); this.getContentPane().setLayout( new BorderLayout()); JPanel buttonPanel = new JPanel(); buttonPanel.add( okButton); this.getContentPane().add( buttonPanel, BorderLayout.SOUTH); JPanel mainPanel = new JPanel( new BorderLayout()); mainPanel.add( imageLabel, BorderLayout.WEST); mainPanel.add( textPane, BorderLayout.CENTER); this.getContentPane().add( mainPanel, BorderLayout.CENTER); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { cancel(); } super.processWindowEvent(e); } //Close the dialog void cancel() { dispose(); } //Close the dialog on a button event public void actionPerformed(ActionEvent e) { cancel(); } } --- NEW FILE: DirTreeCellRenderer.java --- /* * User: Simon * $Id: DirTreeCellRenderer.java,v 1.1 2002/07/30 02:26:17 simon_lei Exp $ */ package org.cdchamber.gui; import org.cdchamber.elements.*; import org.cdchamber.util.DirPath; import javax.swing.tree.*; import javax.swing.*; import java.awt.*; public class DirTreeCellRenderer extends DefaultTreeCellRenderer { private static ImageIcon zipFileIcon = new ImageIcon( DirPath.getIconPath("zipFile.jpg")); private static ImageIcon openFolderIcon = new ImageIcon( DirPath.getIconPath("openFolder.jpg")); private static ImageIcon closeFolderIcon = new ImageIcon( DirPath.getIconPath( "closedFolder.jpg")); private static ImageIcon fileIcon = new ImageIcon( DirPath.getIconPath( "file.jpg")); private static ImageIcon openZipFileIcon = new ImageIcon( DirPath.getIconPath( "openZipFile.jpg")); private static ImageIcon cdromIcon = new ImageIcon( DirPath.getIconPath( "cdrom.gif")); private static ImageIcon rootsIcon = new ImageIcon( DirPath.getIconPath( "roots.jpg")); public DirTreeCellRenderer() { } public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus); DefaultMutableTreeNode node = (DefaultMutableTreeNode)value; if ( node.isRoot()) { setIcon( rootsIcon); return this; } Object ft = node.getUserObject(); if ( ft instanceof CDRomType) { setIcon( cdromIcon); } else if ( ft instanceof CompressedFileType) { //if ( tree.isPathSelected( new TreePath(node.getPath()))) { if ( sel) { setIcon( openZipFileIcon); } else { setIcon( zipFileIcon); } } else if ( ft instanceof DirectoryType ) { if ( sel) { setIcon( openFolderIcon); } else { setIcon( closeFolderIcon); } } else { setIcon( fileIcon); } return this; } } --- NEW FILE: FilesTable.java --- /* * User: Simon * $Id: FilesTable.java,v 1.1 2002/07/30 02:26:17 simon_lei Exp $ */ package org.cdchamber.gui; import javax.swing.*; import javax.swing.table.*; import java.awt.*; public class FilesTable extends JTable { public FilesTable() { super(); // setAutoCreateColumnsFromModel(false); setShowGrid(false); setRowHeight(18); } public void setModel(TableModel dataModel) { super.setModel(dataModel); if (! (dataModel instanceof FilesTableModel)) return; for (int k = 0; k < dataModel.getColumnCount(); k++) { DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); ColumnData columnData = FilesTableModel.columnHeads[k]; renderer.setHorizontalAlignment( columnData.alignment); TableColumn column = getColumn( columnData.title); column.setWidth( columnData.width); column.setCellRenderer( renderer); column.setHeaderRenderer(createDefaultRenderer()); } TypeIconCellRenderer typeRenderer = new TypeIconCellRenderer(); getColumn( FilesTableModel.columnHeads[0].title).setCellRenderer(typeRenderer); JTableHeader header = getTableHeader(); header.setUpdateTableInRealTime(true); // header.addMouseListener(new ColumnListener()); header.setReorderingAllowed(true); // jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } protected TableCellRenderer createDefaultRenderer() { DefaultTableCellRenderer label = new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { setForeground(header.getForeground()); setBackground(header.getBackground()); setFont(header.getFont()); } } setText((value == null) ? "" : value.toString()); setBorder(UIManager.getBorder("TableHeader.cellBorder")); return this; } }; label.setHorizontalAlignment(JLabel.CENTER); return label; } } --- NEW FILE: TypeIconCellRenderer.java --- /* * User: Simon * $Id: TypeIconCellRenderer.java,v 1.1 2002/07/30 02:26:17 simon_lei Exp $ */ package org.cdchamber.gui; import org.cdchamber.elements.*; import org.cdchamber.util.DirPath; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.*; public class TypeIconCellRenderer extends DefaultTableCellRenderer { public void setValue(Object value) { if ( value instanceof FileType) { FileType ft = (FileType)value; this.setIcon( getTypeIcon( ft)); this.setText( ft.getName()); } else super.setValue( value); } public ImageIcon getTypeIcon( FileType fileType) { if ( fileType instanceof CDRomType) return new ImageIcon( DirPath.getIconPath("cdrom.gif")); if ( fileType instanceof CompressedFileType) return new ImageIcon( DirPath.getIconPath("zipFile.jpg")); if ( fileType instanceof DirectoryType) return new ImageIcon( DirPath.getIconPath("closedFolder.jpg")); return new ImageIcon( DirPath.getIconPath( "file.jpg")); } } Index: CDCMainFrame.java =================================================================== RCS file: /cvsroot/cdchamber/CDChamber/src/org/cdchamber/gui/CDCMainFrame.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** CDCMainFrame.java 29 Jul 2002 08:42:36 -0000 1.22 --- CDCMainFrame.java 30 Jul 2002 02:26:17 -0000 1.23 *************** *** 8,11 **** --- 8,12 ---- import org.cdchamber.searcher.Searcher; + import org.cdchamber.util.DirPath; import javax.swing.*; *************** *** 31,70 **** JSplitPane mainPane = new JSplitPane(); JTree directoryTree = new FileTree(); ! JTable filesTable = new JTable(); JList resultList = new JList(); JSplitPane realMainPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT); CDCMainFrameController controller; - public String getUserChoosedDataFile() { - JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode( JFileChooser.FILES_ONLY); - chooser.setFileFilter( new XmlFileFilter()); - int retvalue = chooser.showOpenDialog( this); - if ( retvalue != JFileChooser.APPROVE_OPTION) return null; - return chooser.getSelectedFile().getAbsolutePath(); - } - - public String getUserChoosedDirectory() { - JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY); - int retvalue = chooser.showOpenDialog( this); - if ( retvalue != JFileChooser.APPROVE_OPTION) return null; - return chooser.getSelectedFile().getAbsolutePath(); - } - - public void setDirectoryTreeModel(TreeModel model) { - directoryTree.setModel( model); - } - - public void setFilesTableModel(TableModel model) { - filesTable.setModel( model); - } - - public void dealWithActionException( String message, Exception exception) { - JOptionPane.showMessageDialog( this, message); - exception.printStackTrace(); - } - public CDCMainFrame() { super(); --- 32,42 ---- JSplitPane mainPane = new JSplitPane(); JTree directoryTree = new FileTree(); ! JTable filesTable = new FilesTable(); JList resultList = new JList(); JSplitPane realMainPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT); + JToolBar toolBar = new JToolBar(); CDCMainFrameController controller; public CDCMainFrame() { super(); *************** *** 86,93 **** initMenuBar(); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(new BorderLayout()); ! contentPane.add( BorderLayout.CENTER, realMainPane); --- 58,66 ---- initMenuBar(); + initToolsBar(); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(new BorderLayout()); ! contentPane.add( toolBar, BorderLayout.NORTH); contentPane.add( BorderLayout.CENTER, realMainPane); *************** *** 107,110 **** --- 80,84 ---- mainPane.add( JSplitPane.RIGHT, jScrollPaneTable); + directoryTree.setCellRenderer( new DirTreeCellRenderer()); directoryTree.addTreeSelectionListener( controller); resultList.addListSelectionListener( controller); *************** *** 112,115 **** --- 86,114 ---- } + private void initToolsBar() { + toolBar.add( controller.getCreateNewCDRomAction()); + toolBar.add( controller.getImportCDRomAction()); + toolBar.add( controller.getSaveCDRomAction()); + toolBar.add( controller.getDeleteCDRomAction()); + toolBar.addSeparator(); + toolBar.add( controller.getSearchCDRomAction()); + toolBar.addSeparator(); + toolBar.add( new AboutAction()); + } + + class AboutAction extends AbstractAction { + public AboutAction() { + putValue(Action.NAME, "About"); + putValue(Action.MNEMONIC_KEY, new Integer('A')); + putValue( Action.SHORT_DESCRIPTION, "About CDChamber"); + putValue( Action.SMALL_ICON, new ImageIcon( DirPath.getIconPath( "helpAbout.png"))); + } + + public void actionPerformed(ActionEvent e) { + JDialog dialog = new AboutDialog( null); + CDChamber.showWinowAtCenter( dialog); + } + } + private void initMenuBar() { this.setJMenuBar(mainMenu); *************** *** 123,128 **** helpMenu.setMnemonic('H'); helpMenu.setText("Help"); ! helpAboutMenuItem.setMnemonic('A'); ! helpAboutMenuItem.setText("About"); cdromExitMenuItem.setMnemonic('X'); cdromExitMenuItem.setText("Exit"); --- 122,126 ---- helpMenu.setMnemonic('H'); helpMenu.setText("Help"); ! helpAboutMenuItem.setAction( new AboutAction()); cdromExitMenuItem.setMnemonic('X'); cdromExitMenuItem.setText("Exit"); *************** *** 175,178 **** --- 173,207 ---- public JTable getFilesTable() { return filesTable; + } + + public String getUserChoosedDataFile() { + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode( JFileChooser.FILES_ONLY); + chooser.setFileFilter( new XmlFileFilter()); + int retvalue = chooser.showOpenDialog( this); + if ( retvalue != JFileChooser.APPROVE_OPTION) return null; + return chooser.getSelectedFile().getAbsolutePath(); + } + + public String getUserChoosedDirectory() { + JFileChooser chooser = new JFileChooser(); + chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY); + int retvalue = chooser.showOpenDialog( this); + if ( retvalue != JFileChooser.APPROVE_OPTION) return null; + return chooser.getSelectedFile().getAbsolutePath(); + } + + public void setDirectoryTreeModel(TreeModel model) { + directoryTree.setModel( model); + directoryTree.setSelectionRow(0); + } + + public void setFilesTableModel(TableModel model) { + filesTable.setModel( model); + } + + public void dealWithActionException( String message, Exception exception) { + JOptionPane.showMessageDialog( this, message); + exception.printStackTrace(); } Index: CDCMainFrameController.java =================================================================== RCS file: /cvsroot/cdchamber/CDChamber/src/org/cdchamber/gui/CDCMainFrameController.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** CDCMainFrameController.java 29 Jul 2002 08:42:36 -0000 1.18 --- CDCMainFrameController.java 30 Jul 2002 02:26:17 -0000 1.19 *************** *** 78,81 **** --- 78,82 ---- JList list = (JList) e.getSource(); SearchResult result = (SearchResult) list.getSelectedValue(); + if ( result == null) return; DefaultMutableTreeNode node = (DefaultMutableTreeNode) frame.getDirectoryTree().getModel().getRoot(); DefaultMutableTreeNode[] nodes = new DefaultMutableTreeNode[result.getPathDepth()]; *************** *** 149,154 **** public class CreateNewCDRomAction extends AbstractAction { public CreateNewCDRomAction() { ! putValue(Action.NAME, "Create"); ! putValue(Action.MNEMONIC_KEY, new Integer('C')); } --- 150,157 ---- public class CreateNewCDRomAction extends AbstractAction { public CreateNewCDRomAction() { ! putValue( Action.NAME, "Create"); ! putValue( Action.MNEMONIC_KEY, new Integer('C')); ! putValue( Action.SHORT_DESCRIPTION, "Create a new CDRom"); ! putValue( Action.SMALL_ICON, new ImageIcon( DirPath.getIconPath( "createNewCDRom.png"))); } *************** *** 177,180 **** --- 180,185 ---- putValue(Action.NAME, "Import"); putValue(Action.MNEMONIC_KEY, new Integer('I')); + putValue( Action.SHORT_DESCRIPTION, "Import an exist CDRom"); + putValue( Action.SMALL_ICON, new ImageIcon( DirPath.getIconPath( "importCDRom.png"))); } *************** *** 202,205 **** --- 207,212 ---- putValue(Action.NAME, "Delete"); putValue(Action.MNEMONIC_KEY, new Integer('D')); + putValue( Action.SHORT_DESCRIPTION, "Delete the selected CDRom"); + putValue( Action.SMALL_ICON, new ImageIcon( DirPath.getIconPath( "deleteCDRom.png"))); } *************** *** 213,216 **** --- 220,224 ---- roots.removeFiles(cdrom); frame.setDirectoryTreeModel(new FileTreeModel(loadDataFiles())); + frame.setResultListData( new Vector()); } } *************** *** 220,223 **** --- 228,233 ---- putValue(Action.NAME, "Save"); putValue(Action.MNEMONIC_KEY, new Integer('S')); + putValue( Action.SHORT_DESCRIPTION, "Save the selected CDRom"); + putValue( Action.SMALL_ICON, new ImageIcon( DirPath.getIconPath( "saveCDRom.png"))); } *************** *** 240,243 **** --- 250,255 ---- putValue(Action.NAME, "Search"); putValue(Action.MNEMONIC_KEY, new Integer('e')); + putValue( Action.SHORT_DESCRIPTION, "Search files/directories in CDRoms"); + putValue( Action.SMALL_ICON, new ImageIcon( DirPath.getIconPath( "searchCDRom.png"))); } Index: CDChamber.java =================================================================== RCS file: /cvsroot/cdchamber/CDChamber/src/org/cdchamber/gui/CDChamber.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CDChamber.java 19 Jul 2002 02:07:48 -0000 1.3 --- CDChamber.java 30 Jul 2002 02:26:17 -0000 1.4 *************** *** 14,18 **** public static void main(String[] args) { try { ! UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName()); } catch(Exception e) { e.printStackTrace(); --- 14,19 ---- public static void main(String[] args) { try { ! //UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName()); ! UIManager.setLookAndFeel(new com.incors.plaf.kunststoff.KunststoffLookAndFeel()); } catch(Exception e) { e.printStackTrace(); |