VerticalPanel verticalPanel = new VerticalPanel();
// if we have an extra widget then enclose it within a horizontal
// panel with it on the left and the options on the right
HorizontalPanel topPanel = new HorizontalPanel();
CellPanel optionsPanel = null;
HorizontalPanel widthAndHeightPanel = null;
if (extraWidget != null)
{
topPanel.setWidth("100%");
topPanel.add(extraWidget);
topPanel.setCellHorizontalAlignment(extraWidget,
HasHorizontalAlignment.ALIGN_LEFT);
optionsPanel = new VerticalPanel();
optionsPanel.setStylePrimaryName(
resources.styles().verticalSizeOptions());
optionsPanel.setSpacing(0);
topPanel.add(optionsPanel);
topPanel.setCellHorizontalAlignment(
optionsPanel,
HasHorizontalAlignment.ALIGN_RIGHT);
widthAndHeightPanel = new HorizontalPanel();
widthAndHeightPanel.setStylePrimaryName(
resources.styles().widthAndHeightEntry());
configureHorizontalOptionsPanel(widthAndHeightPanel);
optionsPanel.add(widthAndHeightPanel);
}
else
{
optionsPanel = topPanel ;
optionsPanel.setStylePrimaryName(
resources.styles().horizontalSizeOptions());
widthAndHeightPanel = topPanel;
configureHorizontalOptionsPanel(topPanel);
}
// image width
widthAndHeightPanel.add(createImageOptionLabel("Width:"));
widthTextBox_ = createImageSizeTextBox();
widthTextBox_.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event)
{
// screen out programmatic sets
if (settingDimenensionInProgress_)
return;
// enforce min size
int width = constrainWidth(getImageWidth());
// preserve aspect ratio if requested
if (getKeepRatio())
{
double ratio = (double)lastHeight_ / (double)lastWidth_;
int height = constrainHeight((int) (ratio * (double)width));
setHeightTextBox(height);
}
// set width
setWidthTextBox(width);
}
});
widthAndHeightPanel.add(widthTextBox_);
// image height
widthAndHeightPanel.add(new HTML(" "));
widthAndHeightPanel.add(createImageOptionLabel("Height:"));
heightTextBox_ = createImageSizeTextBox();
heightTextBox_.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event)
{
// screen out programmatic sets
if (settingDimenensionInProgress_)
return;
// enforce min size
int height = constrainHeight(getImageHeight());
// preserve aspect ratio if requested
if (getKeepRatio())
{
double ratio = (double)lastWidth_ / (double)lastHeight_;
int width = constrainWidth((int) (ratio * (double)height));
setWidthTextBox(width);
}
// always set height
setHeightTextBox(height);
}
});
widthAndHeightPanel.add(heightTextBox_);
// add width and height panel to options panel container if necessary
if (widthAndHeightPanel != optionsPanel)
optionsPanel.add(widthAndHeightPanel);
// lock ratio check box
keepRatioCheckBox_ = new CheckBox();
keepRatioCheckBox_.setStylePrimaryName(
resources.styles().maintainAspectRatioCheckBox());
keepRatioCheckBox_.setValue(keepRatio);
keepRatioCheckBox_.setText("Maintain aspect ratio");
optionsPanel.add(keepRatioCheckBox_);
// image and sizer in layout panel (create now so we can call
// setSize in update button click handler)
previewPanel_ = new LayoutPanel();
// update button
ThemedButton updateButton = new ThemedButton("Update Preview",
new ClickHandler(){
public void onClick(ClickEvent event)
{
updatePreview();
}
});
updateButton.setStylePrimaryName(
resources.styles().updateImageSizeButton());
optionsPanel.add(updateButton);
// add top panel
verticalPanel.add(topPanel);
// previewer