Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/esmska/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ public void run() {
} catch (Exception ex) {
logger.log(Level.SEVERE, "Could not load keyring file", ex);
}

try {
pm.loadTemplates();
} catch (Exception ex) {
logger.log(Level.SEVERE, "Could not load templates file", ex);
}

//initialize logging if set from Config
if (Config.getInstance().isDebugMode()) {
//set "full" logging, but don't log to console
Expand Down
49 changes: 49 additions & 0 deletions src/esmska/data/Temp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package esmska.data;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

/**
*
* @author Mizerovi16
*/


public class Temp {
private String template;
// <editor-fold defaultstate="collapsed" desc="PropertyChange support">
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

public void addPropertyChangeListener(PropertyChangeListener listener) {
changeSupport.addPropertyChangeListener(listener);
}

public void removePropertyChangeListener(PropertyChangeListener listener) {
changeSupport.removePropertyChangeListener(listener);
}
// </editor-fold>

public Temp (String template) {
setTemplate(template);
}

public void setTemplate(String template) {
this.template = template;
}

public String getTemplate(){
return this.template;
}

@Override
public String toString() {
return template;
}
}


124 changes: 124 additions & 0 deletions src/esmska/data/Template.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package esmska.data;

import esmska.data.event.ActionEventSupport;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;

/**
*
* @author Mizerovi16
*/
public class Template {

private static final Template instance = new Template();
private final List<Temp> templates = Collections.synchronizedList(new ArrayList<Temp>());
private static final Logger logger = Logger.getLogger(Template.class.getName());
private TemplateChangeListener templateChangeListener = new TemplateChangeListener();
/** new template added */
public static final int ACTION_ADD_TEMPLATE = 0;
/** existing template removed */
public static final int ACTION_REMOVE_TEMPLATE = 1;
/** all templates removed */
public static final int ACTION_CLEAR_TEMPLATES = 2;
/** text of some template changed */
public static final int ACTION_CHANGE_TEMPLATE = 3;


// <editor-fold defaultstate="collapsed" desc="ActionEvent support">
private ActionEventSupport actionSupport = new ActionEventSupport(this);
public void addActionListener(ActionListener actionListener) {
actionSupport.addActionListener(actionListener);
}

public void removeActionListener(ActionListener actionListener) {
actionSupport.removeActionListener(actionListener);
}
// </editor-fold>


/** disabled contructor */
private Template() {
}

/** Get shared instance */
public static Template getInstance() {
return instance;
}
/** get all template */
public List<Temp> getTemplates() {
return Collections.unmodifiableList(templates);
}

/** get template at index */
public Temp getTemplate(int index) {
return templates.get(index);
}

/** add new template
* @param temp added template*/
public void addTemplate(Temp temp) {
templates.add(temp);
actionSupport.fireActionPerformed(ACTION_ADD_TEMPLATE, null);
logger.finer("New template added: " + temp);
}

/** add new templates */
public void addTemplates(Collection<Temp> templates) {
for (Temp temp : templates) {
this.templates.add(temp);
}

logger.finer(templates.size() + " new templates added");
actionSupport.fireActionPerformed(ACTION_ADD_TEMPLATE, null);
}

/** remove existing template */
public boolean removeTemplate(Temp temp) {
if (temp == null) {
throw new IllegalArgumentException("template");
}
logger.fine("Removing template: " + temp);
boolean removed = false;
removed = templates.remove(temp);
if (removed) {
temp.removePropertyChangeListener(templateChangeListener);
}
if (removed) {
actionSupport.fireActionPerformed(ACTION_REMOVE_TEMPLATE, null);
}
return removed;
}

/** delete all templates */
public void clear() {
templates.clear();
actionSupport.fireActionPerformed(ACTION_CLEAR_TEMPLATES, null);
logger.finer("All templates removed");
}

public int size() {
return templates.size();
}


/** Listener for changes in individual templates notifying this class'
* listeners that some templates properties have changed.
*/
private class TemplateChangeListener implements PropertyChangeListener {
@Override
public void propertyChange(PropertyChangeEvent evt) {
actionSupport.fireActionPerformed(ACTION_CHANGE_TEMPLATE, null);
}
}
}
91 changes: 88 additions & 3 deletions src/esmska/gui/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
import esmska.data.History;
import esmska.data.History.Record;
import esmska.data.Icons;
import esmska.data.Links;
import esmska.data.Log;
import esmska.data.Queue;
import esmska.data.Queue.Events;
import esmska.data.SMS;
import esmska.data.Temp;
import esmska.data.event.ValuedEvent;
import esmska.data.event.ValuedListener;
import esmska.persistence.ExportManager;
import esmska.utils.ConfirmingFileChooser;
import esmska.utils.L10N;
import esmska.data.event.ValuedEvent;
import esmska.data.event.ValuedListener;
import esmska.data.Links;
import java.awt.Desktop;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
Expand All @@ -32,6 +33,8 @@
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import static javax.swing.Action.LARGE_ICON_KEY;
import static javax.swing.Action.SMALL_ICON;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
Expand All @@ -58,6 +61,8 @@ public class Actions {
private static Action importAction;
private static Action exportAction;
private static Action logAction;
private static Action showAddTemplateAction;
private static Action showEditTemplateAction;

/** Show about frame */
public static Action getAboutAction() {
Expand Down Expand Up @@ -114,6 +119,22 @@ public static Action getLogAction() {
}
return logAction;
}

/** Show add Template frame */
public static Action getShowAddTemplateAction() {
if (showAddTemplateAction == null) {
showAddTemplateAction = new ShowAddTemplateAction();
}
return showAddTemplateAction;
}

/** Show edit Template frame */
public static Action getShowEditTemplateAction() {
if (showEditTemplateAction == null) {
showEditTemplateAction = new ShowEditTemplateAction();
}
return showEditTemplateAction;
}

/** Pause/unpause the sms queue
* @param showName show name of the action (in button text etc)
Expand Down Expand Up @@ -517,4 +538,68 @@ private void updateStatus() {
this.setEnabled(Context.everythingLoaded());
}
}

/** Show the addTemplate frame */
private static class ShowAddTemplateAction extends AbstractAction {
private AddTemplateFrame templateFrame;
public ShowAddTemplateAction() {
L10N.setLocalizedText(this, l10n.getString("AddTemplate_"));
putValue(SMALL_ICON, Icons.get("add-16.png"));
putValue(LARGE_ICON_KEY, Icons.get("add-22.png"));
putValue(SHORT_DESCRIPTION,l10n.getString("Add_Template_message"));
}
@Override
public void actionPerformed(ActionEvent e) {
logger.fine("Showing Template frame...");
if (templateFrame != null && templateFrame.isVisible()) {
templateFrame.requestFocus();
templateFrame.toFront();
} else {
templateFrame = new AddTemplateFrame();
templateFrame.setLocationRelativeTo(Context.mainFrame);
templateFrame.addValuedListener(new TemplateListener());
templateFrame.setVisible(true);
}
}
}

/** Listens for events from template list */
private static class TemplateListener implements ValuedListener<AddTemplateFrame.Events, Temp> {
@Override
public void eventOccured(ValuedEvent<AddTemplateFrame.Events, Temp> e) {
switch (e.getEvent()) {
case INSERT_TEMPLATE:
Temp template = e.getValue();
if (template == null) {
return;
}

Context.mainFrame.getContactPanel().clearSelection();
Context.mainFrame.getSMSPanel().setText(template.getTemplate());
}
}
}

/** Show the editTemplate frame */
private static class ShowEditTemplateAction extends AbstractAction {
private EditTemplateFrame editTemplateFrame;
public ShowEditTemplateAction() {
L10N.setLocalizedText(this, l10n.getString("EditTemplate_"));
putValue(SMALL_ICON, Icons.get("add-16.png"));
putValue(LARGE_ICON_KEY, Icons.get("add-22.png"));
putValue(SHORT_DESCRIPTION,l10n.getString("Edit_Template_message"));
}
@Override
public void actionPerformed(ActionEvent e) {
logger.fine("Showing edit Template frame...");
if (editTemplateFrame != null && editTemplateFrame.isVisible()) {
editTemplateFrame.requestFocus();
editTemplateFrame.toFront();
} else {
editTemplateFrame = new EditTemplateFrame();
editTemplateFrame.setLocationRelativeTo(Context.mainFrame);
editTemplateFrame.setVisible(true);
}
}
}
}
Loading