|
| 1 | +package com.openfin.desktop.demo; |
| 2 | + |
| 3 | +import com.openfin.desktop.ApplicationOptions; |
| 4 | +import com.openfin.desktop.WindowOptions; |
| 5 | +import info.clearthought.layout.TableLayout; |
| 6 | + |
| 7 | +import javax.swing.*; |
| 8 | +import java.awt.*; |
| 9 | +import java.awt.event.ActionEvent; |
| 10 | +import java.awt.event.ActionListener; |
| 11 | +import java.util.UUID; |
| 12 | + |
| 13 | +/** |
| 14 | + * Created by richard on 2/28/15. |
| 15 | + */ |
| 16 | +public class AppCreateDialog extends JDialog { |
| 17 | + protected JTextField uuidText, nameText, urlText, versionText, applicationIconText, |
| 18 | + defaultLeftText, defaultTopText, defaultWidthText, defaultHeightText, windowStateText, |
| 19 | + applicationIconTopText, applicationIconLeftText; |
| 20 | + |
| 21 | + protected JLabel uuidLabel, nameLabel, urlLabel, versionLabel, applicationIconLabel, |
| 22 | + defaultLeftLabel, defaultTopLabel, defaultWidthLabel, defaultHeightLabel, windowStateLabel, |
| 23 | + applicationIconTopLabel, applicationIconLeftLabel; |
| 24 | + |
| 25 | + protected JCheckBox resizeCheck, frameCheck, alwaysOnBottomCheck, |
| 26 | + showTaskbarIconCheck, autoShowCheck, draggableCheck; |
| 27 | + |
| 28 | + protected JButton createButton; |
| 29 | + protected boolean createClicked = false; |
| 30 | + |
| 31 | + public AppCreateDialog() { |
| 32 | + super(); |
| 33 | + setTitle("Create Application"); |
| 34 | + setModal(true); |
| 35 | + setLayout(new BorderLayout()); |
| 36 | + |
| 37 | + this.add(layoutDescriptionPanel(), BorderLayout.CENTER); |
| 38 | + this.add(layoutActionButtonPanel(), BorderLayout.SOUTH); |
| 39 | + |
| 40 | + setSize(500, 600); |
| 41 | + } |
| 42 | + |
| 43 | + private JPanel layoutDescriptionPanel() { |
| 44 | + |
| 45 | + uuidLabel = new JLabel("UUID: "); |
| 46 | + uuidLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 47 | + uuidText = new JTextField(UUID.randomUUID().toString()); |
| 48 | + uuidText.setColumns(50); |
| 49 | + |
| 50 | + nameLabel = new JLabel("Name: "); |
| 51 | + nameLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 52 | + nameText = new JTextField("FX Live v1.4.0.0b"); |
| 53 | + nameText.setColumns(50); |
| 54 | + |
| 55 | + urlLabel = new JLabel("URL: "); |
| 56 | + urlLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 57 | + urlText = new JTextField("https://fxlive.openf.in/fxlive/1.4.0.0b/"); |
| 58 | + urlText.setColumns(50); |
| 59 | + |
| 60 | + versionLabel = new JLabel("Version: "); |
| 61 | + versionLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 62 | + versionText = new JTextField("1.1.0.0b"); |
| 63 | + versionText.setColumns(50); |
| 64 | + |
| 65 | + applicationIconLabel = new JLabel("Icon URL:" ); |
| 66 | + applicationIconLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 67 | + applicationIconText = new JTextField("https://fxlive.openf.in/fxlive/1.1.0.0b/img/FXlive_icon.png"); |
| 68 | + applicationIconText.setColumns(50); |
| 69 | + |
| 70 | + defaultLeftLabel = new JLabel("Left: "); |
| 71 | + defaultLeftLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 72 | + defaultLeftText = new JTextField("10"); |
| 73 | + defaultLeftText.setColumns(4); |
| 74 | + |
| 75 | + defaultTopLabel = new JLabel("Top: "); |
| 76 | + defaultTopLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 77 | + defaultTopText = new JTextField("10"); |
| 78 | + defaultTopText.setColumns(4); |
| 79 | + |
| 80 | + applicationIconLeftLabel = new JLabel("Icon Left: "); |
| 81 | + applicationIconLeftLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 82 | + applicationIconLeftText = new JTextField("100"); |
| 83 | + applicationIconLeftText.setColumns(4); |
| 84 | + |
| 85 | + applicationIconTopLabel = new JLabel("Icon Top: "); |
| 86 | + applicationIconTopLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 87 | + applicationIconTopText = new JTextField("100"); |
| 88 | + applicationIconTopText.setColumns(4); |
| 89 | + |
| 90 | + defaultWidthLabel = new JLabel("Width: "); |
| 91 | + defaultWidthLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 92 | + defaultWidthText = new JTextField("858"); |
| 93 | + defaultWidthText.setColumns(4); |
| 94 | + |
| 95 | + defaultHeightLabel = new JLabel("Height: "); |
| 96 | + defaultHeightLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 97 | + defaultHeightText = new JTextField("545"); |
| 98 | + defaultHeightText.setColumns(4); |
| 99 | + |
| 100 | + windowStateLabel = new JLabel("Window State: "); |
| 101 | + windowStateLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 102 | + windowStateText = new JTextField("normal"); |
| 103 | + windowStateText.setColumns(10); |
| 104 | + |
| 105 | + resizeCheck = new JCheckBox("resize", true); |
| 106 | + frameCheck = new JCheckBox("frame", true); |
| 107 | + alwaysOnBottomCheck = new JCheckBox("alwaysOnBottom", false); |
| 108 | + showTaskbarIconCheck = new JCheckBox("showTaskbarIcon", true); |
| 109 | + autoShowCheck = new JCheckBox("autoShow", true); |
| 110 | + draggableCheck = new JCheckBox("draggable", false); |
| 111 | + |
| 112 | + JPanel fieldPanel = new JPanel(); |
| 113 | + |
| 114 | + fieldPanel.setLayout(new javax.swing.BoxLayout(fieldPanel, javax.swing.BoxLayout.Y_AXIS)); |
| 115 | + |
| 116 | + double size[][] = |
| 117 | + {{0.25, 0.75}, |
| 118 | + {30,30,30,30,30,30,30,30,30,30,30,30}}; |
| 119 | + |
| 120 | + TableLayout twoColLayout = new TableLayout(size); |
| 121 | + JPanel twoColPanel = new JPanel(twoColLayout); |
| 122 | + |
| 123 | + twoColPanel.add(uuidLabel, "0, 0"); |
| 124 | + twoColPanel.add(uuidText, "1, 0"); |
| 125 | + twoColPanel.add(nameLabel , "0, 1"); |
| 126 | + twoColPanel.add(nameText , "1, 1"); |
| 127 | + twoColPanel.add(urlLabel , "0, 2"); |
| 128 | + twoColPanel.add(urlText , "1, 2"); |
| 129 | + twoColPanel.add(versionLabel , "0, 3"); |
| 130 | + twoColPanel.add(versionText , "1, 3"); |
| 131 | + twoColPanel.add(applicationIconLabel , "0, 4"); |
| 132 | + twoColPanel.add(applicationIconText , "1, 4"); |
| 133 | + twoColPanel.add(applicationIconLeftLabel , "0, 5"); |
| 134 | + twoColPanel.add(applicationIconLeftText , "1, 5"); |
| 135 | + twoColPanel.add(applicationIconTopLabel , "0, 6"); |
| 136 | + twoColPanel.add(applicationIconTopText , "1, 6"); |
| 137 | + twoColPanel.add(defaultLeftLabel , "0, 7"); |
| 138 | + twoColPanel.add(defaultLeftText , "1, 7"); |
| 139 | + twoColPanel.add(defaultTopLabel , "0, 8"); |
| 140 | + twoColPanel.add(defaultTopText , "1, 8"); |
| 141 | + twoColPanel.add(defaultWidthLabel , "0, 9"); |
| 142 | + twoColPanel.add(defaultWidthText , "1, 9"); |
| 143 | + twoColPanel.add(defaultHeightLabel , "0, 10"); |
| 144 | + twoColPanel.add(defaultHeightText , "1, 10"); |
| 145 | + twoColPanel.add(windowStateLabel , "0, 11"); |
| 146 | + twoColPanel.add(windowStateText , "1, 11"); |
| 147 | + |
| 148 | + fieldPanel.add(twoColPanel); |
| 149 | + fieldPanel.add(resizeCheck); |
| 150 | + fieldPanel.add(frameCheck); |
| 151 | + fieldPanel.add(alwaysOnBottomCheck); |
| 152 | + fieldPanel.add(showTaskbarIconCheck); |
| 153 | + fieldPanel.add(autoShowCheck); |
| 154 | + fieldPanel.add(draggableCheck); |
| 155 | + return fieldPanel; |
| 156 | + } |
| 157 | + |
| 158 | + public ApplicationOptions getApplicatonOptions() { |
| 159 | + ApplicationOptions options = null; |
| 160 | + if (createClicked) { |
| 161 | + String uuid = uuidText.getText(); |
| 162 | + String name = nameText.getText(); |
| 163 | + String url = urlText.getText(); |
| 164 | + String version = versionText.getText(); |
| 165 | + String applicationIcon = applicationIconText.getText(); |
| 166 | + int applicationIconTop = Integer.parseInt(applicationIconTopText.getText()); |
| 167 | + int applicationIconLeft = Integer.parseInt(applicationIconLeftText.getText()); |
| 168 | + int defaultLeft = Integer.parseInt(defaultLeftText.getText()); |
| 169 | + int defaultTop = Integer.parseInt(defaultTopText.getText()); |
| 170 | + int defaultWidth = Integer.parseInt(defaultWidthText.getText()); |
| 171 | + int defaultHeight = Integer.parseInt(defaultHeightText.getText()); |
| 172 | + String state = windowStateText.getText(); |
| 173 | + boolean resize = resizeCheck.isSelected(); |
| 174 | + boolean frame = frameCheck.isSelected(); |
| 175 | + boolean alwaysOnBottom = alwaysOnBottomCheck.isSelected(); |
| 176 | + boolean showTaskbarIcon = showTaskbarIconCheck.isSelected(); |
| 177 | + boolean autoShow = autoShowCheck.isSelected(); |
| 178 | + boolean draggable = draggableCheck.isSelected(); |
| 179 | + |
| 180 | + options = new ApplicationOptions(name, uuid, url); |
| 181 | + options.setVersion(version); |
| 182 | + options.setApplicationIcon(applicationIcon); |
| 183 | + |
| 184 | + WindowOptions mainWindowOptions = new WindowOptions(); |
| 185 | + |
| 186 | + mainWindowOptions.setAutoShow(autoShow); |
| 187 | + mainWindowOptions.setDefaultHeight(defaultHeight); |
| 188 | + mainWindowOptions.setDefaultLeft(defaultLeft); |
| 189 | + mainWindowOptions.setDefaultTop(defaultTop); |
| 190 | + mainWindowOptions.setDefaultWidth(defaultWidth); |
| 191 | + mainWindowOptions.setState(state); |
| 192 | + mainWindowOptions.setResizable(resize); |
| 193 | + mainWindowOptions.setFrame(frame); |
| 194 | + mainWindowOptions.setShowTaskbarIcon(showTaskbarIcon); |
| 195 | + |
| 196 | + options.setMainWindowOptions(mainWindowOptions); |
| 197 | + } |
| 198 | + return options; |
| 199 | + } |
| 200 | + |
| 201 | + public void show(Component parent) { |
| 202 | + this.createClicked = false; |
| 203 | + uuidText.setText("OpenFinDesktopDemo"); |
| 204 | + this.setLocationRelativeTo(parent); |
| 205 | + setVisible(true); |
| 206 | + } |
| 207 | + |
| 208 | + private JPanel layoutActionButtonPanel() { |
| 209 | + JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
| 210 | + |
| 211 | + createButton = new JButton("Create"); |
| 212 | + createButton.addActionListener(new ActionListener() { |
| 213 | + @Override |
| 214 | + public void actionPerformed(ActionEvent actionEvent) { |
| 215 | + createClicked = true; |
| 216 | + AppCreateDialog.this.setVisible(false); |
| 217 | + } |
| 218 | + }); |
| 219 | + buttonPanel.add(createButton); |
| 220 | + |
| 221 | + return buttonPanel; |
| 222 | + } |
| 223 | + |
| 224 | +} |
0 commit comments