Java Code Examples for java.awt.event.ComponentEvent

The following examples show how to use java.awt.event.ComponentEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: mars-sim   Source File: SwingDialog.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addNotify() {
    super.addNotify();
    final Component parent = SwingUtilities.getRoot(this);
    componentListener = new ComponentAdapter() {
        @Override
        public void componentMoved(ComponentEvent e) {
            hidePopUps();
            processComponentEvent(new ComponentEvent(JFXPanelEx.this, ComponentEvent.COMPONENT_MOVED));
        }

        @Override
        public void componentResized(ComponentEvent e) {
            hidePopUps();
            processComponentEvent(new ComponentEvent(JFXPanelEx.this, ComponentEvent.COMPONENT_RESIZED));
            processComponentEvent(new ComponentEvent(JFXPanelEx.this, ComponentEvent.COMPONENT_MOVED)); //is important!!!
        }
    };
    parent.addComponentListener(componentListener);
}
 
Example 2
Source Project: radiance   Source File: MatrixRain.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public MatrixPanel() {
    try {
        InputStream is = MatrixRain.class.getClassLoader().getResourceAsStream(
                "fonts/katakana.ttf");
        Font kf = Font.createFont(Font.TRUETYPE_FONT, is);
        int fontSize = 14;
        font = kf.deriveFont(Font.BOLD, fontSize);
    } catch (Exception exc) {
        exc.printStackTrace();
    }

    SwingRepaintTimeline.repaintBuilder(this).playLoop(RepeatBehavior.LOOP);

    this.drops = new ArrayList<>();
    this.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            while (drops.size() < 40)
                addDrop();
        }
    });
}
 
Example 3
/** Creates a new instance of ProgressGlassPane */
public ProgressGlassPane() {
    // blocks all user input
    addMouseListener(new MouseAdapter() { });
    addMouseMotionListener(new MouseMotionAdapter() { });
    addKeyListener(new KeyAdapter() { });
    
    setFocusTraversalKeysEnabled(false);
    addComponentListener(new ComponentAdapter() {
        public void componentShown(ComponentEvent evt) {
            requestFocusInWindow();
        }
    });
    
    setBackground(Color.WHITE);
    setFont(new Font("Default", Font.BOLD, 16));
}
 
Example 4
Source Project: magarena   Source File: AnimationPanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void setCancelOnResize() {
    addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            if (animation != null) {
                animation.cancel();
            }
        }
    });
}
 
Example 5
Source Project: birt   Source File: DataChartsViewer.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void componentShown( ComponentEvent cev )
{
	JFrame jf = (JFrame) cev.getComponent( );
	Rectangle r = jf.getBounds( );
	setLocation( r.x, r.y + r.height );
	setSize( r.width, 50 );
	setVisible( true );
}
 
Example 6
Source Project: littleluck   Source File: LuckPopupFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void componentShown(ComponentEvent e)
{
    Object obj = e.getSource();
    
    if(obj instanceof JWindow)
    {
        JWindow window = (JWindow) obj;
        
        window.repaint();
    }
}
 
Example 7
Source Project: birt   Source File: Regression_137780_swing.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void componentShown( ComponentEvent cev )
{
	JFrame jf = (JFrame) cev.getComponent( );
	Rectangle r = jf.getBounds( );
	setLocation( r.x, r.y + r.height );
	setSize( r.width, 50 );
	setVisible( true );
}
 
Example 8
Source Project: consulo   Source File: DesktopWindowWatcher.java    License: Apache License 2.0 5 votes vote down vote up
final void dispatchComponentEvent(final ComponentEvent e) {
  final int id = e.getID();
  if (WindowEvent.WINDOW_CLOSED == id || (ComponentEvent.COMPONENT_HIDDEN == id && e.getSource() instanceof Window)) {
    dispatchHiddenOrClosed(TargetAWT.from((Window)e.getSource()));
  }
  // Clear obsolete reference on root frame
  if (WindowEvent.WINDOW_CLOSED == id) {
    final Window window = (Window)e.getSource();

    if (JOptionPane.getRootFrame() == window) {
      JOptionPane.setRootFrame(null);
    }
  }
}
 
