Ejemplo n.º 1
0
def makeUI(model):
    # Components:
    table = JTable(model)
    jsp = JScrollPane(table)
    regex_label = JLabel("Search: ")
    regex_field = JTextField(20)
    base_path_label = JLabel("Base path:")
    base_path_field = JTextField(50)
    if base_path is not None:
        base_path_field.setText(base_path)
    # Panel for all components
    all = JPanel()
    all.setBorder(EmptyBorder(20, 20, 20, 20))
    layout, c = GridBagLayout(), GC()
    all.setLayout(layout)
    # First row: label and regex text field
    add(all, regex_label, gridx=0, gridy=0)  # with default constraints
    add(all, regex_field, gridx=1, gridy=0, fill=GC.HORIZONTAL, weightx=1.0)
    # Second row: the table
    add(all,
        jsp,
        gridx=0,
        gridy=1,
        fill=GC.BOTH,
        gridwidth=2,
        weightx=1.0,
        weighty=1.0)  # full weights so it stretches when resizing
    # Third row: the base path
    add(all, base_path_label, gridx=0, gridy=2)
    add(all,
        base_path_field,
        gridx=1,
        gridy=2,
        fill=GC.HORIZONTAL,
        weightx=1.0)
    # Window frame
    frame = JFrame("File paths")
    frame.getContentPane().add(all)
    #frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
    frame.addWindowListener(Closing())
    frame.pack()
    frame.setVisible(True)
    # Listeners
    regex_field.addKeyListener(EnterListener(table))
    table.addMouseListener(RowClickListener(base_path_field))
    al = ArrowListener(table, regex_field)
    table.addKeyListener(al)
    regex_field.addKeyListener(al)
    # Instead of a KeyListener, use the input vs action map
    table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
                            "enter")
    table.getActionMap().put("enter", OpenImageFromTableCell())
    #
    return model, table, regex_field, frame
Ejemplo n.º 2
0
 def data(self):
     table = JTable()  # use an empty (default) table
     iMap = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
     # List of mapped keystrokes & actions
     keystrokes = [(key, iMap.get(key))
                   for key in table.getRegisteredKeyStrokes()]
     #------------------------------------------------------
     # Dict of key names & modified keystrokes
     #------------------------------------------------------
     keys = {}  # Dict, index = key name  -> modifiers
     acts = {}  # Dict, index = keyStroke -> actionName
     for key, act in keystrokes:
         val = str(key)  # e.g., shift ctrl pressed TAB
         acts[val] = act  # e.g., selectNextColumnCell
         pos = val.rfind(' ')
         prefix, name = val[:pos], val[pos + 1:]
         if keys.has_key(name):
             keys[name].append(prefix)
         else:
             keys[name] = [prefix]
     #------------------------------------------------------
     # The list of unique key names, in alphabetical order
     #------------------------------------------------------
     names = keys.keys()
     names.sort()
     prefixes = [
         'pressed',  # unmodified keystroke
         'ctrl pressed',  # Ctrl-<keystroke>
         'shift pressed',  # Shift-<keystroke>
         'shift ctrl pressed'  # Shift-Ctrl-<keystroke>
     ]
     #------------------------------------------------------
     # For each key name (in alphabetical order)
     #------------------------------------------------------
     result = []  # The 2D table of strings
     for name in names:  # For each key name (e.g., TAB)
         here = [name]  # Current table row
         #
         # columns are in a fixed order, based upon prefix
         #
         for prefix in prefixes:
             kName = ' '.join([prefix, name])
             here.append(acts.get(kName, ''))
         result.append(here)
     return result
Ejemplo n.º 3
0
#    From: Swing for Jython
#      By: Robert A. (Bob) Gibson [rag]
# ISBN-13: 978-1-4824-0818-2 (paperback)
# ISBN-13: 978-1-4824-0817-5 (electronic)
# website: http://www.apress.com/978148420818
#    Role: Sample Jython script showing JTable 'SPACE' KeyStrokes & the name of
#          each associated action.
#    Note: This is a "Swing" script only because it imports javax.swing JTable
#   Usage: wsadmin -f KeyStrokes2.py
#            or
#          jython KeyStrokes2.py
# History:
#   date    who  ver   Comment
# --------  ---  ---  ----------
# 14/10/27  rag  0.0  New - ...
#-------------------------------------------------------------------------------
from javax.swing import JTable

table = JTable()
keys = [key for key in table.getRegisteredKeyStrokes()]
print 'Number of JTable KeyStrokes:', len(keys)

width = max([len(str(key)) for key in keys])

print 'JTable "Space" Keys:'
for key in keys:
    if str(key).endswith('SPACE'):
        cond = table.getConditionForKeyStroke(key)
        act = table.getInputMap(cond).get(key)
        print '%*s : %s' % (width, str(key), act)