예제 #1
0
    def __init__(self, imgData):
        n = imgData.size()
        win = JFrame("Point Marker Panel")
        win.setPreferredSize(Dimension(350, 590))
        win.setSize(win.getPreferredSize())
        pan = JPanel()
        pan.setLayout(BoxLayout(pan, BoxLayout.Y_AXIS))
        win.getContentPane().add(pan)

        progressPanel = JPanel()
        progressPanel.setLayout(BoxLayout(progressPanel, BoxLayout.Y_AXIS))
        positionBar = JProgressBar()
        positionBar.setMinimum(0)
        positionBar.setMaximum(n)
        positionBar.setStringPainted(True)
        progressPanel.add(Box.createGlue())
        progressPanel.add(positionBar)

        progressBar = JProgressBar()
        progressBar.setMinimum(0)
        progressBar.setMaximum(n)
        progressBar.setStringPainted(True)
        progressPanel.add(progressBar)
        progressPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10))
        pan.add(progressPanel)

        pan.add(Box.createRigidArea(Dimension(5, 5)))
        savePanel = JPanel()
        savePanel.setLayout(BoxLayout(savePanel, BoxLayout.Y_AXIS))
        saveMessageLabel = JLabel("<html><u>Save Often</u></html>")
        savePanel.add(saveMessageLabel)
        savePanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        savePanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10))
        pan.add(savePanel)
        # pan.add(saveMessageLabel)

        pan.add(Box.createRigidArea(Dimension(5, 5)))
        calPanel = JPanel()
        calPanel.setLayout(BoxLayout(calPanel, BoxLayout.Y_AXIS))
        calPanelIn = JPanel()
        calPanelIn.setLayout(BoxLayout(calPanelIn, BoxLayout.X_AXIS))
        pixelSizeText = JTextField(12)
        pixelSizeText.setHorizontalAlignment(JTextField.RIGHT)
        # pixelSizeText.setMaximumSize(pixelSizeText.getPreferredSize())
        unitText = JTextField(10)
        # unitText.setMaximumSize(unitText.getPreferredSize())
        pixelSizeText.setText("Enter Pixel Size Here")
        calPanelIn.add(pixelSizeText)
        unitText.setText("Unit")
        calPanelIn.add(unitText)
        calPanelIn.setAlignmentX(Component.CENTER_ALIGNMENT)
        calPanelIn.setBorder(
            BorderFactory.createTitledBorder("Custom Calibration"))
        calPanel.add(calPanelIn)
        calPanelIn.setAlignmentX(Component.CENTER_ALIGNMENT)
        calPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10))
        pan.add(calPanel)

        pan.add(Box.createRigidArea(Dimension(5, 5)))
        helpPanel = JPanel()
        helpPanel.setLayout(BoxLayout(helpPanel, BoxLayout.Y_AXIS))
        helpLable = JLabel("<html><ul>\
                            <li>Focus on Image Window</li>\
                            <li>Select multi-point Tool</li>\
                            <li>Click to Draw Points</li>\
                            <li>Drag to Move Points</li>\
                            <li>\"Alt\" + Click to Erase Points</li>\
                            <li>Optional: Customize Calibration Above\
                                 and Refresh Images\
                                (won't be written to files)</li>\
                            </html>")
        helpLable.setBorder(BorderFactory.createTitledBorder("Usage"))
        keyTagOpen = "<span style=\"background-color: #FFFFFF\"><b><kbd>"
        keyTagClose = "</kbd></b></span>"
        keyLable = JLabel("<html><ul>\
                            <li>Next Image --- "                                                 + keyTagOpen + "&lt" + \
                                keyTagClose + "</li>\
                            <li>Previous Image --- "                                                     + keyTagOpen + ">" + \
                                keyTagClose + "</li>\
                            <li>Save --- "                                           + keyTagOpen + "`" + keyTagClose + \
                                " (upper-left to TAB key)</li>\
                            <li>Next Unmarked Image --- "                                                          + keyTagOpen + \
                                "TAB" + keyTagClose + "</li></ul>\
                            </html>"                                    )
        keyLable.setBorder(
            BorderFactory.createTitledBorder("Keyboard Shortcuts"))
        helpPanel.add(helpLable)
        helpPanel.add(keyLable)
        helpPanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        helpPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10))
        pan.add(helpPanel)

        # pan.add(Box.createRigidArea(Dimension(0, 10)))
        infoPanel = JPanel()
        infoPanel.setLayout(BoxLayout(infoPanel, BoxLayout.Y_AXIS))
        infoLabel = JLabel()
        infoLabel.setBorder(BorderFactory.createTitledBorder("Project Info"))
        infoPanel.add(infoLabel)
        infoPanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        infoPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10))
        pan.add(infoPanel)

        win.setVisible(True)

        self.imgData = imgData
        self.win = win
        # self.progressPanel = progressPanel
        self.positionBar = positionBar
        self.progressBar = progressBar
        self.saveMessageLabel = saveMessageLabel
        self.infoLabel = infoLabel
        self.pixelSizeText = pixelSizeText
        self.unitText = unitText
        self.update()
    def __init__(self, imgData):
        n = imgData.size()
        win = JFrame("Point Marker Panel")
        win.setPreferredSize(Dimension(350, 590))
        win.setSize(win.getPreferredSize())
        pan = JPanel()
        pan.setLayout(BoxLayout(pan, BoxLayout.Y_AXIS))
        win.getContentPane().add(pan)

        progressPanel = JPanel()
        progressPanel.setLayout(BoxLayout(progressPanel, BoxLayout.Y_AXIS))
        positionBar = JProgressBar()
        positionBar.setMinimum(0)
        positionBar.setMaximum(n)
        positionBar.setStringPainted(True)
        progressPanel.add(Box.createGlue())
        progressPanel.add(positionBar)

        progressBar = JProgressBar()
        progressBar.setMinimum(0)
        progressBar.setMaximum(n)
        progressBar.setStringPainted(True)
        progressPanel.add(progressBar)
        progressPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
        pan.add(progressPanel)

        pan.add(Box.createRigidArea(Dimension(5,5)))
        savePanel = JPanel()
        savePanel.setLayout(BoxLayout(savePanel, BoxLayout.Y_AXIS))
        saveMessageLabel = JLabel("<html><u>Save Often</u></html>")
        savePanel.add(saveMessageLabel)
        savePanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        savePanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
        pan.add(savePanel)
        # pan.add(saveMessageLabel)

        pan.add(Box.createRigidArea(Dimension(5,5)))
        calPanel = JPanel()
        calPanel.setLayout(BoxLayout(calPanel, BoxLayout.Y_AXIS))
        calPanelIn = JPanel()
        calPanelIn.setLayout(BoxLayout(calPanelIn, BoxLayout.X_AXIS))
        pixelSizeText = JTextField(12)
        pixelSizeText.setHorizontalAlignment(JTextField.RIGHT)
        # pixelSizeText.setMaximumSize(pixelSizeText.getPreferredSize())
        unitText = JTextField(10)
        # unitText.setMaximumSize(unitText.getPreferredSize())
        pixelSizeText.setText("Enter Pixel Size Here")
        calPanelIn.add(pixelSizeText)
        unitText.setText("Unit")
        calPanelIn.add(unitText)
        calPanelIn.setAlignmentX(Component.CENTER_ALIGNMENT)
        calPanelIn.setBorder(BorderFactory.createTitledBorder("Custom Calibration"))
        calPanel.add(calPanelIn)
        calPanelIn.setAlignmentX(Component.CENTER_ALIGNMENT)
        calPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
        pan.add(calPanel)

        pan.add(Box.createRigidArea(Dimension(5,5)))
        helpPanel = JPanel()
        helpPanel.setLayout(BoxLayout(helpPanel, BoxLayout.Y_AXIS))
        helpLable = JLabel("<html><ul>\
                            <li>Focus on Image Window</li>\
                            <li>Select multi-point Tool</li>\
                            <li>Click to Draw Points</li>\
                            <li>Drag to Move Points</li>\
                            <li>\"Alt\" + Click to Erase Points</li>\
                            <li>Optional: Customize Calibration Above\
                                 and Refresh Images\
                                (won't be written to files)</li>\
                            </html>")
        helpLable.setBorder(BorderFactory.createTitledBorder("Usage"))
        keyTagOpen = "<span style=\"background-color: #FFFFFF\"><b><kbd>"
        keyTagClose = "</kbd></b></span>"
        keyLable = JLabel("<html><ul>\
                            <li>Next Image --- " + keyTagOpen + "&lt" + \
                                keyTagClose + "</li>\
                            <li>Previous Image --- " + keyTagOpen + ">" + \
                                keyTagClose + "</li>\
                            <li>Save --- " + keyTagOpen + "`" + keyTagClose + \
                                " (upper-left to TAB key)</li>\
                            <li>Next Unmarked Image --- " + keyTagOpen + \
                                "TAB" + keyTagClose + "</li></ul>\
                            </html>")
        keyLable.setBorder(BorderFactory.createTitledBorder("Keyboard Shortcuts"))
        helpPanel.add(helpLable)
        helpPanel.add(keyLable)
        helpPanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        helpPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
        pan.add(helpPanel)

        # pan.add(Box.createRigidArea(Dimension(0, 10)))
        infoPanel = JPanel()
        infoPanel.setLayout(BoxLayout(infoPanel, BoxLayout.Y_AXIS))
        infoLabel = JLabel()
        infoLabel.setBorder(BorderFactory.createTitledBorder("Project Info"))
        infoPanel.add(infoLabel)
        infoPanel.setAlignmentX(Component.CENTER_ALIGNMENT)
        infoPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10))
        pan.add(infoPanel)

        win.setVisible(True)

        self.imgData = imgData
        self.win = win
        # self.progressPanel = progressPanel
        self.positionBar = positionBar
        self.progressBar = progressBar
        self.saveMessageLabel = saveMessageLabel
        self.infoLabel = infoLabel
        self.pixelSizeText = pixelSizeText
        self.unitText = unitText
        self.update()
