Esempio n. 1
0
  /** Overrides <code>Graphics.drawImage</code>. */
  public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info.log(toShortString() + " Drawing image: " + img + " at: " + new Point(x, y));
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawImage(img, x, y, observer);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      int i, count = (info.flashCount * 2) - 1;
      ImageProducer oldProducer = img.getSource();
      ImageProducer newProducer =
          new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor));
      Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer);
      DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();

      Image imageToDraw;
      for (i = 0; i < count; i++) {
        imageToDraw = (i % 2) == 0 ? newImage : img;
        loadImage(imageToDraw);
        graphics.drawImage(imageToDraw, x, y, imageObserver);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
    }
    return graphics.drawImage(img, x, y, observer);
  }
Esempio n. 2
0
  /** Overrides <code>Graphics.drawImage</code>. */
  public boolean drawImage(
      Image img,
      int dx1,
      int dy1,
      int dx2,
      int dy2,
      int sx1,
      int sy1,
      int sx2,
      int sy2,
      Color bgcolor,
      ImageObserver observer) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info.log(
          toShortString()
              + " Drawing image: "
              + img
              + " destination: "
              + new Rectangle(dx1, dy1, dx2, dy2)
              + " source: "
              + new Rectangle(sx1, sy1, sx2, sy2)
              + ", bgcolor: "
              + bgcolor);
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      int i, count = (info.flashCount * 2) - 1;
      ImageProducer oldProducer = img.getSource();
      ImageProducer newProducer =
          new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor));
      Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer);
      DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();

      Image imageToDraw;
      for (i = 0; i < count; i++) {
        imageToDraw = (i % 2) == 0 ? newImage : img;
        loadImage(imageToDraw);
        graphics.drawImage(
            imageToDraw, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, imageObserver);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
    }
    return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
  }
Esempio n. 3
0
 private void loadCursors() {
   Toolkit toolkit = Toolkit.getDefaultToolkit();
   String path = Prefs.getImageJDir() + "images/crosshair-cursor.gif";
   File f = new File(path);
   if (!f.exists()) return;
   // Image image = toolkit.getImage(path);
   ImageIcon icon = new ImageIcon(path);
   Image image = icon.getImage();
   if (image == null) return;
   int width = icon.getIconWidth();
   int height = icon.getIconHeight();
   Point hotSpot = new Point(width / 2, height / 2);
   Cursor crosshairCursor = toolkit.createCustomCursor(image, hotSpot, "crosshair-cursor.gif");
   ImageCanvas.setCursor(crosshairCursor, 0);
 }
 static {
   Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
   scalex = d.width / 1920.0;
   scaley = d.height / 1080.0;
   if (scalex > 1) scalex = 1;
   if (scaley > 1) scaley = 1;
 }
Esempio n. 5
0
  public APCircleWindow() {
    super("AP Circles");
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    String startDirectoryName = System.getProperty("user.dir");
    startDirectory = new File(startDirectoryName);
    // this for convenience, as the program normally starts in graph/display
    //		startDirectory = startDirectory.getParentFile();

    gw = this;

    generalXML = new GeneralXML(graph);

    gp = new APCirclePanel(this);
    getContentPane().add(gp);

    graph = gp.getGraph();

    initView();
    initExperiment();
    initUtility();
    initLayout();
    initMenu();

    setSize(width, height);

    Dimension frameDim = Toolkit.getDefaultToolkit().getScreenSize();
    int posX = (frameDim.width - getSize().width) / 2;
    int posY = (frameDim.height - getSize().height) / 2;
    setLocation(posX, posY);

    setVisible(true);

    gp.requestFocus();
  }
Esempio n. 6
0
  /** Overrides <code>Graphics.drawLine</code>. */
  public void drawLine(int x1, int y1, int x2, int y2) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Drawing line: from "
                  + pointToString(x1, y1)
                  + " to "
                  + pointToString(x2, y2));
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawLine(x1, y1, x2, y2);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawLine(x1, y1, x2, y2);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawLine(x1, y1, x2, y2);
  }
