Java Code Examples for java.awt.Toolkit

The following are top voted examples for showing how to use java.awt.Toolkit. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: PointerInfoCrashTest.java   View source code 7 votes vote down vote up
private static void testMouseInfoPeer() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    if (toolkit instanceof ComponentFactory) {
        ComponentFactory componentFactory = (ComponentFactory) toolkit;

        MouseInfoPeer mouseInfoPeer = componentFactory.getMouseInfoPeer();
        mouseInfoPeer.fillPointWithCoords(new Point());

        Window win = new Window(null);
        win.setSize(300, 300);
        win.setVisible(true);

        mouseInfoPeer.isWindowUnderMouse(win);
        win.dispose();
    }
}
 
Example 2
Project: AgentWorkbench   File: ChartEditorJDialog.java   View source code 6 votes vote down vote up
/**
 * Instantiates a new JDialog as chart editor .
 *
 * @param dynForm the {@link DynForm}
 * @param startArgIndex the start argument index
 */
public ChartEditorJDialog(DynForm dynForm, int startArgIndex) {
	
	this.dynForm = dynForm;
	this.startArgIndex = startArgIndex;
	
	this.setModal(true);
	this.setSize(600, 450);
	this.setIconImage(imageAgentGUI);
	this.setTitle(Language.translate("Edit Chart", Language.EN));
	
	// --- center dialog --------------------
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 
	int top = (screenSize.height - this.getHeight()) / 2; 
    int left = (screenSize.width - this.getWidth()) / 2; 
    this.setLocation(left, top);	


    this.setContentPane(this.getContentPane());
	this.getContentPane().add(getButtonPane(), BorderLayout.SOUTH);

}
 
Example 3
Project: jdk8u-jdk   File: DitherTest.java   View source code 6 votes vote down vote up
@Override
protected void processEvent(AWTEvent evt) {
    int id = evt.getID();
    if (id != KeyEvent.KEY_TYPED) {
        super.processEvent(evt);
        return;
    }

    KeyEvent kevt = (KeyEvent) evt;
    char c = kevt.getKeyChar();

    // Digits, backspace, and delete are okay
    // Note that the minus sign is not allowed (neither is decimal)
    if (Character.isDigit(c) || (c == '\b') || (c == '\u007f')) {
        super.processEvent(evt);
        return;
    }

    Toolkit.getDefaultToolkit().beep();
    kevt.consume();
}
 
Example 4
Project: WordnetLoom   File: ShortCut.java   View source code 6 votes vote down vote up
/**
 * Ukonanie akcji zwiazanej ze skrotem
 */
public void doAction() {
    // czy jest to skrót do przycisku
    // jeśli tak to wywoływany jest click
    if (button != null && button.isEnabled()) {
        button.doClick();

        // jest to skrót do komponentu
        // a więc ustawienie focuu
    } else if (component != null) {
        if (pane != null) {          // zmienie aktywnej zakladki
            pane.setSelectedIndex(tabIndex);
            Toolkit.getDefaultToolkit().sync();
        }
        component.grabFocus(); // ustawienie focusu
    } else if (action != null) {
        action.doAction(null, -1);
    }
}
 
Example 5
Project: litiengine   File: ImageProcessing.java   View source code 6 votes vote down vote up
/**
 * All pixels that have the specified color are rendered transparent.
 *
 * @param img
 *          the img
 * @param color
 *          the color
 * @return the image
 */
public static Image applyAlphaChannel(final Image img, final Color color) {
  if (color == null || img == null) {
    return img;
  }

  final ImageFilter filter = new RGBImageFilter() {

    // the color we are looking for... Alpha bits are set to opaque
    public final int markerRGB = color.getRGB() | 0xFF000000;

    @Override
    public final int filterRGB(final int x, final int y, final int rgb) {
      if ((rgb | 0xFF000000) == this.markerRGB) {
        // Mark the alpha bits as zero - transparent
        return 0x00FFFFFF & rgb;
      } else {
        // nothing to do
        return rgb;
      }
    }
  };

  final ImageProducer ip = new FilteredImageSource(img.getSource(), filter);
  return Toolkit.getDefaultToolkit().createImage(ip);
}
 
