001 /*
002 * Copyright 2008-2015 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.codehaus.griffon.runtime.javafx.controller;
017
018 import griffon.core.GriffonApplication;
019 import griffon.core.artifact.GriffonController;
020 import griffon.core.controller.Action;
021 import org.codehaus.griffon.runtime.core.controller.AbstractActionManager;
022 import org.slf4j.Logger;
023 import org.slf4j.LoggerFactory;
024
025 import javax.annotation.Nonnull;
026 import javax.inject.Inject;
027
028 import static griffon.util.GriffonApplicationUtils.isMacOSX;
029 import static griffon.util.GriffonNameUtils.isBlank;
030 import static griffon.util.TypeUtils.castToBoolean;
031
032 /**
033 * @author Andres Almiray
034 * @since 2.0.0
035 */
036 public class JavaFXActionManager extends AbstractActionManager {
037 private static final Logger LOG = LoggerFactory.getLogger(JavaFXActionManager.class);
038
039 @Inject
040 public JavaFXActionManager(@Nonnull GriffonApplication application) {
041 super(application);
042 }
043
044 @Nonnull
045 @Override
046 protected Action createControllerAction(@Nonnull GriffonController controller, @Nonnull String actionName) {
047 return new JavaFXGriffonControllerAction(getUiThreadManager(), this, controller, actionName);
048 }
049
050 @Override
051 protected void doConfigureAction(@Nonnull Action action, @Nonnull GriffonController controller, @Nonnull String normalizeNamed, @Nonnull String keyPrefix) {
052 JavaFXGriffonControllerAction javafxAction = (JavaFXGriffonControllerAction) action;
053
054 String rsAccelerator = msg(keyPrefix, normalizeNamed, "accelerator", "");
055 if (!isBlank(rsAccelerator)) {
056 //noinspection ConstantConditions
057 if (!isMacOSX() && rsAccelerator.contains("meta") && !rsAccelerator.contains("ctrl")) {
058 rsAccelerator = rsAccelerator.replace("meta", "ctrl");
059 }
060 if (LOG.isTraceEnabled()) {
061 LOG.trace(keyPrefix + normalizeNamed + ".accelerator = " + rsAccelerator);
062 }
063 javafxAction.setAccelerator(rsAccelerator);
064 }
065
066 String rsDescription = msg(keyPrefix, normalizeNamed, "description", "");
067 if (!isBlank(rsDescription)) {
068 if (LOG.isTraceEnabled()) {
069 LOG.trace(keyPrefix + normalizeNamed + ".description = " + rsDescription);
070 }
071 javafxAction.setDescription(rsDescription);
072 }
073
074 String rsIcon = msg(keyPrefix, normalizeNamed, "icon", "");
075 if (!isBlank(rsIcon)) {
076 if (LOG.isTraceEnabled()) {
077 LOG.trace(keyPrefix + normalizeNamed + ".icon = " + rsIcon);
078 }
079 javafxAction.setIcon(rsIcon);
080 }
081
082 String rsImage = msg(keyPrefix, normalizeNamed, "image", "");
083 if (!isBlank(rsImage)) {
084 if (LOG.isTraceEnabled()) {
085 LOG.trace(keyPrefix + normalizeNamed + ".image = " + rsImage);
086 }
087 javafxAction.setImage(rsImage);
088 }
089
090 String rsEnabled = msg(keyPrefix, normalizeNamed, "enabled", "true");
091 if (!isBlank(rsEnabled)) {
092 if (LOG.isTraceEnabled()) {
093 LOG.trace(keyPrefix + normalizeNamed + ".enabled = " + rsEnabled);
094 }
095 javafxAction.setEnabled(castToBoolean(rsEnabled));
096 }
097
098 String rsSelected = msg(keyPrefix, normalizeNamed, "selected", "false");
099 if (!isBlank(rsSelected)) {
100 if (LOG.isTraceEnabled()) {
101 LOG.trace(keyPrefix + normalizeNamed + ".selected = " + rsSelected);
102 }
103 javafxAction.setSelected(castToBoolean(rsSelected));
104 }
105 }
106 }
|