Esempio n. 7
0
  /** Overrides <code>Graphics.fill3DRect</code>. */
  public void fill3DRect(int x, int y, int width, int height, boolean raised) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Filling 3D rect: "
                  + new Rectangle(x, y, width, height)
                  + " Raised bezel: "
                  + raised);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.fill3DRect(x, y, width, height, raised);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.fill3DRect(x, y, width, height, raised);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.fill3DRect(x, y, width, height, raised);
  }
Esempio n. 8
0
  /** Overrides <code>Graphics.drawOval</code>. */
  public void drawOval(int x, int y, int width, int height) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info().log(toShortString() + " Drawing oval: " + new Rectangle(x, y, width, height));
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawOval(x, y, width, height);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawOval(x, y, width, height);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawOval(x, y, width, height);
  }
Esempio n. 9
0
  /** Overrides <code>Graphics.fillArc</code>. */
  public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Filling arc: "
                  + new Rectangle(x, y, width, height)
                  + " startAngle: "
                  + startAngle
                  + " arcAngle: "
                  + arcAngle);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.fillArc(x, y, width, height, startAngle, arcAngle);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.fillArc(x, y, width, height, startAngle, arcAngle);
  }
Esempio n. 10
0
  /** Overrides <code>Graphics.drawString</code>. */
  public void drawString(AttributedCharacterIterator iterator, int x, int y) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info().log(toShortString() + " Drawing text: \"" + iterator + "\" at: " + new Point(x, y));
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawString(iterator, x, y);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawString(iterator, x, y);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawString(iterator, x, y);
  }
Esempio n. 11
0
  /** Overrides <code>Graphics.drawChars</code>. */
  public void drawChars(char data[], int offset, int length, int x, int y) {
    DebugGraphicsInfo info = info();

    Font font = graphics.getFont();

    if (debugLog()) {
      info().log(toShortString() + " Drawing chars at " + new Point(x, y));
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawChars(data, offset, length, x, y);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.drawChars(data, offset, length, x, y);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.drawChars(data, offset, length, x, y);
  }
  private void addMenuItems(JMenu f, String m[]) {

    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

    for (int i = 0; i < m.length; i++) {
      if (m[i].equals("--")) {
        f.addSeparator();
      } else if (m[i].equals("---")) {

        // (ulrivo): full size on screen with less than 640 width
        if (d.width >= 640) {
          f.addSeparator();
        } else {
          return;
        }
      } else {
        JMenuItem item = new JMenuItem(m[i].substring(1));
        char c = m[i].charAt(0);

        if (c != '-') {
          item.setMnemonic(c);
        }

        item.addActionListener(this);
        f.add(item);
      }
    }
  }
  /** Method declaration */
  private void initGUI() {

    Panel pQuery = new Panel();
    Panel pCommand = new Panel();

    pResult = new Panel();

    pQuery.setLayout(new BorderLayout());
    pCommand.setLayout(new BorderLayout());
    pResult.setLayout(new BorderLayout());

    Font fFont = new Font("Dialog", Font.PLAIN, 12);

    txtCommand = new TextArea(5, 40);

    txtCommand.addKeyListener(this);

    txtResult = new TextArea(20, 40);

    txtCommand.setFont(fFont);
    txtResult.setFont(new Font("Courier", Font.PLAIN, 12));

    butExecute = new Button("Execute");
    butClear = new Button("Clear");

    butExecute.addActionListener(this);
    butClear.addActionListener(this);
    pCommand.add("East", butExecute);
    pCommand.add("West", butClear);
    pCommand.add("Center", txtCommand);

    gResult = new Grid();

    setLayout(new BorderLayout());
    pResult.add("Center", gResult);
    pQuery.add("North", pCommand);
    pQuery.add("Center", pResult);
    fMain.add("Center", pQuery);

    tTree = new Tree();

    // (ulrivo): screen with less than 640 width
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

    if (d.width >= 640) {
      tTree.setMinimumSize(new Dimension(200, 100));
    } else {
      tTree.setMinimumSize(new Dimension(80, 100));
    }

    gResult.setMinimumSize(new Dimension(200, 300));
    fMain.add("West", tTree);
    doLayout();
    fMain.pack();
  }
Esempio n. 14
0
 static ImageIcon loadRes(String fich) {
   try {
     return new ImageIcon(
         Toolkit.getDefaultToolkit()
             .createImage(readStream(NimRODLookAndFeel.class.getResourceAsStream(fich))));
   } catch (Exception ex) {
     ex.printStackTrace();
     System.out.println("No se puede cargar el recurso " + fich);
     return null;
   }
 }
Esempio n. 15
0
 static Image generateDisabledImage(final Image image) {
   final ImageProducer prod =
       new FilteredImageSource(
           image.getSource(),
           new IconImageFilter() {
             @Override
             int getGreyFor(final int gray) {
               return 255 - ((255 - gray) * 65 / 100);
             }
           });
   return Toolkit.getDefaultToolkit().createImage(prod);
 }
Esempio n. 16
0
 static Image generateSelectedDarkImage(final Image image) {
   final ImageProducer prod =
       new FilteredImageSource(
           image.getSource(),
           new IconImageFilter() {
             @Override
             int getGreyFor(final int gray) {
               return gray * 75 / 100;
             }
           });
   return Toolkit.getDefaultToolkit().createImage(prod);
 }
Esempio n. 17
0
 // create the menu bar (changed to private)
 private static JMenuBar createMenuBar() {
   JMenuBar menuBar = new JMenuBar();
   JMenu menu = new JMenu("File");
   menuBar.add(menu);
   JMenuItem menuItem1 = new JMenuItem(" Save...   ");
   menuItem1.addActionListener(std);
   menuItem1.setAccelerator(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
   menu.add(menuItem1);
   return menuBar;
 }
Esempio n. 18
0
 static Icon getOceanDisabledButtonIcon(Image image) {
   Object[] range = (Object[]) UIManager.get("Button.disabledGrayRange");
   int min = 180;
   int max = 215;
   if (range != null) {
     min = ((Integer) range[0]).intValue();
     max = ((Integer) range[1]).intValue();
   }
   ImageProducer prod =
       new FilteredImageSource(image.getSource(), new OceanDisabledButtonImageFilter(min, max));
   return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod));
 }
