Search in sources :

Example 1 with SVGElementException

use of com.kitfox.svg.SVGElementException in project pivot by apache.

the class Pivot964Pivot method startup.

@Override
public void startup(Display display, Map<String, String> properties) {
    // force dimensions for host frame
    display.getHostWindow().setSize(1028, 600);
    window = new Window();
    prepareSVG();
    final ImageView image = new ImageView(new Drawing(diagram));
    BoxPane bp = new BoxPane();
    TablePane tp = new TablePane();
    setStyles(tp, "{padding: 4}");
    TablePane.Column c1 = new TablePane.Column(-1);
    TablePane.Column c2 = new TablePane.Column(-1);
    tp.getColumns().add(c1);
    tp.getColumns().add(c2);
    TablePane.Row r1 = new TablePane.Row(-1);
    TablePane.Row r2 = new TablePane.Row(-1);
    TablePane.Row r3 = new TablePane.Row(-1);
    PushButton pb1 = new PushButton("Visible");
    PushButton pb2 = new PushButton("Invisible (bug)");
    r1.add(pb1);
    r1.add(pb2);
    final Spinner sp1 = new Spinner(new ListAdapter<>(spinnerData));
    sp1.setPreferredWidth(80);
    sp1.setSelectedIndex(0);
    final Spinner sp2 = new Spinner(new ListAdapter<>(spinnerData));
    sp2.setPreferredWidth(80);
    sp2.setSelectedIndex(0);
    BoxPane bp1 = new BoxPane();
    setStyles(bp1, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp1.add(new Label("X:"));
    bp1.add(sp1);
    r2.add(bp1);
    BoxPane bp2 = new BoxPane();
    setStyles(bp2, "{verticalAlignment:'center', padding: 4, spacing: 2}");
    bp2.add(new Label("Y:"));
    bp2.add(sp2);
    r2.add(bp2);
    tp.getRows().add(r1);
    tp.getRows().add(r2);
    r3.add(new Label("   Max X=507"));
    r3.add(new Label("   Max Y=269"));
    tp.getRows().add(r3);
    bp.add(image);
    bp.add(tp);
    pb1.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    pb2.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button arg0) {
            try {
                String xOffset = (String) sp1.getSelectedItem();
                String yOffset = (String) sp2.getSelectedItem();
                String viewBox = String.format("%1$s %2$s 2368 1652", xOffset, yOffset);
                root.setAttribute("viewBox", AnimationElement.AT_XML, viewBox);
                root.updateTime(0f);
                image.repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    window.setContent(bp);
    window.setMaximized(true);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) Drawing(org.apache.pivot.wtk.media.Drawing) Spinner(org.apache.pivot.wtk.Spinner) SVGException(com.kitfox.svg.SVGException) Label(org.apache.pivot.wtk.Label) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) BoxPane(org.apache.pivot.wtk.BoxPane) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) ImageView(org.apache.pivot.wtk.ImageView) SVGElementException(com.kitfox.svg.SVGElementException) PushButton(org.apache.pivot.wtk.PushButton) TablePane(org.apache.pivot.wtk.TablePane)

Example 2 with SVGElementException

use of com.kitfox.svg.SVGElementException in project pivot by apache.

the class Drawing method setSize.

public void setSize(int width, int height) {
    int previousWidth = getWidth();
    int previousHeight = getHeight();
    SVGRoot root = diagram.getRoot();
    try {
        root.setAttribute("width", AnimationElement.AT_XML, Integer.toString(width));
        root.setAttribute("height", AnimationElement.AT_XML, Integer.toString(height));
    } catch (SVGElementException exception) {
        throw new RuntimeException(exception);
    }
    try {
        diagram.updateTime(0.0);
    } catch (SVGException exception) {
        throw new RuntimeException(exception);
    }
    imageListeners.sizeChanged(this, previousWidth, previousHeight);
}
Also used : SVGRoot(com.kitfox.svg.SVGRoot) SVGException(com.kitfox.svg.SVGException) SVGElementException(com.kitfox.svg.SVGElementException)

Example 3 with SVGElementException

use of com.kitfox.svg.SVGElementException in project pivot by apache.

the class TestPanel method initComponents.

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
    panelDisplay = new javax.swing.JPanel();
    button1 = new javax.swing.JButton();
    button2 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    panelDisplay.setLayout(new java.awt.BorderLayout());
    getContentPane().add(panelDisplay, java.awt.BorderLayout.CENTER);
    button1.setText("Visible");
    button1.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            SVGElement root = Pivot964Swing.this.panel.root;
            try {
                root.setAttribute("viewBox", AnimationElement.AT_XML, "0 0 2368 1652");
                root.updateTime(0f);
                repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    button2.setText("Invisible");
    button2.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            SVGElement root = Pivot964Swing.this.panel.root;
            try {
                root.setAttribute("viewBox", AnimationElement.AT_XML, "800 0 2368 1652");
                root.updateTime(0f);
                repaint();
            } catch (SVGElementException e) {
                e.printStackTrace();
            } catch (SVGException e) {
                e.printStackTrace();
            }
        }
    });
    panelDisplay.add(button1, java.awt.BorderLayout.EAST);
    panelDisplay.add(button2, java.awt.BorderLayout.WEST);
    pack();
}
Also used : SVGElement(com.kitfox.svg.SVGElement) SVGException(com.kitfox.svg.SVGException) SVGElementException(com.kitfox.svg.SVGElementException) BorderLayout(java.awt.BorderLayout) JPanel(javax.swing.JPanel)

Aggregations

SVGElementException (com.kitfox.svg.SVGElementException)3 SVGException (com.kitfox.svg.SVGException)3 SVGElement (com.kitfox.svg.SVGElement)1 SVGRoot (com.kitfox.svg.SVGRoot)1 BorderLayout (java.awt.BorderLayout)1 JPanel (javax.swing.JPanel)1 BoxPane (org.apache.pivot.wtk.BoxPane)1 Button (org.apache.pivot.wtk.Button)1 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)1 ImageView (org.apache.pivot.wtk.ImageView)1 Label (org.apache.pivot.wtk.Label)1 PushButton (org.apache.pivot.wtk.PushButton)1 Spinner (org.apache.pivot.wtk.Spinner)1 TablePane (org.apache.pivot.wtk.TablePane)1 Window (org.apache.pivot.wtk.Window)1 Drawing (org.apache.pivot.wtk.media.Drawing)1