Example usage for java.awt.event ComponentEvent getComponent

List of usage examples for java.awt.event ComponentEvent getComponent

Introduction

In this page you can find the example usage for java.awt.event ComponentEvent getComponent.

Prototype

public Component getComponent() 

Source Link

Document

Returns the originator of the event.

Usage

From source file:com.intel.stl.ui.common.view.ChartsView.java

@Override
protected JComponent getMainComponent() {
    if (mainPanel == null) {
        mainPanel = new JPanel(new BorderLayout(0, 0));
        mainPanel.setOpaque(false);// w w  w. ja v a 2 s  .c  o m
        mainPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));

        chartPanel = new JumpChartPanel(null);
        chartPanel.setOpaque(false);
        chartPanel.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent e) {
                chartPanel.setMaximumDrawHeight(e.getComponent().getHeight());
                chartPanel.setMaximumDrawWidth(e.getComponent().getWidth());
                chartPanel.setMinimumDrawWidth(e.getComponent().getWidth());
                chartPanel.setMinimumDrawHeight(e.getComponent().getHeight());
            }
        });
        mainPanel.add(chartPanel, BorderLayout.CENTER);
    }
    return mainPanel;
}

From source file:AnimatedMetadataGraph.java

@Override
public void init() {

    //create a graph
    Graph<String, String> ig = Graphs
            .<String, String>synchronizedDirectedGraph(new DirectedSparseMultigraph<String, String>());

    ObservableGraph<String, String> og = new ObservableGraph<String, String>(ig);
    og.addGraphEventListener(new GraphEventListener<String, String>() {

        public void handleGraphEvent(GraphEvent<String, String> evt) {
            System.err.println("got " + evt);

        }/* w  w w  .  j  ava  2  s  .  com*/
    });
    this.g = og;
    //create a graphdraw
    layout = new FRLayout<String, String>(g);
    layout.setSize(new Dimension(600, 600));
    Relaxer relaxer = new VisRunner((IterativeContext) layout);
    relaxer.stop();
    relaxer.prerelax();

    Layout<String, String> staticLayout = new StaticLayout<String, String>(g, layout);

    vv = new VisualizationViewer<String, String>(staticLayout, new Dimension(600, 600));

    JRootPane rp = this.getRootPane();
    rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().setBackground(java.awt.Color.lightGray);
    getContentPane().setFont(new Font("Serif", Font.PLAIN, 12));

    vv.setGraphMouse(new DefaultModalGraphMouse<Number, Number>());

    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.setForeground(Color.black);

    vv.addComponentListener(new ComponentAdapter() {

        /**
         * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent)
         */
        @Override
        public void componentResized(ComponentEvent arg0) {
            super.componentResized(arg0);
            System.err.println("resized");
            layout.setSize(arg0.getComponent().getSize());
        }
    });

    getContentPane().add(vv);
    switchLayout = new JButton("Switch to SpringLayout");
    switchLayout.addActionListener(new ActionListener() {

        @SuppressWarnings("unchecked")
        public void actionPerformed(ActionEvent ae) {
            Dimension d = vv.getSize();//new Dimension(600,600);
            if (switchLayout.getText().indexOf("Spring") > 0) {
                switchLayout.setText("Switch to FRLayout");
                layout = new SpringLayout<String, String>(g, new ConstantTransformer(EDGE_LENGTH));
                layout.setSize(d);
                Relaxer relaxer = new VisRunner((IterativeContext) layout);
                relaxer.stop();
                relaxer.prerelax();
                StaticLayout<String, String> staticLayout = new StaticLayout<String, String>(g, layout);
                LayoutTransition<String, String> lt = new LayoutTransition<String, String>(vv,
                        vv.getGraphLayout(), staticLayout);
                Animator animator = new Animator(lt);
                animator.start();
                //   vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.repaint();

            } else {
                switchLayout.setText("Switch to SpringLayout");
                layout = new FRLayout<String, String>(g, d);
                layout.setSize(d);
                Relaxer relaxer = new VisRunner((IterativeContext) layout);
                relaxer.stop();
                relaxer.prerelax();
                StaticLayout<String, String> staticLayout = new StaticLayout<String, String>(g, layout);
                LayoutTransition<String, String> lt = new LayoutTransition<String, String>(vv,
                        vv.getGraphLayout(), staticLayout);
                Animator animator = new Animator(lt);
                animator.start();
                //   vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
                vv.repaint();

            }
        }
    });

    getContentPane().add(switchLayout, BorderLayout.SOUTH);

    timer = new Timer();
}

