Menu

Sample2 Log in to Edit

Ramon Casha

Sample Java File

This file demonstrates the use of the HashInclude comment to embed an external file.

package mt.rcasha.swingext;

import javax.swing.JComponent;
import mt.rcasha.swingext.value.ValueChangedEvent;
import mt.rcasha.swingext.value.ValueChangedListener;

public class Sample2 extends JComponent {

//#include(filename=../value-changed-listener.inc,replace=(TYPE=Integer))
    protected final ValueChangeSupport<Integer> vcs = new ValueChangeSupport<Integer>(this);
    @Override
    public void addValueChangedListener(ValueChangedListener l) {
        listenerList.add(ValueChangedListener.class, l);
    }

    @Override
    public void removeValueChangedListener(ValueChangedListener l) {
        listenerList.remove(ValueChangedListener.class, l);
    }

    @SuppressWarnings("unchecked")
    public void fireValueChangedEvent(Integer oldValue, Integer newValue, boolean userChanged) {
        if(oldValue==null && newValue==null) return;
        if(oldValue!=null && newValue!=null && oldValue.equals(newValue)) return;
        @SuppressWarnings("unchecked")
        ValueChangedEvent<Integer> source = new ValueChangedEvent<Integer>(this, oldValue, newValue, userChanged);
        for ( ValueChangedListener<Integer> vcl : getListeners(ValueChangedListener.class)) {
            vcl.valueChanged(source);
        }
    }
//#end
}

Note the comment starting with //#include and another starting with //#end. These are the two key parts that tell HashInclude where the file is located, which block of text to replace, and optional replacements to perform.


Discussion

Anonymous
Anonymous

Add attachments
Cancel