예제 #3
0
class JTabPanel(JSplitPane, ActionListener, FocusListener):
    def __init__(self, ui):
        JSplitPane.__init__(self, JSplitPane.HORIZONTAL_SPLIT)
        self._ui = ui

        # create the executor object
        self._executor = Executor(self, ui.callbacks)

        ####
        # start Left Top split layout
        jLeftTopPanel = JPanel()
        jMenuPanel = JPanel()

        #Load button
        self.jLoad = JButton(Strings.jLoad_text)
        self.jLoad.addActionListener(self)
        #File name text field
        self.jFileName = JTextField(Strings.jFileName_default, 30)
        self.jFileName.setHorizontalAlignment(JTextField.CENTER)
        self.jFileName.setEditable(False)
        #Save button
        self.jSave = JButton(Strings.jSave_text)
        self.jSave.addActionListener(self)
        #Exit button
        self.jExit = JButton(Strings.jExit_text)
        self.jExit.addActionListener(self)
        #Wiki button (URL)
        self.jWiki = JButton(Strings.jWiki_title)
        self.jWiki.setToolTipText(Strings.jWiki_tooltip)
        self.jWiki.addActionListener(self)
        # make it borderless
        self.jWiki.setBorder(EmptyBorder(0, 0, 0, 0))
        self.jWiki.setBorderPainted(False)
        self.jWiki.setContentAreaFilled(False)

        #Console text area
        jConsoleText = JTextArea()
        jConsoleText.setEditable(0)
        jConsoleText.setWrapStyleWord(1)
        jConsoleText.setRows(10)
        #set initial text
        jConsoleText.setText(Strings.jConsoleText_help)
        #make scrollable
        jScrollConsolePane = JScrollPane()
        jScrollConsolePane.setViewportView(jConsoleText)

        jMenuPanelLayout = GroupLayout(jMenuPanel)
        jMenuPanel.setLayout(jMenuPanelLayout)
        jMenuPanelLayout.setHorizontalGroup(
            jMenuPanelLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).
            addGroup(jMenuPanelLayout.createSequentialGroup().addContainerGap(
            ).addComponent(self.jLoad).addComponent(
                self.jFileName).addPreferredGap(
                    LayoutStyle.ComponentPlacement.RELATED).addComponent(
                        self.jSave).addPreferredGap(
                            LayoutStyle.ComponentPlacement.RELATED).
                     addComponent(self.jWiki).addPreferredGap(
                         LayoutStyle.ComponentPlacement.RELATED).addComponent(
                             self.jExit).addContainerGap()))
        jMenuPanelLayout.setVerticalGroup(
            jMenuPanelLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addGroup(
                    jMenuPanelLayout.createSequentialGroup().addGroup(
                        jMenuPanelLayout.createParallelGroup(
                            GroupLayout.Alignment.BASELINE).addComponent(
                                self.jLoad).addComponent(
                                    self.jFileName, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE).addComponent(
                                        self.jSave).addComponent(
                                            self.jWiki).addComponent(
                                                self.jExit))))

        jLeftTopPanelLayout = GroupLayout(jLeftTopPanel)
        jLeftTopPanel.setLayout(jLeftTopPanelLayout)
        jLeftTopPanelLayout.setHorizontalGroup(
            jLeftTopPanelLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addComponent(
                    jMenuPanel, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.DEFAULT_SIZE,
                    GroupLayout.DEFAULT_SIZE).addComponent(
                        jScrollConsolePane, GroupLayout.DEFAULT_SIZE,
                        GroupLayout.DEFAULT_SIZE, 32767))
        jLeftTopPanelLayout.setVerticalGroup(
            jLeftTopPanelLayout.
            createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
                GroupLayout.Alignment.TRAILING,
                jLeftTopPanelLayout.createSequentialGroup().addComponent(
                    jMenuPanel, GroupLayout.PREFERRED_SIZE,
                    GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE).addPreferredGap(
                        LayoutStyle.ComponentPlacement.RELATED).addComponent(
                            jScrollConsolePane, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.DEFAULT_SIZE, 32767)))
        # end Left Top split layout
        ####

        ####
        # start Left Down split layout
        jLeftDownPanel = JPanel()
        jMenu2Panel = JPanel()

        #Clear button
        self.jClear = JButton(Strings.jClear_text)
        self.jClear.setToolTipText(Strings.jClear_tooltip)
        self.jClear.addActionListener(self)

        #Run button
        self.jRun = JButton(Strings.jRun_text)
        self.jRun.setToolTipText(Strings.jRun_tooltip)
        self.jRun.addActionListener(self)

        #Variables text area
        jVarsPane = JTextPane()
        jVarsPane.setFont(Font('Monospaced', Font.PLAIN, 11))
        jVarsPane.addFocusListener(self)
        # set initial value
        jVarsPane.setText(Strings.jVarsPane_header)
        # make scrollable
        jScrollpaneLeftDown = JScrollPane()
        jScrollpaneLeftDown.setViewportView(jVarsPane)

        jMenu2PanelLayout = GroupLayout(jMenu2Panel)
        jMenu2Panel.setLayout(jMenu2PanelLayout)
        jMenu2PanelLayout.setHorizontalGroup(
            jMenu2PanelLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addGroup(
                    jMenu2PanelLayout.createSequentialGroup().addContainerGap(
                    ).addComponent(self.jClear).addPreferredGap(
                        LayoutStyle.ComponentPlacement.RELATED, 100,
                        32767).addComponent(self.jRun).addContainerGap()))
        jMenu2PanelLayout.setVerticalGroup(
            jMenu2PanelLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addGroup(
                    jMenu2PanelLayout.createSequentialGroup().addGroup(
                        jMenu2PanelLayout.createParallelGroup(
                            GroupLayout.Alignment.BASELINE).addComponent(
                                self.jClear).addComponent(self.jRun))))
        jLeftDownPanelLayout = GroupLayout(jLeftDownPanel)
        jLeftDownPanel.setLayout(jLeftDownPanelLayout)
        jLeftDownPanelLayout.setHorizontalGroup(
            jLeftDownPanelLayout.createParallelGroup(
                GroupLayout.Alignment.LEADING).addComponent(
                    jMenu2Panel, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.DEFAULT_SIZE,
                    GroupLayout.DEFAULT_SIZE).addComponent(
                        jScrollpaneLeftDown, GroupLayout.DEFAULT_SIZE,
                        GroupLayout.DEFAULT_SIZE, 32767))
        jLeftDownPanelLayout.setVerticalGroup(
            jLeftDownPanelLayout.
            createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
                GroupLayout.Alignment.TRAILING,
                jLeftDownPanelLayout.createSequentialGroup().addComponent(
                    jMenu2Panel, GroupLayout.PREFERRED_SIZE,
                    GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE).addPreferredGap(
                        LayoutStyle.ComponentPlacement.RELATED).addComponent(
                            jScrollpaneLeftDown, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.DEFAULT_SIZE, 32767)))
        # end Left Down split layout
        ####

        ####
        # start Left layout
        jSplitPaneLeft = JSplitPane(JSplitPane.VERTICAL_SPLIT, jLeftTopPanel,
                                    jLeftDownPanel)
        jSplitPaneLeft.setDividerLocation(300)
        # end Left layout
        ####

        ####
        # start Right layout
        jScriptPane = JTextPane()
        jScriptPane.setFont(Font('Monospaced', Font.PLAIN, 11))
        # set initial value
        jScriptPane.setText(Strings.jScriptPane_header)
        #jScriptPane.addMouseListener(self)

        jScrollPaneRight = JScrollPane()
        jScrollPaneRight.setViewportView(jScriptPane)
        # end Right layout
        ####

        self.setLeftComponent(jSplitPaneLeft)
        self.setRightComponent(jScrollPaneRight)
        self.setDividerLocation(450)

        #Exported variables
        self.jConsoleText = jConsoleText
        self.jScrollConsolePane = jScrollConsolePane
        self.jScriptPane = jScriptPane
        self.jVarsPane = jVarsPane

    def actionPerformed(self, event):
        #Load button was clicked
        #> opens the file chooser
        #> opens and parses the file
        #> populates the persistand value and script panes
        #> display path inside FileName field
        if self.jLoad == event.getSource():
            if self.jFileName.getText() == Strings.jFileName_default:
                jFileChooser = JFileChooser()
            else:
                jFileChooser = JFileChooser(self.jFileName.getText())
            result = jFileChooser.showOpenDialog(None)

            if result == JFileChooser.APPROVE_OPTION:
                selectedFile = jFileChooser.getSelectedFile()

                #Update the Tab Title if it contains a file name or default name
                currentTitle = self._ui.getTabName(self)
                currentFile = FileSystems.getDefault().getPath(
                    self.jFileName.getText()).getFileName().toString()

                if self.jFileName.getText(
                ) == Strings.jFileName_default or currentTitle == currentFile:
                    self._ui.setTabName(
                        self,
                        selectedFile.toPath().getFileName().toString())

                # read from file
                (vars, script) = FileUtils.read(selectedFile.toPath())

                if vars is None or script is None:
                    # content could not be parsed
                    JOptionPane.showMessageDialog(None,
                                                  Strings.FileUtils_error,
                                                  Strings.FileUtils_error,
                                                  JOptionPane.ERROR_MESSAGE)

                else:
                    # update var and scipt content
                    self.jVarsPane.setText(vars)
                    self.jScriptPane.setText(script)
                    self._executor.init(vars)

                    # update the File Name to the current choosen file
                    self.jFileName.setText(selectedFile.getAbsolutePath())

        #Save button clicked
        #> open the file chooser
        #> creates the file content
        #> writes the file on disk
        if self.jSave == event.getSource():
            if self.jFileName.getText() == Strings.jFileName_default:
                jFileChooser = JFileChooser()
            else:
                jFileChooser = JFileChooser(self.jFileName.getText())
            #self.jFileName.setText(selectedFile.getAbsolutePath())
            result = jFileChooser.showSaveDialog(None)
            if result == JFileChooser.APPROVE_OPTION:
                selectedFile = jFileChooser.getSelectedFile()
                self.jFileName.setText(selectedFile.getAbsolutePath())

                FileUtils.write(selectedFile.toPath(),
                                self.jVarsPane.getText(),
                                self.jScriptPane.getText())

        #Wiki button clicked
        if self.jWiki == event.getSource():
            uri = URI.create("https://github.com/DanNegrea/PyRules")
            if uri and Desktop.isDesktopSupported() and Desktop.getDesktop(
            ).isSupported(Desktop.Action.BROWSE):
                Desktop.getDesktop().browse(uri)

        #Exit button clicked
        if self.jExit == event.getSource():
            result = JOptionPane.showConfirmDialog(
                None, Strings.jExit_confim_question,
                Strings.jExit_confim_title, JOptionPane.YES_NO_OPTION)
            if result == 0:
                self._ui.deleteTab(self)

        #Clear button clicked
        if self.jClear == event.getSource():
            self.jConsoleText.setText("")
            self.log(self._executor.getVars(), "state")

        #Run once button clicked
        if self.jRun == event.getSource():
            if self.isRequestFocusEnabled():
                print "is RequestFocusEnabled"
            else:
                print "is NOT RequestFocusEnabled"
            if self.isFocusOwner():
                print "is FocusOwner"
            else:
                print "is NOT FocusOwner"
            # request to init the vars (if edited)
            self.initVars()
            # request execution with toolFlag set to 999 (Run once)
            self.execute(999)

    def focusGained(self, event):
        pass

    #Reinitialize the state variables (Vars)
    def focusLost(self, event):
        if self.jVarsPane == event.getSource():
            self.initVars()

    #Init the vars (persistant variables)
    def initVars(self):
        # get the text from the Vars pane
        end = self.jVarsPane.document.length
        varsText = self.jVarsPane.document.getText(0, end)
        # the executor initializes Vals if required
        self._executor.init(varsText)

    #Call the executor
    def execute(self, toolFlag, messageIsRequest=None, messageInfo=None):
        end = self.jScriptPane.document.length
        scriptText = self.jScriptPane.document.getText(0, end)
        self._executor.execute(scriptText, toolFlag, messageIsRequest,
                               messageInfo)

    #Log the information into the console screen
    # type can be:
    #	err   - when printing errors
    #	state - when printing the state variables (Vars)
    def log(self, obj, type=""):
        if type == "err":
            self.jConsoleText.append(Strings.jConsoleText_error)
        if type == "state":
            self.jConsoleText.append(Strings.jConsoleText_state)

        # if string just append. else use pformat from pprint
        if isinstance(obj, str):
            self.jConsoleText.append(obj + "\n")
        else:
            self.jConsoleText.append(pformat(obj) + "\n")
        # scroll to bottom
        verticalScrollBar = self.jScrollConsolePane.getVerticalScrollBar()
        verticalScrollBar.setValue(verticalScrollBar.getMaximum())
