Search in sources :

Example 31 with TextAttribute

use of java.awt.font.TextAttribute in project opennars by opennars.

the class StyledString method addAttribute.

/**
 * Set the attribute to be applied to a range of characters starting at
 * beginIdx and ending with endIdx-1.
 *
 * @param type attribute type
 * @param value attribute value
 * @param beginIdx the index of the first character (inclusive)
 * @param endIdx the index of the last character (exclusive)
 */
public void addAttribute(Attribute type, Object value, int beginIdx, int endIdx) {
    value = validateTextAttributeColor((TextAttribute) type, value);
    AttributeRun ar = new AttributeRun(type, value, beginIdx, endIdx);
    // runs if possible and removing runs that no longer have a visible effect.
    if (atrun.size() > 0) {
        ListIterator<AttributeRun> iter = atrun.listIterator(atrun.size());
        while (iter.hasPrevious()) {
            AttributeRun a = iter.previous();
            int action = ar.intersectionWith(a);
            int intersect = action & I_MODES;
            int combiMode = action & COMBI_MODES;
            if (combiMode == MERGE_RUNS) {
                switch(intersect) {
                    case I_TL:
                    case I_CL:
                        ar.start = a.start;
                        iter.remove();
                        break;
                    case I_TR:
                    case I_CR:
                        ar.end = a.end;
                        iter.remove();
                        break;
                }
            } else if (combiMode == CLIP_RUN) {
                switch(intersect) {
                    case I_CL:
                        a.end = ar.start;
                        break;
                    case I_CR:
                        a.start = ar.end;
                        break;
                }
            }
            switch(intersect) {
                case I_INSIDE:
                    iter.remove();
                    break;
                case I_COVERED:
                    ar = null;
                    break;
            }
        }
    }
    // If the run is still effective then add it
    if (ar != null)
        atrun.addLast(ar);
    applyAttributes();
    invalidLayout = true;
}
Also used : TextAttribute(java.awt.font.TextAttribute) Point(java.awt.Point)

Aggregations

TextAttribute (java.awt.font.TextAttribute)31 Font (java.awt.Font)22 HashMap (java.util.HashMap)22 Configuration (com.haulmont.cuba.core.global.Configuration)2 DesktopConfig (com.haulmont.cuba.desktop.DesktopConfig)2 FontMetrics (java.awt.FontMetrics)2 Paint (java.awt.Paint)2 MouseEvent (java.awt.event.MouseEvent)2 AffineTransform (java.awt.geom.AffineTransform)2 Hashtable (java.util.Hashtable)2 DesktopResources (com.haulmont.cuba.desktop.DesktopResources)1 CollapsiblePanel (com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel)1 WebColors (com.revolsys.awt.WebColors)1 Geometry (com.revolsys.geometry.model.Geometry)1 SwingUtil (com.revolsys.swing.SwingUtil)1 ClipboardUtil (com.revolsys.swing.dnd.ClipboardUtil)1 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)1 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)1 LayerRecordMenu (com.revolsys.swing.map.layer.record.LayerRecordMenu)1 RecordLayerTableModel (com.revolsys.swing.map.layer.record.table.model.RecordLayerTableModel)1