Example 9
Source Project: mars-sim   Source File: MainDesktopPane.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create background tile when MainDesktopPane is first displayed. Recenter
 * logoLabel on MainWindow and set backgroundLabel to the size of
 * MainDesktopPane.
 * 
 * @param e the component event
 */
@Override
public void componentResized(ComponentEvent e) {
	// If displayed for the first time, create background image tile.
	// The size of the background tile cannot be determined during construction
	// since it requires the MainDesktopPane be displayed first.
	if (firstDisplay) {
		ImageIcon baseImageIcon = ImageLoader.getIcon(Msg.getString("img.background")); //$NON-NLS-1$
		Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
		Image backgroundImage = createImage((int) screen_size.getWidth(), (int) screen_size.getHeight());
		Graphics backgroundGraphics = backgroundImage.getGraphics();

		for (int x = 0; x < backgroundImage.getWidth(this); x += baseImageIcon.getIconWidth()) {
			for (int y = 0; y < backgroundImage.getHeight(this); y += baseImageIcon.getIconHeight()) {
				backgroundGraphics.drawImage(baseImageIcon.getImage(), x, y, this);
			}
		}

		backgroundImageIcon.setImage(backgroundImage);

		backgroundLabel.setSize(getSize());

		firstDisplay = false;
	}

	// Set the backgroundLabel size to the size of the desktop
	backgroundLabel.setSize(getSize());

}
 
Example 10
Source Project: jdk8u-jdk   Source File: Ruler.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the shape to window. It is recommended to apply shape in
 * componentResized() method
 */
@Override
public void componentResized(ComponentEvent e) {

    // We do apply shape only if PERPIXEL_TRANSPARENT is supported
    if (transparencySupported) {
        setShape(buildShape());
    }
}
 
Example 11
Source Project: Logisim   Source File: ExpressionView.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void componentResized(ComponentEvent arg0) {
	int width = getWidth();
	if (renderData != null && Math.abs(renderData.width - width) > 2) {
		Graphics g = getGraphics();
		FontMetrics fm = g == null ? null : g.getFontMetrics();
		renderData = new RenderData(renderData.exprData, width, fm);
		setPreferredSize(renderData.getPreferredSize());
		revalidate();
		repaint();
	}
}
 
Example 12
Source Project: openjdk-8   Source File: XWindowPeer.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setBounds(int x, int y, int width, int height, int op) {
    XToolkit.awtLock();
    try {
        Rectangle oldBounds = getBounds();

        super.setBounds(x, y, width, height, op);

        Rectangle bounds = getBounds();

        XSizeHints hints = getHints();
        setSizeHints(hints.get_flags() | XUtilConstants.PPosition | XUtilConstants.PSize,
                         bounds.x, bounds.y, bounds.width, bounds.height);
        XWM.setMotifDecor(this, false, 0, 0);

        boolean isResized = !bounds.getSize().equals(oldBounds.getSize());
        boolean isMoved = !bounds.getLocation().equals(oldBounds.getLocation());
        if (isMoved || isResized) {
            repositionSecurityWarning();
        }
        if (isResized) {
            postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_RESIZED));
        }
        if (isMoved) {
            postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_MOVED));
        }
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 13
Source Project: birt   Source File: Regression_139388_swing.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void componentResized( ComponentEvent cev )
{
	JFrame jf = (JFrame) cev.getComponent( );
	Rectangle r = jf.getBounds( );
	setLocation( r.x, r.y + r.height );
	setSize( r.width, 50 );
}
 
Example 14
Source Project: jdk8u-jdk   Source File: bug8071705.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void componentShown(ComponentEvent e) {
    JFrame frame = (JFrame) e.getComponent();

    runActualTest(device, latch, frame, result);

    frame.setVisible(false);
    frame.dispose();
    latch.countDown();
}
 
