0001: /*
0002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
0003: * for visualizing and manipulating spatial features with geometry and attributes.
0004: *
0005: * Copyright (C) 2003 Vivid Solutions
0006: *
0007: * This program is free software; you can redistribute it and/or
0008: * modify it under the terms of the GNU General Public License
0009: * as published by the Free Software Foundation; either version 2
0010: * of the License, or (at your option) any later version.
0011: *
0012: * This program is distributed in the hope that it will be useful,
0013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015: * GNU General Public License for more details.
0016: *
0017: * You should have received a copy of the GNU General Public License
0018: * along with this program; if not, write to the Free Software
0019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
0020: *
0021: * For more information, contact:
0022: *
0023: * Vivid Solutions
0024: * Suite #1A
0025: * 2328 Government Street
0026: * Victoria BC V8T 5G5
0027: * Canada
0028: *
0029: * (250)385-6040
0030: * www.vividsolutions.com
0031: */
0032: package de.latlon.deejump.plugin.style;
0033:
0034: import java.awt.BorderLayout;
0035: import java.awt.Color;
0036: import java.awt.Component;
0037: import java.awt.Dimension;
0038: import java.awt.GridBagConstraints;
0039: import java.awt.GridBagLayout;
0040: import java.awt.Insets;
0041: import java.awt.event.ActionEvent;
0042: import java.awt.event.ActionListener;
0043: import java.awt.event.MouseAdapter;
0044: import java.awt.event.MouseEvent;
0045: import java.util.Collection;
0046: import java.util.EventObject;
0047: import java.util.HashSet;
0048: import java.util.Iterator;
0049: import java.util.Map;
0050: import java.util.SortedSet;
0051: import java.util.TreeMap;
0052: import java.util.TreeSet;
0053: import java.util.Vector;
0054:
0055: import javax.swing.BorderFactory;
0056: import javax.swing.DefaultCellEditor;
0057: import javax.swing.DefaultComboBoxModel;
0058: import javax.swing.Icon;
0059: import javax.swing.JButton;
0060: import javax.swing.JCheckBox;
0061: import javax.swing.JComboBox;
0062: import javax.swing.JComponent;
0063: import javax.swing.JDialog;
0064: import javax.swing.JLabel;
0065: import javax.swing.JList;
0066: import javax.swing.JPanel;
0067: import javax.swing.JScrollPane;
0068: import javax.swing.JSlider;
0069: import javax.swing.JTable;
0070: import javax.swing.ScrollPaneConstants;
0071: import javax.swing.SwingUtilities;
0072: import javax.swing.event.CellEditorListener;
0073: import javax.swing.event.ChangeEvent;
0074: import javax.swing.event.ChangeListener;
0075: import javax.swing.event.ListSelectionEvent;
0076: import javax.swing.event.ListSelectionListener;
0077: import javax.swing.event.TableModelEvent;
0078: import javax.swing.event.TableModelListener;
0079: import javax.swing.table.DefaultTableCellRenderer;
0080: import javax.swing.table.TableCellEditor;
0081: import javax.swing.table.TableCellRenderer;
0082:
0083: import com.vividsolutions.jump.I18N;
0084: import com.vividsolutions.jump.feature.Feature;
0085: import com.vividsolutions.jump.util.CollectionUtil;
0086: import com.vividsolutions.jump.util.Range;
0087: import com.vividsolutions.jump.workbench.WorkbenchContext;
0088: import com.vividsolutions.jump.workbench.model.Layer;
0089: import com.vividsolutions.jump.workbench.model.LayerManager;
0090: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
0091: import com.vividsolutions.jump.workbench.plugin.EnableCheck;
0092: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
0093: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
0094: import com.vividsolutions.jump.workbench.ui.ColorPanel;
0095: import com.vividsolutions.jump.workbench.ui.EnableableToolBar;
0096: import com.vividsolutions.jump.workbench.ui.GUIUtil;
0097: import com.vividsolutions.jump.workbench.ui.OKCancelPanel;
0098: import com.vividsolutions.jump.workbench.ui.images.IconLoader;
0099: import com.vividsolutions.jump.workbench.ui.renderer.style.BasicStyle;
0100: import com.vividsolutions.jump.workbench.ui.renderer.style.BasicStyleListCellRenderer;
0101: import com.vividsolutions.jump.workbench.ui.renderer.style.ColorScheme;
0102: import com.vividsolutions.jump.workbench.ui.renderer.style.ColorSchemeListCellRenderer;
0103: import com.vividsolutions.jump.workbench.ui.renderer.style.ColorThemingStyle;
0104: import com.vividsolutions.jump.workbench.ui.renderer.style.ColorThemingStylePanel;
0105: import com.vividsolutions.jump.workbench.ui.renderer.style.DiscreteColorThemingState;
0106: import com.vividsolutions.jump.workbench.ui.renderer.style.SquareVertexStyle;
0107: import com.vividsolutions.jump.workbench.ui.renderer.style.Style;
0108: import com.vividsolutions.jump.workbench.ui.renderer.style.VertexStyle;
0109: import com.vividsolutions.jump.workbench.ui.renderer.style.ColorThemingStylePanel.State;
0110: import com.vividsolutions.jump.workbench.ui.style.BasicStylePanel;
0111: import com.vividsolutions.jump.workbench.ui.style.StylePanel;
0112:
0113: public class DeeColorThemingStylePanel extends JPanel implements
0114: StylePanel {
0115: // GH 2005.09.22
0116: VertexStyleChooser vertexStyleChooser = new VertexStyleChooser(true);
0117: private static final String CUSTOM_ENTRY = I18N
0118: .get("ui.renderer.style.ColorThemingPanel.custom");
0119: public static final String TITLE = I18N
0120: .get("ui.renderer.style.ColorThemingPanel.colour-theming");
0121: public static final String COLOR_SCHEME_KEY = DeeColorThemingStylePanel.class
0122: .getName()
0123: + " - COLOR SCHEME";
0124: private WorkbenchContext workbenchContext;
0125: private Layer layer;
0126: private GridBagLayout gridBagLayout1 = new GridBagLayout();
0127: private JPanel jPanel1 = new JPanel();
0128: private JScrollPane scrollPane = new JScrollPane();
0129: private DefaultTableCellRenderer allOtherValuesRenderer = new DefaultTableCellRenderer();
0130: private JTable table = new JTable() {
0131: public TableCellRenderer getCellRenderer(int row, int column) {
0132: TableCellRenderer renderer = getCellRendererProper(row,
0133: column);
0134:
0135: if (renderer instanceof JComponent) {
0136: updateBackground((JComponent) renderer);
0137: }
0138:
0139: return renderer;
0140: }
0141:
0142: private TableCellRenderer getCellRendererProper(int row,
0143: int column) {
0144: if ((row == 0) && (column == attributeColumn())) {
0145: return allOtherValuesRenderer;
0146: }
0147: if ((row == 0) && (column == labelColumn())) {
0148: return allOtherValuesRenderer;
0149: }
0150: TableCellRenderer renderer = super .getCellRenderer(row,
0151: column);
0152:
0153: if (renderer instanceof JLabel) {
0154: ((JLabel) renderer).setHorizontalAlignment(JLabel.LEFT);
0155: }
0156:
0157: return renderer;
0158: }
0159: };
0160:
0161: private JPanel jPanel3 = new JPanel();
0162: private GridBagLayout gridBagLayout2 = new GridBagLayout();
0163: private GridBagLayout gridBagLayout4 = new GridBagLayout();
0164: private JComboBox attributeNameComboBox = new JComboBox();
0165: private JLabel attributeLabel = new JLabel();
0166: private JLabel statusLabel = new JLabel() {
0167: public void setText(String text) {
0168: super .setText(text);
0169: setToolTipText(text);
0170: }
0171: };
0172:
0173: private EnableableToolBar toolBar = new EnableableToolBar();
0174: private JPanel jPanel4 = new JPanel();
0175: private GridBagLayout gridBagLayout5 = new GridBagLayout();
0176: private JComboBox colorSchemeComboBox = new JComboBox();
0177: private JLabel colorSchemeLabel = new JLabel();
0178: private boolean updatingComponents = false;
0179: private boolean initializing = false;
0180: private BasicStyleListCellRenderer basicStyleListCellRenderer = new BasicStyleListCellRenderer();
0181: public BasicStylePanel basicStylePanel;
0182: private TableCellEditor basicStyleTableCellEditor = new TableCellEditor() {
0183: private DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
0184: private BasicStyle originalStyle;
0185: private DefaultCellEditor editor;
0186: private JComboBox comboBox = new JComboBox(comboBoxModel) {
0187: public void setSelectedItem(Object anObject) {
0188: if (anObject != CUSTOM_ENTRY) {
0189: super .setSelectedItem(anObject);
0190:
0191: return;
0192: }
0193: Style[] styles = promptBasicStyle(originalStyle);
0194: VertexStyle vertexStyle = (VertexStyle) styles[1];
0195: BasicStyle style = (BasicStyle) styles[0];
0196: if (style == null) {
0197: return;
0198: }
0199:
0200: // this is never ever going to cause anything
0201: //ColorThemingTableModel obj = new ColorThemingTableModel();
0202:
0203: ((DeeColorThemingTableModel) table.getModel())
0204: .setVertexStyleAt(vertexStyle, table
0205: .getSelectedRow());
0206:
0207: comboBox.addItem(style);
0208: super .setSelectedItem(style);
0209: }
0210:
0211: };
0212:
0213: {
0214: comboBox.setRenderer(basicStyleListCellRenderer);
0215: editor = new DefaultCellEditor(comboBox);
0216: }
0217:
0218: public Component getTableCellEditorComponent(JTable table,
0219: Object value, boolean isSelected, int row, int column) {
0220:
0221: originalStyle = (BasicStyle) value;
0222: comboBoxModel.removeAllElements();
0223: comboBoxModel.addElement(CUSTOM_ENTRY);
0224:
0225: //Include the current BasicStyle; otherwise, the current BasicStyle
0226: //will not show up as the selected item in the combo box. [Jon Aquino]
0227: comboBoxModel.addElement(value);
0228:
0229: for (Iterator i = ColorScheme.create(
0230: (String) colorSchemeComboBox.getSelectedItem())
0231: .getColors().iterator(); i.hasNext();) {
0232: Color color = (Color) i.next();
0233: comboBoxModel.addElement(new BasicStyle(color));
0234: }
0235:
0236: comboBoxModel.setSelectedItem(value);
0237:
0238: return editor.getTableCellEditorComponent(table, value,
0239: isSelected, row, column);
0240: }
0241:
0242: public Object getCellEditorValue() {
0243: return editor.getCellEditorValue();
0244: }
0245:
0246: public boolean isCellEditable(EventObject anEvent) {
0247: return editor.isCellEditable(anEvent);
0248: }
0249:
0250: public boolean shouldSelectCell(EventObject anEvent) {
0251: return editor.shouldSelectCell(anEvent);
0252: }
0253:
0254: public boolean stopCellEditing() {
0255: return editor.stopCellEditing();
0256: }
0257:
0258: public void cancelCellEditing() {
0259: editor.cancelCellEditing();
0260: }
0261:
0262: public void addCellEditorListener(CellEditorListener l) {
0263: editor.addCellEditorListener(l);
0264: }
0265:
0266: public void removeCellEditorListener(CellEditorListener l) {
0267: editor.removeCellEditorListener(l);
0268: }
0269: };
0270:
0271: private DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
0272: private JPanel fillerPanel = new JPanel();
0273: private String lastAttributeName;
0274: private ColorScheme colorSchemeForInserts = null;
0275: private MyPlugIn insertPlugIn = new MyPlugIn() {
0276: public String getName() {
0277: return I18N
0278: .get("ui.renderer.style.ColorThemingPanel.insert-row");
0279: }
0280:
0281: public Icon getIcon() {
0282: return GUIUtil.toSmallIcon(IconLoader.icon("Plus.gif"));
0283: }
0284:
0285: public boolean execute(PlugInContext context) throws Exception {
0286: reportNothingToUndoYet(context);
0287: stopCellEditing();
0288: tableModel()
0289: .insertAttributeValue(
0290: (table.getSelectedRowCount() > 0) ? table
0291: .getSelectedRows()[0] : table
0292: .getRowCount(),
0293: getColorSchemeForInserts());
0294:
0295: if (table.getSelectedRowCount() == 0) {
0296: table.scrollRectToVisible(table.getCellRect(table
0297: .getRowCount() - 1, 0, true));
0298: }
0299:
0300: if (table.getSelectedRowCount() != 0) {
0301: int firstSelectedRow = table.getSelectedRows()[0];
0302: table.clearSelection();
0303: table.addRowSelectionInterval(firstSelectedRow,
0304: firstSelectedRow);
0305:
0306: }
0307:
0308: return true;
0309: }
0310: };
0311:
0312: private MyPlugIn deletePlugIn = new MyPlugIn() {
0313: public String getName() {
0314: return I18N
0315: .get("ui.renderer.style.ColorThemingPanel.delete-row");
0316: }
0317:
0318: public Icon getIcon() {
0319: return GUIUtil.toSmallIcon(IconLoader.icon("Delete.gif"));
0320: }
0321:
0322: public boolean execute(PlugInContext context) throws Exception {
0323: reportNothingToUndoYet(context);
0324: stopCellEditing();
0325: tableModel().removeAttributeValues(table.getSelectedRows());
0326:
0327: return true;
0328: }
0329: };
0330:
0331: //Maintain a blackboard for error messages instead of running all
0332: //validations whenever we need to check for messages -- some validations
0333: //may be expensive. [Jon Aquino]
0334: private HashSet errorMessages = new HashSet();
0335: private DiscreteColorThemingState discreteColorThemingState = new DiscreteColorThemingState(
0336: table);
0337: private DeeRangeColorThemingState rangeColorThemingState;
0338: private ColorThemingStylePanel.State state = discreteColorThemingState;
0339: private JPanel jPanel5 = new JPanel();
0340: private GridBagLayout gridBagLayout3 = new GridBagLayout();
0341: private JCheckBox enableColorThemingCheckBox = new JCheckBox();
0342: private JCheckBox byRangeCheckBox = new JCheckBox();
0343: private JSlider transparencySlider = new JSlider();
0344:
0345: public DeeColorThemingStylePanel(Layer layer,
0346: WorkbenchContext workbenchContext) {
0347: initializing = true;
0348:
0349: try {
0350: basicStylePanel = new BasicStylePanel(workbenchContext
0351: .getWorkbench().getBlackboard(),
0352: ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
0353: this .layer = layer;
0354: this .workbenchContext = workbenchContext;
0355: rangeColorThemingState = new DeeRangeColorThemingState(this );
0356: jbInit();
0357: byRangeCheckBox
0358: .setSelected(colorThemingStyleHasRanges(layer));
0359:
0360: //Must set state early so that #initTable can call #fromExternalFormat. [Jon Aquino]
0361: state = byRangeCheckBox.isSelected() ? (ColorThemingStylePanel.State) rangeColorThemingState
0362: : discreteColorThemingState;
0363:
0364: //Init the table before calling #setState, in which
0365: //RangeColorThemingState will add itself as a listener
0366: //to the table model. [Jon Aquino]
0367: initTable(layer);
0368: setState(state);
0369: initAttributeNameComboBox(layer);
0370: initColorSchemeComboBox(layer.getLayerManager());
0371: initTransparencySlider(layer);
0372: initToolBar();
0373: enableColorThemingCheckBox.setSelected(DeeColorThemingStyle
0374: .get(layer).isEnabled());
0375: updateComponents();
0376: GUIUtil.sync(basicStylePanel.getTransparencySlider(),
0377: transparencySlider);
0378: basicStylePanel.setSynchronizingLineColor(layer
0379: .isSynchronizingLineColor());
0380: } catch (Exception e) {
0381: e.printStackTrace();
0382: } finally {
0383: initializing = false;
0384: }
0385: }
0386:
0387: private void updateBackground(JComponent component) {
0388: component
0389: .setBackground(enableColorThemingCheckBox.isSelected() ? Color.white
0390: : jPanel1.getBackground());
0391: }
0392:
0393: private int attributeColumn() {
0394: return table
0395: .convertColumnIndexToView(DeeColorThemingTableModel.ATTRIBUTE_COLUMN);
0396: }
0397:
0398: private int labelColumn() {
0399: return table
0400: .convertColumnIndexToView(DeeColorThemingTableModel.LABEL_COLUMN);
0401: }
0402:
0403: private int colorColumn() {
0404: return table
0405: .convertColumnIndexToView(DeeColorThemingTableModel.COLOR_COLUMN);
0406: }
0407:
0408: public String getTitle() {
0409: return TITLE;
0410: }
0411:
0412: public void updateStyles() {
0413: boolean firingEvents = layer.getLayerManager().isFiringEvents();
0414: layer.getLayerManager().setFiringEvents(false);
0415:
0416: try {
0417: ////[UT] 31.10.2005 must remove ColorThemingStyle here, because panel is not
0418: // being called for points and ColorThem Style was first of list
0419: // xsl doesn't want it so: <xsl:param name="defaultFillColor"
0420: //select="xslutil:toHexColor(/layer/styles/style[1]/fill/color)"/>
0421:
0422: layer.removeStyle(ColorThemingStyle.get(layer));
0423:
0424: layer.removeStyle(DeeColorThemingStyle.get(layer));
0425: layer.addStyle(new DeeColorThemingStyle(getAttributeName(),
0426: state.toExternalFormat(tableModel()
0427: .getAttributeValueToBasicStyleMap()), state
0428: .toExternalFormat(tableModel()
0429: .getAttributeValueToLabelMap()),
0430: state.toExternalFormat(tableModel()
0431: .getAttributeValueToVertexStyleMap()),
0432: tableModel().getDefaultStyle()));
0433: DeeColorThemingStyle.get(layer).setAlpha(getAlpha());
0434: DeeColorThemingStyle.get(layer).setEnabled(
0435: enableColorThemingCheckBox.isSelected());
0436: layer.getBasicStyle().setEnabled(
0437: !enableColorThemingCheckBox.isSelected());
0438: } finally {
0439: layer.getLayerManager().setFiringEvents(firingEvents);
0440: }
0441: layer.fireAppearanceChanged();
0442: }
0443:
0444: private String getAttributeName() {
0445: return (String) attributeNameComboBox.getSelectedItem();
0446: }
0447:
0448: private void stopCellEditing() {
0449: if (table.getCellEditor() instanceof DefaultCellEditor) {
0450: ((DefaultCellEditor) table.getCellEditor())
0451: .stopCellEditing();
0452: }
0453: }
0454:
0455: public JCheckBox getSynchronizeCheckBox() {
0456: return basicStylePanel.getSynchronizeCheckBox();
0457: }
0458:
0459: public Layer getLayer() {
0460: return layer;
0461: }
0462:
0463: private void initTransparencySlider(Layer layer) {
0464: transparencySlider.setValue(transparencySlider.getMaximum()
0465: - DeeColorThemingStyle.get(layer).getDefaultStyle()
0466: .getAlpha());
0467: transparencySlider.addChangeListener(new ChangeListener() {
0468: public void stateChanged(ChangeEvent e) {
0469: basicStyleListCellRenderer.setAlpha(getAlpha());
0470: }
0471: });
0472: basicStyleListCellRenderer.setAlpha(getAlpha());
0473: }
0474:
0475: private boolean colorThemingStyleHasRanges(Layer layer) {
0476: return !DeeColorThemingStyle.get(layer)
0477: .getAttributeValueToBasicStyleMap().isEmpty()
0478: && DeeColorThemingStyle.get(layer)
0479: .getAttributeValueToBasicStyleMap().keySet()
0480: .iterator().next() instanceof Range;
0481: }
0482:
0483: private void initToolBar() {
0484: EnableCheck atLeast1RowMustBeSelectedCheck = new EnableCheck() {
0485: public String check(JComponent component) {
0486: return (table.getSelectedRowCount() == 0) ? I18N
0487: .get("ui.renderer.style.ColorThemingPanel.at-least-1-row-must-be-selected")
0488: : null;
0489: }
0490: };
0491:
0492: EnableCheck layerMustHaveAtLeast1AttributeCheck = new EnableCheck() {
0493: public String check(JComponent component) {
0494: return (attributeNameComboBox.getItemCount() == 0) ? I18N
0495: .get("ui.renderer.style.ColorThemingPanel.layer-must-have-at-least-1-attribute")
0496: : null;
0497: }
0498: };
0499:
0500: EnableCheck colorThemingMustBeEnabledCheck = new EnableCheck() {
0501: public String check(JComponent component) {
0502: return (!enableColorThemingCheckBox.isSelected()) ? I18N
0503: .get("ui.renderer.style.ColorThemingPanel.colour-theming-must-be-enabled")
0504: : null;
0505: }
0506: };
0507:
0508: addPlugIn(insertPlugIn, new MultiEnableCheck().add(
0509: layerMustHaveAtLeast1AttributeCheck).add(
0510: colorThemingMustBeEnabledCheck));
0511: addPlugIn(deletePlugIn, new MultiEnableCheck().add(
0512: layerMustHaveAtLeast1AttributeCheck).add(
0513: atLeast1RowMustBeSelectedCheck).add(
0514: colorThemingMustBeEnabledCheck));
0515: }
0516:
0517: private void addPlugIn(MyPlugIn plugIn, EnableCheck enableCheck) {
0518: JButton button = new JButton();
0519: toolBar.add(button, plugIn.getName(), plugIn.getIcon(),
0520: AbstractPlugIn.toActionListener(plugIn,
0521: workbenchContext, null), enableCheck);
0522: }
0523:
0524: private void updateComponents() {
0525: if (updatingComponents) {
0526: return;
0527: }
0528:
0529: updatingComponents = true;
0530:
0531: try {
0532: attributeLabel.setEnabled(enableColorThemingCheckBox
0533: .isSelected());
0534: attributeNameComboBox.setEnabled(enableColorThemingCheckBox
0535: .isSelected());
0536: state.getPanel()
0537: .setEnabled(
0538: enableColorThemingCheckBox.isSelected()
0539: && (attributeNameComboBox
0540: .getItemCount() > 0));
0541: colorSchemeLabel.setEnabled(enableColorThemingCheckBox
0542: .isSelected()
0543: && (attributeNameComboBox.getItemCount() > 0));
0544: byRangeCheckBox.setEnabled(enableColorThemingCheckBox
0545: .isSelected()
0546: && (attributeNameComboBox.getItemCount() > 0));
0547: colorSchemeComboBox.setEnabled(enableColorThemingCheckBox
0548: .isSelected()
0549: && (attributeNameComboBox.getItemCount() > 0));
0550: table.setEnabled(enableColorThemingCheckBox.isSelected()
0551: && (attributeNameComboBox.getItemCount() > 0));
0552: scrollPane.setEnabled(enableColorThemingCheckBox
0553: .isSelected()
0554: && (attributeNameComboBox.getItemCount() > 0));
0555: transparencySlider.setEnabled(enableColorThemingCheckBox
0556: .isSelected()
0557: && (attributeNameComboBox.getItemCount() > 0));
0558: statusLabel.setEnabled(enableColorThemingCheckBox
0559: .isSelected());
0560: toolBar.updateEnabledState();
0561:
0562: //Give the "Cannot colour-theme layer" message priority. [Jon Aquino]
0563: if (!setErrorMessage(
0564: new ErrorMessage(
0565: I18N
0566: .get("ui.renderer.style.ColorThemingPanel.cannot-colour-theme-layer-with-no-attributes")),
0567: attributeNameComboBox.getItemCount() == 0)) {
0568: setErrorMessage(
0569: new ErrorMessage(
0570: I18N
0571: .get("ui.renderer.style.ColorThemingPanel.table-must-not-be-empty")),
0572: table.getRowCount() == 0);
0573: }
0574:
0575: updateErrorDisplay();
0576:
0577: if (table.getColumnCount() > 0) {
0578: //Column count == 0 during initialization. [Jon Aquino]
0579: table
0580: .getColumnModel()
0581: .getColumn(
0582: table
0583: .convertColumnIndexToView(DeeColorThemingTableModel.ATTRIBUTE_COLUMN))
0584: .setHeaderValue(
0585: state.getAttributeValueColumnTitle());
0586: }
0587: } finally {
0588: updatingComponents = false;
0589: }
0590: }
0591:
0592: /**
0593: * @return null if user hits Cancel
0594: */
0595: private Style[] promptBasicStyle(BasicStyle basicStyle) {
0596: int originalTransparencySliderValue = transparencySlider
0597: .getValue();
0598: basicStylePanel.setBasicStyle(basicStyle);
0599: basicStylePanel.getTransparencySlider().setValue(
0600: originalTransparencySliderValue);
0601:
0602: OKCancelPanel okCancelPanel = new OKCancelPanel();
0603: final JDialog dialog = new JDialog((JDialog) SwingUtilities
0604: .windowForComponent(this ), I18N
0605: .get("ui.renderer.style.ColorThemingPanel.custom"),
0606: true);
0607: dialog.getContentPane().setLayout(new BorderLayout());
0608: dialog.getContentPane()
0609: .add(basicStylePanel, BorderLayout.NORTH);
0610: dialog.getContentPane().add(vertexStyleChooser,
0611: BorderLayout.WEST);
0612: dialog.getContentPane().add(okCancelPanel, BorderLayout.SOUTH);
0613: okCancelPanel.addActionListener(new ActionListener() {
0614: public void actionPerformed(ActionEvent e) {
0615: dialog.setVisible(false);
0616: }
0617: });
0618: dialog.pack();
0619: GUIUtil.centreOnWindow(dialog);
0620: dialog.setVisible(true);
0621:
0622: if (!okCancelPanel.wasOKPressed()) {
0623: transparencySlider
0624: .setValue(originalTransparencySliderValue);
0625: }
0626: Style style[] = new Style[2];
0627: style[0] = basicStylePanel.getBasicStyle();
0628: style[1] = vertexStyleChooser.getSelectedStyle();
0629: return okCancelPanel.wasOKPressed() ? style : null;
0630: }
0631:
0632: //GH 2005.10.17
0633:
0634: private void initTable(Layer layer) {
0635: table.setModel(new DeeColorThemingTableModel(
0636: DeeColorThemingStyle.get(layer).getDefaultStyle(),
0637: DeeColorThemingStyle.get(layer).getAttributeName(),
0638: attributeValueToBasicStyleMap(layer),
0639: attributeValueToLabelMap(layer),
0640: attributeValueToVertexStyleMap(layer), layer
0641: .getFeatureCollectionWrapper()
0642: .getFeatureSchema()) {
0643: public Object getValueAt(int rowIndex, int columnIndex) {
0644: //Don't use #attributeColumn() here because this is in the *model*,
0645: //not the view. Otherwise, an exception will be thrown when
0646: //the user tries to move the columns. [Jon Aquino]
0647: if ((rowIndex == 0)
0648: && (columnIndex == DeeColorThemingTableModel.ATTRIBUTE_COLUMN)) {
0649: return state.getAllOtherValuesDescription();
0650: }
0651: if ((rowIndex == 0)
0652: && (columnIndex == DeeColorThemingTableModel.LABEL_COLUMN)) {
0653: return "";
0654: }
0655: return super .getValueAt(rowIndex, columnIndex);
0656: }
0657: });
0658: table.createDefaultColumnsFromModel();
0659: table.setRowSelectionAllowed(true);
0660: table.getSelectionModel().addListSelectionListener(
0661: new ListSelectionListener() {
0662: public void valueChanged(ListSelectionEvent e) {
0663: updateComponents();
0664: }
0665: });
0666: table.getTableHeader().addMouseListener(new MouseAdapter() {
0667: public void mousePressed(MouseEvent e) {
0668: if (SwingUtilities.isLeftMouseButton(e)
0669: && (e.getClickCount() == 1)
0670: && table.isEnabled()) {
0671: tableModel().sort();
0672: }
0673: }
0674: });
0675: table.getColumnModel().getColumn(colorColumn())
0676: .setCellRenderer(new TableCellRenderer() {
0677: public Component getTableCellRendererComponent(
0678: JTable table, Object value,
0679: boolean isSelected, boolean hasFocus,
0680: int row, int column) {
0681:
0682: JComponent renderer = (JComponent) basicStyleListCellRenderer
0683: .getListCellRendererComponent(
0684: new JList(), value, row,
0685: isSelected, hasFocus);
0686:
0687: if (!isSelected) {
0688: updateBackground(renderer);
0689: }
0690:
0691: return renderer;
0692: }
0693: });
0694: table.getColumnModel().getColumn(colorColumn()).setCellEditor(
0695: basicStyleTableCellEditor);
0696: table.getModel().addTableModelListener(
0697: new TableModelListener() {
0698: public void tableChanged(TableModelEvent e) {
0699: updateComponents();
0700:
0701: Object duplicateAttributeValue = tableModel()
0702: .findDuplicateAttributeValue();
0703: setErrorMessage(
0704: new ErrorMessage(
0705: I18N
0706: .get("ui.renderer.style.ColorThemingPanel.table-must-not-have-duplicate-attribute-values"),
0707: "(" + duplicateAttributeValue
0708: + ")"),
0709: duplicateAttributeValue != null);
0710: setErrorMessage(
0711: new ErrorMessage(
0712: I18N
0713: .get("ui.renderer.style.ColorThemingPanel.table-must-not-have-null-attribute-values")),
0714: tableModel()
0715: .containsNullAttributeValues());
0716: }
0717: });
0718:
0719: int colorWidth = 10 + (int) basicStyleListCellRenderer
0720: .getListCellRendererComponent(new JList(),
0721: new BasicStyle(), 0, false, false)
0722: .getPreferredSize().getWidth();
0723: table.getColumnModel().getColumn(colorColumn())
0724: .setPreferredWidth(colorWidth);
0725: table.getColumnModel().getColumn(colorColumn()).setMinWidth(
0726: colorWidth);
0727: table.getColumnModel().getColumn(colorColumn()).setMaxWidth(
0728: colorWidth);
0729: }
0730:
0731: /**
0732: * @param layer2
0733: * @return
0734: */
0735: protected Map attributeValueToVertexStyleMap(Layer layer2) {
0736: if (!colorThemingAttributeValid(layer)) {
0737: return new TreeMap();
0738: }
0739: return state.fromExternalFormat(DeeColorThemingStyle.get(layer)
0740: .getAttributeValueToVertexStyleMap());
0741: }
0742:
0743: private Map attributeValueToBasicStyleMap(Layer layer) {
0744: if (!colorThemingAttributeValid(layer)) {
0745: return new TreeMap();
0746: }
0747: return state.fromExternalFormat(DeeColorThemingStyle.get(layer)
0748: .getAttributeValueToBasicStyleMap());
0749: }
0750:
0751: private Map attributeValueToLabelMap(Layer layer) {
0752: if (!colorThemingAttributeValid(layer)) {
0753: return new TreeMap();
0754: }
0755: return state.fromExternalFormat(DeeColorThemingStyle.get(layer)
0756: .getAttributeValueToLabelMap());
0757: }
0758:
0759: private boolean colorThemingAttributeValid(Layer layer) {
0760: if (DeeColorThemingStyle.get(layer).getAttributeName() == null) {
0761: return false;
0762: }
0763: //Schema won't have attribute name if user has deleted the attribute.
0764: //[Jon Aquino]
0765: if (!layer.getFeatureCollectionWrapper().getFeatureSchema()
0766: .hasAttribute(
0767: DeeColorThemingStyle.get(layer)
0768: .getAttributeName())) {
0769: return false;
0770: }
0771: return true;
0772: }
0773:
0774: private void initColorSchemeComboBox(LayerManager layerManager) {
0775: colorSchemeComboBox
0776: .setRenderer(new ColorSchemeListCellRenderer() {
0777: protected void color(ColorPanel colorPanel,
0778: Color fillColor, Color lineColor) {
0779: super .color(colorPanel, GUIUtil.alphaColor(
0780: fillColor, getAlpha()), GUIUtil
0781: .alphaColor(lineColor, getAlpha()));
0782: }
0783:
0784: protected ColorScheme colorScheme(String name) {
0785: return state.filterColorScheme(super
0786: .colorScheme(name));
0787: }
0788: });
0789: }
0790:
0791: private int getAlpha() {
0792: return transparencySlider.getMaximum()
0793: - transparencySlider.getValue();
0794: }
0795:
0796: private void initAttributeNameComboBox(Layer layer) {
0797: DefaultComboBoxModel model = new DefaultComboBoxModel();
0798:
0799: for (int i = 0; i < layer.getFeatureCollectionWrapper()
0800: .getFeatureSchema().getAttributeCount(); i++) {
0801: if (i == layer.getFeatureCollectionWrapper()
0802: .getFeatureSchema().getGeometryIndex()) {
0803: continue;
0804: }
0805:
0806: model.addElement(layer.getFeatureCollectionWrapper()
0807: .getFeatureSchema().getAttributeName(i));
0808: }
0809:
0810: attributeNameComboBox.setModel(model);
0811:
0812: if (model.getSize() == 0) {
0813: //Can get here if the only attribute is the geometry. [Jon Aquino]
0814: return;
0815: }
0816:
0817: attributeNameComboBox.setSelectedItem(DeeColorThemingStyle.get(
0818: layer).getAttributeName());
0819: }
0820:
0821: private void jbInit() throws Exception {
0822: this .setLayout(gridBagLayout1);
0823: jPanel1.setLayout(gridBagLayout2);
0824: jPanel3.setLayout(gridBagLayout4);
0825: attributeLabel.setText(I18N
0826: .get("ui.renderer.style.ColorThemingPanel.attribute")
0827: + " ");
0828: statusLabel.setBorder(BorderFactory.createLoweredBevelBorder());
0829: statusLabel.setText(" ");
0830: jPanel4.setLayout(gridBagLayout5);
0831: colorSchemeLabel
0832: .setText(I18N
0833: .get("ui.renderer.style.ColorThemingPanel.colour-scheme")
0834: + " ");
0835: attributeNameComboBox
0836: .addActionListener(new java.awt.event.ActionListener() {
0837: public void actionPerformed(ActionEvent e) {
0838: attributeNameComboBox_actionPerformed(e);
0839: }
0840: });
0841: colorSchemeComboBox
0842: .addActionListener(new java.awt.event.ActionListener() {
0843: public void actionPerformed(ActionEvent e) {
0844: colorSchemeComboBox_actionPerformed(e);
0845: }
0846: });
0847: jPanel5.setLayout(gridBagLayout3);
0848: enableColorThemingCheckBox
0849: .addActionListener(new java.awt.event.ActionListener() {
0850: public void actionPerformed(ActionEvent e) {
0851: enableColorThemingCheckBox_actionPerformed(e);
0852: }
0853: });
0854: enableColorThemingCheckBox
0855: .setText(I18N
0856: .get("ui.renderer.style.ColorThemingPanel.enable-colour-theming"));
0857: byRangeCheckBox.setText(I18N
0858: .get("ui.renderer.style.ColorThemingPanel.by-range"));
0859: byRangeCheckBox
0860: .addActionListener(new java.awt.event.ActionListener() {
0861: public void actionPerformed(ActionEvent e) {
0862: byRangeCheckBox_actionPerformed(e);
0863: }
0864: });
0865: transparencySlider.setMaximum(255);
0866: transparencySlider.setPreferredSize(new Dimension(75, 24));
0867:
0868: //Don't get squished by overlong status messages. [Jon Aquino]
0869: transparencySlider.setMinimumSize(new Dimension(75, 24));
0870: transparencySlider
0871: .setToolTipText(I18N
0872: .get("ui.renderer.style.ColorThemingPanel.transparency"));
0873: transparencySlider
0874: .addChangeListener(new javax.swing.event.ChangeListener() {
0875: public void stateChanged(ChangeEvent e) {
0876: transparencySlider_stateChanged(e);
0877: }
0878: });
0879: this .add(jPanel1, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0,
0880: GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
0881: new Insets(0, 0, 0, 0), 0, 0));
0882: jPanel1.add(attributeNameComboBox, new GridBagConstraints(1, 0,
0883: 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
0884: GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
0885: jPanel1.add(attributeLabel, new GridBagConstraints(0, 0, 1, 1,
0886: 0.0, 0.0, GridBagConstraints.CENTER,
0887: GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
0888: jPanel1.add(fillerPanel, new GridBagConstraints(4, 0, 1, 1, 1,
0889: 0.0, GridBagConstraints.CENTER,
0890: GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2),
0891: 0, 0));
0892: this .add(scrollPane, new GridBagConstraints(0, 4, 1, 1, 1.0,
0893: 1.0, GridBagConstraints.CENTER,
0894: GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0));
0895: this .add(jPanel3, new GridBagConstraints(0, 5, 1, 1, 1.0, 0.0,
0896: GridBagConstraints.CENTER,
0897: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
0898: 0, 0));
0899: jPanel3.add(statusLabel, new GridBagConstraints(1, 0, 1, 1,
0900: 1.0, 0.0, GridBagConstraints.CENTER,
0901: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
0902: 0, 0));
0903: jPanel3.add(toolBar, new GridBagConstraints(2, 0, 1, 1, 0.0,
0904: 0.0, GridBagConstraints.CENTER,
0905: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
0906: jPanel3.add(transparencySlider, new GridBagConstraints(3, 0, 1,
0907: 1, 0.0, 0.0, GridBagConstraints.CENTER,
0908: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
0909: this .add(jPanel4, new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0,
0910: GridBagConstraints.CENTER,
0911: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
0912: 0, 0));
0913: jPanel4.add(colorSchemeComboBox, new GridBagConstraints(1, 0,
0914: 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
0915: GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2),
0916: 0, 0));
0917: jPanel4.add(colorSchemeLabel, new GridBagConstraints(0, 0, 1,
0918: 1, 0.0, 0.0, GridBagConstraints.CENTER,
0919: GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
0920: this .add(jPanel5, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
0921: GridBagConstraints.WEST, GridBagConstraints.NONE,
0922: new Insets(0, 0, 0, 0), 0, 0));
0923: jPanel5.add(enableColorThemingCheckBox, new GridBagConstraints(
0924: 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
0925: GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
0926: jPanel5.add(byRangeCheckBox, new GridBagConstraints(1, 0, 1, 1,
0927: 0.0, 0.0, GridBagConstraints.CENTER,
0928: GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
0929: scrollPane.getViewport().add(table);
0930: }
0931:
0932: protected void enableColorThemingCheckBox_actionPerformed(
0933: ActionEvent e) {
0934: if (table.getRowCount() == 1) {
0935: //1 == just the "All other values" row. [Jon Aquino]
0936: populateTable();
0937: }
0938:
0939: updateComponents();
0940: }
0941:
0942: void attributeNameComboBox_actionPerformed(ActionEvent e) {
0943: try {
0944: if (initializing) {
0945: return;
0946: }
0947:
0948: if (attributeNameComboBox.getItemCount() == 0) {
0949: return;
0950: }
0951: Object selectedItem = attributeNameComboBox
0952: .getSelectedItem();
0953: if (selectedItem != null
0954: && selectedItem.equals(lastAttributeName)) {
0955: //Don't want to clear the table if the attribute hasn't changed. [Jon Aquino]
0956: return;
0957: }
0958:
0959: stopCellEditing();
0960: populateTable();
0961: } finally {
0962: //Want to set lastAttributeName even during initialization. Otherwise, the following
0963: //undesirable behaviour occurs: Open dialog box; press Get All Values
0964: // -- the table is populated; edit the table; click on attribute combo box but click
0965: //on the same attribute -- the table is repopulated! [Jon Aquino]
0966: lastAttributeName = getAttributeName();
0967:
0968: if (table.getModel() instanceof DeeColorThemingTableModel) {
0969: //Model will be DefaultTableModel during early initialization. [Jon Aquino]
0970: tableModel().setAttributeName(getAttributeName());
0971: }
0972: }
0973: }
0974:
0975: public DeeColorThemingTableModel tableModel() {
0976: return (DeeColorThemingTableModel) table.getModel();
0977: }
0978:
0979: private SortedSet getNonNullAttributeValues() {
0980: TreeSet values = new TreeSet();
0981:
0982: for (Iterator i = layer.getFeatureCollectionWrapper()
0983: .getFeatures().iterator(); i.hasNext();) {
0984: Feature feature = (Feature) i.next();
0985:
0986: if (feature.getAttribute(getAttributeName()) != null) {
0987: values.add(DeeColorThemingStyle.trimIfString(feature
0988: .getAttribute(getAttributeName())));
0989: }
0990: }
0991:
0992: return values;
0993: }
0994:
0995: public void populateTable() {
0996: if (!(enableColorThemingCheckBox.isSelected() && (attributeNameComboBox
0997: .getItemCount() > 0))) {
0998: return;
0999: }
1000: stopCellEditing();
1001: tableModel().clear();
1002: tableModel()
1003: .setMaps(
1004: toAttributeValueToBasicStyleMap(filteredAttributeValues()),
1005: toAttributeValueToLabelMap(filteredAttributeValues()),
1006: toAttributeValueToVertexStyleMap(filteredAttributeValues()));
1007: tableModel().sort(tableModel().wasLastSortAscending());
1008: applyColorScheme();
1009: }
1010:
1011: /**
1012: * @param collection
1013: * @return
1014: */
1015: protected Map toAttributeValueToVertexStyleMap(
1016: Collection attributeValues) {
1017: Map attributeValueToVertexStyleMap = new TreeMap();
1018:
1019: // FIXME need here to get vertex style from layer???
1020: //ColorThemingStyle style = (ColorThemingStyle)layer.getStyle( ColorThemingStyle.class );
1021:
1022: for (Iterator i = attributeValues.iterator(); i.hasNext();) {
1023: Object attributeValue = i.next();
1024:
1025: attributeValueToVertexStyleMap.put(attributeValue,
1026: new SquareVertexStyle());
1027: }
1028: return attributeValueToVertexStyleMap;
1029: }
1030:
1031: private Collection filteredAttributeValues() {
1032: return state.filterAttributeValues(getNonNullAttributeValues());
1033: }
1034:
1035: private Map toAttributeValueToLabelMap(Collection attributeValues) {
1036: Map attributeValueToAttributeValueMap = new TreeMap();
1037: for (Iterator i = attributeValues.iterator(); i.hasNext();) {
1038: Object attributeValue = i.next();
1039: attributeValueToAttributeValueMap.put(attributeValue,
1040: attributeValue);
1041: }
1042: Map attributeValueToLabelMap = CollectionUtil.inverse(state
1043: .toExternalFormat(attributeValueToAttributeValueMap));
1044: for (Iterator i = attributeValueToLabelMap.keySet().iterator(); i
1045: .hasNext();) {
1046: Object attributeValue = i.next();
1047: attributeValueToLabelMap.put(attributeValue,
1048: attributeValueToLabelMap.get(attributeValue)
1049: .toString());
1050: }
1051: return attributeValueToLabelMap;
1052: }
1053:
1054: private Map toAttributeValueToBasicStyleMap(
1055: Collection attributeValues) {
1056: Map attributeValueToBasicStyleMap = new TreeMap();
1057: for (Iterator i = attributeValues.iterator(); i.hasNext();) {
1058: Object attributeValue = i.next();
1059: attributeValueToBasicStyleMap.put(attributeValue,
1060: new BasicStyle());
1061: }
1062: return attributeValueToBasicStyleMap;
1063: }
1064:
1065: void colorSchemeComboBox_actionPerformed(ActionEvent e) {
1066: if (initializing) {
1067: return;
1068: }
1069:
1070: stopCellEditing();
1071: layer.getLayerManager().getBlackboard().put(COLOR_SCHEME_KEY,
1072: colorSchemeComboBox.getSelectedItem());
1073: applyColorScheme();
1074: colorSchemeForInserts = null;
1075: }
1076:
1077: private ColorScheme getColorSchemeForInserts() {
1078: //Cache the colour-scheme; otherwise the first color will always
1079: //be used for inserts. [Jon Aquino]
1080: if ((colorSchemeForInserts == null)
1081: || !colorSchemeForInserts.getName().equalsIgnoreCase(
1082: (String) colorSchemeComboBox.getSelectedItem())) {
1083: colorSchemeForInserts = ColorScheme
1084: .create((String) colorSchemeComboBox
1085: .getSelectedItem());
1086: }
1087:
1088: return colorSchemeForInserts;
1089: }
1090:
1091: public void applyColorScheme() {
1092: stopCellEditing();
1093: state.applyColorScheme(state
1094: .filterColorScheme(ColorScheme
1095: .create((String) colorSchemeComboBox
1096: .getSelectedItem())));
1097: }
1098:
1099: private void cancelCellEditing() {
1100: if (table.getCellEditor() instanceof DefaultCellEditor) {
1101: ((DefaultCellEditor) table.getCellEditor())
1102: .cancelCellEditing();
1103: }
1104: }
1105:
1106: public String validateInput() {
1107: stopCellEditing();
1108:
1109: //Split into #validateInput and #internalValidateInput to avoid
1110: //infinite recursion (#stopCellEditing causes #fireTableChanged
1111: //which causes #validateInput which causes #stopCellEditing...)
1112: //[Jon Aquino]
1113: return internalValidateInput();
1114: }
1115:
1116: private String internalValidateInput() {
1117: if (!enableColorThemingCheckBox.isSelected()) {
1118: return null;
1119: }
1120:
1121: if (errorMessages.isEmpty()) {
1122: return null;
1123: }
1124:
1125: return errorMessages.iterator().next().toString();
1126: }
1127:
1128: /**
1129: * @return enabled
1130: */
1131: private boolean setErrorMessage(ErrorMessage message,
1132: boolean enabled) {
1133: //Always remove the original, because #add doesn't replace, but is
1134: //ignored if the message already exists. Need to replace because the
1135: //"specific part" of the error message may be new. [Jon Aquino]
1136: errorMessages.remove(message);
1137:
1138: if (enabled) {
1139: errorMessages.add(message);
1140: }
1141:
1142: updateErrorDisplay();
1143:
1144: return enabled;
1145: }
1146:
1147: private void updateErrorDisplay() {
1148: String errorMessage = internalValidateInput();
1149:
1150: if (errorMessage != null) {
1151: statusLabel.setText(errorMessage);
1152: statusLabel.setIcon(GUIUtil.toSmallIcon(IconLoader
1153: .icon("Delete.gif")));
1154: } else {
1155: statusLabel.setText(" ");
1156: statusLabel.setIcon(null);
1157: }
1158: }
1159:
1160: private void setState(State state) {
1161: this .state.deactivate();
1162: jPanel1.remove(this .state.getPanel());
1163:
1164: //Need to call #revalidate; otherwise, the component won't get
1165: //removed. [Jon Aquino]
1166: this .state = state;
1167: jPanel1.add(state.getPanel(), new GridBagConstraints(3, 0, 1,
1168: 1, 0.0, 0.0, GridBagConstraints.CENTER,
1169: GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
1170: initializing = true;
1171:
1172: try {
1173: colorSchemeComboBox.setModel(new DefaultComboBoxModel(
1174: new Vector(state.getColorSchemeNames())));
1175:
1176: //The colour scheme may not be present if it was taken from the
1177: //set of discrete colour schemes but the combo box currently contains
1178: //the range colour schemes. [Jon Aquino]
1179: colorSchemeComboBox.setSelectedItem(layer.getLayerManager()
1180: .getBlackboard().get(COLOR_SCHEME_KEY,
1181: colorSchemeComboBox.getItemAt(0)));
1182: } finally {
1183: initializing = false;
1184: }
1185:
1186: updateComponents();
1187: this .state.activate();
1188: jPanel1.repaint();
1189: }
1190:
1191: void byRangeCheckBox_actionPerformed(ActionEvent e) {
1192: setState(byRangeCheckBox.isSelected() ? (ColorThemingStylePanel.State) rangeColorThemingState
1193: : discreteColorThemingState);
1194: populateTable();
1195: }
1196:
1197: void transparencySlider_stateChanged(ChangeEvent e) {
1198: repaint();
1199: }
1200:
1201: public JSlider getTransparencySlider() {
1202: return transparencySlider;
1203: }
1204:
1205: public JTable getTable() {
1206: return table;
1207: }
1208:
1209: private abstract class MyPlugIn extends AbstractPlugIn {
1210: public abstract Icon getIcon();
1211: }
1212:
1213: private class ErrorMessage {
1214: private String commonPart;
1215: private String specificPart;
1216:
1217: public ErrorMessage(String commonPart) {
1218: this (commonPart, "");
1219: }
1220:
1221: public ErrorMessage(String commonPart, String specificPart) {
1222: this .commonPart = commonPart;
1223: this .specificPart = specificPart;
1224: }
1225:
1226: public int hashCode() {
1227: return commonPart.hashCode();
1228: }
1229:
1230: public boolean equals(Object obj) {
1231: return commonPart.equals(((ErrorMessage) obj).commonPart);
1232: }
1233:
1234: public String toString() {
1235: return commonPart + specificPart;
1236: }
1237: }
1238: }
|