Search in sources :

Example 6 with CalendarButton

use of org.apache.pivot.wtk.CalendarButton in project pivot by apache.

the class TerraCalendarButtonSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    CalendarButton calendarButton = (CalendarButton) getComponent();
    Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
    dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
    int preferredWidth = dataRenderer.getPreferredWidth(-1) + paddingWidth();
    return preferredWidth;
}
Also used : CalendarButton(org.apache.pivot.wtk.CalendarButton) Button(org.apache.pivot.wtk.Button) CalendarButton(org.apache.pivot.wtk.CalendarButton) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 7 with CalendarButton

use of org.apache.pivot.wtk.CalendarButton in project pivot by apache.

the class TerraCalendarButtonSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    CalendarButton calendarButton = (CalendarButton) getComponent();
    int width = getWidth();
    int height = getHeight();
    Color backgroundColorLocal = null;
    Color bevelColorLocal = null;
    Color borderColorLocal = null;
    if (calendarButton.isEnabled()) {
        backgroundColorLocal = this.backgroundColor;
        bevelColorLocal = (pressed || (calendarPopup.isOpen() && !calendarPopup.isClosing())) ? pressedBevelColor : this.bevelColor;
        borderColorLocal = this.borderColor;
    } else {
        backgroundColorLocal = disabledBackgroundColor;
        bevelColorLocal = disabledBevelColor;
        borderColorLocal = disabledBorderColor;
    }
    // Paint the background
    GraphicsUtilities.setAntialiasingOn(graphics);
    if (!themeIsFlat()) {
        graphics.setPaint(new GradientPaint(width / 2f, 0, bevelColorLocal, width / 2f, height / 2f, backgroundColorLocal));
    } else {
        graphics.setPaint(backgroundColorLocal);
    }
    graphics.fill(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
    // Paint the content
    GraphicsUtilities.setAntialiasingOff(graphics);
    Bounds contentBounds = new Bounds(0, 0, Math.max(width - TRIGGER_WIDTH - 1, 0), Math.max(height - 1, 0));
    Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
    dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
    dataRenderer.setSize(Math.max(contentBounds.width - (paddingWidth() - TRIGGER_WIDTH) + 1, 0), Math.max(contentBounds.height - paddingHeight() + 1, 0));
    Graphics2D contentGraphics = (Graphics2D) graphics.create();
    contentGraphics.translate(padding.left + 1, padding.top + 1);
    contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
    dataRenderer.paint(contentGraphics);
    contentGraphics.dispose();
    GraphicsUtilities.setAntialiasingOn(graphics);
    if (!themeIsFlat()) {
        // Paint the border
        if (borderColorLocal != null) {
            graphics.setPaint(borderColorLocal);
            graphics.setStroke(new BasicStroke(1));
            graphics.draw(new RoundRectangle2D.Double(0.5, 0.5, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
        }
    }
    // Paint the focus state
    if (calendarButton.isFocused()) {
        BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 0.0f, 2.0f }, 0.0f);
        graphics.setStroke(dashStroke);
        graphics.setColor(this.borderColor);
        graphics.draw(new RoundRectangle2D.Double(2.5, 2.5, Math.max(width - 5, 0), Math.max(height - 5, 0), CORNER_RADIUS / 2, CORNER_RADIUS / 2));
    }
    GraphicsUtilities.setAntialiasingOff(graphics);
    // Paint the trigger
    GeneralPath triggerIconShape = new GeneralPath(Path2D.WIND_EVEN_ODD);
    triggerIconShape.moveTo(0, 0);
    triggerIconShape.lineTo(3, 3);
    triggerIconShape.lineTo(6, 0);
    triggerIconShape.closePath();
    Graphics2D triggerGraphics = (Graphics2D) graphics.create();
    triggerGraphics.setStroke(new BasicStroke(0));
    triggerGraphics.setPaint(color);
    Bounds triggerBounds = new Bounds(Math.max(width - (padding.right + TRIGGER_WIDTH), 0), 0, TRIGGER_WIDTH, Math.max(height - padding.getHeight(), 0));
    int tx = triggerBounds.x + (triggerBounds.width - triggerIconShape.getBounds().width) / 2;
    int ty = triggerBounds.y + (triggerBounds.height - triggerIconShape.getBounds().height) / 2;
    triggerGraphics.translate(tx, ty);
    triggerGraphics.draw(triggerIconShape);
    triggerGraphics.fill(triggerIconShape);
    triggerGraphics.dispose();
}
Also used : BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) CalendarButton(org.apache.pivot.wtk.CalendarButton) Button(org.apache.pivot.wtk.Button) CalendarButton(org.apache.pivot.wtk.CalendarButton) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Bounds(org.apache.pivot.wtk.Bounds) GradientPaint(java.awt.GradientPaint) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 8 with CalendarButton

