Skip to content

Commit

Permalink
copy dialog as a workaround for missing text selection in chat callou…
Browse files Browse the repository at this point in the history
…ts. issue #2395
  • Loading branch information
j-dimension committed Sep 24, 2024
1 parent 3a866f7 commit d2eded3
Show file tree
Hide file tree
Showing 7 changed files with 923 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ You should also get your employer (if you work as a programmer) or school,
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.UIManager;
import org.apache.log4j.Logger;
import themes.colors.DefaultColorTheme;
Expand All @@ -690,30 +691,36 @@ public class AiCalloutComponent extends javax.swing.JPanel {

private static final Logger log = Logger.getLogger(AiCalloutComponent.class.getName());
private static final ImageIcon ICON_COPY=new javax.swing.ImageIcon(AiCalloutComponent.class.getResource("/icons16/material/baseline_content_copy_lightgrey_48dp.png"));
private static final ImageIcon ICON_SELECT=new javax.swing.ImageIcon(AiCalloutComponent.class.getResource("/icons16/material/select_all_20dp_FFFFFF.png"));

private JDialog owner=null;

private int deleteX=1000;
private int copyX=1000;
private int copyY=10;
private int markReadX=1000;
private int markReadY=10;
private Font defaultFont = null;
private Font defaultFontBold = null;
private Font miniFont = null;

protected Message message = null;
protected boolean ownMessage = false;
protected String ownPrincipal = null;

private String tooltipText="";

/**
* Creates new form AiCalloutComponent
*/
public AiCalloutComponent() {
this("admin", new Message(), true);
this(null, new Message(), true);
}

public AiCalloutComponent(String ownPrincipal, Message m, boolean ownMessage) {
public AiCalloutComponent(JDialog ownerDialog, Message m, boolean ownMessage) {
initComponents();

this.owner=ownerDialog;

this.defaultFont = UIManager.getFont("defaultFont");
if (this.defaultFont == null) {
this.defaultFont = new Font("Arial", Font.PLAIN, 12);
Expand All @@ -726,9 +733,8 @@ public AiCalloutComponent(String ownPrincipal, Message m, boolean ownMessage) {
miniFont = new Font("Arial", Font.PLAIN, 8);
}

this.ownPrincipal = ownPrincipal;
this.ownMessage = ownMessage;
this.setMessage(m);
this.setMessage(m, this.owner);

this.setPreferredSize(new Dimension(250, 70)); // Adjust size as needed´

Expand All @@ -740,6 +746,14 @@ public void mouseClicked(MouseEvent e) {
&& e.getY() >= (copyY) && e.getY() <= copyY + 20) {
copyMessageToClipboard();
}
if (e.getX() >= (markReadX) && e.getX() <= markReadX + 20
&& e.getY() >= (markReadY) && e.getY() <= markReadY + 20) {
if(owner!=null) {
AiChatMessageTextSelection selDlg=new AiChatMessageTextSelection(owner, true, message.getContent());
selDlg.setLocation(e.getLocationOnScreen());
selDlg.setVisible(true);
}
}
}

});
Expand All @@ -751,7 +765,13 @@ public void mouseMoved(MouseEvent e) {
if (e.getX() >= (copyX) && e.getX() <= copyX + 20
&& e.getY() >= (copyY) && e.getY() <= copyY + 20) {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
setToolTipText("Text kopieren");
setToolTipText("gesamten Text in die Zwischenablage kopieren");
return;
}
if (e.getX() >= (markReadX) && e.getX() <= markReadX + 20
&& e.getY() >= (markReadY) && e.getY() <= markReadY + 20) {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
setToolTipText("Text auswählen und in die Zwischenablage kopieren");
return;
}
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
Expand Down Expand Up @@ -834,6 +854,9 @@ protected void paintComponent(Graphics g) {
this.copyX=this.deleteX-20;
ICON_COPY.paintIcon(this, g2d, this.copyX, this.copyY);

this.markReadX = this.copyX - 25;
ICON_SELECT.paintIcon(this, g2d, this.markReadX, this.markReadY);

this.setPreferredSize(new Dimension(width, yOffset + lineSpacing));

}
Expand Down Expand Up @@ -924,9 +947,11 @@ public Message getMessage() {

/**
* @param message the message to set
* @param owner
*/
public void setMessage(Message message) {
public void setMessage(Message message, JDialog owner) {
this.message = message;
this.owner=owner;
}

/**
Expand All @@ -943,22 +968,6 @@ public void setOwnMessage(boolean ownMessage) {
this.ownMessage = ownMessage;
}

/**
* @return the ownPrincipal
*/
public String getOwnPrincipal() {
return ownPrincipal;
}

/**
* @param ownPrincipal the ownPrincipal to set
*/
public void setOwnPrincipal(String ownPrincipal) {
this.ownPrincipal = ownPrincipal;

// need to retrigger calculation of the READ member
this.setMessage(this.message);
}


// Variables declaration - do not modify//GEN-BEGIN:variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ You should also get your employer (if you work as a programmer) or school,
import com.jdimension.jlawyer.client.settings.UserSettings;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JDialog;
import javax.swing.UIManager;
import org.apache.log4j.Logger;
import themes.colors.DefaultColorTheme;
Expand All @@ -679,6 +680,7 @@ public class AiChatMessagePanel extends javax.swing.JPanel {

private static final Logger log = Logger.getLogger(AiChatMessagePanel.class.getName());

private JDialog owner=null;
private Message msg = null;

protected int maxDocumentChars = Integer.MAX_VALUE;
Expand All @@ -689,12 +691,13 @@ public class AiChatMessagePanel extends javax.swing.JPanel {
public AiChatMessagePanel() {
initComponents();

this.aiCalloutComponent1.setMessage(new Message());
this.aiCalloutComponent1.setMessage(new Message(), null);
}

public AiChatMessagePanel(Message aiMessage) {
public AiChatMessagePanel(Message aiMessage, JDialog owner) {
initComponents();

this.owner=owner;
this.msg = aiMessage;

this.lblUser.setForeground(Color.WHITE);
Expand All @@ -715,14 +718,14 @@ public AiChatMessagePanel(Message aiMessage) {
this.lblUser.setBackground(DefaultColorTheme.COLOR_DARK_GREY);
}

this.aiCalloutComponent1.setMessage(aiMessage);
this.aiCalloutComponent1.setMessage(aiMessage, owner);
this.aiCalloutComponent1.setOwnMessage(ownMessage);

}

public void setMessage(Message m) {
public void setMessage(Message m, JDialog owner) {
this.msg=m;
this.aiCalloutComponent1.setMessage(msg);
this.aiCalloutComponent1.setMessage(msg, owner);
}

public Message getMessage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="title" type="java.lang.String" value="Textauswahl kopieren"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="0" pref="700" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="cmdCopy" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jScrollPane1" pref="517" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cmdCopy" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>

<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextArea" name="taText">
<Properties>
<Property name="columns" type="int" value="20"/>
<Property name="rows" type="int" value="5"/>
</Properties>
<Events>
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="taTextMouseReleased"/>
</Events>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="cmdCopy">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons16/editpaste.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Kopieren"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmdCopyActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
Loading

0 comments on commit d2eded3

Please sign in to comment.