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.project.ui.internal;
010:
011: import java.awt.Color;
012: import java.io.IOException;
013: import java.util.ArrayList;
014: import java.util.Iterator;
015:
016: import net.refractions.udig.project.internal.Layer;
017: import net.refractions.udig.project.internal.Map;
018: import net.refractions.udig.style.sld.SLDContent;
019: import net.refractions.udig.ui.graphics.SLDs;
020:
021: import org.eclipse.core.runtime.IAdaptable;
022: import org.eclipse.jface.preference.IPreferenceStore;
023: import org.eclipse.swt.graphics.Point;
024: import org.eclipse.swt.widgets.Button;
025: import org.eclipse.swt.widgets.Combo;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Control;
028: import org.eclipse.ui.IWorkbench;
029: import org.eclipse.ui.IWorkbenchPropertyPage;
030: import org.eclipse.ui.dialogs.PropertyPage;
031: import org.geotools.styling.Style;
032:
033: /**
034: * <p>
035: * <b>Purpose:</b>
036: * </p>
037: * <p>
038: * Property page for <em><b>Map</b></em> objects allows user to change default colours.
039: * </p>
040: *
041: * @author ptozer
042: */
043: public class PalettePropertyPage extends PropertyPage implements
044: IWorkbenchPropertyPage {
045: PaletteDefaultChooserPanel panel = new PaletteDefaultChooserPanel();
046:
047: private Map map;
048:
049: public PalettePropertyPage() {
050: setTitle(Messages.PalettePropertyPage_Title);
051: }
052:
053: @Override
054: public void setElement(IAdaptable element) {
055: Map map;
056: if (element instanceof Map) {
057: map = (Map) element;
058: } else {
059: map = (Map) element.getAdapter(Map.class);
060: }
061: this .map = map;
062: }
063:
064: // public PalettePropertyPage( Map map ) {
065: // setTitle(Messages.PalettePropertyPage_Title);
066: // this.map = map;
067: // }
068:
069: /**
070: * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
071: * @param parent
072: */
073: protected Control createContents(Composite parent) {
074:
075: Control c = panel.createPaletteDefaultChooserPanel(parent, map);
076: return c;
077: }
078:
079: /**
080: * @see org.eclipse.jface.preference.IPreferencePage#performOk()
081: */
082: public boolean performOk() {
083:
084: // get colours from the combos and set them into the layer
085: // Control [] allChildren = panel.composite.getChildren();
086: // find controls that are the layer colours
087: // get colour scheme
088: // get the layer colour letter
089: // set colour on symbolizer for the layer
090:
091: ArrayList<PaletteCombo> allLayerColourControls = panel
092: .getAllLayerControls();
093: // so here we want to get all controls, check if the checkbox is selected, and update colour
094: // for the given layer if it is checked
095: // colour controls have a ref to their layer, so we can use this to make changes to the
096: // default for the layer
097:
098: Iterator<PaletteCombo> iterator = allLayerColourControls
099: .iterator();
100:
101: /*
102: * Check all user selections-> if the check box is selected, then we replace all colour info
103: * with the current default colour scheme for the Map. If not, ignore it and the song
104: * remains the same.
105: */
106: while (iterator.hasNext()) {
107: PaletteCombo combo = iterator.next();
108: Layer l = combo.layerReference;
109: Button checkbox = combo.getCheckbox();
110:
111: if (checkbox.getSelection()) {
112: //ColourScheme cs = map.getColourScheme();
113: Combo colourLetterCombo = combo.getColourLetterCombo();
114: String[] letters = colourLetterCombo.getItems();
115: int index = colourLetterCombo.getSelectionIndex();
116: Color colour = null;
117: if (index >= 0) {
118: colour = map.getColorPalette().getColors(
119: letters.length)[index];
120: l.setDefaultColor(colour);
121: }
122: // set layer default colours here
123: Style style = (Style) l.getStyleBlackboard().get(
124: SLDContent.ID);
125:
126: if (style != null) {
127: SLDs.setLineColour(style, colour);
128: SLDs.setPointColour(style, colour);
129: SLDs.setPolyColour(style, colour);
130: }
131: l.setStyleBlackboard(l.getStyleBlackboard());
132: try {
133: // show the change on the Map
134: l.refresh(l.getBounds(null, l.getCRS()));
135:
136: } catch (IOException e) {
137: // TODO Auto-generated catch block
138: e.printStackTrace();
139: }
140: }
141: }
142: return super .performOk();
143: }
144:
145: /*
146: * TODO; where to call dispose() for the panel control?
147: */
148:
149: /**
150: * @see org.eclipse.jface.preference.PreferencePage#doComputeSize()
151: */
152: protected Point doComputeSize() {
153: return new Point(500, 500);
154: }
155:
156: /**
157: * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
158: */
159: public void init(IWorkbench workbench) {
160: }
161:
162: /**
163: * @see org.eclipse.jface.preference.PreferencePage#getPreferenceStore()
164: */
165: public IPreferenceStore getPreferenceStore() {
166: return ProjectUIPlugin.getDefault().getPreferenceStore();
167: }
168: }
|