Skip to content

Commit

Permalink
Added class SwissArmyKnife to hold common tools. Added a class to that
Browse files Browse the repository at this point in the history
which sets the application icons used by the Operating System.

Signed-off-by: Mike Schoonover <[email protected]>
  • Loading branch information
Mike Schoonover committed Sep 25, 2013
1 parent c4c8683 commit dcbf09a
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 0 deletions.
Binary file added Icon/IRScan Chart Icon 16x16-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icon/IRScan Chart Icon 16x16-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icon/IRScan Chart Icon 16x16-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icon/IRScan Chart Icon 256x256-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icon/IRScan Chart Icon 32x32-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icon/IRScan Chart Icon 32x32-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icon/IRScan Chart Icon 32x32-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icon/IRScan Chart Icon 48x48-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icon/IRScan Chart Icon 48x48-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/chart/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import chart.mksystems.settings.Settings;
import chart.mksystems.stripchart.ChartGroup;
import chart.mksystems.tools.MultipleInstancePreventer;
import chart.mksystems.tools.SwissArmyKnife;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand Down Expand Up @@ -281,6 +282,9 @@ public void init()
//create the program's main window
mainFrame = new JFrame("Java Chart");
settings.mainFrame = mainFrame; //store for use by other objects

SwissArmyKnife.setIconImages(mainFrame, Main.class, "IRScan Chart Icon");

//do not auto exit on close - shut down handled by the timer function
mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
mainFrame.addComponentListener(this);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions src/chart/mksystems/tools/SwissArmyKnife.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/******************************************************************************
* Title: SwissArmyKnife.java
* Author: Mike Schoonover
* Date: 9/25/13
*
* Purpose:
*
* This class handles various functions required by the typical application.
* It consists of static methods and is not meant to be instantiated.
*
* Open Source Policy:
*
* This source code is Public Domain and free to any interested party. Any
* person, company, or organization may do with it as they please.
*
*/

package chart.mksystems.tools;

//-----------------------------------------------------------------------------

import chart.ControlPanel;
import java.awt.Image;
import java.awt.Window;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;

//

public class SwissArmyKnife extends Object{


//-----------------------------------------------------------------------------
// SwissArmyKnife::setIconImages
//
// Sets the images to be used by the Operating System as icons for pWindow.
//
// The images are loaded from the "images/application icons" folder located
// in the root folder of the application's jar file. pRootClass should be
// any class in the jar's root folder, such as class Main and is used to
// locate the image folder.
//
// pIconBaseName is the unique name part of each icon -- the name will be
// completed by adding "16x16-32.png", "32x32-32.png", "48x48-32.png",
// "256x256-32.png", etc... Where YxY is the image size and -zz is the color
// depth.
//
// So if the icons are named "IRScan Chart Icon 16x16-32.png" and so forth,
// pIconBaseName should be set to "IRScan Chart Icon" and this method will
// append the appropriate suffixes to load each size of icon.
//

static public void setIconImages(Window pWindow, Class pRootClass,
String pIconBaseName)
{

String path = "images/application icons/";
String fullPath;
java.net.URL imgURL;

List <Image> icons = new ArrayList<>();

//retrieve each size of icon image

fullPath = path + pIconBaseName + " 16x16-32.png";
imgURL = pRootClass.getResource(fullPath);
if (imgURL != null) { icons.add(new ImageIcon(imgURL).getImage()); }

fullPath = path + pIconBaseName + " 32x32-32.png";
imgURL = pRootClass.getResource(fullPath);
if (imgURL != null) { icons.add(new ImageIcon(imgURL).getImage()); }

fullPath = path + pIconBaseName + " 48x48-32.png";
imgURL = pRootClass.getResource(fullPath);
if (imgURL != null) { icons.add(new ImageIcon(imgURL).getImage()); }

fullPath = path + pIconBaseName + " 256x256-32.png";
imgURL = pRootClass.getResource(fullPath);
if (imgURL != null) { icons.add(new ImageIcon(imgURL).getImage()); }

//set the window's icon set

pWindow.setIconImages(icons);

}//end of SwissArmyKnife::setIconImages
//-----------------------------------------------------------------------------

}//end of class SwissArmyKnife
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

0 comments on commit dcbf09a

Please sign in to comment.