Package com.nexirius.framework.gadgets

Source Code of com.nexirius.framework.gadgets.TestLayoutPanel$MyModelListener

//{HEADER
/**
* This class is part of jnex 'Nexirius Application Framework for Java'
* Copyright (C) Nexirius GmbH, CH-4450 Sissach, Switzerland (www.nexirius.ch)
*
* <p>This library is free software; you can redistribute it and/or<br>
* modify it under the terms of the GNU Lesser General Public<br>
* License as published by the Free Software Foundation; either<br>
* version 2.1 of the License, or (at your option) any later version.</p>
*
* <p>This library is distributed in the hope that it will be useful,<br>
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
* Lesser General Public License for more details.</p>
*
* <p>You should have received a copy of the GNU Lesser General Public<br>
* License along with this library; if not, write to the Free Software<br>
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</p>
* </blockquote>
*
* <p>
* Nexirius GmbH, hereby disclaims all copyright interest in<br>
* the library jnex' 'Nexirius Application Framework for Java' written<br>
* by Marcel Baumann.</p>
*/
//}HEADER
package com.nexirius.framework.gadgets;

import com.nexirius.framework.datamodel.*;
import com.nexirius.framework.dataviewer.ImageViewer;
import com.nexirius.framework.dataviewer.ImageViewerCreator;
import com.nexirius.framework.dataviewer.ProgressViewerCreator;
import com.nexirius.framework.dataviewer.ViewerFactory;
import com.nexirius.util.XFile;

import javax.swing.*;
import java.awt.*;

public class TestLayoutPanel {



    JFrame frame;
    LayoutPanel panel;
    ViewerFactory factory;
    XFile file;

    public static void main(String argv[]) throws Exception {
        new TestLayoutPanel().run();
    }

    public void run() throws Exception {
        file = new XFile("C:\\temp\\TestLayoutPanel.txt");

        factory = ViewerFactory.getDefaultInstance("TestLayoutPanel");

        frame = new JFrame("TestLayoutPanel");
        panel = new LayoutPanel();

        frame.getContentPane().setLayout(new BorderLayout());
        frame.getContentPane().add(panel, BorderLayout.CENTER);
        frame.getContentPane().add(new JLabel("WEST"), BorderLayout.WEST);
        frame.getContentPane().add(new JLabel("NORTH"), BorderLayout.NORTH);

        JButton button = new JButton("Button");
        JLabel label = new JLabel("Label");

        label.setLocation(100, 100);
        label.setName("This is the JLabel");
        label.setOpaque(true);
        label.setBackground(Color.yellow);
        label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
        button.setName("The JButton");

        panel.add(button);
        panel.add(label);
        panel.add(new JLabel("LABEL2"));

        FileNameModel filename = new FileNameModel("", "filename");
        LimitIntModel limit = new LimitIntModel(10, 0, 100, "progress");

        panel.add(factory.createDefaultEditor(filename).getJComponent());
        panel.add(factory.createViewer(new ProgressViewerCreator(), limit).getJComponent());
        ImageViewerCreator creator = new ImageViewerCreator();

        ImageViewer viewer = (ImageViewer) factory.createViewer(creator, filename);
        viewer.setAutoFit(true);
        panel.add(viewer.getJComponent());
        panel.add(factory.createDefaultEditor(limit).getJComponent());

        panel.add(factory.createDefaultEditor(panel.getModel()).getJComponent());


        //panel.add(factory.createDefaultEditor(panel.getModel()).getJComponent());

        if (file.exists()) {
            panel.getModel().dropData(new String(file.getBytes()));
            panel.updateLayout();
        }

        frame.pack();
        frame.setVisible(true);

        JFrame frame2 = new JFrame(panel.getModel().getFieldName());

        frame2.getContentPane().setLayout(new GridLayout(1, 1));
        frame2.getContentPane().add(factory.createDefaultEditor(panel.getModel()).getJComponent(), BorderLayout.SOUTH);
        frame2.setLocation(300, 300);
        frame2.pack();
        frame2.setVisible(true);
        frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        panel.getModel().addDataModelListener(new MyModelListener());
    }

    class MyModelListener extends DataModelAdaptor {
        public void dataModelChangeValue(DataModelEvent event) {
            try {
                file.writeText(panel.getModel().dragData());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public void dataModelGrabFocus(DataModelEvent event) {
            System.out.println(event);
            DataModel model = panel.getModel().getActiveComponentModel();
            JFrame frame = new JFrame(model.getFieldName());

            frame.getContentPane().setLayout(new GridLayout(1, 1));

            try {
                frame.getContentPane().add(factory.createDefaultEditor(model).getJComponent());
            } catch (Exception e) {
                e.printStackTrace();
            }

            frame.setLocation(300, 300);
            frame.pack();
            frame.setVisible(true);
        }
    }
}
TOP

Related Classes of com.nexirius.framework.gadgets.TestLayoutPanel$MyModelListener

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.