Search in sources :

Example 41 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class TerraPromptSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Prompt prompt = (Prompt) component;
    prompt.setPreferredWidth(320);
    prompt.setMinimumWidth(160);
    prompt.getPromptListeners().add(this);
    // Load the prompt content
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    Component content;
    try {
        content = (Component) bxmlSerializer.readObject(TerraPromptSkin.class, "terra_prompt_skin.bxml");
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
    prompt.setContent(content);
    typeImageView = (ImageView) bxmlSerializer.getNamespace().get("typeImageView");
    messageLabel = (Label) bxmlSerializer.getNamespace().get("messageLabel");
    messageBoxPane = (BoxPane) bxmlSerializer.getNamespace().get("messageBoxPane");
    optionButtonBoxPane = (BoxPane) bxmlSerializer.getNamespace().get("optionButtonBoxPane");
    for (Object option : prompt.getOptions()) {
        PushButton optionButton = new PushButton(option);
        optionButton.setStyleName(BUTTON_STYLE_NAME);
        optionButton.getButtonPressListeners().add(optionButtonPressListener);
        optionButtonBoxPane.add(optionButton);
    }
    messageTypeChanged(prompt, null);
    messageChanged(prompt, null);
    bodyChanged(prompt, null);
}
Also used : Prompt(org.apache.pivot.wtk.Prompt) Component(org.apache.pivot.wtk.Component) PushButton(org.apache.pivot.wtk.PushButton) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 42 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class TerraAlertSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Alert alert = (Alert) component;
    alert.setPreferredWidth(320);
    alert.setMinimumWidth(160);
    alert.getAlertListeners().add(this);
    // Load the alert content
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    Component content;
    try {
        content = (Component) bxmlSerializer.readObject(TerraAlertSkin.class, "terra_alert_skin.bxml");
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
    alert.setContent(content);
    typeImageView = (ImageView) bxmlSerializer.getNamespace().get("typeImageView");
    messageLabel = (Label) bxmlSerializer.getNamespace().get("messageLabel");
    messageBorder = (Border) bxmlSerializer.getNamespace().get("messageBorder");
    messageBoxPane = (BoxPane) bxmlSerializer.getNamespace().get("messageBoxPane");
    optionButtonBoxPane = (BoxPane) bxmlSerializer.getNamespace().get("optionButtonBoxPane");
    // Explicitly set the message border color and background color, this can't be done properly in the constructor
    // as messageBorder is null at that point.
    setBorderBackgroundColor(borderBackgroundColor);
    setBorderColor(borderColor);
    for (Object option : alert.getOptions()) {
        PushButton optionButton = new PushButton(option);
        optionButton.setStyleName(BUTTON_STYLE_NAME);
        optionButton.getButtonPressListeners().add(optionButtonPressListener);
        optionButtonBoxPane.add(optionButton);
    }
    messageTypeChanged(alert, null);
    messageChanged(alert, null);
    bodyChanged(alert, null);
}
Also used : Alert(org.apache.pivot.wtk.Alert) Component(org.apache.pivot.wtk.Component) PushButton(org.apache.pivot.wtk.PushButton) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 43 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class Expenses method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    // Get startup properties
    URL origin = ApplicationContext.getOrigin();
    if (origin == null) {
        System.out.println("Warning: Origin null, so for this application to run you have to set the following properties: \n" + SECURE_KEY + ", " + HOSTNAME_KEY + ", " + PORT_KEY + "\n");
        System.exit(1);
        // make Eclipse's null checker happy
        return;
    }
    if (properties.containsKey(SECURE_KEY)) {
        secure = Boolean.parseBoolean(properties.get(SECURE_KEY));
    } else {
        secure = origin.getProtocol().equals("HTTPS");
    }
    if (properties.containsKey(HOSTNAME_KEY)) {
        hostname = properties.get(HOSTNAME_KEY);
    } else {
        hostname = origin.getHost();
    }
    if (properties.containsKey(PORT_KEY)) {
        port = Integer.parseInt(properties.get(PORT_KEY));
    } else {
        port = origin.getPort();
    }
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    expensesWindow = (ExpensesWindow) bxmlSerializer.readObject(ExpensesWindow.class, "expenses_window.bxml", true);
    expensesWindow.setExpensesApplication(this);
    expensesWindow.open(display);
}
Also used : URL(java.net.URL) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 44 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class ExpensesWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    expenseTableView = (TableView) namespace.get("expenseTableView");
    activityIndicator = (ActivityIndicator) namespace.get("activityIndicator");
    activityIndicatorBoxPane = (BoxPane) namespace.get("activityIndicatorBoxPane");
    // Load the add/edit sheet
    try {
        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        expenseSheet = (ExpenseSheet) bxmlSerializer.readObject(ExpenseSheet.class, "expense_sheet.bxml", true);
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    } catch (SerializationException exception) {
        throw new RuntimeException(exception);
    }
    // Create the delete confirmation prompt
    ArrayList<String> options = new ArrayList<>((String) resources.get("ok"), (String) resources.get("cancel"));
    deleteConfirmationPrompt = new Prompt(MessageType.QUESTION, (String) resources.get("confirmDelete"), options);
    // Attach event listeners
    expenseTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener() {

        @Override
        public void selectedRowChanged(TableView tableView, Object previousSelectedRow) {
            int selectedIndex = expenseTableView.getSelectedIndex();
            editSelectedExpenseAction.setEnabled(selectedIndex != -1);
            deleteSelectedExpenseAction.setEnabled(selectedIndex != -1);
        }
    });
}
Also used : SerializationException(org.apache.pivot.serialization.SerializationException) ArrayList(org.apache.pivot.collections.ArrayList) Prompt(org.apache.pivot.wtk.Prompt) IOException(java.io.IOException) TableViewSelectionListener(org.apache.pivot.wtk.TableViewSelectionListener) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) TableView(org.apache.pivot.wtk.TableView)

