BinaryAttributeEditorPanel.java revision 94e9037522922b67e8af412b4cfe476f5e991118
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* Panel that is displayed in the dialog where the user can specify the value
* of a binary attribute.
*
*/
public class BinaryAttributeEditorPanel extends StatusGenericPanel
{
private static final long serialVersionUID = -877248486446244170L;
private JRadioButton useFile;
private JRadioButton useBase64;
private JTextField file;
private JTextField base64;
private JLabel imagePreview;
private JButton refreshButton;
private BinaryValue value;
private boolean valueChanged;
private static final int MAX_IMAGE_HEIGHT = 300;
/**
* Default constructor.
*
*/
public BinaryAttributeEditorPanel()
{
super();
createLayout();
}
/**
* Sets the value to be displayed in the panel.
* @param attrName the attribute name.
* @param value the binary value.
*/
final BinaryValue value)
{
// Read the file or encode the base 64 content.
{
/**
* {@inheritDoc}
*/
{
try
{
}
catch (Throwable t)
{
}
valueChanged = false;
if (hasImageSyntax(attrName))
{
{
}
else
{
}
setImageVisible(true);
useFile.setSelected(true);
}
else
{
setImageVisible(false);
{
}
}
{
{
}
else
{
useFile.setSelected(true);
}
}
else
{
useFile.setSelected(true);
}
return null;
}
/**
* {@inheritDoc}
*/
Throwable t)
{
setEnabledOK(true);
if (t != null)
{
}
}
};
if (launchBackground)
{
setEnabledOK(false);
}
else
{
setEnabledOK(true);
{
if (isImage)
{
useFile.setSelected(true);
}
else
{
useBase64.setSelected(true);
}
}
}
}
/**
* {@inheritDoc}
*/
public Component getPreferredFocusComponent()
{
return file;
}
/**
* {@inheritDoc}
*/
public void cancelClicked()
{
valueChanged = false;
super.cancelClicked();
}
/**
* Returns the binary value displayed in the panel.
* @return the binary value displayed in the panel.
*/
public BinaryValue getBinaryValue()
{
return value;
}
/**
* {@inheritDoc}
*/
public void okClicked()
{
refresh(true, false);
}
/**
* Refresh the contents in the panel.
* @param closeAndUpdateValue whether the dialog must be closed and the value
* updated at the end of the method or not.
* @param updateImage whether the displayed image must be updated or not.
*/
private void refresh(final boolean closeAndUpdateValue,
final boolean updateImage)
{
if (closeAndUpdateValue)
{
}
if (useFile.isSelected())
{
{
{
// Do nothing. We do not want to regenerate the image and we
// are on the case where the user simply did not change the image.
}
else
{
}
}
else
{
{
}
else if (theFile.isDirectory())
{
}
{
}
}
}
else
{
if (b.length() == 0)
{
}
}
{
// Read the file or encode the base 64 content.
{
/**
* {@inheritDoc}
*/
{
try
{
}
catch (Throwable t)
{
}
if (useBase64.isSelected())
{
}
{
try
{
in = new FileInputStream(f);
boolean done = false;
while (!done)
{
if (len == -1)
{
done = true;
}
else
{
}
}
}
finally
{
{
}
}
}
else
{
// We do not want to regenerate the image and we
// are on the case where the user simply did not change the image.
}
if (closeAndUpdateValue)
{
}
if (updateImage)
{
}
return returnValue;
}
/**
* {@inheritDoc}
*/
Throwable t)
{
setEnabledOK(true);
if (closeAndUpdateValue)
{
value = returnValue;
}
else
{
}
if (t != null)
{
if (useFile.isSelected())
{
}
else
{
}
}
else
{
if (closeAndUpdateValue)
{
setVisible(false);
}
}
}
};
setEnabledOK(false);
}
else
{
}
}
/**
* {@inheritDoc}
*/
public LocalizableMessage getTitle()
{
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
public boolean valueChanged()
{
return valueChanged;
}
/**
* {@inheritDoc}
*/
public boolean requiresScroll()
{
return true;
}
/**
* Creates the layout of the panel (but the contents are not populated here).
*/
private void createLayout()
{
{
/**
* {@inheritDoc}
*/
{
}
});
{
{
}
};
}
/**
* Updates the enabling state of all the components in the panel.
*
*/
private void updateEnabling()
{
}
/**
* Updates the provided component with the base 64 representation of the
* provided binary array.
* @param base64 the text component to be updated.
* @param bytes the byte array.
*/
{
{
}
else
{
}
}
/**
* Updates a label, by displaying the image in the provided byte array.
* @param lImage the label to be updated.
* @param bytes the array of bytes containing the image.
*/
{
INFO_CTRL_PANEL_IMAGE_OF_ATTRIBUTE_LABEL.get(), false);
{
}
else
{
}
}
/**
* Updates the visibility of the components depending on whether the image
* must be made visible or not.
* @param visible whether the image must be visible or not.
*/
private void setImageVisible(boolean visible)
{
}
/**
* Class used to refresh automatically the contents in the panel after the
* user provides a path value through the JFileChooser associated with the
* browse button.
*
*/
class CustomBrowseActionListener extends BrowseActionListener
{
/**
* Constructor of this listener.
* @param field the text field.
* @param type the type of browsing (file, directory, etc.)
* @param parent the parent component to be used as reference to display
* the file chooser dialog.
*/
{
}
/**
* {@inheritDoc}
*/
protected void fieldUpdated()
{
super.fieldUpdated();
if (refreshButton.isVisible())
{
// The file field is updated, if refreshButton is visible it means
// that we can have a preview.
}
}
}
/**
* Called when the refresh button is clicked by the user.
*
*/
private void refreshButtonClicked()
{
refresh(false, true);
}
/**
* Returns <CODE>true</CODE> if the attribute has an image syntax and
* <CODE>false</CODE> otherwise.
* @param attrName the attribute name.
* @return <CODE>true</CODE> if the attribute has an image syntax and
* <CODE>false</CODE> otherwise.
*/
{
}
}