Example 15
Source Project: megamek   Source File: PicMap.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void processComponentEvent(ComponentEvent e) {
    switch (e.getID()) {
        case ComponentEvent.COMPONENT_RESIZED:
            onResize();
            update();
            break;
    }
}
 
Example 16
public PreviewArea(Project project, Set<FlutterOutline> outlinesWithWidgets, Disposable parent) {
  this.outlinesWithWidgets = outlinesWithWidgets;

  context = new WidgetEditingContext(
    project,
    FlutterDartAnalysisServer.getInstance(project),
    InspectorGroupManagerService.getInstance(project),
    EditorPositionService.getInstance(project)
  );

  inspectorClient = new InspectorGroupManagerService.Client(parent);
  context.inspectorGroupManagerService.addListener(inspectorClient, parent);
  preview = new PreviewViewController(new WidgetViewModelData(context), false, layeredPanel, parent);

  deviceMirrorPanel = new PreviewViewModelPanel(preview);

  windowToolbar = ActionManager.getInstance().createActionToolbar("PreviewArea", toolbarGroup, true);
  toolbarGroup.add(new TitleAction("Device Mirror"));

  window = new SimpleToolWindowPanel(true, true);
  window.setToolbar(windowToolbar.getComponent());

  deviceMirrorPanel.setLayout(new BorderLayout());

  // TODO(jacobr): reafactor to remove the layeredPanel as we aren't getting any benefit from it.
  window.setContent(layeredPanel);
  layeredPanel.add(deviceMirrorPanel, Integer.valueOf(0));

  // Layers should cover the whole root panel.
  layeredPanel.addComponentListener(new ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
      final Dimension renderSize = getRenderSize();
      preview.setScreenshotBounds(new Rectangle(0, 0, renderSize.width, renderSize.height));
    }
  });
}
 
Example 17
Source Project: birt   Source File: Regression_123931_swing.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void componentMoved( ComponentEvent cev )
{
	JFrame jf = (JFrame) cev.getComponent( );
	Rectangle r = jf.getBounds( );
	setLocation( r.x, r.y + r.height );
	setSize( r.width, 50 );
}
 
Example 18
Source Project: bytecode-viewer   Source File: ClassViewer.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Whoever wrote this function, THANK YOU!
 *
 * @param splitter
 * @param proportion
 * @return
 */
public static JSplitPane setDividerLocation(final JSplitPane splitter,
                                            final double proportion) {
    if (splitter.isShowing()) {
        if (splitter.getWidth() > 0 && splitter.getHeight() > 0) {
            splitter.setDividerLocation(proportion);
        } else {
            splitter.addComponentListener(new ComponentAdapter() {
                @Override
                public void componentResized(ComponentEvent ce) {
                    splitter.removeComponentListener(this);
                    setDividerLocation(splitter, proportion);
                }
            });
        }
    } else {
        splitter.addHierarchyListener(new HierarchyListener() {
            @Override
            public void hierarchyChanged(HierarchyEvent e) {
                if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0
                        && splitter.isShowing()) {
                    splitter.removeHierarchyListener(this);
                    setDividerLocation(splitter, proportion);
                }
            }
        });
    }
    return splitter;
}
 
Example 19
@Override
protected void onLaunch() {
   d.addComponentListener(new ComponentAdapter() {
      @Override
      public void componentResized(ComponentEvent ev) {
         ConfigManager preferencesManager = getUser().getPreferencesManager();
         Dimension dim = d.getSize();
         preferencesManager.setEntry(EntryType.INTEGER, KEY_EDIT_ROSTER_WIDTH, dim.width);
         preferencesManager.setEntry(EntryType.INTEGER, KEY_EDIT_ROSTER_HEIGHT, dim.height);
      }
   });
}
 
Example 20
Source Project: wandora   Source File: VideoMp4.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void componentResized(ComponentEvent e) {
    Platform.runLater(new Runnable() {
        @Override 
        public void run() {
            refreshLayout();
        }
    });
}
 
