示例#1
0
 def __init__(self):
     # The form name will be automatically determined from the class name
     WindowWrapper.__init__(self)
     self.firstField.text = u"Some text"
     self.readOnlyField.text = u"Can't change this"
     self.editorPane.text = u'Sample text'
     addEventListener(self.exitButton, MouseListener, 'mouseClicked',
                      lambda event: self.dispose())
示例#2
0
def testBuiltinListener():
    model = DefaultListModel()
    lst = JList(model)
    model.addElement(u'Test')
    events = []
    addEventListener(lst, ListSelectionListener, 'valueChanged',
                     events.append)

    lst.setSelectionInterval(0, 0)
    assert len(events) == 1
    assert events[0].firstIndex == 0
    assert events[0].lastIndex == 0
示例#3
0
def testListSelectionEventKwargs():
    def selectionListener(event, **kwargs):
        holder[0] = kwargs

    model = DefaultListModel()
    lst = JList(model)
    model.addElement(u'Test')
    holder = [None]
    addEventListener(lst, ListSelectionListener, 'valueChanged',
                     selectionListener, test=2)

    lst.setSelectionInterval(0, 0)
    assert holder[0] == {'test': 2}
示例#4
0
def testListSelectionEventVarargs():
    def selectionListener(*args):
        _event, holder[0] = args

    model = DefaultListModel()
    lst = JList(model)
    model.addElement(u'Test')
    holder = [None]
    addEventListener(lst, ListSelectionListener, 'valueChanged',
                     selectionListener, 2)

    lst.setSelectionInterval(0, 0)
    assert holder[0] == 2
示例#5
0
def testListSelectionEvent():
    def selectionListener(event):
        eventHolder[0] = event

    model = DefaultListModel()
    lst = JList(model)
    model.addElement(u'Test')
    eventHolder = [None]
    addEventListener(lst, ListSelectionListener, 'valueChanged',
                     selectionListener)

    lst.setSelectionInterval(0, 0)
    event = eventHolder[0]
    assert event.firstIndex == 0
    assert event.lastIndex == 0
示例#6
0
 def addSelectionListener(self, parent, callback, *args, **kwargs):
     selectionModel = parent.selectionModel
     if selectionModel is not None:
         from javax.swing.event import ListSelectionListener
         self.listeners['selection'] = addEventListener(selectionModel,
             ListSelectionListener, 'valueChanged', self.selectionChanged,
             callback, *args, **kwargs)
示例#7
0
 def setup(self):
     self.model = DelegateListModel([])
     addEventListener(self.model, ListDataListener, 'intervalAdded',
                      self.intervalAdded)
     addEventListener(self.model, ListDataListener, 'intervalRemoved',
                      self.intervalRemoved)
     addEventListener(self.model, ListDataListener, 'contentsChanged',
                      self.contentsChanged)
示例#8
0
 def setup(self):
     self.model = DelegateListModel([])
     addEventListener(self.model, ListDataListener,
                      'intervalAdded', self.intervalAdded)
     addEventListener(self.model, ListDataListener,
                      'intervalRemoved', self.intervalRemoved)
     addEventListener(self.model, ListDataListener,
                      'contentsChanged', self.contentsChanged)
示例#9
0
    def __init__(self, controller):
        '''
        Creates default empty console-looking panel.
        It should be separated from the rest of the GUI so that users can
        choose to show or hide the console. Or should it be a split panel?
        This panel will display log and validation/lemmatization messages.
        It might need its own toolbar for searching, etc.
        It will also accept commands in later stages of development, if need
        be.
        '''
        # Give reference to controller to delegate action response
        self.controller = controller

        # Make text area occupy all available space and resize with parent
        # window
        self.setLayout(BorderLayout())

        # Create console-looking area
        self.edit_area = JEditorPane()

        # Although most of the styling is done using css, we need to set these
        # properties to ensure the html is rendered properly in the console
        self.edit_area.border = BorderFactory.createEmptyBorder(6, 6, 6, 6)
        self.edit_area.setContentType("text/html")

        # Disable writing in the console - required to render hyperlinks
        self.edit_area.setEditable(False)

        # Map CSS color strings to Java Color objects
        self.colors = {'Gray': Color(238, 238, 238),
                       'Black': Color(0, 0, 0),
                       'Yellow': Color(255, 255, 0)}

        # Initial call to refresh console to set the console style properties
        self.refreshConsole()

        # Set up a hyperlink listener
        listener = addEventListener(self.edit_area, HyperlinkListener,
                                    'hyperlinkUpdate', self.handleEvent)

        # Will need scrolling controls
        scrollingText = JScrollPane(self.edit_area)
        scrollingText.setPreferredSize(Dimension(1, 150))

        # Make text area auto scroll down to last printed line
        caret = self.edit_area.getCaret()
        caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE)

        # Add to parent panel
        self.add(scrollingText, BorderLayout.CENTER)
