Package com.mucommander.ui.quicksearch

Examples of com.mucommander.ui.quicksearch.QuickSearch


        int                   focusedIndex;
        int                   selectedIndex;
        CellLabel             label;
        AbstractFile          file;
        boolean               matches;
        QuickSearch       search;

        // Need to check that row index is not out of bounds because when the folder
        // has just been changed, the JTable may try to repaint the old folder and
        // ask for a row index greater than the length if the old folder contained more files
        if(rowIndex < 0 || rowIndex >= tableModel.getRowCount())
            return null;

        // Sanity check.
        file = tableModel.getCachedFileAtRow(rowIndex);
        if(file==null) {
            LOGGER.debug("tableModel.getCachedFileAtRow("+ rowIndex +") RETURNED NULL !");
            return null;
        }

        search = this.table.getQuickSearch();
        if(!table.hasFocus())
            matches = true;
        else {
            if(search.isActive())
                matches = search.matches(this.table.getFileNameAtRow(rowIndex));
            else
                matches = true;
        }

        // Retrieves the various indexes of the colors to apply.
        // Selection only applies when the table is the active one
        selectedIndex =  (isSelected && ((FileTable)table).isActiveTable()) ? ThemeCache.SELECTED : ThemeCache.NORMAL;
        focusedIndex  = table.hasFocus() ? ThemeCache.ACTIVE : ThemeCache.INACTIVE;
        colorIndex    = getColorIndex(rowIndex, file, tableModel);

        column = Column.valueOf(table.convertColumnIndexToModel(columnIndex));
        label = cellLabels[column.ordinal()];

        // Extension/icon column: return ImageIcon instance
        if(column == Column.EXTENSION) {
            // Set file icon (parent folder icon if '..' file)
            label.setIcon(rowIndex ==0 && tableModel.hasParentFolder()
                    ?IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.PARENT_FOLDER_ICON_NAME, FileIcons.getScaleFactor())
                    :FileIcons.getFileIcon(file));
        }
        // Any other column (name, date or size)
        else {
            String text = (String)value;
            if(matches || isSelected)
                label.setForeground(ThemeCache.foregroundColors[focusedIndex][selectedIndex][colorIndex]);
            else
                label.setForeground(ThemeCache.unmatchedForeground);

            // Set the label's text, before calculating it width
            label.setText(text);

            // If label's width is larger than the column width:
            // - truncate the text from the center and equally to the left and right sides, adding an ellipsis ('...')
            // where characters have been removed. This allows both the start and end of filename to be visible.
            // - set a tooltip text that will display the whole text when mouse is over the label
            if (table.getColumnModel().getColumn(columnIndex).getWidth() < label.getPreferredSize().getWidth()) {
                String leftText = text.substring(0, text.length()/2);
                String rightText = text.substring(text.length()/2, text.length());

                while(table.getColumnModel().getColumn(columnIndex).getWidth() < label.getPreferredSize().getWidth()
                   && leftText.length()>0 && rightText.length()>0) {    // Prevents against going out of bounds

                    if(leftText.length()>rightText.length())
                        leftText = leftText.substring(0, leftText.length()-1);
                    else
                        rightText = rightText.substring(1, rightText.length());

                    label.setText(leftText+"..."+rightText);
                }

                // Set the toop
                label.setToolTipText(text);
            }
            // Have to set it to null otherwise the defaultRender sets the tooltip text to the last one
            // specified
            else
                label.setToolTipText(null);
        }

        // Set background color depending on whether the row is selected or not, and whether the table has focus or not
        if(selectedIndex == ThemeCache.SELECTED)
            label.setBackground(ThemeCache.backgroundColors[focusedIndex][ThemeCache.SELECTED], ThemeCache.backgroundColors[focusedIndex][ThemeCache.SECONDARY]);
        else if(matches) {
            if(table.hasFocus() && search.isActive())
                label.setBackground(ThemeCache.backgroundColors[focusedIndex][ThemeCache.NORMAL]);
            else
                label.setBackground(ThemeCache.backgroundColors[focusedIndex][(rowIndex % 2 == 0) ? ThemeCache.NORMAL : ThemeCache.ALTERNATE]);
        }
        else
View Full Code Here

TOP

Related Classes of com.mucommander.ui.quicksearch.QuickSearch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.