Search in sources :

Example 6 with AdjustmentListener

use of java.awt.event.AdjustmentListener in project artisynth_core by artisynth.

the class TimelineController method displaySetup.

private void displaySetup() {
    timescale.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            double cursorTime = timescale.getTimescaleCursorTime();
            // adjusted manually, then the restart time must be changed
            if (!myScheduler.isPlaying() && timescale.isTimeManuallyDragged()) {
                // be reset to any time corresponding to the timeline cursor
                if (!myMain.getWorkspace().rootModelHasState()) {
                    myScheduler.setTime(cursorTime);
                } else // Else only reset the scheduler time to the closest valid
                // waypoint when the cursor is dragged past a valid waypoint
                {
                    setRestartTime(TimelineConstants.RESTART_BY_CURSOR_DRAG);
                }
            }
            // See if the duration of the timeline has to be extended
            if (cursorTime >= 0.9 * timescale.getMaximumTime()) {
                extendTimeline();
            }
            if (timescale.isTimeManuallyDragged()) {
                requestUpdateWidgets();
            }
        }
    });
    timelineScrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {

        public void adjustmentValueChanged(AdjustmentEvent e) {
            requestUpdateDisplay();
        }
    });
    timelineScrollPane.setViewportView(timelinePane);
    JScrollPane workspaceScrollPane = new JScrollPane(workspacePane);
    timelineScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    // Set the workspace scrollpane not to show vertical scroll bar
    workspaceScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
    workspaceScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // Synchronize scrollbars of workspace and timeline panels
    timelineScrollPane.getVerticalScrollBar().setModel(workspaceScrollPane.getVerticalScrollBar().getModel());
    mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, workspaceScrollPane, timelineScrollPane);
    mainSplitPane.setDividerLocation(GuiStorage.TIMELINE_PANEL_WIDTH);
    mainSplitPane.setDividerSize(SPLIT_DIVIDER_SIZE);
    mainSplitPane.setContinuousLayout(true);
    mainSplitPane.addPropertyChangeListener("dividerLocation", new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent pc_evt) {
            updateComponentSizes();
        }
    });
    Container contentPane = getContentPane();
    contentPane.add(myToolBar, BorderLayout.PAGE_START);
    contentPane.add(mainSplitPane);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation(screenSize.width / 6, screenSize.height / 6);
    setSize(screenSize.width * 1 / 2, screenSize.height * 1 / 4);
    updateComponentSizes();
}
Also used : JScrollPane(javax.swing.JScrollPane) PropertyChangeEvent(java.beans.PropertyChangeEvent) Container(java.awt.Container) ValueChangeEvent(maspack.widgets.ValueChangeEvent) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) AdjustmentEvent(java.awt.event.AdjustmentEvent) AdjustmentListener(java.awt.event.AdjustmentListener) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) Dimension(java.awt.Dimension) JSplitPane(javax.swing.JSplitPane)

Example 7 with AdjustmentListener

use of java.awt.event.AdjustmentListener in project cytoscape-impl by cytoscape.

the class PreviewTablePanel method getTableScrollPane.

private JScrollPane getTableScrollPane() {
    if (tableScrollPane == null) {
        tableScrollPane = new JScrollPane(getPreviewTable());
        tableScrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {

            @Override
            public void adjustmentValueChanged(AdjustmentEvent e) {
                // Realign the Attribute Editor Dialog if it is open
                if (!e.getValueIsAdjusting())
                    positionEditDialog();
            }
        });
    }
    return tableScrollPane;
}
Also used : JScrollPane(javax.swing.JScrollPane) AdjustmentEvent(java.awt.event.AdjustmentEvent) AdjustmentListener(java.awt.event.AdjustmentListener)

Example 8 with AdjustmentListener

use of java.awt.event.AdjustmentListener in project metagenomicsTools by afodor.

the class FragmentRecruiterApp method getLeftPanel.