示例#10
0
 def addDocumentListener(self, parent, callback, *args, **kwargs):
     if parent.document is not None:
         from javax.swing.event import DocumentListener
         events = (u'changedUpdate', u'insertUpdate', u'removeUpdate')
         self.listeners['document'] = addEventListener(parent.document,
             DocumentListener, events, callback, *args, **kwargs)
示例#11
0
 def addFocusListener(self, parent, callback, *args, **kwargs):
     from java.awt.event import FocusListener
     self.listeners['focus'] = addEventListener(parent, FocusListener,
         'focusLost', callback, *args, **kwargs)
示例#12
0
 def addListeners(self, parent, callback, *args, **kwargs):
     from java.awt.event import ItemListener
     self.listeners['item'] = addEventListener(parent, ItemListener,
         'itemStateChanged', callback, *args, **kwargs)
示例#13
0
 def addListeners(self, parent, callback, *args, **kwargs):
     from javax.swing.event import TableModelListener
     self.listeners['table'] = addEventListener(parent,
         TableModelListener, 'tableChanged', callback, *args, **kwargs)
示例#14
0
 def addListeners(self, parent, callback, *args, **kwargs):
     from javax.swing.event import ListDataListener
     events = ('contentsChanged', 'intervalAdded', 'intervalRemoved')
     self.listeners['list'] = addEventListener(parent, ListDataListener,
         events, callback, *args, **kwargs)
示例#15
0
 def addListeners(self, parent, callback, *args, **kwargs):
     from javax.swing.event import ChangeListener
     self.listeners['state'] = addEventListener(parent, ChangeListener,
         'stateChanged', callback, *args, **kwargs)
示例#16
0
    def build_welcome_panel(self):
        '''
        Construct the welcome panel here.
        '''
        panel = JPanel(GridBagLayout())
        constraints = GridBagConstraints()
        constraints.insets = Insets(10, 10, 10, 10)

        message = ('<html><body>'
                   '<h1>Welcome to Nammu</h1>'
                   '<h2>An editor for the ORACC project<h2>'
                   '<p>'
                   '<a href=\'oracc\'>Click here</a> for help with ORACC.'
                   '</p>'
                   '<p>Learn more about Nammu <a href=\'nammu\'>here</a>.</p>'
                   '</body></html>')

        # Configure a JEditorPane to display HTML for our welcome message
        msg_pane = JEditorPane()
        msg_pane.setEditable(False)
        kit = HTMLEditorKit()
        msg_pane.setEditorKit(kit)
        scrollPane = JScrollPane(msg_pane)

        # This handles the stylesheet applied to the welcome message
        styleSheet = kit.getStyleSheet()
        styleSheet.addRule('body {color:black; font-size: 16 pt; }')
        styleSheet.addRule('h1 {text-align:center; }')
        styleSheet.addRule('h2 {text-align:center; }')

        # Set the JEditorPane background to match the rest of the window
        msg_pane.border = BorderFactory.createEmptyBorder(4, 4, 4, 4)
        msg_pane.background = Color(238, 238, 238)

        # Add the message and the css and to the JEditorPane
        doc = kit.createDefaultDocument()
        msg_pane.setDocument(doc)
        msg_pane.setText(message)

        # Set up a hyperlink listener
        listener = addEventListener(msg_pane, HyperlinkListener,
                                    'hyperlinkUpdate', self.handleEvent)

        # Configure the placement of the JEditorPane
        constraints.gridx = 1
        constraints.gridy = 1
        constraints.fill = GridBagConstraints.BOTH
        constraints.anchor = GridBagConstraints.CENTER

        panel.add(msg_pane, constraints)

        # Build and place the checkbox
        self.checkbox = JCheckBox('Don\'t show this message again.',
                                  selected=False)
        constraints.gridx = 1
        constraints.gridy = 2
        panel.add(self.checkbox, constraints)

        # Build and place the close button
        close_button = JButton('Close', actionPerformed=self.close_action)

        constraints.gridx = 2
        constraints.gridy = 2
        panel.add(close_button, constraints)

        return panel