gvsig-scripting / org.gvsig.scripting.app / trunk / org.gvsig.scripting.app / org.gvsig.scripting.app.extension / src / main / resources / scripting / lib / console / tip.py @ 423
History | View | Annotate | Download (1.63 KB)
1 | 359 | jjdelcerro | from java.awt import Color, Dimension |
---|---|---|---|
2 | from javax.swing import JWindow, JTextArea, JScrollPane |
||
3 | |||
4 | __author__ = "Don Coleman <dcoleman@chariotsolutions.com>"
|
||
5 | __cvsid__ = "$Id: tip.py 5782 2006-06-12 07:56:49Z jmvivo $"
|
||
6 | |||
7 | class Tip(JWindow): |
||
8 | """
|
||
9 | Window which provides the user with information about the method
|
||
10 | For Python, this shows arguments, and the documention
|
||
11 | For Java, this shows the signature(s) and return type
|
||
12 | """
|
||
13 | # TODO handle java methods with many overload more gracefully
|
||
14 | MAX_HEIGHT = 300
|
||
15 | MAX_WIDTH = 400
|
||
16 | |||
17 | def __init__(self, frame): |
||
18 | JWindow.__init__(self, frame)
|
||
19 | #self.size = (300,150)
|
||
20 | self.textarea = JTextArea()
|
||
21 | # TODO put this color with all the other colors
|
||
22 | self.textarea.setBackground(Color(225,255,255)) |
||
23 | self.textarea.setEditable(0) |
||
24 | self.jscrollpane = JScrollPane(self.textarea) |
||
25 | self.getContentPane().add(self.jscrollpane) |
||
26 | |||
27 | def setText(self, tip): |
||
28 | self.textarea.setText(tip)
|
||
29 | self.textarea.setCaretPosition(0) |
||
30 | #print >> sys.stderr, self.textarea.getPreferredScrollableViewportSize()
|
||
31 | self.setSize(self.getPreferredSize()) |
||
32 | |||
33 | def getPreferredSize(self): |
||
34 | # need to add a magic amount to the size to avoid scrollbars
|
||
35 | # I'm sure there's a better way to do this
|
||
36 | MAGIC = 20
|
||
37 | size = self.textarea.getPreferredScrollableViewportSize()
|
||
38 | height = size.height + MAGIC |
||
39 | width = size.width + MAGIC |
||
40 | if height > Tip.MAX_HEIGHT:
|
||
41 | height = Tip.MAX_HEIGHT |
||
42 | if width > Tip.MAX_WIDTH:
|
||
43 | width = Tip.MAX_WIDTH |
||
44 | return Dimension(width, height)
|