Example 6
Project: incubator-netbeans   File: TooltipWindow.java   View source code 6 votes vote down vote up
public void show(Point location) {
    Rectangle screenBounds = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gds = ge.getScreenDevices();
    for (GraphicsDevice device : gds) {
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        screenBounds = gc.getBounds();
        if (screenBounds.contains(location)) {
            break;
        }
    }

    // showing the popup tooltip
    cp = new TooltipContentPanel(master.getTextComponent());

    Window w = SwingUtilities.windowForComponent(master.getTextComponent());
    contentWindow = new JWindow(w);
    contentWindow.add(cp);
    contentWindow.pack();
    Dimension dim = contentWindow.getSize();

    if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) {
        dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER);
    }
    if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) {
        dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER);
    }

    contentWindow.setSize(dim);

    contentWindow.setLocation(location.x, location.y - 1);  // slight visual adjustment
    contentWindow.setVisible(true);

    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
    w.addWindowFocusListener(this);
    contentWindow.addWindowFocusListener(this);
}
 
Example 7
Project: incubator-netbeans   File: HintsUI.java   View source code 6 votes vote down vote up
private void removePopup() {
    Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    if (listPopup != null) {
        closeSubList();
        if( tooltipPopup != null )
            tooltipPopup.hide();
        tooltipPopup = null;
        listPopup.hide();
        if (hintListComponent != null) {
            hintListComponent.getView().removeMouseListener(this);
            hintListComponent.getView().removeMouseMotionListener(this);
        }
        if (errorTooltip != null) {
            errorTooltip.removeMouseListener(this);
        }
        hintListComponent = null;
        errorTooltip = null;
        listPopup = null;
        if (hintIcon != null)
            hintIcon.setToolTipText(NbBundle.getMessage(HintsUI.class, "HINT_Bulb")); // NOI18N
    }
}
 
Example 8
Project: blitzcrank_screenshoot   File: Blitzcrank.java   View source code 6 votes vote down vote up
/**
 * @param args the command line arguments
 * @throws java.awt.AWTException
 * @throws java.lang.InterruptedException
 * @throws java.io.IOException
 */
public static void main(String[] args) throws AWTException, InterruptedException, IOException {
    String stringfyCurrent = String.valueOf(System.currentTimeMillis());
    String path = "{path}";
    String name = "capture" + stringfyCurrent;
    String type = ".jpg";
    //--
    File file = new File(path + name + type);
    BufferedImage imagexd = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(imagexd, type.replace(".", ""), baos);
    byte[] bytes = baos.toByteArray();

    OutputStream out = new FileOutputStream(file);

    out.write(bytes);
    
}
 
Example 9
Project: jNotifyOSD   File: ServerOSD.java   View source code 6 votes vote down vote up
private Dimension getDeviceDimension() {
    Dimension deviceDimension = null;
    try {
        Toolkit tool = Toolkit.getDefaultToolkit();
        deviceDimension = tool.getScreenSize();
    } catch (AWTError e) {
        System.out.println(CLASS_NAME+": ERROR! "+ e.getMessage());
        e.printStackTrace();
    }
    return deviceDimension;
}
 
Example 10
Project: incubator-netbeans   File: FastTypeProvider.java   View source code 6 votes vote down vote up
@Override
public void open() {
    boolean success = false;
    try {
        final FileObject fo = getFileObject();
        if (fo != null) {
            final DataObject d = DataObject.find(fo);
            final EditCookie cake = d.getCookie(EditCookie.class);
            if (cake != null) {
                cake.edit();
                success = true;
            }
        }
    } catch (DataObjectNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    }
    if (!success) {
        Toolkit.getDefaultToolkit().beep();
    }
}
 
Example 11
Project: incubator-netbeans   File: KeyboardDnd.java   View source code 6 votes vote down vote up
private void stop( boolean commitChanges ) {
    Toolkit.getDefaultToolkit().removeAWTEventListener( this );
    TopComponent.getRegistry().removePropertyChangeListener( this );
    try {
        if( commitChanges ) {
            TopComponentDroppable droppable = targets.get( currentIndex );
            Point dropLocation = currentSide.getDropLocation( droppable );
            if( droppable.canDrop( draggable, dropLocation ) ) {
                dndManager.performDrop( dndManager.getController(), droppable, draggable, dropLocation );
            }
        }
    } finally {
        dndManager.dragFinished();
        dndManager.dragFinishedEx();
        if( currentDnd == this )
            currentDnd = null;
    }
}
 
