Revision 250 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/gui/dialogs/FFrameViewDialog.java

View differences:

FFrameViewDialog.java
29 29
import java.awt.event.ActionListener;
30 30
import java.awt.geom.Rectangle2D;
31 31

  
32
import javax.swing.BorderFactory;
33
import javax.swing.ButtonGroup;
32 34
import javax.swing.JButton;
33 35
import javax.swing.JCheckBox;
36
import javax.swing.JLabel;
34 37
import javax.swing.JList;
35 38
import javax.swing.JOptionPane;
36 39
import javax.swing.JPanel;
40
import javax.swing.JRadioButton;
41
import javax.swing.JTextField;
37 42

  
38 43
import org.gvsig.andami.messages.NotificationManager;
44
import org.gvsig.andami.ui.mdiManager.IWindow;
45
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
39 46
import org.gvsig.andami.ui.mdiManager.WindowInfo;
40 47
import org.gvsig.app.ApplicationLocator;
48
import org.gvsig.app.ApplicationManager;
41 49
import org.gvsig.app.project.ProjectManager;
42 50
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
43 51
import org.gvsig.app.project.documents.layout.LayoutManager;
44 52
import org.gvsig.app.project.documents.layout.fframes.FFrameGrid;
45 53
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
46 54
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
55
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap.SCALE_TYPE;
47 56
import org.gvsig.app.project.documents.layout.fframes.ListViewModel;
57
import org.gvsig.app.project.documents.layout.fframes.gui.EnvelopePanel;
48 58
import org.gvsig.app.project.documents.layout.fframes.gui.JPRotation;
49 59
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
50 60
import org.gvsig.app.project.documents.view.DefaultViewDocument;
61
import org.gvsig.app.project.documents.view.ViewDocument;
62
import org.gvsig.fmap.geom.primitive.Envelope;
51 63
import org.gvsig.fmap.mapcontext.ViewPort;
64
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
52 65
import org.gvsig.i18n.Messages;
66
import org.gvsig.tools.observer.Observer;
67
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
53 68

  
54 69
/**
55 70
 * Dialog to add a view to the Layout document, by means of a FFrameView
......
58 73
 * @author Cesar Martinez Izquierdo
59 74
 */