private JPanel getLeftPanel() {
    JPanel leftPanel = new JPanel();
    leftPanel.setLayout(new BorderLayout());
    leftPanel.add(fragmentPanel, BorderLayout.CENTER);
    leftPanel.add(xScrollBar, BorderLayout.SOUTH);
    leftPanel.add(yScrollBar, BorderLayout.WEST);
    yScrollBar.setVisibleAmount(yScrollBar.getMaximum());
    yScrollBar.setValue(0);
    xScrollBar.setMaximum(10000);
    xScrollBar.setVisibleAmount(xScrollBar.getMaximum());
    xScrollBar.setValue(0);
    yScrollBar.addAdjustmentListener(new AdjustmentListener() {

        public void adjustmentValueChanged(AdjustmentEvent e) {
            fragmentPanel.getSelectedYAxis().updateWithNewValuesFromScrollBar(yScrollBar);
            fragmentPanel.repaint();
            if (lastOptionDialog != null && lastOptionDialog.dialogIsStillActive()) {
                lastOptionDialog.layoutMainPanel();
                lastOptionDialog.validate();
            }
        }
    });
    xScrollBar.addAdjustmentListener(new AdjustmentListener() {

        public void adjustmentValueChanged(AdjustmentEvent e) {
            fragmentPanel.getXAxis().updateWithNewValuesFromScrollBar(xScrollBar);
            fragmentPanel.repaint();
            if (lastOptionDialog != null && lastOptionDialog.dialogIsStillActive()) {
                lastOptionDialog.layoutMainPanel();
                lastOptionDialog.validate();
            }
        }
    });
    return leftPanel;
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) AdjustmentEvent(java.awt.event.AdjustmentEvent) AdjustmentListener(java.awt.event.AdjustmentListener)

Example 9 with AdjustmentListener

use of java.awt.event.AdjustmentListener in project CodenameOne by codenameone.

the class SEBrowserComponent method init.

