Пример #1
0
 /**
  * Load image from resource path (using getResource). Note that GIFs are loaded as _translucent_
  * indexed images. Images are cached: loading an image with the same name twice will get the
  * cached image the second time. If you want to remove an image from the cache, use purgeImage.
  * Throws JGError when there was an error.
  */
 @SuppressWarnings({"deprecation", "unchecked"})
 public JGImage loadImage(String imgfile) {
   Image img = (Image) loadedimages.get(imgfile);
   if (img == null) {
     URL imgurl = getClass().getResource(imgfile);
     if (imgurl == null) {
       try {
         File imgf = new File(imgfile);
         if (imgf.canRead()) {
           imgurl = imgf.toURL();
         } else {
           imgurl = new URL(imgfile);
           // throw new JGameError(
           //	"File "+imgfile+" not found.",true);
         }
       } catch (MalformedURLException e) {
         // e.printStackTrace();
         throw new JGameError("File not found or malformed path or URL '" + imgfile + "'.", true);
       }
     }
     img = output_comp.getToolkit().createImage(imgurl);
     loadedimages.put(imgfile, img);
   }
   try {
     ensureLoaded(img);
   } catch (Exception e) {
     // e.printStackTrace();
     throw new JGameError("Error loading image " + imgfile);
   }
   return new JREImage(img);
 }
 void addQueueFor(Component component) {
   EventQueue queue = component.getToolkit().getSystemEventQueue();
   Map<Window, Boolean> windowMapping = queueMap.get(queue);
   if (windowMapping == null) windowMapping = createWindowMapping(queue);
   if (!(component instanceof Window) || parentOf(component) != null) return;
   windowMapping.put((Window) component, TRUE);
 }
 /**
  * Locates the given component on the screen's center.
  *
  * @param component the component to be centered
  */
 protected final void locateOnOpticalScreenCenter(Component component) {
   Dimension paneSize = component.getSize();
   Dimension screenSize = component.getToolkit().getScreenSize();
   component.setLocation(
       (screenSize.width - paneSize.width) / 2,
       (int) ((screenSize.height - paneSize.height) * 0.45));
 }
 public void actionPerformed(ActionEvent evt) {
   Component focusOwner =
       KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
   if (focusOwner != null) {
     if (focusOwner instanceof EditableComponent) {
       ((EditableComponent) focusOwner).duplicate();
     } else {
       focusOwner.getToolkit().beep();
     }
   }
 }
Пример #5
0
  public static void keepComponentInsideScreen(int x, int y, Component c) {
    Dimension screenDim = c.getToolkit().getScreenSize();
    GraphicsConfiguration g = c.getGraphicsConfiguration();
    if (g != null) {
      Insets insets = c.getToolkit().getScreenInsets(g);

      if (x + c.getWidth() > screenDim.width - insets.right) {
        x = (screenDim.width - insets.right) - c.getWidth();
      } else if (x < insets.left) {
        x = insets.left;
      }

      if (y + c.getHeight() > screenDim.height - insets.bottom) {
        y = (screenDim.height - insets.bottom) - c.getHeight();
      } else if (y < insets.top) {
        y = insets.top;
      }

      c.setLocation(x, y);
    } else {
      System.out.println("null");
    }
  }
Пример #6
0
 /** Behaves like loadImage(String). Returns null if there was an error. */
 @SuppressWarnings("unchecked")
 public static JGImage loadImage(URL imgurl) {
   Image img = (Image) loadedimages.get(imgurl);
   if (img == null) {
     img = output_comp.getToolkit().createImage(imgurl);
     loadedimages.put(imgurl, img);
   }
   try {
     ensureLoaded(img);
   } catch (Exception e) {
     System.err.println("Error loading image " + imgurl);
     return null;
   }
   return new JREImage(img);
 }
 /**
  * Synchronize this painter with the current state of the view.
  *
  * @param v Sync to this view.
  */
 @SuppressWarnings("deprecation")
 void sync(GlyphView v) {
   Font f = v.getFont();
   if ((metrics == null) || (!f.equals(metrics.getFont()))) {
     // fetch a new FontMetrics
     Toolkit kit;
     Component c = v.getContainer();
     if (c != null) {
       kit = c.getToolkit();
     } else {
       kit = Toolkit.getDefaultToolkit();
     }
     metrics = kit.getFontMetrics(f);
   }
 }
 @RunsInCurrentThread
 void removeMappingFor(Component component) {
   EventQueue queue = component.getToolkit().getSystemEventQueue();
   removeComponent(component, queue);
   for (EventQueue q : queueMap.keySet()) removeComponent(component, q);
 }
Пример #9
0
 /**
  * Checks and answers whether we have a true color system.
  *
  * @param c the component used to determine the toolkit
  * @return true if the component's toolkit has a pixel size >= 24
  */
 public static boolean isTrueColor(Component c) {
   return c.getToolkit().getColorModel().getPixelSize() >= 24;
 }
Пример #10
0
 /** Locates the given component on the screen's center. */
 protected void locateOnScreen(Component component) {
   Dimension paneSize = component.getSize();
   Dimension screenSize = component.getToolkit().getScreenSize();
   component.setLocation(
       (screenSize.width - paneSize.width) / 2, (screenSize.height - paneSize.height) / 2 - 40);
 }