001: /*
002: * Created on 26/08/2005
003: *
004: * Swing Components - visit http://sf.net/projects/gfd
005: *
006: * Copyright (C) 2005 Igor Regis da Silva Simões
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: *
022: */
023: package br.com.gfp.windows.views;
024:
025: import java.awt.BorderLayout;
026: import java.awt.Component;
027: import java.awt.event.ActionEvent;
028: import java.io.File;
029: import java.io.IOException;
030: import java.net.URL;
031: import java.util.ArrayList;
032: import java.util.Locale;
033:
034: import javax.swing.AbstractAction;
035: import javax.swing.Action;
036: import javax.swing.JEditorPane;
037: import javax.swing.JPanel;
038: import javax.swing.JScrollPane;
039: import javax.swing.event.HyperlinkEvent;
040: import javax.swing.event.HyperlinkListener;
041:
042: import org.flexdock.docking.Dockable;
043: import org.flexdock.docking.DockingConstants;
044: import org.flexdock.docking.DockingManager;
045: import org.flexdock.util.SwingUtility;
046: import org.flexdock.view.View;
047:
048: import br.com.gfp.dao.GFPController;
049: import br.com.gfp.internationalization.ViewsMessages;
050: import br.com.gfp.util.SimpleLog;
051: import br.com.gfpshare.beans.aplicativos.IconeFactory;
052:
053: /**
054: * Esta é a view de help, usada para visualizar a ajuda do GFP
055: * @author Igor Regis da Silva Simoes
056: * @since 26/08/2005
057: */
058: public class HelpView extends View {
059: private JEditorPane helpHTML = new JEditorPane();
060:
061: /**
062: * Botão que retorna o histórico
063: */
064: private Action back = null;
065:
066: /**
067: * Botão que avança o histórico
068: */
069: private Action forward = null;
070:
071: /**
072: * Lista de links já navegados pelo usuário
073: */
074: private ArrayList<URL> links = new ArrayList<URL>();
075:
076: /**
077: * Indice do link autal vizualizado pelo usuário
078: */
079: private int indiceLinkAtual = 0;
080:
081: /**
082: * Arquivo de help a ser usado
083: */
084: private String helpPath = null;
085:
086: /**
087: * Cria uma instancia dea view de help
088: */
089: public HelpView() {
090: super (ViewsMessages.getMessages().getString("Help"),
091: ViewsMessages.getMessages().getString("Help"),
092: ViewsMessages.getMessages().getString("Help"));
093: setIcon(IconeFactory.getIconeFactory().getScaledImage(
094: "/icones/22x22/help.png", 10));
095: buildUI();
096: }
097:
098: /**
099: * Constroi o interface gráfica da tela
100: */
101: @SuppressWarnings("unchecked")
102: private void buildUI() {
103: setContentPane(createMyContentPane());
104: back = new AbstractAction() {
105: public void actionPerformed(ActionEvent e) {
106: try {
107: if (indiceLinkAtual - 1 >= 0) {
108: helpHTML.setPage(links.get(--indiceLinkAtual));
109: forward.setEnabled(true);
110: if (indiceLinkAtual == 0)
111: back.setEnabled(false);
112: }
113: } catch (IOException e1) {
114: ((SimpleLog) GFPController.getGFPController()
115: .getContexto().get(GFPController.LOG))
116: .log("Erro na navegação do help com botão back!");
117: ((SimpleLog) GFPController.getGFPController()
118: .getContexto().get(GFPController.LOG))
119: .log("ActionEvent: " + e);
120: ((SimpleLog) GFPController.getGFPController()
121: .getContexto().get(GFPController.LOG))
122: .log(e1.getLocalizedMessage());
123: ((SimpleLog) GFPController.getGFPController()
124: .getContexto().get(GFPController.LOG))
125: .log(e1);
126: }
127: }
128: };
129: back.putValue(Action.SMALL_ICON, IconeFactory.getIconeFactory()
130: .getScaledImage("/icones/16x16/back.png", 10));
131: back.putValue(Action.NAME, ViewsMessages.getMessages()
132: .getString("Retornar"));
133: back.setEnabled(false);
134:
135: forward = new AbstractAction() {
136: public void actionPerformed(ActionEvent e) {
137: try {
138: if (indiceLinkAtual + 1 < links.size()) {
139: helpHTML.setPage(links.get(++indiceLinkAtual));
140: back.setEnabled(true);
141: if (indiceLinkAtual + 1 == links.size()) {
142: forward.setEnabled(false);
143: }
144: }
145: } catch (IOException e1) {
146: ((SimpleLog) GFPController.getGFPController()
147: .getContexto().get(GFPController.LOG))
148: .log("Erro na navegação do help com botão forward!");
149: ((SimpleLog) GFPController.getGFPController()
150: .getContexto().get(GFPController.LOG))
151: .log("ActionEvent: " + e);
152: ((SimpleLog) GFPController.getGFPController()
153: .getContexto().get(GFPController.LOG))
154: .log(e1.getLocalizedMessage());
155: ((SimpleLog) GFPController.getGFPController()
156: .getContexto().get(GFPController.LOG))
157: .log(e1);
158: }
159: }
160: };
161: forward.putValue(Action.SMALL_ICON, IconeFactory
162: .getIconeFactory().getScaledImage(
163: "/icones/16x16/forward.png", 10));
164: forward.putValue(Action.NAME, ViewsMessages.getMessages()
165: .getString("Avancar"));
166: forward.setEnabled(false);
167:
168: addAction(DockingConstants.CLOSE_ACTION);
169: addAction(forward);
170: addAction(back);
171: Action max = new AbstractAction() {
172: public void actionPerformed(ActionEvent e) {
173: DockingManager
174: .toggleMaximized((Dockable) HelpView.this );
175: SwingUtility.repaint((Component) GFPController
176: .getGFPController().getContexto().get(
177: GFPController.DESKTOP));
178: }
179: };
180: max.putValue(Action.NAME, "Max");
181: max.putValue(Action.SMALL_ICON, IconeFactory.getIconeFactory()
182: .getScaledImage("/icones/16x16/maximize.gif", 16));
183: addAction(max);
184: addAction(DockingConstants.PIN_ACTION);
185: }
186:
187: public HelpView(String helpFile) {
188: this ();
189: this .helpPath = helpFile;
190: buildUI();
191: }
192:
193: /**
194: * Inicializamos o painel de conteúdo do help
195: * @return JPanel
196: */
197: private JPanel createMyContentPane() {
198: JPanel content = new JPanel();
199: content.setLayout(new BorderLayout());
200:
201: helpHTML.setEditable(false);
202: try {
203: File helpFile = null;
204: String helpFilePath = null;
205: if (helpPath == null) {
206: helpFile = new File(System.getProperty("user.dir")
207: + "/helpFiles/index_"
208: + Locale.getDefault().getLanguage() + ".html");
209:
210: if (helpFile.exists())//Se existe help para o idioma selecionado na estacao...
211: helpPath = "file:///" + helpFile.getAbsolutePath();
212: else
213: //Usamos o default (ingles)
214: helpPath = "file:///"
215: + System.getProperty("user.dir")
216: + "/helpFiles/index_en.html";
217: }
218: helpFilePath = helpPath;
219: helpHTML.setPage(helpFilePath);
220: helpHTML.addHyperlinkListener(new LinkListener());
221: links.add(indiceLinkAtual, helpHTML.getPage());
222: } catch (IOException e) {
223: ((SimpleLog) GFPController.getGFPController().getContexto()
224: .get(GFPController.LOG))
225: .log("Erro na inicializacao do help");
226: ((SimpleLog) GFPController.getGFPController().getContexto()
227: .get(GFPController.LOG)).log(e
228: .getLocalizedMessage());
229: ((SimpleLog) GFPController.getGFPController().getContexto()
230: .get(GFPController.LOG)).log(e);
231: }
232:
233: content.add(new JScrollPane(helpHTML), BorderLayout.CENTER);
234: return content;
235: }
236:
237: /**
238: * Listener responsável por realizar a abertura de hyperlinks
239: *
240: * @author Igor Regis da Silva Simoes
241: * @since 10/08/2005
242: */
243: private class LinkListener implements HyperlinkListener {
244:
245: /**
246: * Aqui ouvimos os aventos relativos a hyperlinks
247: * @see javax.swing.event.HyperlinkListener#hyperlinkUpdate(javax.swing.event.HyperlinkEvent)
248: */
249: public void hyperlinkUpdate(HyperlinkEvent e) {
250: //Se for umn clique do mouse então
251: if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
252: try {// nós abrimos o link solicitado
253: helpHTML.setPage(e.getURL());
254: if (links.size() > indiceLinkAtual + 1
255: && links.get(indiceLinkAtual + 1) != null)
256: links.remove(indiceLinkAtual + 1);
257: links.add(++indiceLinkAtual, e.getURL());
258: back.setEnabled(true);
259: } catch (IOException e1) {
260: ((SimpleLog) GFPController.getGFPController()
261: .getContexto().get(GFPController.LOG))
262: .log("Erro na navegacao do help: "
263: + e.getURL());
264: ((SimpleLog) GFPController.getGFPController()
265: .getContexto().get(GFPController.LOG))
266: .log(e1.getLocalizedMessage());
267: ((SimpleLog) GFPController.getGFPController()
268: .getContexto().get(GFPController.LOG))
269: .log(e1);
270: }
271: }
272: }
273:
274: }
275: }
|