60 75
public class FFrameViewDialog extends AbstractFFrameDialog implements
61
    IFFrameDialog {
76
    IFFrameDialog, SingletonWindow {
62 77

  
63 78
    private static final long serialVersionUID = -7223804566537544559L;
64 79
    
......
74 89
    private javax.swing.JComboBox cbCalidad = null;
75 90
    private DefaultViewDocument m_projectView = null;
76 91
    private Rectangle2D rect = new Rectangle2D.Double();
77
    private FFrameView fframeview = null; // new FFrameView();
92
    private FFrameView fframeview = null;
78 93
    private boolean isAcepted = false;
79 94
    private JPRotation rotation = null;
80 95
    private FFrameView newFFrameView = null;
......
85 100
	
86 101
	private WindowInfo windowInfo = null;
87 102

  
103
	private GridBagLayoutPanel pnlSyncGroup = null;
104
	private GridBagLayoutPanel pnlScaleTypeGroup = null;
105
	private ButtonGroup grpScaleType = null;
106
	private JRadioButton btnNormalScale = null;
107
	private JRadioButton btnFixedScale = null;
108
	private JRadioButton btnFixedExtent = null;
109
	private JTextField fldScale = null;
110
	private EnvelopePanel pnlExtent = null;
111
	private JButton btConfigView = null;
112
	private JPanel pnlScale = null;
88 113

  
114

  
89 115
    /**
90 116
     * This is the default constructor
91 117
     * 
......
120 146
        c.gridx = 0;
121 147
        c.gridy = row++;
122 148
        c.gridwidth = GridBagConstraints.REMAINDER;
123
        add(getChbSyncLayers(), c);
124
        c.insets = insets;
125
        c.gridx = 0;
149
        c.fill = GridBagConstraints.HORIZONTAL;
150
        
151
        GridBagLayoutPanel pnl = getPnlSyncGroup();
152
        pnl.addComponent(getChbSyncLayers(), insets);
153
        pnl.addComponent(getChbSyncExtent(), insets);
154
        add(pnl, c);
155
        
156
        getGrpScaleType().add(getBtnNormalScale());
157
        getGrpScaleType().add(getBtnFixedScale());
158
        getGrpScaleType().add(getBtnFixedExtent());
159
        
160
        pnl = getPnlScaleTypeGroup();
161
        pnl.addComponent(getBtnNormalScale(), insets);
162
        pnl.addComponent(getPnlScale(), insets); // pnlScale() contains btnFixedScale
163
        pnl.addComponent(getBtnFixedExtent(), new Insets(5, 5, 0, 5));
164
        pnl.addComponent(getPnlExtent(), GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5));
165
        if (fframeview.getScaleType()==SCALE_TYPE.FIXED_SCALE) {
166
        	getBtnFixedScale().setSelected(true);
167
        	scaleTypeSet(SCALE_TYPE.FIXED_SCALE);
168
        }
169
        else if (fframeview.getScaleType()==SCALE_TYPE.FIXED_EXTENT) {
170
        	getBtnFixedExtent().setSelected(true);
171
        	scaleTypeSet(SCALE_TYPE.FIXED_EXTENT);
172
        }
173
        else {
174
        	getBtnNormalScale().setSelected(true);
175
        	scaleTypeSet(SCALE_TYPE.NORMAL);
176
        }
177
        
126 178
        c.gridy = row++;
127
        c.gridwidth = GridBagConstraints.REMAINDER;
128
        add(getChbSyncExtent(), c);
179
        add(pnl, c);
180
        
181
        c.fill = GridBagConstraints.NONE;
129 182
        c.gridx = 0;
130 183
        c.gridy = row++;
131 184
        c.gridwidth = 1;
......
164 217
    		pnlFirstRow  = new JPanel(new GridBagLayout());
165 218
    		GridBagConstraints c = new GridBagConstraints();
166 219
            Insets insets = new Insets(5, 5, 5, 5);
220
            Insets insetsTop = new Insets(12, 5, 5, 5);
167 221
            c.gridx = 0;
168
            c.gridy = 1;
169
            c.insets = insets;
222
            c.gridy = 0;
223
            c.insets = insetsTop;
170 224
            c.anchor = GridBagConstraints.PAGE_START;
171 225
            pnlFirstRow.add(getLViews(), c);
172 226
            c.gridx = 1;
173 227
            pnlFirstRow.add(getScrolledViewList(), c);
228
            c.insets = insets;
174 229
            c.gridx = 2;
230
            c.gridheight = 2;
175 231
            pnlFirstRow.add(getPRotation(), c);
232
            c.anchor = GridBagConstraints.LINE_END;
233
            c.gridy = 1;
234
            c.gridx = 1;
235
            c.gridheight = 1;
236
            pnlFirstRow.add(getBtnConfigView(), c);
176 237
    	}
177 238
    	return pnlFirstRow; 
178 239
    }
240
    
241
    protected ViewDocument getSelectedView() {
242
    	Object selected = getViewList().getSelectedValue();
243
    	if (selected instanceof ViewDocument) {
244
    		return (ViewDocument) selected;
245
    	}
246
    	return null;
247
    }
248
    
249
    private JButton getBtnConfigView() {
250
		UsabilitySwingManager manager = org.gvsig.tools.swing.api.ToolsSwingLocator.getUsabilitySwingManager();
251
		btConfigView = manager.createJButton(Messages.getText("Configure_view"));
252
		btConfigView.addActionListener(new ActionListener() {
253
			public void actionPerformed(ActionEvent e) {
254
				ViewDocument view = getSelectedView();
255
				if (view!=null) {
256
					IWindow propWin = view.getPropertiesWindow();
257
					ApplicationManager manager = ApplicationLocator.getManager();
258
					manager.getUIManager().addWindow(propWin);
259
				}
260
			}
261
		});
262
    	return btConfigView;
263
    }
179 264

  
180 265
    /**
181 266
     * This method initializes lVistas
......
310 395
    	}
311 396
    	return chbSyncExtent;
312 397
    }
398
    
399
    protected void disableChbSyncExtent() {
400
    	getChbSyncExtent().setEnabled(false);
401
    	getChbSyncExtent().setToolTipText(Messages.getText("Extent_cant_be_synchronized_when_using_fixed_scale_or_fixed_extent"));
402
    }
403
    
404
    protected void enableChbSyncExtent() {
405
    	getChbSyncExtent().setEnabled(true);
406
    	getChbSyncExtent().setToolTipText(null);
407
    }
313 408

  
314 409
    /**
315 410
     * This method initializes jButton
......
332 427
                        newFFrameView.setLayerSynced(getChbSyncLayers()
333 428
                                .isSelected());
334 429
                        newFFrameView.setExtentSynced(getChbSyncExtent().isSelected());
335

  
430
                        try {
431
                        	if (getBtnFixedScale().isSelected()) {
432
                        		Double d = Double.parseDouble(getFldScale().getText());
433
                        		newFFrameView.setScaleType(SCALE_TYPE.FIXED_SCALE, d);
434
                        	}
435
                        	else if (getBtnFixedExtent().isSelected()) {
436
                        		Envelope envelope = getPnlExtent().getEnvelope();
437
                        		if (envelope!=null) {
438
                        			newFFrameView.setScaleType(SCALE_TYPE.FIXED_EXTENT, envelope);
439
                        		}
440
                        		else {
441
                        			newFFrameView.setScaleType(SCALE_TYPE.NORMAL);
442
                        		}
443
                        	}
444
                        	else {
445
                        		newFFrameView.setScaleType(SCALE_TYPE.NORMAL);
446
                        	}
447
                        }
448
                        catch (Exception ex) {
449
                        	newFFrameView.setScaleType(SCALE_TYPE.NORMAL);
450
                        }
336 451
                        if (m_projectView != null) {
337 452
                            newFFrameView.setView(m_projectView);
338 453
                            newFFrameView.setQuality(getCbCalidad()
......
354 469
                    isAcepted = true;
355 470
                    ApplicationLocator.getManager().getUIManager().closeWindow(
356 471
                        FFrameViewDialog.this);
472
                    notifyDialogClosed();
357 473
                    layoutPanel.getLayoutControl().setDefaultTool();
358 474
                }
359 475
            });
......
377 493
                    newFFrameView = null;
378 494
                    ApplicationLocator.getManager().getUIManager().closeWindow(
379 495
                        FFrameViewDialog.this);
496
                    notifyDialogClosed();
380 497
                }
381 498
            });
382 499
        }
......
422 539
     */
423 540
    public WindowInfo getWindowInfo() {
424 541
    	if (windowInfo==null) {
425
    		windowInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
426
    		windowInfo.setHeight(300);
542
    		windowInfo = new WindowInfo(WindowInfo.RESIZABLE);
543
    		windowInfo.setHeight(600);
427 544
    		windowInfo.setWidth(550);
428 545
    		windowInfo.setTitle(Messages.getText(
429 546
    				"propiedades_marco_vista"));
......
507 624
        }
508 625
        return chbShowGrid;
509 626
    }
627
    
628
    private GridBagLayoutPanel getPnlSyncGroup() {
629
    	if (pnlSyncGroup ==null) {
630
    		pnlSyncGroup = new GridBagLayoutPanel();
631
    		pnlSyncGroup.setBorder(BorderFactory.createTitledBorder(Messages.getText("Synchronization_of_the_view_and_the_frame_view")));
632
    	}
633
    	return pnlSyncGroup;
634
    }
635
    
636
    private GridBagLayoutPanel getPnlScaleTypeGroup() {
637
    	if (pnlScaleTypeGroup ==null) {
638
    		pnlScaleTypeGroup  = new GridBagLayoutPanel();
639
    		pnlScaleTypeGroup.setBorder(BorderFactory.createTitledBorder(Messages.getText("Fixed_scale_and_extent")));
640
    	}
641
    	return pnlScaleTypeGroup;
642
    }
643
    
644
    private ButtonGroup getGrpScaleType() {
645
    	if (grpScaleType==null) {
646
    		grpScaleType  = new ButtonGroup();
647
    	}
648
    	return grpScaleType;
649
    }
650
    
651
    private JRadioButton getBtnNormalScale() {
652
    	if (btnNormalScale==null) {
653
    		btnNormalScale  = new JRadioButton(Messages.getText("Non_fixed"));
654
    		btnNormalScale.addActionListener(new ActionListener() {
655
				public void actionPerformed(ActionEvent e) {
656
					FFrameViewDialog.this.scaleTypeSet(SCALE_TYPE.NORMAL);
657
					FFrameViewDialog.this.enableChbSyncExtent();
658
				}
659
			});
660
    	}
661
    	return btnNormalScale;
662
    }
663
    
664
    private JRadioButton getBtnFixedScale() {
665
    	if (btnFixedScale==null) {
666
    		btnFixedScale  = new JRadioButton(Messages.getText("Fixed_scale"));
667
    		btnFixedScale.addActionListener(new ActionListener() {
668
				public void actionPerformed(ActionEvent e) {
669
					FFrameViewDialog.this.scaleTypeSet(SCALE_TYPE.FIXED_SCALE);
670
					FFrameViewDialog.this.disableChbSyncExtent();
671
				}
672
			});
673
    	}
674
    	return btnFixedScale;
675
    }
676
    
677
    private JPanel getPnlScale() {
678
    	if (pnlScale==null) {
679
    		pnlScale  = new JPanel(new GridBagLayout());
680
    		GridBagConstraints c = new GridBagConstraints();
681
    		c.insets = new Insets(0, 0, 0, 0);
682
    		c.gridx = 0;
683
    		pnlScale.add(getBtnFixedScale());
684
    		c.anchor = GridBagConstraints.LINE_START;
685
    		c.gridx = 1;
686
    		c.insets = new Insets(0, 25, 0, 5);
687
    		c.anchor = GridBagConstraints.LINE_END;
688
    		pnlScale.add(getLblScale(), c);
689
    		c.gridx = 2;
690
    		c.insets = new Insets(0, 5, 0, 5);;
691
    		c.anchor = GridBagConstraints.LINE_START;
692
    		pnlScale.add(getFldScale(), c);
693
    	}
694
    	return pnlScale;
695
    }
696
    
697
    private JTextField getFldScale() {
698
		if (fldScale==null) {
699
    		fldScale  = new JTextField(8);
700
    		if (fframeview!=null &&
701
    				fframeview.getMapContext()!=null &&
702
    				fframeview.getMapContext().getViewPort().getEnvelope()!=null) {
703
    			fldScale.setText(Long.toString(fframeview.getMapContext().getScaleView()));
704
    		}
705
    	}
706
    	return fldScale;
707
    }
708
    
709
    private JLabel getLblScale() {
710
    	return new JLabel(Messages.getText("1__"));
711
    }
712
    
713
    private JRadioButton getBtnFixedExtent() {
714
    	if (btnFixedExtent==null) {
715
    		btnFixedExtent   = new JRadioButton(Messages.getText("Fixed_extent"));
716
    		btnFixedExtent.addActionListener(new ActionListener() {
717
				public void actionPerformed(ActionEvent e) {
718
					FFrameViewDialog.this.scaleTypeSet(SCALE_TYPE.FIXED_EXTENT);
719
					FFrameViewDialog.this.disableChbSyncExtent();
720
				}
721
			});
722
    	}
723
    	return btnFixedExtent;
724
    }
725
    
726
    private EnvelopePanel getPnlExtent() {
727
    	if (pnlExtent==null) {
728
    		pnlExtent  = new EnvelopePanel();
729
    		if (fframeview!=null &&
730
    				fframeview.getMapContext()!=null &&
731
    				fframeview.getMapContext().getViewPort().getEnvelope()!=null) {
732
    			pnlExtent.setEnvelope(fframeview.getMapContext().getViewPort().getEnvelope());
733
    		}
734
    	}
735
    	return pnlExtent;
736
    }
510 737

  
511 738
    public Object getWindowProfile() {
512 739
        return WindowInfo.DIALOG_PROFILE;
513 740
    }
514 741

  
742
	public Object getWindowModel() {
743
		return fframeview;
744
	}
745
	
746
	protected void scaleTypeSet(SCALE_TYPE type) {
747
		if (type==SCALE_TYPE.NORMAL) {
748
			getFldScale().setEditable(false);
749
			getFldScale().setEnabled(false);
750
			getPnlExtent().setEditable(false);
751
			getPnlExtent().setEnabled(false);
752
		}
753
		else if (type==SCALE_TYPE.FIXED_SCALE) {
754
			getFldScale().setEditable(true);
755
			getFldScale().setEnabled(true);
756
			getPnlExtent().setEditable(false);
757
			getPnlExtent().setEnabled(false);
758
		}
759
		else if (type==SCALE_TYPE.FIXED_EXTENT) {
760
			getFldScale().setEditable(false);
761
			getFldScale().setEnabled(false);
762
			getPnlExtent().setEditable(true);
763
			getPnlExtent().setEnabled(true);
764
		}
765
		
766
	}
767
	
768
	protected SCALE_TYPE getSelectedScaleType() {
769
		if (getBtnFixedScale().isSelected()) {
770
			return SCALE_TYPE.FIXED_SCALE;
771
		}
772
		else if (getBtnFixedExtent().isSelected()) {
773
			return SCALE_TYPE.FIXED_EXTENT;
774
		}
775
		return SCALE_TYPE.NORMAL;		
776
	}
777

  
515 778
} // @jve:decl-index=0:visual-constraint="10,10"

Also available in: Unified diff