Esempio n. 19
0
 public TransparentWindow(BufferedImage img, int x, int y) {
   image = img;
   try {
     Robot robot = new Robot();
     Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
     screen = robot.createScreenCapture(new Rectangle(0, 0, d.width, d.height));
   } catch (AWTException e) {
     throw new Error(e);
   }
   setBounds(x, y, img.getWidth(), img.getHeight());
   setVisible(true);
   buffer = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
   graphics = (Graphics2D) buffer.getGraphics();
 }
Esempio n. 20
0
 private void paintScreen()
       // use active rendering to put the buffered image on-screen
     {
   Graphics g;
   try {
     g = this.getGraphics();
     if ((g != null) && (dbImage != null)) g.drawImage(dbImage, 0, 0, null);
     // Sync the display on some systems.
     // (on Linux, this fixes event queue problems)
     Toolkit.getDefaultToolkit().sync();
     g.dispose();
   } catch (Exception e) {
     System.out.println("Graphics context error: " + e);
   }
 } // end of paintScreen()
Esempio n. 21
0
  private void setup() {
    playerSetup();

    deathLocation = new int[4];
    Arrays.fill(deathLocation, -1);

    menu.setVisible(false);
    this.revalidate();

    audioSetup();

    Iterator i = players.iterator();
    Player p;
    while (i.hasNext()) {
      p = (Player) i.next();
      p.resetLives(3);
      p.setActive(true);
    }

    BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Cursor blank =
        Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "BLANK");
    this.setCursor(blank);

    reset();

    ballN = 1;
    level = 1;
    timeLast = 0;
    score = 0;
    counterN = 10;
    timeCircle = 0;
    timeCircleSwitch = 0;
    programLoopCounter = 1;
    programSpeedAdjust = 1;

    onePlayerAlive = true;
    countdownF = true;
    circular = true;
    spawnIncrease = true;
    spawnCircleB = false;
    spawnMonsterB = false;
    spawnRandomersB = false;

    levelSetup();
    countdown();
    animate();
  }