Example 12
Project: jdk8u-jdk   File: MaximizedToMaximized.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {

       Frame frame = new Frame();
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
        final GraphicsEnvironment graphicsEnvironment =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        final GraphicsDevice graphicsDevice =
                graphicsEnvironment.getDefaultScreenDevice();

        final Dimension screenSize = toolkit.getScreenSize();
        final Insets screenInsets = toolkit.getScreenInsets(
                graphicsDevice.getDefaultConfiguration());

        final Rectangle availableScreenBounds = new Rectangle(screenSize);

        availableScreenBounds.x += screenInsets.left;
        availableScreenBounds.y += screenInsets.top;
        availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
        availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);

        frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
                availableScreenBounds.width, availableScreenBounds.height);
        frame.setVisible(true);

        Rectangle frameBounds = frame.getBounds();
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        ((SunToolkit) toolkit).realSync();

        Rectangle maximizedFrameBounds = frame.getBounds();
        if (maximizedFrameBounds.width < frameBounds.width
                || maximizedFrameBounds.height < frameBounds.height) {
            throw new RuntimeException("Maximized frame is smaller than non maximized");
        }
    }
 
Example 13
Project: incubator-netbeans   File: ModeResizer.java   View source code 6 votes vote down vote up
private void stop( boolean commitChanges ) {
    Toolkit.getDefaultToolkit().removeAWTEventListener( this );
    TopComponent.getRegistry().removePropertyChangeListener( this );
    if( null != frame ) {
        boolean glassVisible = oldGlass.isVisible();
        frame.setGlassPane( oldGlass);
        oldGlass.setVisible( glassVisible );
    }
    if( !commitChanges ) {
        if( null != parentSplitter ) {
            parentSplitter.finishDraggingTo( originalParentLocation );
        }
        splitter.finishDraggingTo( originalLocation );
    }
    if( currentResizer == this )
        currentResizer = null;
}
 
Example 14
Project: jdk8u-jdk   File: Metalworks.java   View source code 6 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);
}
 
Example 15
Project: Equella   File: JNumberTextField.java   View source code 6 votes vote down vote up
@Override
public void insertString(int offset, String s, AttributeSet attributeSet) throws BadLocationException
{
	try
	{
		int value = Integer.parseInt(s);
		if( value < 0 )
		{
			Toolkit.getDefaultToolkit().beep();
			return;
		}
	}
	catch( NumberFormatException ex )
	{
		Toolkit.getDefaultToolkit().beep();
		return;
	}

	super.insertString(offset, s, attributeSet);

	if( Integer.parseInt(getText(0, getLength())) > maxNumber )
	{
		Toolkit.getDefaultToolkit().beep();
		super.remove(offset, s.length());
	}
}
 
Example 16
Project: incubator-netbeans   File: SystemActionTest.java   View source code 6 votes vote down vote up
/** Test that iconResource really works.
 * @see "#26887"
 */
public void testIcons() throws Exception {
    Image i = Toolkit.getDefaultToolkit().getImage(SystemActionTest.class.getResource("data/someicon.gif"));
    int h = imageHash("Control icon", i, 16, 16);
    SystemAction a = SystemAction.get(SystemAction1.class);
    CharSequence log = Log.enable("org.openide.util", Level.WARNING);
    assertEquals("Absolute slash-initial iconResource works (though deprecated)", h, imageHash("icon1", icon2Image(a.getIcon()), 16, 16));
    assertTrue(log.toString(), log.toString().contains("Initial slashes in Utilities.loadImage deprecated"));
    a = SystemAction.get(SystemAction2.class);
    assertEquals("Absolute no-slash-initial iconResource works", h, imageHash("icon2", icon2Image(a.getIcon()), 16, 16));
    a = SystemAction.get(SystemAction3.class);
    assertEquals("Relative iconResource works (though deprecated)", h, imageHash("icon3", icon2Image(a.getIcon()), 16, 16));
    assertTrue(log.toString(), log.toString().contains("Deprecated relative path"));
    a = SystemAction.get(SystemAction4.class);
    a.getIcon();
    assertTrue(log.toString(), log.toString().contains("No such icon"));
}
 