use of org.apache.pivot.wtk.CalendarButton in project pivot by apache.

the class TerraCalendarButtonSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    CalendarButton calendarButton = (CalendarButton) getComponent();
    Button.DataRenderer dataRenderer = calendarButton.getDataRenderer();
    dataRenderer.render(calendarButton.getButtonData(), calendarButton, false);
    int preferredHeight = dataRenderer.getPreferredHeight(-1) + paddingHeight();
    return preferredHeight;
}
Also used : CalendarButton(org.apache.pivot.wtk.CalendarButton) Button(org.apache.pivot.wtk.Button) CalendarButton(org.apache.pivot.wtk.CalendarButton) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 9 with CalendarButton

use of org.apache.pivot.wtk.CalendarButton in project pivot by apache.

the class Pivot714 method getWindow.

public Window getWindow(final Window ownerArgument) {
    this.owner = ownerArgument;
    final BXMLSerializer bxmlSerializer = new BXMLSerializer();
    try {
        result = (Dialog) bxmlSerializer.readObject(Pivot714.class.getResource("pivot_714.bxml"));
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SerializationException e) {
        e.printStackTrace();
    }
    final ListButton motif = (ListButton) bxmlSerializer.getNamespace().get("motif");
    ArrayList<String> al = new ArrayList<>();
    al.add("One");
    al.add("Two");
    motif.setListData(al);
    CalendarButton cbDate = (CalendarButton) bxmlSerializer.getNamespace().get("date");
    dcl = (new DialogCloseListener() {

        @Override
        public void dialogClosed(Dialog dialog, boolean modal) {
        // empty block
        }
    });
    cbDate.getCalendarButtonSelectionListeners().add(new CalendarButtonSelectionListener() {

        @Override
        public void selectedDateChanged(CalendarButton calendarButton, CalendarDate previousSelectedDate) {
        // empty block
        }
    });
    return result;
}
Also used : SerializationException(org.apache.pivot.serialization.SerializationException) ArrayList(org.apache.pivot.collections.ArrayList) CalendarButtonSelectionListener(org.apache.pivot.wtk.CalendarButtonSelectionListener) IOException(java.io.IOException) ListButton(org.apache.pivot.wtk.ListButton) CalendarDate(org.apache.pivot.util.CalendarDate) CalendarButton(org.apache.pivot.wtk.CalendarButton) Dialog(org.apache.pivot.wtk.Dialog) DialogCloseListener(org.apache.pivot.wtk.DialogCloseListener) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 10 with CalendarButton

use of org.apache.pivot.wtk.CalendarButton in project pivot by apache.

the class Pivot694 method initializeFields.