Example 45 with BXMLSerializer

use of org.apache.pivot.beans.BXMLSerializer in project pivot by apache.

the class WebQueries method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    window = (Window) bxmlSerializer.readObject(WebQueries.class, "web_queries.bxml");
    listView = (ListView) bxmlSerializer.getNamespace().get("listView");
    loadingLabel = (Label) bxmlSerializer.getNamespace().get("loadingLabel");
    // Execute the query:
    // http://pipes.yahoo.com/pipes/pipe.run?_id=43115761f2da5af5341ae2e56a93d646&_render=json
    GetQuery getQuery = new GetQuery("pipes.yahoo.com", "/pipes/pipe.run");
    getQuery.getParameters().put("_id", "43115761f2da5af5341ae2e56a93d646");
    getQuery.getParameters().put("_render", "json");
    getQuery.execute(new TaskAdapter<>(new TaskListener<Object>() {

        @Override
        public void taskExecuted(Task<Object> task) {
            List<?> items = (List<?>) JSON.get(task.getResult(), "value.items");
            if (items.getLength() > 0) {
                listView.setListData(items);
                loadingLabel.setVisible(false);
            } else {
                loadingLabel.setText("No results.");
            }
        }

        @Override
        public void executeFailed(Task<Object> task) {
            loadingLabel.setText(task.getFault().getMessage());
        }
    }));
    window.open(display);
}
Also used : Task(org.apache.pivot.util.concurrent.Task) GetQuery(org.apache.pivot.web.GetQuery) TaskListener(org.apache.pivot.util.concurrent.TaskListener) List(org.apache.pivot.collections.List) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Aggregations

BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)86 Component (org.apache.pivot.wtk.Component)24 IOException (java.io.IOException)19 SerializationException (org.apache.pivot.serialization.SerializationException)14 Window (org.apache.pivot.wtk.Window)13 Button (org.apache.pivot.wtk.Button)11 PushButton (org.apache.pivot.wtk.PushButton)11 File (java.io.File)9 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)9 Frame (org.apache.pivot.wtk.Frame)8 TextInput (org.apache.pivot.wtk.TextInput)8 ArrayList (org.apache.pivot.collections.ArrayList)7 List (org.apache.pivot.collections.List)7 Mouse (org.apache.pivot.wtk.Mouse)6 Sequence (org.apache.pivot.collections.Sequence)5 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)5 ListButton (org.apache.pivot.wtk.ListButton)5 TextInputContentListener (org.apache.pivot.wtk.TextInputContentListener)5 URL (java.net.URL)4 MalformedURLException (java.net.MalformedURLException)3