From: Mailing l. f. S. c. m. <jtc...@li...> - 2011-01-08 11:14:54
|
Revision: 3241 http://jtcfrost.svn.sourceforge.net/jtcfrost/?rev=3241&view=rev Author: artur8ur Date: 2011-01-08 11:14:45 +0000 (Sat, 08 Jan 2011) Log Message: ----------- - Changed a lot of classes, to inherit and use Java generics. This required a lot of changes in the code, but should make it more maintainable and error resistant in the long term. - Fixed various other warning Modified Paths: -------------- trunk/frost-wot/source/frost/Frost.java trunk/frost-wot/source/frost/MainFrame.java trunk/frost-wot/source/frost/fcp/DataNotFoundException.java trunk/frost-wot/source/frost/fcp/FcpHandler.java trunk/frost-wot/source/frost/fcp/FcpResultGet.java trunk/frost-wot/source/frost/fcp/FcpToolsException.java trunk/frost-wot/source/frost/fileTransfer/FileTransferManager.java trunk/frost-wot/source/frost/fileTransfer/FrostFileListFileObject.java trunk/frost-wot/source/frost/fileTransfer/PersistenceManager.java trunk/frost-wot/source/frost/fileTransfer/SharedFileXmlFile.java trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsDialog.java trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsTableFormat.java trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsTableModel.java trunk/frost-wot/source/frost/fileTransfer/download/DownloadManager.java trunk/frost-wot/source/frost/fileTransfer/download/DownloadModel.java trunk/frost-wot/source/frost/fileTransfer/download/DownloadPanel.java trunk/frost-wot/source/frost/fileTransfer/download/DownloadTableFormat.java trunk/frost-wot/source/frost/fileTransfer/search/SearchModel.java trunk/frost-wot/source/frost/fileTransfer/search/SearchTable.java trunk/frost-wot/source/frost/fileTransfer/sharing/SharedFilesModel.java trunk/frost-wot/source/frost/fileTransfer/sharing/SharedFilesPanel.java trunk/frost-wot/source/frost/fileTransfer/upload/UploadManager.java trunk/frost-wot/source/frost/fileTransfer/upload/UploadModel.java trunk/frost-wot/source/frost/fileTransfer/upload/UploadPanel.java trunk/frost-wot/source/frost/fileTransfer/upload/UploadTableFormat.java trunk/frost-wot/source/frost/messaging/frost/AbstractMessageObject.java trunk/frost-wot/source/frost/messaging/frost/Attachment.java trunk/frost-wot/source/frost/messaging/frost/AttachmentList.java trunk/frost-wot/source/frost/messaging/frost/BoardAttachment.java trunk/frost-wot/source/frost/messaging/frost/FrostMessageObject.java trunk/frost-wot/source/frost/messaging/frost/FrostUnsentMessageObject.java trunk/frost-wot/source/frost/messaging/frost/boards/TOF.java trunk/frost-wot/source/frost/messaging/frost/gui/AttachedBoardTableModel.java trunk/frost-wot/source/frost/messaging/frost/gui/AttachedFilesTableModel.java trunk/frost-wot/source/frost/messaging/frost/gui/MessageTextPane.java trunk/frost-wot/source/frost/messaging/frost/gui/MessageUploadFailedDialog.java trunk/frost-wot/source/frost/messaging/frost/gui/sentmessages/SentMessagesTable.java trunk/frost-wot/source/frost/messaging/frost/gui/sentmessages/SentMessagesTableFormat.java trunk/frost-wot/source/frost/messaging/frost/gui/sentmessages/SentMessagesTableModel.java trunk/frost-wot/source/frost/messaging/frost/gui/unsentmessages/UnsentMessagesTable.java trunk/frost-wot/source/frost/messaging/frost/gui/unsentmessages/UnsentMessagesTableFormat.java trunk/frost-wot/source/frost/messaging/frost/gui/unsentmessages/UnsentMessagesTableModel.java trunk/frost-wot/source/frost/storage/perst/filelist/FileListStorage.java trunk/frost-wot/source/frost/util/model/AbstractTableFormat.java trunk/frost-wot/source/frost/util/model/ModelTable.java trunk/frost-wot/source/frost/util/model/ModelTableFormat.java trunk/frost-wot/source/frost/util/model/SortedModel.java trunk/frost-wot/source/frost/util/model/SortedModelListener.java trunk/frost-wot/source/frost/util/model/SortedModelListenerSupport.java trunk/frost-wot/source/frost/util/model/SortedModelTable.java trunk/frost-wot/source/frost/util/model/SortedTableFormat.java Modified: trunk/frost-wot/source/frost/Frost.java =================================================================== --- trunk/frost-wot/source/frost/Frost.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/Frost.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -248,6 +248,7 @@ core.initialize(); } catch (final Exception e) { logger.log(Level.SEVERE, "There was a problem while initializing Frost.", e); + System.out.println(e.getStackTrace().toString()); System.exit(3); } } Modified: trunk/frost-wot/source/frost/MainFrame.java =================================================================== --- trunk/frost-wot/source/frost/MainFrame.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/MainFrame.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -637,7 +637,7 @@ public void run() { while (true) { Mixed.wait(1000); - // refactor this method in Core. lots of work :) + // TODO: refactor this method in Core. lots of work :) timer_actionPerformed(); } } Modified: trunk/frost-wot/source/frost/fcp/DataNotFoundException.java =================================================================== --- trunk/frost-wot/source/frost/fcp/DataNotFoundException.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fcp/DataNotFoundException.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -18,6 +18,7 @@ */ package frost.fcp; +@SuppressWarnings("serial") public class DataNotFoundException extends FcpToolsException { public DataNotFoundException() { Modified: trunk/frost-wot/source/frost/fcp/FcpHandler.java =================================================================== --- trunk/frost-wot/source/frost/fcp/FcpHandler.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fcp/FcpHandler.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -39,6 +39,7 @@ } public static void initializeFcp(final String node) throws UnsupportedOperationException, Exception { + // Currently hardcoded to version 0.7 (The only existing version) instance = new FcpHandler07(); instance.initialize(node); FreenetKeys.initializeFor07(); Modified: trunk/frost-wot/source/frost/fcp/FcpResultGet.java =================================================================== --- trunk/frost-wot/source/frost/fcp/FcpResultGet.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fcp/FcpResultGet.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -21,7 +21,6 @@ /** * This class is a utility class to provide a datatype for results * returned from an FCP operation. - * This class is used by freenet 05 and 07. 07 does not use the metadata. */ public class FcpResultGet { Modified: trunk/frost-wot/source/frost/fcp/FcpToolsException.java =================================================================== --- trunk/frost-wot/source/frost/fcp/FcpToolsException.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fcp/FcpToolsException.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -15,13 +15,12 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ + */ package frost.fcp; -public class FcpToolsException extends Exception -{ - public FcpToolsException(String s) - { - super(s); - } +@SuppressWarnings("serial") +public class FcpToolsException extends Exception { + public FcpToolsException(String s) { + super(s); + } } Modified: trunk/frost-wot/source/frost/fileTransfer/FileTransferManager.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/FileTransferManager.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/FileTransferManager.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -18,14 +18,18 @@ */ package frost.fileTransfer; -import frost.*; -import frost.fileTransfer.download.*; -import frost.fileTransfer.search.*; -import frost.fileTransfer.sharing.*; -import frost.fileTransfer.upload.*; -import frost.identities.*; -import frost.storage.*; -import frost.util.model.*; +import frost.Core; +import frost.MainFrame; +import frost.fileTransfer.download.DownloadManager; +import frost.fileTransfer.search.SearchManager; +import frost.fileTransfer.sharing.FrostSharedFileItem; +import frost.fileTransfer.sharing.SharedFilesManager; +import frost.fileTransfer.upload.FrostUploadItem; +import frost.fileTransfer.upload.UploadManager; +import frost.identities.LocalIdentity; +import frost.storage.AutoSavable; +import frost.storage.ExitSavable; +import frost.storage.StorageException; public class FileTransferManager implements ExitSavable, AutoSavable { @@ -139,7 +143,9 @@ } final FrostSharedFileItem suf = (FrostSharedFileItem)obj; if( suf.getOwner().equals(li.getUniqueName()) ) { - getUploadManager().getModel().removeItems(new ModelItem[] { suf }); + // FIXME: why do we have a FrostSharedFileItem and try to remove a FrostUploadItem? + FrostUploadItem frostSharedFileItem = (FrostUploadItem) (Object) suf; + getUploadManager().getModel().removeItem(frostSharedFileItem); } } @@ -147,7 +153,7 @@ for (int x = 0; x < getSharedFilesManager().getModel().getItemCount(); x++) { final FrostSharedFileItem item = (FrostSharedFileItem) getSharedFilesManager().getModel().getItemAt(x); if( item.getOwner().equals( li.getUniqueName()) ) { - getSharedFilesManager().getModel().removeItems(new ModelItem[] { item }); + getSharedFilesManager().getModel().removeItem(item); } } } Modified: trunk/frost-wot/source/frost/fileTransfer/FrostFileListFileObject.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/FrostFileListFileObject.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/FrostFileListFileObject.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -137,16 +137,20 @@ } return frostFileListFileObjectOwnerList; } + public void addFrostFileListFileObjectOwner(final FrostFileListFileObjectOwner v) { v.setFileListFileObject(this); getFrostFileListFileObjectOwnerList().add(v); } + public void deleteFrostFileListFileObjectOwner(final FrostFileListFileObjectOwner v) { getFrostFileListFileObjectOwnerList().remove(v); } + public Iterator<FrostFileListFileObjectOwner> getFrostFileListFileObjectOwnerIterator() { return getFrostFileListFileObjectOwnerList().iterator(); } + public int getFrostFileListFileObjectOwnerListSize() { return getFrostFileListFileObjectOwnerList().size(); } Modified: trunk/frost-wot/source/frost/fileTransfer/PersistenceManager.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/PersistenceManager.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/PersistenceManager.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -62,7 +62,8 @@ private final FcpListenThreadConnection fcpConn; private final FcpMultiRequestConnectionFileTransferTools fcpTools; - private final Set<String> directGETsInProgress = new HashSet<String>(); + + private final Set<String> directGETsInProgress = new HashSet<String>(); private final Set<String> directPUTsInProgress = new HashSet<String>(); private final Set<String> directPUTsWithoutAnswer = new HashSet<String>(); @@ -134,7 +135,7 @@ // enqueue listeners to keep updated about the model items uploadModel.addOrderedModelListener( - new SortedModelListener() { + new SortedModelListener<FrostUploadItem>() { public void modelCleared() { for( final FrostUploadItem ul : uploadModelItems.values() ) { if( ul.isExternal() == false ) { @@ -143,29 +144,27 @@ } uploadModelItems.clear(); } - public void itemAdded(final int position, final ModelItem item) { - final FrostUploadItem ul = (FrostUploadItem) item; - uploadModelItems.put(ul.getGqIdentifier(), ul); - if( !ul.isExternal() ) { + public void itemAdded(final int position, final FrostUploadItem item) { + uploadModelItems.put(item.getGqIdentifier(), item); + if( !item.isExternal() ) { // maybe start immediately startNewUploads(); } } - public void itemChanged(final int position, final ModelItem item) { + public void itemChanged(final int position, final FrostUploadItem item) { } - public void itemsRemoved(final int[] positions, final ModelItem[] items) { - for(final ModelItem item : items) { - final FrostUploadItem ul = (FrostUploadItem) item; - uploadModelItems.remove(ul.getGqIdentifier()); - if( ul.isExternal() == false ) { - fcpTools.removeRequest(ul.getGqIdentifier()); + public void itemsRemoved(final int[] positions, final List<FrostUploadItem> items) { + for(final FrostUploadItem item : items) { + uploadModelItems.remove(item.getGqIdentifier()); + if( item.isExternal() == false ) { + fcpTools.removeRequest(item.getGqIdentifier()); } } } }); downloadModel.addOrderedModelListener( - new SortedModelListener() { + new SortedModelListener<FrostDownloadItem>() { public void modelCleared() { for( final FrostDownloadItem ul : downloadModelItems.values() ) { if( ul.isExternal() == false ) { @@ -174,22 +173,20 @@ } downloadModelItems.clear(); } - public void itemAdded(final int position, final ModelItem item) { - final FrostDownloadItem ul = (FrostDownloadItem) item; - downloadModelItems.put(ul.getGqIdentifier(), ul); - if( !ul.isExternal() ) { + public void itemAdded(final int position, final FrostDownloadItem item) { + downloadModelItems.put(item.getGqIdentifier(), item); + if( !item.isExternal() ) { // maybe start immediately startNewDownloads(); } } - public void itemChanged(final int position, final ModelItem item) { + public void itemChanged(final int position, final FrostDownloadItem item) { } - public void itemsRemoved(final int[] positions, final ModelItem[] items) { - for(final ModelItem item : items) { - final FrostDownloadItem ul = (FrostDownloadItem) item; - downloadModelItems.remove(ul.getGqIdentifier()); - if( ul.isExternal() == false ) { - fcpTools.removeRequest(ul.getGqIdentifier()); + public void itemsRemoved(final int[] positions, final List<FrostDownloadItem> items) { + for(final FrostDownloadItem item : items) { + downloadModelItems.remove(item.getGqIdentifier()); + if( item.isExternal() == false ) { + fcpTools.removeRequest(item.getGqIdentifier()); } } } @@ -201,6 +198,10 @@ persistentQueue = new FcpPersistentQueue(fcpTools, this); } + public FcpMultiRequestConnectionFileTransferTools getFcpTools() { + return fcpTools; + } + public void startThreads() { directTransferThread.start(); persistentQueue.startThreads(); @@ -219,31 +220,7 @@ } } - public void changeItemPriorites(final ModelItem[] items, final int newPrio) { - if (items == null || items.length == 0) { - return; - } - for (final ModelItem item : items) { - String gqid = null; - if (item instanceof FrostUploadItem) { - final FrostUploadItem ui = (FrostUploadItem) item; - if (ui.getState() == FrostUploadItem.STATE_PROGRESS) { - ui.setPriority(newPrio); - gqid = ui.getGqIdentifier(); - } - } else if (item instanceof FrostDownloadItem) { - final FrostDownloadItem di = (FrostDownloadItem) item; - if (di.getState() == FrostDownloadItem.STATE_PROGRESS) { - gqid = di.getGqIdentifier(); - di.setPriority(newPrio); - } - } - if (gqid != null) { - fcpTools.changeRequestPriority(gqid, newPrio); - } - } - } - + /** * @param dlItem items whose global identifier is to check * @return true if this item is currently in the global queue, no matter in what state @@ -834,10 +811,6 @@ notifyAll(); // notify all waiters (if any) of new record } - - public synchronized int getQueueSize() { - return queue.size(); - } } public void persistentRequestError(final String id, final NodeMessage nm) { @@ -900,7 +873,9 @@ if( ulItem.isExternal() ) { SwingUtilities.invokeLater(new Runnable() { public void run() { - uploadModel.removeItems(new ModelItem[] { ulItem }); + List<FrostUploadItem> itemList = new ArrayList<FrostUploadItem>(); + itemList.add(ulItem); + uploadModel.removeItems(itemList); } }); } else { @@ -921,7 +896,9 @@ if( dlItem.isExternal() ) { SwingUtilities.invokeLater(new Runnable() { public void run() { - downloadModel.removeItems(new ModelItem[] { dlItem }); + List<FrostDownloadItem> itemList = new ArrayList<FrostDownloadItem>(); + itemList.add(dlItem); + downloadModel.removeItems(itemList); } }); } else { Modified: trunk/frost-wot/source/frost/fileTransfer/SharedFileXmlFile.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/SharedFileXmlFile.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/SharedFileXmlFile.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -25,6 +25,7 @@ import frost.util.*; +@SuppressWarnings("serial") public class SharedFileXmlFile implements XMLizable { public static final int MAX_COMMENT_LENGTH = 100; @@ -71,11 +72,7 @@ } // rather than marking a file invalid if invalid chars are in the name we replace this chars ensureValidity(); -// for( int i = 0; i < invalidChars.length; i++ ) { -// if( filename.indexOf(invalidChars[i]) != -1 ) { -// return false; -// } -// } + return true; } Modified: trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsDialog.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsDialog.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsDialog.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -21,6 +21,7 @@ import java.awt.*; import java.awt.event.*; import java.util.*; +import java.util.List; import javax.swing.*; @@ -34,6 +35,7 @@ import frost.util.gui.translation.*; import frost.util.model.*; +@SuppressWarnings("serial") public class FileListFileDetailsDialog extends JDialog { Language language = Language.getInstance(); @@ -43,7 +45,7 @@ private JPanel mainPanel = null; private JButton Bclose = null; - private SortedModelTable modelTable = null; + private SortedModelTable<FileListFileDetailsItem> modelTable = null; private FileListFileDetailsTableModel model = null; private FileListFileDetailsTableFormat tableFormat = null; @@ -163,11 +165,11 @@ return mainPanel; } - private SortedModelTable getModelTable() { + private SortedModelTable<FileListFileDetailsItem> getModelTable() { if( modelTable == null ) { tableFormat = new FileListFileDetailsTableFormat(); model = new FileListFileDetailsTableModel(tableFormat); - modelTable = new SortedModelTable(model); + modelTable = new SortedModelTable<FileListFileDetailsItem>(model); modelTable.getScrollPane().addMouseListener(listener); modelTable.getTable().addMouseListener(listener); @@ -246,7 +248,7 @@ public void actionPerformed(final ActionEvent e) { if (e.getSource() == copyKeysAndNamesItem) { - CopyToClipboard.copyKeysAndFilenames(modelTable.getSelectedItems()); + CopyToClipboard.copyKeysAndFilenames(modelTable.getSelectedItems().toArray()); } else if (e.getSource() == showOwnerFilesItem) { searchFilesOfOwner(); } else if (e.getSource() == setGoodItem) { @@ -261,9 +263,9 @@ } private void changeTrustState(final IdentityState is) { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - if (selectedItems.length == 1) { - final FileListFileDetailsItem item = (FileListFileDetailsItem) selectedItems[0]; + final List<FileListFileDetailsItem> selectedItems = modelTable.getSelectedItems(); + if (selectedItems.size() == 1) { + final FileListFileDetailsItem item = selectedItems.get(0); if( is == IdentityState.GOOD ) { item.getOwnerIdentity().setGOOD(); } else if( is == IdentityState.CHECK ) { @@ -280,9 +282,9 @@ } private void searchFilesOfOwner() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - if (selectedItems.length == 1) { - final FileListFileDetailsItem item = (FileListFileDetailsItem) selectedItems[0]; + final List<FileListFileDetailsItem> selectedItems = modelTable.getSelectedItems(); + if (selectedItems.size() == 1) { + final FileListFileDetailsItem item = selectedItems.get(0); final String owner = item.getOwnerIdentity().getUniqueName(); final SearchParameters sp = new SearchParameters(false); @@ -299,16 +301,16 @@ public void show(final Component invoker, final int x, final int y) { removeAll(); - final ModelItem[] selectedItems = modelTable.getSelectedItems(); + final List<FileListFileDetailsItem> selectedItems = modelTable.getSelectedItems(); - if( selectedItems.length == 0 ) { + if( selectedItems.size() == 0 ) { return; } // if at least 1 item is selected add(copyToClipboardMenu); - if (selectedItems.length == 1) { + if (selectedItems.size() == 1) { addSeparator(); @@ -321,7 +323,7 @@ setCheckItem.setEnabled(false); setBadItem.setEnabled(false); - final FileListFileDetailsItem item = (FileListFileDetailsItem) selectedItems[0]; + final FileListFileDetailsItem item = selectedItems.get(0); final Identity ownerId = item.getOwnerIdentity(); if( ownerId instanceof LocalIdentity ) { @@ -347,7 +349,7 @@ } } - if( isOwnerSearchAllowed && selectedItems.length == 1 ) { + if( isOwnerSearchAllowed && selectedItems.size() == 1 ) { addSeparator(); add(showOwnerFilesItem); } Modified: trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsTableFormat.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsTableFormat.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsTableFormat.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -31,7 +31,7 @@ import frost.util.gui.translation.*; import frost.util.model.*; -public class FileListFileDetailsTableFormat extends SortedTableFormat implements LanguageListener { +public class FileListFileDetailsTableFormat extends SortedTableFormat<FileListFileDetailsItem> implements LanguageListener { private static final String CFGKEY_SORTSTATE_SORTEDCOLUMN = "FileListFileDetailsDialog.sortState.sortedColumn"; private static final String CFGKEY_SORTSTATE_SORTEDASCENDING = "FileListFileDetailsDialog.sortState.sortedAscending"; @@ -338,7 +338,8 @@ } } - private class ShowContentTooltipRenderer extends ShowColoredLinesRenderer { + @SuppressWarnings("serial") + private class ShowContentTooltipRenderer extends ShowColoredLinesRenderer { public ShowContentTooltipRenderer() { super(); } @@ -364,7 +365,8 @@ } } - private class IdentityStateRenderer extends ShowColoredLinesRenderer { + @SuppressWarnings("serial") + private class IdentityStateRenderer extends ShowColoredLinesRenderer { public IdentityStateRenderer() { super(); } @@ -398,7 +400,8 @@ } } - private class ShowColoredLinesRenderer extends DefaultTableCellRenderer { + @SuppressWarnings("serial") + private class ShowColoredLinesRenderer extends DefaultTableCellRenderer { public ShowColoredLinesRenderer() { super(); } Modified: trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsTableModel.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsTableModel.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/common/FileListFileDetailsTableModel.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -20,9 +20,9 @@ import frost.util.model.*; -public class FileListFileDetailsTableModel extends SortedModel { +public class FileListFileDetailsTableModel extends SortedModel<FileListFileDetailsItem> { - public FileListFileDetailsTableModel(SortedTableFormat f) { + public FileListFileDetailsTableModel(SortedTableFormat<FileListFileDetailsItem> f) { super(f); } Modified: trunk/frost-wot/source/frost/fileTransfer/download/DownloadManager.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/download/DownloadManager.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/download/DownloadManager.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -42,7 +42,6 @@ import frost.storage.perst.filelist.FileListStorage; import frost.util.FileAccess; import frost.util.Mixed; -import frost.util.model.ModelItem; public class DownloadManager implements ExitSavable { @@ -246,9 +245,8 @@ * file name */ public FrostDownloadItem addNewDownload(final String key, - final String fileName, final String dlDir, final String prefix) { - // TODO: enhancement: search for key in shared files, maybe add as - // shared file + final String fileName, final String dlDir, final String prefix) { + // TODO: enhancement: search for key in shared files, maybe add as shared file final FrostDownloadItem dlItem = new FrostDownloadItem(fileName, key); dlItem.setDownloadDir(dlDir); dlItem.setFilenamePrefix(prefix); @@ -538,7 +536,6 @@ return retryImmediately; } - @SuppressWarnings("unchecked") public List<FrostDownloadItem> getDownloadItemList() { return getModel().getItems(); } @@ -594,33 +591,29 @@ return waitingItems.get(0); } - public void notifyDownloadItemEnabledStateChanged( - final FrostDownloadItem dlItem) { + public void notifyDownloadItemEnabledStateChanged(final FrostDownloadItem dlItem) { // for persistent items, set priority to 6 (pause) when disabled; and to // configured default if enabled - if (FileTransferManager.inst().getPersistenceManager() == null) { - return; - } if (dlItem.isExternal()) { return; } + if (dlItem.getState() != FrostDownloadItem.STATE_PROGRESS) { // not running, not in queue return; } + final boolean itemIsEnabled = (dlItem.isEnabled() == null ? true : dlItem.isEnabled().booleanValue()); + int prio = 6; if (itemIsEnabled) { - // item is now enabled - final int prio = Core.frostSettings - .getIntValue(SettingsClass.FCP2_DEFAULT_PRIO_FILE_DOWNLOAD); - FileTransferManager.inst().getPersistenceManager() - .changeItemPriorites(new ModelItem[] { dlItem }, prio); - } else { - // item is now disabled - FileTransferManager.inst().getPersistenceManager() - .changeItemPriorites(new ModelItem[] { dlItem }, 6); + prio = Core.frostSettings.getIntValue(SettingsClass.FCP2_DEFAULT_PRIO_FILE_DOWNLOAD); } + + List<FrostDownloadItem> frostDownloadItems = new ArrayList<FrostDownloadItem>(); + frostDownloadItems.add(dlItem); + + panel.changeItemPriorites(frostDownloadItems, prio); } /** Modified: trunk/frost-wot/source/frost/fileTransfer/download/DownloadModel.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/download/DownloadModel.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/download/DownloadModel.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -35,11 +35,11 @@ * Its implementation is thread-safe (subclasses should synchronize against protected attribute data when necessary). It * is also assumed that the load and save methods will not be used while other threads are under way. */ -public class DownloadModel extends SortedModel implements ExitSavable { +public class DownloadModel extends SortedModel<FrostDownloadItem> implements ExitSavable { private static final Logger logger = Logger.getLogger(DownloadModel.class.getName()); - public DownloadModel(final SortedTableFormat f) { + public DownloadModel(final SortedTableFormat<FrostDownloadItem> f) { super(f); } @@ -80,7 +80,7 @@ } for (int x = 0; x < getItemCount(); x++) { - final FrostDownloadItem item = (FrostDownloadItem) getItemAt(x); + final FrostDownloadItem item = getItemAt(x); // maybe null of manually added final FrostFileListFileObject flf = item.getFileListFileObject(); @@ -136,8 +136,7 @@ */ public synchronized boolean containsItemWithSha(final String sha) { for (int x = 0; x < getItemCount(); x++) { - final FrostDownloadItem dlItem = (FrostDownloadItem) getItemAt(x); - final FrostFileListFileObject flf = dlItem.getFileListFileObject(); + final FrostFileListFileObject flf = getItemAt(x).getFileListFileObject(); if (flf != null) { if (flf.getSha().equals(sha)) { return true; @@ -153,17 +152,13 @@ public synchronized void removeFinishedDownloads() { final ArrayList<FrostDownloadItem> items = new ArrayList<FrostDownloadItem>(); for (int i = getItemCount() - 1; i >= 0; i--) { - final FrostDownloadItem dlItem = (FrostDownloadItem) getItemAt(i); + final FrostDownloadItem dlItem = getItemAt(i); if (dlItem.getState() == FrostDownloadItem.STATE_DONE) { items.add(dlItem); } } if (items.size() > 0) { - final FrostDownloadItem[] itemsArray = new FrostDownloadItem[items.size()]; - for (int i = 0; i < itemsArray.length; i++) { - itemsArray[i] = items.get(i); - } - removeItems(itemsArray); + removeItems(items); } } @@ -173,26 +168,24 @@ public synchronized void removeExternalDownloads() { final ArrayList<FrostDownloadItem> items = new ArrayList<FrostDownloadItem>(); for (int i = getItemCount() - 1; i >= 0; i--) { - final FrostDownloadItem dlItem = (FrostDownloadItem) getItemAt(i); + final FrostDownloadItem dlItem = getItemAt(i); if (dlItem.isExternal()) { items.add(dlItem); } } if (items.size() > 0) { - final FrostDownloadItem[] itemsArray = new FrostDownloadItem[items.size()]; - items.toArray(itemsArray); - removeItems(itemsArray); + removeItems(items); } } /** * Called to restart the item. */ - public void restartItems(final ModelItem[] items) { + public void restartItems(final List<FrostDownloadItem> items) { final LinkedList<FrostDownloadItem> running = new LinkedList<FrostDownloadItem>(); - for (int x = items.length - 1; x >= 0; x--) { - final FrostDownloadItem dlItem = (FrostDownloadItem) items[x]; + for (int x = items.size() - 1; x >= 0; x--) { + final FrostDownloadItem dlItem = items.get(x); if (dlItem.getState() == FrostDownloadItem.STATE_FAILED || dlItem.getState() == FrostDownloadItem.STATE_WAITING @@ -219,7 +212,7 @@ */ public synchronized void setAllItemsEnabled(final Boolean enabled) { for (int x = 0; x < getItemCount(); x++) { - final FrostDownloadItem dlItem = (FrostDownloadItem) getItemAt(x); + final FrostDownloadItem dlItem = getItemAt(x); if (dlItem.getState() != FrostDownloadItem.STATE_DONE) { dlItem.setEnabled(enabled); FileTransferManager.inst().getDownloadManager().notifyDownloadItemEnabledStateChanged(dlItem); @@ -236,9 +229,8 @@ * @param items * items to modify */ - public void setItemsEnabled(final Boolean enabled, final ModelItem[] items) { - for (final ModelItem element : items) { - final FrostDownloadItem item = (FrostDownloadItem) element; + public void setItemsEnabled(final Boolean enabled, final List<FrostDownloadItem> items) { + for (final FrostDownloadItem item : items) { if (item.getState() != FrostDownloadItem.STATE_DONE) { item.setEnabled(enabled); FileTransferManager.inst().getDownloadManager().notifyDownloadItemEnabledStateChanged(item); @@ -279,17 +271,13 @@ public boolean restartRunningDownloads(final List<FrostDownloadItem> dlItems) { - final FrostDownloadItem[] itemsArray = new FrostDownloadItem[dlItems.size()]; - // don't flag as failed later when item is removed from gq for (final FrostDownloadItem dlItem : dlItems) { dlItem.setInternalRemoveExpected(true); } - dlItems.toArray(itemsArray); + removeItems(dlItems); - removeItems(itemsArray); - new Thread() { @Override public void run() { Modified: trunk/frost-wot/source/frost/fileTransfer/download/DownloadPanel.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/download/DownloadPanel.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/download/DownloadPanel.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -138,7 +138,7 @@ private final JCheckBox removeFinishedDownloadsCheckBox = new JCheckBox(); private final JCheckBox showExternalGlobalQueueItems = new JCheckBox(); private Color downloadDirDefaultBackground; - private SortedModelTable modelTable; + private SortedModelTable<FrostDownloadItem> modelTable; private boolean initialized = false; @@ -295,7 +295,7 @@ updateDownloadDirTextFieldBackground(); // create the main download panel - modelTable = new SortedModelTable(model); + modelTable = new SortedModelTable<FrostDownloadItem>(model); new TableFindAction().install(modelTable.getTable()); setLayout(new BorderLayout()); @@ -443,10 +443,9 @@ } private void applyDownloadPrefixToSelectedDownloads() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); + final List<FrostDownloadItem> selectedItems = modelTable.getSelectedItems(); - for (final ModelItem mi : selectedItems) { - final FrostDownloadItem i = (FrostDownloadItem) mi; + for (final FrostDownloadItem i : selectedItems) { if (!i.isExternal()) { i.setFilenamePrefix(getDownloadPrefix()); @@ -456,10 +455,9 @@ } private void applyDownloadDirToSelectedDownloads() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); + final List<FrostDownloadItem> selectedItems = modelTable.getSelectedItems(); - for (final ModelItem mi : selectedItems) { - final FrostDownloadItem i = (FrostDownloadItem) mi; + for (final FrostDownloadItem i : selectedItems) { if (!i.isExternal()) { i.setDownloadDir(getDownloadDir()); @@ -498,20 +496,18 @@ } private void removeSelectedDownloads() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); + final List<FrostDownloadItem> selectedItems = modelTable.getSelectedItems(); final List<String> externalRequestsToRemove = new LinkedList<String>(); - final List<ModelItem> requestsToRemove = new LinkedList<ModelItem>(); - for (final ModelItem mi : selectedItems) { - final FrostDownloadItem frostDownloadItem = (FrostDownloadItem) mi; - requestsToRemove.add(mi); + final List<FrostDownloadItem> requestsToRemove = new LinkedList<FrostDownloadItem>(); + for (final FrostDownloadItem frostDownloadItem : selectedItems) { + requestsToRemove.add(frostDownloadItem); if (frostDownloadItem.isExternal()) { externalRequestsToRemove.add(frostDownloadItem.getGqIdentifier()); } } - final ModelItem[] ri = requestsToRemove.toArray(new ModelItem[requestsToRemove.size()]); - model.removeItems(ri); + model.removeItems(requestsToRemove); modelTable.getTable().clearSelection(); @@ -626,10 +622,6 @@ final AddNewDownloadsDialog addNewDownloadsDialog = new AddNewDownloadsDialog(MainFrame.getInstance(), frostDownloadItemList); addNewDownloadsDialog.startDialog(frostDownloadItemList); -// frostDownloadItemList = -// -// // add files from dialog to download queue -// FileTransferManager.inst().getDownloadManager().getModel().addDownloadItemList(frostDownloadItemList); } private void downloadActivateButtonPressed(final ActionEvent e) { @@ -672,6 +664,22 @@ public void updateSettings() { Core.frostSettings.setValue(SettingsClass.DOWNLOADING_ACTIVATED, isDownloadingActivated()); } + + public void changeItemPriorites(final List<FrostDownloadItem> items, final int newPrio) { + if (items == null || items.size() == 0 || FileTransferManager.inst().getPersistenceManager() == null) { + return; + } + for (final FrostDownloadItem di : items) { + String gqid = null; + if (di.getState() == FrostDownloadItem.STATE_PROGRESS) { + gqid = di.getGqIdentifier(); + di.setPriority(newPrio); + } + if (gqid != null) { + FileTransferManager.inst().getPersistenceManager().getFcpTools().changeRequestPriority(gqid, newPrio); + } + } + } private void assignHotkeys() { @@ -679,8 +687,9 @@ final Action setPriorityAction = new AbstractAction() { public void actionPerformed(final ActionEvent event) { final int prio = new Integer(event.getActionCommand()).intValue(); - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - FileTransferManager.inst().getPersistenceManager().changeItemPriorites(selectedItems, prio); + final List<FrostDownloadItem> selectedItems = modelTable.getSelectedItems(); + changeItemPriorites(selectedItems, prio); + } }; getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_1, 0), @@ -864,9 +873,9 @@ public void actionPerformed(final ActionEvent e) { if (e.getSource() == copyKeysAndNamesItem) { - CopyToClipboard.copyKeysAndFilenames(modelTable.getSelectedItems()); + CopyToClipboard.copyKeysAndFilenames(modelTable.getSelectedItems().toArray()); } else if (e.getSource() == copyExtendedInfoItem) { - CopyToClipboard.copyExtendedInfo(modelTable.getSelectedItems()); + CopyToClipboard.copyExtendedInfo(modelTable.getSelectedItems().toArray()); } else if (e.getSource() == restartSelectedDownloadsItem) { restartSelectedDownloads(); } else if (e.getSource() == useThisDownloadDirItem) { @@ -916,11 +925,10 @@ if (FileTransferManager.inst().getPersistenceManager() == null) { return; } - final ModelItem[] selectedItems = modelTable.getSelectedItems(); + final List<FrostDownloadItem> selectedItems = modelTable.getSelectedItems(); final List<String> requestsToRemove = new ArrayList<String>(); final List<FrostDownloadItem> itemsToUpdate = new ArrayList<FrostDownloadItem>(); - for (final ModelItem mi : selectedItems) { - final FrostDownloadItem item = (FrostDownloadItem) mi; + for (final FrostDownloadItem item : selectedItems) { if (FileTransferManager.inst().getPersistenceManager().isItemInGlobalQueue(item)) { requestsToRemove.add(item.getGqIdentifier()); itemsToUpdate.add(item); @@ -941,9 +949,8 @@ if (FileTransferManager.inst().getPersistenceManager() == null) { return; } - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - for (final ModelItem mi : selectedItems) { - final FrostDownloadItem item = (FrostDownloadItem) mi; + final List<FrostDownloadItem> selectedItems = modelTable.getSelectedItems(); + for (final FrostDownloadItem item : selectedItems) { if (item.isExternal() && item.isDirect() && item.getState() == FrostDownloadItem.STATE_DONE) { final long expectedFileSize = item.getFileSize(); // set // from @@ -955,11 +962,10 @@ } private void startSelectedDownloadsNow() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); + final List<FrostDownloadItem> selectedItems = modelTable.getSelectedItems(); final List<FrostDownloadItem> itemsToStart = new LinkedList<FrostDownloadItem>(); - for (final ModelItem mi : selectedItems) { - final FrostDownloadItem i = (FrostDownloadItem) mi; + for (final FrostDownloadItem i : selectedItems) { if (i.isExternal()) { continue; } @@ -982,25 +988,22 @@ if (FileTransferManager.inst().getPersistenceManager() == null) { return; } - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - FileTransferManager.inst().getPersistenceManager().changeItemPriorites(selectedItems, prio); + changeItemPriorites(modelTable.getSelectedItems(), prio); } private void showDetails() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - if (selectedItems.length != 1) { + final List<FrostDownloadItem> selectedItems = modelTable.getSelectedItems(); + if (selectedItems.size() != 1) { return; } - final FrostDownloadItem item = (FrostDownloadItem) selectedItems[0]; - if (!item.isSharedFile()) { + if (!selectedItems.get(0).isSharedFile()) { return; } - new FileListFileDetailsDialog(MainFrame.getInstance()).startDialog(item.getFileListFileObject()); + new FileListFileDetailsDialog(MainFrame.getInstance()).startDialog(selectedItems.get(0).getFileListFileObject()); } private void invertEnabledSelected() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - model.setItemsEnabled(null, selectedItems); + model.setItemsEnabled(null, modelTable.getSelectedItems()); } private void invertEnabledAll() { @@ -1008,13 +1011,11 @@ } private void disableSelectedDownloads() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - model.setItemsEnabled(Boolean.FALSE, selectedItems); + model.setItemsEnabled(Boolean.FALSE, modelTable.getSelectedItems()); } private void enableSelectedDownloads() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - model.setItemsEnabled(Boolean.TRUE, selectedItems); + model.setItemsEnabled(Boolean.TRUE, modelTable.getSelectedItems()); } private void disableAllDownloads() { @@ -1026,23 +1027,18 @@ } private void restartSelectedDownloads() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - model.restartItems(selectedItems); + model.restartItems(modelTable.getSelectedItems()); } private void useThisDownloadDirectory() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - if (selectedItems.length > 0) { - final FrostDownloadItem item = (FrostDownloadItem) selectedItems[0]; - - downloadDirTextField.setText(item.getDownloadDir()); + if (modelTable.getSelectedItems().size() > 0) { + downloadDirTextField.setText(modelTable.getSelectedItems().get(0).getDownloadDir()); } } private void jumpToAssociatedMessage() { - final ModelItem[] selectedItems = modelTable.getSelectedItems(); - if (selectedItems.length > 0) { - final FrostDownloadItem item = (FrostDownloadItem) selectedItems[0]; + if (modelTable.getSelectedItems().size() > 0) { + final FrostDownloadItem item = modelTable.getSelectedItems().get(0); final String boardName = item.getAssociatedBoardName(); final String messageId = item.getAssociatedMessageId(); @@ -1069,9 +1065,9 @@ public void show(final Component invoker, final int x, final int y) { removeAll(); - final ModelItem[] selectedItems = modelTable.getSelectedItems(); + final List<FrostDownloadItem> selectedItems = modelTable.getSelectedItems(); - if (selectedItems.length == 0) { + if (selectedItems.size() == 0) { return; } @@ -1102,8 +1098,7 @@ // we only find external items if persistence is enabled if (PersistenceManager.isPersistenceEnabled()) { - for (final ModelItem mi : selectedItems) { - final FrostDownloadItem item = (FrostDownloadItem) mi; + for (final FrostDownloadItem item : selectedItems) { if (item.isExternal() && item.isDirect() && item.getState() == FrostDownloadItem.STATE_DONE) { add(retrieveDirectExternalDownloads); break; @@ -1113,16 +1108,15 @@ add(removeSelectedDownloadsItem); if (FileTransferManager.inst().getPersistenceManager() != null && selectedItems != null) { // add only if there are removable items selected - for (final ModelItem mi : selectedItems) { - final FrostDownloadItem item = (FrostDownloadItem) mi; + for (final FrostDownloadItem item : selectedItems) { if (FileTransferManager.inst().getPersistenceManager().isItemInGlobalQueue(item)) { add(removeFromGqItem); break; } } } - if (selectedItems.length == 1) { - final FrostDownloadItem item = (FrostDownloadItem) selectedItems[0]; + if (selectedItems.size() == 1) { + final FrostDownloadItem item = selectedItems.get(0); if (item.isSharedFile()) { addSeparator(); add(detailsItem); Modified: trunk/frost-wot/source/frost/fileTransfer/download/DownloadTableFormat.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/download/DownloadTableFormat.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/download/DownloadTableFormat.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -32,7 +32,7 @@ import frost.util.gui.translation.*; import frost.util.model.*; -class DownloadTableFormat extends SortedTableFormat implements LanguageListener, PropertyChangeListener { +class DownloadTableFormat extends SortedTableFormat<FrostDownloadItem> implements LanguageListener, PropertyChangeListener { private static final String CFGKEY_SORTSTATE_SORTEDCOLUMN = "DownloadTable.sortState.sortedColumn"; private static final String CFGKEY_SORTSTATE_SORTEDASCENDING = "DownloadTable.sortState.sortedAscending"; @@ -45,11 +45,12 @@ private static final long CONST_32k = 32 * 1024; - private SortedModelTable modelTable = null; + private SortedModelTable<FrostDownloadItem> modelTable = null; private boolean showColoredLines; - private class BaseRenderer extends DefaultTableCellRenderer { + @SuppressWarnings("serial") + private class BaseRenderer extends DefaultTableCellRenderer { public BaseRenderer() { super(); } @@ -85,7 +86,8 @@ } } - private class BlocksProgressRenderer extends JProgressBar implements TableCellRenderer { + @SuppressWarnings("serial") + private class BlocksProgressRenderer extends JProgressBar implements TableCellRenderer { public BlocksProgressRenderer() { super(); setMinimum(0); @@ -134,6 +136,7 @@ } } + @SuppressWarnings("serial") private class RightAlignRenderer extends BaseRenderer { final javax.swing.border.EmptyBorder border = new javax.swing.border.EmptyBorder(0, 0, 0, 3); public RightAlignRenderer() { @@ -155,7 +158,8 @@ } } - private class ShowContentTooltipRenderer extends BaseRenderer { + @SuppressWarnings("serial") + private class ShowContentTooltipRenderer extends BaseRenderer { public ShowContentTooltipRenderer() { super(); } @@ -180,7 +184,8 @@ } } - private class ShowNameTooltipRenderer extends BaseRenderer { + @SuppressWarnings("serial") + private class ShowNameTooltipRenderer extends BaseRenderer { public ShowNameTooltipRenderer() { super(); } @@ -226,7 +231,8 @@ } } - private class ShowStateContentTooltipRenderer extends BaseRenderer { + @SuppressWarnings("serial") + private class ShowStateContentTooltipRenderer extends BaseRenderer { public ShowStateContentTooltipRenderer() { super(); } @@ -253,7 +259,8 @@ } } - private class IsEnabledRenderer extends JCheckBox implements TableCellRenderer { + @SuppressWarnings("serial") + private class IsEnabledRenderer extends JCheckBox implements TableCellRenderer { public IsEnabledRenderer() { super(); setHorizontalAlignment(SwingConstants.CENTER); @@ -292,7 +299,8 @@ } } - private class IsSharedRenderer extends BaseRenderer { + @SuppressWarnings("serial") + private class IsSharedRenderer extends BaseRenderer { public IsSharedRenderer() { super(); } @@ -321,7 +329,8 @@ } } - private class IsRequestedRenderer extends BaseRenderer { + @SuppressWarnings("serial") + private class IsRequestedRenderer extends BaseRenderer { public IsRequestedRenderer() { super(); } @@ -350,7 +359,8 @@ } } - private class IsDDARenderer extends BaseRenderer { + @SuppressWarnings("serial") + private class IsDDARenderer extends BaseRenderer { public IsDDARenderer() { super(); } @@ -794,11 +804,10 @@ } } - @Override - public void customizeTable(final ModelTable lModelTable) { + public void customizeTable(final ModelTable<FrostDownloadItem> lModelTable) { super.customizeTable(lModelTable); - modelTable = (SortedModelTable) lModelTable; + modelTable = (SortedModelTable<FrostDownloadItem>) lModelTable; if( Core.frostSettings.getBoolValue(SettingsClass.SAVE_SORT_STATES) && Core.frostSettings.getObjectValue(CFGKEY_SORTSTATE_SORTEDCOLUMN) != null Modified: trunk/frost-wot/source/frost/fileTransfer/search/SearchModel.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/search/SearchModel.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/search/SearchModel.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -18,17 +18,18 @@ */ package frost.fileTransfer.search; +import java.util.List; import java.util.logging.*; import frost.fileTransfer.*; import frost.fileTransfer.download.*; import frost.util.model.*; -public class SearchModel extends SortedModel { +public class SearchModel extends SortedModel<FrostSearchItem> { final static Logger logger = Logger.getLogger(SearchModel.class.getName()); - public SearchModel(final SortedTableFormat f) { + public SearchModel(final SortedTableFormat<FrostSearchItem> f) { super(f); } @@ -36,7 +37,7 @@ addItem(searchItem); } - public void addItemsToDownloadTable(final ModelItem[] selectedItems) { + public void addItemsToDownloadTable(final List<FrostSearchItem> selectedItems) { if( selectedItems == null ) { return; @@ -44,9 +45,8 @@ final DownloadModel downloadModel = FileTransferManager.inst().getDownloadManager().getModel(); - for (int i = selectedItems.length - 1; i >= 0; i--) { - final FrostSearchItem searchItem = (FrostSearchItem) selectedItems[i]; - final FrostFileListFileObject flf = searchItem.getFrostFileListFileObject(); + for (int i = selectedItems.size() - 1; i >= 0; i--) { + final FrostFileListFileObject flf = selectedItems.get(i).getFrostFileListFileObject(); String filename = flf.getDisplayName(); // maybe convert html codes (e.g. %2c -> , ) if( filename.indexOf("%") > 0 ) { @@ -58,7 +58,7 @@ } final FrostDownloadItem dlItem = new FrostDownloadItem(flf, filename); downloadModel.addDownloadItem(dlItem); - searchItem.updateState(); + selectedItems.get(i).updateState(); } } } Modified: trunk/frost-wot/source/frost/fileTransfer/search/SearchTable.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/search/SearchTable.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/search/SearchTable.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -21,6 +21,7 @@ import java.awt.*; import java.awt.event.*; import java.util.*; +import java.util.List; import javax.swing.*; @@ -32,7 +33,8 @@ import frost.util.gui.translation.*; import frost.util.model.*; -public class SearchTable extends SortedModelTable { +@SuppressWarnings("serial") +public class SearchTable extends SortedModelTable<FrostSearchItem> { private final SearchModel searchModel; private final CloseableTabbedPane tabPane; @@ -113,30 +115,28 @@ } private void showDetails() { - final ModelItem[] selectedItems = getSelectedItems(); - if (selectedItems.length != 1) { + final List<FrostSearchItem> selectedItems = getSelectedItems(); + if (selectedItems.size() != 1) { return; } - final FrostSearchItem item = (FrostSearchItem) selectedItems[0]; - new FileListFileDetailsDialog(MainFrame.getInstance(), true).startDialog(item.getFrostFileListFileObject()); + new FileListFileDetailsDialog(MainFrame.getInstance(), true).startDialog(selectedItems.get(0).getFrostFileListFileObject()); } /** * Add selected items, or all item if called with null, to the download table. * Updates state of item in search table. */ - private void addItemsToDownloadTable(ModelItem[] selectedItems) { + private void addItemsToDownloadTable(List <FrostSearchItem> selectedItems) { if( selectedItems == null ) { // add all items - selectedItems = (ModelItem[]) searchModel.getItems().toArray(); + selectedItems = searchModel.getItems(); } searchModel.addItemsToDownloadTable(selectedItems); // redraw items in model - for( final ModelItem selectedItem : selectedItems ) { - final FrostSearchItem si = (FrostSearchItem) selectedItem; - final int i = model.indexOf(si); + for( final FrostSearchItem selectedItem : selectedItems ) { + final int i = model.indexOf(selectedItem); fireTableRowsUpdated(i,i); } } @@ -244,10 +244,10 @@ downloadAllKeys(); } if (e.getSource() == copyKeysAndNamesItem) { - CopyToClipboard.copyKeysAndFilenames(getSelectedItems()); + CopyToClipboard.copyKeysAndFilenames(getSelectedItems().toArray()); } if (e.getSource() == copyExtendedInfoItem) { - CopyToClipboard.copyExtendedInfo(getSelectedItems()); + CopyToClipboard.copyExtendedInfo(getSelectedItems().toArray()); } if (e.getSource() == hideSelectedKeysItem) { hideSelectedFiles(); @@ -266,8 +266,8 @@ } private void hideSelectedFiles() { - final ModelItem[] selectedItems = getSelectedItems(); - if (selectedItems == null || selectedItems.length == 0) { + final List<FrostSearchItem> selectedItems = getSelectedItems(); + if (selectedItems == null || selectedItems.size() == 0) { return; } @@ -277,8 +277,8 @@ public void run() { if( FileListStorage.inst().beginExclusiveThreadTransaction() ) { try { - for (int x=selectedItems.length -1; x >= 0; x--) { - final FrostSearchItem si = (FrostSearchItem) selectedItems[x]; + for (int x=selectedItems.size() -1; x >= 0; x--) { + final FrostSearchItem si = selectedItems.get(x); if (si.getFrostFileListFileObject() != null) { FileListStorage.inst().markFileListFileHidden(si.getFrostFileListFileObject()); } @@ -302,14 +302,14 @@ public void show(final Component invoker, final int x, final int y) { removeAll(); - final ModelItem[] selectedItems = getSelectedItems(); + final List<FrostSearchItem> selectedItems = getSelectedItems(); - if (selectedItems.length > 0) { + if (selectedItems.size() > 0) { add(copyToClipboardMenu); addSeparator(); } - if (selectedItems.length != 0) { + if (selectedItems.size() != 0) { // If at least 1 item is selected add(downloadSelectedKeysItem); addSeparator(); @@ -318,7 +318,7 @@ addSeparator(); add(hideSelectedKeysItem); - if (selectedItems.length == 1) { + if (selectedItems.size() == 1) { addSeparator(); add(detailsItem); } Modified: trunk/frost-wot/source/frost/fileTransfer/sharing/SharedFilesModel.java =================================================================== --- trunk/frost-wot/source/frost/fileTransfer/sharing/SharedFilesModel.java 2011-01-07 23:34:20 UTC (rev 3240) +++ trunk/frost-wot/source/frost/fileTransfer/sharing/SharedFilesModel.java 2011-01-08 11:14:45 UTC (rev 3241) @@ -35,7 +35,7 @@ * protected attribute data when necessary). It is also assumed that the load * and save method... [truncated message content] |