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 @ 2847
History | View | Annotate | Download (5.91 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 java.util.Objects; |
30 |
import javax.swing.JButton; |
31 |
import javax.swing.JPanel; |
32 |
import javax.swing.JTextField; |
33 |
import javax.swing.event.ChangeEvent; |
34 |
import javax.swing.event.ChangeListener; |
35 |
import javax.swing.text.JTextComponent; |
36 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
37 |
import org.gvsig.tools.dynform.JDynFormField; |
38 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
39 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
40 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
41 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
42 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
43 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
44 |
|
45 |
public class JDynFormFieldBytearray extends AbstractJDynFormField implements JDynFormField, FocusListener { |
46 |
|
47 |
protected byte[] assignedValue = null; |
48 |
protected byte[] currentValue = null; |
49 |
protected JTextComponent jtext = null; |
50 |
protected JButton jbuttonUpload = null; |
51 |
protected JButton jbuttonDownload = null; |
52 |
protected JButton jbuttonEditAsText = null; |
53 |
private PickerController<byte[]> picker; |
54 |
|
55 |
public JDynFormFieldBytearray(
|
56 |
DynFormSPIManager serviceManager, |
57 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
58 |
JDynFormFieldFactory factory, |
59 |
DynFormFieldDefinition definition, |
60 |
Object value
|
61 |
) { |
62 |
super(serviceManager, componentsFactory, factory, definition, value);
|
63 |
this.assignedValue = (byte[]) value; |
64 |
} |
65 |
|
66 |
@Override
|
67 |
public void setReadOnly(boolean readonly) { |
68 |
// super.setReadOnly(readonly);
|
69 |
this.readOnly = readonly;
|
70 |
// if (this.contents != null) {
|
71 |
// this.contents.setEnabled(true);
|
72 |
// }
|
73 |
if (this.picker != null) { |
74 |
this.picker.setEnabled(!this.isReadOnly()); |
75 |
} |
76 |
} |
77 |
|
78 |
@Override
|
79 |
public Object getAssignedValue() { |
80 |
return this.assignedValue; |
81 |
} |
82 |
|
83 |
@Override
|
84 |
public void initComponent() { |
85 |
this.contents = new JPanel(); |
86 |
this.contents.setLayout(new BorderLayout()); |
87 |
|
88 |
DynFormSPIManager.ComponentsFactory componentsFactory = this.getComponentsFactory();
|
89 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
90 |
|
91 |
this.jtext = componentsFactory.getJTextField(this.getDefinition(), null); |
92 |
this.jbuttonDownload = componentsFactory.getJButton(this.getDefinition(), "Download"); |
93 |
this.jbuttonUpload = componentsFactory.getJButton(this.getDefinition(), "Upload"); |
94 |
this.jbuttonEditAsText = componentsFactory.getJButton(this.getDefinition(), "EditAsText"); |
95 |
|
96 |
this.picker = toolsSwingManager.createByteArrayPickerController(
|
97 |
(JTextField) jtext,
|
98 |
jbuttonUpload, |
99 |
jbuttonDownload, |
100 |
jbuttonEditAsText, |
101 |
this.getForm().getDefinition().getName() + ".RAWDATA", |
102 |
null
|
103 |
); |
104 |
this.picker.addChangeListener(new ChangeListener() { |
105 |
@Override
|
106 |
public void stateChanged(ChangeEvent e) { |
107 |
fireFieldChangedEvent(); |
108 |
} |
109 |
}); |
110 |
if (!componentsFactory.containsComponents(this.getDefinition())) { |
111 |
toolsSwingManager.removeBorder(this.jbuttonDownload);
|
112 |
toolsSwingManager.removeBorder(this.jbuttonUpload);
|
113 |
toolsSwingManager.removeBorder(this.jbuttonEditAsText);
|
114 |
JPanel buttons = new JPanel(new FlowLayout(FlowLayout.TRAILING, 4, 2)); |
115 |
buttons.add(this.jbuttonUpload);
|
116 |
buttons.add(this.jbuttonDownload);
|
117 |
if( this.jbuttonEditAsText!=null ) { |
118 |
buttons.add(this.jbuttonEditAsText);
|
119 |
} |
120 |
this.contents.add(jtext, BorderLayout.CENTER); |
121 |
this.contents.add(buttons, BorderLayout.LINE_END); |
122 |
this.contents.setVisible(true); |
123 |
} |
124 |
|
125 |
this.picker.setEnabled(!this.isReadOnly()); |
126 |
this.setValue(this.assignedValue); |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public void setValue(Object value) { |
131 |
this.picker.set((byte[]) value); |
132 |
this.assignedValue = (byte[]) value; |
133 |
} |
134 |
|
135 |
@Override
|
136 |
public Object getValue() { |
137 |
return this.picker.get(); |
138 |
} |
139 |
|
140 |
@Override
|
141 |
public boolean hasValidValue() { |
142 |
return true; |
143 |
} |
144 |
|
145 |
@Override
|
146 |
public void focusGained(FocusEvent arg0) { |
147 |
fireFieldEnterEvent(); |
148 |
this.problemIndicator().restore();
|
149 |
} |
150 |
|
151 |
@Override
|
152 |
public void focusLost(FocusEvent arg0) { |
153 |
fireFieldExitEvent(); |
154 |
} |
155 |
|
156 |
@Override
|
157 |
public void clear() { |
158 |
this.picker.set(null); |
159 |
} |
160 |
|
161 |
@Override
|
162 |
public boolean isModified() { |
163 |
try {
|
164 |
byte[] value = this.picker.get(); |
165 |
return !Objects.equals(value, this.getAssignedValue()); |
166 |
} catch (Exception ex) { |
167 |
return false; |
168 |
} |
169 |
} |
170 |
|
171 |
|
172 |
} |