예제 #4
0
class BeautifierOptionsPanel(JScrollPane):
    def __init__(self, extender):
        super(BeautifierOptionsPanel, self).__init__()
        self._extender = extender

        self.contentWrapper = JPanel(GridBagLayout())
        self.setViewportView(self.contentWrapper)
        self.getVerticalScrollBar().setUnitIncrement(16)
        self.addMouseListener(self.RequestFocusListener(
            self))  # Let textArea lose focus when click empty area

        innerContainer = JPanel(GridBagLayout())
        innerContainer.setFocusable(
            True
        )  # make sure the maxSizeText TextField is not focused when BeautifierOptionsPanel display

        # generalOptionPanel and it's inner component
        maxSizeLabel = JLabel("Max Size: ")
        self.maxSizeText = JTextField(5)
        self.maxSizeText.setHorizontalAlignment(SwingConstants.RIGHT)
        self.maxSizeText.addFocusListener(self.MaxSizeTextListener(self))
        sizeUnitLabel = JLabel("KB")

        generalOptionPanel = JPanel(GridBagLayout())
        generalOptionPanel.setBorder(
            BorderFactory.createTitledBorder("General Options"))
        gbc = GridBagConstraints()
        gbc.anchor = GridBagConstraints.WEST
        gbc.gridx = 0
        gbc.gridy = 0
        generalOptionPanel.add(maxSizeLabel, gbc)
        gbc.fill = GridBagConstraints.HORIZONTAL
        gbc.gridx = 1
        gbc.gridy = 0
        generalOptionPanel.add(self.maxSizeText, gbc)
        gbc.fill = GridBagConstraints.NONE
        gbc.gridx = 2
        gbc.gridy = 0
        gbc.weightx = 1.0
        generalOptionPanel.add(sizeUnitLabel, gbc)

        gbc = GridBagConstraints()
        gbc.fill = GridBagConstraints.BOTH
        gbc.gridx = 1
        gbc.gridy = 0
        gbc.gridheight = 2
        innerContainer.add(generalOptionPanel, gbc)

        # messageTabOptionPanel and it's inner component
        self.messageTabFormatCheckBoxs = []
        for f in supportedFormats:
            ckb = JCheckBox(f)
            ckb.addItemListener(self.messageTabFormatListener)
            self.messageTabFormatCheckBoxs.append(ckb)

        messageTabOptionPanel = JPanel()
        messageTabOptionPanel.setLayout(
            BoxLayout(messageTabOptionPanel, BoxLayout.Y_AXIS))
        messageTabOptionPanel.setBorder(
            BorderFactory.createTitledBorder("Enable in MessageEditorTab"))
        for b in self.messageTabFormatCheckBoxs:
            messageTabOptionPanel.add(b)

        gbc.gridx = 1
        gbc.gridy = 2
        gbc.gridheight = 9

        innerContainer.add(messageTabOptionPanel, gbc)

        # replaceResponsePanel and it's inner component
        self.chkEnableReplace = JCheckBox("Enable")
        self.chkEnableReplace.addItemListener(self.repalceResponseBoxListener)
        replaceResponseFormatLabel = JLabel("Format")
        self.replaceResponseFormatCheckBoxs = []
        for f in supportedFormats:
            ckb = JCheckBox(f)
            ckb.addItemListener(self.replaceResponseFormatListener)
            self.replaceResponseFormatCheckBoxs.append(ckb)
        replaceResponseIncludeLabel = JLabel(
            "Include URL that matches below(one item one line)")
        self.URLIncludeTextArea = JTextArea(6, 32)
        self.URLIncludeTextArea.addFocusListener(
            self.URLIncludeFocusListener(self))
        URLIncludeScrollPane = JScrollPane(self.URLIncludeTextArea)
        URLIncludeScrollPane.setAlignmentX(Component.LEFT_ALIGNMENT)
        replaceResponseExcludeLabel = JLabel(
            "Exclude URL that matches below(one item one line)")
        self.URLExcludeTextArea = JTextArea(5, 32)
        self.URLExcludeTextArea.addFocusListener(
            self.URLExcludeFocusListener(self))
        URLExcludeScrollPane = JScrollPane(self.URLExcludeTextArea)
        URLExcludeScrollPane.setAlignmentX(Component.LEFT_ALIGNMENT)

        replaceResponsePanel = JPanel()
        replaceResponsePanel.setLayout(
            BoxLayout(replaceResponsePanel, BoxLayout.Y_AXIS))
        replaceResponsePanel.setBorder(
            BorderFactory.createTitledBorder("Replace PROXY Response"))
        replaceResponsePanel.add(self.chkEnableReplace)
        replaceResponsePanel.add(Box.createVerticalStrut(10))
        replaceResponsePanel.add(replaceResponseFormatLabel)
        for b in self.replaceResponseFormatCheckBoxs:
            replaceResponsePanel.add(b)
        replaceResponsePanel.add(Box.createVerticalStrut(10))
        replaceResponsePanel.add(replaceResponseIncludeLabel)
        replaceResponsePanel.add(URLIncludeScrollPane)
        replaceResponsePanel.add(Box.createVerticalStrut(10))
        replaceResponsePanel.add(replaceResponseExcludeLabel)
        replaceResponsePanel.add(URLExcludeScrollPane)

        gbc.gridy = 11
        innerContainer.add(replaceResponsePanel, gbc)

        # let innerContainer keep away from left and up
        gbc = GridBagConstraints()
        gbc.gridx = 1
        gbc.gridy = 1
        self.contentWrapper.add(Box.createHorizontalStrut(15), gbc)

        # gbc.ipadx = gbc.ipady = 25
        gbc.gridx = 2
        self.contentWrapper.add(innerContainer, gbc)

        # let innerContainer stay left side
        gbc = GridBagConstraints()
        gbc.gridx = 3
        gbc.gridy = 2
        gbc.gridwidth = 1
        gbc.weightx = gbc.weighty = 1
        paddingPanel = JPanel()
        self.contentWrapper.add(paddingPanel, gbc)

        self.setDefaultOptionDisplay()

    def disableReplaceResponseDisplay(self):
        for chb in self.replaceResponseFormatCheckBoxs:
            chb.setEnabled(False)
        self.URLIncludeTextArea.setEnabled(False)
        self.URLExcludeTextArea.setEnabled(False)

    def enableReplaceResponseDisplay(self):
        for chb in self.replaceResponseFormatCheckBoxs:
            chb.setEnabled(True)
        self.URLIncludeTextArea.setEnabled(True)
        self.URLExcludeTextArea.setEnabled(True)

    def setDefaultOptionDisplay(self):
        self.maxSizeText.setText(
            str(options.get("general").get("dataMaxSize") / 1024))

        for chb in self.messageTabFormatCheckBoxs:
            format = chb.getText()
            chb.setSelected(options.get("messageEditorTabFormat").get(format))

        self.chkEnableReplace.setSelected(
            options.get("replaceProxyResponse").get("enable"))
        for chb in self.replaceResponseFormatCheckBoxs:
            format = chb.getText()
            chb.setSelected(
                options.get("replaceProxyResponse").get("formats").get(format))

        self.URLIncludeTextArea.setText("\n".join(
            options.get("replaceProxyResponse").get("include", [])))
        self.URLExcludeTextArea.setText("\n".join(
            options.get("replaceProxyResponse").get("exclude", [])))

        if self.chkEnableReplace.isSelected():
            self.enableReplaceResponseDisplay()
        else:
            self.disableReplaceResponseDisplay()

    def saveOptions(self):
        if self._extender:
            self._extender._callbacks.saveExtensionSetting(
                "options", json.dumps(options))

    class RequestFocusListener(MouseAdapter):
        def __init__(self, beautifierOptionsPanel):
            super(BeautifierOptionsPanel.RequestFocusListener, self).__init__()
            self.beautifierOptionsPanel = beautifierOptionsPanel

        def mouseClicked(self, e):
            self.beautifierOptionsPanel.requestFocusInWindow()

    class MaxSizeTextListener(FocusListener):
        def __init__(self, beautifierOptionsPanel):
            super(BeautifierOptionsPanel.MaxSizeTextListener, self).__init__()
            self.beautifierOptionsPanel = beautifierOptionsPanel

        def focusGained(self, e):
            pass

        def focusLost(self, e):
            size = e.getSource().getText()
            try:
                size = int(float(size))
                options.get("general").update({"dataMaxSize": size * 1024})
                e.getSource().setText(str(size))
                self.beautifierOptionsPanel.saveOptions()
            except:
                e.getSource().setText(
                    str(options.get("general").get("dataMaxSize") / 1024))

    def messageTabFormatListener(self, e):
        format = e.getSource().getText()
        if e.getStateChange() == ItemEvent.SELECTED:
            options.get("messageEditorTabFormat").update({format: True})
        else:
            options.get("messageEditorTabFormat").update({format: False})
        self.saveOptions()

    def repalceResponseBoxListener(self, e):
        if e.getStateChange() == ItemEvent.SELECTED:
            options.get("replaceProxyResponse").update({"enable": True})
            self.enableReplaceResponseDisplay()
        else:
            options.get("replaceProxyResponse").update({"enable": False})
            self.disableReplaceResponseDisplay()
        self.saveOptions()

    def replaceResponseFormatListener(self, e):
        format = e.getSource().getText()
        if e.getStateChange() == ItemEvent.SELECTED:
            options.get("replaceProxyResponse").get("formats").update(
                {format: True})
        else:
            options.get("replaceProxyResponse").get("formats").update(
                {format: False})
        self.saveOptions()

    class URLIncludeFocusListener(FocusListener):
        def __init__(self, beautifierOptionsPanel):
            super(BeautifierOptionsPanel.URLIncludeFocusListener,
                  self).__init__()
            self.beautifierOptionsPanel = beautifierOptionsPanel

        def focusGained(self, e):
            pass

        def focusLost(self, e):
            text = e.getSource().getText()  # <unicode>
            urlPatterns = [
                p.strip() for p in text.split("\n") if p.strip() != ""
            ]
            options.get("replaceProxyResponse").update(
                {"include": urlPatterns})
            self.beautifierOptionsPanel.saveOptions()

    class URLExcludeFocusListener(FocusListener):
        def __init__(self, beautifierOptionsPanel):
            super(BeautifierOptionsPanel.URLExcludeFocusListener,
                  self).__init__()
            self.beautifierOptionsPanel = beautifierOptionsPanel

        def focusGained(self, e):
            pass

        def focusLost(self, e):
            text = e.getSource().getText()  # <unicode>
            urlPatterns = [
                p.strip() for p in text.split("\n") if p.strip() != ""
            ]
            options.get("replaceProxyResponse").update(
                {"exclude": urlPatterns})
            self.beautifierOptionsPanel.saveOptions()
