001: /*
002: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004: * under the terms of the GNU Lesser General Public License as published by the Free Software
005: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008: */
009: package net.refractions.udig.style.sld.internal;
010:
011: import net.refractions.udig.style.sld.SLDEditorPart;
012: import net.refractions.udig.ui.graphics.SLDs;
013:
014: import org.eclipse.swt.SWT;
015: import org.eclipse.swt.events.SelectionAdapter;
016: import org.eclipse.swt.events.SelectionEvent;
017: import org.eclipse.swt.events.SelectionListener;
018: import org.eclipse.swt.layout.GridLayout;
019: import org.eclipse.swt.layout.RowLayout;
020: import org.eclipse.swt.widgets.Composite;
021: import org.eclipse.swt.widgets.Control;
022: import org.eclipse.swt.widgets.Group;
023: import org.eclipse.swt.widgets.Scale;
024: import org.eclipse.swt.widgets.Text;
025: import org.geotools.styling.RasterSymbolizer;
026: import org.geotools.styling.StyleBuilder;
027:
028: /**
029: * summary sentence.
030: * <p>
031: * Paragraph ...
032: * </p>
033: * <p>
034: * Responsibilities:
035: * <ul>
036: * <li>
037: * <li>
038: * </ul>
039: * </p>
040: * <p>
041: * Example:
042: *
043: * <pre><code>
044: *
045: * SLDRasterEditorPart x = new SLDRasterEditorPart( ... );
046: * TODO code example
047: *
048: * </code></pre>
049: *
050: * </p>
051: *
052: * @author aalam
053: * @since 0.6.0
054: */
055: public class SLDRasterEditorPart extends SLDEditorPart implements
056: SelectionListener {
057:
058: private Composite myparent;
059: private Scale opacityScale;
060: private Text opacityText;
061:
062: /*
063: * (non-Javadoc)
064: *
065: * @see net.refractions.udig.style.sld.SLDEditorPart#getContentType()
066: */
067: public Class getContentType() {
068: return RasterSymbolizer.class;
069: }
070:
071: /*
072: * (non-Javadoc)
073: *
074: * @see net.refractions.udig.style.sld.SLDEditorPart#init()
075: */
076: public void init() {
077: //Nothing to do...
078: }
079:
080: /*
081: * (non-Javadoc)
082: *
083: * @see net.refractions.udig.style.sld.SLDEditorPart#reset()
084: */
085: public void reset() {
086: // initialize the ui
087: setStylingElements((RasterSymbolizer) getContent());
088: }
089:
090: private void setStylingElements(RasterSymbolizer symbolizer) {
091: double number = SLDs.rasterOpacity(symbolizer);
092: int opacity = (new Double(number * 100)).intValue();
093:
094: opacityScale.setSelection(opacity);
095: opacityText.setText(Integer.toString(opacity) + "%"); //$NON-NLS-1$
096: opacityText.pack(true);
097: }
098:
099: /*
100: * (non-Javadoc)
101: *
102: * @see net.refractions.udig.style.sld.SLDEditorPart#createPartControl(org.eclipse.swt.widgets.Composite)
103: */
104: protected Control createPartControl(Composite parent) {
105: myparent = parent;
106: RowLayout layout = new RowLayout();
107: myparent.setLayout(layout);
108: layout.pack = false;
109: layout.wrap = true;
110: layout.type = SWT.HORIZONTAL;
111:
112: /* Border Opacity */
113: Group borderOpacityArea = new Group(myparent, SWT.NONE);
114: borderOpacityArea.setLayout(new GridLayout(2, false));
115: borderOpacityArea.setText("Raster Opacity"); //$NON-NLS-1$
116:
117: opacityScale = new Scale(borderOpacityArea, SWT.HORIZONTAL);
118: opacityScale.setMinimum(0);
119: opacityScale.setMaximum(100);
120: opacityScale.setPageIncrement(10);
121: opacityScale.setBounds(0, 0, 10, SWT.DEFAULT);
122: opacityScale.addSelectionListener(new SelectionAdapter() {
123: public void widgetSelected(SelectionEvent e) {
124: opacityText.setText(String.valueOf(opacityScale
125: .getSelection())
126: + "%"); //$NON-NLS-1$
127: opacityText.pack(true);
128: }
129: });
130: opacityScale.addSelectionListener(this );
131:
132: opacityText = new Text(borderOpacityArea, SWT.BORDER
133: | SWT.READ_ONLY);
134: opacityText.pack(true);
135:
136: return parent;
137: }
138:
139: /*
140: * (non-Javadoc)
141: *
142: * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
143: */
144: public void widgetDefaultSelected(SelectionEvent e) {
145: // Meh! Meh I say!
146: }
147:
148: /*
149: * (non-Javadoc)
150: *
151: * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
152: */
153: public void widgetSelected(SelectionEvent e) {
154: apply();
155: }
156:
157: /**
158: * TODO summary sentence for apply ...
159: */
160: public void apply() {
161: RasterSymbolizer symbolizer = (RasterSymbolizer) getContent();
162: StyleBuilder styleBuilder = getStyleBuilder();
163:
164: double opacity = ((double) opacityScale.getSelection()) / 100;
165: symbolizer.setOpacity(styleBuilder.literalExpression(opacity));
166: }
167: }
|