Search in sources :

Example 1 with WatermarkTextField

use of net.technicpack.ui.controls.WatermarkTextField in project LauncherV3 by TechnicPack.

the class ModpackSelector method initComponents.

private void initComponents() {
    setLayout(new BorderLayout());
    setBackground(LauncherFrame.COLOR_SELECTOR_BACK);
    setMaximumSize(new Dimension(287, getMaximumSize().height));
    JPanel header = new JPanel();
    header.setLayout(new GridBagLayout());
    header.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 4));
    header.setBackground(LauncherFrame.COLOR_SELECTOR_OPTION);
    add(header, BorderLayout.PAGE_START);
    filterContents = new WatermarkTextField(resources.getString("launcher.packselector.filter.hotfix"), LauncherFrame.COLOR_BLUE_DARKER);
    filterContents.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 14));
    filterContents.setBorder(new RoundBorder(LauncherFrame.COLOR_BUTTON_BLUE, 1, 8));
    filterContents.setForeground(LauncherFrame.COLOR_BLUE);
    filterContents.setBackground(LauncherFrame.COLOR_FORMELEMENT_INTERNAL);
    filterContents.setSelectedTextColor(Color.black);
    filterContents.setSelectionColor(LauncherFrame.COLOR_BUTTON_BLUE);
    filterContents.setCaretColor(LauncherFrame.COLOR_BUTTON_BLUE);
    filterContents.setColumns(20);
    ((AbstractDocument) filterContents.getDocument()).setDocumentFilter(new DocumentFilter() {

        @Override
        public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
            if (fb.getDocument().getLength() + string.length() <= MAX_SEARCH_STRING) {
                fb.insertString(offset, string, attr);
            }
        }

        @Override
        public void remove(DocumentFilter.FilterBypass fb, int offset, int length) throws BadLocationException {
            fb.remove(offset, length);
        }

        @Override
        public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
            int finalTextLength = (fb.getDocument().getLength() - length) + text.length();
            if (finalTextLength > MAX_SEARCH_STRING)
                text = text.substring(0, text.length() - (finalTextLength - MAX_SEARCH_STRING));
            fb.replace(offset, length, text, attrs);
        }
    });
    filterContents.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            detectFilterChanges();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            detectFilterChanges();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            detectFilterChanges();
        }
    });
    header.add(filterContents, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(3, 0, 3, 0), 0, 12));
    widgetList = new JPanel();
    widgetList.setOpaque(false);
    widgetList.setLayout(new GridBagLayout());
    scrollPane = new JScrollPane(widgetList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setOpaque(false);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    scrollPane.getViewport().setOpaque(false);
    scrollPane.getVerticalScrollBar().setUI(new SimpleScrollbarUI(LauncherFrame.COLOR_SCROLL_TRACK, LauncherFrame.COLOR_SCROLL_THUMB));
    scrollPane.getVerticalScrollBar().setPreferredSize(new Dimension(10, 10));
    scrollPane.getVerticalScrollBar().setUnitIncrement(12);
    add(scrollPane, BorderLayout.CENTER);
    widgetList.add(Box.createHorizontalStrut(294), new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    widgetList.add(Box.createGlue(), new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
}
Also used : DocumentListener(javax.swing.event.DocumentListener) SimpleScrollbarUI(net.technicpack.ui.controls.list.SimpleScrollbarUI) DocumentFilter(javax.swing.text.DocumentFilter) DocumentEvent(javax.swing.event.DocumentEvent) AbstractDocument(javax.swing.text.AbstractDocument) AttributeSet(javax.swing.text.AttributeSet) RoundBorder(net.technicpack.ui.controls.borders.RoundBorder) BadLocationException(javax.swing.text.BadLocationException) WatermarkTextField(net.technicpack.ui.controls.WatermarkTextField)

Aggregations

DocumentEvent (javax.swing.event.DocumentEvent)1 DocumentListener (javax.swing.event.DocumentListener)1 AbstractDocument (javax.swing.text.AbstractDocument)1 AttributeSet (javax.swing.text.AttributeSet)1 BadLocationException (javax.swing.text.BadLocationException)1 DocumentFilter (javax.swing.text.DocumentFilter)1 WatermarkTextField (net.technicpack.ui.controls.WatermarkTextField)1 RoundBorder (net.technicpack.ui.controls.borders.RoundBorder)1 SimpleScrollbarUI (net.technicpack.ui.controls.list.SimpleScrollbarUI)1