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 |
/**
|
---|---|
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.text.JTextComponent; |
33 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
34 |
import org.gvsig.tools.dynform.JDynFormField; |
35 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
36 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
37 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
38 |
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 |
|
42 |
public class JDynFormFieldBytearray extends AbstractJDynFormField implements JDynFormField, FocusListener { |
43 |
|
44 |
protected byte[] assignedValue = null; |
45 |
protected byte[] currentValue = null; |
46 |
protected JTextComponent jtext = null; |
47 |
protected JButton jbuttonUpload = null; |
48 |
protected JButton jbuttonDownload = null; |
49 |
private PickerController<byte[]> picker; |
50 |
|
51 |
public JDynFormFieldBytearray(
|
52 |
DynFormSPIManager serviceManager, |
53 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
54 |
JDynFormFieldFactory factory, |
55 |
DynFormFieldDefinition definition, |
56 |
Object value
|
57 |
) { |
58 |
super(serviceManager, componentsFactory, factory, definition, value);
|
59 |
this.assignedValue = (byte[]) value; |
60 |
} |
61 |
|
62 |
@Override
|
63 |
public void setReadOnly(boolean readonly) { |
64 |
super.setReadOnly(readonly);
|
65 |
if( this.contents!=null ) { |
66 |
this.contents.setEnabled(true); |
67 |
} |
68 |
if (this.picker != null) { |
69 |
this.picker.setEnabled(!this.isReadOnly()); |
70 |
} |
71 |
} |
72 |
|
73 |
@Override
|
74 |
public Object getAssignedValue() { |
75 |
return this.assignedValue; |
76 |
} |
77 |
|
78 |
@Override
|
79 |
public void initComponent() { |
80 |
this.contents = new JPanel(); |
81 |
this.contents.setLayout(new BorderLayout()); |
82 |
|
83 |
DynFormSPIManager.ComponentsFactory components = this.getComponentsFactory();
|
84 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
85 |
|
86 |
this.jtext = components.getJTextField(this.getDefinition(), null); |
87 |
this.jbuttonDownload = components.getJButton(this.getDefinition(), "Download"); |
88 |
this.jbuttonUpload = components.getJButton(this.getDefinition(), "Upload"); |
89 |
|
90 |
this.picker = toolsSwingManager.createByteArrayPickerController(
|
91 |
(JTextField) jtext,
|
92 |
jbuttonUpload, |
93 |
jbuttonDownload, |
94 |
this.getForm().getDefinition().getName()+".RAWDATA", |
95 |
null
|
96 |
); |
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 |
} |
107 |
|
108 |
this.picker.setEnabled(!this.isReadOnly()); |
109 |
this.setValue(this.assignedValue); |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public void setValue(Object value) { |
114 |
this.picker.set((byte[]) value); |
115 |
} |
116 |
|
117 |
@Override
|
118 |
public Object getValue() { |
119 |
return this.picker.get(); |
120 |
} |
121 |
|
122 |
@Override
|
123 |
public boolean hasValidValue() { |
124 |
return true; |
125 |
} |
126 |
|
127 |
@Override
|
128 |
public void focusGained(FocusEvent arg0) { |
129 |
fireFieldEnterEvent(); |
130 |
this.problemIndicator().restore();
|
131 |
} |
132 |
|
133 |
@Override
|
134 |
public void focusLost(FocusEvent arg0) { |
135 |
fireFieldExitEvent(); |
136 |
} |
137 |
|
138 |
@Override
|
139 |
public void clear() { |
140 |
this.picker.set(null); |
141 |
} |
142 |
|
143 |
} |