java.awt.Toolkit Java Examples

The following examples show how to use java.awt.Toolkit. 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 check out the related API usage on the sidebar.
Example #1
Source File: Password.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Shows a dialog and verifies user entry of the password.
 *
 * @param password the password
 * @param filename the name of the password-protected file (may be null).
 * @return true if password is null, "", or correctly verified
 */
public static boolean verify(String password, String fileName) {
  if((password==null)||password.equals("")) {//$NON-NLS-1$
    return true; 
  }
 Password dialog = new Password();
  dialog.password = password;
  if((fileName==null)||fileName.equals("")) {                                     //$NON-NLS-1$
    dialog.messageLabel.setText(ControlsRes.getString("Password.Message.Short")); //$NON-NLS-1$
  } else {
    dialog.messageLabel.setText(ControlsRes.getString("Password.Message.File")    //$NON-NLS-1$
                                +" \""+XML.getName(fileName)+"\".");               //$NON-NLS-1$ //$NON-NLS-2$
  }
  dialog.pack();
  // center on screen
  Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
  int x = (dim.width-dialog.getBounds().width)/2;
  int y = (dim.height-dialog.getBounds().height)/2;
  dialog.setLocation(x, y);
  dialog.pass = false;
  dialog.passwordField.setText(""); //$NON-NLS-1$
  dialog.setVisible(true);
  dialog.dispose();
  return dialog.pass;
}
 
Example #2
Source File: SnapWindow.java    From Spark with Apache License 2.0 6 votes vote down vote up
private void adjustWindow() {
    if (!parentFrame.isVisible()) {
        return;
    }

    Point mainWindowLocation = parentFrame.getLocationOnScreen();

    int x = (int)mainWindowLocation.getX() + parentFrame.getWidth();

    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = getWidth();
    if (width == 0) {
        width = preferredWidth;
    }
    if ((int)screenSize.getWidth() - width < x) {
        x = (int)mainWindowLocation.getX() - width;
    }


    setSize(preferredWidth, (int)parentFrame.getHeight());
    setLocation(x, (int)mainWindowLocation.getY());
}
 
Example #3
Source File: Player.java    From jclic with GNU General Public License v2.0 6 votes vote down vote up
/** Creates and initializes the members of the {@link cursors} array. */
protected void createCursors() {
  try {
    Toolkit tk = Toolkit.getDefaultToolkit();

    cursors[HAND_CURSOR] = tk.createCustomCursor(ResourceManager.getImageIcon("cursors/hand.gif").getImage(),
        new Point(8, 0), "hand");

    cursors[OK_CURSOR] = tk.createCustomCursor(ResourceManager.getImageIcon("cursors/ok.gif").getImage(),
        new Point(0, 0), "ok");

    cursors[REC_CURSOR] = tk.createCustomCursor(ResourceManager.getImageIcon("cursors/micro.gif").getImage(),
        new Point(15, 3), "record");

  } catch (Exception e) {
    System.err.println("Error creating cursor:\n" + e);
  }
}
 
Example #4
Source File: bug7189299.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    final SunToolkit toolkit = ((SunToolkit) Toolkit.getDefaultToolkit());

    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            setup();
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            try {
                verifySingleDefaultButtonModelListener();
                doTest();
                verifySingleDefaultButtonModelListener();
            } finally {
                frame.dispose();
            }
        }
    });
}
 
Example #5
Source File: MultiResolutionToolkitImageTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean imageUpdate(Image img, int infoflags, int x, int y,
        int width, int height) {

    if (isRVObserver()) {
        isRVObserverCalled = true;
        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Image resolutionVariant = getResolutionVariant(img);
        int rvFlags = toolkit.checkImage(resolutionVariant, width, height,
                new IdleImageObserver());
        if (rvFlags < infoflags) {
            throw new RuntimeException("Info flags are greater than"
                    + " resolution varint info flags");
        }
    } else if ((infoflags & ALLBITS) != 0) {
        isImageLoaded = true;
    }

    return (infoflags & ALLBITS) == 0;
}
 
