Search in sources :

Example 36 with AttributeSet

use of javax.swing.text.AttributeSet 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)

Example 37 with AttributeSet

use of javax.swing.text.AttributeSet in project omegat by omegat-org.

the class SegmentBuilder method addActiveSegPart.

/**
 * Add active (translation) segment part, with segment begin/end marks.
 *
 * @param text
 *            segment part text
 * @throws BadLocationException
 */
private String addActiveSegPart(String text) throws BadLocationException {
    int prevOffset = offset;
    // write translation part
    boolean rtl = controller.targetLangIsRTL;
    insertDirectionEmbedding(rtl);
    activeTranslationBeginOffset = offset;
    String result = insertTextWithTags(text, false);
    activeTranslationEndOffset = offset;
    insertDirectionEndEmbedding();
    // write segment marker
    // we want the marker AFTER the translated text, so use same direction as target text.
    insertDirectionMarker(rtl);
    // the marker itself is in user language
    insertDirectionEmbedding(Language.localeIsRTL());
    AttributeSet attrSegmentMark = settings.getSegmentMarkerAttributeSet();
    insert(createSegmentMarkText(), attrSegmentMark);
    insertDirectionEndEmbedding();
    // we want the marker AFTER the translated text, so embed in same direction as target text.
    insertDirectionMarker(rtl);
    insert("\n", null);
    setAlignment(prevOffset, offset, rtl);
    return result;
}
Also used : MutableAttributeSet(javax.swing.text.MutableAttributeSet) AttributeSet(javax.swing.text.AttributeSet)

Example 38 with AttributeSet

use of javax.swing.text.AttributeSet in project omegat by omegat-org.

the class SegmentBuilder method resetTextAttributes.

public void resetTextAttributes() {
    doc.trustedChangesInProgress = true;
    try {
        if (posSourceBeg != null) {
            int sBeg = posSourceBeg.getOffset();
            int sLen = posSourceLength;
            AttributeSet attrs = attrs(true, false, false, false);
            doc.setCharacterAttributes(sBeg, sLen, attrs, true);
        }
        if (active) {
            int tBeg = doc.getTranslationStart();
            int tEnd = doc.getTranslationEnd();
            AttributeSet attrs = attrs(false, false, false, false);
            doc.setCharacterAttributes(tBeg, tEnd - tBeg, attrs, true);
        } else {
            if (posTranslationBeg != null) {
                int tBeg = posTranslationBeg.getOffset();
                int tLen = posTranslationLength;
                AttributeSet attrs = attrs(false, false, false, false);
                doc.setCharacterAttributes(tBeg, tLen, attrs, true);
            }
        }
    } finally {
        doc.trustedChangesInProgress = false;
    }
}
Also used : MutableAttributeSet(javax.swing.text.MutableAttributeSet) AttributeSet(javax.swing.text.AttributeSet)

Example 39 with AttributeSet

use of javax.swing.text.AttributeSet in project omegat by omegat-org.

the class SegmentBuilder method addModificationInfoPart.

/**
 * Adds a string that displays the modification info (author and date). Does
 * nothing if the translation entry is null.
 *
 * @param trans
 *            The translation entry (can be null)
 * @throws BadLocationException
 */
private void addModificationInfoPart(TMXEntry trans) throws BadLocationException {
    if (!trans.isTranslated()) {
        return;
    }
    String text;
    if (Preferences.isPreference(Preferences.VIEW_OPTION_TEMPLATE_ACTIVE)) {
        text = ModificationInfoManager.apply(trans);
    } else {
        String author = (trans.changer == null ? OStrings.getString("TF_CUR_SEGMENT_UNKNOWN_AUTHOR") : trans.changer);
        String template;
        if (trans.changeDate != 0) {
            template = OStrings.getString("TF_CUR_SEGMENT_AUTHOR_DATE");
            Date changeDate = new Date(trans.changeDate);
            String changeDateString = DateFormat.getDateInstance().format(changeDate);
            String changeTimeString = DateFormat.getTimeInstance().format(changeDate);
            Object[] args = { author, changeDateString, changeTimeString };
            text = StringUtil.format(template, args);
        } else {
            template = OStrings.getString("TF_CUR_SEGMENT_AUTHOR");
            Object[] args = { author };
            text = StringUtil.format(template, args);
        }
    }
    int prevOffset = offset;
    boolean rtl = Language.localeIsRTL();
    insertDirectionEmbedding(rtl);
    AttributeSet attrs = settings.getModificationInfoAttributeSet();
    insert(text, attrs);
    insertDirectionEndEmbedding();
    insert("\n", null);
    setAlignment(prevOffset, offset, rtl);
}
Also used : MutableAttributeSet(javax.swing.text.MutableAttributeSet) AttributeSet(javax.swing.text.AttributeSet) Date(java.util.Date)

Example 40 with AttributeSet

use of javax.swing.text.AttributeSet in project binnavi by google.

the class BaseTypeTableCellRenderer method convertDocumentToFormattedCharacterBuffer.

public static FormattedCharacterBuffer convertDocumentToFormattedCharacterBuffer(final StyledDocument document, Font font, int desiredWidth) {
    // The following code calculates the number of rows and the number of columns required for the
    // FormattedCharacterBuffer.
    int width = desiredWidth, height = 0;
    String text = "";
    try {
        text = document.getText(0, document.getLength());
    } catch (BadLocationException e) {
    // Cannot happen.
    }
    String[] chunks = text.split("\n");
    height = chunks.length;
    for (String line : chunks) {
        // The +1 is necessary because we wish to store the newline characters in the
        // FormattedCharacterBuffer.
        width = Math.max(width, line.length() + 1);
    }
    // Height & width is calculated, now create the buffer.
    FormattedCharacterBuffer result = new FormattedCharacterBuffer(height, width);
    int lineindex = 0, columnindex = 0;
    for (int index = 0; index < document.getLength(); ++index) {
        if (text.charAt(index) != '\n') {
            AttributeSet attributes = document.getCharacterElement(index).getAttributes();
            Color foreground = document.getForeground(attributes);
            Color background = document.getBackground(attributes);
            columnindex++;
            result.setAt(lineindex, columnindex, text.charAt(index), font, foreground, background);
        } else {
            columnindex = 0;
            lineindex++;
        }
    }
    return result;
}
Also used : AttributeSet(javax.swing.text.AttributeSet) Color(java.awt.Color) BadLocationException(javax.swing.text.BadLocationException) FormattedCharacterBuffer(com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)

Aggregations

AttributeSet (javax.swing.text.AttributeSet)44 Element (javax.swing.text.Element)15 MutableAttributeSet (javax.swing.text.MutableAttributeSet)10 BadLocationException (javax.swing.text.BadLocationException)9 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)9 HTMLDocument (javax.swing.text.html.HTMLDocument)7 AbstractDocument (javax.swing.text.AbstractDocument)6 Document (javax.swing.text.Document)5 DocumentFilter (javax.swing.text.DocumentFilter)5 Font (java.awt.Font)3 Point (java.awt.Point)3 URL (java.net.URL)3 HTML (javax.swing.text.html.HTML)3 java.awt (java.awt)2 Color (java.awt.Color)2 Dimension (java.awt.Dimension)2 FontMetrics (java.awt.FontMetrics)2 Rectangle (java.awt.Rectangle)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2