From source file:com.hammurapi.jcapture.CaptureFrame.java

public CaptureFrame(final AbstractCaptureApplet applet) throws Exception {
    super("Screen capture");
    setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("camera.png")));

    setUndecorated(true);/*  ww w.j  a  v  a 2 s.c o m*/

    Translucener.makeFrameTranslucent(this);

    setAlwaysOnTop(true);
    this.applet = applet;
    captureConfig = new CaptureConfig();
    captureConfig.load(applet.loadConfig());
    captureConfig.setBackgroundProcessor(applet.getBackgroundProcessor());

    //--- GUI construction ---

    capturePanel = new JPanel();

    final JLabel dimensionsLabel = new JLabel("");
    capturePanel.add(dimensionsLabel, BorderLayout.CENTER);

    capturePanel.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            super.componentResized(e);
            dimensionsLabel.setText(e.getComponent().getWidth() + " x " + e.getComponent().getHeight());
        }
    });

    JButton captureButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Rectangle bounds = capturePanel.getBounds();
            Point loc = bounds.getLocation();
            SwingUtilities.convertPointToScreen(loc, capturePanel);
            bounds.setLocation(loc);
            Properties props = captureConfig.setRecordingRectangle(bounds);
            if (props != null) {
                getApplet().storeConfig(props);
            }
            capturing.set(true);
            setVisible(false);
        }

    });
    captureButton.setText("Capture");
    captureButton.setToolTipText("Create a snapshot of the screen");
    capturePanel.add(captureButton, BorderLayout.CENTER);

    recordButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Rectangle bounds = capturePanel.getBounds();
            Point loc = bounds.getLocation();
            SwingUtilities.convertPointToScreen(loc, capturePanel);
            bounds.setLocation(loc);
            Properties props = captureConfig.setRecordingRectangle(bounds);
            if (props != null) {
                getApplet().storeConfig(props);
            }
            recording.set(true);
            setVisible(false);
        }

    });
    recordButton.setText("Record");
    setRecordButtonState();
    capturePanel.add(recordButton, BorderLayout.CENTER);

    JButton optionsButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            new CaptureOptionsDialog(CaptureFrame.this).setVisible(true);
        }

    });
    optionsButton.setText("Options");
    capturePanel.add(optionsButton, BorderLayout.CENTER);

    JButton cancelButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            CaptureFrame.this.setVisible(false);
        }

    });
    cancelButton.setText("Cancel");
    capturePanel.add(cancelButton, BorderLayout.CENTER);

    getContentPane().add(capturePanel, BorderLayout.CENTER);

    capturePanel.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false));

    if (captureConfig.getRecordingRectangle() == null) {
        setSize(400, 300);
        setLocationRelativeTo(null);
    } else {
        setBounds(captureConfig.getRecordingRectangle());
    }

    Insets dragInsets = new Insets(5, 5, 5, 5);
    new ComponentResizer(dragInsets, this);

    ComponentMover cm = new ComponentMover();
    cm.registerComponent(this);
    cm.setDragInsets(dragInsets);

    addComponentListener(new ComponentListener() {

        @Override
        public void componentShown(ComponentEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void componentResized(ComponentEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void componentMoved(ComponentEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void componentHidden(ComponentEvent e) {
            if (capturing.get()) {
                capturing.set(false);
                try {
                    capture();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            } else if (recording.get()) {
                recording.set(false);
                record();
            }
        }
    });

}

From source file:com.willwinder.universalgcodesender.MainWindow.java

private void visualizeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_visualizeButtonActionPerformed
    // Create new object if it is null.
    if (this.vw == null) {
        this.vw = new VisualizerWindow(settings.getVisualizerWindowSettings());

        final MainWindow mw = this;
        vw.addComponentListener(new ComponentListener() {
            @Override/*from ww w. j a  v  a 2  s .  c  o  m*/
            public void componentResized(ComponentEvent ce) {
                mw.settings.getVisualizerWindowSettings().height = ce.getComponent().getSize().height;
                mw.settings.getVisualizerWindowSettings().width = ce.getComponent().getSize().width;
            }

            @Override
            public void componentMoved(ComponentEvent ce) {
                mw.settings.getVisualizerWindowSettings().xLocation = ce.getComponent().getLocation().x;
                mw.settings.getVisualizerWindowSettings().yLocation = ce.getComponent().getLocation().y;
            }

            @Override
            public void componentShown(ComponentEvent ce) {
            }

            @Override
            public void componentHidden(ComponentEvent ce) {
            }
        });

        vw.setMinArcLength(settings.getSmallArcThreshold());
        vw.setArcLength(settings.getSmallArcSegmentLength());
        setVisualizerFile();

        // Add listener
        this.backend.addControllerListener(vw);
    }

    // Display the form
    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            vw.setVisible(true);
        }
    });
}

