Java Code Examples for java.awt.Image

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Agot-Java, under directory /src/main/java/got/test/.

Source file: TestApplet.java

  18 
vote

@Override public void init(){
  this.setSize(960 + 100,768);
  ImageScrollModel model=new ImageScrollModel();
  model.setBoxDimensions(480,384);
  model.setScrollX(false);
  Image image=Utility.loadImage("got/resource/agotsmall.png");
  ImageScrollerSmallView small=new ImageScrollerSmallView(image,model);
  LargePanel large=new LargePanel(new Dimension(960,1768),model);
  JSplitPane mainPanel=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,small,large);
  mainPanel.setSize(960 + 277,768);
  mainPanel.setDividerSize(0);
  mainPanel.setDividerLocation(100);
  this.add(mainPanel);
}
 

Example 2

From project BMach, under directory /src/jsyntaxpane/actions/gui/.

Source file: MemberCell.java

  18 
vote

private Image readImage(String iconLoc,String kind){
  String fullPath=iconLoc + kind + ".png";
  URL loc=this.getClass().getResource(fullPath);
  if (loc == null) {
    return null;
  }
 else {
    Image i=new ImageIcon(loc).getImage();
    return i;
  }
}
 

Example 3

From project core_5, under directory /exo.core.component.document/src/main/java/org/exoplatform/services/document/impl/image/.

Source file: ImageProcessingServiceImpl.java

  18 
vote

public BufferedImage createScaledImage(BufferedImage img,double factor){
  int imgWidth=img.getWidth();
  int imgHeight=img.getHeight();
  int newWidth=(new Double(imgWidth * factor)).intValue();
  int newHeight=(new Double(imgHeight * factor)).intValue();
  Image imgScaled=img.getScaledInstance(newWidth,newHeight,Image.SCALE_DEFAULT);
  BufferedImage scaledImage=new BufferedImage(newWidth,newHeight,BufferedImage.TYPE_INT_RGB);
  Graphics2D aImage=scaledImage.createGraphics();
  aImage.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
  aImage.drawImage(imgScaled,0,0,newWidth,newHeight,null);
  return scaledImage;
}
 

Example 4

From project Custom-Salem, under directory /src/haven/.

Source file: MainFrame.java

  18 
vote

private void seticon(){
  Image icon;
  try {
    InputStream data=MainFrame.class.getResourceAsStream("icon.gif");
    icon=javax.imageio.ImageIO.read(data);
    data.close();
  }
 catch (  IOException e) {
    throw (new Error(e));
  }
  setIconImage(icon);
}
 

Example 5

From project dawn-common, under directory /org.dawb.hdf5/src/ncsa/hdf/view/.

Source file: DefaultImageView.java

  18 
vote

/** 
 * Creates a RGB indexed image of 256 colors.
 * @param imageData the byte array of the image data.
 * @param palette the color lookup table.
 * @param w the width of the image.
 * @param h the height of the image.
 * @return the image.
 */
public Image createIndexedImage(byte[] imageData,byte[][] palette,int w,int h){
  Image theImage=null;
  IndexColorModel colorModel=new IndexColorModel(8,256,palette[0],palette[1],palette[2]);
  if (memoryImageSource == null) {
    memoryImageSource=new MemoryImageSource(w,h,colorModel,imageData,0,w);
  }
 else {
    memoryImageSource.newPixels(imageData,colorModel,0,w);
  }
  theImage=Toolkit.getDefaultToolkit().createImage(memoryImageSource);
  return theImage;
}
 

Example 6

From project des, under directory /daemon/lib/apache-log4j-1.2.16/contribs/SvenReimers/gui/.

Source file: JListView.java

  18 
vote

public Image loadIcon(String path){
  Image img=null;
  try {
    URL url=ClassLoader.getSystemResource(path);
    img=(Image)(Toolkit.getDefaultToolkit()).getImage(url);
  }
 catch (  Exception e) {
    System.out.println("Exception occured: " + e.getMessage() + " - "+ e);
  }
  return (img);
}
 

Example 7

From project encog-java-core, under directory /src/main/java/org/encog/ca/program/generic/.

Source file: GenericIO.java

  18 
vote

public static void save(CARunner runner,File f){
  try {
    EncogDirectoryPersistence.saveObject(new File(FileUtil.forceExtension(f.toString(),"eg")),runner.getUniverse());
    SerializeObject.save(new File(FileUtil.forceExtension(f.toString(),"bin")),(Serializable)runner.getPhysics());
    BasicCAVisualizer visualizer=new BasicCAVisualizer(runner.getUniverse());
    Image img=visualizer.visualize();
    ImageIO.write((RenderedImage)img,"png",new File(FileUtil.forceExtension(f.toString(),"png")));
  }
 catch (  IOException ex) {
    throw new CellularAutomataError(ex);
  }
}
 

Example 8

From project encog-java-examples, under directory /src/main/java/org/encog/examples/neural/image/.

Source file: ImageNeuralNetwork.java

  18 
vote

public void processWhatIs() throws IOException {
  final String filename=getArg("image");
  final File file=new File(filename);
  final Image img=ImageIO.read(file);
  final ImageMLData input=new ImageMLData(img);
  input.downsample(this.downsample,false,this.downsampleHeight,this.downsampleWidth,1,-1);
  final int winner=this.network.winner(input);
  System.out.println("What is: " + filename + ", it seems to be: "+ this.neuron2identity.get(winner));
}
 

Example 9

From project entando-core-engine, under directory /src/main/java/com/agiletec/plugins/jacms/aps/system/services/resource/model/imageresizer/.

Source file: PNGImageResizer.java

  18 
vote

/** 
 * Crea e restituisce un'immagine in base all'immagine master ed alle dimensioni massime consentite. L'immagine risultante sar? un'immagine rispettante le proporzioni dell'immagine sorgente.
 * @param imageIcon L'immagine sorgente.
 * @param dimensioneX la dimensione orizzontale massima.
 * @param dimensioneY La dimensione verticale massima.
 * @return L'immagine risultante.
 * @throws ApsSystemException In caso di errore.
 */
protected BufferedImage getResizedImage(ImageIcon imageIcon,int dimensioneX,int dimensioneY) throws ApsSystemException {
  Image image=imageIcon.getImage();
  BufferedImage bi=this.toBufferedImage(image);
  double scale=this.computeScale(image.getWidth(null),image.getHeight(null),dimensioneX,dimensioneY);
  int scaledW=(int)(scale * image.getWidth(null));
  int scaledH=(int)(scale * image.getHeight(null));
  BufferedImage biRes=new BufferedImage(bi.getColorModel(),bi.getColorModel().createCompatibleWritableRaster(scaledW,scaledH),bi.isAlphaPremultiplied(),null);
  AffineTransform tx=new AffineTransform();
  tx.scale(scale,scale);
  Graphics2D bufImageGraphics=biRes.createGraphics();
  bufImageGraphics.drawImage(image,tx,null);
  return biRes;
}
 

Example 10

From project Enterprise-Application-Samples, under directory /CCA/PushApp/src/eclserver/.

Source file: NewJFrame.java

  18 
vote

/** 
 * Load our own "address book" icon into our frame window.
 */
private void loadFrameIcon(){
  URL imgUrl=null;
  ImageIcon imgIcon=null;
  imgUrl=NewJFrame.class.getResource("images/Burn.png");
  imgIcon=new ImageIcon(imgUrl);
  Image img=imgIcon.getImage();
  this.setIconImage(img);
}
 

Example 11

From project FScape, under directory /src/main/java/de/sciss/fscape/gui/.

Source file: OpIcon.java

  18 
vote

protected synchronized static IconBitmap getIconBitmap(){
  if (opib == null) {
    final Image imgOp=Toolkit.getDefaultToolkit().getImage(OpIcon.class.getResource("op.gif"));
    opib=new IconBitmap(imgOp,ibWidth,ibHeight);
    basicIcons=new IconicComponent[5];
    for (int i=0; i < basicIcons.length; i++) {
      basicIcons[i]=new IconicComponent(opib,i);
    }
  }
  return opib;
}
 

Example 12

From project Haven-and-Hearth-client-modified-by-Ender, under directory /src/haven/.

Source file: MainFrame.java

  18 
vote

private void seticon(){
  Image icon;
  try {
    InputStream data=MainFrame.class.getResourceAsStream("icon.png");
    icon=javax.imageio.ImageIO.read(data);
    data.close();
  }
 catch (  IOException e) {
    throw (new Error(e));
  }
  setIconImage(icon);
}
 

Example 13

From project jAPS2, under directory /src/com/agiletec/plugins/jacms/aps/system/services/resource/model/imageresizer/.