Example #6
Source File: Opt4JAbout.java    From opt4j with MIT License 6 votes vote down vote up
@Override
public JDialog getDialog(ApplicationFrame frame) {
	JDialog dialog = new JDialog(frame, "About Opt4J", true);
	dialog.setBackground(Color.WHITE);
	dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
	dialog.setResizable(false);

	Opt4JAbout content = new Opt4JAbout();
	content.startup();
	dialog.add(content);

	Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
	Dimension window = dialog.getPreferredSize();
	dialog.setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);

	return dialog;
}
 
Example #7
Source File: RCClient.java    From oim-fx with MIT License 6 votes vote down vote up
public static void main(String[] args) throws IOException {

		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		RemoteControlFrame rcm = new RemoteControlFrame();
		rcm.setVisible(true);
		new Thread(new Runnable() {
			public void run() {
				while (true) {
					BufferedImage img = ScreenCapture.getScreen(0, 0, (int) d.getWidth(), (int) d.getHeight());
					rcm.setIcon(new ImageIcon(img));
					try {
						Thread.sleep(20);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
	}
 
Example #8
Source File: KeyCharTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

        Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setVisible(true);
        toolkit.realSync();

        Robot robot = new Robot();

        robot.keyPress(KeyEvent.VK_DELETE);
        robot.keyRelease(KeyEvent.VK_DELETE);
        toolkit.realSync();

        frame.dispose();

        if (eventsCount != 3) {
            throw new RuntimeException("Wrong number of key events: " + eventsCount);
        }
    }
 
Example #9
Source File: GraphicUtils.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
    * Sets the location of the specified window so that it is centered on
    * screen.
    * 
    * @param window
    *            The window to be centered.
    */
   public static void centerWindowOnScreen(Window window) {
final Dimension screenSize = Toolkit.getDefaultToolkit()
	.getScreenSize();
final Dimension size = window.getSize();

if (size.height > screenSize.height) {
    size.height = screenSize.height;
}

if (size.width > screenSize.width) {
    size.width = screenSize.width;
}

window.setLocation((screenSize.width - size.width) / 2,
	(screenSize.height - size.height) / 2);
   }
 
Example #10
Source File: CopyActionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void tearDown() throws Exception {
    Waiter waiter = new Waiter(new Waitable() {

        @Override
        public Object actionProduced(Object obj) {
            Object clipboard2 = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
            return clipboard1 != clipboard2 ? Boolean.TRUE : null;
        }

        @Override
        public String getDescription() {
            return ("Wait clipboard contains data");
        }
    });
    waiter.waitAction(null);
}
 
Example #11
Source File: bug4524490.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");

    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            fileChooser = new JFileChooser();
            fileChooser.showOpenDialog(null);
        }
    });

    toolkit.realSync();

    if (OSInfo.OSType.MACOSX.equals(OSInfo.getOSType())) {
        Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_L);
    } else {
        Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_L);
    }
    checkFocus();
}
 
Example #12
Source File: DeadKeySystemAssertionDialog.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        frame.setVisible(true);
        toolkit.realSync();

        textField.requestFocus();
        toolkit.realSync();

        // Check that the system assertion dialog does not block Java
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        frame.setVisible(false);
        frame.dispose();
    }
 
Example #13
Source File: MousePrintRecorder.java    From sc2gears with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new Recorder.
 */
public Recorder() {
	super( "Mouse Print Recorder" );
	
	WhatToSave whatToSave_;
	try {
		whatToSave_ = WhatToSave.values()[ Settings.getInt( Settings.KEY_SETTINGS_MISC_MOUSE_PRINT_WHAT_TO_SAVE ) ];
	} catch ( final IllegalArgumentException iae ) {
		whatToSave_ = WhatToSave.values()[ Settings.getDefaultInt( Settings.KEY_SETTINGS_MISC_MOUSE_PRINT_WHAT_TO_SAVE ) ];
	}
	whatToSave = whatToSave_;
	
	samplingTime = Settings.getInt( Settings.KEY_SETTINGS_MISC_MOUSE_PRINT_SAMPLING_TIME );
	
	final Toolkit toolkit = Toolkit.getDefaultToolkit();
	screenResolution = toolkit.getScreenResolution();
	final Dimension screenSize = toolkit.getScreenSize();
	buffer = new BufferedImage( screenSize.width, screenSize.height, BufferedImage.TYPE_INT_RGB );
	dataStream = whatToSave.saveBinaryData ? new ByteArrayOutputStream( 100000 ) : null;
	
	setRecorderFrameRefreshRate( RECORDER_REFRESH_RATES[ Settings.getInt( Settings.KEY_MOUSE_PRINT_REFRESH_RATE ) ] );
}
 