From source file:base.BasePlayer.Main.java

public void componentResized(ComponentEvent e) {
    if (e.getSource() == drawScroll) {
        if (Main.sidebarWidth != Main.upPanel.getDividerLocation() + 2) {
            if (samples * drawCanvas.drawVariables.sampleHeight < drawScroll.getViewport().getHeight()) {
                drawDimensions.setSize(drawScroll.getViewport().getWidth(),
                        drawScroll.getViewport().getSize().height);
                drawCanvas.setPreferredSize(drawDimensions);
                drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(),
                        drawScroll.getViewport().getHeight());

                if (drawCanvas.splits.size() > 0) {
                    for (int i = 0; i < drawCanvas.splits.size(); i++) {
                        drawCanvas.splits.get(i).updateReads = true;
                    }//  w ww . j av  a 2s.c  o  m
                }
            }
            Draw.updatevars = true;
            drawCanvas.repaint();
        }
        Main.sidebarWidth = upPanel.getDividerLocation() + 4;
        chromDimensions.setSize(drawScroll.getViewport().getWidth() - upPanel.getDividerLocation(),
                splitPane.getDividerLocation());
        chromDraw.setPreferredSize(chromDimensions);
        chromDraw.updateExons = true;
        chromDraw.repaint();
        if (Main.samples == 0) {
            drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(), drawScroll.getViewport().getHeight());
        } else if (Main.drawCanvas.drawVariables.visiblesamples == Main.samples) {

            Main.drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(), Main.drawCanvas.getHeight());

            if (Main.drawCanvas.drawVariables.sampleHeight < Main.drawScroll.getViewport().getHeight()) {

                Main.drawCanvas.drawVariables.visiblesamples = (short) ((Main.drawScroll.getViewport()
                        .getHeight() / (double) Main.drawCanvas.drawVariables.sampleHeight) + 0.5);

            }
        }

        return;
    } else if (e.getSource() == chrompan) {
        if (Main.sidebarWidth != Main.upPanel.getDividerLocation() + 2) {
            if (samples * drawCanvas.drawVariables.sampleHeight < drawScroll.getViewport().getHeight()) {

                drawDimensions.setSize(drawScroll.getViewport().getWidth(),
                        drawScroll.getViewport().getSize().height);
                drawCanvas.setPreferredSize(drawDimensions);

                drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(),
                        drawScroll.getViewport().getHeight());
                if (drawCanvas.splits.size() > 0) {
                    for (int i = 0; i < drawCanvas.splits.size(); i++) {
                        drawCanvas.splits.get(i).updateReads = true;

                    }
                }

            }
            Main.bedCanvas.repaint();
            Main.controlDraw.repaint();
            Draw.updatevars = true;
            drawCanvas.repaint();

        }

        Main.sidebarWidth = upPanel.getDividerLocation() + 4;
        //   drawCanvas.drawWidth = drawScroll.getViewport().getWidth()-Main.sidebarWidth;
        chromDimensions.setSize(drawScroll.getViewport().getWidth() - upPanel.getDividerLocation(),
                splitPane.getDividerLocation());
        chromDraw.setPreferredSize(chromDimensions);
        chromDraw.updateExons = true;
        chromDraw.repaint();
        if (Main.drawCanvas.drawVariables.visiblesamples == Main.samples) {
            Main.drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(), Main.drawCanvas.getHeight());
            if (Main.drawCanvas.drawVariables.sampleHeight < Main.drawScroll.getViewport().getHeight()) {
                Main.drawCanvas.drawVariables.visiblesamples = (short) ((Main.drawScroll.getViewport()
                        .getHeight() / (double) Main.drawCanvas.drawVariables.sampleHeight) + 0.5);
                //TODO
            }
        } else {
            Main.drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(), Main.drawCanvas.getHeight());
        }

        return;

    }

    if (e.getComponent().getName() != null && e.getComponent().getName().contains("frame0")) {

        if (drawScroll.getViewport().getWidth() > 0) {
            drawDimensions.setSize(drawScroll.getViewport().getWidth(),
                    drawScroll.getViewport().getSize().height);
            drawCanvas.setPreferredSize(drawDimensions);

            chromDimensions.setSize(drawScroll.getViewport().getWidth() - Main.sidebarWidth - 1,
                    splitPane.getDividerLocation());

            chromDraw.setPreferredSize(chromDimensions);

            drawCanvas.resizeCanvas(drawScroll.getViewport().getWidth(), drawScroll.getViewport().getHeight());

            if (drawCanvas.splits.size() > 0) {
                for (int i = 0; i < drawCanvas.splits.size(); i++) {
                    drawCanvas.splits.get(i).updateReads = true;
                }
            }
            drawCanvas.repaint();
            return;
        }
    }
}