Example 17
Project: openjdk-jdk10   File: CSS.java   View source code 6 votes vote down vote up
ImageIcon getImage(URL base) {
    if (!loadedImage) {
        synchronized(this) {
            if (!loadedImage) {
                URL url = CSS.getURL(base, svalue);
                loadedImage = true;
                if (url != null) {
                    image = new ImageIcon();
                    Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
                    if (tmpImg != null) {
                        image.setImage(tmpImg);
                    }
                }
            }
        }
    }
    return image;
}
 
Example 18
Project: jdk8u-jdk   File: WPageDialog.java   View source code 6 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public void addNotify() {
    synchronized(getTreeLock()) {
        Container parent = getParent();
        if (parent != null && parent.getPeer() == null) {
            parent.addNotify();
        }

        if (getPeer() == null) {
            ComponentPeer peer = ((WToolkit)Toolkit.getDefaultToolkit()).
                createWPageDialog(this);
            setPeer(peer);
        }
        super.addNotify();
    }
}
 
Example 19
Project: jdk8u-jdk   File: bug7189299.java   View source code 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 20
Project: LP_Proyecto   File: Principal.java   View source code 6 votes vote down vote up
private void jl_Imagen_ContactsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jl_Imagen_ContactsMouseClicked
    // TODO add your handling code here:
    jl_Imagen_Contacts.setText("");

    JFileChooser fc = new JFileChooser();
    FileFilter filtro = new FileNameExtensionFilter("Imagenes", "png", "jpg", "jpeg", "gif");
    fc.setFileFilter(filtro);

    File Archivo;
    int op = fc.showOpenDialog(this);

    if (op == JFileChooser.APPROVE_OPTION) {
        Archivo = fc.getSelectedFile();
        RutaImagen = Archivo.getPath();
        System.out.println(Archivo.getPath());
        Image Img = Toolkit.getDefaultToolkit().createImage(Archivo.getPath()).getScaledInstance(180, 229, 0);
        this.jl_Imagen_Contacts.setIcon(new ImageIcon(Img));
    }
}
 
Example 21
Project: SpotSpotter   File: BMPReader.java   View source code 6 votes vote down vote up
protected static Image readImage24(FileInputStream fs, BitmapHeader bh) throws IOException {
	Image image;
	if (bh.iSizeimage == 0) {
		bh.iSizeimage = ((((bh.iWidth * bh.iBitcount) + 31) & ~31) >> 3);
		bh.iSizeimage *= bh.iHeight;
	}
	final int npad = (bh.iSizeimage / bh.iHeight) - bh.iWidth * 3;
	final int ndata[] = new int[bh.iHeight * bh.iWidth];
	final byte brgb[] = new byte[(bh.iWidth + npad) * 3 * bh.iHeight];
	fs.read(brgb, 0, (bh.iWidth + npad) * 3 * bh.iHeight);
	int nindex = 0;
	for (int j = 0; j < bh.iHeight; j++) {
		for (int i = 0; i < bh.iWidth; i++) {
			ndata[bh.iWidth * (bh.iHeight - j - 1) + i] = constructInt3(brgb, nindex);
			nindex += 3;
		}
		nindex += npad;
	}
	image = Toolkit.getDefaultToolkit()
			.createImage(new MemoryImageSource(bh.iWidth, bh.iHeight, ndata, 0, bh.iWidth));
	fs.close();
	return (image);
}
 
Example 22
Project: geomapapp   File: Cursors.java   View source code 6 votes vote down vote up
public static Cursor getCursor( int which ) {
	Cursor c = (Cursor) cursorCache.get(new Integer(which));
	if (c != null) return c;

	try {
		ClassLoader loader = org.geomapapp.util.Icons.class.getClassLoader();
		String path = "org/geomapapp/resources/icons/" +names[which];
		java.net.URL url = loader.getResource(path);
		BufferedImage im = ImageIO.read(url);
		String name = names[which].substring(0, names[which].lastIndexOf("."));
		System.out.println(im.getWidth() + "\t" + im.getHeight());
		
		c = Toolkit.getDefaultToolkit().createCustomCursor(im, new Point(hotSpot[which][0],hotSpot[which][1]), name);
		cursorCache.put(new Integer(which), c);
		return c;
	} catch(Exception ex) {
		return Cursor.getDefaultCursor();
	}
}
 
