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 @ 2487
History | View | Annotate | Download (5.19 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* 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 |
*
|
11 |
* 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 |
*
|
16 |
* 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 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.tools.dynform.services.dynformfield.Bytearray; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.FlowLayout; |
27 |
import java.awt.event.FocusEvent; |
28 |
import java.awt.event.FocusListener; |
29 |
import javax.swing.JButton; |
30 |
import javax.swing.JPanel; |
31 |
import javax.swing.JTextField; |
32 |
import javax.swing.event.ChangeEvent; |
33 |
import javax.swing.event.ChangeListener; |
34 |
import javax.swing.text.JTextComponent; |
35 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
36 |
import org.gvsig.tools.dynform.JDynFormField; |
37 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
38 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
39 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
40 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
41 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
42 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
43 |
|
44 |
public class JDynFormFieldBytearray extends AbstractJDynFormField implements JDynFormField, FocusListener { |
45 |
|
46 |
protected byte[] assignedValue = null; |
47 |
protected byte[] currentValue = null; |
48 |
protected JTextComponent jtext = null; |
49 |
protected JButton jbuttonUpload = null; |
50 |
protected JButton jbuttonDownload = null; |
51 |
private PickerController<byte[]> picker; |
52 |
|
53 |
public JDynFormFieldBytearray(
|
54 |
DynFormSPIManager serviceManager, |
55 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
56 |
JDynFormFieldFactory factory, |
57 |
DynFormFieldDefinition definition, |
58 |
Object value
|
59 |
) { |
60 |
super(serviceManager, componentsFactory, factory, definition, value);
|
61 |
this.assignedValue = (byte[]) value; |
62 |
} |
63 |
|
64 |
@Override
|
65 |
public void setReadOnly(boolean readonly) { |
66 |
super.setReadOnly(readonly);
|
67 |
if (this.contents != null) { |
68 |
this.contents.setEnabled(true); |
69 |
} |
70 |
if (this.picker != null) { |
71 |
this.picker.setEnabled(!this.isReadOnly()); |
72 |
} |
73 |
} |
74 |
|
75 |
@Override
|
76 |
public Object getAssignedValue() { |
77 |
return this.assignedValue; |
78 |
} |
79 |
|
80 |
@Override
|
81 |
public void initComponent() { |
82 |
this.contents = new JPanel(); |
83 |
this.contents.setLayout(new BorderLayout()); |
84 |
|
85 |
DynFormSPIManager.ComponentsFactory components = this.getComponentsFactory();
|
86 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
87 |
|
88 |
this.jtext = components.getJTextField(this.getDefinition(), null); |
89 |
this.jbuttonDownload = components.getJButton(this.getDefinition(), "Download"); |
90 |
this.jbuttonUpload = components.getJButton(this.getDefinition(), "Upload"); |
91 |
|
92 |
this.picker = toolsSwingManager.createByteArrayPickerController(
|
93 |
(JTextField) jtext,
|
94 |
jbuttonUpload, |
95 |
jbuttonDownload, |
96 |
this.getForm().getDefinition().getName() + ".RAWDATA", |
97 |
null
|
98 |
); |
99 |
this.picker.addChangeListener(new ChangeListener() { |
100 |
@Override
|
101 |
public void stateChanged(ChangeEvent e) { |
102 |
fireFieldChangedEvent(); |
103 |
} |
104 |
}); |
105 |
if (!components.containsComponents(this.getDefinition())) { |
106 |
toolsSwingManager.removeBorder(this.jbuttonDownload);
|
107 |
toolsSwingManager.removeBorder(this.jbuttonUpload);
|
108 |
JPanel buttons = new JPanel(new FlowLayout(FlowLayout.TRAILING, 4, 2)); |
109 |
buttons.add(this.jbuttonUpload);
|
110 |
buttons.add(this.jbuttonDownload);
|
111 |
this.contents.add(jtext, BorderLayout.CENTER); |
112 |
this.contents.add(buttons, BorderLayout.LINE_END); |
113 |
this.contents.setVisible(true); |
114 |
} |
115 |
|
116 |
this.picker.setEnabled(!this.isReadOnly()); |
117 |
this.setValue(this.assignedValue); |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public void setValue(Object value) { |
122 |
this.picker.set((byte[]) value); |
123 |
this.assignedValue = (byte[]) value; |
124 |
} |
125 |
|
126 |
@Override
|
127 |
public Object getValue() { |
128 |
return this.picker.get(); |
129 |
} |
130 |
|
131 |
@Override
|
132 |
public boolean hasValidValue() { |
133 |
return true; |
134 |
} |
135 |
|
136 |
@Override
|
137 |
public void focusGained(FocusEvent arg0) { |
138 |
fireFieldEnterEvent(); |
139 |
this.problemIndicator().restore();
|
140 |
} |
141 |
|
142 |
@Override
|
143 |
public void focusLost(FocusEvent arg0) { |
144 |
fireFieldExitEvent(); |
145 |
} |
146 |
|
147 |
@Override
|
148 |
public void clear() { |
149 |
this.picker.set(null); |
150 |
} |
151 |
|
152 |
} |