Source file: PNGImageResizer.java

  18 
vote

/** 
 * Crea e restituisce un'immagine in base all'immagine master ed alle dimensioni massime consentite. L'immagine risultante sar? un'immagine rispettante le proporzioni dell'immagine sorgente.
 * @param imageIcon L'immagine sorgente.
 * @param dimensioneX la dimensione orizzontale massima.
 * @param dimensioneY La dimensione verticale massima.
 * @return L'immagine risultante.
 * @throws ApsSystemException In caso di errore.
 */
protected BufferedImage getResizedImage(ImageIcon imageIcon,int dimensioneX,int dimensioneY) throws ApsSystemException {
  Image image=imageIcon.getImage();
  BufferedImage bi=this.toBufferedImage(image);
  double scale=this.computeScale(image.getWidth(null),image.getHeight(null),dimensioneX,dimensioneY);
  int scaledW=(int)(scale * image.getWidth(null));
  int scaledH=(int)(scale * image.getHeight(null));
  BufferedImage biRes=new BufferedImage(bi.getColorModel(),bi.getColorModel().createCompatibleWritableRaster(scaledW,scaledH),bi.isAlphaPremultiplied(),null);
  AffineTransform tx=new AffineTransform();
  tx.scale(scale,scale);
  Graphics2D bufImageGraphics=biRes.createGraphics();
  bufImageGraphics.drawImage(image,tx,null);
  return biRes;
}
 

Example 14

From project jftp, under directory /src/main/java/com/myjavaworld/jftp/.

Source file: OSXAdapter.java

  18 
vote

/** 
 * Sets the dock icon for the application.
 */
private static void handleDockIcon(){
  try {
    Method method=macOSXApplication.getClass().getMethod("setDockIconImage",Image.class);
    Image image=Toolkit.getDefaultToolkit().getImage(JFTP.class.getResource("jftp128.gif"));
    method.invoke(macOSXApplication,new Object[]{image});
  }
 catch (  Throwable t) {
    System.err.println("Unable to set the dock icon");
    t.printStackTrace();
  }
}
 

Example 15

From project jgraphx, under directory /src/com/mxgraph/canvas/.

Source file: mxGraphicsCanvas2D.java

  18 
vote

/** 
 */
public void image(double x,double y,double w,double h,String src,boolean aspect,boolean flipH,boolean flipV){
  if (src != null && w > 0 && h > 0) {
    Image img=loadImage(src);
    if (img != null) {
      Rectangle bounds=getImageBounds(img,x,y,w,h,aspect);
      img=scaleImage(img,bounds.width,bounds.height);
      if (img != null) {
        drawImage(createImageGraphics(bounds.x,bounds.y,bounds.width,bounds.height,flipH,flipV),img,bounds.x,bounds.y);
      }
    }
  }
}
 

Example 16

From project jinx, under directory /src/main/java/net/jeremybrooks/jinx/dto/.

Source file: PhotoBase.java

  18 
vote

/** 
 * Get the image at the specified size. <p>The available sizes are: <ul> <li>JinxConstants.SIZE_SMALL_SQUARE</li> <li>JinxConstants.SIZE_THUMBNAIL</li> <li>JinxConstants.SIZE_SMALL</li> <li>JinxConstants.SIZE_MEDIUM</li> <li>JinxConstants.SIZE_MEDIUM_640</li> <li>JinxConstants.SIZE_LARGE</li> <li>JinxConstants.SIZE_ORIGINAL</li> </ul> </p>
 * @param size the desired size.
 * @return image at the desired size.
 * @throws JinxException if there are any errors.
 */
public Image getImageForSize(int size) throws JinxException {
  Image image=null;
  try {
    image=ImageIO.read(new URL(this.getUrlForSize(size)));
  }
 catch (  Exception e) {
    throw new JinxException("Unable to get image for size " + size,e);
  }
  return image;
}
 

Example 17

From project LateralGM, under directory /org/lateralgm/components/.

Source file: GmTreeGraphics.java

  18 
vote

public static Icon getScaledIcon(Image i){
  int w=i.getWidth(null);
  int h=i.getHeight(null);
  int m=Math.min(w,h);
  if (m > 16)   i=i.getScaledInstance(w * 16 / m,h * 16 / m,BufferedImage.SCALE_SMOOTH);
  Image i2=new BufferedImage(16,16,BufferedImage.TYPE_INT_ARGB);
  int x=0;
  int y=0;
  if (w < 16)   x=8 - w / 2;
  if (h < 16)   y=8 - h / 2;
  i2.getGraphics().drawImage(i,x,y,null);
  i=i2;
  return new ImageIcon(i);
}
 

Example 18

From project log4j, under directory /contribs/SvenReimers/gui/.

Source file: JListView.java

  18 
vote

public Image loadIcon(String path){
  Image img=null;
  try {
    URL url=ClassLoader.getSystemResource(path);
    img=(Image)(Toolkit.getDefaultToolkit()).getImage(url);
  }
 catch (  Exception e) {
    System.out.println("Exception occured: " + e.getMessage() + " - "+ e);
  }
  return (img);
}
 

Example 19

From project log4jna, under directory /thirdparty/log4j/contribs/SvenReimers/gui/.

Source file: JListView.java

  18 
vote

public Image loadIcon(String path){
  Image img=null;
  try {
    URL url=ClassLoader.getSystemResource(path);
    img=(Image)(Toolkit.getDefaultToolkit()).getImage(url);
  }
 catch (  Exception e) {
    System.out.println("Exception occured: " + e.getMessage() + " - "+ e);
  }
  return (img);
}
 

Example 20

From project mtc, under directory /mtc-gui/src/main/java/org/drugis/mtc/gui/.

Source file: MainWindow.java

  18 
vote

public static void setAppIcon(JFrame frame){
  Image image=null;
  try {
    image=((ImageIcon)MainWindow.IMAGELOADER.getIcon(FileNames.ICON_GEMTC)).getImage();
  }
 catch (  Exception e) {
  }
  if (image != null) {
    frame.setIconImage(image);
  }
}
 

Example 21

From project multibit, under directory /src/main/java/org/multibit/viewsystem/swing/view/.

Source file: ImageSelection.java

  18 
vote

private Image getURLImage(URL url){
  Image imageToReturn=null;
  try {
    imageToReturn=ImageIO.read(url);
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  return imageToReturn;
}
 

Example 22

From project obpro_team_p, under directory /src/.

Source file: OPLife.java

  18 
vote

public void paint(Graphics g){
  Image icon=new ImageIcon("src/notification_text_back.png",null).getImage();
  Image gradient=new ImageIcon("src/gradient.jpg",null).getImage();
  g.drawImage(icon,this.positionX - this.width / 2,this.positionY - this.height / 2,this.width,this.height,null);
  float gage=this.hp / this.maxHp;
  int gradientWidth=(int)(gage * 0.97 * this.width);
  int gradientHeight=(int)(0.7 * this.height);
  g.drawImage(gradient,this.positionX - this.width / 2 + 5,this.positionY - this.height / 2 + 5,gradientWidth,gradientHeight,null);
}
 

Example 23

From project autopsy, under directory /Core/src/org/sleuthkit/autopsy/corecomponents/.

Source file: DataContentViewerPicture.java

  17 
vote

@Override public void setNode(Node selectedNode){
  this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  try {
    if (selectedNode != null) {
      try {
        Content content=selectedNode.getLookup().lookup(Content.class);
        byte[] dataSource=new byte[(int)content.getSize()];
        int bytesRead=content.read(dataSource,0,content.getSize());
        if (bytesRead > 0) {
          InputStream is=new ByteArrayInputStream(dataSource);
          Image image=ImageIO.read(is);
          if (image != null)           this.picLabel.setIcon(new javax.swing.ImageIcon(image));
        }
      }
 catch (      TskException ex) {
        Logger.getLogger(this.className).log(Level.WARNING,"Error while trying to display the picture content.",ex);
      }
catch (      Exception ex) {
        Logger.getLogger(this.className).log(Level.WARNING,"Error while trying to display the picture content.",ex);
      }
    }
  }
  finally {
    this.setCursor(null);
  }
}
 

Example 24

From project Carolina-Digital-Repository, under directory /djatoka-cdr/src/gov/lanl/adore/djatoka/io/reader/.

Source file: ImageJReader.java

  17 
vote

/** 
 * Internal ImagePlus processing to populate BufferedIMage using Graphics objects
 * @param imp an ImageJ ImagePlus object
 * @return a BufferedImage of type BufferedImage.TYPE_3BYTE_BGR
 * @throws FormatIOException
 */
private BufferedImage open(ImagePlus imp) throws FormatIOException {
  if (imp == null) {
    logger.error("Null ImagePlus Object.");
    throw new FormatIOException("Null ImagePlus Object.");
  }
  ImageProcessor ip=imp.getProcessor();
  int width=ip.getWidth();
  int height=ip.getHeight();
  Image img=ip.createImage();
  imp.flush();
  imp=null;
  ip=null;
  BufferedImage bImg=new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);
  Graphics g=bImg.getGraphics();
  g.drawImage(img,0,0,null);
  img.flush();
  img=null;
  g.dispose();
  g=null;
  return bImg;
}
 

