Ignore:
Timestamp:
2013-05-09T21:00:19+02:00 (11 years ago)
Author:
zverik
Message:

[josm_geochat] autocomplete works, notification was redone slightly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/geochat/src/geochat/ChatPaneManager.java

    r29568 r29571  
    77import javax.swing.event.ChangeEvent;
    88import javax.swing.event.ChangeListener;
    9 import javax.swing.text.BadLocationException;
    10 import javax.swing.text.DefaultCaret;
    11 import javax.swing.text.Document;
     9import javax.swing.text.*;
    1210import static org.openstreetmap.josm.tools.I18n.tr;
    1311
     
    5351        int alarm = 0;
    5452        for( ChatPane entry : chatPanes.values() ) {
    55             if( entry.notify ) {
    56                 if( entry.isPublic && alarm < 1 )
    57                     alarm = 1;
    58                 else if( !entry.isPublic )
    59                     alarm = 2;
    60             }
     53            if( entry.notify > alarm )
     54                alarm = entry.notify;
    6155        }
    6256        return alarm;
     
    6862    }
    6963
    70     public void notify( String user, boolean really ) {
    71 //        if( user == null && !really && !collapsed )
    72 //            return;
    73         if( !hasUser(user) )
     64    public void notify( String user, int alarmLevel ) {
     65        if( alarmLevel <= 0 || !hasUser(user) )
    7466            return;
    7567        ChatPane entry = chatPanes.get(user == null ? PUBLIC_PANE : user);
    76         System.out.println("Notifying " + user);
    77         entry.notify = true;
     68        entry.notify = alarmLevel;
    7869        int idx = tabs.indexOfComponent(entry.component);
    7970        if( idx >= 0 )
     
    8273
    8374    public void addLineToChatPane( String userName, String line ) {
     75        if( line.length() == 0 )
     76            return;
    8477        if( !chatPanes.containsKey(userName) )
    8578            createChatPane(userName);
     
    9891    }
    9992
     93    /**
     94     * Special case: the line contains username, so it must be highlighted.
     95     */
     96    public void addLineToPublicEm( String line ) {
     97        if( !line.startsWith("\n") )
     98            line = "\n" + line;
     99        Document doc = chatPanes.get(PUBLIC_PANE).pane.getDocument();
     100        try {
     101            SimpleAttributeSet attrs = new SimpleAttributeSet();
     102            StyleConstants.setItalic(attrs, true);
     103            doc.insertString(doc.getLength(), line, attrs);
     104        } catch( BadLocationException ex ) {
     105            // whatever
     106        }
     107    }
     108
    100109    public void clearPublicChatPane() {
    101110        chatPanes.get(PUBLIC_PANE).pane.setText("");
     
    139148        entry.pane = chatPane;
    140149        entry.component = scrollPane;
    141         entry.notify = false;
     150        entry.notify = 0;
    142151        entry.userName = userName;
    143152        entry.isPublic = userName == null;
     
    207216                boldFont = getFont().deriveFont(Font.BOLD);
    208217            }
    209             System.out.println("clauses: collapsed=" + collapsed + ", tabs:" + tabs.getSelectedIndex() + "=" + tabs.indexOfComponent(entry.component));
    210             if( entry.notify && !collapsed && tabs.getSelectedIndex() == tabs.indexOfComponent(entry.component) )
    211                 entry.notify = false;
    212             setFont(entry.notify ? boldFont : normalFont);
     218            if( entry.notify > 0 && !collapsed && tabs.getSelectedIndex() == tabs.indexOfComponent(entry.component) )
     219                entry.notify = 0;
     220            setFont(entry.notify > 0 ? boldFont : normalFont);
    213221            panel.updateTitleAlarm();
    214222        }
     
    220228        public JTextPane pane;
    221229        public JScrollPane component;
    222         public boolean notify;
     230        public int notify;
    223231
    224232    }
Note: See TracChangeset for help on using the changeset viewer.