Example usage for javax.swing JSplitPane addPropertyChangeListener

List of usage examples for javax.swing JSplitPane addPropertyChangeListener

Introduction

In this page you can find the example usage for javax.swing JSplitPane addPropertyChangeListener.

Prototype

public void addPropertyChangeListener(PropertyChangeListener listener) 

Source Link

Document

Adds a PropertyChangeListener to the listener list.

Usage

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Property Split");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

    splitPane.setTopComponent(new JLabel("www.java2s.com"));

    splitPane.setBottomComponent(new JLabel("www.java2s.com"));

    PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent changeEvent) {
            JSplitPane sourceSplitPane = (JSplitPane) changeEvent.getSource();
            String propertyName = changeEvent.getPropertyName();
            if (propertyName.equals(JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY)) {
                int current = sourceSplitPane.getDividerLocation();
                System.out.println("Current: " + current);
                Integer last = (Integer) changeEvent.getNewValue();
                System.out.println("Last: " + last);
                Integer priorLast = (Integer) changeEvent.getOldValue();
                System.out.println("Prior last: " + priorLast);
            }/*from   ww w. j  a  va 2s. c  o  m*/
        }
    };

    // Attach listener
    splitPane.addPropertyChangeListener(propertyChangeListener);

    frame.add(splitPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:PropertySplitPane.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Property Split");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setContinuousLayout(true);
    splitPane.setOneTouchExpandable(true);

    JComponent topComponent = new JButton("A");
    splitPane.setTopComponent(topComponent);

    JComponent bottomComponent = new JButton("B");
    splitPane.setBottomComponent(bottomComponent);

    PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent changeEvent) {
            JSplitPane sourceSplitPane = (JSplitPane) changeEvent.getSource();
            String propertyName = changeEvent.getPropertyName();
            if (propertyName.equals(JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY)) {
                int current = sourceSplitPane.getDividerLocation();
                System.out.println("Current: " + current);
                Integer last = (Integer) changeEvent.getNewValue();
                System.out.println("Last: " + last);
                Integer priorLast = (Integer) changeEvent.getOldValue();
                System.out.println("Prior last: " + priorLast);
            }//from w  w  w .ja  v  a  2 s. c om
        }
    };

    splitPane.addPropertyChangeListener(propertyChangeListener);

    frame.add(splitPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:com.qspin.qtaste.ui.MainPanel.java

public void genUI() {
    try {//w ww. jav a2 s.c om
        getContentPane().setLayout(new BorderLayout());
        // prepare the top panel that contains the following panes:
        //   - logo
        //   - ConfigInfopanel
        //   - Current Date/time
        JPanel topanel = new JPanel(new BorderLayout());
        JPanel center = new JPanel(new GridBagLayout());
        ImageIcon topLeftLogo = ResourceManager.getInstance().getImageIcon("main/qspin");
        JLabel iconlabel = new JLabel(topLeftLogo);

        mHeaderPanel = new ConfigInfoPanel(this);
        mTestCasePanel = new TestCasePane(this);
        mTestCampaignPanel = new TestCampaignMainPanel(this);

        mHeaderPanel.init();

        GridBagLineAdder centeradder = new GridBagLineAdder(center);
        JLabel sep = new JLabel("  ");
        sep.setFont(ResourceManager.getInstance().getSmallFont());
        sep.setUI(new FillLabelUI(ResourceManager.getInstance().getLightColor()));
        centeradder.setWeight(1.0f, 0.0f);
        centeradder.add(mHeaderPanel);

        // prepare the right panels containg the main information:
        // the right pane is selected through the tabbed pane:
        //    - Test cases: management of test cases and test suites
        //    - Test campaign: management of test campaigns
        //    - Interactive: ability to invoke QTaste verbs one by one

        mRightPanels = new JPanel(new CardLayout());

        mRightPanels.add(mTestCasePanel, "Test Cases");
        mRightPanels.add(mTestCampaignPanel, "Test Campaign");

        final TestCaseInteractivePanel testInterractivePanel = new TestCaseInteractivePanel();
        mRightPanels.add(testInterractivePanel, "Interactive");

        mTreeTabsPanel = new JTabbedPane(JTabbedPane.BOTTOM);
        mTreeTabsPanel.setPreferredSize(new Dimension(TREE_TABS_WIDTH, HEIGHT));

        TestCaseTree tct = new TestCaseTree(mTestCasePanel);
        JScrollPane sp2 = new JScrollPane(tct);
        mTreeTabsPanel.addTab("Test Cases", sp2);

        // add tree view for test campaign definition
        com.qspin.qtaste.ui.testcampaign.TestCaseTree mtct = new com.qspin.qtaste.ui.testcampaign.TestCaseTree(
                mTestCampaignPanel.getTreeTable());
        JScrollPane sp3 = new JScrollPane(mtct);
        mTreeTabsPanel.addTab("Test Campaign", sp3);

        genMenu(tct);

        // add another tab contain used for Interactive mode
        TestAPIDocsTree jInteractive = new TestAPIDocsTree(testInterractivePanel);
        JScrollPane spInter = new JScrollPane(jInteractive);
        mTreeTabsPanel.addTab("Interactive", spInter);

        // init will do the link between the tree view and the pane
        testInterractivePanel.init();

        // Define the listener to display the pane depending on the selected tab
        mTreeTabsPanel.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                String componentName = mTreeTabsPanel.getTitleAt(mTreeTabsPanel.getSelectedIndex());
                CardLayout rcl = (CardLayout) mRightPanels.getLayout();
                rcl.show(mRightPanels, componentName);
            }
        });
        mTestCampaignPanel.addTestCampaignActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (e.getID() == TestCampaignMainPanel.RUN_ID) {
                    if (e.getActionCommand().equals(TestCampaignMainPanel.STARTED_CMD)) {
                        // open the tab test cases
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                mTreeTabsPanel.setSelectedIndex(0);
                                mTestCasePanel.setSelectedTab(TestCasePane.RESULTS_INDEX);
                            }
                        });

                        // update the buttons
                        mTestCasePanel.setExecutingTestCampaign(true,
                                ((TestCampaignMainPanel) e.getSource()).getExecutionThread());
                        mTestCasePanel.updateButtons(true);
                    } else if (e.getActionCommand().equals(TestCampaignMainPanel.STOPPED_CMD)) {
                        mTestCasePanel.setExecutingTestCampaign(false, null);
                        mTestCasePanel.updateButtons();
                    }
                }
            }
        });

        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mTreeTabsPanel, mRightPanels);
        splitPane.setDividerSize(4);
        GUIConfiguration guiConfiguration = GUIConfiguration.getInstance();
        int mainHorizontalSplitDividerLocation = guiConfiguration
                .getInt(MAIN_HORIZONTAL_SPLIT_DIVIDER_LOCATION_PROPERTY, 285);
        splitPane.setDividerLocation(mainHorizontalSplitDividerLocation);

        splitPane.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("dividerLocation")) {
                    GUIConfiguration guiConfiguration = GUIConfiguration.getInstance();
                    if (evt.getSource() instanceof JSplitPane) {
                        JSplitPane splitPane = (JSplitPane) evt.getSource();
                        guiConfiguration.setProperty(MAIN_HORIZONTAL_SPLIT_DIVIDER_LOCATION_PROPERTY,
                                splitPane.getDividerLocation());
                        try {
                            guiConfiguration.save();
                        } catch (ConfigurationException ex) {
                            logger.error("Error while saving GUI configuration: " + ex.getMessage());
                        }
                    }
                }
            }
        });

        topanel.add(iconlabel, BorderLayout.WEST);
        topanel.add(center);

        getContentPane().add(topanel, BorderLayout.NORTH);
        getContentPane().add(splitPane);
        this.pack();

        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        if (mTestSuiteDir != null) {
            DirectoryTestSuite testSuite = DirectoryTestSuite.createDirectoryTestSuite(mTestSuiteDir);
            if (testSuite != null) {
                testSuite.setExecutionLoops(mNumberLoops, mLoopsInHour);
                setTestSuite(testSuite.getName());
                mTestCasePanel.runTestSuite(testSuite, false);
            }
        }
        setVisible(true);
        //treeTabs.setMinimumSize(new Dimension(100, this.HEIGHT));

    } catch (Exception e) {
        logger.fatal(e);
        e.printStackTrace();
        TestEngine.shutdown();
        System.exit(1);
    }

}