Example #14
Source File: KeyCharTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

        Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setVisible(true);
        toolkit.realSync();

        Robot robot = new Robot();

        robot.keyPress(KeyEvent.VK_DELETE);
        robot.keyRelease(KeyEvent.VK_DELETE);
        toolkit.realSync();

        frame.dispose();

        if (eventsCount != 3) {
            throw new RuntimeException("Wrong number of key events: " + eventsCount);
        }
    }
 
Example #15
Source File: CEmbeddedFrame.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void handleFocusEvent(boolean focused) {
    synchronized (classLock) {
        // In some cases an applet may not receive the focus lost event
        // from the parent window (see 8012330)
        globalFocusedWindow = (focused) ? this
                : ((globalFocusedWindow == this) ? null : globalFocusedWindow);
    }
    if (globalFocusedWindow == this) {
        // see bug 8010925
        // we can't put this to handleWindowFocusEvent because
        // it won't be invoced if focuse is moved to a html element
        // on the same page.
        CClipboard clipboard = (CClipboard) Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.checkPasteboardAndNotify();
    }
    if (parentWindowActive) {
        responder.handleWindowFocusEvent(focused, null);
    }
}
 
Example #16
Source File: NSImageToMultiResolutionImageTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            return;
        }

        String icon = "NSImage://NSApplicationIcon";
        final Image image = Toolkit.getDefaultToolkit().getImage(icon);

        if (!(image instanceof MultiResolutionImage)) {
            throw new RuntimeException("Icon does not have resolution variants!");
        }

        MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

        int width = 0;
        int height = 0;

        for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
            int rvWidth = resolutionVariant.getWidth(null);
            int rvHeight = resolutionVariant.getHeight(null);
            if (rvWidth < width || rvHeight < height) {
                throw new RuntimeException("Resolution variants are not sorted!");
            }
            width = rvWidth;
            height = rvHeight;
        }
    }
 
Example #17
Source File: XmlReporter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate text report.
 */
public void writeReport(BenchInfo[] binfo, Properties props)
    throws IOException
{
    PrintStream p = new PrintStream(out);

    p.println("<REPORT>");
    p.println("<NAME>" + title + "</NAME>");
    p.println("<DATE>" + new Date() + "</DATE>");
    p.println("<VERSION>" + props.getProperty("java.version") +
            "</VERSION>");
    p.println("<VENDOR>" + props.getProperty("java.vendor") + "</VENDOR>");
    p.println("<DIRECTORY>" + props.getProperty("java.home") +
            "</DIRECTORY>");
    String vmName = props.getProperty("java.vm.name");
    String vmInfo = props.getProperty("java.vm.info");
    String vmString = (vmName != null && vmInfo != null) ?
        vmName + " " + vmInfo : "Undefined";
    p.println("<VM_INFO>" + vmString + "</VM_INFO>");
    p.println("<OS>" + props.getProperty("os.name") +
            " version " + props.getProperty("os.version") + "</OS>");
    p.println("<BIT_DEPTH>" +
            Toolkit.getDefaultToolkit().getColorModel().getPixelSize() +
            "</BIT_DEPTH>");
    p.println();

    p.println("<DATA RUNS=\"" + 1 + "\" TESTS=\"" + binfo.length + "\">");
    for (int i = 0; i < binfo.length; i++) {
        BenchInfo b = binfo[i];
        String score = (b.getTime() != -1) ?
            Double.toString(b.getTime() * b.getWeight()) : "-1";
        p.println(b.getName() + "\t" + score);
    }

    p.println("</DATA>");
    p.println("</REPORT>");
}
 
Example #18
Source File: InputMethodPopupMenu.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a localized locale name for input methods with the
 * given locale. It falls back to Locale.getDisplayName() and
 * then to Locale.toString() if no localized locale name is found.
 *
 * @param locale Locale for which localized locale name is obtained
 */