Esempio n. 22
0
 public Sprite(String img, int width, int height) {
   try {
     Image image = Toolkit.getDefaultToolkit().getImage(location + img + ".png");
     myWidth = width;
     myHeight = height;
     anInt1444 = myWidth;
     anInt1445 = myHeight;
     anInt1442 = 0;
     anInt1443 = 0;
     myPixels = new int[myWidth * myHeight];
     PixelGrabber pixelgrabber =
         new PixelGrabber(image, 0, 0, myWidth, myHeight, myPixels, 0, myWidth);
     pixelgrabber.grabPixels();
     image = null;
   } catch (Exception _ex) {
     System.out.println(_ex);
   }
 }
Esempio n. 23
0
  private void init() {
    soundPlayer = new SoundPlayer();
    soundPlayer.startBackgroundMusic();

    try {
      emptyCursor =
          Toolkit.getDefaultToolkit()
              .createCustomCursor(
                  new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), new Point(0, 0), "empty");
    } catch (RuntimeException e) {
      e.printStackTrace();
    }
    setFocusTraversalKeysEnabled(false);
    requestFocus();

    // hide cursor, since we're drawing our own one
    setCursor(emptyCursor);
  }
Esempio n. 24
0
 public Sprite(String img) {
   try {
     Image image = Toolkit.getDefaultToolkit().getImage(location + img + ".png");
     ImageIcon sprite = new ImageIcon(image);
     myWidth = sprite.getIconWidth();
     myHeight = sprite.getIconHeight();
     anInt1444 = myWidth;
     anInt1445 = myHeight;
     anInt1442 = 0;
     anInt1443 = 0;
     myPixels = new int[myWidth * myHeight];
     PixelGrabber pixelgrabber =
         new PixelGrabber(image, 0, 0, myWidth, myHeight, myPixels, 0, myWidth);
     pixelgrabber.grabPixels();
     image = null;
     setTransparency(255, 0, 255);
   } catch (Exception _ex) {
     System.out.println(_ex);
   }
 }
Esempio n. 25
0
 public Sprite(byte abyte0[], Component component) {
   try {
     // Image image = Toolkit.getDefaultToolkit().getImage(location+"mopar.jpg");
     Image image = Toolkit.getDefaultToolkit().createImage(abyte0);
     MediaTracker mediatracker = new MediaTracker(component);
     mediatracker.addImage(image, 0);
     mediatracker.waitForAll();
     myWidth = image.getWidth(component);
     myHeight = image.getHeight(component);
     anInt1444 = myWidth;
     anInt1445 = myHeight;
     anInt1442 = 0;
     anInt1443 = 0;
     myPixels = new int[myWidth * myHeight];
     PixelGrabber pixelgrabber =
         new PixelGrabber(image, 0, 0, myWidth, myHeight, myPixels, 0, myWidth);
     pixelgrabber.grabPixels();
   } catch (Exception _ex) {
     System.out.println("Error converting jpg");
   }
 }
