|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JPanel com.jidesoft.field.IPTextField
public class IPTextField
IPTextField
is a component for editing an IP address. It can accept IP address as either a String such
as "255.16.32.15" (using setText(String)
or an int array such as new int[]{255, 16, 32, 15} (using setValue(int[])
. It also can return IP address in either of the two formats. You can use static methods convertIPToString(int[])
and convertStringToIP(String)
to convert between the two formats.
IPTextField
also supports subnet mask. You can specify a Class B mask "255.255.0.0" for example using
setSubnetMask(String)
method. Any IP addresses that are outside the subnet will be automatically corrected.
Here are some technical notes. At first glance, you may think it is possible to implement IPTextField using
JFormattedTextField with MaskFormatter. Sure, it can get your almost there. However it's not easy to enforce each
octet of the IP address to less than 255. In our implementation, we actually use four JTextFields for each octet and
three JLabels for the "." between octets. However we still want to give user the impression that it is one text
field. That's why we add code to handle all the keystrokes that can be possibly used. For example, left, right, home,
end and backspace keys will transverse among text fields transparently. "." key will navigate to next field. You could
invoke getTextFields()
to get all the JTextFields it created.
Although it is one of the JTextFields that owns the focus, you may want to know if IPTextField right now "owns" the
focus. For this purpose, you could add focus listener to this component. As long as the focus is switched between the
JTextFields inside, you will not get the listener triggered.
This component is still in beta.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JPanel |
---|
JPanel.AccessibleJPanel |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected ChangeEvent |
changeEvent
|
String |
PROPERTY_EDITABLE
|
String |
PROPERTY_SUBNET_MASK
|
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
IPTextField()
|
|
IPTextField(int[] ip)
|
|
IPTextField(String ip)
|
Method Summary | |
---|---|
void |
addChangeListener(ChangeListener l)
Adds a ChangeListener to the model. |
void |
addFocusListener(FocusListener l)
|
static String |
convertIPToString(int[] ip)
Converts an ip (int array) to a string. |
static int[] |
convertStringToIP(String str)
Converts a string to ip (int array). |
protected JTextField |
createTextField(JTextField previousTextField)
Creates the text fields for this IPTextField. |
protected void |
fireStateChanged()
Runs each ChangeListener 's stateChanged method. |
int |
getBaseline(int width,
int height)
|
ChangeListener[] |
getChangeListeners()
Returns an array of all the ChangeListener s added to this DefaultColorSelectionModel
with addChangeListener . |
FocusListener[] |
getFocusListeners()
|
String[] |
getRawText()
Gets the raw texts in each text field. |
int[] |
getSubnetMask()
|
String |
getText()
Gets the IP as text. |
JTextField[] |
getTextFields()
Gets the four text fields that used by this IPTextField. |
int[] |
getValue()
Gets the IP address as int[]. |
boolean |
hasFocus()
|
boolean |
isEditable()
Returns the boolean indicating whether this IPTextField is editable or not. |
protected boolean |
isNavigateToNextField(char ch)
Check if the input character should trigger navigating to next available field. |
boolean |
isValueValid()
Checks if the value in IPTextField is valid. |
void |
removeChangeListener(ChangeListener l)
Removes a ChangeListener from the model. |
void |
removeFocusListener(FocusListener l)
|
void |
requestFocus()
|
boolean |
requestFocus(boolean temporary)
|
boolean |
requestFocusInWindow()
|
void |
setEditable(boolean b)
Sets the specified boolean to indicate whether or not this IPTextField should be editable. |
void |
setFocusable(boolean focusable)
|
void |
setRawText(String[] rawText)
Sets the raw texts in each text field. |
void |
setSubnetMask(int[] subnetMask)
|
void |
setSubnetMask(String subnetMask)
|
void |
setText(String str)
Sets the IP as text. |
void |
setToolTipText(String text)
|
void |
setToolTipText(String[] toolTips)
Set the tool tips to the sub fields |
void |
setToolTipText(String text,
boolean forward)
Set the tool tip to the component, could be forwarded to set the tool tip of sub fields |
void |
setValue(int[] ip)
Sets the IP as int[]. |
void |
updateUI()
|
Methods inherited from class javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final String PROPERTY_SUBNET_MASK
public final String PROPERTY_EDITABLE
protected transient ChangeEvent changeEvent
Constructor Detail |
---|
public IPTextField()
public IPTextField(String ip)
public IPTextField(int[] ip)
Method Detail |
---|
public void updateUI()
updateUI
in class JPanel
public void setText(String str)
str
- the new IP textpublic String getText()
public void setValue(int[] ip)
ip
- the IP address int arraypublic int[] getValue()
public String[] getRawText()
setRawText(String[])
public void setRawText(String[] rawText)
rawText
- the actual text that is in each text field.public boolean isValueValid()
getValue()
will fill invalid
fields with 0 to make a valid IP address. However if you use getRawText()
, it will give you the exact
text in each octet so that you can check to see which value is invalid.
public int[] getSubnetMask()
public void setSubnetMask(int[] subnetMask)
public void setSubnetMask(String subnetMask)
public static String convertIPToString(int[] ip)
ip
- the IP address in int array
public static int[] convertStringToIP(String str)
str
- the IP string
public void requestFocus()
requestFocus
in class JComponent
public boolean requestFocus(boolean temporary)
requestFocus
in class JComponent
public boolean requestFocusInWindow()
requestFocusInWindow
in class JComponent
public boolean hasFocus()
hasFocus
in class Component
protected JTextField createTextField(JTextField previousTextField)
previousTextField
- the previous JTextField
public void setFocusable(boolean focusable)
setFocusable
in class Component
public void addFocusListener(FocusListener l)
addFocusListener
in class Component
public void removeFocusListener(FocusListener l)
removeFocusListener
in class Component
public FocusListener[] getFocusListeners()
getFocusListeners
in class Component
protected boolean isNavigateToNextField(char ch)
ch
- the input character
public boolean isEditable()
IPTextField
is editable or not.
setEditable(boolean)
public void setEditable(boolean b)
IPTextField
should be editable. A
PropertyChange event ("editable") is fired when the state is changed.
b
- the boolean to be setisEditable()
public JTextField[] getTextFields()
public void addChangeListener(ChangeListener l)
ChangeListener
to the model.
l
- the ChangeListener
to be addedremoveChangeListener(javax.swing.event.ChangeListener)
,
getChangeListeners()
public void removeChangeListener(ChangeListener l)
ChangeListener
from the model.
l
- the ChangeListener
to be removedpublic ChangeListener[] getChangeListeners()
ChangeListener
s added to this DefaultColorSelectionModel
with addChangeListener
.
ChangeListener
s added, or an empty array if no listeners have been addedprotected void fireStateChanged()
ChangeListener
's stateChanged
method.
EventListenerList
public int getBaseline(int width, int height)
getBaseline
in class JComponent
public void setToolTipText(String[] toolTips)
toolTips
- The String array of tool tips, will try to set the most available toop tips to the sub fieldspublic void setToolTipText(String text, boolean forward)
text
- the tool tip textforward
- if true, the text will be forwarded to sub fieldspublic void setToolTipText(String text)
setToolTipText
in class JComponent
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |