samples/extensibleicon/test/org/apidesign/extensibleicon/ModifiableIcon.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 30 Oct 2014 21:30:10 +0100
changeset 409 40cabcdcd2be
permissions -rw-r--r--
Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
jtulach@256
     1
package org.apidesign.extensibleicon;
jtulach@256
     2
jtulach@256
     3
import java.awt.Component;
jtulach@256
     4
import java.awt.Graphics;
jtulach@256
     5
import java.io.IOException;
jtulach@256
     6
import org.openide.util.Lookup;
jtulach@256
     7
import org.openide.util.lookup.AbstractLookup;
jtulach@256
     8
import org.openide.util.lookup.InstanceContent;
jtulach@256
     9
jtulach@256
    10
// BEGIN: ext.modifiable.icon
jtulach@256
    11
public final class ModifiableIcon implements ExtIcon {
jtulach@256
    12
    // AbstractLookup is helper implementation
jtulach@256
    13
    // so that people do not need to write its own
jtulach@256
    14
    // lookup from scratch
jtulach@256
    15
    private AbstractLookup lookup;
jtulach@256
    16
    // InstanceContent is interface that gives
jtulach@256
    17
    // "creator of the lookup" more rights, like
jtulach@256
    18
    // ability to modify the content
jtulach@256
    19
    private InstanceContent ic;
jtulach@256
    20
    
jtulach@256
    21
    ModifiableIcon() {
jtulach@256
    22
        ic = new InstanceContent();
jtulach@256
    23
        lookup = new AbstractLookup(ic);
jtulach@256
    24
    }
jtulach@256
    25
    
jtulach@256
    26
    public Lookup getLookup() {
jtulach@256
    27
        return lookup;
jtulach@256
    28
    }
jtulach@256
    29
    
jtulach@256
    30
    public void markModified() {
jtulach@256
    31
        if (lookup.lookup(ModifiedImpl.class) == null) {
jtulach@256
    32
            ic.add(new ModifiedImpl());
jtulach@256
    33
        }
jtulach@256
    34
    }
jtulach@256
    35
    
jtulach@256
    36
    private final class ModifiedImpl implements Modified {
jtulach@256
    37
        public void save() throws IOException {
jtulach@256
    38
            // save somehow
jtulach@256
    39
        }
jtulach@256
    40
jtulach@256
    41
        public void discard() throws IOException {
jtulach@256
    42
            // discard changes
jtulach@256
    43
        }
jtulach@256
    44
    }
jtulach@256
    45
// FINISH: ext.modifiable.icon
jtulach@256
    46
jtulach@256
    47
    public void paintIcon(Component c, Graphics g, int x, int y) {
jtulach@256
    48
        g.fillRect(x, y, 16, 16);
jtulach@256
    49
    }
jtulach@256
    50
jtulach@256
    51
    public int getIconWidth() {
jtulach@256
    52
        return 16;
jtulach@256
    53
    }
jtulach@256
    54
jtulach@256
    55
    public int getIconHeight() {
jtulach@256
    56
        return 16;
jtulach@256
    57
    }
jtulach@256
    58
}