Beispiel #1
0
    def __init__(self):
        self.setLayout(GridBagLayout())

        shrinkX = JButton("shrinkX")
        shrinkX.actionPerformed = lambda event : rescaleLayout(0.5, 1)
        constr = GridBagConstraints()
        constr.gridx = 0
        constr.gridy = 0
        self.add(shrinkX, constr)

        growX = JButton("growX")
        growX.actionPerformed = lambda event : rescaleLayout(1.5, 1)
        constr = GridBagConstraints()
        constr.gridx = 2
        constr.gridy = 0
        self.add(growX, constr)

        shrinkY = JButton("shrinkY")
        shrinkY.actionPerformed = lambda event : rescaleLayout(1, 0.5)
        constr = GridBagConstraints()
        constr.gridx = 0
        constr.gridy = 2
        self.add(shrinkY, constr)

        growY = JButton("growY")
        growY.actionPerformed = lambda event : rescaleLayout(1, 1.5)
        constr = GridBagConstraints()
        constr.gridx = 2
        constr.gridy = 2
        self.add(growY, constr)

        centerB = JButton("center")
        centerB.actionPerformed = lambda event : center()
        constr = GridBagConstraints()
        constr.gridx = 1
        constr.gridy = 1
        self.add(centerB, constr)

        ui.dock(self)
Beispiel #2
0
    def __init__(self):
        self.setLayout(GridBagLayout())

        shrinkX = JButton("shrinkX")
        shrinkX.actionPerformed = lambda event: rescaleLayout(0.5, 1)
        constr = GridBagConstraints()
        constr.gridx = 0
        constr.gridy = 0
        self.add(shrinkX, constr)

        growX = JButton("growX")
        growX.actionPerformed = lambda event: rescaleLayout(1.5, 1)
        constr = GridBagConstraints()
        constr.gridx = 2
        constr.gridy = 0
        self.add(growX, constr)

        shrinkY = JButton("shrinkY")
        shrinkY.actionPerformed = lambda event: rescaleLayout(1, 0.5)
        constr = GridBagConstraints()
        constr.gridx = 0
        constr.gridy = 2
        self.add(shrinkY, constr)

        growY = JButton("growY")
        growY.actionPerformed = lambda event: rescaleLayout(1, 1.5)
        constr = GridBagConstraints()
        constr.gridx = 2
        constr.gridy = 2
        self.add(growY, constr)

        centerB = JButton("center")
        centerB.actionPerformed = lambda event: center()
        constr = GridBagConstraints()
        constr.gridx = 1
        constr.gridy = 1
        self.add(centerB, constr)

        ui.dock(self)
Beispiel #3
0
    def create_file_choice_button(name, label_text):
        button = JButton('Click to select')
        label = JLabel(label_text)
        file_chooser = JFileChooser()
        
        def choose_file(event):
            user_did_choose_file = (file_chooser.showOpenDialog(frame) ==
                                   JFileChooser.APPROVE_OPTION)
            if user_did_choose_file:
                file_ = file_chooser.getSelectedFile();
                button.text = chosen_values[name] = str(file_)
        button.actionPerformed = choose_file

        panel.add(label)
        panel.add(button)
Beispiel #4
0
    def create_file_choice_button(name, label_text):
        button = JButton('Click to select')
        label = JLabel(label_text)
        file_chooser = JFileChooser()

        def choose_file(event):
            user_did_choose_file = (file_chooser.showOpenDialog(frame) ==
                                    JFileChooser.APPROVE_OPTION)
            if user_did_choose_file:
                file_ = file_chooser.getSelectedFile()
                button.text = chosen_values[name] = str(file_)

        button.actionPerformed = choose_file

        panel.add(label)
        panel.add(button)
Beispiel #5
0
import sys
from java.awt import Window
from javax.swing import JFrame, WindowConstants
from javax.swing import JButton, JLabel
from java.awt import BorderLayout


def buttonPressed(e):
    l.setText("Button Pressed")


