Code Monkey home page Code Monkey logo

iconmanager's Introduction

Maven Central Build Status License codecov Known Vulnerabilities Codacy Badge

Icon Manager

This is java utilite reads different icon formats to use it in the applicaitons (e.g. Swing), but it doesn't depend on any Swing's sources).

E.g. in Swing application, usually we use png files for images. This manager provide ability to use any icon formats instead.

Currently supports:

  • *.ico - Windows Icon
  • *.icl - Windows Icon Library
  • *.icns - Macintosh Icon
How do we use images in Swing application
JLabel label_16x16_HighColor = new JLabel(new ImageIcon("smile_16x16_HighColor.png"));
JLabel label_24x24_HighColor = new JLabel(new ImageIcon("smile_24x24_HighColor.png"));
JLabel label_32x32_HighColor = new JLabel(new ImageIcon("smile_32x32_HighColor.png"));

It means, that if we use lot's of different images, we have lot's of files in resources.

How to use Icon Manager
  • *.ico and *.icns
IconManager iconManager = IconManager.getInstance();
File file = new File("smile.ico");  // or "smile.icns"
String id = file.getName();
iconManager.addIcon(id, ImageIO.createImageInputStream(file));

// get icon from the icon manager
IconFile iconFile = iconManager.getIconFile(id);

JLabel label_16x16_HighColor = new JLabel(new ImageIcon(iconFile.getImage(ImageKey.parse(16, 16, 16))));
JLabel label_24x24_HighColor = new JLabel(new ImageIcon(iconFile.getImage(ImageKey.parse(24, 24, 16))));
JLabel label_32x32_HighColor = new JLabel(new ImageIcon(iconFile.getImage(ImageKey.parse(32, 32, 16))));

// or use id directly in format: "<width>x<height>_<bitsPerPixel>"
JLabel label_16x16_HighColor = new JLabel(new ImageIcon(iconFile.getImage("16x16_16")));
JLabel label_24x24_HighColor = new JLabel(new ImageIcon(iconFile.getImage("24x24_16")));
JLabel label_32x32_HighColor = new JLabel(new ImageIcon(iconFile.getImage("32x32_16")));
  • *.icl This is a Windows icon library, therefore each icon has it's own name (lower-case) inside the library
IconManager iconManager = IconManager.getInstance();
File file = new File("smile.icl");
String id = file.getName();
iconManager.addIcon(id, ImageIO.createImageInputStream(file));

// get icon library from the icon manager
IclFile iconFile = iconManager.getIconFile(id);

// get list of  existed icons from the library
Set<String> names = getNames(); // e.g. name = "Doom"
String firstIcon = names.iterator().next();

JLabel label_16x16_HighColor = new JLabel(new ImageIcon(iconFile.getImage(ImageKey.parse("Doom", 16, 16, 16))));
JLabel label_24x24_HighColor = new JLabel(new ImageIcon(iconFile.getImage(ImageKey.parse("Doom", 24, 24, 16))));
JLabel label_32x32_HighColor = new JLabel(new ImageIcon(iconFile.getImage(ImageKey.parse("Doom", 32, 32, 16))));

// or use id directly in format: "<iconMame>_<width>x<height>_<bitsPerPixel>"
JLabel label_16x16_HighColor = new JLabel(new ImageIcon(iconFile.getImage("doom_16x16_16")));
JLabel label_24x24_HighColor = new JLabel(new ImageIcon(iconFile.getImage("doom_24x24_16")));
JLabel label_32x32_HighColor = new JLabel(new ImageIcon(iconFile.getImage("doom_32x32_16")));
Links

iconmanager's People

Contributors

oleg-cherednik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kapawit

iconmanager's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.