private void registerAutoMove() { if (myOwner != null) { myOwnerWindow = SwingUtilities.getWindowAncestor(myOwner); if (myOwnerWindow != null) { myLastOwnerPoint = myOwnerWindow.getLocationOnScreen(); myOwnerListener = new MyComponentAdapter(); myOwnerWindow.addComponentListener(myOwnerListener); } } }
private void registerMoveResizeHandler() { myParent.addComponentListener( new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { super.componentResized(e); setPositionRelativeToParent(); } @Override public void componentMoved(ComponentEvent e) { super.componentMoved(e); setPositionRelativeToParent(); } }); }
public ProgressComponent(Window dialog) { setFloatable(false); setBorderPainted(false); bar.setStringPainted(true); bar.setMaximumSize(new Dimension(60, 60)); addSeparator(); add(bar); setVisible(false); this.trackerDialog = dialog; dialog.addComponentListener( new ComponentListener() { @Override public void componentResized(ComponentEvent e) {} @Override public void componentMoved(ComponentEvent e) {} @Override public void componentShown(ComponentEvent e) { setVisible(false); } @Override public void componentHidden(ComponentEvent e) { if (lastState == ProgressState.Start || lastState == ProgressState.Work) { setVisible(true); } } }); bar.addMouseListener( new PopupMouseAdapter() { @Override protected void triggerDoubleClick(MouseEvent e) { trackerDialog.setVisible(true); } @Override protected void triggerPopup(MouseEvent e) {} }); }
public static void main(String[] args) { final Window window = new Window(g_szApplicationName); window.setIconImage(LoadIcon("/SimpleSoccer/icon1.png")); window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); buffer = new BufferedImage(WindowWidth, WindowHeight, BufferedImage.TYPE_INT_RGB); hdcBackBuffer = buffer.createGraphics(); // these hold the dimensions of the client window area cxClient = buffer.getWidth(); cyClient = buffer.getHeight(); // seed random number generator common.misc.utils.setSeed(0); window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); // Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); window.setResizable(false); int y = center.y - window.getHeight() / 2; window.setLocation(center.x - window.getWidth() / 2, y >= 0 ? y : 0); Script1.MyMenuBar menu = Script1.createMenu(IDR_MENU1); window.setJMenuBar(menu); g_SoccerPitch = new SoccerPitch(cxClient, cyClient); CheckAllMenuItemsAppropriately(menu); createPanel(); window.add(panel); window.pack(); window.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { CppToJava.keyCache.released(e); switch (e.getKeyChar()) { case KeyEvent.VK_ESCAPE: { System.exit(0); } break; case 'r': case 'R': { SoccerPitchLock.lock(); g_SoccerPitch = null; g_SoccerPitch = new SoccerPitch(cxClient, cyClient); JMenuBar bar = Script1.createMenu(IDR_MENU1); window.setJMenuBar(bar); bar.revalidate(); SoccerPitchLock.unlock(); } break; case 'p': case 'P': { g_SoccerPitch.TogglePause(); } break; } // end switch } // end switch } @Override public void keyPressed(KeyEvent e) { CppToJava.keyCache.pressed(e); } }); window.addComponentListener( new ComponentAdapter() { @Override // has the user resized the client area? public void componentResized(ComponentEvent e) { // if so we need to update our variables so that any drawing // we do using cxClient and cyClient is scaled accordingly cxClient = e.getComponent().getBounds().width; cyClient = e.getComponent().getBounds().height; // now to resize the backbuffer accordingly. buffer = new BufferedImage(cxClient, cyClient, BufferedImage.TYPE_INT_RGB); hdcBackBuffer = buffer.createGraphics(); } }); // make the window visible window.setVisible(true); // timer.SmoothUpdatesOn(); // start the timer timer.Start(); while (true) { // update if (timer.ReadyForNextFrame()) { SoccerPitchLock.lock(); g_SoccerPitch.Update(); SoccerPitchLock.unlock(); // render // panel.revalidate(); panel.repaint(); try { // System.out.println(timer.TimeElapsed()); Thread.sleep(2); } catch (InterruptedException ex) { } } } // end while }
/** Installs the sheet on the owner. This method is invoked just before the JSheet is shown. */ protected void installSheet() { if (!isNativeSheetSupported() && !isInstalled && isExperimentalSheet()) { Window owner = getOwner(); if (owner != null) { owner.addWindowListener(windowEventHandler); } isInstalled = true; } else { Window owner = getOwner(); if (owner != null) { // Determine the location for the sheet and its owner while // the sheet will be visible. // In case we have to shift the owner to fully display the // dialog, we remember the shift back position. Point ownerLoc = owner.getLocation(); Point sheetLoc; if (isShowAsSheet()) { if (owner instanceof JFrame) { sheetLoc = new Point( ownerLoc.x + (owner.getWidth() - getWidth()) / 2, ownerLoc.y + owner.getInsets().top + ((JFrame) owner).getRootPane().getContentPane().getY()); } else if (owner instanceof JDialog) { sheetLoc = new Point( ownerLoc.x + (owner.getWidth() - getWidth()) / 2, ownerLoc.y + owner.getInsets().top + ((JDialog) owner).getRootPane().getContentPane().getY()); } else { sheetLoc = new Point( ownerLoc.x + (owner.getWidth() - getWidth()) / 2, ownerLoc.y + owner.getInsets().top); } if (sheetLoc.x < 0) { owner.setLocation(ownerLoc.x - sheetLoc.x, ownerLoc.y); sheetLoc.x = 0; shiftBackLocation = ownerLoc; oldLocation = owner.getLocation(); } else { shiftBackLocation = null; oldLocation = ownerLoc; } } else { sheetLoc = new Point( ownerLoc.x + (owner.getWidth() - getWidth()) / 2, ownerLoc.y + (owner.getHeight() - getHeight()) / 2); } setLocation(sheetLoc); oldFocusOwner = owner.getFocusOwner(); // Note: We mustn't change the windows focusable state because // this also affects the focusable state of the JSheet. // owner.setFocusableWindowState(false); owner.setEnabled(false); // ((JFrame) owner).setResizable(false); if (isShowAsSheet()) { owner.addComponentListener(ownerMovementHandler); } else { if (owner instanceof Frame) { setTitle(((Frame) owner).getTitle()); } } } isInstalled = true; } }
/** Color chooser popup */ private void showColorChooserPopup() { // Checking that component is eligable for focus request if (!requestFocusInWindow() && !isFocusOwner()) { // Cancel operation if component is not eligable for focus yet // This might occur if some other component input verifier holds the focus or in some other // rare cases return; } // Update date from field if it was changed updateColorFromField(); // Create popup if it doesn't exist if (popup == null || colorChooserPanel == null) { final Window ancestor = SwingUtils.getWindowAncestor(this); // Color chooser colorChooserPanel = new WebColorChooserPanel(true); colorChooserPanel.setColor(color); colorChooserPanel.setUndecorated(false); colorChooserPanel.setPaintFocus(false); colorChooserPanel.setRound(StyleConstants.smallRound); colorChooserPanel.setShadeWidth(0); // Popup window popup = new WebWindow(ancestor); popup.setLayout(new BorderLayout()); popup.setCloseOnFocusLoss(true); popup.setWindowOpaque(false); popup.add(colorChooserPanel); popup.pack(); // Correct popup positioning updatePopupLocation(); ancestor.addComponentListener( new ComponentAdapter() { @Override public void componentMoved(final ComponentEvent e) { if (popup.isShowing()) { updatePopupLocation(); } } @Override public void componentResized(final ComponentEvent e) { if (popup.isShowing()) { updatePopupLocation(); } } }); ancestor.addPropertyChangeListener( WebLookAndFeel.ORIENTATION_PROPERTY, new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { if (popup.isShowing()) { updatePopupLocation(); } } }); colorChooserPanel.addColorChooserListener( new ColorChooserListener() { @Override public void okPressed(final ActionEvent e) { setColor(colorChooserPanel.getColor()); popup.setVisible(false); } @Override public void resetPressed(final ActionEvent e) {} @Override public void cancelPressed(final ActionEvent e) { popup.setVisible(false); } }); } else { // Updating window location updatePopupLocation(); // Updating color colorChooserPanel.setColor(color); } // Applying orientation to popup SwingUtils.copyOrientation(WebColorChooserField.this, popup); // Showing popup and changing focus popup.setVisible(true); colorChooserPanel.requestFocusInWindow(); }