/** * Copyright 1999-2009 The Pegadi Team * * 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 org.pegadi.artis; import no.dusken.common.model.Person; import org.jgraph.event.GraphModelEvent; import org.jgraph.event.GraphModelListener; import org.jgraph.graph.GraphModel; import org.pegadi.maildialog.MailDialog; import org.pegadi.model.LoginContext; import org.pegadi.storysketch.BrowserLauncher; import org.pegadi.storysketch.StorySketchApplication; import org.pegadi.storysketch.StorySketchPanel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Element; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.util.Locale; import java.util.ResourceBundle; public class StorySketchEditor extends Editor implements StorySketchApplication, BrowserLauncher { ResourceBundle sourceStrings; StorySketchPanel sketch; Element xml; private final Logger log = LoggerFactory.getLogger(getClass()); public StorySketchEditor(Element xml, Artis artis) { super(xml, artis); } protected void createUI(Locale loc) { super.createUI(loc); setLayout(new BorderLayout()); sketch = new StorySketchPanel(); sketch.setStorySketchApplication(this); StorySketchPanel.launcher = this; add(sketch, BorderLayout.CENTER); sourceStrings = ResourceBundle.getBundle("org.pegadi.artis.StorySketchEditorStrings",loc); } public synchronized void updateXML() { // Remove all old nodes from root XML element. while (mElement.getChildNodes().getLength() > 0) { mElement.removeChild(mElement.getFirstChild()); } Element model = org.pegadi.storysketch.XMLUtil.createModelElement(sketch.getModel(), mElement.getOwnerDocument()); mElement.appendChild(model); } public int getLength() { return 0; } /** * Returns an icon representing this editor. * * @return The icon. * @see org.pegadi.artis.Editor#getDisplayIcon() */ public ImageIcon getDisplayIcon() { return new ImageIcon(getClass().getResource(sourceStrings.getString("icon_source"))); } public void setXML(Element mElement) { this.mElement = mElement; GraphModel model = org.pegadi.storysketch.XMLUtil.getGraphModel(mElement); model.addGraphModelListener(new GraphModelListener() { public void graphChanged(GraphModelEvent e) { changedFlag = true; } }); sketch.setModel(model); changedFlag = false; } public JMenu getMenu() { return null; } protected void cutPerformed(ActionEvent param1) { } protected void pastePerformed(ActionEvent parm1) { //TODO: implement this pegadi.artis.Editor abstract method } protected void copyPerformed(ActionEvent parm1) { //TODO: implement this pegadi.artis.Editor abstract method } public Action getInsertAction() { return null; } public String getDisplayName() { return sourceStrings.getString("display_name"); } public void sendArticleAsMail(String to) { if(artis != null) { artis.mailArticleText(to); } } public void sendMail(String to, String subject, String text) { log.debug("Mail\n To: " + to +"\n Subject: " +subject +"\n Text: " +text); String fullName = ""; String emailAddress = ""; try { Person u = LoginContext.server.getSessionUser(LoginContext.sessionKey); fullName = u.getName(); emailAddress = u.getEmailAddress(); } catch (Exception e) { log.error("Could not get user data from server", e); } MailDialog dialog = new MailDialog((Frame)SwingUtilities.windowForComponent(this), "Send epost", true); dialog.setFromAddress(fullName +" <" +emailAddress +">"); dialog.setToAddress(to); dialog.setSubjectText(subject); dialog.setBodyText(text +"\n\n-- \n" +fullName + "\n" + emailAddress); dialog.setFromFieldEditable(false); dialog.setToFieldEditable(true); dialog.pack(); dialog.setVisible(true); } public void browserLaunch(String address) { try { log.debug("Lauching " + address); org.pegadi.util.BrowserLauncher.openURL(address); } catch (Exception e) { log.error("Error launching browser", e); } } }