private static void init(SEBrowserComponent self, BrowserComponent p) {
    final WeakReference<SEBrowserComponent> weakSelf = new WeakReference<>(self);
    final WeakReference<BrowserComponent> weakP = new WeakReference<>(p);
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            SEBrowserComponent self = weakSelf.get();
            if (self == null) {
                return;
            }
            self.cnt = new InternalJPanel(self.instance, self);
            // <--- Important if container is opaque it will cause
            self.cnt.setOpaque(false);
            // all kinds of flicker due to painting conflicts with CN1 pipeline.
            self.cnt.setLayout(new BorderLayout());
            self.cnt.add(BorderLayout.CENTER, self.panel);
        // cnt.setVisible(false);
        }
    });
    self.web.getEngine().getLoadWorker().messageProperty().addListener(new ChangeListener<String>() {

        @Override
        public void changed(ObservableValue<? extends String> ov, String t, String t1) {
            SEBrowserComponent self = weakSelf.get();
            BrowserComponent p = weakP.get();
            if (self == null || p == null) {
                return;
            }
            if (t1.startsWith("Loading http:") || t1.startsWith("Loading file:") || t1.startsWith("Loading https:")) {
                String url = t1.substring("Loading ".length());
                if (!url.equals(self.currentURL)) {
                    p.fireWebEvent("onStart", new ActionEvent(url));
                }
                self.currentURL = url;
            } else if ("Loading complete".equals(t1)) {
            }
        }
    });
    self.web.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {

        @Override
        public void handle(WebEvent<String> t) {
            BrowserComponent p = weakP.get();
            if (p == null) {
                return;
            }
            String msg = t.getData();
            if (msg.startsWith("!cn1_message:")) {
                System.out.println("Receiving message " + msg);
                p.fireWebEvent("onMessage", new ActionEvent(msg.substring("!cn1_message:".length())));
            }
        }
    });
    self.web.getEngine().getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() {

        @Override
        public void changed(ObservableValue<? extends Throwable> ov, Throwable t, Throwable t1) {
            System.out.println("Received exception: " + t1.getMessage());
            if (ov.getValue() != null) {
                ov.getValue().printStackTrace();
            }
            if (t != ov.getValue() && t != null) {
                t.printStackTrace();
            }
            if (t1 != ov.getValue() && t1 != t && t1 != null) {
                t.printStackTrace();
            }
        }
    });
    self.web.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {

        @Override
        public void changed(ObservableValue ov, State oldState, State newState) {
            SEBrowserComponent self = weakSelf.get();
            BrowserComponent p = weakP.get();
            try {
                netscape.javascript.JSObject w = (netscape.javascript.JSObject) self.web.getEngine().executeScript("window");
                if (w == null) {
                    System.err.println("Could not get window");
                } else {
                    Bridge b = new Bridge(p);
                    self.putClientProperty("SEBrowserComponent.Bridge.jconsole", b);
                    w.setMember("jconsole", b);
                }
            } catch (Throwable t) {
                Log.e(t);
            }
            if (self == null || p == null) {
                return;
            }
            String url = self.web.getEngine().getLocation();
            if (newState == State.SCHEDULED) {
                p.fireWebEvent("onStart", new ActionEvent(url));
            } else if (newState == State.RUNNING) {
                p.fireWebEvent("onLoadResource", new ActionEvent(url));
            } else if (newState == State.SUCCEEDED) {
                if (!p.isNativeScrollingEnabled()) {
                    self.web.getEngine().executeScript("document.body.style.overflow='hidden'");
                }
                // let's just add a client property to the BrowserComponent to enable firebug
                if (Boolean.TRUE.equals(p.getClientProperty("BrowserComponent.firebug"))) {
                    self.web.getEngine().executeScript("if (!document.getElementById('FirebugLite')){E = document['createElement' + 'NS'] && document.documentElement.namespaceURI;E = E ? document['createElement' + 'NS'](E, 'script') : document['createElement']('script');E['setAttribute']('id', 'FirebugLite');E['setAttribute']('src', 'https://getfirebug.com/' + 'firebug-lite.js' + '#startOpened');E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);E = new Image;E['setAttribute']('src', 'https://getfirebug.com/' + '#startOpened');}");
                }
                netscape.javascript.JSObject window = (netscape.javascript.JSObject) self.web.getEngine().executeScript("window");
                Bridge b = new Bridge(p);
                self.putClientProperty("SEBrowserComponent.Bridge.cn1application", b);
                window.setMember("cn1application", b);
                self.web.getEngine().executeScript("while (window._cn1ready && window._cn1ready.length > 0) {var f = window._cn1ready.shift(); f();}");
                // System.out.println("cn1application is "+self.web.getEngine().executeScript("window.cn1application && window.cn1application.shouldNavigate"));
                self.web.getEngine().executeScript("window.addEventListener('unload', function(e){console.log('unloading...');return 'foobar';});");
                p.fireWebEvent("onLoad", new ActionEvent(url));
            }
            self.currentURL = url;
            self.repaint();
        }
    });
    self.web.getEngine().getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() {

        @Override
        public void changed(ObservableValue<? extends Throwable> ov, Throwable t, Throwable t1) {
            BrowserComponent p = weakP.get();
            if (p == null) {
                return;
            }
            t1.printStackTrace();
            if (t1 == null) {
                if (t == null) {
                    p.fireWebEvent("onError", new ActionEvent("Unknown error", -1));
                } else {
                    p.fireWebEvent("onError", new ActionEvent(t.getMessage(), -1));
                }
            } else {
                p.fireWebEvent("onError", new ActionEvent(t1.getMessage(), -1));
            }
        }
    });
    // Monitor the location property so that we can send the shouldLoadURL event.
    // This allows us to cancel the loading of a URL if we want to handle it ourself.
    self.web.getEngine().locationProperty().addListener(new ChangeListener<String>() {

        @Override
        public void changed(ObservableValue<? extends String> prop, String before, String after) {
            SEBrowserComponent self = weakSelf.get();
            BrowserComponent p = weakP.get();
            if (self == null || p == null) {
                return;
            }
            if (!p.fireBrowserNavigationCallbacks(self.web.getEngine().getLocation())) {
                self.web.getEngine().getLoadWorker().cancel();
            }
        }
    });
    self.adjustmentListener = new AdjustmentListener() {

        @Override
        public void adjustmentValueChanged(AdjustmentEvent e) {
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    SEBrowserComponent self = weakSelf.get();
                    if (self == null) {
                        return;
                    }
                    self.onPositionSizeChange();
                }
            });
        }
    };
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) ObservableValue(javafx.beans.value.ObservableValue) BorderLayout(java.awt.BorderLayout) WeakReference(java.lang.ref.WeakReference) WebEvent(javafx.scene.web.WebEvent) AdjustmentEvent(java.awt.event.AdjustmentEvent) State(javafx.concurrent.Worker.State) AdjustmentListener(java.awt.event.AdjustmentListener)

Aggregations

AdjustmentEvent (java.awt.event.AdjustmentEvent)9 AdjustmentListener (java.awt.event.AdjustmentListener)9 JScrollBar (javax.swing.JScrollBar)3 BorderLayout (java.awt.BorderLayout)2 JPanel (javax.swing.JPanel)2 JScrollPane (javax.swing.JScrollPane)2 ActionEvent (com.codename1.ui.events.ActionEvent)1 Content (ij3d.Content)1 UniverseListener (ij3d.UniverseListener)1 IntegerField (ini.trakem2.utils.IntegerField)1 Container (java.awt.Container)1 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 WeakReference (java.lang.ref.WeakReference)1