/* * Copyright 2008 Federal Chancellery Austria and * Graz University of Technology * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package at.gv.egiz.bku.gui; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Locale; import java.util.ResourceBundle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class HelpListener implements MouseListener, KeyListener, HelpURLProvider { public static final String MESSAGE_BUNDLE = "at/gv/egiz/bku/gui/Messages"; private final Logger log = LoggerFactory.getLogger(HelpListener.class); private String helpURL; protected String helpTopic; protected ResourceBundle messageBundle; public HelpListener(String baseHelpURL, Locale locale) { helpURL = baseHelpURL; if (locale != null) { log.trace("Check for support of requested help locale {}.", locale); messageBundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, locale); } else { messageBundle = ResourceBundle.getBundle(MESSAGE_BUNDLE); } if ("".equals(messageBundle.getLocale().getLanguage())) { log.trace("Using help locale 'default'."); } else { log.trace("Using help locale '{}'.", messageBundle.getLocale()); helpURL += messageBundle.getLocale().getLanguage() + '/'; } log.debug("Setting help context to {}.", helpURL); } @Override public synchronized void setHelpTopic(String topic) { log.trace("Setting help topic: {}.", topic); helpTopic = topic; } @Override public synchronized String getHelpURL() { if (helpTopic == null) { log.debug("No help topic set, return index."); return helpURL + "index.html"; } StringBuilder url = new StringBuilder(helpURL); url.append(helpTopic); url.append(".html"); log.debug("Return help url: {}.", url.toString()); return url.toString(); } /** * By default, HelpListener cannot handle action events and acts as (deaf) help context only. * Subclasses may add listener functionality. * * Whether a listener is available so that GUI elements may be included to provide context help. * (whether a help icon shall be included) * @return true if this HelpListener implements the Mouse/KeyListeners */ public boolean implementsListener() { return false; } @Override public void mouseClicked(MouseEvent arg0) { } @Override public void keyPressed(KeyEvent arg0) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { } }