Logo Search packages:      
Sourcecode: pauker version File versions  Download package

java.awt.Component pauker::program::gui::swing::BatchListCellRenderer::getListCellRendererComponent ( JList  list,
Object  object,
int  index,
boolean  isSelected,
boolean  cellHasFocus 
) [inline]

Return a component that has been configured to display the specified card.

Parameters:
list The JList we're painting.
object The card
index the cell index
isSelected true, if the cell is selected
cellHasFocus true, if the cell has the focus
Returns:
a component that has been configured to display the specified card

Definition at line 93 of file BatchListCellRenderer.java.

References pauker::program::Card::getExpirationTime(), pauker::program::Card::getFrontSide(), pauker::program::Card::getLearnedTimestamp(), pauker::program::Card::getLongTermBatchNumber(), pauker::program::Card::getReverseSide(), pauker::program::CardSide::getText(), pauker::program::Card::isLearned(), and pauker::program::Card::isRepeatedByTyping().

Referenced by pauker::program::gui::swing::ExpirationTest::testExpiration(), and pauker::program::gui::swing::BatchListCellRendererTest::testGetListCellRendererComponent().

                                                                 {
        Card card = (Card) object;

        // front side
        CardSide frontSide = card.getFrontSide();
        PaukerFrame.fillTextComponentWithCardSide(frontSide,
                frontSideTextArea, false);

        // reverse side
        CardSide reverseSide = card.getReverseSide();
        PaukerFrame.fillTextComponentWithCardSide(reverseSide,
                reverseSideTextArea, false);

        // set RED & YELLOW search marks
        highLight(card, Card.Element.FRONT_SIDE, frontSideTextArea);
        highLight(card, Card.Element.REVERSE_SIDE, reverseSideTextArea);

        // lazy change of background color
        if (isSelected) {
            if (!wasSelected) {
                setBackgroundColor(selectedColor);
                wasSelected = true;
            }
        } else {
            if (wasSelected) {
                setBackgroundColor(backgroundColor);
                wasSelected = false;
            }
        }

        if (card.isLearned()) {
            int longTermBatchNumber = card.getLongTermBatchNumber();
            String longTermBatchString =
                    String.valueOf(longTermBatchNumber + 1);
            PaukerFrame.lazyStringChange(
                    batchNumberTextField, longTermBatchString);
            if (isSelected) {
                lazyBackgroundChange(batchNumberTextField, selectedColor);
            } else {
                lazyBackgroundChange(batchNumberTextField, backgroundColor);
            }
            long now = System.currentTimeMillis();
            long expirationTime = card.getExpirationTime();
            if (expirationTime < now) {
                // the card is expired
                if (isSelected) {
                    lazyBackgroundChange(learnedLabel, selectedColor);
                    lazyBackgroundChange(learnedDateTextField, selectedColor);
                } else {
                    lazyBackgroundChange(learnedLabel, backgroundColor);
                    lazyBackgroundChange(learnedDateTextField, backgroundColor);
                }
                PaukerFrame.lazyStringChange(expiredLabel, expiredString);
                lazyBackgroundChange(expiredLabel, PaukerFrame.BLUE);
                lazyBackgroundChange(expirationTextField, PaukerFrame.BLUE);

            } else {
                // the card is not expired
                PaukerFrame.lazyStringChange(expiredLabel, expiresString);
                lazyBackgroundChange(learnedLabel, PaukerFrame.GREEN);
                lazyBackgroundChange(learnedDateTextField, PaukerFrame.GREEN);
                if (isSelected) {
                    lazyBackgroundChange(expiredLabel, selectedColor);
                    lazyBackgroundChange(expirationTextField, selectedColor);
                } else {
                    lazyBackgroundChange(expiredLabel, backgroundColor);
                    lazyBackgroundChange(expirationTextField, backgroundColor);
                }
            }
            PaukerFrame.lazyStringChange(learnedLabel, learnedString);

            // the following textfields have always different values
            // (no need for "lazy" changes...)
            Date learnedDate = new Date(card.getLearnedTimestamp());
            learnedDateTextField.setText(dateFormat.format(learnedDate));
            expirationTextField.setText(dateFormat.format(expirationTime));

        } else {
            // the card is not learned
            PaukerFrame.lazyStringChange(
                    batchNumberTextField, notLearnedString);
            lazyBackgroundChange(batchNumberTextField, PaukerFrame.RED);
            PaukerFrame.lazyStringChange(learnedLabel, "");
            PaukerFrame.lazyStringChange(learnedDateTextField, "");
            // learnedDateTextField background is set above depending on
            // "isSelected"
            PaukerFrame.lazyStringChange(expiredLabel, "");
            PaukerFrame.lazyStringChange(expirationTextField, "");
            if (isSelected) {
                lazyBackgroundChange(learnedDateTextField, selectedColor);
                lazyBackgroundChange(expirationTextField, selectedColor);
            } else {
                lazyBackgroundChange(learnedDateTextField, backgroundColor);
                lazyBackgroundChange(expirationTextField, backgroundColor);
            }
        }

        // set repeating icon
        if (card.isRepeatedByTyping()) {
            if (brainIconSet) {
                repeatByTypingLabel.setIcon(typingIcon);
                brainIconSet = false;
            }
        } else {
            if (!brainIconSet) {
                repeatByTypingLabel.setIcon(brainIcon);
                brainIconSet = true;
            }
        }

        // Scheisse! Why do I always have to fix that Swing crap!?
        if (lineWrapping) {
            String frontSideText = frontSide.getText();
            int frontTextLenth =
                    getUnWrappedTextWidth(frontSideTextArea, frontSideText);
            String reverseSideText = reverseSide.getText();
            int reverseTextLenth =
                    getUnWrappedTextWidth(reverseSideTextArea, reverseSideText);
            int textLengthSum = frontTextLenth + reverseTextLenth;
            int listWidth = list.getWidth();
            // 23 = 3 + 3 + 3 + 5 + 3 + 3 + 3 
            // (insets, border, border, insets, border, border, insets)
            int widthForText = listWidth - 23;

            if (frontTextLenth > reverseTextLenth) {
                // layout reverse side first
                layoutTextAreas(widthForText, textLengthSum,
                        reverseTextLenth, reverseSideTextArea,
                        frontTextLenth, frontSideTextArea);
            } else {
                // layout front side first
                layoutTextAreas(widthForText, textLengthSum,
                        frontTextLenth, frontSideTextArea,
                        reverseTextLenth, reverseSideTextArea);
            }
        }

        return this;
    }


Generated by  Doxygen 1.6.0   Back to index