Example 21
Source Project: birt   Source File: Regression_117986_swing.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void componentShown( ComponentEvent cev )
{
	JFrame jf = (JFrame) cev.getComponent( );
	Rectangle r = jf.getBounds( );
	setLocation( r.x, r.y + r.height );
	setSize( r.width, 50 );
	setVisible( true );
}
 
Example 22
Source Project: openjdk-jdk8u-backup   Source File: Ruler.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the shape to window. It is recommended to apply shape in
 * componentResized() method
 */
@Override
public void componentResized(ComponentEvent e) {

    // We do apply shape only if PERPIXEL_TRANSPARENT is supported
    if (transparencySupported) {
        setShape(buildShape());
    }
}
 
Example 23
Source Project: birt   Source File: Regression_116616_swing.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public void componentShown( ComponentEvent e )
{
	// TODO Auto-generated method stub

}
 
Example 24
public void attach(Component _comp) {
  if(this.comp != null) {
    throw new IllegalStateException("SizeSaver can only be attach to one compoent. current component is " + this.comp);
  }
  this.comp = _comp;

  Dimension size = getSize();

  if(size != null) {
    // System.out.println("attach " + id + " size=" + size);
    comp.setSize(size);
    if(comp instanceof JComponent) {
      ((JComponent)comp).setPreferredSize(size);
    }
  }

  Preferences prefs = getPrefs();

  if(comp instanceof JFrame) {
    Toolkit tk = comp.getToolkit();
    if(tk.isFrameStateSupported(Frame.MAXIMIZED_VERT) ||
       tk.isFrameStateSupported(Frame.MAXIMIZED_HORIZ) ||
       tk.isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
      int state = prefs.getInt(KEY_STATE, Frame.NORMAL);
      ((Frame)comp).setExtendedState(state);
    }
    int x = prefs.getInt(KEY_X, 0);
    int y = prefs.getInt(KEY_Y, 0);
    // System.out.println("attach " + id + " pos=" + x + ", " + y);
    comp.setLocation(x, y);
  }

  if(comp instanceof JSplitPane) {
    JSplitPane split = (JSplitPane)comp;
    int pos = prefs.getInt(KEY_SPLITPOS, defSplit);
    if(pos != -1) {
      // System.out.println("attach " + id + " split=" + pos);
      split.setDividerLocation(pos);
      // Tell components that they may want to redo its layout
      Component parent = split.getParent();
      if (null!=parent) {
        parent.invalidate();
      } else {
        split.invalidate();
      }
    }

    splitListener = new ComponentAdapter() {
        public void 	componentResized(ComponentEvent e) {
          store();
        }
        public void 	componentMoved(ComponentEvent e) {
          store();
        }
      };

    split.getLeftComponent().addComponentListener(splitListener);
  }

  this.comp.addComponentListener(this);
}
 
Example 25
Source Project: seaglass   Source File: SeaGlassDesktopPaneUI.java    License: Apache License 2.0 4 votes vote down vote up
public void componentShown(ComponentEvent e) {
    if (e.getSource() instanceof JInternalFrame) {
        adjustSize();
    }
}
 
Example 26
Source Project: weblaf   Source File: ComponentHighlighter.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void componentHidden ( @NotNull final ComponentEvent e )
{
    uninstall ();
}
 
Example 27
Source Project: jdk8u60   Source File: InputContext.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void componentHidden(ComponentEvent e) {
    notifyClientWindowChange((Window)e.getComponent());
}
 
Example 28
@Override
public void componentHidden(ComponentEvent e) {
    // Override required for ComponentListener, intentionally left blank
}
 
Example 29
Source Project: birt   Source File: Regression_136077_swing.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public void componentMoved( ComponentEvent e )
{
	// TODO Auto-generated method stub

}
 
Example 30
public void componentHidden(ComponentEvent e) {
}