Search in sources :

Example 1 with ChartBounds

use of com.ramussoft.chart.core.ChartBounds in project ramus by Vitaliy-Yakovchuk.

the class ChartSetView method createComponent.

@Override
public JComponent createComponent() {
    final JLabel label = new JLabel(ChartResourceManager.getString("Message.MoveChartToChartSet"));
    desktop = new JDesktopPane();
    desktop.setTransferHandler(new TransferHandler("") {

        /**
         */
        private static final long serialVersionUID = 4967256166603971141L;

        @Override
        public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
            for (DataFlavor flavor : transferFlavors) {
                if (flavor.equals(RowTreeTable.rowsListFlavor)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public boolean importData(JComponent comp, Transferable t) {
            try {
                Rows rows = (Rows) t.getTransferData(RowTreeTable.rowsListFlavor);
                if (rows.size() > 0) {
                    ((Journaled) engine).startUserTransaction();
                    for (Row row : rows) {
                        Point position = comp.getMousePosition();
                        if (position == null)
                            position = new Point(10, 10);
                        ChartPlugin.addChartLink(engine, element, row.getElement(), position.getX(), position.getY(), 340, 300);
                    }
                }
                ((Journaled) engine).commitUserTransaction();
                return rows.size() > 0;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return false;
        }
    });
    label.setBackground(desktop.getBackground());
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    List<ChartBounds> bounds = ChartPlugin.getChartBounds(engine, element);
    for (ChartBounds cb : bounds) {
        final JInternalFrame frame = new JInternalFrame(cb.getChart().getName(), true, true, true, true);
        final ChartView chartView = new ChartView(framework, cb.getChart()) {

            protected void titleChanged(String newTitle) {
                frame.setTitle(newTitle);
                reload();
            }
        };
        final ChartBounds b = cb;
        frame.setSize((int) cb.getWidth(), (int) cb.getHeight());
        frame.setLocation((int) cb.getX(), (int) cb.getY());
        frame.setContentPane(chartView.createComponent());
        desktop.add(frame);
        frame.setVisible(true);
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                ChartHolder holder = new ChartHolder(chartView, frame, b.getLink());
                holders.add(holder);
            }
        });
    }
    return desktop;
}
Also used : JDesktopPane(javax.swing.JDesktopPane) JComponent(javax.swing.JComponent) Transferable(java.awt.datatransfer.Transferable) JLabel(javax.swing.JLabel) Point(java.awt.Point) PrinterException(java.awt.print.PrinterException) DataFlavor(java.awt.datatransfer.DataFlavor) TransferHandler(javax.swing.TransferHandler) ChartBounds(com.ramussoft.chart.core.ChartBounds) Row(com.ramussoft.database.common.Row) JInternalFrame(javax.swing.JInternalFrame) Rows(com.ramussoft.gui.qualifier.table.Rows)

Aggregations

ChartBounds (com.ramussoft.chart.core.ChartBounds)1 Row (com.ramussoft.database.common.Row)1 Rows (com.ramussoft.gui.qualifier.table.Rows)1 Point (java.awt.Point)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 Transferable (java.awt.datatransfer.Transferable)1 PrinterException (java.awt.print.PrinterException)1 JComponent (javax.swing.JComponent)1 JDesktopPane (javax.swing.JDesktopPane)1 JInternalFrame (javax.swing.JInternalFrame)1 JLabel (javax.swing.JLabel)1 TransferHandler (javax.swing.TransferHandler)1