001: /*
002: * Copyright (C) 2001, 2002 Robert MacGrogan
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: *
019: * $Archive: SourceJammer$
020: * $FileName: ChangeLookAndFeelAction.java$
021: * $FileID: 4044$
022: *
023: * Last change:
024: * $AuthorName: Timo Haberkern$
025: * $Date: 9/11/03 5:31 AM$
026: * $Comment: Added Metuia and Plastic3D L&F$
027: */
028:
029: package org.sourcejammer.client.gui.action;
030:
031: import java.awt.event.ActionEvent;
032:
033: import javax.swing.AbstractAction;
034: import javax.swing.Action;
035: import javax.swing.SwingUtilities;
036: import javax.swing.UIManager;
037: import javax.swing.UnsupportedLookAndFeelException;
038:
039: import org.sourcejammer.client.SourceJammerClient;
040: import org.sourcejammer.client.gui.CommandCentral;
041: import org.sourcejammer.client.gui.MessageBoxUtil;
042: import org.sourcejammer.client.gui.SJPrimaryWindow;
043: import org.sourcejammer.client.gui.conf.UserPrefs;
044: import org.sourcejammer.client.gui.icons.IconBank;
045: import org.sourcejammer.util.AppConfig;
046:
047: /**
048: * Title: $FileName: ChangeLookAndFeelAction.java$
049: * @version $VerNum: 8$
050: * @author $AuthorName: Timo Haberkern$<br><br>
051: *
052: * $Description: $<br>
053: * $KeyWordsOff: $<br>
054: *
055: * Abstract super-class for Look and feel selection actions.
056: */
057: public abstract class ChangeLookAndFeelAction extends AbstractAction {
058:
059: private static Integer currentLAF = null;
060:
061: public ChangeLookAndFeelAction() {
062: super ();
063: }
064:
065: public ChangeLookAndFeelAction(String name) {
066: super (name);
067: Integer current = getCurrentLAF();
068: if (current.equals(getActionIdentifier())) {
069: putValue(Action.SMALL_ICON, IconBank.getInstance().getIcon(
070: IconBank.ACTION_ON));
071: } else {
072: putValue(Action.SMALL_ICON, IconBank.getInstance().getIcon(
073: IconBank.BLANK_TOOL));
074: }
075: }
076:
077: private static Integer getCurrentLAF() {
078: if (currentLAF == null) {
079: String sInitialLAF = SourceJammerClient.getInstance()
080: .getInitialLookAndFeel();
081:
082: sInitialLAF = UserPrefs.getInstance().getString(
083: UserPrefs.LOOK_AND_FEEL, sInitialLAF);
084:
085: if (sInitialLAF.equals(AppConfig.LookAndFeel.WINDOWS)) {
086: currentLAF = Actions.act_WINDOWS_LOOK_AND_FEEL;
087: } else if (sInitialLAF.equals(AppConfig.LookAndFeel.MOTIF)) {
088: currentLAF = Actions.act_MOTIF_LOOK_AND_FEEL;
089: } else if (sInitialLAF
090: .equals(AppConfig.LookAndFeel.KUNSTOFF)) {
091: currentLAF = Actions.act_K_LOOK_AND_FEEL;
092: } else if (sInitialLAF
093: .equals(AppConfig.LookAndFeel.PLASTIC)) {
094: currentLAF = Actions.act_PLASTIC_LOOK_AND_FEEL;
095: } else if (sInitialLAF
096: .equals(AppConfig.LookAndFeel.METOUIA)) {
097: currentLAF = Actions.act_METOUIA_LOOK_AND_FEEL;
098: } else {
099: currentLAF = Actions.act_METAL_LOOK_AND_FEEL;
100: }
101: }
102: return currentLAF;
103: }
104:
105: public void actionPerformed(ActionEvent ev) {
106: try {
107: String sLookAndFeel = getLookAndFeelName();
108: UIManager.setLookAndFeel(sLookAndFeel);
109: SJPrimaryWindow win = CommandCentral.getInstance()
110: .getRootAppFrame();
111: SwingUtilities.updateComponentTreeUI(win);
112: win.updatePopupUI();
113: //Action act = ActionCentral.getInstance().getAction(currentLAF);
114: //act.putValue(Action.SMALL_ICON, IconBank.getInstance().getIcon(IconBank.BLANK_TOOL));
115: //currentLAF = getActionIdentifier();
116: //putValue(Action.SMALL_ICON, IconBank.getInstance().getIcon(IconBank.ACTION_ON));
117: } catch (UnsupportedLookAndFeelException ex) {
118: MessageBoxUtil
119: .displayErrorMessage("The look and feel you selected is not supported.");
120: } catch (Throwable thr) {
121: MessageBoxUtil.displayErrorMessage(thr.getMessage(), true);
122: thr.printStackTrace();
123: }
124: }
125:
126: protected abstract String getLookAndFeelName();
127:
128: protected abstract Integer getActionIdentifier();
129:
130: }
|