From source file:op.care.nursingprocess.DlgNursingProcess.java

private void jspPlanungComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jspPlanungComponentResized
    JScrollPane jsp = (JScrollPane) evt.getComponent();
    if (tblPlanung.getRowCount() <= 0) {
        return;/*from w  w w. j  a va  2  s  . c o  m*/
    }
    Dimension dim = jsp.getSize();
    int textWidth = dim.width - 25;
    TableColumnModel tcm1 = tblPlanung.getColumnModel();
    tcm1.getColumn(0).setPreferredWidth(textWidth);
    tcm1.getColumn(0).setHeaderValue(SYSTools.xx("nursingrecords.nursingprocess.interventions"));
}

From source file:op.care.sysfiles.PnlFiles.java

private void jspFilesComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jspFilesComponentResized
    JScrollPane jsp = (JScrollPane) evt.getComponent();
    Dimension dim = jsp.getSize();
    // Gre der Text Spalte im TB ndern.
    // Summe der fixen Spalten  = 210 + ein bisschen
    int textWidth = dim.width - 250;
    tblFiles.getColumnModel().getColumn(0).setPreferredWidth(170);
    tblFiles.getColumnModel().getColumn(1).setPreferredWidth(80);
    tblFiles.getColumnModel().getColumn(2).setPreferredWidth(textWidth / 3 * 2);
    tblFiles.getColumnModel().getColumn(3).setPreferredWidth(textWidth / 3);
    //        tblFiles.getColumnModel().getColumn(2).setPreferredWidth(100);

    //        SYSTools.packTable(tblFiles, 0);

}

From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java

/**
 * {@inheritDoc}//from  w w w .ja  v a 2  s .c  o  m
 */
public void componentHidden(ComponentEvent e) {
    checkDispatchThread();
    if (e.getComponent() instanceof Window) {
        remove((Window) e.getComponent());
    } else {
        removeComponent(e.getComponent(), e.getComponent().getParent());
    }
}

From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java

/**
 * {@inheritDoc}/*w  w  w .j a v a2s.co  m*/
 */
public void componentShown(ComponentEvent e) {
    checkDispatchThread();
    if (e.getComponent() instanceof Window) {
        add((Window) e.getComponent());
    } else {
        addComponent(e.getComponent());
    }
}

From source file:org.eclipse.jubula.rc.swing.listener.ComponentHandler.java

/**
 * {@inheritDoc}// w w w. j  a v  a 2s .  co m
 */
public void eventDispatched(AWTEvent event) {

    final ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
    try {
        if (log.isDebugEnabled()) {
            log.debug(event.paramString());
        }
        final int id = event.getID();
        ComponentEvent componentEvent;
        switch (id) {
        case WindowEvent.WINDOW_ACTIVATED:
        case WindowEvent.WINDOW_OPENED:
            // add recursivly all components to AUTHierarchy 
            // and create names for unnamed components
            Window window = ((WindowEvent) event).getWindow();
            autHierarchy.add(window);
            break;
        case ContainerEvent.COMPONENT_ADDED:
            checkContainerListener((ContainerEvent) event);
            break;
        case ComponentEvent.COMPONENT_HIDDEN:
            componentEvent = (ComponentEvent) event;
            if (!hasListener(componentEvent.getComponent(), ComponentListener.class)) {
                autHierarchy.componentHidden(componentEvent);
            }
            break;
        case ComponentEvent.COMPONENT_SHOWN:
            componentEvent = (ComponentEvent) event;
            if (!hasListener(componentEvent.getComponent(), ComponentListener.class)) {
                autHierarchy.componentShown(componentEvent);
            }
            break;
        default:
            // do nothing
        }
        if (AUTServer.getInstance().getMode() == ChangeAUTModeMessage.OBJECT_MAPPING) {

            AUTServer.getInstance().updateHighLighter();
        }
    } catch (Throwable t) {
        log.error("exception during ComponentHandler", t); //$NON-NLS-1$
    } finally {
        Thread.currentThread().setContextClassLoader(originalCL);
    }
}