border = BorderLayout()
f = JFrame()
l = JLabel("This is a label")
b = JButton("Press Me!")
f.title = "Hello AWT"
f.setLayout(border)
f.contentPane.add(b, BorderLayout.SOUTH)
f.contentPane.add(l, BorderLayout.NORTH)
f.setSize(400, 400)
b.actionPerformed = buttonPressed
f.visible = True
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
Beispiel #6
0
    def __init__(self, arg_dict):
        super(CumulusUI, self).__init__()

        # Load argument from the command line
        self.start_time = arg_dict['start_time']
        self.end_time = arg_dict['end_time']
        self.dss_path = arg_dict['dss_path']
        self.cwms_home = arg_dict['cwms_home']
        self.config = arg_dict['config']

        # Get the DSS Path if one was saved in the "cumulus.config" file
        if os.path.isfile(self.config):
            with open(os.path.join(APPDATA, "cumulus.config")) as f:
                self.dss_path = f.read()

        # Get the basins and products, load JSON, create lists for JList, and create dictionaries
        self.basin_download = json.loads(self.http_get(url_basins))        
        self.jlist_basins = ["{}:{}".format(b['office_symbol'], b['name']) for b in self.basin_download]
        self.basin_meta = dict(zip(self.jlist_basins, self.basin_download))
        self.jlist_basins.sort()

        self.product_download = json.loads(self.http_get(url_products))
        self.jlist_products = ["{}".format(p['name'].replace("_", " ").title()) for p in self.product_download]
        self.product_meta = dict(zip(self.jlist_products, self.product_download))
        self.jlist_products.sort()

        btn_submit = JButton()
        lbl_start_date = JLabel()
        lbl_end_date = JLabel()
        self.txt_select_file = JTextField()
        btn_select_file = JButton()
        lbl_origin = JLabel()
        lbl_extent = JLabel()
        lbl_select_file = JLabel()

        self.txt_start_time = JTextField()
        self.txt_end_time = JTextField()

        jScrollPane1 = JScrollPane()
        self.lst_product = JList()
        self.lst_product = JList(self.jlist_products, valueChanged = self.choose_product)
        
        jScrollPane2 = JScrollPane()
        self.lst_watershed = JList()
        self.lst_watershed = JList(self.jlist_basins, valueChanged = self.choose_watershed)

        self.cwms_dssname = JCheckBox()

        self.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
        self.setTitle("Cumulus CAVI UI")
        self.setLocation(Point(10, 10))
        self.setLocationByPlatform(True)
        self.setName("CumulusCaviUi")
        self.setResizable(False)

        btn_submit.setFont(Font("Tahoma", 0, 18))
        btn_submit.setText("Submit")
        btn_submit.actionPerformed = self.submit

        lbl_start_date.setText("Start Date/Time")

        lbl_end_date.setText("End Date/Time")

        self.txt_select_file.setToolTipText("FQPN to output file (.dss)")

        btn_select_file.setText("...")
        btn_select_file.setToolTipText("Select File...")
        btn_select_file.actionPerformed = self.select_file

        lbl_origin.setText("Minimum (x,y):")

        lbl_extent.setText("Maximum (x,y):")

        lbl_select_file.setText("Output File Location")

        self.txt_start_time.setToolTipText("Start Time")
        self.txt_end_time.setToolTipText("End Time")

        self.lst_product.setBorder(BorderFactory.createTitledBorder(None, "Available Products", TitledBorder.CENTER, TitledBorder.TOP, Font("Tahoma", 0, 14)))
        self.lst_product.setFont(Font("Tahoma", 0, 14))
        jScrollPane1.setViewportView(self.lst_product)
        self.lst_product.getAccessibleContext().setAccessibleName("Available Products")
        self.lst_product.getAccessibleContext().setAccessibleParent(jScrollPane2)

        self.lst_watershed.setBorder(BorderFactory.createTitledBorder(None, "Available Watersheds", TitledBorder.CENTER, TitledBorder.TOP, Font("Tahoma", 0, 14)))
        self.lst_watershed.setFont(Font("Tahoma", 0, 14))
        self.lst_watershed.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
        jScrollPane2.setViewportView(self.lst_watershed)

        self.cwms_dssname.setText("CWMS DSS filename")
        self.cwms_dssname.setToolTipText("Parameter.yyyy.mm.dss")
        self.cwms_dssname.setVisible(False)

        layout = GroupLayout(self.getContentPane());
        self.getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, False)
                    .addComponent(lbl_select_file)
                    .addComponent(jScrollPane1)
                    .addComponent(jScrollPane2)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                            .addComponent(btn_submit)
                            .addComponent(self.txt_select_file, GroupLayout.PREFERRED_SIZE, 377, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_select_file))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_start_date)
                            .addComponent(self.txt_start_time, GroupLayout.PREFERRED_SIZE, 170, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(self.txt_end_time, GroupLayout.PREFERRED_SIZE, 170, GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbl_end_date))))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        )
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_start_date)
                    .addComponent(lbl_end_date))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(self.txt_start_time, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(self.txt_end_time, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 201, GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 201, GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, Short.MAX_VALUE)
                .addComponent(lbl_select_file)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(self.txt_select_file, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_select_file))
                .addGap(18, 18, 18)
                .addComponent(btn_submit)
                .addContainerGap())
        )

        self.txt_select_file.setText(self.dss_path)
        self.txt_start_time.setText(self.start_time)
        self.txt_end_time.setText(self.end_time)

        self.pack()
        self.setLocationRelativeTo(None)