Search in sources :

Example 1 with TextualFactoryBlock

use of edu.mit.blocks.renderable.TextualFactoryBlock in project openblocks by mikaelhg.

the class AutoCompletePanel method updateMenu.

/**
     * Updates the menu such that it can display
     * all the possible blocks that match the user-generated pattern
     * (the user-generated pattern is entered within AutoCompletePanel.editor)
     */
private void updateMenu() {
    //resize to display entire text in editor
    if (this.editor.getPreferredSize().width > preferredWidth) {
        this.setSize(this.editor.getPreferredSize().width, preferredHeight);
    } else {
        this.setSize(preferredWidth, preferredHeight);
    }
    //get matching blocks
    String text = editor.getText().trim();
    List<TextualFactoryBlock> matchingBlocks;
    // two "+" blocks, otherwise get the blocks matching the input text
    try {
        Float.valueOf(text);
        matchingBlocks = BlockUtilities.getDigits(workspace, text);
    } catch (NumberFormatException e) {
        if (text.equals(TypeBlockManager.PLUS_OPERATION_LABEL)) {
            matchingBlocks = BlockUtilities.getPlusBlocks(workspace, text);
        } else {
            matchingBlocks = BlockUtilities.getAllMatchingBlocks(workspace, text);
        }
    }
    //update menu and repaint
    menu.setModel(new DefaultComboBoxModel(matchingBlocks.toArray()));
    this.revalidate();
    this.repaint();
}
Also used : TextualFactoryBlock(edu.mit.blocks.renderable.TextualFactoryBlock) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Aggregations

TextualFactoryBlock (edu.mit.blocks.renderable.TextualFactoryBlock)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1