예제 #5
0
btn9 = JButton("9", actionPerformed=clickBtn9)
btn9.setBounds(201, 101, 100, 100)
btnDivide = JButton("/", actionPerformed=clickBtnDivide)
btnDivide.setBounds(301, 101, 100, 80)
btnMultiply = JButton("*", actionPerformed=clickBtnMultiply)
btnMultiply.setBounds(301, 181, 100, 80)
btnSubtract = JButton("-", actionPerformed=clickBtnSubtract)
btnSubtract.setBounds(301, 261, 100, 80)
btnPlus = JButton("+", actionPerformed=clickBtnPlus)
btnPlus.setBounds(301, 341, 100, 80)
btnEqual = JButton("=", actionPerformed=clickBtnEqual)
btnEqual.setBounds(301, 421, 100, 80)

tf = JTextField("")
tf.setBounds(0, 0, 400, 100)
tf.setHorizontalAlignment(JTextField.RIGHT)
font = Font("Courier", Font.BOLD, 30)
tf.setFont(font)

frame.add(btnDot)
frame.add(btnDel)
frame.add(btn0)
frame.add(btnEqual)
frame.add(btn1)
frame.add(btn2)
frame.add(btn3)
frame.add(btn4)
frame.add(btn5)
frame.add(btn6)
frame.add(btn7)
frame.add(btn8)