Esempio n. 26
0
  // ///////////////////////////////////////////////////////////////
  // 双线性内插值算法
  // 参数:img:要缩放的Image对象
  // dstW:目标图像宽
  // dstH:目标图像高
  // comp:组件参数,比如Applet
  //
  // 公式:f(i+u,j+v) = (1-u)(1-v)f(i,j) + (1-u)vf(i,j+1) + u(1-v)f(i+1,j) +
  // uvf(i+1,j+1)
  //
  // ///////////////////////////////////////////////////////////////
  public static Image doubleLinearScale(Image img, int dstW, int dstH) {
    OperateImage OI = new OperateImage();
    Image imgTemp;
    int[] scaled, src;
    int srcW, srcH;
    int R, G, B;
    double widthFactor, heightFactor, tempX, tempY;
    // double srcX_float = 0.0, srcY_float = 0.0;// 坐标的小数部分
    // int srcX_int = 0, srcY_int = 0;// 坐标的整数部分
    src = OI.takeImg(img, img.getWidth(null), img.getHeight(null));
    ColorModel cm = ColorModel.getRGBdefault();
    for (int j = 0; j < src.length; j++) {
      R = cm.getRed(src[j]);
      G = cm.getGreen(src[j]);
      B = cm.getBlue(src[j]);
      if (R >= 200 && G >= 200 && B >= 200) src[j] = 0xffffffff;
      else src[j] = 0xff000000;
    }
    scaled = new int[dstW * dstH]; // 存放缩放后的图片
    srcW = img.getWidth(null);
    srcH = img.getHeight(null);

    widthFactor = srcW / (dstW + 0.0);
    // System.out.println("widthFactor:"+widthFactor);
    heightFactor = srcH / (dstH + 0.0);
    // System.out.println("heightFactor:"+heightFactor);
    for (int a = 0; a < dstH; a++)
      for (int b = 0; b < dstW; b++) {
        tempX = b * widthFactor;
        tempY = a * heightFactor;
        scaled[a * dstW + b] = getDestPixle(src, srcW, srcH, tempX, tempY);
      }
    // System.out.println("双线性内插值算法完成!");
    imgTemp = OI.madeImg(scaled, dstW, dstH);
    ImageFilter filter = new BWFilter();
    return Toolkit.getDefaultToolkit()
        .createImage(new FilteredImageSource(imgTemp.getSource(), filter));
    // return imgTemp;
  }
Esempio n. 27
0
  /** ****************** Open & Read an Image ********************** */
  void OpenImage2() {
    int returnVal = jfc.showOpenDialog(IPToolKit.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      file1 = jfc.getSelectedFile();
      String path = file.getAbsolutePath();
      //	image = Toolkit.getDefaultToolkit().getImage(path);

      try {
        try {
          inImage1 = new FileImageInputStream(file1);
          len1 = (int) inImage1.length();
          byteArray1 = new byte[len1];
          // System.out.println(len);
          inImage1.read(byteArray1, 0, len1);
          image1 = Toolkit.getDefaultToolkit().createImage(byteArray1);
          MediaTracker t = new MediaTracker(this);
          t.addImage(image1, 0);

          try {
            t.waitForID(1);
          } catch (Exception eeee) {
            System.out.println(eeee);
          }

          w1 = image1.getWidth(null);
          h1 = image1.getHeight(null);

          // System.out.println(w+"\t"+h);

        } catch (Exception fnfe) {
          JOptionPane.showMessageDialog(this, "File: Not Found");
        }
      } catch (Exception ice) {

        JOptionPane.showMessageDialog(this, "File I/O Error");
      }
    }
  }
Esempio n. 28
0
  /** Overrides <code>Graphics.fillPolygon</code>. */
  public void fillPolygon(int xPoints[], int yPoints[], int nPoints) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Filling polygon: "
                  + " nPoints: "
                  + nPoints
                  + " X's: "
                  + xPoints
                  + " Y's: "
                  + yPoints);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.fillPolygon(xPoints, yPoints, nPoints);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.fillPolygon(xPoints, yPoints, nPoints);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.fillPolygon(xPoints, yPoints, nPoints);
  }