Example 25

From project ceres, under directory /ceres-jai/src/main/java/com/bc/ceres/jai/js/.

Source file: JsJai.java

  17 
vote

public static int show(Context cx,Scriptable thisObj,Object[] args,Function funObj){
  final RenderedImage renderedImage=args.length > 0 ? (RenderedImage)Context.jsToJava(args[0],RenderedImage.class) : null;
  int frameId=args.length > 1 ? (Integer)Context.jsToJava(args[1],Integer.class) : -1;
  final Image image;
  if (renderedImage instanceof PlanarImage) {
    image=((PlanarImage)renderedImage).getAsBufferedImage();
  }
 else   if (renderedImage instanceof Image) {
    image=(Image)renderedImage;
  }
 else {
    image=new BufferedImage(512,512,BufferedImage.TYPE_BYTE_GRAY);
  }
  JFrame frame=frames.get(frameId);
  if (frame != null) {
    frame.getContentPane().removeAll();
  }
 else {
    frameId=JsJai.frameId++;
    frame=new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frames.put(frameId,frame);
  }
  frame.setTitle("Image #" + frameId);
  frame.getContentPane().add(new JScrollPane(new JLabel(new ImageIcon(image))));
  frame.pack();
  frame.setVisible(true);
  return frameId;
}
 

Example 26

From project Chess_1, under directory /src/chess/gui/.

Source file: ImageDisplay.java

  17 
vote

/** 
 * Draws a unit-length object facing North. This implementation draws an object by tinting, scaling, and rotating the image in the image file.
 * @param obj object we want to draw
 * @param comp the component we're drawing on
 * @param g2 drawing surface
 */
public void draw(Object obj,Component comp,Graphics2D g2){
  Color color;
  if (obj == null)   color=null;
 else   color=(Color)getProperty(obj,"color");
  String imageSuffix=(String)getProperty(obj,"imageSuffix");
  if (imageSuffix == null)   imageSuffix="";
  Image tinted=tintedVersions.get(color + imageSuffix);
  if (tinted == null) {
    Image untinted=tintedVersions.get(imageSuffix);
    if (untinted == null) {
      try {
        URL url=cl.getClassLoader().getResource(imageFilename + imageSuffix + imageExtension);
        if (url == null)         throw new FileNotFoundException(imageFilename + imageSuffix + imageExtension+ " not found.");
        untinted=ImageIO.read(url);
        tintedVersions.put(imageSuffix,untinted);
      }
 catch (      IOException ex) {
        untinted=tintedVersions.get("");
      }
    }
    if (color == null)     tinted=untinted;
 else {
      FilteredImageSource src=new FilteredImageSource(untinted.getSource(),new TintFilter(color));
      tinted=comp.createImage(src);
      tintedVersions.put(color + imageSuffix,tinted);
    }
  }
  int width=tinted.getWidth(null);
  int height=tinted.getHeight(null);
  int size=Math.max(width,height);
  g2.scale(1.0 / size,1.0 / size);
  g2.clip(new Rectangle(-width / 2,-height / 2,width,height));
  g2.drawImage(tinted,-width / 2,-height / 2,null);
}
 

Example 27

From project Clotho-Core, under directory /ClothoApps/PluginManager/src/org/clothocore/tool/pluginmanager/gui/.

Source file: ChoosePreferredViewers.java

  17 
vote

private void promoteAvatarToDrawable(List<DrawableAvatar> drawables,int x,int y,int width,int height,int offset){
  double spacing=offset * avatarSpacing;
  double avatarPos=this.avatarPosition + spacing;
  if (avatarIndex + offset < 0 || avatarIndex + offset >= avatars.size()) {
    return;
  }
  Image avatar=avatars.get(avatarIndex + offset);
  int avatarWidth=avatar.getWidth(null);
  int avatarHeight=avatar.getHeight(null);
  double result=computeModifier(avatarPos);
  int newWidth=(int)(avatarWidth * result);
  if (newWidth == 0) {
    return;
  }
  int newHeight=(int)(avatarHeight * result);
  if (newHeight == 0) {
    return;
  }
  double avatar_x=x + (width - newWidth) / 2.0;
  double avatar_y=y + (height - newHeight / 2.0) / 1.7;
  double semiWidth=width / 2.0;
  avatar_x+=avatarPos * semiWidth;
  if (avatar_x >= width || avatar_x < -newWidth) {
    return;
  }
  drawables.add(new DrawableAvatar(avatarIndex + offset,avatar_x,avatar_y,newWidth,newHeight,avatarPos,result));
}
 

Example 28

From project en4j, under directory /NBPlatformApp/NoteContentViewModule/src/main/java/com/rubenlaguna/en4j/NoteContentViewModule/.

Source file: ENMLReplacedElementFactory.java

  17 
vote

private ReplacedElement loadImage(LayoutContext context,String hash){
  ReplacedElement toReturn=null;
  InputStream is=getImage(hash);
  Image image=null;
  if (is == null) {
    return brokenImage(context,100,100);
  }
  try {
    image=ImageIO.read(is);
  }
 catch (  IOException e) {
    LOG.log(Level.WARNING,"exception caught:",e);
  }
 finally {
    try {
      is.close();
    }
 catch (    IOException e) {
    }
  }
  if (image == null) {
    return brokenImage(context,100,100);
  }
  ImageIcon icon=new ImageIcon(image);
  JLabel cc=new JLabel(icon);
  cc.setSize(cc.getPreferredSize());
  FSCanvas canvas=context.getCanvas();
  if (canvas instanceof JComponent) {
    ((JComponent)canvas).add(cc);
  }
  toReturn=new SwingReplacedElement(cc){
    public boolean isRequiresInteractivePaint(){
      return false;
    }
  }
;
  return toReturn;
}
 

Example 29

From project engine, under directory /main/com/midtro/platform/modules/assets/types/.

Source file: ImageAssembler.java

  17 
vote

/** 
 * {@inheritDoc}
 */
@Override public void assemble(String assetName,String fileName,AssetConfig config,Map<String,Asset<?>> store) throws Exception {
  Image img=null;
switch (config.getMountType()) {
case FILE:
    img=ImageIO.read(new File(config.getFileLocation() + fileName.replace('/',File.separatorChar)));
  break;
case CACHE:
img=ImageIO.read(new File(config.getCacheLocation() + fileName.replace('/',File.separatorChar)));
break;
case URL:
img=ImageIO.read(new URL(config.getUrlLocation() + fileName));
break;
default :
throw new IllegalStateException("Unknown mount type");
}
store.put("image." + assetName,new ImageAsset(assetName,img));
}
 

Example 30

From project flyingsaucer, under directory /flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/.

Source file: Java2DOutputDevice.java

  17 
vote

public void paintReplacedElement(RenderingContext c,BlockBox box){
  ReplacedElement replaced=box.getReplacedElement();
  if (replaced instanceof SwingReplacedElement) {
    Rectangle contentBounds=box.getContentAreaEdge(box.getAbsX(),box.getAbsY(),c);
    JComponent component=((SwingReplacedElement)box.getReplacedElement()).getJComponent();
    RootPanel canvas=(RootPanel)c.getCanvas();
    CellRendererPane pane=canvas.getCellRendererPane();
    pane.paintComponent(_graphics,component,canvas,contentBounds.x,contentBounds.y,contentBounds.width,contentBounds.height,true);
  }
 else   if (replaced instanceof ImageReplacedElement) {
    Image image=((ImageReplacedElement)replaced).getImage();
    Point location=replaced.getLocation();
    _graphics.drawImage(image,(int)location.getX(),(int)location.getY(),null);
  }
}
 

Example 31

From project geronimo-javamail, under directory /geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/handlers/.

Source file: AbstractImageHandler.java

  17 
vote