String getLocaleName(Locale locale) {
    String localeString = locale.toString();
    String localeName = Toolkit.getProperty("AWT.InputMethodLanguage." + localeString, null);
    if (localeName == null) {
        localeName = locale.getDisplayName();
        if (localeName == null || localeName.length() == 0)
            localeName = localeString;
    }
    return localeName;
}
 
Example #19
Source File: StatusLineComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void hidePopup() {
        if (GraphicsEnvironment.isHeadless()) {
            return;
        }
        if (popupWindow != null) {
//            popupWindow.getContentPane().removeAll();
            popupWindow.setVisible(false);
        }
        Toolkit.getDefaultToolkit().removeAWTEventListener(hideListener);
        WindowManager.getDefault().getMainWindow().removeWindowStateListener(hideListener);
        WindowManager.getDefault().getMainWindow().removeComponentListener(hideListener);
        showingPopup = false;
    }
 
Example #20
Source File: NameExchangeFrame.java    From Qora with MIT License 5 votes vote down vote up
public NameExchangeFrame() 
{
	//CREATE FRAME
	super("Qora - Name Exchange");
	
	//ICON
	List<Image> icons = new ArrayList<Image>();
	icons.add(Toolkit.getDefaultToolkit().getImage("images/icons/icon16.png"));
	icons.add(Toolkit.getDefaultToolkit().getImage("images/icons/icon32.png"));
	icons.add(Toolkit.getDefaultToolkit().getImage("images/icons/icon64.png"));
	icons.add(Toolkit.getDefaultToolkit().getImage("images/icons/icon128.png"));
	this.setIconImages(icons);
	
	//NAME EXCHANGE TABPANE
       this.nameExchangeTabPane = new NameExchangeTabPane();
	
	//ON CLOSE
	this.addWindowListener(new WindowAdapter()
	{
           public void windowClosing(WindowEvent e)
           {
           	//CLOSE name EXCHANGE
               nameExchangeTabPane.close();
               
               //DISPOSE
               setVisible(false);
               dispose();
           }
       });
	       
	 //ADD GENERAL TABPANE TO FRAME
       this.add(this.nameExchangeTabPane);
       
       //SHOW FRAME
       this.pack();
       this.setLocationRelativeTo(null);
       this.setVisible(true);
}
 
Example #21
Source File: JBRCustomDecorations.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
private Color calculateActiveBorderColor() {
	if( !colorizationAffectsBorders )
		return defaultActiveBorder;

	Toolkit toolkit = Toolkit.getDefaultToolkit();
	Color colorizationColor = (Color) toolkit.getDesktopProperty( "win.dwm.colorizationColor" );
	if( colorizationColor != null ) {
		Object colorizationColorBalanceObj = toolkit.getDesktopProperty( "win.dwm.colorizationColorBalance" );
		if( colorizationColorBalanceObj instanceof Integer ) {
			int colorizationColorBalance = (Integer) colorizationColorBalanceObj;
			if( colorizationColorBalance < 0 )
				colorizationColorBalance = 100;

			if( colorizationColorBalance == 0 )
				return new Color( 0xD9D9D9 );
			if( colorizationColorBalance == 100 )
				return colorizationColor;

			float alpha = colorizationColorBalance / 100.0f;
			float remainder = 1 - alpha;
			int r = Math.round( (colorizationColor.getRed() * alpha + 0xD9 * remainder) );
			int g = Math.round( (colorizationColor.getGreen() * alpha + 0xD9 * remainder) );
			int b = Math.round( (colorizationColor.getBlue() * alpha + 0xD9 * remainder) );
			return new Color( r, g, b );
		}
		return colorizationColor;
	}

	Color activeBorderColor = (Color) toolkit.getDesktopProperty( "win.frame.activeBorderColor" );
	return (activeBorderColor != null) ? activeBorderColor : UIManager.getColor( "MenuBar.borderColor" );
}
 
