Index: Thuban/UI/classifier.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/classifier.py,v
retrieving revision 1.69
diff -u -r1.69 classifier.py
--- Thuban/UI/classifier.py	7 Oct 2004 14:43:45 -0000	1.69
+++ Thuban/UI/classifier.py	24 Jan 2005 22:54:38 -0000
@@ -35,13 +35,13 @@
 
 from Thuban.Model.color import Transparent
 
-from Thuban.Model.layer import Layer, RasterLayer
+from Thuban.Model.layer import Layer
 from Thuban.Model.data import SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT
 
 from Thuban.UI.classgen import ClassGenDialog
 from Thuban.UI.colordialog import ColorDialog
 
-from dialogs import NonModalNonParentDialog
+from Thuban.UI.layerproperties import LayerProperties
 from messages import MAP_REPLACED
 
 ID_CLASS_TABLE = 40011
@@ -684,7 +684,7 @@
 EB_SELECT_FIELD = 1
 EB_GEN_CLASS = 2
 
-class Classifier(NonModalNonParentDialog):
+class Classifier(LayerProperties):
 
     type2string = {None:             _("None"),
                    FIELDTYPE_STRING: _("Text"),
@@ -697,36 +697,28 @@
         group in the classification table.
         """
 
-        NonModalNonParentDialog.__init__(self, parent, name, "")
+        LayerProperties.__init__(self, parent, name, layer)
 
-        self.__SetTitle(layer.Title())
-
-        self.parent.Subscribe(MAP_REPLACED, self.map_replaced)
-        self.layer = layer
-        self.map = parent.Map()
-
-        self.map.Subscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)
         self.layer.Subscribe(LAYER_SHAPESTORE_REPLACED,
                              self.layer_shapestore_replaced)
 
         self.genDlg = None
+        self.group = group
 
-        ############################
-        # Create the controls
-        #
+        LayerProperties.dialog_layout(self)
 
-        panel = wxPanel(self, -1)
+    def dialog_layout(self, panel, panelBox):
 
-        text_title = wxTextCtrl(panel, ID_PROPERTY_TITLE, layer.Title())
-        self.fieldTypeText = wxStaticText(panel, -1, "")
+        if self.layer.HasClassification():
+
+            self.fieldTypeText = wxStaticText(panel, -1, "")
 
-        if layer.HasClassification():
             self.originalClass = self.layer.GetClassification()
             self.originalClassField = self.layer.GetClassificationColumn()
             field = self.originalClassField
             fieldType = self.layer.GetFieldType(field)
 
-            table = layer.ShapeStore().Table()
+            table = self.layer.ShapeStore().Table()
             #
             # make field choice box
             #
@@ -773,37 +765,8 @@
             # calling __SelectField after creating the classGrid fills in the
             # grid with the correct information
             self.fields.SetSelection(self.__cur_field)
-            self.__SelectField(self.__cur_field, group = group)
-
-        button_try = wxButton(self, ID_PROPERTY_TRY, _("Try"))
-        button_revert = wxButton(self, ID_PROPERTY_REVERT, _("Revert"))
-        button_ok = wxButton(self, wxID_OK, _("OK"))
-        button_close = wxButton(self, wxID_CANCEL, _("Close"))
-        button_ok.SetDefault()
-
-        ############################
-        # Layout the controls
-        #
-
-        topBox = wxBoxSizer(wxVERTICAL)
-        panelBox = wxBoxSizer(wxVERTICAL)
-
-        sizer = wxBoxSizer(wxHORIZONTAL)
-        sizer.Add(wxStaticText(panel, -1, _("Title: ")),
-            0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 4)
-        sizer.Add(text_title, 1, wxGROW, 0)
-
-        panelBox.Add(sizer, 0, wxGROW, 4)
-
-        if isinstance(layer, RasterLayer):
-            type = "Image"
-        else:
-            type = layer.ShapeType()
-
-        panelBox.Add(wxStaticText(panel, -1, _("Type: %s") % type),
-            0, wxALIGN_LEFT | wxALL, 4) 
+            self.__SelectField(self.__cur_field, group = self.group)
 
-        if layer.HasClassification():
 
             classBox = wxStaticBoxSizer(
                         wxStaticBox(panel, -1, _("Classification")), wxVERTICAL)
@@ -838,35 +801,7 @@
             panelBox.Add(classBox, 1, wxGROW, 0)
 
 
-        buttonBox = wxBoxSizer(wxHORIZONTAL)
-        buttonBox.Add(button_try, 0, wxRIGHT|wxEXPAND, 10)
-        buttonBox.Add(button_revert, 0, wxRIGHT|wxEXPAND, 10)
-        buttonBox.Add(button_ok, 0, wxRIGHT|wxEXPAND, 10)
-        buttonBox.Add(button_close, 0, wxRIGHT|wxEXPAND, 10)
-
-        panel.SetAutoLayout(True)
-        panel.SetSizer(panelBox)
-        panelBox.Fit(panel) 
-        panelBox.SetSizeHints(panel) 
-
-        topBox.Add(panel, 1, wxGROW | wxALL, 4)
-        topBox.Add(buttonBox, 0, wxALIGN_RIGHT|wxBOTTOM|wxTOP, 10)
-
-        self.SetAutoLayout(True)
-        self.SetSizer(topBox)
-        topBox.Fit(self)
-        topBox.SetSizeHints(self)
-        self.Layout()
-
-        ###########
-
         EVT_CHOICE(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
-        EVT_TEXT(self, ID_PROPERTY_TITLE, self._OnTitleChanged)
-        EVT_BUTTON(self, wxID_OK, self._OnOK)
-        EVT_BUTTON(self, ID_PROPERTY_TRY, self._OnTry)
-        EVT_BUTTON(self, wxID_CANCEL, self._OnCloseBtn)
-        EVT_BUTTON(self, ID_PROPERTY_REVERT, self._OnRevert)
-
         EVT_BUTTON(self, ID_PROPERTY_ADD, self._OnAdd)
         EVT_BUTTON(self, ID_PROPERTY_EDITSYM, self._OnEditSymbol)
         EVT_BUTTON(self, ID_PROPERTY_REMOVE, self._OnRemove)
@@ -874,36 +809,18 @@
         EVT_BUTTON(self, ID_PROPERTY_MOVEUP, self._OnMoveUp)
         EVT_BUTTON(self, ID_PROPERTY_MOVEDOWN, self._OnMoveDown)
 
-        ######################
-
-        text_title.SetFocus()
-        self.haveApplied = False
-
     def unsubscribe_messages(self):
         """Unsubscribe from all messages."""
-        self.parent.Unsubscribe(MAP_REPLACED, self.map_replaced)
-        self.map.Unsubscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)
+        LayerProperties.unsubscribe_messages(self)
         self.layer.Unsubscribe(LAYER_SHAPESTORE_REPLACED,
                                self.layer_shapestore_replaced)
 
-    def map_layers_removed(self, map):
-        """Subscribed to MAP_LAYERS_REMOVED. If this layer was removed,
-        Close self.
-        """
-        if self.layer not in self.map.Layers():
-            self.Close()
-
     def layer_shapestore_replaced(self, *args):
         """Subscribed to the map's LAYER_SHAPESTORE_REPLACED message.
-
         Close self.
         """
         self.Close()
 
-    def map_replaced(self, *args):
-        """Subscribed to the mainwindow's MAP_REPLACED message. Close self."""
-        self.Close()
-
     def EditSymbol(self, row):
         """Open up a dialog where the user can select the properties 
         for a group.
@@ -1025,7 +942,7 @@
         self.__SelectField(index, self.__cur_field)
         self.__cur_field = index
 
-    def _OnTry(self, event):
+    def OnTry(self, event):
         """Put the data from the table into a new Classification and hand
            it to the layer.
         """
@@ -1045,25 +962,13 @@
 
         self.haveApplied = True
 
-    def _OnOK(self, event):
-        self._OnTry(event)
-        self.Close()
-
-    def OnClose(self, event):
-        self.unsubscribe_messages()
-        NonModalNonParentDialog.OnClose(self, event)
-
-    def _OnCloseBtn(self, event):
-        """Close is similar to Cancel except that any changes that were
-        made and applied remain applied, but the currently displayed
-        classification is discarded.
-        """
-
+    def OnOK(self, event):
+        self.OnTry(event)
         self.Close()
 
-    def _OnRevert(self, event):
+    def OnRevert(self, event):
         """The layer's current classification stays the same."""
-        if self.haveApplied:
+        if self.haveApplied and self.layer.HasClassification():
             self.layer.SetClassificationColumn(self.originalClassField)
             self.layer.SetClassification(self.originalClass)
 
@@ -1575,6 +1480,3 @@
     def _OnLeftDClick(self, event):
         self.DoEdit()
 
-from Thuban.UI.mainwindow import layer_properties_dialogs
-layer_properties_dialogs.add(Layer, Classifier)
-layer_properties_dialogs.add(RasterLayer, Classifier)
