Revision 36443 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/project/documents/gui/ProjectWindow.java

View differences:

ProjectWindow.java
33 33
import java.util.ArrayList;
34 34
import java.util.Collections;
35 35
import java.util.Comparator;
36
import java.util.Enumeration;
36 37
import java.util.List;
37 38

  
39
import javax.swing.AbstractButton;
38 40
import javax.swing.ButtonGroup;
39 41
import javax.swing.JDialog;
40 42
import javax.swing.JLabel;
......
58 60
import org.gvsig.app.project.documents.Document;
59 61
import org.gvsig.app.project.documents.DocumentManager;
60 62
import org.gvsig.gui.beans.swing.JButton;
63
import org.gvsig.tools.observer.Observable;
64
import org.gvsig.tools.observer.Observer;
61 65
import org.gvsig.utils.DefaultListModel;
62 66

  
63 67
/**
......
67 71
 * @author Vicente Caballero Navarro
68 72
 */
69 73
public class ProjectWindow extends JPanel implements PropertyChangeListener,
70
    IWindow, SingletonWindow {
74
    IWindow, SingletonWindow, Observer {
71 75

  
72 76
    /**
73 77
	 * 
......
117 121
        initialize();
118 122
        refreshControls();
119 123
        Help.getHelp().enableHelp(this, this.getClass().getName());
124
        // Observe document factory registration changes
125
        ProjectManager.getInstance().addObserver(this);
120 126
    }
121 127

  
122 128
    /**
......
269 275
        this.setPreferredSize(new java.awt.Dimension(430, 554));
270 276
        this.setMinimumSize(new java.awt.Dimension(430, 554));
271 277
        this.add(getJScrollPane1(), gridBagConstraints);
272
        for (int i = 0; i < btnsDocuments.length; i++) {
273
            grupo.add(btnsDocuments[i]);
274
        }
275
        if (btnsDocuments.length > 0) {
276
            btnsDocuments[0].setSelected(true);
277
        }
278
        refreshDocuments();
278 279
    }
279 280

  
280 281
    private Document createDocumentInProject(String doctype) {
......
470 471
            java.awt.FlowLayout layFlowLayout1 = new java.awt.FlowLayout();
471 472
            layFlowLayout1.setHgap(15);
472 473
            jPanel.setLayout(layFlowLayout1);
473
            JRadioButton[] btns = getBtnDocuments();
474
            for (int i = 0; i < btns.length; i++) {
475
                jPanel.add(btns[i], null);
476
            }
474
            fillDocumentTypeButtons();
477 475
            jPanel.setName("tipoDocPanel");
478 476
            // jPanel.setPreferredSize(new java.awt.Dimension(700, 200));
479 477
            jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
......
486 484
    }
487 485

  
488 486
    /**
487
     * Adds a button for each document type
488
     */
489
    private void fillDocumentTypeButtons() {
490
        JRadioButton[] btns = getBtnDocuments();
491
        for (int i = 0; i < btns.length; i++) {
492
            jPanel.add(btns[i], null);
493
        }
494
    }
495

  
496
    /**
489 497
     * This method initializes btnVistas
490 498
     * 
491 499
     * @return JRadioButton
......
495 503

  
496 504
            List<JRadioButton> btns = new ArrayList<JRadioButton>();
497 505
            List<DocumentManager> factories =
498
                ProjectManager.getInstance().getDocumentManager();
506
                ProjectManager.getInstance().getDocumentManagers();
499 507
            Collections.sort(factories, new Comparator<DocumentManager>() {
500 508

  
501 509
                public int compare(DocumentManager arg0, DocumentManager arg1) {
......
1060 1068
        return m_viewInfo;
1061 1069
    }
1062 1070

  
1063
    /**
1064
     * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
1065
     */
1066 1071
    public void propertyChange(PropertyChangeEvent evt) {
1067 1072
        refreshControls();
1068 1073
    }
1069 1074

  
1070
    // /**
1071
    // * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
1072
    // */
1073
    // public void viewActivated() {
1074
    // // do nothing
1075
    // }
1076

  
1077 1075
    /**
1078 1076
     * This method initializes jPanel4
1079 1077
     * 
......
1115 1113
        return WindowInfo.PROJECT_PROFILE;
1116 1114
    }
1117 1115

  
1116
    public void update(Observable observable, Object notification) {
1117
        if (observable instanceof ProjectManager) {
1118
            refreshDocuments();
1119
        }
1120
    }
1121

  
1122
    private void refreshDocuments() {
1123
        // Setting it to null will make it recreate in the next
1124
        // getBtnDocuments() call
1125
        this.btnsDocuments = null;
1126

  
1127
        // Clear previous document type buttons
1128
        jPanel.removeAll();
1129
        for (Enumeration<AbstractButton> buttons = grupo.getElements(); buttons
1130
            .hasMoreElements();) {
1131
            grupo.remove(buttons.nextElement());
1132
        }
1133

  
1134
        JRadioButton[] btnDocuments = getBtnDocuments();
1135
        for (int i = 0; i < btnDocuments.length; i++) {
1136
            grupo.add(btnDocuments[i]);
1137
        }
1138
        if (btnDocuments.length > 0) {
1139
            btnDocuments[0].setSelected(true);
1140
        }
1141
        fillDocumentTypeButtons();
1142
    }
1143

  
1118 1144
}

Also available in: Unified diff