class FileView: """ SplitPane containing an editoresque (Sublime-alike) filetree+editor widget """ def __init__(self, dir=None, filetree_label=None, texteditor_factory=None): if not dir: dir = os.getcwd() self._filetree = FileTree(dir=dir, label=filetree_label) self._payloadview = PayloadView(texteditor_factory=texteditor_factory) self.this = JSplitPane(JSplitPane.HORIZONTAL_SPLIT, self._filetree.this, self._payloadview.this) self.this.setOneTouchExpandable(True) self._filetree.add_tree_selection_listener(self._tree_listener) self.this.getRightComponent().setVisible(False) def _tree_listener(self, e): """ Listen for tree selection and fill the payloadview :param e: unused :return: None """ try: fpath = os.path.join(*[str(p) for p in e.getPath().getPath()][1:]) if fpath.endswith('.html'): self.this.getRightComponent().setVisible(False) return with open(fpath, 'r') as f: payload = f.read() self._payloadview.set_editable(True) self._payloadview.refresh(payload) self.this.getRightComponent().setVisible(True) self.this.setDividerLocation(0.25) except IOError: pass def addTreeListener(self, action): """ Add a new Tree ActionListener :param action: actionListener lambda :return: """ self._filetree.add_tree_selection_listener(action) def addPayloadListener(self, action): """ Add a new PayloadView Listener :param action: actionListener lambda :return: """ self._payloadview.add_listener(action) def refresh(self): self._filetree.refresh()
class javadocInfo_10( java.lang.Runnable ) : #--------------------------------------------------------------------------- # Name: __init__() # Role: Constructor - initialize application variables #--------------------------------------------------------------------------- def __init__( self ) : self.prevText = None # Previously specified user input (text) #--------------------------------------------------------------------------- # Name: run() # Role: Instantiate the user class # Note: Invoked by the Swing Event Dispatch Thread #--------------------------------------------------------------------------- def run( self ) : #----------------------------------------------------------------------- # Size the frame to use 1/2 of the screen #----------------------------------------------------------------------- screenSize = Toolkit.getDefaultToolkit().getScreenSize() frameSize = Dimension( screenSize.width >> 1, screenSize.height >> 1 ) frame = JFrame( 'javadocInfo_10', size = frameSize, defaultCloseOperation = JFrame.EXIT_ON_CLOSE ) #----------------------------------------------------------------------- # Reposition the frame to be in the center of the screen #----------------------------------------------------------------------- frame.setLocation( ( screenSize.width - frameSize.width ) >> 1, ( screenSize.height - frameSize.height ) >> 1 ) #----------------------------------------------------------------------- # Initialize the list to have exactly 1 element #----------------------------------------------------------------------- model = DefaultListModel() model.addElement( 'One moment please...' ) self.List = JList( model, valueChanged = self.pick, selectionMode = ListSelectionModel.SINGLE_SELECTION ) #----------------------------------------------------------------------- # Put the List in a ScrollPane and place it in the middle of a pane #----------------------------------------------------------------------- pane = JPanel( layout = BorderLayout() ) pane.add( JScrollPane( self.List, minimumSize = ( 300, 50 ) ), BorderLayout.CENTER ) #----------------------------------------------------------------------- # Add a TextField [for the URL of the selected entry] at the bottom #----------------------------------------------------------------------- self.text = JTextField( 'Enter text...', caretUpdate = self.caretUpdate ) pane.add( self.text, BorderLayout.SOUTH ) #----------------------------------------------------------------------- # Add the pane and a scrollable TextArea to a SplitPane in the frame #----------------------------------------------------------------------- self.area = JEditorPane( 'text/html', '<html><h3>Nothing selected</h3></html>', editable = 0 ) self.splitPane = JSplitPane( JSplitPane.HORIZONTAL_SPLIT, pane, self.area ) self.splitPane.setDividerLocation( 234 ) frame.add( self.splitPane ) #----------------------------------------------------------------------- # Create a separate thread to locate & proces the remote URL #----------------------------------------------------------------------- self.Links = {} # Initialize the Links dictionary self.classes = None # complete list of all classes found soupTask( self.List, # The visible JList instance self.text, # User input field JAVADOC_URL, # Remote web page URL to be processed self.Links, # Dictionary of links found ).execute() frame.setVisible( 1 ) #--------------------------------------------------------------------------- # Name: pick() # Role: ListSelectionListener event handler #--------------------------------------------------------------------------- def pick( self, e ) : #----------------------------------------------------------------------- # Note: Ignore valueIsAdjusting events #----------------------------------------------------------------------- if not e.getValueIsAdjusting() : List = self.List model = List.getModel() #--------------------------------------------------------------- # Is a "valid" item selected? #--------------------------------------------------------------- index = List.getSelectedIndex() if index > -1 : choice = model.elementAt( index ) if self.Links.has_key( choice ) : url = self.Links[ choice ] headerTask( url, self.splitPane ).execute() else : message = 'Nothing selected' comp = self.splitPane.getRightComponent() Type = str( comp.getClass() ).split( '.' )[ -1 ] if Type == 'JEditorPane' : comp.setText( '<html><h3>%s</h3></html>' % message ) else : area = JEditorPane( 'text/html', '<html><h3>%s</h3></html>' % message, editable = 0 ) self.splitPane.setRightComponent( area ) #--------------------------------------------------------------------------- # Name: caretUpdate() # Role: CaretListener event handler used to monitor JTextField for user input #--------------------------------------------------------------------------- def caretUpdate( self, e ) : field = e.getSource() text = field.getText() if self.prevText == None : self.prevText = text if self.classes == None : result = self.Links.keys() if len( result ) > 0 : result.sort() self.classes = result #----------------------------------------------------------------------- # Did the user just move the cursor, or did they change the text field? #----------------------------------------------------------------------- if text != self.prevText : # print 'dot: %2d text: "%s"' % ( e.getDot(), text ) model = DefaultListModel() items = [ item for item in self.classes if item.find( text ) > -1 ] if len( items ) > 0 : for item in items : model.addElement( item ) else : model.addElement( 'No matching classes found.' ) self.List.setModel( model ) self.prevText = text