Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / gui / dialogs / FAlignDialog.java @ 1700

History | View | Annotate | Download (9.12 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.gui.dialogs;
23

    
24
import java.awt.Dimension;
25
import java.awt.event.ItemEvent;
26
import java.awt.event.ItemListener;
27
import java.net.URL;
28
import javax.swing.ImageIcon;
29
import org.apache.commons.io.FilenameUtils;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
32
import org.gvsig.andami.ui.mdiManager.WindowInfo;
33
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.i18n.I18nManager;
36
import org.gvsig.tools.swing.api.ToolsSwingLocator;
37
import org.gvsig.tools.swing.api.ToolsSwingManager;
38
import org.gvsig.tools.swing.api.ToolsSwingUtils;
39
import org.gvsig.tools.swing.icontheme.IconTheme;
40
import org.gvsig.tools.util.LabeledValue;
41
import org.gvsig.tools.util.LabeledValueImpl;
42

    
43
/**
44
 * Contenedor de los botones necesarios para alinear, desplazar y cambiar el
45
 * tama�o de los fframes.
46
 * 
47
 * @author gvSIG Team
48
 */
49
public class FAlignDialog extends FAlignDialogView implements SingletonWindow {
50

    
51
    private static final long serialVersionUID = -4811888913915502937L;
52
    
53
    public static final String RELATIVE_TO_THE_PAGE_LABEL = "_the_page";
54
    public static final String RELATIVE_TO_SELECTION_LABEL = "_the_selection";
55
    public static final String RELATIVE_TO_GREATER_OBJECT_LABEL = "_the_greater_object";
56
    public static final String RELATIVE_TO_MINOR_OBJECT_LABEL="_the_minor_object";
57

    
58
    public static final int RELATIVE_TO_SELECTION = 0;
59
    public static final int RELATIVE_TO_THE_PAGE = 1;
60
    public static final int RELATIVE_TO_GREATER_OBJECT = 2;
61
    public static final int RELATIVE_TO_MINOR_OBJECT = 3;
62

    
63
    /**
64
     * This is the default constructor
65
     * 
66
     * @param layout
67
     *            Referencia al Layout.
68
     */
69
    public FAlignDialog(LayoutPanel layout) {
70
        super();
71
        initialize();
72
        translate();
73
    }
74

    
75
    /**
76
     * This method initializes this
77
     */
78
    private void initialize() {
79
        EventsFAlign listener = new EventsFAlign();
80
        btnLeft.addActionListener(listener);
81
        btnLeft.setActionCommand("LEFT");
82
        btnCenterV.addActionListener(listener);
83
        btnCenterV.setActionCommand("CENTERV");
84
        btnRight.addActionListener(listener);
85
        btnRight.setActionCommand("RIGHT");
86
        btnUp.addActionListener(listener);
87
        btnUp.setActionCommand("UP");
88
        btnCenterH.addActionListener(listener);
89
        btnCenterH.setActionCommand("CENTERH");
90
        btnDown.addActionListener(listener);
91
        btnDown.setActionCommand("DOWN");
92
        btnDistUp.addActionListener(listener);
93
        btnDistUp.setActionCommand("DISTUP");
94
        btnDistCenterV.addActionListener(listener);
95
        btnDistCenterV.setActionCommand("DISTCENTERV");
96
        btnDistDown.addActionListener(listener);
97
        btnDistDown.setActionCommand("DISTDOWN");
98
        btnDistLeft.addActionListener(listener);
99
        btnDistLeft.setActionCommand("DISTLEFT");
100
        btnDistCenterH.addActionListener(listener);
101
        btnDistCenterH.setActionCommand("DISTCENTERH");
102
        btnDistRight.addActionListener(listener);
103
        btnDistRight.setActionCommand("DISTRIGHT");
104
        btnSizeV.addActionListener(listener);
105
        btnSizeV.setActionCommand("SIZECENTERV");
106
        btnSizeH.addActionListener(listener);
107
        btnSizeH.setActionCommand("SIZECENTERH");
108
        btnSizeBoth.addActionListener(listener);
109
        btnSizeBoth.setActionCommand("SIZEOTHER");
110
        btnSpaceRight.addActionListener(listener);
111
        btnSpaceRight.setActionCommand("SPACERIGHT");
112
        btnSpaceDown.addActionListener(listener);
113
        btnSpaceDown.setActionCommand("SPACEDOWN");
114

    
115
        I18nManager i18n = ToolsLocator.getI18nManager();
116
        this.cboAlignRelativeTo.addItem(new LabeledValueImpl<>(i18n.getTranslation(RELATIVE_TO_SELECTION_LABEL), RELATIVE_TO_SELECTION));
117
        this.cboAlignRelativeTo.addItem(new LabeledValueImpl<>(i18n.getTranslation(RELATIVE_TO_THE_PAGE_LABEL), RELATIVE_TO_THE_PAGE));
118
        this.cboAlignRelativeTo.addItem(new LabeledValueImpl<>(i18n.getTranslation(RELATIVE_TO_GREATER_OBJECT_LABEL), RELATIVE_TO_GREATER_OBJECT));
119
        this.cboAlignRelativeTo.addItem(new LabeledValueImpl<>(i18n.getTranslation(RELATIVE_TO_MINOR_OBJECT_LABEL), RELATIVE_TO_MINOR_OBJECT));
120
        cboAlignRelativeTo.addItemListener(new ItemListener() {
121
            @Override
122
            public void itemStateChanged(ItemEvent e) {
123
               listener.setAlignRelativeTo((int)((LabeledValue)cboAlignRelativeTo.getSelectedItem()).getValue());
124
               updateComponents();
125
            }
126
        });
127
        
128
        Dimension dim = ToolsSwingUtils.ensureRowsCols(this, 13, 32, 15, 38);
129
        this.setSize(dim);
130

    
131
    }
132

    
133
        private void translate() {
134
        ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
135
        
136
        toolsSwingManager.translate(btnLeft);
137
        toolsSwingManager.translate(btnCenterV);
138
        toolsSwingManager.translate(btnRight);
139
        toolsSwingManager.translate(btnUp);
140
        toolsSwingManager.translate(btnCenterH);
141
        toolsSwingManager.translate(btnDown);
142
        toolsSwingManager.translate(btnDistUp);
143
        toolsSwingManager.translate(btnDistCenterV);
144
        toolsSwingManager.translate(btnDistDown);
145
        toolsSwingManager.translate(btnDistLeft);
146
        toolsSwingManager.translate(btnDistCenterH);
147
        toolsSwingManager.translate(btnDistRight);
148
        toolsSwingManager.translate(btnSizeV);
149
        toolsSwingManager.translate(btnSizeH);
150
        toolsSwingManager.translate(btnSizeBoth);
151
        toolsSwingManager.translate(btnSpaceRight);
152
        toolsSwingManager.translate(btnSpaceDown);
153
        toolsSwingManager.translate(cboAlignRelativeTo);
154
        toolsSwingManager.translate(lblAlignRelativeTo);
155
        toolsSwingManager.translate(lblAlign);
156
        toolsSwingManager.translate(lblDistribute);
157
        toolsSwingManager.translate(lblMatchSize);
158
        toolsSwingManager.translate(lblGap);
159
    }
160
        
161
    private void updateComponents() {
162
        int relativeTo = (int)((LabeledValue)this.cboAlignRelativeTo.getSelectedItem()).getValue();
163
        switch (relativeTo) {
164
            case RELATIVE_TO_GREATER_OBJECT:
165
            case RELATIVE_TO_MINOR_OBJECT:
166
                btnDistLeft.setEnabled(false);
167
                btnDistRight.setEnabled(false);
168
                btnDistCenterV.setEnabled(false);
169
                btnDistUp.setEnabled(false);
170
                btnDistDown.setEnabled(false);
171
                btnDistCenterH.setEnabled(false);
172
                btnSpaceDown.setEnabled(false);
173
                btnSpaceRight.setEnabled(false);
174
                break;
175
            default:
176
                btnDistLeft.setEnabled(true);
177
                btnDistRight.setEnabled(true);
178
                btnDistCenterV.setEnabled(true);
179
                btnDistUp.setEnabled(true);
180
                btnDistDown.setEnabled(true);
181
                btnDistCenterH.setEnabled(true);
182
                btnSpaceDown.setEnabled(true);
183
                btnSpaceRight.setEnabled(true);
184
                break;
185
        }
186
    }
187

    
188

    
189
    /**
190
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
191
     */
192
    @Override
193
    public Object getWindowModel() {
194
        return "AlignDialog";
195
    }
196

    
197
    /**
198
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
199
     */
200
    @Override
201
    public WindowInfo getWindowInfo() {
202
        WindowInfo m_viewinfo =
203
            new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE | WindowInfo.RESIZABLE);
204
        m_viewinfo.setTitle(PluginServices.getText(this, "alinear"));
205

    
206
        return m_viewinfo;
207
    }
208

    
209
    /**
210
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
211
     */
212
    public void viewActivated() {
213
    }
214

    
215
    @Override
216
    public Object getWindowProfile() {
217
        return WindowInfo.PROPERTIES_PROFILE;
218
    }
219

    
220
    @Override
221
    public ImageIcon loadImage(String imageName) {
222
        String name = FilenameUtils.getBaseName(imageName);
223
        IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault();
224
        if (theme.exists(name)) {
225
            return theme.get(name);
226
        }
227
        URL url = FAlignDialog.class.getResource("images/layout/"+name + ".png");
228
        if (url == null) {
229
            return null;
230
        }
231
        return new ImageIcon(url);    
232
    }
233
    
234

    
235
    
236
    
237

    
238
}