Revision 270 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/usability/DefaultUsabilitySwingManager.java

View differences:

DefaultUsabilitySwingManager.java
1 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
*/
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 22

  
23 23
/*
24
* AUTHORS (In addition to CIT):
25
* 2010 {}  {{Task}}
26
*/
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {}  {{Task}}
26
 */
27 27
package org.gvsig.tools.swing.impl.usability;
28 28

  
29 29
import java.awt.Component;
......
47 47
 */
48 48
public class DefaultUsabilitySwingManager implements UsabilitySwingManager {
49 49

  
50
	/* (non-Javadoc)
51
	 * @see org.gvsig.tools.swing.api.usability.UsabilitySwingManager#createBoxLayout(java.awt.Component, java.awt.Component, java.lang.Integer, java.lang.Integer)
52
	 */
53
	public JPanel createGridBagRowPanel(JPanel gridBagPanel, Component labelComponent,
54
		Component fieldComponent,
55
		Integer labelMargin, Integer fieldMargin) {
56
	    // Create a panel that uses BoxLayout.
57
	    JPanel panel;
58
	    if (gridBagPanel==null){
59
		panel = new JPanel();
60
		panel.setLayout(new GridBagLayout());
61
	    }else
62
		panel = gridBagPanel;
63
	    
64
	    GridBagConstraints constr = this.getDefaultParametersConstraints();
65
	    constr.fill = GridBagConstraints.HORIZONTAL;	   
50
    /*
51
     * (non-Javadoc)
52
     * 
53
     * @see
54
     * org.gvsig.tools.swing.api.usability.UsabilitySwingManager#createBoxLayout
55
     * (java.awt.Component, java.awt.Component, java.lang.Integer,
56
     * java.lang.Integer)
57
     */
58
    public JPanel createGridBagRowPanel(JPanel gridBagPanel,
59
        Component labelComponent, Component fieldComponent,
60
        Integer labelMargin, Integer fieldMargin) {
61
        // Create a panel that uses BoxLayout.
62
        JPanel panel;
63
        if (gridBagPanel == null) {
64
            panel = new JPanel();
65
            panel.setLayout(new GridBagLayout());
66
        } else
67
            panel = gridBagPanel;
66 68

  
67
	    constr.gridwidth = GridBagConstraints.RELATIVE;
68
	    constr.weighty = 0;
69
	    
70
	    if (labelComponent != null) {
71
//		constr.weightx = 0;
72
//		int width = labelComponent.getSize().width;
73
		
74
		if (labelMargin != null)
75
		    constr.weightx = labelMargin;
76
		panel.add(labelComponent, constr);
77
	    }
78
	    constr.fill = GridBagConstraints.NONE;  
79
//	    constr.gridwidth = GridBagConstraints.RELATIVE;
80
	       
81
	    
82
	    if (fieldComponent != null) {
83
		constr.weightx = 0;
84
		if (fieldMargin != null)
85
		    constr.weightx = labelMargin;
86
		panel.add(fieldComponent, constr);
87
	    }
88
	    return panel;
89
	}
69
        GridBagConstraints constr = this.getDefaultParametersConstraints();
70
        constr.fill = GridBagConstraints.HORIZONTAL;
90 71

  
91
	public JButton createJButton() {
92
		return new JStandardizedButton();
93
	}
72
        constr.gridwidth = GridBagConstraints.RELATIVE;
73
        constr.weighty = 0;
94 74

  
95
	public JButton createJButton(Action action) {
96
		return new JStandardizedButton(action);
97
	}
75
        if (labelComponent != null) {
76
            // constr.weightx = 0;
77
            // int width = labelComponent.getSize().width;
98 78

  
99
	public JButton createJButton(Icon icon) {
100
		return new JStandardizedButton(icon);
101
	}
79
            if (labelMargin != null)
80
                constr.weightx = labelMargin;
81
            panel.add(labelComponent, constr);
82
        }
83
        constr.fill = GridBagConstraints.NONE;
84
        // constr.gridwidth = GridBagConstraints.RELATIVE;
102 85

  
103
	public JButton createJButton(String text) {
104
		return new JStandardizedButton(text);
105
	}
106
	
107
	public JButton createJButton(String text, Icon icon) {
108
		return new JStandardizedButton(text, icon);
109
	}
110
	
86
        if (fieldComponent != null) {
87
            constr.weightx = 0;
88
            if (fieldMargin != null)
89
                constr.weightx = labelMargin;
90
            panel.add(fieldComponent, constr);
91
        }
92
        return panel;
93
    }
111 94

  
112
	public JButton createJToolButton(String text) {
113
		return new JStandardizedToolButton(text);
114
	}
115
	
116
	/**
117
	 * @return
118
	 */
119
	private GridBagConstraints getDefaultParametersConstraints() {
120
	    GridBagConstraints constr = new GridBagConstraints();
121
	    constr.insets = new Insets(2, 2, 2, 2);
122
	    constr.ipadx = 2;
123
	    constr.ipady = 2;
124
	    constr.anchor = GridBagConstraints.PAGE_START;
125
	    return constr;
126
	}	
95
    public JButton createJButton() {
96
        return new JStandardizedButton();
97
    }
127 98

  
128
}
99
    public JButton createJButton(Action action) {
100
        return new JStandardizedButton(action);
101
    }
102

  
103
    public JButton createJButton(Icon icon) {
104
        return new JStandardizedButton(icon);
105
    }
106

  
107
    public JButton createJButton(String text) {
108
        return new JStandardizedButton(text);
109
    }
110

  
111
    public JButton createJButton(String text, Icon icon) {
112
        return new JStandardizedButton(text, icon);
113
    }
114

  
115
    public JButton createJToolButton(String text) {
116
        return new JStandardizedToolButton(text);
117
    }
118

  
119
    /**
120
     * @return
121
     */
122
    private GridBagConstraints getDefaultParametersConstraints() {
123
        GridBagConstraints constr = new GridBagConstraints();
124
        constr.insets = new Insets(2, 2, 2, 2);
125
        constr.ipadx = 2;
126
        constr.ipady = 2;
127
        constr.anchor = GridBagConstraints.PAGE_START;
128
        return constr;
129
    }
130

  
131
}

Also available in: Unified diff