Example #22
Source File: DragSource.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Start a drag, given the <code>DragGestureEvent</code>
 * that initiated the drag, the initial
 * <code>Cursor</code> to use,
 * the <code>Image</code> to drag,
 * the offset of the <code>Image</code> origin
 * from the hotspot of the <code>Cursor</code> at
 * the instant of the trigger,
 * the <code>Transferable</code> subject data
 * of the drag, the <code>DragSourceListener</code>,
 * and the <code>FlavorMap</code>.
 * <P>
 * @param trigger        the <code>DragGestureEvent</code> that initiated the drag
 * @param dragCursor     the initial {@code Cursor} for this drag operation
 *                       or {@code null} for the default cursor handling;
 *                       see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a>
 *                       for more details on the cursor handling mechanism during drag and drop
 * @param dragImage      the image to drag or {@code null}
 * @param imageOffset    the offset of the <code>Image</code> origin from the hotspot
 *                       of the <code>Cursor</code> at the instant of the trigger
 * @param transferable   the subject data of the drag
 * @param dsl            the <code>DragSourceListener</code>
 * @param flavorMap      the <code>FlavorMap</code> to use, or <code>null</code>
 * <P>
 * @throws java.awt.dnd.InvalidDnDOperationException
 *    if the Drag and Drop
 *    system is unable to initiate a drag operation, or if the user
 *    attempts to start a drag while an existing drag operation
 *    is still executing
 */

public void startDrag(DragGestureEvent   trigger,
                      Cursor             dragCursor,
                      Image              dragImage,
                      Point              imageOffset,
                      Transferable       transferable,
                      DragSourceListener dsl,
                      FlavorMap          flavorMap) throws InvalidDnDOperationException {

    SunDragSourceContextPeer.setDragDropInProgress(true);

    try {
        if (flavorMap != null) this.flavorMap = flavorMap;

        DragSourceContextPeer dscp = Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger);

        DragSourceContext     dsc = createDragSourceContext(dscp,
                                                            trigger,
                                                            dragCursor,
                                                            dragImage,
                                                            imageOffset,
                                                            transferable,
                                                            dsl
                                                            );

        if (dsc == null) {
            throw new InvalidDnDOperationException();
        }

        dscp.startDrag(dsc, dsc.getCursor(), dragImage, imageOffset); // may throw
    } catch (RuntimeException e) {
        SunDragSourceContextPeer.setDragDropInProgress(false);
        throw e;
    }
}
 
Example #23
Source File: ShakeWindow.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
    * punishes the User by moving the Chatwindow around for 10 seconds
    */
   public void startRandomMovement(final int seconds)
   {
if(window instanceof JFrame){
           JFrame f = (JFrame)window;
           f.setState(Frame.NORMAL);
           f.setVisible(true);
       }
       SparkManager.getNativeManager().flashWindow(window);
       
       final long startTime = System.currentTimeMillis()/1000L;
       
moveTimer = new Timer(5, e -> {
   Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

   double x = Math.random()*10000 % d.getWidth();
   double y = Math.random()*10000 % d.getHeight();
   int xx = Math.round(Math.round(x));
   int yy = Math.round(Math.round(y));
   window.setLocation(xx,yy);
   window.repaint();

   long now = System.currentTimeMillis()/1000L;
   long diff = now-startTime;
   System.out.println(diff);
   if(diff > seconds)
   {
       moveTimer.stop();
   }

       } );

moveTimer.start();

   }
 
Example #24
Source File: SelectionInvisibleTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        Frame frame = new Frame();
        frame.setSize(300, 200);
        TextField textField = new TextField(TEXT + LAST_WORD, 30);
        Panel panel = new Panel(new FlowLayout());
        panel.add(textField);
        frame.add(panel);
        frame.setVisible(true);

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        toolkit.realSync();

        Robot robot = new Robot();
        robot.setAutoDelay(50);

        Point point = textField.getLocationOnScreen();
        int x = point.x + textField.getWidth() / 2;
        int y = point.y + textField.getHeight() / 2;
        robot.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        robot.mousePress(InputEvent.BUTTON1_MASK);
        int N = 10;
        int dx = textField.getWidth() / N;
        for (int i = 0; i < N; i++) {
            x += dx;
            robot.mouseMove(x, y);
        }
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        if (!textField.getSelectedText().endsWith(LAST_WORD)) {
            throw new RuntimeException("Last word is not selected!");
        }
    }
 
