From e8b3d6c6a5dce08a4edf4d7f149d03e5d80b8f1d Mon Sep 17 00:00:00 2001 From: Charlie Waters Date: Sun, 4 Mar 2018 11:41:41 -0500 Subject: [PATCH] Add Notes plugin --- .../client/plugins/notes/NotesConfig.java | 55 ++++++++++ .../client/plugins/notes/NotesPanel.java | 94 ++++++++++++++++++ .../client/plugins/notes/NotesPlugin.java | 80 +++++++++++++++ .../client/plugins/notes/notes_icon.png | Bin 0 -> 503 bytes 4 files changed, 229 insertions(+) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesConfig.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPanel.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPlugin.java create mode 100644 runelite-client/src/main/resources/net/runelite/client/plugins/notes/notes_icon.png diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesConfig.java new file mode 100644 index 0000000000..b82cc1ff5d --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesConfig.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018 Charlie Waters + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.notes; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup( + keyName = "notes", + name = "Notes", + description = "Configuration for the Notes plugin" +) +public interface NotesConfig extends Config +{ + @ConfigItem( + keyName = "notesData", + name = "", + description = "", + hidden = true + ) + default String notesData() + { + return ""; + } + + @ConfigItem( + keyName = "notesData", + name = "", + description = "" + ) + void notesData(String str); +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPanel.java new file mode 100644 index 0000000000..c214e23381 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPanel.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2018 Charlie Waters + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.notes; + +import javax.swing.BorderFactory; +import javax.swing.JEditorPane; +import javax.swing.JLabel; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; + +import lombok.extern.slf4j.Slf4j; +import net.runelite.client.ui.PluginPanel; + +import java.awt.BorderLayout; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; + +@Slf4j +public class NotesPanel extends PluginPanel +{ + private final JEditorPane notesEditor = new JEditorPane(); + + void init(NotesConfig config) + { + // this may or may not qualify as a hack + // but this lets the editor pane expand to fill the whole parent panel + getParent().setLayout(new BorderLayout()); + getParent().add(this, BorderLayout.CENTER); + + setLayout(new BorderLayout()); + setBorder(BorderFactory.createEmptyBorder(2, 6, 6, 6)); + + final JLabel notesHeader = new JLabel("Notes"); + add(notesHeader, BorderLayout.NORTH); + + notesEditor.setContentType("text/plain"); + + // load note text + String data = config.notesData(); + notesEditor.setText(data); + + notesEditor.addFocusListener(new FocusListener() + { + @Override + public void focusGained(FocusEvent e) + { + + } + + @Override + public void focusLost(FocusEvent e) + { + notesChanged(notesEditor.getDocument()); + } + + private void notesChanged(Document doc) + { + try + { + // get document text and save to config whenever editor is changed + String data = doc.getText(0, doc.getLength()); + config.notesData(data); + } + catch (BadLocationException ex) + { + log.warn("Notes Document Bad Location: " + ex); + } + } + }); + add(notesEditor, BorderLayout.CENTER); + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPlugin.java new file mode 100644 index 0000000000..7d00d21013 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/notes/NotesPlugin.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2018 Charlie Waters + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.notes; + +import javax.imageio.ImageIO; +import javax.inject.Inject; + +import com.google.inject.Provides; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.ui.ClientUI; +import net.runelite.client.ui.NavigationButton; +import lombok.extern.slf4j.Slf4j; + +@PluginDescriptor( + name = "Notes", + loadWhenOutdated = true +) +@Slf4j +public class NotesPlugin extends Plugin +{ + @Inject + private ClientUI ui; + + @Inject + private NotesConfig config; + + private NotesPanel panel; + private NavigationButton navButton; + + @Provides + NotesConfig getConfig(ConfigManager configManager) + { + return configManager.getConfig(NotesConfig.class); + } + + @Override + protected void startUp() throws Exception + { + panel = injector.getInstance(NotesPanel.class); + panel.init(config); + + navButton = new NavigationButton( + "Notes", + ImageIO.read(getClass().getResourceAsStream("notes_icon.png")), + () -> panel + ); + + ui.getPluginToolbar().addNavigation(navButton); + } + + @Override + protected void shutDown() + { + ui.getPluginToolbar().removeNavigation(navButton); + } +} diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/notes/notes_icon.png b/runelite-client/src/main/resources/net/runelite/client/plugins/notes/notes_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..e94292baf184b380e45ae507497429ce29e63e95 GIT binary patch literal 503 zcmV5cm&74<5h0^5xslS0D{chFX%5^Ev~TFftOQpW*-i{|p(m zo0Csoc(M?rgT>51DtYxR{~4q>Jtk*M{^3)Pr-2QyGL=c*y)v961AODw7VJCn0Ahfp ziFER=<-sHw;FqwWVE@raPy>vmlD9AQBgue(q^$)9jzPU(VI-NnZLt?g1_Y(-EI4rd z3CsZTY^EZ=CBy(17nh{xbae^N)d-hm|2L^I*ZDlh3C? zqfs<@!)!ae2K@T{kKxUGMg}%E4h9ycFAV9GCkqardI>W?Bzf&jE1U-W|MwrL`9A{- z3pc~ZPahfXJ$ld3JL^`#r5o=d2AJv#C$E`qhTQ;Qx_$TIH^ZxUe;DpR`pEG0`(Fkn zIc|pbskaJFU3?2QKu;)n^;8oK1Ar-(;qi;_4Ck(VVEFs@KZB|w4}**Z2Lm5BD?>u* z`TQei-b@D>z%0PWYGJG+7!71|q4*mZV9#EDXW-#tVc-U0HdZDECMHHuj{A20+J}|z tKKwcY%RL~Cf*{ur8H;~__yZ7s1pv)VuT8owdF}uJ002ovPDHLkV1jf++d%*T literal 0 HcmV?d00001