From source file:com.net2plan.gui.tools.GUINetworkDesign.java

@Override
public void configure(JPanel contentPane) {
    this.currentNetPlan = new NetPlan();

    BidiMap<NetworkLayer, Integer> mapLayer2VisualizationOrder = new DualHashBidiMap<>();
    Map<NetworkLayer, Boolean> layerVisibilityMap = new HashMap<>();
    for (NetworkLayer layer : currentNetPlan.getNetworkLayers()) {
        mapLayer2VisualizationOrder.put(layer, mapLayer2VisualizationOrder.size());
        layerVisibilityMap.put(layer, true);
    }/*  w ww  .  j  a va 2  s  . c o m*/
    this.vs = new VisualizationState(currentNetPlan, mapLayer2VisualizationOrder, layerVisibilityMap,
            MAXSIZEUNDOLISTPICK);

    topologyPanel = new TopologyPanel(this, JUNGCanvas.class);

    JPanel leftPane = new JPanel(new BorderLayout());
    JPanel logSection = configureLeftBottomPanel();
    if (logSection == null) {
        leftPane.add(topologyPanel, BorderLayout.CENTER);
    } else {
        JSplitPane splitPaneTopology = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        splitPaneTopology.setTopComponent(topologyPanel);
        splitPaneTopology.setBottomComponent(logSection);
        splitPaneTopology.addPropertyChangeListener(new ProportionalResizeJSplitPaneListener());
        splitPaneTopology.setBorder(new LineBorder(contentPane.getBackground()));
        splitPaneTopology.setOneTouchExpandable(true);
        splitPaneTopology.setDividerSize(7);
        leftPane.add(splitPaneTopology, BorderLayout.CENTER);
    }
    contentPane.add(leftPane, "grow");

    viewEditTopTables = new ViewEditTopologyTablesPane(GUINetworkDesign.this, new BorderLayout());

    reportPane = new ViewReportPane(GUINetworkDesign.this, JSplitPane.VERTICAL_SPLIT);

    setCurrentNetPlanDoNotUpdateVisualization(currentNetPlan);
    Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = VisualizationState
            .generateCanvasDefaultVisualizationLayerInfo(getDesign());
    vs.setCanvasLayerVisibilityAndOrder(getDesign(), res.getFirst(), res.getSecond());

    /* Initialize the undo/redo manager, and set its initial design */
    this.undoRedoManager = new UndoRedoManager(this, MAXSIZEUNDOLISTCHANGES);
    this.undoRedoManager.addNetPlanChange();

    onlineSimulationPane = new OnlineSimulationPane(this);
    executionPane = new OfflineExecutionPanel(this);
    whatIfAnalysisPane = new WhatIfAnalysisPane(this);

    // Closing windows
    WindowUtils.clearFloatingWindows();

    final JTabbedPane tabPane = new JTabbedPane();
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.network),
            viewEditTopTables);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.offline), executionPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.online),
            onlineSimulationPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.whatif),
            whatIfAnalysisPane);
    tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.report), reportPane);

    // Installing customized mouse listener
    MouseListener[] ml = tabPane.getListeners(MouseListener.class);

    for (int i = 0; i < ml.length; i++) {
        tabPane.removeMouseListener(ml[i]);
    }

    // Left click works as usual, right click brings up a pop-up menu.
    tabPane.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JTabbedPane tabPane = (JTabbedPane) e.getSource();

            int tabIndex = tabPane.getUI().tabForCoordinate(tabPane, e.getX(), e.getY());

            if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) {
                if (tabIndex == tabPane.getSelectedIndex()) {
                    if (tabPane.isRequestFocusEnabled()) {
                        tabPane.requestFocus();

                        tabPane.repaint(tabPane.getUI().getTabBounds(tabPane, tabIndex));
                    }
                } else {
                    tabPane.setSelectedIndex(tabIndex);
                }

                if (!tabPane.isEnabled() || SwingUtilities.isRightMouseButton(e)) {
                    final JPopupMenu popupMenu = new JPopupMenu();

                    final JMenuItem popWindow = new JMenuItem("Pop window out");
                    popWindow.addActionListener(e1 -> {
                        final int selectedIndex = tabPane.getSelectedIndex();
                        final String tabName = tabPane.getTitleAt(selectedIndex);
                        final JComponent selectedComponent = (JComponent) tabPane.getSelectedComponent();

                        // Pops up the selected tab.
                        final WindowController.WindowToTab windowToTab = WindowController.WindowToTab
                                .parseString(tabName);

                        if (windowToTab != null) {
                            switch (windowToTab) {
                            case offline:
                                WindowController.buildOfflineWindow(selectedComponent);
                                WindowController.showOfflineWindow(true);
                                break;
                            case online:
                                WindowController.buildOnlineWindow(selectedComponent);
                                WindowController.showOnlineWindow(true);
                                break;
                            case whatif:
                                WindowController.buildWhatifWindow(selectedComponent);
                                WindowController.showWhatifWindow(true);
                                break;
                            case report:
                                WindowController.buildReportWindow(selectedComponent);
                                WindowController.showReportWindow(true);
                                break;
                            default:
                                return;
                            }
                        }

                        tabPane.setSelectedIndex(0);
                    });

                    // Disabling the pop up button for the network state tab.
                    if (WindowController.WindowToTab.parseString(tabPane
                            .getTitleAt(tabPane.getSelectedIndex())) == WindowController.WindowToTab.network) {
                        popWindow.setEnabled(false);
                    }

                    popupMenu.add(popWindow);

                    popupMenu.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });

    // Building windows
    WindowController.buildTableControlWindow(tabPane);
    WindowController.showTablesWindow(false);

    addAllKeyCombinationActions();
    updateVisualizationAfterNewTopology();
}