private void initializeFields(BXMLSerializer serializer) {
    System.out.println("initializeFields: start");
    // TODO: for release 2.1 ... maybe generalizing some test here
    // pushButtons =
    // (ButtonGroup)serializer.getNamespace().get("pushButtons");
    // toggleButtons =
    // (ButtonGroup)serializer.getNamespace().get("toggleButtons");
    // radioButtons =
    // (ButtonGroup)serializer.getNamespace().get("radioButtons");
    // checkButtons =
    // (ButtonGroup)serializer.getNamespace().get("checkButtons");
    // checkTriButtons =
    // (ButtonGroup)serializer.getNamespace().get("checkTriButtons");
    calendarButton1 = (CalendarButton) serializer.getNamespace().get("calendarButton1");
    calendarButton2 = (CalendarButton) serializer.getNamespace().get("calendarButton2");
    spinner1 = (Spinner) serializer.getNamespace().get("spinner1");
    spinner2 = (Spinner) serializer.getNamespace().get("spinner2");
    listView1 = (ListView) serializer.getNamespace().get("listView1");
    listView2 = (ListView) serializer.getNamespace().get("listView2");
    tableView1 = (TableView) serializer.getNamespace().get("tableView1");
    tableView2 = (TableView) serializer.getNamespace().get("tableView2");
    treeView1 = (TreeView) serializer.getNamespace().get("treeView1");
    treeView2 = (TreeView) serializer.getNamespace().get("treeView2");
    listButton1 = (ListButton) serializer.getNamespace().get("listButton1");
    listButton2 = (ListButton) serializer.getNamespace().get("listButton2");
    clearSelectionButton = (PushButton) serializer.getNamespace().get("clearSelectionButton");
    clearSelectionButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            System.out.println("Clearing selection from " + button.getName() + " at " + new Date());
            // TODO: for release 2.1 ... maybe generalizing some test here
            // pushButtons.clearSelection();
            // toggleButtons.clearSelection();
            // radioButtons.clearSelection();
            // checkButtons.clearSelection();
            // checkTriButtons.clearSelection();
            calendarButton1.clearSelection();
            calendarButton2.clearSelection();
            spinner1.clearSelection();
            spinner2.clearSelection();
            listButton1.clearSelection();
            listButton2.clearSelection();
            listView1.clearSelection();
            listView2.clearSelection();
            tableView1.clearSelection();
            tableView2.clearSelection();
            treeView1.clearSelection();
            treeView2.clearSelection();
        }
    });
    clearButton = (PushButton) serializer.getNamespace().get("clearButton");
    clearButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            System.out.println("Clearing data from " + button.getName() + " at " + new Date());
            // TODO: verify for release 2.1 if implement a method to empty
            // components inside ...
            // pushButtons.remove(button);
            // toggleButtons.remove(button);
            // radioButtons.remove(button);
            // checkButtons.remove(button);
            // checkTriButtons.remove(button);
            // force clear of elements data ...
            clearComponent(calendarButton1);
            clearComponent(calendarButton2);
            clearComponent(spinner1);
            clearComponent(spinner2);
            clearComponent(listButton1);
            clearComponent(listButton2);
            clearComponent(listView1);
            clearComponent(listView2);
            clearComponent(tableView1);
            clearComponent(tableView2);
            clearComponent(treeView1);
            clearComponent(treeView2);
        // TODO: put (in bxml) the two tableView in a SplitPane, and see
        // some strange moving mouse over ...
        // TODO: add clear/clearSelection methods even to some type of
        // buttons (all types in the first row displayed) ...
        }
    });
    System.out.println("initializeFields: end");
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) CalendarButton(org.apache.pivot.wtk.CalendarButton) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ListButton(org.apache.pivot.wtk.ListButton) Date(java.util.Date)

Aggregations

CalendarButton (org.apache.pivot.wtk.CalendarButton)12 Button (org.apache.pivot.wtk.Button)6 GradientPaint (java.awt.GradientPaint)5 CalendarDate (org.apache.pivot.util.CalendarDate)5 Point (org.apache.pivot.wtk.Point)5 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 CalendarButtonSelectionListener (org.apache.pivot.wtk.CalendarButtonSelectionListener)2 ListButton (org.apache.pivot.wtk.ListButton)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 GeneralPath (java.awt.geom.GeneralPath)1 RoundRectangle2D (java.awt.geom.RoundRectangle2D)1 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 Date (java.util.Date)1 Locale (java.util.Locale)1 ArrayList (org.apache.pivot.collections.ArrayList)1 SerializationException (org.apache.pivot.serialization.SerializationException)1 Filter (org.apache.pivot.util.Filter)1