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));
}
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;
}
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;
}
}
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);
}
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;
}
Aggregations