use of org.apache.pivot.wtk.Sheet in project pivot by apache.
the class TerraSheetSkin method install.
@Override
public void install(Component component) {
super.install(component);
Sheet sheet = (Sheet) component;
sheet.getSheetStateListeners().add(this);
// Attach the drop-shadow decorator
if (!themeIsFlat()) {
dropShadowDecorator = new DropShadowDecorator();
sheet.getDecorators().add(dropShadowDecorator);
}
sheet.add(resizeHandle);
}
use of org.apache.pivot.wtk.Sheet in project pivot by apache.
the class TerraSheetSkin method alignToOwner.
public void alignToOwner() {
Sheet sheet = (Sheet) getComponent();
Window owner = sheet.getOwner();
if (owner != null) {
Bounds clientArea = owner.getClientArea();
Point location = owner.mapPointToAncestor(owner.getDisplay(), clientArea.x, clientArea.y);
int x = location.x;
int y = location.y;
switch(slideSource) {
case NORTH:
x = location.x + (clientArea.width - getWidth()) / 2;
y = location.y;
break;
case SOUTH:
x = location.x + (clientArea.width - getWidth()) / 2;
y = location.y + (clientArea.height - getHeight());
break;
case WEST:
x = location.x;
y = location.y + (clientArea.height - getHeight()) / 2;
break;
case EAST:
x = location.x + (clientArea.width - getWidth());
y = location.y + (clientArea.height - getHeight()) / 2;
break;
default:
throw new IllegalStateException("slideSource is null or an unexpected value");
}
sheet.setLocation(x, y);
}
}
use of org.apache.pivot.wtk.Sheet in project pivot by apache.
the class ExpensesWindow method addExpense.
private void addExpense() {
expenseSheet.clear();
expenseSheet.open(this, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
// Get the expense data from the sheet
final HashMap<String, Object> expense = new HashMap<>();
expenseSheet.store(expense);
// POST expense to server and then add to table
Expenses expensesApplicationLocal = getExpensesApplication();
PostQuery addExpenseQuery = new PostQuery(expensesApplicationLocal.getHostname(), expensesApplicationLocal.getPort(), "/pivot-tutorials/expenses", expensesApplicationLocal.isSecure());
addExpenseQuery.setValue(expense);
activityIndicatorBoxPane.setVisible(true);
activityIndicator.setActive(true);
addExpenseQuery.execute(new TaskAdapter<>(new TaskListener<URL>() {
@Override
public void taskExecuted(Task<URL> task) {
activityIndicatorBoxPane.setVisible(false);
activityIndicator.setActive(false);
URL location = task.getResult();
String file = location.getFile();
int id = Integer.parseInt(file.substring(file.lastIndexOf('/') + 1));
expense.put("id", id);
@SuppressWarnings("unchecked") List<Object> expenses = (List<Object>) expenseTableView.getTableData();
expenses.add(expense);
}
@Override
public void executeFailed(Task<URL> task) {
activityIndicatorBoxPane.setVisible(false);
activityIndicator.setActive(false);
Prompt.prompt(MessageType.ERROR, task.getFault().getMessage(), ExpensesWindow.this);
}
}));
}
}
});
}
use of org.apache.pivot.wtk.Sheet in project pivot by apache.
the class ExpensesWindow method updateSelectedExpense.
private void updateSelectedExpense() {
Object expense = expenseTableView.getSelectedRow();
final int id = JSON.getInt(expense, "id");
expenseSheet.load(expense);
expenseSheet.open(this, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
// Get the expense data from the sheet
final HashMap<String, Object> expenseLocal = new HashMap<>();
expenseSheet.store(expenseLocal);
// PUT expense to server and then update table
Expenses expensesApplicationLocal = getExpensesApplication();
PutQuery updateExpenseQuery = new PutQuery(expensesApplicationLocal.getHostname(), expensesApplicationLocal.getPort(), "/pivot-tutorials/expenses/" + JSON.get(expenseLocal, "id"), expensesApplicationLocal.isSecure());
updateExpenseQuery.setValue(expenseLocal);
activityIndicatorBoxPane.setVisible(true);
activityIndicator.setActive(true);
updateExpenseQuery.execute(new TaskAdapter<>(new TaskListener<Boolean>() {
@Override
public void taskExecuted(Task<Boolean> task) {
activityIndicatorBoxPane.setVisible(false);
activityIndicator.setActive(false);
// Find matching row and update
@SuppressWarnings("unchecked") List<Object> expenses = (List<Object>) expenseTableView.getTableData();
for (int i = 0, n = expenses.getLength(); i < n; i++) {
if (JSON.get(expenses.get(i), "id").equals(id)) {
expenses.update(i, expenseLocal);
break;
}
}
}
@Override
public void executeFailed(Task<Boolean> task) {
activityIndicatorBoxPane.setVisible(false);
activityIndicator.setActive(false);
Prompt.prompt(MessageType.ERROR, task.getFault().getMessage(), ExpensesWindow.this);
}
}));
}
}
});
}
use of org.apache.pivot.wtk.Sheet in project pivot by apache.
the class TabPanes method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
confirmCloseTabPrompt = (Prompt) namespace.get("confirmCloseTabPrompt");
tabPane = (TabPane) namespace.get("tabPane");
closeableCheckbox = (Checkbox) namespace.get("closeableCheckbox");
collapsibleCheckbox = (Checkbox) namespace.get("collapsibleCheckbox");
horizontalRadioButton = (RadioButton) namespace.get("horizontalRadioButton");
verticalRadioButton = (RadioButton) namespace.get("verticalRadioButton");
cornerBoxPane = (BoxPane) namespace.get("cornerBoxPane");
tabPane.getTabPaneListeners().add(new TabPaneListener() {
@Override
public Vote previewRemoveTabs(final TabPane tabPaneArgument, final int index, final int count) {
Vote vote;
if (confirmCloseTab) {
confirmCloseTabPrompt.open(TabPanes.this, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (confirmCloseTabPrompt.getResult() && confirmCloseTabPrompt.getSelectedOptionIndex() == 1) {
confirmCloseTab = false;
int n = tabPaneArgument.getTabs().getLength();
if (index < n - 1) {
tabPaneArgument.setSelectedIndex(index + 1);
} else {
tabPaneArgument.setSelectedIndex(index - 1);
}
tabPaneArgument.getTabs().remove(index, count);
confirmCloseTab = true;
}
}
});
vote = Vote.DENY;
} else {
vote = Vote.APPROVE;
}
return vote;
}
});
ButtonStateListener checkboxStateListener = new ButtonStateListener() {
@Override
public void stateChanged(Button button, Button.State previousState) {
updateTabPane();
}
};
closeableCheckbox.getButtonStateListeners().add(checkboxStateListener);
collapsibleCheckbox.getButtonStateListeners().add(checkboxStateListener);
ButtonStateListener radioButtonStateListener = new ButtonStateListener() {
@Override
public void stateChanged(Button button, Button.State previousState) {
if (button.isSelected()) {
updateTabPane();
}
}
};
horizontalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
verticalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
updateTabPane();
}
Aggregations