Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.dynform / org.gvsig.tools.dynform.services / src / main / java / org / gvsig / tools / dynform / services / dynformfield / Bytearray / JDynFormFieldBytearray.java @ 1961

History | View | Annotate | Download (4.88 KB)

1 954 jbadia
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6 1081 jjdelcerro
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10 954 jbadia
 *
11 1081 jjdelcerro
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15 954 jbadia
 *
16 1081 jjdelcerro
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 954 jbadia
 *
20 1081 jjdelcerro
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22 954 jbadia
 */
23 1894 jjdelcerro
package org.gvsig.tools.dynform.services.dynformfield.Bytearray;
24 919 jjdelcerro
25
import java.awt.BorderLayout;
26 1894 jjdelcerro
import java.awt.FlowLayout;
27 919 jjdelcerro
import java.awt.event.FocusEvent;
28
import java.awt.event.FocusListener;
29
import javax.swing.JButton;
30
import javax.swing.JPanel;
31 1894 jjdelcerro
import javax.swing.JTextField;
32 1881 jjdelcerro
import javax.swing.text.JTextComponent;
33
import org.gvsig.tools.dynform.DynFormFieldDefinition;
34 933 jjdelcerro
import org.gvsig.tools.dynform.JDynFormField;
35 1881 jjdelcerro
import org.gvsig.tools.dynform.spi.DynFormSPIManager;
36
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory;
37 919 jjdelcerro
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField;
38 1894 jjdelcerro
import org.gvsig.tools.swing.api.ToolsSwingLocator;
39
import org.gvsig.tools.swing.api.ToolsSwingManager;
40
import org.gvsig.tools.swing.api.pickercontroller.PickerController;
41 919 jjdelcerro
42 1894 jjdelcerro
public class JDynFormFieldBytearray extends AbstractJDynFormField implements JDynFormField, FocusListener {
43 919 jjdelcerro
44 1894 jjdelcerro
    protected byte[] assignedValue = null;
45
    protected byte[] currentValue = null;
46 1881 jjdelcerro
    protected JTextComponent jtext = null;
47 1894 jjdelcerro
    protected JButton jbuttonUpload = null;
48
    protected JButton jbuttonDownload = null;
49
    private PickerController<byte[]> picker;
50 919 jjdelcerro
51 1894 jjdelcerro
    public JDynFormFieldBytearray(
52 1881 jjdelcerro
            DynFormSPIManager serviceManager,
53
            DynFormSPIManager.ComponentsFactory componentsFactory,
54
            JDynFormFieldFactory factory,
55
            DynFormFieldDefinition definition,
56
            Object value
57
            ) {
58
            super(serviceManager, componentsFactory, factory, definition, value);
59 1894 jjdelcerro
        this.assignedValue = (byte[]) value;
60 1081 jjdelcerro
    }
61 919 jjdelcerro
62 1881 jjdelcerro
    @Override
63 1081 jjdelcerro
    public void setReadOnly(boolean readonly) {
64 1895 jjdelcerro
        super.setReadOnly(readonly);
65
        if( this.contents!=null ) {
66
            this.contents.setEnabled(true);
67 1081 jjdelcerro
        }
68 1895 jjdelcerro
        if (this.picker != null) {
69
            this.picker.setEnabled(!this.isReadOnly());
70
        }
71 1081 jjdelcerro
    }
72 940 jjdelcerro
73 1881 jjdelcerro
    @Override
74 1081 jjdelcerro
    public Object getAssignedValue() {
75
        return this.assignedValue;
76
    }
77 919 jjdelcerro
78 1881 jjdelcerro
    @Override
79 1081 jjdelcerro
    public void initComponent() {
80
        this.contents = new JPanel();
81
        this.contents.setLayout(new BorderLayout());
82 919 jjdelcerro
83 1894 jjdelcerro
        DynFormSPIManager.ComponentsFactory components = this.getComponentsFactory();
84
        ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
85 919 jjdelcerro
86 1894 jjdelcerro
        this.jtext = components.getJTextField(this.getDefinition(), null);
87
        this.jbuttonDownload = components.getJButton(this.getDefinition(), "Download");
88
        this.jbuttonUpload = components.getJButton(this.getDefinition(), "Upload");
89 1081 jjdelcerro
90 1894 jjdelcerro
        this.picker = toolsSwingManager.createByteArrayPickerController(
91
                (JTextField) jtext,
92
                jbuttonUpload,
93 1961 jjdelcerro
                jbuttonDownload,
94
                this.getForm().getDefinition().getName()+".RAWDATA",
95
                null
96 1894 jjdelcerro
        );
97
        if (!components.containsComponents(this.getDefinition())) {
98
            toolsSwingManager.removeBorder(this.jbuttonDownload);
99
            toolsSwingManager.removeBorder(this.jbuttonUpload);
100
            JPanel buttons = new JPanel(new FlowLayout(FlowLayout.TRAILING, 4, 2));
101
            buttons.add(this.jbuttonUpload);
102
            buttons.add(this.jbuttonDownload);
103
            this.contents.add(jtext, BorderLayout.CENTER);
104
            this.contents.add(buttons, BorderLayout.LINE_END);
105
            this.contents.setVisible(true);
106 1081 jjdelcerro
        }
107 1894 jjdelcerro
108 1895 jjdelcerro
        this.picker.setEnabled(!this.isReadOnly());
109 1081 jjdelcerro
        this.setValue(this.assignedValue);
110
    }
111
112 1894 jjdelcerro
    @Override
113 1081 jjdelcerro
    public void setValue(Object value) {
114 1894 jjdelcerro
        this.picker.set((byte[]) value);
115 1081 jjdelcerro
    }
116
117 1894 jjdelcerro
    @Override
118 1081 jjdelcerro
    public Object getValue() {
119 1894 jjdelcerro
        return this.picker.get();
120 1081 jjdelcerro
    }
121
122 1894 jjdelcerro
    @Override
123 1081 jjdelcerro
    public boolean hasValidValue() {
124
        return true;
125
    }
126
127 1894 jjdelcerro
    @Override
128 1081 jjdelcerro
    public void focusGained(FocusEvent arg0) {
129
        fireFieldEnterEvent();
130
        this.problemIndicator().restore();
131
    }
132
133 1894 jjdelcerro
    @Override
134 1081 jjdelcerro
    public void focusLost(FocusEvent arg0) {
135
        fireFieldExitEvent();
136
    }
137
138 1894 jjdelcerro
    @Override
139 1145 jjdelcerro
    public void clear() {
140 1894 jjdelcerro
        this.picker.set(null);
141 1145 jjdelcerro
    }
142
143 1081 jjdelcerro
}