From source file:org.tros.torgo.ControllerBase.java

/**
 * Initialize the window. This is called here from run() and not the
 * constructor so that the Service Provider doesn't load up all of the
 * necessary resources when the application loads.
 *///w  w w  .  ja  v  a2s.  co m
private void initSwing() {
    this.torgoPanel = createConsole((Controller) this);
    this.torgoCanvas = createCanvas(torgoPanel);

    //init the GUI w/ the components...
    Container contentPane = window.getContentPane();
    JToolBar tb = createToolBar();
    if (tb != null) {
        contentPane.add(tb, BorderLayout.NORTH);
    }

    final java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(NamedWindow.class);
    if (torgoCanvas != null) {
        final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, torgoCanvas.getComponent(),
                torgoPanel.getComponent());
        int dividerLocation = prefs.getInt(this.getClass().getName() + "divider-location",
                window.getWidth() - 300);
        splitPane.setDividerLocation(dividerLocation);
        splitPane.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent pce) {
                prefs.putInt(this.getClass().getName() + "divider-location", splitPane.getDividerLocation());
            }
        });

        contentPane.add(splitPane);
    } else {
        contentPane.add(torgoPanel.getComponent());
    }

    JMenuBar mb = createMenuBar();
    if (mb == null) {
        mb = new TorgoMenuBar(window, this);
    }
    window.setJMenuBar(mb);
    JMenu helpMenu = new JMenu("Help");
    JMenuItem aboutMenu = new JMenuItem("About Torgo");
    try {
        java.util.Enumeration<URL> resources = ClassLoader.getSystemClassLoader()
                .getResources(ABOUT_MENU_TORGO_ICON);
        ImageIcon ico = new ImageIcon(resources.nextElement());
        aboutMenu.setIcon(ico);
    } catch (IOException ex) {
        Logger.getLogger(ControllerBase.class.getName()).log(Level.SEVERE, null, ex);
    }

    aboutMenu.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            AboutWindow aw = new AboutWindow();
            aw.setVisible(true);
        }
    });
    helpMenu.add(aboutMenu);

    JMenu vizMenu = new JMenu("Visualization");
    for (String name : TorgoToolkit.getVisualizers()) {
        JCheckBoxMenuItem item = new JCheckBoxMenuItem(name);
        viz.add(item);
        vizMenu.add(item);
    }
    if (vizMenu.getItemCount() > 0) {
        mb.add(vizMenu);
    }

    mb.add(helpMenu);
    window.setJMenuBar(mb);

    window.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(WindowEvent e) {
        }

        /**
         * We only care if the window is closing so we can kill the
         * interpreter thread.
         *
         * @param e
         */
        @Override
        public void windowClosing(WindowEvent e) {
            stopInterpreter();
        }

        @Override
        public void windowClosed(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }
    });
}