Java Code Examples for javax.swing.text.StyleConstants#getBackground()

The following examples show how to use javax.swing.text.StyleConstants#getBackground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationDisplayCustomizationFrame.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
  Style style = AnnotationDisplayCustomizationFrame.this.styleMap
      .get(AnnotationDisplayCustomizationFrame.this.currentTypeName);
  if (style == null) {
    style = AnnotationDisplayCustomizationFrame.this.styleMap.get(CAS.TYPE_NAME_ANNOTATION);
  }
  // assert(style != null);
  AnnotationDisplayCustomizationFrame.this.fgColor = StyleConstants.getForeground(style);
  AnnotationDisplayCustomizationFrame.this.fgIcon
      .setColor(AnnotationDisplayCustomizationFrame.this.fgColor);
  AnnotationDisplayCustomizationFrame.this.bgColor = StyleConstants.getBackground(style);
  AnnotationDisplayCustomizationFrame.this.bgIcon
      .setColor(AnnotationDisplayCustomizationFrame.this.bgColor);
  setCurrentStyle(style);
  setTextPane();
  enableButtons(false);
  AnnotationDisplayCustomizationFrame.this.repaint();
}
 
Example 2
Source File: AnnotationDisplayCustomizationFrame.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the customization panel.
 *
 * @param typeName the new customization panel
 */
private void setCustomizationPanel(String typeName) {
  this.currentTypeName = typeName;
  Style defaultAnnotStyle = this.styleMap.get(CAS.TYPE_NAME_ANNOTATION);
  Style style = this.styleMap.get(typeName);
  if (style == null) {
    style = defaultAnnotStyle;
  }
  // Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(
  // StyleContext.DEFAULT_STYLE);
  setCurrentStyle(style);
  this.fgColor = StyleConstants.getForeground(this.currentStyle);
  this.bgColor = StyleConstants.getBackground(this.currentStyle);
  this.fgIcon.setColor(this.fgColor);
  this.bgIcon.setColor(this.bgColor);
  setTextPane();
  enableButtons(false);
  this.repaint();
}
 
Example 3
Source File: MainFrame.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Save color preferences.
 *
 * @param file the file
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void saveColorPreferences(File file) throws IOException {
  Properties prefs1 = new Properties();
  Iterator<String> it = this.styleMap.keySet().iterator();
  String type;
  Style style;
  Color fg, bg;
  while (it.hasNext()) {
    type = it.next();
    style = this.styleMap.get(type);
    fg = StyleConstants.getForeground(style);
    bg = StyleConstants.getBackground(style);
    prefs1.setProperty(type, Integer.toString(fg.getRGB()) + "+" + Integer.toString(bg.getRGB()));
  }
  FileOutputStream out = new FileOutputStream(file);
  prefs1.store(out, "Color preferences for annotation viewer.");
}
 
Example 4
Source File: TextEditorGUI.java    From trygve with GNU General Public License v2.0 5 votes vote down vote up
public ArrayList<Integer> breakpointByteOffsets() {
	State state = State.LookingForField;
	ArrayList<Integer> retval = new ArrayList<Integer>();
	
	final StyledDocument doc = (StyledDocument)editPane.getDocument();
	final SimpleAttributeSet breakpointColored = new SimpleAttributeSet(); 
	StyleConstants.setBackground(breakpointColored, Color.cyan);
	
	for(int i = 0; i < doc.getLength(); i++) {
		final Element element = doc.getCharacterElement(i);
	    final AttributeSet set = element.getAttributes();
	    final Color backgroundColor = StyleConstants.getBackground(set);
	    switch (state) {
	    case LookingForField:
	    	if (true == backgroundColor.equals(Color.cyan)) {
	    		state = State.InField;
	    		retval.add(new Integer(i));
	    	}
	    	break;
	    case InField:
	    	if (false == backgroundColor.equals(Color.cyan)) {
	    		state = State.LookingForField;
	    	} else if (element.toString().equals("\n")) {
	    		state = State.LookingForField;
	    	}
	    	break;
	    default:
	    	assert (false);
	    	break;
	    }
	}
	
	return retval;
}
 
Example 5
Source File: TextEditorGUI.java    From trygve with GNU General Public License v2.0 5 votes vote down vote up
public void removeAllBreakpoints() {
	final StyledDocument doc = (StyledDocument)editPane.getDocument();
	final SimpleAttributeSet sas = new SimpleAttributeSet();
	StyleConstants.setBackground(sas, new java.awt.Color(233, 228, 242));
	
	// https://stackoverflow.com/questions/28927274/get-attributes-of-selected-text-in-jtextpane
	for(int i = 0; i < doc.getLength(); i++) {
	    final AttributeSet set = doc.getCharacterElement(i).getAttributes();
	    final Color backgroundColor = StyleConstants.getBackground(set);
	    if (backgroundColor.equals(Color.cyan)) {
	    	// The breakpoint color. Remove breakpoint annotation from this text
	    	doc.setCharacterAttributes(i, 1, sas, false);
	    }
	}
}
 
Example 6
Source File: AnnotationDisplayCustomizationFrame.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the customization panel.
 *
 * @param typeName the type name
 * @return the j panel
 */
private JPanel createCustomizationPanel(String typeName) {
  this.currentTypeName = typeName;
  String defaultAnnotStyleName = CAS.TYPE_NAME_ANNOTATION;
  Style defaultAnnotStyle = this.styleMap.get(defaultAnnotStyleName);
  GridLayout layout = new GridLayout(0, 1);
  JPanel topPanel = new JPanel(layout);
  this.textPane = new JTextPane();
  Style style = this.styleMap.get(typeName);
  if (style == null) {
    style = defaultAnnotStyle;
  }
  Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
  this.textPane.addStyle(defaultStyleName, defaultStyle);
  setCurrentStyle(style);
  this.fgColor = StyleConstants.getForeground(this.currentStyle);
  this.bgColor = StyleConstants.getBackground(this.currentStyle);
  this.fgIcon = new ColorIcon(this.fgColor);
  this.bgIcon = new ColorIcon(this.bgColor);
  topPanel.add(createColorPanel("Foreground: ", this.fgIcon, FG));
  topPanel.add(createColorPanel("Background: ", this.bgIcon, BG));
  setTextPane();
  topPanel.add(this.textPane);
  JPanel buttonPanel = new JPanel();
  createButtonPanel(buttonPanel);
  topPanel.add(buttonPanel);
  return topPanel;
}