Example 23
Project: OpenJSharp   File: ExecutableInputMethodManager.java   View source code 6 votes vote down vote up
ExecutableInputMethodManager() {

        // set up host adapter locator
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        try {
            if (toolkit instanceof InputMethodSupport) {
                InputMethodDescriptor hostAdapterDescriptor =
                    ((InputMethodSupport)toolkit)
                    .getInputMethodAdapterDescriptor();
                if (hostAdapterDescriptor != null) {
                    hostAdapterLocator = new InputMethodLocator(hostAdapterDescriptor, null, null);
                }
            }
        } catch (AWTException e) {
            // if we can't get a descriptor, we'll just have to do without native input methods
        }

        javaInputMethodLocatorList = new Vector<InputMethodLocator>();
        initializeInputMethodLocatorList();
    }
 
Example 24
Project: powertext   File: RtfGenerator.java   View source code 5 votes vote down vote up
/**
 * Resets this generator.  All document information and content is
 * cleared.
 */
public void reset() {
	fontList.clear();
	colorList.clear();
	document.setLength(0);
	lastWasControlWord = false;
	lastFontIndex = 0;
	lastFGIndex = 0;
	lastBold = false;
	lastItalic = false;
	lastFontSize = DEFAULT_FONT_SIZE;
	screenRes = Toolkit.getDefaultToolkit().getScreenResolution();
}
 
Example 25
Project: NotifyTools   File: SimpleBeanInfo.java   View source code 5 votes vote down vote up
public Image loadImage(String resourceName) {
    if (null == resourceName) {
        return null;
    }
    
    URL file = getClass().getResource(resourceName);
    
    if (file != null) {
        return Toolkit.getDefaultToolkit().createImage(file);
    }
    return null;
}
 
Example 26
Project: jaer   File: EyeTarget.java   View source code 5 votes vote down vote up
/** Creates a new instance of EyeTarget */
public EyeTarget() {
	super(caps);
	addGLEventListener(this);
	setAutoSwapBufferMode(true);
	glu=new GLU();
	glut=new GLUT();
	Dimension ss=Toolkit.getDefaultToolkit().getScreenSize();
	ss.setSize(ss.width/2,ss.height/2);
	setSize(ss);
	target=new Target();
}
 
Example 27
Project: marathonv5   File: TransparentFrame.java   View source code 5 votes vote down vote up
public void dispose() {
    disposed = true;
    Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    SwingUtilities.invokeLater(new Runnable() {
        @Override public void run() {
            paintTransparentFrame();
        }
    });
}
 
Example 28
Project: freecol   File: DropListener.java   View source code 5 votes vote down vote up
/**
 * Gets called when the mouse was released on a Swing component
 * that has this object as a MouseListener.
 *
 * @param e The event that holds the information about the mouse click.
 */
@Override
public void mouseReleased(MouseEvent e) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable clipData = clipboard.getContents(clipboard);
    if (clipData != null) {
        if (clipData.isDataFlavorSupported(DefaultTransferHandler.flavor)) {
            JComponent comp = (JComponent)e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.importData(comp, clipData);
        }
    }
}
 
Example 29
Project: Hydrograph   File: TransformDialog.java   View source code 5 votes vote down vote up
/**
 * Return the initial size of the dialog.
 */
@Override
protected Point getInitialSize() {
	container.getShell().layout(true, true);
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	final Point newSize = container.getShell().computeSize(screenSize.width, screenSize.height, true);
	container.getShell().setSize(newSize);
	return newSize;
}
 
Example 30
Project: litiengine   File: KeyBoard.java   View source code 5 votes vote down vote up
@Override
public String getText(final KeyEvent e) {
  if (this.isPressed(KeyEvent.VK_SHIFT) || Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK)) {
    return this.getShiftText(e);
  } else if (this.isPressed(KeyEvent.VK_ALT_GRAPH)) {
    return this.getAltText(e);
  } else {
    return this.getNormalText(e);
  }
}
 
