appsettingsimpl.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 761 行 · 第 1/2 页
JAVA
761 行
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package com.sun.midp.appmanager;import javax.microedition.lcdui.*;import com.sun.midp.i18n.Resource;import com.sun.midp.i18n.ResourceConstants;import com.sun.midp.installer.*;import com.sun.midp.midletsuite.*;import com.sun.midp.security.*;import com.sun.midp.io.j2me.push.*;import com.sun.midp.log.Logging;import com.sun.midp.log.LogChannels;import java.util.Vector;/** * The Graphical MIDlet suite settings form. */class AppSettingsImpl implements AppSettings, CommandListener { /** Application settings UI */ AppSettingsUI settingsUI; /** ID for the interrupt choice. */ private static final int INTERRUPT_CHOICE_ID = 2000; /** ID for the first push option radio button. */ private static final int PUSH_OPTION_1_ID = 1000; /** The settings choice group. */ private ValueChoiceImpl groupChoice; /** The application interruption setting. */ private ValueChoiceImpl interruptChoice; /** The previous current choice value. */ private int prevValueID; /** The currently active choice group ID. */ private int curChoiceID; /** The application permission settings. */ private ValueChoiceImpl[] groupSettings; /** The number of group permission settings. */ private int numberOfSettings; /** The initial setting. */ private ValueChoiceImpl initialSetting; /** Holds the maximum levels for permissions. */ private byte[] maxLevels; /** Holds the updated permissions. */ private byte[] curLevels; /** Holds the permissions selected by user for validation. */ private byte[] tmpLevels; /** Holds the previous permissions selected by user for validation. */ private byte[] prevTmpLevels; /** Holds the PUSH permission index */ private int PUSH_ID; /** Holds the updated push interrupt level. */ private byte pushInterruptSetting; /** Holds the selected push interrupt level for validation. */ private byte tmpPushInterruptSetting; /** Holds the updated push options. */ private int pushOptions; /** Permission group information. */ private PermissionGroup[] groups; /** Mutually exclusive permission groups currently selected by user */ private PermissionGroup[] groupsInConflict; /** MIDlet Suite storage object. */ MIDletSuiteStorage midletSuiteStorage; /** UI to display error alerts. */ DisplayError displayError; /** The displayable to be displayed after dismissing AppSettings. */ Displayable nextScreen; /** Display for the Manager midlet. */ Display display; /** Display name of the suite. */ String suiteDisplayName; /** Interface to suite */ MIDletSuiteImpl midletSuite; /** Installation information of the suite. */ InstallInfo installInfo; /** Command object for "OK" command for the alert * that is shown during choice selection validation. */ private Command okChoiceSelectionCmd = new Command(Resource.getString(ResourceConstants.OK), Command.OK, 1); /** Command object for "Cancel" command for the alert * that is shown during choice selection validation. */ private Command cancelChoiceSelectionCmd = new Command(Resource.getString(ResourceConstants.CANCEL), Command.CANCEL, 1); /** * Command object for "OK" command for the alert * that is shown during exclusive group conflict. */ private Command okExclusiveChoiceSelectionCmd = new Command(Resource.getString(ResourceConstants.YES), Command.OK, 1); /** * Command object for "NO" command for the alert * that is shown during exclusive group conflict. */ private Command noExclusiveChoiceSelectionCmd = new Command(Resource.getString(ResourceConstants.NO), Command.CANCEL, 1); /** * Create and initialize a new application settings MIDlet. * @param suiteId - the id of the suite for * which the App settings should be displayed * @param display - the display instance to be used * @param displayError - the UI to be used to display error alerts. * @param nextScreen - the displayable to be shown after * this Form is dismissed */ AppSettingsImpl(int suiteId, Display display, DisplayError displayError, Displayable nextScreen) throws MIDletSuiteLockedException, MIDletSuiteCorruptedException { this.displayError = displayError; midletSuiteStorage = MIDletSuiteStorage.getMIDletSuiteStorage(); this.display = display; this.nextScreen = nextScreen; PUSH_ID = Permissions.getId("javax.microedition.io.PushRegistry"); loadApplicationSettings(suiteId); settingsUI = new AppSettingsUIImpl(); settingsUI.showAppSettings(this, Resource.getString( ResourceConstants.AMS_MGR_SETTINGS), display, displayError); } /** * Called when interrupt choice selection changed */ void onInterruptChoiceChanged() { byte maxInterruptSetting; int interruptSetting = interruptChoice.getSelectedID(); if (maxLevels[PUSH_ID] == Permissions.ALLOW) { maxInterruptSetting = Permissions.BLANKET_GRANTED; } else { maxInterruptSetting = maxLevels[PUSH_ID]; } int newInterruptSettings; if (interruptSetting == PUSH_OPTION_1_ID) { newInterruptSettings = maxInterruptSetting; } else { newInterruptSettings = (byte)interruptSetting; } groupsInConflict = Permissions.checkForMutuallyExclusiveCombination( tmpLevels, (byte)newInterruptSettings); if (groupsInConflict != null) { showGroupsInConflictAlert(); } else { tmpPushInterruptSetting = (byte)newInterruptSettings; } } /** * Called when setting group selection changed * * @param c setting value choice * @param prevValID ID of previously selected value */ private void onChoiceGroupSelectionChanged(ValueChoiceImpl c, int prevValID) { if (c == interruptChoice) { onInterruptChoiceChanged(); } else { for (int i = 0; i < groupSettings.length; i++) { if (groupSettings[i] == c) { byte newSetting = (byte)groupSettings[i].getSelectedID(); onChoiceGroupSelectionChanged(i, prevValID, newSetting); return; } } } } /** * Called when setting group selection changed * @param settingID ID of setting * @param lastSelectedID ID of previously selected value * @param newSetting ID of new value */ private void onChoiceGroupSelectionChanged(int settingID, int lastSelectedID, byte newSetting) { // store previous values if we need to roll back System.arraycopy(tmpLevels, 0, prevTmpLevels, 0, tmpLevels.length); groupsInConflict = Permissions.checkForMutuallyExclusiveCombination(tmpLevels, tmpPushInterruptSetting, groups[settingID], newSetting); if (groupsInConflict != null) { showGroupsInConflictAlert(); return; } try { Permissions.setPermissionGroup(tmpLevels, tmpPushInterruptSetting, groups[settingID], newSetting); } catch (SecurityException e) { // returning to previous selection groupSettings[settingID].setSelectedID(lastSelectedID); // nothing else to do return; } String warning = Permissions.getInsecureCombinationWarning(tmpLevels, tmpPushInterruptSetting, groups[settingID], newSetting); if (warning != null) { // set up variables used afterAlert been dismissed prevValueID = lastSelectedID; curChoiceID = settingID; // show Alert Alert alert = new Alert(Resource.getString(ResourceConstants.WARNING), warning, null, AlertType.WARNING); alert.addCommand(okChoiceSelectionCmd); alert.addCommand(cancelChoiceSelectionCmd); alert.setCommandListener(this); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } } /** * Called by UI when value of particular application setting has been * changed by user. AppSettings validates the user input and If value * is not acceptable, for example due to exclusive combination selected, * changeSettingValue method of AppSettingsUI could be called by AppSettings * to change settings to appropriate values. All necessary informational * alerts in this case are shown to the user by AppSettings and thus * AppSettingsUI has just to change UI accordingly when changeSettingValue * is called. * * @param settingID id of setting * @param valueID id of selected value */ public void onSettingChanged(int settingID, int valueID) { if (settingID == INTERRUPT_CHOICE_ID) { if (interruptChoice != null) { interruptChoice.setSelectedID(valueID); onInterruptChoiceChanged(); } } else { //else ID of group is equivalent to index in array int lastSelectedID = groupSettings[settingID].getSelectedID(); groupSettings[settingID].setSelectedID(valueID); byte newSetting = (byte)groupSettings[settingID].getSelectedID(); if (newSetting != lastSelectedID) { onChoiceGroupSelectionChanged(settingID, lastSelectedID, newSetting); } } } /** * Respond to a command issued on any Screen. * * @param c command activated by the user * @param s the Displayable the command was on. */ public void commandAction(Command c, Displayable s) { if (c == cancelChoiceSelectionCmd) { // roll back group levels System.arraycopy(prevTmpLevels, 0, tmpLevels, 0, tmpLevels.length); // restore choice selection if (curChoiceID >= 0 && curChoiceID < groupSettings.length) { ValueChoiceImpl curChoice = groupSettings[curChoiceID]; curChoice.setSelectedID(prevValueID); settingsUI.changeSettingValue(curChoiceID, curChoice.getSelectedID()); } } else if (c == okExclusiveChoiceSelectionCmd) { if (groupsInConflict != null) { // set [0] to blanket, [1] to session ValueChoiceImpl bs1 = findChoice(groupsInConflict[1]); int prevValID1 = bs1.getSelectedID(); bs1.setSelectedID(Permissions.SESSION); ValueChoiceImpl bs2 = findChoice(groupsInConflict[0]); int prevValID2 = bs2.getSelectedID(); bs2.setSelectedID(Permissions.BLANKET_GRANTED); onChoiceGroupSelectionChanged(bs1, prevValID1); onChoiceGroupSelectionChanged(bs2, prevValID2); settingsUI.changeSettingValue(bs1.getPermissionGroupID(), bs1.getSelectedID()); settingsUI.changeSettingValue(bs2.getPermissionGroupID(), bs2.getSelectedID()); //display.setCurrent(settingsUI.getDisplayable()); } } else if (c == noExclusiveChoiceSelectionCmd) { if (groupsInConflict != null) { // set [1] to blanket, [0] to session ValueChoiceImpl bs1 = findChoice(groupsInConflict[0]); int prevValID1 = bs1.getSelectedID(); bs1.setSelectedID(Permissions.SESSION); ValueChoiceImpl bs2 = findChoice(groupsInConflict[1]); int prevValID2 = bs2.getSelectedID(); bs2.setSelectedID(Permissions.BLANKET_GRANTED); onChoiceGroupSelectionChanged(bs1, prevValID1); onChoiceGroupSelectionChanged(bs2, prevValID2); settingsUI.changeSettingValue(bs1.getPermissionGroupID(), bs1.getSelectedID()); settingsUI.changeSettingValue(bs2.getPermissionGroupID(), bs2.getSelectedID()); //display.setCurrent(settingsUI.getDisplayable()); } } } /** * Returns choice for specified permission group. * * @param pg permission group * @return vlue choice */ private ValueChoiceImpl findChoice(PermissionGroup pg) { if (pg == Permissions.getPushInterruptGroup()) { return interruptChoice; } for (int i = 0; i < groupSettings.length; i++) { if ((groupSettings[i] != null) && (groupSettings[i].getPermissionGroup() == pg)) { return groupSettings[i]; } } return null; } /** * Show alert when mutullu exclusive setting combination * accured.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?