Esempio n. 29
0
File: set.java Progetto: wcyuan/Set
    public void centerText(String s1, String s2, Graphics g, Color c, int x, int y, int w, int h) {
      // locs[0].centerText(s1, s2, this.getGraphics(),
      // Color.white, 400,0,200,50);
      // g.setXORMode(unselected_color);
      // centerText("pic" + im, null, g, Color.black, x, y, w, h);

      Font f = g.getFont();
      FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f);
      int ascent = fm.getAscent();
      int height = fm.getHeight();
      int width1 = 0, width2 = 0, x0 = 0, x1 = 0, y0 = 0, y1 = 0;
      width1 = fm.stringWidth(s1);
      if (s2 != null) width2 = fm.stringWidth(s2);
      x0 = x + (w - width1) / 2;
      x0 = x + (w - width2) / 2;
      if (s2 == null) y0 = y + (h - height) / 2 + ascent;
      else {
        y0 = y + (h - (int) (height * 2.2)) / 2 + ascent;
        y1 = y0 + (int) (height * 1.2);
      }
      g.setColor(c);
      g.drawString(s1, x0, y0);
      if (s2 != null) g.drawString(s2, x1, y1);
    }
Esempio n. 30
0
  /** Restores original disk or network version of image. */
  public void revertToSaved(ImagePlus imp) {
    Image img;
    ProgressBar pb = IJ.getInstance().getProgressBar();
    ImageProcessor ip;
    String path = fi.directory + fi.fileName;

    if (fi.fileFormat == fi.GIF_OR_JPG) {
      // restore gif or jpg
      img = Toolkit.getDefaultToolkit().createImage(path);
      imp.setImage(img);
      if (imp.getType() == ImagePlus.COLOR_RGB) Opener.convertGrayJpegTo8Bits(imp);
      return;
    }

    if (fi.fileFormat == fi.DICOM) {
      // restore DICOM
      ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.DICOM", path);
      if (imp2 != null) imp.setProcessor(null, imp2.getProcessor());
      return;
    }

    if (fi.fileFormat == fi.BMP) {
      // restore BMP
      ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.BMP_Reader", path);
      if (imp2 != null) imp.setProcessor(null, imp2.getProcessor());
      return;
    }

    if (fi.fileFormat == fi.PGM) {
      // restore PGM
      ImagePlus imp2 = (ImagePlus) IJ.runPlugIn("ij.plugin.PGM_Reader", path);
      if (imp2 != null) imp.setProcessor(null, imp2.getProcessor());
      return;
    }

    if (fi.fileFormat == fi.ZIP_ARCHIVE) {
      // restore ".zip" file
      ImagePlus imp2 = (new Opener()).openZip(path);
      if (imp2 != null) imp.setProcessor(null, imp2.getProcessor());
      return;
    }

    // restore PNG or another image opened using ImageIO
    if (fi.fileFormat == fi.IMAGEIO) {
      ImagePlus imp2 = (new Opener()).openUsingImageIO(path);
      if (imp2 != null) imp.setProcessor(null, imp2.getProcessor());
      return;
    }

    if (fi.nImages > 1) return;

    ColorModel cm;
    if (fi.url == null || fi.url.equals("")) IJ.showStatus("Loading: " + path);
    else IJ.showStatus("Loading: " + fi.url + fi.fileName);
    Object pixels = readPixels(fi);
    if (pixels == null) return;
    cm = createColorModel(fi);
    switch (fi.fileType) {
      case FileInfo.GRAY8:
      case FileInfo.COLOR8:
      case FileInfo.BITMAP:
        ip = new ByteProcessor(width, height, (byte[]) pixels, cm);
        imp.setProcessor(null, ip);
        break;
      case FileInfo.GRAY16_SIGNED:
      case FileInfo.GRAY16_UNSIGNED:
      case FileInfo.GRAY12_UNSIGNED:
        ip = new ShortProcessor(width, height, (short[]) pixels, cm);
        imp.setProcessor(null, ip);
        break;
      case FileInfo.GRAY32_INT:
      case FileInfo.GRAY32_FLOAT:
        ip = new FloatProcessor(width, height, (float[]) pixels, cm);
        imp.setProcessor(null, ip);
        break;
      case FileInfo.RGB:
      case FileInfo.BGR:
      case FileInfo.ARGB:
      case FileInfo.ABGR:
      case FileInfo.RGB_PLANAR:
        img =
            Toolkit.getDefaultToolkit()
                .createImage(new MemoryImageSource(width, height, (int[]) pixels, 0, width));
        imp.setImage(img);
        break;
    }
  }