Example 31
Project: jdk8u-jdk   File: DragSource.java   View source code 5 votes vote down vote up
private static Cursor load(String name) {
    if (GraphicsEnvironment.isHeadless()) {
        return null;
    }

    try {
        return (Cursor)Toolkit.getDefaultToolkit().getDesktopProperty(name);
    } catch (Exception e) {
        e.printStackTrace();

        throw new RuntimeException("failed to load system cursor: " + name + " : " + e.getMessage());
    }
}
 
Example 32
Project: marathonv5   File: DocumentSizeFilter.java   View source code 5 votes vote down vote up
public void insertString(FilterBypass fb, int offs, String str, AttributeSet a) throws BadLocationException {
    if (DEBUG) {
        System.out.println("in DocumentSizeFilter's insertString method");
    }

    // This rejects the entire insertion if it would make
    // the contents too long. Another option would be
    // to truncate the inserted string so the contents
    // would be exactly maxCharacters in length.
    if ((fb.getDocument().getLength() + str.length()) <= maxCharacters)
        super.insertString(fb, offs, str, a);
    else
        Toolkit.getDefaultToolkit().beep();
}
 
Example 33
Project: rekit-game   File: GameView.java   View source code 5 votes vote down vote up
/**
 * Center {@link Frame} relative to monitor.
 *
 * @param frame
 *            the frame
 */
private void center(Frame frame) {
	Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
	int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2);
	int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2);
	frame.setLocation(x, y);
}
 
Example 34
Project: incubator-netbeans   File: SimpleEngine.java   View source code 5 votes vote down vote up
public Action getAction (final String action, String containerCtx, final Map context) {
    return new AbstractAction () {
        public void actionPerformed (ActionEvent ae) {
            SimpleInvoker invoker = interp.getInvoker(action);
            System.err.println("Invoker is " + invoker);
            System.err.println("Invoking " + action + " on " + context);
            if (invoker != null) {
                invoker.invoke(context);
            } else {
                Toolkit.getDefaultToolkit().beep();
            }
        }
    };
}
 
Example 35
Project: incubator-netbeans   File: TooltipWindow.java   View source code 5 votes vote down vote up
/**
 * Closes the window
 */
void shutdown() {
    Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    if (contentWindow != null) {
        contentWindow.getOwner().removeWindowFocusListener(this);
        contentWindow.removeWindowFocusListener(this);
        contentWindow.dispose();
    }
    contentWindow = null;
}
 
Example 36
Project: myfaces-trinidad   File: ImageUtils.java   View source code 5 votes vote down vote up
/**
 * Return true if the Image has been successfully loaded.
 * <p>
 * @param image Image to check for sucessful loading
 * <p>
 * @return True if the image has been sucessfully loaded.
 */
static public boolean isImageLoaded(
  Image image
  )
{
  Toolkit tk = Toolkit.getDefaultToolkit();
  int status = tk.checkImage(image, -1, -1, null);

  return ((status & (ImageObserver.ALLBITS |ImageObserver.FRAMEBITS)) != 0);
}
 
Example 37
Project: sentimental-analyzer   File: Analyzer.java   View source code 5 votes vote down vote up
/**
 * Initialize the contents of the frame.
 */
