Skip to content

Commit

Permalink
updates MessageRenderer withh card searched icon
Browse files Browse the repository at this point in the history
  • Loading branch information
nicol authored and nicol committed Sep 19, 2023
1 parent 96fae78 commit dd6a90c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/beta/RedisDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import com.google.gson.JsonObject;

import io.lettuce.core.AbstractRedisAsyncCommands;
import io.lettuce.core.ClientOptions;
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/magic/api/interfaces/MTGDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public interface MTGDao extends MTGPlugin{
public MTGStockItem getStockById(EnumItems typeStock, Long id)throws SQLException;
public void saveOrUpdateStock(MTGStockItem stock) throws SQLException;



public List<MagicCardStock> listStocks(MagicCard mc) throws SQLException;
public List<MagicCardStock> listStocks(MagicCard mc, MagicCollection col,boolean editionStrict) throws SQLException;
public List<MagicCardStock> listStocks(String cardName, List<MagicCollection> cols) throws SQLException;
Expand Down Expand Up @@ -141,4 +139,5 @@ public interface MTGDao extends MTGPlugin{




}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.magic.api.exports.impl.JsonExport;
import org.magic.api.interfaces.MTGDao;
import org.magic.api.interfaces.MTGPool;
import org.magic.api.interfaces.MTGProduct;
import org.magic.api.interfaces.MTGStockItem;
import org.magic.services.tools.TCache;

Expand Down Expand Up @@ -122,6 +123,7 @@ public List<MTGStockItem> listStockItems() throws SQLException {

return ret;
}


@Override
public MagicCardStock getStockById(Long id) throws SQLException {
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/org/magic/gui/components/NetworkChatPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -32,7 +31,6 @@
import org.magic.api.beans.abstracts.AbstractMessage;
import org.magic.api.beans.messages.SearchMessage;
import org.magic.api.beans.messages.StatutMessage;
import org.magic.api.beans.messages.TalkMessage;
import org.magic.api.beans.messages.TechMessageUsers;
import org.magic.api.interfaces.MTGDao;
import org.magic.api.interfaces.MTGNetworkClient;
Expand All @@ -41,7 +39,7 @@
import org.magic.gui.abstracts.MTGUIComponent;
import org.magic.gui.components.dialog.CardSearchImportDialog;
import org.magic.gui.components.widgets.JLangLabel;
import org.magic.gui.renderer.JsonMessageRenderer;
import org.magic.gui.renderer.MessageRenderer;
import org.magic.gui.renderer.PlayerRenderer;
import org.magic.servers.impl.ActiveMQServer;
import org.magic.services.MTGConstants;
Expand Down Expand Up @@ -101,7 +99,7 @@ public NetworkChatPanel() {
editorPane.setWrapStyleWord(true);
editorPane.setRows(3);
listPlayers.setCellRenderer(new PlayerRenderer());
listMsg.setCellRenderer(new JsonMessageRenderer());
listMsg.setCellRenderer(new MessageRenderer());

btnSearch = new JButton("Search");

Expand All @@ -110,9 +108,6 @@ public NetworkChatPanel() {
} catch (Exception e) {
editorPane.setForeground(Color.BLACK);
}




add(panneauHaut, BorderLayout.NORTH);
panneauHaut.add(lblIp);
Expand Down Expand Up @@ -242,11 +237,17 @@ public void keyReleased(java.awt.event.KeyEvent e) {


btnSearch.addActionListener(al->{
try {
try
{
var diag = new CardSearchImportDialog();
diag.setVisible(true);
var msg = new SearchMessage(diag.getSelected());
client.sendMessage(msg);

if(diag.getSelected()!=null)
{
var msg = new SearchMessage(diag.getSelected());
client.sendMessage(msg);
}

} catch (IOException e1) {
logger.error(e1);
}
Expand Down Expand Up @@ -331,7 +332,7 @@ protected void process(List<AbstractMessage> chunks) {
}
break;

case TALK:listMsgModel.addElement((TalkMessage)s);break;
case TALK:listMsgModel.addElement(s);break;

case SYSTEM : listPlayerModel.removeAllElements();
listPlayerModel.addAll(((TechMessageUsers)s).getPlayers());
Expand All @@ -340,12 +341,16 @@ protected void process(List<AbstractMessage> chunks) {
case SEARCH:
var msgs = (SearchMessage)s;
try {
listMsgModel.addElement(msgs);

if(!msgs.getAuthor().getId().equals(client.getPlayer().getId())) {

var ret = MTG.getEnabledPlugin(MTGDao.class).listStocks((MagicCard)msgs.getItem());
logger.info(ret);

if(!ret.isEmpty())
client.sendMessage("I have ! "+ ret.stream().map(mcs->mcs.getProduct().getName() + " " + mcs.getQte() + " " + mcs.getLanguage() + " " + mcs.getCondition()).collect(Collectors.joining(System.lineSeparator())) ,editorPane.getForeground());
}

} catch (Exception e) {
logger.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public String getCurrentURL() {
return currentUrl;
}


@Override
public void loadURL(String url) {
logger.debug("loading {}",url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Date;

import javax.swing.ImageIcon;
Expand All @@ -14,7 +16,10 @@
import javax.swing.border.LineBorder;

import org.magic.api.beans.abstracts.AbstractMessage;
import org.magic.api.beans.abstracts.AbstractMessage.MSG_TYPE;
import org.magic.api.beans.messages.SearchMessage;
import org.magic.services.MTGControler;
import org.magic.services.network.URLTools;
import org.magic.services.tools.ImageTools;
import org.magic.services.tools.UITools;
import org.ocpsoft.prettytime.PrettyTime;
Expand Down Expand Up @@ -50,6 +55,28 @@ public JsonMessagePanel(AbstractMessage value) {


var separator = new JPanel();

if(value.getTypeMessage()==MSG_TYPE.SEARCH)
{
var item = ((SearchMessage)value).getItem();
BufferedImage bi;
try {
bi = URLTools.extractAsImage(item.getUrl());
bi=ImageTools.scaleResize(bi, iconSize*2);
var lab = new JLabel(new ImageIcon(bi));

separator.add(lab);

} catch (IOException e) {
//do nothing
}




}


separator.setBackground(value.getColor());

GridBagConstraints gbcseparator = new GridBagConstraints();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.magic.api.beans.abstracts.AbstractMessage;
import org.magic.gui.components.renderer.JsonMessagePanel;

public class JsonMessageRenderer implements ListCellRenderer<AbstractMessage> {
public class MessageRenderer implements ListCellRenderer<AbstractMessage> {

@Override
public Component getListCellRendererComponent(JList<? extends AbstractMessage> list, AbstractMessage value, int index,boolean isSelected, boolean cellHasFocus) {
Expand Down

0 comments on commit dd6a90c

Please sign in to comment.