public void writeTo(Object obj,String mimeType,OutputStream os) throws IOException {
  Iterator i=ImageIO.getImageWritersByMIMEType(flavour.getMimeType());
  if (!i.hasNext()) {
    throw new UnsupportedDataTypeException("Unknown image type " + flavour.getMimeType());
  }
  ImageWriter writer=(ImageWriter)i.next();
  writer.setOutput(ImageIO.createImageOutputStream(os));
  if (obj instanceof RenderedImage) {
    writer.write((RenderedImage)obj);
  }
 else   if (obj instanceof BufferedImage) {
    BufferedImage buffered=(BufferedImage)obj;
    writer.write(new IIOImage(buffered.getRaster(),null,null));
  }
 else   if (obj instanceof Image) {
    Image image=(Image)obj;
    BufferedImage buffered=new BufferedImage(image.getWidth(null),image.getHeight(null),BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics=buffered.createGraphics();
    graphics.drawImage(image,0,0,null,null);
    writer.write(new IIOImage(buffered.getRaster(),null,null));
  }
 else {
    throw new UnsupportedDataTypeException("Unknown image type " + obj.getClass().getName());
  }
  os.flush();
}
 

Example 32

From project glg2d, under directory /src/test/java/glg2d/.

Source file: StressTest.java

  17 
vote

@Test public void imageTest() throws Exception {
  final int numimages=1000;
  final Image image=ImageIO.read(StressTest.class.getClassLoader().getResource("duke.gif"));
  TimedPainter painter=new TimedPainter(){
    @Override protected void paint(    Graphics2D g2d){
      int x=300;
      int y=400;
      for (int i=0; i < numimages; i++) {
        g2d.drawImage(image,rand.nextInt(x),rand.nextInt(y),rand.nextInt(x),rand.nextInt(y),null);
      }
    }
  }
;
  tester.setPainter(painter);
  painter.waitAndLogTimes("images");
}
 

Example 33

From project Gmote, under directory /gmoteserver/src/org/gmote/server/.

Source file: GmoteHttpServer.java

  17 
vote

private void sendImage(File originalImagePath,BufferedOutputStream dataOut) throws InterruptedException, ImageFormatException, IOException {
  LOGGER.info("Converting image to smaller scale");
  Image image=Toolkit.getDefaultToolkit().getImage(originalImagePath.getAbsolutePath());
  MediaTracker mediaTracker=new MediaTracker(new Container());
  mediaTracker.addImage(image,0);
  mediaTracker.waitForID(0);
  int imageWidth=image.getWidth(null);
  int imageHeight=image.getHeight(null);
  int thumbWidth=imageWidth;
  int thumbHeight=imageHeight;
  int MAX_SIZE=500;
  if (imageWidth > MAX_SIZE || imageHeight > MAX_SIZE) {
    double imageRatio=(double)imageWidth / (double)imageHeight;
    if (imageWidth > imageHeight) {
      thumbWidth=MAX_SIZE;
      thumbHeight=(int)(thumbWidth / imageRatio);
    }
 else {
      thumbHeight=MAX_SIZE;
      thumbWidth=(int)(thumbHeight * imageRatio);
    }
  }
  BufferedImage thumbImage;
  thumbImage=new BufferedImage(thumbWidth,thumbHeight,BufferedImage.TYPE_INT_RGB);
  Graphics2D graphics2D=thumbImage.createGraphics();
  graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  graphics2D.drawImage(image,0,0,thumbWidth,thumbHeight,null);
  if (PlatformUtil.isLinux()) {
    ImageIO.write(thumbImage,"JPEG",dataOut);
  }
 else {
    JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(dataOut);
    JPEGEncodeParam param=encoder.getDefaultJPEGEncodeParam(thumbImage);
    float quality=80;
    param.setQuality(quality / 100.0f,false);
    encoder.encode(thumbImage,param);
  }
  dataOut.close();
  LOGGER.info("Done sending image");
}
 

Example 34

From project grid-goggles, under directory /Dependent Libraries/controlP5/src/controlP5/.

Source file: ControlP5IOHandler.java

  17 
vote

/** 
 * load an image with MediaTracker to prevent nullpointers e.g. in BitFontRenderer
 * @param theURL
 * @return
 */
@Deprecated public Image loadImage(Component theComponent,URL theURL){
  if (theComponent == null) {
    theComponent=cp5.papplet;
  }
  Image img=null;
  img=Toolkit.getDefaultToolkit().createImage(theURL);
  MediaTracker mt=new MediaTracker(theComponent);
  mt.addImage(img,0);
  try {
    mt.waitForAll();
  }
 catch (  InterruptedException e) {
    ControlP5.logger().severe("loading image failed." + e.toString());
  }
catch (  Exception e) {
    ControlP5.logger().severe("loading image failed." + e.toString());
  }
  return img;
}
 

Example 35

From project gs-core, under directory /src/org/graphstream/ui/swingViewer/util/.

Source file: ImageCache.java

  17 
vote

/** 
 * The same as  {@link #getImage(String)} but you can force the cache to tryto reload an image that where not found before.
 * @param fileNameOrUrl A file name or an URL pointing at the image.
 * @param forceTryReload If true, try to reload an image that where not found before.
 * @return An image or null if the image cannot be found.
 */
public Image getImage(String fileNameOrUrl,boolean forceTryReload){
  Image ii=imageCache.get(fileNameOrUrl);
  if (ii == dummy && !forceTryReload)   return null;
  if (ii == null) {
    URL url=ImageCache.class.getClassLoader().getResource(fileNameOrUrl);
    if (url != null) {
      try {
        ii=ImageIO.read(url);
        imageCache.put(fileNameOrUrl,ii);
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
    }
 else {
      try {
        url=new URL(fileNameOrUrl);
        ii=ImageIO.read(url);
        imageCache.put(fileNameOrUrl,ii);
      }
 catch (      Exception e) {
        try {
          ii=ImageIO.read(new File(fileNameOrUrl));
          imageCache.put(fileNameOrUrl,ii);
        }
 catch (        IOException ee) {
          imageCache.put(fileNameOrUrl,dummy);
          System.err.printf("Cannot read image '%s'%n",fileNameOrUrl);
        }
      }
    }
  }
  return ii;
}
 

Example 36

From project ihtika, under directory /Incubator/JavaToTray/src/main/java/khartn/javatotray/.

Source file: App.java

  17 
vote

public void run(){
  SystemTray tray=SystemTray.getSystemTray();
  String imgName="favicon_1.jpg";
  URL imgURL=getClass().getResource(imgName);
  Image image=Toolkit.getDefaultToolkit().getImage(imgURL);
  ActionListener exitListener=new ActionListener(){
    public void actionPerformed(    ActionEvent e){
      System.out.println("Exiting...");
      System.exit(0);
    }
  }
;
  PopupMenu popup=new PopupMenu();
  MenuItem defaultItem=new MenuItem("Exit");
  defaultItem.addActionListener(exitListener);
  popup.add(defaultItem);
  final TrayIcon trayIcon=new TrayIcon(image,"Tray Demo",popup);
  ActionListener actionListener=new ActionListener(){
    public void actionPerformed(    ActionEvent e){
      trayIcon.displayMessage("Action Event","An Action Event Has Been Performed!",TrayIcon.MessageType.INFO);
    }
  }
;
  trayIcon.setImageAutoSize(true);
  trayIcon.addActionListener(actionListener);
  try {
    tray.add(trayIcon);
  }
 catch (  AWTException e) {
    System.err.println("TrayIcon could not be added.");
  }
}
 

Example 37

From project JaamSim, under directory /com/sandwell/JavaSimulation3D/.

Source file: OrbitBehavior.java

  17 
vote

/** 
 * Creates a new OrbitBehavior
 * @param c The Canvas3D to add the behavior to
 * @param flags The option flags
 */
public OrbitBehavior(ModelView v,Sim3DWindow window){
  super(v.getCanvas3D(),MOUSE_LISTENER | MOUSE_MOTION_LISTENER);
  modelView=v;
  this.window=window;
  setEnable(true);
  orbitCenter=new Vector3d();
  orbitAngles=new Vector3d();
  orbitRadius=DEFAULT_RADIUS;
  fov=DEFAULT_FOV;
  integrateTransforms();
  Toolkit tk=Toolkit.getDefaultToolkit();
  Dimension dim=tk.getBestCursorSize(32,32);
  dim.height/=2;
  dim.width/=2;
  Image cursorImage=tk.getImage(GUIFrame.class.getResource("/resources/images/rotating.png"));
  try {
    rotation=tk.createCustomCursor(cursorImage,new Point(dim.width,dim.height),"Rotating");
  }
 catch (  Exception exc) {
    rotation=null;
  }
  tooltip=new JWindow();
  tooltip.setAlwaysOnTop(true);
  textArea=new JTextArea();
  textArea.setFocusable(false);
  textArea.setEditable(false);
  textArea.setFont(new Font("Verdana",Font.PLAIN,11));
  JPanel contentPane=(JPanel)tooltip.getContentPane();
  contentPane.setBorder(new LineBorder(Color.black));
  tooltip.getContentPane().add(textArea,BorderLayout.CENTER);
  tooltip.getContentPane().setBackground(new Color(255,255,198));
}
 

Example 38

From project jASM_16, under directory /src/main/java/de/codesourcery/jasm16/ide/ui/views/.

Source file: ScreenView.java

  17 
vote

protected JPanel createPanel(){
  panel=new JPanel(){
    public void paint(    java.awt.Graphics g){
      super.paint(g);
      final int height;
      if (debugCustomFonts) {
        height=getHeight() / 2;
      }
 else {
        height=getHeight();
      }
      BufferedImage original1=screen.getScreenImage();
      final Image scaled1=original1.getScaledInstance(getWidth(),height,Image.SCALE_FAST);
      ((Graphics2D)g).drawImage(scaled1,0,0,null);
      if (debugCustomFonts) {
        BufferedImage original2=screen.getFontImage();
        final Image scaled2=original2.getScaledInstance(getWidth(),height,Image.SCALE_FAST);
        ((Graphics2D)g).drawImage(scaled2,0,height,null);
      }
    }
  }
;
  panel.setDoubleBuffered(true);
  panel.setPreferredSize(new Dimension(400,200));
  panel.setSize(new Dimension(400,200));
  panel.setFocusable(true);
  setColors(panel);
  return panel;
}
 

Example 39

From project jbpm-plugin, under directory /jbpm/src/main/java/hudson/jbpm/rendering/.

Source file: ProcessInstanceRenderer.java

  17 
vote

public void paintTask(Graphics2D g2,Node node,Rectangle2D.Double rect){
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  Color nodeColor=getNodeColor(node);
  g2.setPaint(new GradientPaint(new Point2D.Double(rect.x,rect.y),nodeColor,new Point2D.Double(rect.x,rect.y + rect.height),NODE_COLOR_2));
  g2.fill(rect);
  g2.setPaint(LINE_COLOR);
  g2.draw(rect);
  double imageY=rect.y + rect.height / 2 - 16 / 2;
  Image image=GraphicsUtil.getImage(node);
  if (image != null) {
    int w=image.getWidth(null);
    int h=image.getHeight(null);
    g2.drawImage(image,(int)rect.x + 8,(int)imageY,(int)rect.x + 8 + w,(int)imageY + h,0,0,w,h,this);
  }
  int textWidth=g2.getFontMetrics().stringWidth(node.getName());
  int textHeight=g2.getFontMetrics().getAscent();
  g2.setColor(TEXT_COLOR);
  g2.setFont(FONT);
  g2.drawString(node.getName(),(int)(rect.x + 12 + (rect.width - textWidth) / 2),(int)(rect.y + (rect.height + textHeight) / 2));
}
 

Example 40

From project jchempaint, under directory /src/main/org/openscience/jchempaint/.

Source file: AbstractJChemPaintPanel.java

  17 
vote

public Image takeTransparentSnapshot(){
  Image snapshot=takeSnapshot();
  ImageFilter filter=new RGBImageFilter(){
    public int markerRGB=renderPanel.getRenderer().getRenderer2DModel().getBackColor().getRGB() | 0xFF000000;
    public final int filterRGB(    int x,    int y,    int rgb){
      if ((rgb | 0xFF000000) == markerRGB) {
        return 0x00FFFFFF & rgb;
      }
 else {
        return rgb;
      }
    }
  }
;
  ImageProducer ip=new FilteredImageSource(snapshot.getSource(),filter);
  return Toolkit.getDefaultToolkit().createImage(ip);
}
 

Example 41

From project jena-examples, under directory /src/main/java/org/apache/jena/examples/.

Source file: ExampleJenaJUNG_01.java

  17 
vote

public static void main(String[] args){
  FileManager fm=FileManager.get();
  fm.addLocatorClassLoader(ExampleJenaJUNG_01.class.getClassLoader());
  Model model=fm.loadModel("data/data.nt");
  Graph<RDFNode,Statement> g=new JenaJungGraph(model);
  Layout<RDFNode,Statement> layout=new FRLayout<RDFNode,Statement>(g);
  int width=1400;
  int height=800;
  layout.setSize(new Dimension(width,height));
  VisualizationImageServer<RDFNode,Statement> viz=new VisualizationImageServer<RDFNode,Statement>(layout,new Dimension(width,height));
  RenderContext<RDFNode,Statement> context=viz.getRenderContext();
  context.setEdgeLabelTransformer(Transformers.EDGE);
  context.setVertexLabelTransformer(Transformers.NODE);
  viz.setPreferredSize(new Dimension(width,height));
  Image img=viz.getImage(new Point(width / 2,height / 2),new Dimension(width,height));
  BufferedImage bi=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
  Graphics2D g2d=bi.createGraphics();
  g2d.setColor(Color.white);
  g2d.fillRect(0,0,width,height);
  g2d.setColor(Color.white);
  g2d.drawImage(img,0,0,width,height,Color.blue,null);
  try {
    ImageIO.write(bi,"PNG",new File("/tmp/graph.png"));
    System.out.println("Image saved");
  }
 catch (  IOException ex) {
    ex.printStackTrace(System.err);
  }
}
 

Example 42

From project jupload, under directory /src/wjhk/jupload2/filedata/.

Source file: PictureFileData.java

  17 
vote

/** 
 * This method creates a new Image, from the current picture. The resulting width and height will be less or equal than the given maximum width and height. The scale is maintained. Thus the width or height may be inferior than the given values.
 * @param canvas The canvas on which the picture will be displayed.
 * @param shadow True if the pictureFileData should store this picture.False if the pictureFileData instance should not store this picture. Store this picture avoid calculating the image each time the user selects it in the file panel.
 * @return The rescaled image.
 * @throws JUploadException Encapsulation of the Exception, if any wouldoccurs.
 */
public Image getImage(Canvas canvas,boolean shadow) throws JUploadException {
  Image localImage=null;
  if (canvas == null) {
    throw new JUploadException("canvas null in PictureFileData.getImage");
  }
  int canvasWidth=canvas.getWidth();
  int canvasHeight=canvas.getHeight();
  if (canvasWidth <= 0 || canvasHeight <= 0) {
    this.uploadPolicy.displayDebug("canvas width and/or height null in PictureFileData.getImage()",1);
  }
 else   if (shadow && this.offscreenImage != null) {
    localImage=this.offscreenImage;
  }
 else   if (this.isPicture) {
    try {
      ImageReaderWriterHelper irwh=new ImageReaderWriterHelper((PictureUploadPolicy)uploadPolicy,this);
      BufferedImage sourceImage=irwh.readImage(0);
      irwh.dispose();
      irwh=null;
      ImageHelper ih=new ImageHelper((PictureUploadPolicy)this.uploadPolicy,this,canvasWidth,canvasHeight,this.quarterRotation);
      localImage=ih.getBufferedImage(((PictureUploadPolicy)this.uploadPolicy).getHighQualityPreview(),sourceImage);
      sourceImage.flush();
      sourceImage=null;
    }
 catch (    OutOfMemoryError e) {
      localImage=null;
      tooBigPicture();
    }
  }
  if (shadow) {
    this.offscreenImage=localImage;
  }
  freeMemory("end of " + this.getClass().getName() + ".getImage()");
  this.uploadPolicy.getApplet().getUploadPanel().getProgressBar().setValue(0);
  return localImage;
}
 

Example 43

From project JVerge, under directory /src/domain/.

Source file: VImage.java

  17 
vote

public VImage(URL url){
  try {
    if (url == null) {
      System.err.println("Unable to find image from URL " + url);
      return;
    }
    if (url.getFile().toUpperCase().endsWith("PCX")) {
      image=PCXReader.loadImage(url.openStream());
    }
 else {
      image=ImageIO.read(url);
    }
  }
 catch (  IOException e) {
    System.err.println("Unable to read image from URL " + url);
  }
  this.width=image.getWidth();
  this.height=image.getHeight();
  Image img=makeColorTransparent(image,new Color(255,0,255));
  this.image=imageToBufferedImage(img);
  g=(Graphics2D)image.getGraphics();
}
 

Example 44

From project leaves, under directory /libraries/controlP5/src/controlP5/.

Source file: ControlP5IOHandler.java

  17 
vote

/** 
 * load an image with MediaTracker to prevent nullpointers e.g. in BitFontRenderer
 * @param theURL
 * @return
 */
@Deprecated public Image loadImage(Component theComponent,URL theURL){
  if (theComponent == null) {
    theComponent=cp5.papplet;
  }
  Image img=null;
  img=Toolkit.getDefaultToolkit().createImage(theURL);
  MediaTracker mt=new MediaTracker(theComponent);
  mt.addImage(img,0);
  try {
    mt.waitForAll();
  }
 catch (  InterruptedException e) {
    ControlP5.logger().severe("loading image failed." + e.toString());
  }
catch (  Exception e) {
    ControlP5.logger().severe("loading image failed." + e.toString());
  }
  return img;
}
 

Example 45

From project Maimonides, under directory /src/com/codeko/apps/maimonides/digitalizacion/.

Source file: CacheImagenes.java

  17 
vote

public static Image getImagenCasilla(ParteFaltas parte,int pagina,int fila,int hora){
  long t=System.currentTimeMillis();
  String id=parte.getId() + "-" + pagina;
  fila=fila - 1;
  hora=(hora - 1);
  Image img=null;
  long dif=0;
  if (casillas.containsKey(id)) {
    Logger.getLogger(CacheImagenes.class.getName()).log(Level.INFO,"Recuperando casilla {0} desde cach\u00e9 de im\u00e1genes.",id);
    ArrayList<ArrayList<Image>> vCasillas=casillas.get(id);
    try {
      img=vCasillas.get(fila).get(hora);
    }
 catch (    Exception e) {
      Logger.getLogger(CacheImagenes.class.getName()).log(Level.FINE,"No existe la fila solicitada",e);
    }
  }
 else {
    Logger.getLogger(CacheImagenes.class.getName()).log(Level.INFO,"Procesando casillas de imagen ''{0}''.",id);
    BufferedImage imgParte=getImagenParte(parte,pagina);
    dif=System.currentTimeMillis() - t;
    Logger.getLogger(CacheImagenes.class.getName()).log(Level.INFO,"Se ha tardado {0}ms en la carga de la imagen del parte.",dif);
    long t2=System.currentTimeMillis();
    if (imgParte != null) {
      addImagenCasillas(parte,pagina,imgParte);
      ArrayList<ArrayList<Image>> vCasillas=casillas.get(id);
      img=vCasillas.get(fila).get(hora);
      dif=System.currentTimeMillis() - t2;
      Logger.getLogger(CacheImagenes.class.getName()).log(Level.INFO,"Se ha tardado {0}ms en procesar las casillas.",dif);
    }
  }
  dif=System.currentTimeMillis() - t;
  Logger.getLogger(CacheImagenes.class.getName()).log(Level.INFO,"Se ha tardado {0}ms en la carga.",dif);
  return img;
}
 

Example 46

From project Minicraft, under directory /src/com/github/jleahey/minicraft/.

Source file: SpriteStore.java

  17 
vote

/** 
 * Retrieve a sprite from the store
 * @param ref The reference to the image to use for the sprite
 * @return A sprite instance containing an accelerate image of the request reference
 */
public Sprite getSprite(String ref){
  if (sprites.get(ref) != null) {
    return (Sprite)sprites.get(ref);
  }
  BufferedImage sourceImage=null;
  try {
    URL url=this.getClass().getClassLoader().getResource(ref);
    if (url == null) {
      fail("Can't find ref: " + ref);
    }
    sourceImage=ImageIO.read(url);
  }
 catch (  IOException e) {
    fail("Failed to load: " + ref);
  }
  GraphicsConfiguration gc=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
  Image image=gc.createCompatibleImage(sourceImage.getWidth(),sourceImage.getHeight(),Transparency.BITMASK);
  image.getGraphics().drawImage(sourceImage,0,0,null);
  Sprite sprite=new Sprite(image,ref);
  sprites.put(ref,sprite);
  return sprite;
}
 

Example 47

From project nenya, under directory /core/src/test/java/com/threerings/media/util/.

Source file: TraceViz.java

  17 
vote

public TraceViz(String[] args) throws IOException {
  _frame=new JFrame();
  _frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  ClientImageManager imgr=new ClientImageManager(null,_frame);
  JPanel content=(JPanel)_frame.getContentPane();
  content.setBackground(Color.white);
  content.setLayout(new VGroupLayout());
  BufferedImage image=ImageIO.read(new File(args[0]));
  if (image == null) {
    throw new RuntimeException("Failed to read file " + "[file=" + args[0] + "].");
  }
  Image timage=ImageUtil.createTracedImage(imgr,image,Color.red,5,0.4f,0.1f);
  content.add(new JLabel(new ImageIcon(image)));
  content.add(new JLabel(new ImageIcon(timage)));
}
 

Example 48

From project OMS3, under directory /src/main/java/oms3/dsl/.

Source file: AbstractSimulation.java

  17 
vote

/** 
 * Edit parameter file content. Edit only the 
 * @throws Exception
 */
public void edit() throws Exception {
  List<File> l=new ArrayList<File>();
  for (  Params p : model.getParams()) {
    if (p.getFile() != null) {
      l.add(new File(p.getFile()));
    }
  }
  if (l.isEmpty()) {
    throw new ComponentException("No parameter files to edit.");
  }
  if (l.size() == 1) {
    File f=l.get(0);
    if (!f.exists()) {
      CSProperties p=DataIO.properties(ComponentAccess.createDefault(model.getComponent()));
      DataIO.save(p,f,"Parameter");
    }
  }
  nativeLF();
  PEditor p=new PEditor(l);
  Image im=Toolkit.getDefaultToolkit().getImage(getClass().getResource("/ngmf/ui/table.png"));
  JFrame f=new JFrame();
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.getContentPane().add(p);
  f.setIconImage(im);
  f.setTitle("Parameter " + getName());
  f.setSize(800,600);
  f.setLocation(500,200);
  f.setVisible(true);
  f.toFront();
  System.out.flush();
}
 

Example 49

From project ANNIS, under directory /annis-kickstarter/src/main/java/de/hu_berlin/german/korpling/annis/kickstarter/.

Source file: MainFrame.java

  15 
vote

/** 
 * Creates new form MainFrame
 */
public MainFrame(){
  Integer[] sizes=new Integer[]{192,128,64,48,32,16,14};
  List<Image> allImages=new LinkedList<Image>();
  for (  int s : sizes) {
    try {
      BufferedImage imgIcon=ImageIO.read(MainFrame.class.getResource("logo/annis_" + s + ".png"));
      allImages.add(imgIcon);
    }
 catch (    IOException ex) {
      log.error(null,ex);
    }
  }
  this.setIconImages(allImages);
  System.setProperty("annis.home",".");
  this.corpusAdministration=(CorpusAdministration)AnnisBaseRunner.getBean("corpusAdministration",true,"file:" + Utils.getAnnisFile("conf/spring/Admin.xml").getAbsolutePath());
  try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  }
 catch (  Exception ex) {
    log.error(null,ex);
  }
  initComponents();
  serviceWorker=new MainFrameWorker();
  serviceWorker.addPropertyChangeListener(new PropertyChangeListener(){
    public void propertyChange(    PropertyChangeEvent evt){
      if (serviceWorker.getProgress() == 1) {
        pbStart.setIndeterminate(true);
        lblStatusService.setText("<html>Starting ANNIS...</html>");
        lblStatusService.setIcon(new javax.swing.ImageIcon(getClass().getResource("/de/hu_berlin/german/korpling/annis/kickstarter/crystal_icons/quick_restart.png")));
      }
    }
  }
);
  if (isInitialized()) {
    btImport.setEnabled(true);
    btList.setEnabled(true);
    serviceWorker.execute();
  }
}
 

Example 50

From project Calendar-Application, under directory /com/toedter/components/.

Source file: GenericBeanInfo.java

  15 
vote

/** 
 * This method returns an image object that can be used to represent the bean in toolboxes, toolbars, etc.
 * @param iconKind the kind of requested icon
 * @return the icon image
 */
public Image getIcon(int iconKind){
switch (iconKind) {
case ICON_COLOR_16x16:
    return iconColor16;
case ICON_COLOR_32x32:
  return iconColor32;
case ICON_MONO_16x16:
return iconMono16;
case ICON_MONO_32x32:
return iconMono32;
}
return null;
}
 

Example 51

From project CraftCommons, under directory /src/main/java/com/craftfire/commons/.

Source file: CraftCommons.java

  15 
vote

/** 
 * @param urlstring The url of the image.
 * @return Image object.
 */
public static Image urlToImage(String urlstring){
  try {
    URL url=new URL(urlstring);
    return Toolkit.getDefaultToolkit().getDefaultToolkit().createImage(url);
  }
 catch (  MalformedURLException e) {
    e.printStackTrace();
  }
  return null;
}
 

Example 52

From project dawn-isencia, under directory /com.isencia.passerelle.commons/src/main/java/com/isencia/util/swing/calendar/.

Source file: JCalendarBeanInfo.java

  15 
vote

/** 
 * This method returns an image object that can be used to represent the bean in toolboxes, toolbars, etc.
 */
public Image getIcon(int iconKind){
switch (iconKind) {
case ICON_COLOR_16x16:
    return icon;
case ICON_COLOR_32x32:
  return icon32;
case ICON_MONO_16x16:
return iconM;
case ICON_MONO_32x32:
return icon32M;
}
return null;
}
 

Example 53

From project echo2, under directory /src/webcontainer/java/nextapp/echo2/webcontainer/image/.

Source file: ImageToBufferedImage.java

  15 
vote

/** 
 * Converts an <code>Image</code> to a <code>BufferedImage</code>. If the image is already a <code>BufferedImage</code>, the original is returned.
 * @param image the image to convert
 * @return the image as a <code>BufferedImage</code>
 */
static BufferedImage toBufferedImage(Image image){
  if (image instanceof BufferedImage) {
    return (BufferedImage)image;
  }
  image=new ImageIcon(image).getImage();
  int type=hasAlpha(image) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
  BufferedImage bufferedImage=new BufferedImage(image.getWidth(null),image.getHeight(null),type);
  Graphics g=bufferedImage.createGraphics();
  g.drawImage(image,0,0,null);
  g.dispose();
  return bufferedImage;
}
 

Example 54

From project echo3, under directory /src/server-java/webcontainer/nextapp/echo/webcontainer/util/.

Source file: PngEncoder.java

  15 
vote

/** 
 * Converts an <code>Image</code> to a <code>BufferedImage</code>. If the image is already a <code>BufferedImage</code>, the original is returned.
 * @param image the image to convert
 * @return the image as a <code>BufferedImage</code>
 */
static BufferedImage toBufferedImage(Image image){
  if (image instanceof BufferedImage) {
    return (BufferedImage)image;
  }
  image=new ImageIcon(image).getImage();
  int type=hasAlpha(image) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
  BufferedImage bufferedImage=new BufferedImage(image.getWidth(null),image.getHeight(null),type);
  Graphics g=bufferedImage.createGraphics();
  g.drawImage(image,0,0,null);
  g.dispose();
  return bufferedImage;
}
 

Example 55

From project formic, under directory /src/java/org/formic/.

Source file: Installer.java

  15 
vote

/** 
 * Gets an image given either the image resource path or a key to lookup the resource path.
 * @param image The path or key.
 * @return The image or null if not found.
 */
public static Image getImage(String image){
  String path=getString(image);
  if (path == null) {
    path=image;
  }
  URL url=Installer.class.getResource(path);
  return url != null ? Toolkit.getDefaultToolkit().createImage(url) : null;
}
 

Example 56

From project freemind, under directory /freemind/freemind/view/mindmapview/.

Source file: MultipleImage.java

  15 
vote

public Image getImage(){
  if (!isDirty)   return super.getImage();
  int w=getIconWidth();
  int h=getIconHeight();
  if (w == 0 || h == 0) {
    return null;
  }
  BufferedImage outImage=new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
  Graphics2D g=outImage.createGraphics();
  double myX=0;
  for (Iterator i=mImages.iterator(); i.hasNext(); ) {
    ImageIcon currentIcon=(ImageIcon)i.next();
    double pwidth=(currentIcon.getIconWidth() * zoomFactor);
    AffineTransform inttrans=AffineTransform.getScaleInstance(zoomFactor,zoomFactor);
    g.drawImage(currentIcon.getImage(),inttrans,null);
    g.translate(pwidth,0);
    myX+=pwidth;
  }
  g.dispose();
  setImage(outImage);
  isDirty=false;
  return super.getImage();
}
 

Example 57

From project groovejaar, under directory /src/groovejaar/.

Source file: SplashWindow.java

  15 
vote

/** 
 * Creates a new instance.
 * @param parent the parent of the window.
 * @param image the splash image.
 */
private SplashWindow(Frame parent,Image image){
  super(parent);
  this.image=image;
  MediaTracker mt=new MediaTracker(this);
  mt.addImage(image,0);
  try {
    mt.waitForID(0);
  }
 catch (  InterruptedException ie) {
  }
  int imgWidth=image.getWidth(this);
  int imgHeight=image.getHeight(this);
  setSize(imgWidth,imgHeight);
  Dimension screenDim=Toolkit.getDefaultToolkit().getScreenSize();
  setLocation((screenDim.width - imgWidth) / 2,(screenDim.height - imgHeight) / 2);
}
 

Example 58

From project gs-tool, under directory /src/org/graphstream/tool/gui/.

Source file: Resources.java

  15 
vote

public static Image getImage(String url,int width,int height,boolean keepAspect){
  InputStream in=ToolGUI.class.getClassLoader().getResourceAsStream(url);
  BufferedImage image;
  try {
    image=ImageIO.read(in);
  }
 catch (  IOException e) {
    image=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
  }
  boolean validWidth=(width <= 0 || width == image.getWidth());
  boolean validHeight=(height <= 0 || height == image.getHeight());
  if ((validWidth && !validHeight && !keepAspect) || (validHeight && !validWidth && !keepAspect) || (!validWidth && !validHeight)) {
    if (keepAspect) {
      double ratio=image.getWidth() / (double)image.getHeight();
      width=validWidth ? width : (int)(ratio * height);
      height=validWidth ? (int)(width / ratio) : height;
    }
    return image.getScaledInstance(width,height,BufferedImage.SCALE_SMOOTH);
  }
  return image;
}
 

Example 59

From project guj.com.br, under directory /src/net/jforum/util/image/.

Source file: ImageUtils.java

  15 
vote

/** 
 * Determines if the image has transparent pixels.
 * @param image The image to check for transparent pixel.s
 * @return <code>true</code> of <code>false</code>, according to the result
 */
public static boolean hasAlpha(Image image){
  try {
    PixelGrabber pg=new PixelGrabber(image,0,0,1,1,false);
    pg.grabPixels();
    return pg.getColorModel().hasAlpha();
  }
 catch (  InterruptedException e) {
    return false;
  }
}
 

Example 60

From project Hotel-Management_MINF10-HCM, under directory /HotelManagement/src/main/java/core/datechooser/.

Source file: GenericBeanInfo.java

  15 
vote

/** 
 * This method returns an image object that can be used to represent the bean in toolboxes, toolbars, etc.
 * @param iconKind the kind of requested icon
 * @return the icon image
 */
public Image getIcon(int iconKind){
switch (iconKind) {
case ICON_COLOR_16x16:
    return iconColor16;
case ICON_COLOR_32x32:
  return iconColor32;
case ICON_MONO_16x16:
return iconMono16;
case ICON_MONO_32x32:
return iconMono32;
}
return null;
}
 

Example 61

From project hudsontrayapp-plugin, under directory /client-common/src/main/java/org/hudson/trayapp/gui/.

Source file: CellImageObserver.java

  15 
vote

public boolean imageUpdate(Image img,int flags,int x,int y,int w,int h){
  if ((flags & (FRAMEBITS | ALLBITS)) != 0) {
    Rectangle rect=table.getCellRect(row,col,false);
    table.repaint(rect);
  }
  return (flags & (ALLBITS | ABORT)) == 0;
}
 

Example 62

From project huiswerk, under directory /print/src/print/.

Source file: PrintStil.java

  15 
vote

public PrintStil(Image _qrCode,String _Regel1,String _Regel2){
  qrImage=_qrCode;
  Regel1=_Regel1;
  Regel2=_Regel2.split("\n");
  if (!voorbeeld) {
    PrinterJob pj=PrinterJob.getPrinterJob();
    mPageFormat=new PageFormat();
    Paper paper=new Paper();
    paper.setImageableArea(0,0,160,290);
    paper.setSize(160,290);
    mPageFormat.setPaper(paper);
    pj.setPrintable(new OutPrintable(),mPageFormat);
    try {
      pj.print();
    }
 catch (    PrinterException e) {
      System.out.println(e);
    }
  }
}
 

Example 63

From project iee, under directory /org.eclipse.iee.sample.graph/src/org/jfree/experimental/swt/.

Source file: SWTGraphics2D.java

  15 
vote

/** 
 * Draws an image with the top left corner aligned to the point (x, y).
 * @param image  the image.
 * @param x  the x-coordinate.
 * @param y  the y-coordinate.
 * @param observer  ignored here.
 * @return <code>true</code> if the image has been drawn.
 */
public boolean drawImage(Image image,int x,int y,ImageObserver observer){
  ImageData data=SWTUtils.convertAWTImageToSWT(image);
  if (data == null) {
    return false;
  }
  org.eclipse.swt.graphics.Image im=new org.eclipse.swt.graphics.Image(this.gc.getDevice(),data);
  this.gc.drawImage(im,x,y);
  im.dispose();
  return true;
}
 

Example 64

From project imageflow, under directory /src/de/danielsenff/imageflow/gui/.

Source file: BICanvas.java

  15 
vote

/** 
 * Overwrite the current source-BufferedImage. This will also update the displayed canvas and the window-size.
 * @param bi
 */
public void setSourceBI(final Image bi){
  this.biRendered=bi;
  this.biSource=bi;
  int width=(int)(zoomFactor * bi.getWidth(null));
  int height=(int)(zoomFactor * bi.getHeight(null));
  this.setPreferredSize(new Dimension(width,height));
  this.getParent().setPreferredSize(new Dimension(bi.getWidth(null),bi.getHeight(null)));
  invalidate();
  this.repaint();
}
 

Example 65

From project jCAE, under directory /viewer3d/src/org/jcae/viewer3d/post/.

Source file: ImageViewable.java

  15 
vote

public void setImage(Image image){
  TextureLoader tl=new TextureLoader(image,null);
  Texture t=tl.getTexture();
  t.setBoundaryModeS(Texture.CLAMP);
  t.setBoundaryModeT(Texture.CLAMP);
  if (!interpolate)   t.setMagFilter(Texture.BASE_LEVEL_POINT);
  appearance.setTexture(t);
}
 

Example 66

From project jforum2, under directory /src/net/jforum/util/image/.

Source file: ImageUtils.java

  15 
vote

/** 
 * Determines if the image has transparent pixels.
 * @param image The image to check for transparent pixel.s
 * @return <code>true</code> of <code>false</code>, according to the result
 */
public static boolean hasAlpha(Image image){
  try {
    PixelGrabber pg=new PixelGrabber(image,0,0,1,1,false);
    pg.grabPixels();
    return pg.getColorModel().hasAlpha();
  }
 catch (  InterruptedException e) {
    return false;
  }
}
 

Example 67

From project joshua, under directory /src/joshua/ui/.

Source file: StartupWindow.java

  15 
vote

public StartupWindow(String title,String author,String year,Image image,Color borderColor,int borderWidth){
  JPanel content=(JPanel)getContentPane();
  content.setBackground(Color.WHITE);
  int width=250;
  int height=100;
  Point center=GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
  setBounds(center.x - width / 2,center.y - height / 2,width,height);
  JLabel titleLabel=new JLabel(title,JLabel.CENTER);
  titleLabel.setFont(new Font("Sans-Serif",Font.BOLD,24));
  content.add(titleLabel,BorderLayout.NORTH);
  JLabel copyright=new JLabel("\u24D2 " + year + " - "+ author,JLabel.CENTER);
  copyright.setFont(new Font("Sans-Serif",Font.PLAIN,8));
  content.add(copyright,BorderLayout.SOUTH);
  if (image != null) {
    content.add(new JLabel(new ImageIcon(image)));
  }
  content.setBorder(BorderFactory.createLineBorder(borderColor,borderWidth));
  setVisible(true);
}
 

Example 68

From project MEditor, under directory /editor-common/editor-common-server/src/main/java/cz/mzk/editor/server/fedora/.

Source file: KrameriusImageSupport.java

  15 
vote

/** 
 * Write full image to stream.
 * @param scaledImage the scaled image
 * @param javaFormat the java format
 * @param os the os
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void writeFullImageToStream(Image scaledImage,String javaFormat,OutputStream os) throws IOException {
  BufferedImage bufImage=new BufferedImage(scaledImage.getWidth(null),scaledImage.getHeight(null),BufferedImage.TYPE_BYTE_BINARY);
  Graphics gr=bufImage.getGraphics();
  gr.drawImage(scaledImage,0,0,null);
  gr.dispose();
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  ImageIO.write(bufImage,javaFormat,bos);
  IOUtils.copyStreams(new ByteArrayInputStream(bos.toByteArray()),os);
}
 

Example 69

From project medsavant, under directory /medsavant/MedSavantClient/src/org/ut/biolab/medsavant/view/.

Source file: BottomBar.java

  15 
vote

public BottomBar(){
  setLayout(new BoxLayout(this,BoxLayout.X_AXIS));
  setBorder(BorderFactory.createCompoundBorder(ViewUtil.getEndzoneLineBorder(),ViewUtil.getSmallBorder()));
  setPreferredSize(new Dimension(25,25));
  loginStatusLabel=new JLabel();
  statusLabel=new JLabel("");
  statusLabel.setFont(ViewUtil.getMediumTitleFont());
  ImageIcon im=IconFactory.getInstance().getIcon(IconFactory.StandardIcon.LOGGED_IN);
  loginImagePanel=new ImagePanel(im.getImage().getScaledInstance(15,15,Image.SCALE_SMOOTH),15,15);
  notificationPanel=new NotificationPanel();
  add(loginImagePanel);
  add(ViewUtil.getSmallSeparator());
  add(loginStatusLabel);
  add(ViewUtil.getLargeSeparator());
  add(notificationPanel);
  add(Box.createHorizontalGlue());
  updateLoginStatus();
}
 

Example 70

From project movsim, under directory /viewer/src/main/java/org/movsim/viewer/util/.

Source file: SwingHelper.java

  15 
vote

public static ImageIcon createImageIcon(Class<?> bezugsklasse,String path,int width,int height){
  final URL imgURL=bezugsklasse.getResource(path);
  if (imgURL != null) {
    return new ImageIcon(new ImageIcon(imgURL).getImage().getScaledInstance(width,height,Image.SCALE_SMOOTH));
  }
  System.err.println("Couldn't find file: " + path);
  return null;
}
 

Example 71

From project netifera, under directory /platform/com.netifera.platform.ui.visualizations/com.netifera.platform.ui.graphs/src/com/netifera/platform/ui/graphs/.

Source file: GraphControl.java

  15 
vote

private void setRenderers(){
  AbstractShapeRenderer nodeRenderer;
  if (showLabels || showImages) {
    nodeRenderer=new LabelRenderer(){
      public String getText(      VisualItem item){
        if (showLabels && item.canGet("entity",IEntity.class))         return nodeLabelProvider.getText(item.get("entity"));
        return null;
      }
      public Image getImage(      VisualItem item){
        if (showImages && item.canGet("entity",IEntity.class))         return ImageConverter.convert(nodeLabelProvider.getImage(item.get("entity")));
        return null;
      }
    }
;
  }
 else {
    nodeRenderer=new ShapeRenderer();
  }
  DefaultRendererFactory rendererFactory=new DefaultRendererFactory();
  rendererFactory.setDefaultRenderer(nodeRenderer);
  PolygonRenderer polygonRenderer=new PolygonRenderer(Constants.POLY_TYPE_CURVE);
  polygonRenderer.setCurveSlack(0.15f);
  rendererFactory.add("ingroup('" + AGGREGATES + "')",polygonRenderer);
  visualization.setRendererFactory(rendererFactory);
}
 

Example 72

From project niravCS2103, under directory /CS2103/src/gui/.

Source file: Resource.java

  15 
vote

/** 
 * change icon to image
 * @param icon
 * @return image from icon
 */
static Image iconToImage(Icon icon){
  if (icon instanceof ImageIcon) {
    return ((ImageIcon)icon).getImage();
  }
 else {
    int w=icon.getIconWidth();
    int h=icon.getIconHeight();
    GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd=ge.getDefaultScreenDevice();
    GraphicsConfiguration gc=gd.getDefaultConfiguration();
    BufferedImage image=gc.createCompatibleImage(w,h);
    Graphics2D g=image.createGraphics();
    icon.paintIcon(null,g,0,0);
    g.dispose();
    return image;
  }
}
 

Example 73

From project Openbravo-POS-iPhone-App, under directory /UnicentaPOS/src-pos/com/openbravo/pos/catalog/.

Source file: JProductsSelector.java

  15 
vote

public void addProduct(Image img,String name,ActionListener al){
  JButton btn=new JButton();
  btn.applyComponentOrientation(getComponentOrientation());
  btn.setText(name);
  btn.setIcon(new ImageIcon(img));
  btn.setFocusPainted(false);
  btn.setFocusable(false);
  btn.setRequestFocusEnabled(false);
  btn.setHorizontalTextPosition(SwingConstants.CENTER);
  btn.setVerticalTextPosition(SwingConstants.BOTTOM);
  btn.setMargin(new Insets(2,2,2,2));
  btn.setMaximumSize(new Dimension(80,70));
  btn.setPreferredSize(new Dimension(80,70));
  btn.setMinimumSize(new Dimension(80,70));
  btn.addActionListener(al);
  flowpanel.add(btn);
}