Example #25
Source File: EncryptionTool.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the password of the currently displayed control.
 *
 * @param password the password
 */
private void setPassword(String password) {
  XMLControlElement control = getCurrentControl();
  if(control==null) {
    return;
  }
  String pass = control.getPassword();
  if(!encryptedCheckBox.isEnabled()) {
    boolean verified = password.equals(pass);
    if(verified) {
      displayXML(decrypt(control));
      encryptedCheckBox.setEnabled(true);
    } else {
      Toolkit.getDefaultToolkit().beep();
      OSPLog.fine("Bad password: "+password);                  //$NON-NLS-1$
    }
  } else if(control.getObjectClass()==Cryptic.class) {
    // decrypt control, change password, and re-encrypt
    XMLControlElement temp = decrypt(control);
    temp.setPassword(password);
    temp = encrypt(temp);
    control.setValue("cryptic", temp.getString("cryptic"));    //$NON-NLS-1$ //$NON-NLS-2$
    treePanel.refresh();
  } else {
    // change password
    if(password.equals("")&&!encryptedCheckBox.isSelected()) { //$NON-NLS-1$
      password = null;
    }
    control.setPassword(password);
    treePanel.refresh();
    //      treePanel.setSelectedNode("xml_password"); //$NON-NLS-1$
  }
  refreshGUI();
}
 
Example #26
Source File: bug8057893.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

    EventQueue.invokeAndWait(() -> {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        JComboBox<String> comboBox = new JComboBox<>(new String[]{"one", "two"});
        comboBox.setEditable(true);
        comboBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if ("comboBoxEdited".equals(e.getActionCommand())) {
                    isComboBoxEdited = true;
                }
            }
        });
        frame.add(comboBox);
        frame.pack();
        frame.setVisible(true);
        comboBox.requestFocusInWindow();
    });

    toolkit.realSync();

    robot.keyPress(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_A);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    toolkit.realSync();

    if(!isComboBoxEdited){
        throw new RuntimeException("ComboBoxEdited event is not fired!");
    }
}
 
Example #27
Source File: FilterUtils.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
    if (!FILTER_ACTION_KEY.equals(actionKey)) return null;
    
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    actionMap.put(actionKey, action);
    inputMap.put(ks, actionKey);

    return ks;
}
 
Example #28
Source File: DragSource.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reports
 * whether or not drag
 * <code>Image</code> support
 * is available on the underlying platform.
 * <P>
 * @return if the Drag Image support is available on this platform
 */

public static boolean isDragImageSupported() {
    Toolkit t = Toolkit.getDefaultToolkit();

    Boolean supported;

    try {
        supported = (Boolean)Toolkit.getDefaultToolkit().getDesktopProperty("DnD.isDragImageSupported");

        return supported.booleanValue();
    } catch (Exception e) {
        return false;
    }
}
 
Example #29
Source File: _AppEventLegacyHandler.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void printFiles(PrintFilesEvent e) {
    final List<File> files = e.getFiles();
    for (final File file : files) { // legacy ApplicationListeners only understood one file at a time
        final ApplicationEvent ae = new ApplicationEvent(Toolkit.getDefaultToolkit(), file.getAbsolutePath());
        sendEventToEachListenerUntilHandled(ae, new EventDispatcher() {
            public void dispatchEvent(final ApplicationListener listener) {
                listener.handlePrintFile(ae);
            }
        });
    }
}
 
Example #30
Source File: Metalworks.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    JDialog.setDefaultLookAndFeelDecorated(true);
    JFrame.setDefaultLookAndFeelDecorated(true);
    Toolkit.getDefaultToolkit().setDynamicLayout(true);
    System.setProperty("sun.awt.noerasebackground", "true");
    try {
        UIManager.setLookAndFeel(new MetalLookAndFeel());
    } catch (UnsupportedLookAndFeelException e) {
        System.out.println(
                "Metal Look & Feel not supported on this platform. \n"
                + "Program Terminated");
        System.exit(0);
    }
    JFrame frame = new MetalworksFrame();
    frame.setVisible(true);
}