private void initialize() {
	frame = new JFrame();
	frame.setIconImage(Toolkit.getDefaultToolkit().getImage("E:\\图片\\u=1829416607,2140971604&fm=21&gp=0.jpg"));
	frame.setType(Type.UTILITY);
	frame.setTitle("网络电影评论情感倾向性分类");
	frame.setBounds(100, 100, 639, 412);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	JMenuBar menuBar = new JMenuBar();
	frame.setJMenuBar(menuBar);
	
	JMenu mnNewMenu = new JMenu("数据集自动标注");
	menuBar.add(mnNewMenu);
	
	JMenuItem mntmNewMenuItem_2 = new JMenuItem("自动标注");
	mnNewMenu.add(mntmNewMenuItem_2);
	
	JMenu mnNewMenu_1 = new JMenu("情感分析");
	menuBar.add(mnNewMenu_1);
	
	JMenuItem mntmNewMenuItem_3 = new JMenuItem("朴素贝叶斯算法");
	mnNewMenu_1.add(mntmNewMenuItem_3);
	
	JMenuItem mntmNewMenuItem_4 = new JMenuItem("N-Gram算法");
	mnNewMenu_1.add(mntmNewMenuItem_4);
	
	JMenuItem mntmNewMenuItem_5 = new JMenuItem("支持向量机");
	mnNewMenu_1.add(mntmNewMenuItem_5);
	
	JMenu mnNewMenu_2 = new JMenu("关于");
	menuBar.add(mnNewMenu_2);
	
	JMenuItem mntmNewMenuItem = new JMenuItem("作者");
	mnNewMenu_2.add(mntmNewMenuItem);
	
	JMenuItem mntmNewMenuItem_1 = new JMenuItem("New menu item");
	mnNewMenu_2.add(mntmNewMenuItem_1);
}
 
Example 38
Project: incubator-netbeans   File: Utils.java   View source code 5 votes vote down vote up
public static Graphics2D prepareGraphics(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Map rhints = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N
    if( rhints == null && Boolean.getBoolean("swing.aatext") ) { //NOI18N
         g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
    } else if( rhints != null ) {
        g2.addRenderingHints( rhints );
    }
    return g2;
}
 
Example 39
Project: org.alloytools.alloy   File: OurUtil.java   View source code 5 votes vote down vote up
/**
 * Construct a new JMenuItem then add it to an existing JMenu.
 * 
 * @param parent - the JMenu to add this JMenuItem into (or null if you
 *            don't want to add it to any JMenu yet)
 * @param label - the text to show on the menu
 * @param attrs - a list of attributes to apply onto the new JMenuItem
 *            <p>
 *            If one positive number a is supplied, we call setMnemonic(a)
 *            <p>
 *            If two positive numbers a and b are supplied, and a!=VK_ALT,
 *            and a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b)
 *            <p>
 *            If two positive numbers a and b are supplied, and a==VK_ALT or
 *            a==VK_SHIFT, we call setAccelerator(a | b)
 *            <p>
 *            If an ActionListener is supplied, we call addActionListener(x)
 *            <p>
 *            If an Boolean x is supplied, we call setEnabled(x)
 *            <p>
 *            If an Icon x is supplied, we call setIcon(x)
 */
public static JMenuItem menuItem(JMenu parent, String label, Object... attrs) {
	JMenuItem m = new JMenuItem(label, null);
	int accelMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
	boolean hasMnemonic = false;
	for (Object x : attrs) {
		if (x instanceof Character || x instanceof Integer) {
			int k = (x instanceof Character) ? ((int) ((Character) x)) : ((Integer) x).intValue();
			if (k < 0)
				continue;
			if (k == KeyEvent.VK_ALT) {
				hasMnemonic = true;
				accelMask = accelMask | InputEvent.ALT_MASK;
				continue;
			}
			if (k == KeyEvent.VK_SHIFT) {
				hasMnemonic = true;
				accelMask = accelMask | InputEvent.SHIFT_MASK;
				continue;
			}
			if (!hasMnemonic) {
				m.setMnemonic(k);
				hasMnemonic = true;
			} else
				m.setAccelerator(KeyStroke.getKeyStroke(k, accelMask));
		}
		if (x instanceof ActionListener)
			m.addActionListener((ActionListener) x);
		if (x instanceof Icon)
			m.setIcon((Icon) x);
		if (x instanceof Boolean)
			m.setEnabled((Boolean) x);
	}
	if (parent != null)
		parent.add(m);
	return m;
}
 
Example 40
Project: jaer   File: SimpleIPotSliderTextControl.java   View source code 5 votes vote down vote up
private void valueTextFieldActionPerformed(final java.awt.event.ActionEvent evt) {// GEN-FIRST:event_valueTextFieldActionPerformed
	// new pots current value entered
	// System.out.println("value field action performed");
	try {
		startEdit();
		pot.setBitValue(Integer.parseInt(valueTextField.getText()));
		endEdit();
	}
	catch (final NumberFormatException e) {
		Toolkit.getDefaultToolkit().beep();
		valueTextField.selectAll();
	}
}