📄 iconmanager.java
字号:
package openicq.gui;import java.util.ArrayList;import javax.swing.JList;import openicq.Start;import openicq.data.Resource;import org.javalib.gui.IconListCellRenderer;import org.javalib.sound.MediaPlayer;/** * The <code>IconManager</code> class manages the icons of an * <code>IconListCellRenderer</code> * @author Hansgeorg Schwibbe * @copyright 2004 */public class IconManager implements Runnable{ private MediaPlayer player = new MediaPlayer(); private Thread th; private JList list; private IconListCellRenderer renderer; private Object[] arrPrimaryKeys; private ArrayList listDefaultIconSources = new ArrayList(); private ArrayList listIconSources1 = new ArrayList(); private ArrayList listIconSources2 = new ArrayList(); private ArrayList listPrimaryKeys = new ArrayList(); private ArrayList listIcons1 = new ArrayList(); private ArrayList listIcons2 = new ArrayList(); private boolean again; private final int MIN_CELL_HEIGHT = 20; private final int SLEEPTIME = 650; /** * Initializes a new instance of the class <code>IconManager</code>. * @param list the list on which the icons will be painted * @param listDefaultIconSources the list of all standard icons * @param arrPrimaryKeys the array with the primary keys */ public IconManager(JList list, ArrayList listDefaultIconSources, Object[] arrPrimaryKeys) { this.list = list; this.renderer = new IconListCellRenderer(); this.list.setCellRenderer(renderer); this.setIconSources(listDefaultIconSources, arrPrimaryKeys); } /** * Sets the standard icons for all primary keys. * @param listDefaultIconSources the list of all standard icons * @param arrPrimaryKeys the array with the primary keys */ public synchronized void setIconSources(ArrayList listDefaultIconSources, Object[] arrPrimaryKeys) { this.listDefaultIconSources = listDefaultIconSources; this.arrPrimaryKeys = arrPrimaryKeys; this.listIconSources1.clear(); this.listIconSources2.clear(); int size = this.listDefaultIconSources.size(); for (int index = 0; index < size; index++) { this.listIconSources1.add(this.listDefaultIconSources.get(index)); this.listIconSources2.add(this.listDefaultIconSources.get(index)); } for (int idx = 0; idx < arrPrimaryKeys.length; idx++) { int position = listPrimaryKeys.indexOf(arrPrimaryKeys[idx]); if (position >= 0) { try { this.listIconSources1.set(idx, this.listIcons1.get(position)); this.listIconSources2.set(idx, this.listIcons2.get(position)); } catch (Exception ex) { System.err.println(this.getClass().getName() + ": " + ex.toString()); } } } if (renderer.getMaxIconHeight() > MIN_CELL_HEIGHT) { list.setFixedCellHeight(renderer.getMaxIconHeight()); } else { list.setFixedCellHeight(MIN_CELL_HEIGHT); } } /** * Retuns whether any flicker icon has been set. * @return true if a flicker icon has been set. */ public boolean hasFlickerIcon() { if (this.listIcons1.size() > 0 && this.listIcons2.size() > 0) { return true; } return false; } /** * Sets the flicker icon to the specified primary key (toggling between two * icons) * @param primaryKey the primary key * @param icon1 the first icon * @param icon2 the second icon */ public synchronized void setFlickerIcon(String primaryKey, String icon1, String icon2) { for (int index = 0; index < this.arrPrimaryKeys.length; index++) { if (arrPrimaryKeys[index].equals(primaryKey)) { if (!listPrimaryKeys.contains(primaryKey)) { listPrimaryKeys.add(primaryKey); listIcons1.add(icon1); listIcons2.add(icon2); listIconSources1.set(index, icon1); listIconSources2.set(index, icon2); } synchronized (Start.env) { if (Start.env.isSoundEnabled() && Start.env.getSoundFlags()[2] == true && !Start.env.getSoundFileNames()[2].equals("")) { try { player.playSound(Start.env.getSoundFileNames()[2]); } catch (Exception ex) { System.err.println(this.getClass().getName() + ": " + ex.toString()); } } } return; } } } /** * Removes the flicker icon from the primary key and sets the standard icon. * @param primaryKey the primary key */ public synchronized void removeFlickerIcon(String primaryKey) { for (int index = 0; index < this.arrPrimaryKeys.length; index++) { if (arrPrimaryKeys[index].equals(primaryKey)) { int position = listPrimaryKeys.indexOf(primaryKey); if (position >= 0) { listIcons1.remove(position); listIcons2.remove(position); listPrimaryKeys.remove(position); } listIconSources1.set(index, listDefaultIconSources.get(index)); listIconSources2.set(index, listDefaultIconSources.get(index)); return; } } } /** * Starts this icon manager. */ public void startManager() { if (th != null && th.isAlive()) { return; } again = true; th = new Thread(this); th.start(); } /** * (non-Javadoc) * @see java.lang.Runnable#run() */ public void run() { while (again) { try { if (this.hasFlickerIcon()) { SysTray.setOverlayIcon(Resource.ICON_SOURCE_TRAY[9]); } else { SysTray.removeOverlayIcon(); } renderer.setCellIcons(list, listIconSources1.toArray()); Thread.sleep(SLEEPTIME); if (this.hasFlickerIcon()) { SysTray.setOverlayIcon(Resource.ICON_SOURCE_TRAY[10]); } else { SysTray.removeOverlayIcon(); } renderer.setCellIcons(list, listIconSources2.toArray()); Thread.sleep(SLEEPTIME); } catch (Exception ex) { System.err.println(this.getClass().getName() + ": " + ex.toString()); } } } /** * Stops this icon manager. */ public void stopManager() { again = false; if (th != null) { try { th.join(); } catch (Exception ex) { System.err.println(this.getClass().getName() + ": " + ex.toString()); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -