public static void addComponentsToPane(Container pane) { if (RIGHT_TO_LEFT) { pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); } pane.setLayout(new GridLayout(0, 2)); pane.add(new JButton("Button 1")); pane.add(new JButton("Button 2")); pane.add(new JButton("Button 3")); pane.add(new JButton("Long-Named Button 4")); pane.add(new JButton("5")); }
public static void addComponentsToPane(Container pane) { if (RIGHT_TO_LEFT) { pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); } /* * Start with the GridBagLayout & GridBadContraints(values it uses) */ pane.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); /* * Creating the menuBar with: * * menuEdit (Edit): * - About * - Reset * - Exit * menuView (View): * - View * menuHelp (Help): * - Help * */ JMenuBar menuBar = new JMenuBar(); JMenu menuEdit = new JMenu("Edit"); JMenu menuView = new JMenu("View"); JMenu menuHelp = new JMenu("Help"); // MenuItems for menuEdit JMenuItem menuItemAbout = new JMenuItem("About"); JMenuItem menuItemReset = new JMenuItem("Reset"); JMenuItem menuItemExit = new JMenuItem("Exit"); // MenuItem for menuView JMenuItem menuItemView = new JMenuItem("View More"); // MenuItem for menuHelp JMenuItem menuItemHelp = new JMenuItem("Help!!!"); // Building the Edit Menu menuEdit.setMnemonic(KeyEvent.VK_A); menuEdit.getAccessibleContext().setAccessibleDescription("Test A"); // Building the menuEdit menuEdit.add(menuItemAbout); menuEdit.add(menuItemReset); menuEdit.add(menuItemExit); // Building the menuView menuView.add(menuItemView); // Building the menuHelp menuHelp.add(menuItemHelp); // Building the menuBar menuBar.add(menuEdit); menuBar.add(menuView); menuBar.add(menuHelp); // menu.addSeparator(); /* * Buttons TOP * Backspace, C & CE * * Backspace = Delete last pushed input * C = Clear all data * CE = Clear last entry */ JButton buttonBS = new JButton("Backspace"); // deletes last key input JButton buttonCAD = new JButton("C"); // ClearAllData JButton buttonCLE = new JButton("CE"); // ClearLastEntry buttonBS.addActionListener(new CalculatorAlt.ButtonBSListener()); buttonCAD.addActionListener(new CalculatorAlt.ButtonCADListener()); buttonCLE.addActionListener(new CalculatorAlt.ButtonCLEListener()); /* * Buttons LEFT * * MC = Memory Clear: Clears any number stored in memory * MR = Memory Recall: Recalls number in memory. * MS = Memory Save: Saves number in memory. * M+ = Memory Addition: Takes number on display and adds to number in memory, saving the result into memory. */ JButton buttonMC = new JButton("MC"); JButton buttonMR = new JButton("MR"); JButton buttonMS = new JButton("MS"); JButton buttonMA = new JButton("M+"); buttonMC.addActionListener(new CalculatorAlt.ButtonMCListener()); buttonMR.addActionListener(new CalculatorAlt.ButtonMRListener()); buttonMS.addActionListener(new CalculatorAlt.ButtonMSListener()); buttonMA.addActionListener(new CalculatorAlt.ButtonMAListener()); /* * Creating the digits buttons with actionListeners */ JButton button0 = new JButton("0"); JButton button1 = new JButton("1"); JButton button2 = new JButton("2"); JButton button3 = new JButton("3"); JButton button4 = new JButton("4"); JButton button5 = new JButton("5"); JButton button6 = new JButton("6"); JButton button7 = new JButton("7"); JButton button8 = new JButton("8"); JButton button9 = new JButton("9"); button0.addActionListener(new CalculatorAlt.Button0Listener()); button1.addActionListener(new CalculatorAlt.Button1Listener()); button2.addActionListener(new CalculatorAlt.Button2Listener()); button3.addActionListener(new CalculatorAlt.Button3Listener()); button4.addActionListener(new CalculatorAlt.Button4Listener()); button5.addActionListener(new CalculatorAlt.Button5Listener()); button6.addActionListener(new CalculatorAlt.Button6Listener()); button7.addActionListener(new CalculatorAlt.Button7Listener()); button8.addActionListener(new CalculatorAlt.Button8Listener()); button9.addActionListener(new CalculatorAlt.Button9Listener()); /* * Creating the functions buttons */ JButton buttonPlus = new JButton("+"); JButton buttonMinus = new JButton("-"); JButton buttonTimes = new JButton("*"); JButton buttonObelus = new JButton("/"); JButton buttonSquared = new JButton("sqrt"); JButton buttonPercent = new JButton("%"); JButton buttonSR = new JButton("1/x"); // not sure if right symbol JButton buttonDot = new JButton("."); JButton buttonToggle = new JButton("+/-"); JButton buttonCompute = new JButton("="); buttonPlus.addActionListener(new CalculatorAlt.ButtonPlusListener()); buttonMinus.addActionListener(new CalculatorAlt.ButtonMinusListener()); buttonTimes.addActionListener(new CalculatorAlt.ButtonTimesListener()); buttonObelus.addActionListener(new CalculatorAlt.ButtonObelusListener()); buttonSquared.addActionListener(new CalculatorAlt.ButtonSquaredListener()); buttonPercent.addActionListener(new CalculatorAlt.ButtonPercentListener()); buttonSR.addActionListener(new CalculatorAlt.ButtonSRListener()); buttonDot.addActionListener(new CalculatorAlt.ButtonDotListener()); buttonToggle.addActionListener(new CalculatorAlt.ButtonToggleListener()); buttonCompute.addActionListener(new CalculatorAlt.ButtonComputeListener()); /** * Bringing all into the pane * * <p>the gbc(GridBagConstraints) is created one time, and adjusted when needed. */ /* * adding the menuBar to the pane */ gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(2, 2, 2, 2); gbc.weighty = 1.0; gbc.anchor = GridBagConstraints.FIRST_LINE_START; // top of space gbc.gridwidth = 7; // 7 columns wide gbc.gridy = 0; // first row pane.add(menuBar, gbc); /* * adding labelInput and textField to the pane */ gbc.gridwidth = 2; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 0; // first column gbc.gridy = 1; // second row pane.add(textInput, gbc); gbc.gridwidth = 3; gbc.gridx = 3; // fourth column gbc.gridy = 1; // second row pane.add(textField, gbc); gbc.gridwidth = 1; gbc.gridx = 2; // first column gbc.gridy = 1; // second row pane.add(textFunction, gbc); /* * adding the first row of buttons to pane */ gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridwidth = 3; // 3 columns wide gbc.weighty = 0.5; // reset to 0.5 gbc.gridx = 1; // second column gbc.gridy = 2; // third row pane.add(buttonBS, gbc); gbc.gridwidth = 1; gbc.gridx = 4; pane.add(buttonCAD, gbc); gbc.gridx = 5; pane.add(buttonCLE, gbc); /* * Left side buttons */ gbc.gridwidth = 1; // 1 columns wide gbc.gridx = 0; // first column gbc.gridy = 3; // fourth row pane.add(buttonMC, gbc); gbc.gridy = 4; // fifth row pane.add(buttonMR, gbc); gbc.gridy = 5; // sixth row pane.add(buttonMS, gbc); gbc.gridy = 6; // seventh row pane.add(buttonMA, gbc); /* * digits buttons */ gbc.gridwidth = 1; // 1 columns wide - to make sure it stays 1 gbc.gridx = 1; gbc.gridy = 6; pane.add(button0, gbc); gbc.gridx = 1; gbc.gridy = 5; pane.add(button1, gbc); gbc.gridx = 2; gbc.gridy = 5; pane.add(button2, gbc); gbc.gridx = 3; gbc.gridy = 5; pane.add(button3, gbc); gbc.gridx = 1; gbc.gridy = 4; pane.add(button4, gbc); gbc.gridx = 2; gbc.gridy = 4; pane.add(button5, gbc); gbc.gridx = 3; gbc.gridy = 4; pane.add(button6, gbc); gbc.gridx = 1; gbc.gridy = 3; pane.add(button7, gbc); gbc.gridx = 2; gbc.gridy = 3; pane.add(button8, gbc); gbc.gridx = 3; gbc.gridy = 3; pane.add(button9, gbc); /* * function buttons */ gbc.gridx = 4; gbc.gridy = 3; pane.add(buttonObelus, gbc); gbc.gridx = 4; gbc.gridy = 4; pane.add(buttonTimes, gbc); gbc.gridx = 4; gbc.gridy = 5; pane.add(buttonMinus, gbc); gbc.gridx = 4; gbc.gridy = 6; pane.add(buttonPlus, gbc); gbc.gridx = 5; gbc.gridy = 3; pane.add(buttonSquared, gbc); gbc.gridx = 5; gbc.gridy = 4; pane.add(buttonPercent, gbc); gbc.gridx = 5; gbc.gridy = 5; pane.add(buttonSR, gbc); gbc.gridx = 5; gbc.gridy = 6; pane.add(buttonCompute, gbc); gbc.gridx = 2; gbc.gridy = 6; pane.add(buttonToggle, gbc); gbc.gridx = 3; gbc.gridy = 6; pane.add(buttonDot, gbc); }
/** * This method is used to display the window to interact with obix as well as colibri. * * @param chosenComponents The {@link ObixObject} which have been chosen in the previous windows. * @return The container which contains all elemtents that are used for interacting with obix as * well as colibri. */ private Container interactionWindow(List<ObixObject> chosenComponents) { Container pane = new Container(); pane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 10; c.gridx = 0; c.gridy = 0; c.insets = new Insets(30, 20, 0, 0); c.gridy++; pane.add(registeredColibriChannelCheckBox, c); JLabel label = new JLabel("OBIX Components"); Font headerF = new Font("Courier", Font.BOLD, 25); label.setFont(headerF); c.gridy++; pane.add(label, c); /* Print lobby Data */ for (ObixObject o : chosenComponents) { if (connector.getColibriChannel().getRegistered()) { connector.getColibriChannel().send(ColibriMessage.createAddServiceMessage(o)); } c.gridy++; c.insets = new Insets(30, 10, 0, 0); JLabel uriLabel = new JLabel(o.getObixUri()); uriLabel.setFont(new Font("Courier", Font.ITALIC, 15)); c.gridx = 0; c.gridwidth = 10; pane.add(uriLabel, c); c.gridwidth = 1; c.insets = new Insets(5, 10, 0, 0); final JTextField textField = new JTextField("NOT OBSERVED", 20); Font tempF = new Font("Courier", Font.PLAIN, 15); textField.setFont(tempF); c.gridy++; pane.add(textField, c); JLabel unitLabel = new JLabel(); if (o.hasUnit()) { String unitString = o.getUnit().symbol().get(); int unitCode = unitString.codePointAt(0); if (unitCode == 65533) { unitString = "\u2103"; } unitLabel.setText(unitString); } c.gridx++; pane.add(unitLabel, c); final JButton getObixButton = new JButton("GET from OBIX"); c.gridx++; pane.add(getObixButton, c); final JButton getColibriButton = new JButton("GET from Colibri"); c.gridx++; pane.add(getColibriButton, c); final JCheckBox writableCheckBox = new JCheckBox("Writable"); writableCheckBox.setSelected(o.getObj().isWritable()); writableCheckBox.setEnabled(false); c.gridx++; pane.add(writableCheckBox, c); final JCheckBox observeObixCheckBox = new JCheckBox("observe Obix Data"); observeObixCheckBox.setMargin(new Insets(0, 20, 0, 20)); c.gridx++; pane.add(observeObixCheckBox, c); final JCheckBox observedByColibriCheckBox = new JCheckBox("Colibri observes Data"); observedByColibriCheckBox.setEnabled(false); commandFactory.addCommand( () -> observedByColibriCheckBox.setSelected(o.getObservedByColibri())); c.gridx++; pane.add(observedByColibriCheckBox, c); final JCheckBox addServiceCheckbox = new JCheckBox("Service Added to Colibri"); commandFactory.addCommand(() -> addServiceCheckbox.setSelected(o.getAddedAsService())); commandFactory.addCommand( () -> addServiceCheckbox.setEnabled(connector.getColibriChannel().getRegistered())); c.gridx++; pane.add(addServiceCheckbox, c); final JCheckBox observeColibriActionsCheckbox = new JCheckBox("Observe Colibri Actions"); if (o.getObj().isWritable()) { commandFactory.addCommand( () -> observeColibriActionsCheckbox.setEnabled(o.getAddedAsService())); commandFactory.addCommand( () -> observeColibriActionsCheckbox.setSelected(o.getObservesColibriActions())); } else { observeColibriActionsCheckbox.setEnabled(false); } c.gridx++; pane.add(observeColibriActionsCheckbox, c); representationRows.add( new RepresentationRow( uriLabel, observeObixCheckBox, textField, o, writableCheckBox, getObixButton, getColibriButton, addServiceCheckbox, observedByColibriCheckBox, observeColibriActionsCheckbox)); PutToObixTask putToObixTask = new PutToObixTask(o, connector.getColibriChannel(), connector.getObixChannel(), null); connector.getColibriChannel().addPutToObixTask(o.getServiceUri(), putToObixTask); ObixObservationUpdates observationUpdates = new ObixObservationUpdates(observeObixCheckBox, textField, o, connector); /** * Listener for the checkbox which indicates, if an {@link ObixObject] is observed by the obix connector. */ observeObixCheckBox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { ObixObject object = new ObixObject("", o.getObixChannelPort()); for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { if (r.getObservedCheckBox().equals(observeObixCheckBox)) { object = r.getObixObject(); } } if (e.getStateChange() == ItemEvent.SELECTED) { obixChannel.observe(object); commandFactory.addCommand( object.getObixUri() + "ObserveCommand", observationUpdates::run); } else { commandFactory.removeCommand(object.getObixUri() + "ObserveCommand"); object.getRelation().proactiveCancel(); } } }); /** * Listener for the checkbox which indicates, if an {@link ObixObject] is writeable. */ writableCheckBox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { ObixObject object = new ObixObject("", o.getObixChannelPort()); for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { if (r.getWritableCheckbox().equals(writableCheckBox)) { object = r.getObixObject(); } } if (e.getStateChange() == ItemEvent.SELECTED) { } else { object.getObj().setWritable(false); } object = obixChannel.put(object); writableCheckBox.setSelected(object.getObj().isWritable()); } }); /** * Listener for the checkbox which indicates, if an {@link ObixObject] is added as a service at colibri. */ addServiceCheckbox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { ObixObject object = new ObixObject("", o.getObixChannelPort()); for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { if (r.getAddedAsServiceCheckBox().equals(addServiceCheckbox)) { object = r.getObixObject(); } } if (e.getStateChange() == ItemEvent.SELECTED) { if (!object.getAddedAsService()) { connector .getColibriChannel() .send(ColibriMessage.createAddServiceMessage(object)); } } else { if (object.getAddedAsService()) { connector .getColibriChannel() .send(ColibriMessage.createRemoveServiceMessage(object)); } } } }); /** * Listener for the checkbox which indicates, if the connector observes the actions that the colibri * semantic core performs on an {@link ObixObject]. */ observeColibriActionsCheckbox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { ObixObject object = new ObixObject("", o.getObixChannelPort()); for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { if (r.getObserveColibriActionsCheckbox().equals(observeColibriActionsCheckbox)) { object = r.getObixObject(); } } if (e.getStateChange() == ItemEvent.SELECTED) { if (!object.getObservesColibriActions()) { connector .getColibriChannel() .send(ColibriMessage.createObserveServiceMessage(object)); } } else { if (object.getObservesColibriActions()) { connector .getColibriChannel() .send(ColibriMessage.createDetachServiceMessage(object)); } } } }); /** GET Obix button listener */ Action getObixAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { ObixObject object = new ObixObject("", o.getObixChannelPort()); JTextField textF = null; for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { if (r.getGetObixButton().equals(getObixButton)) { object = r.getObixObject(); textF = r.getValueTextField(); } } textField.setText(""); object = obixChannel.get(object.getObixUri()); textF.setText(object.toString()); if (o.getObservedByColibri()) { o.getPutMessageToColibriTask().execute(o); } } }; getObixButton.addActionListener(getObixAction); /** GET Colibri button listener */ Action getColibriAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { ObixObject object = new ObixObject("", o.getObixChannelPort()); JTextField textF = null; for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { if (r.getGetColibriButton().equals(getColibriButton)) { object = r.getObixObject(); textF = r.getValueTextField(); } } connector.getColibriChannel().send(ColibriMessage.createGetMessage(object)); } }; getColibriButton.addActionListener(getColibriAction); /** * Listener for the textfield connected with an {@link ObixObject}, to send PUT messages to * obix on <Enter>. */ textField.addKeyListener( new KeyListener() { public void keyTyped(KeyEvent e) { // intentionally empty } public void keyPressed(KeyEvent e) { // intentionally empty } public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { ObixObject object = new ObixObject("", o.getObixChannelPort()); for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { if (r.getValueTextField().equals(textField)) { object = r.getObixObject(); } } object.setValueParameter1(textField.getText()); textField.setText(""); object = obixChannel.put(object); textField.setText(object.toString()); } } }); } JTextArea receivedMessagesTextArea = new JTextArea("Received Messages"); receivedMessagesTextArea.setLineWrap(true); receivedMessagesTextArea.setWrapStyleWord(true); c.gridy++; c.gridx = 0; c.insets = new Insets(50, 0, 0, 0); c.gridwidth = 10; pane.add(receivedMessagesTextArea, c); receivedMessagesTextArea.setEnabled(false); commandFactory.addCommand( () -> receivedMessagesTextArea.setText( connector.getColibriChannel().getLastMessageReceived())); c.gridy++; c.gridwidth = 1; JLabel sendMessageLabel = new JLabel("Send Message to Colibri Semantic Core:"); pane.add(sendMessageLabel, c); c.gridy++; c.gridwidth = 10; JTextArea sendMessageArea = new JTextArea(""); pane.add(sendMessageArea, c); c.gridy++; c.gridwidth = 2; JButton sendQueMessageButton = new JButton("Send Query Message"); pane.add(sendQueMessageButton, c); c.gridx++; c.gridx++; c.gridwidth = 2; JButton sendUpdMessageButton = new JButton("Send Update Message"); pane.add(sendUpdMessageButton, c); commandFactory.addCommand( () -> sendQueMessageButton.setEnabled(connector.getColibriChannel().getRegistered())); commandFactory.addCommand( () -> sendUpdMessageButton.setEnabled(connector.getColibriChannel().getRegistered())); /** QUE to Colibri button listener */ Action sendQueMessageAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { connector .getColibriChannel() .send( ColibriMessage.createQueryMessage( sendMessageArea.getText(), new ArrayList<>())); } }; sendQueMessageButton.addActionListener(sendQueMessageAction); /** UPD to Colibri button listener */ Action sendUpdMessageAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { connector .getColibriChannel() .send(ColibriMessage.createUpdateMessage(sendMessageArea.getText())); } }; sendUpdMessageButton.addActionListener(sendUpdMessageAction); return pane; }
/** * This method represents the window in which the preferred parameters for the obix components can * be chosen. * * @param chosenComponents The list of {@link ObixObject} which have been chosen in the previous * window. * @return The container in which the preferred parameters for the obix components can be chosen. */ private Container chooseParameters(List<ObixObject> chosenComponents) { Container pane = new Container(); pane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); Font titelF = new Font("Courier", Font.BOLD, 30); title = new JLabel("Please choose the appropriate Parameters for the datapoints"); title.setFont(titelF); c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 10; c.gridx = 0; c.gridy = 0; pane.add(title, c); List<String> parametersList = Configurator.getInstance().getAvailableParameterTypes(); String[] parameterTypes = new String[parametersList.size()]; parameterTypes = parametersList.toArray(parameterTypes); for (ObixObject o : chosenComponents) { c.gridy++; c.insets = new Insets(30, 10, 0, 0); JLabel uriLabel = new JLabel(o.getObixUri()); uriLabel.setFont(new Font("Courier", Font.ITALIC, 15)); c.gridx = 0; c.gridwidth = 10; pane.add(uriLabel, c); c.gridwidth = 1; c.insets = new Insets(10, 10, 0, 0); JLabel parameter1Label = new JLabel("Parameter 1 Type:"); c.gridy++; pane.add(parameter1Label, c); JLabel parameter1ObixUnitLabel = new JLabel("OBIX unit: " + o.getObixUnitUri()); c.gridx++; pane.add(parameter1ObixUnitLabel, c); JComboBox parameter1comboBox = new JComboBox(parameterTypes); c.gridx++; pane.add(parameter1comboBox, c); JButton param1AddStateButton = new JButton("Add State"); Box vBox1 = Box.createVerticalBox(); vBox1.setBorder(BorderFactory.createLineBorder(Color.black)); JLabel parameter1UnitLabel = new JLabel("Set Parameter 1 Unit:"); c.gridx++; pane.add(parameter1UnitLabel, c); JTextField parameter1UnitTextField = new JTextField(o.getParameter1().getParameterUnit()); parameter1UnitTextField.setPreferredSize(new Dimension(500, 20)); parameter1UnitTextField.setMinimumSize(new Dimension(500, 20)); c.gridx++; pane.add(parameter1UnitTextField, c); JLabel parameter1ValueTypeLabel = new JLabel("valueType: " + o.getParameter1().getValueType()); c.gridx++; pane.add(parameter1ValueTypeLabel, c); int param1UnitLabelxPosition = c.gridx; int param1UnitLabelyPosition = c.gridy; for (StateDescription s : o.getParameter1().getStateDescriptions()) { JLabel stateNameLabel = new JLabel("State Name: "); JTextField stateNameTextfield = new JTextField(20); stateNameTextfield.setText(s.getName().getName()); vBox1.add(stateNameLabel); vBox1.add(stateNameTextfield); JLabel stateValueLabel = new JLabel("State Value: "); JTextField stateValueTextfield = new JTextField(20); stateValueTextfield.setText(s.getValue().getValue()); vBox1.add(stateValueLabel); vBox1.add(stateValueTextfield); JLabel stateURILabel = new JLabel("State URI: "); JTextField stateURITextfield = new JTextField(20); stateURITextfield.setText(s.getStateDescriptionUri()); vBox1.add(stateURILabel); vBox1.add(stateURITextfield); JButton deleteStateButton = new JButton("Delete State"); vBox1.add(deleteStateButton); JSeparator horizontalLine = new JSeparator(JSeparator.HORIZONTAL); vBox1.add(horizontalLine); vBox1.add(horizontalLine); StateRepresentation stateRepresentation = (new StateRepresentation( param1AddStateButton, deleteStateButton, stateNameLabel, stateNameTextfield, stateValueLabel, stateValueTextfield, stateURILabel, stateURITextfield, horizontalLine, vBox1, o.getParameter1())); addDeleteStateListener(stateRepresentation); listOfStateRepresentations.add(stateRepresentation); pane.revalidate(); pane.repaint(); } addParameterBoxListener( parameter1comboBox, param1UnitLabelxPosition, param1UnitLabelyPosition, parameter1UnitLabel, parameter1UnitTextField, pane, param1AddStateButton, vBox1); /** Add state to parameter 1 function listener */ param1AddStateButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JLabel stateNameLabel = new JLabel("State Name: "); JTextField stateNameTextfield = new JTextField(20); vBox1.add(stateNameLabel); vBox1.add(stateNameTextfield); JLabel stateValueLabel = new JLabel("State Value: "); JTextField stateValueTextfield = new JTextField(20); vBox1.add(stateValueLabel); vBox1.add(stateValueTextfield); JLabel stateURILabel = new JLabel("State URI: "); JTextField stateURITextfield = new JTextField(20); vBox1.add(stateURILabel); vBox1.add(stateURITextfield); JButton deleteStateButton = new JButton("Delete State"); vBox1.add(deleteStateButton); JSeparator horizontalLine = new JSeparator(JSeparator.HORIZONTAL); vBox1.add(horizontalLine); vBox1.add(horizontalLine); StateRepresentation stateRepresentation = (new StateRepresentation( param1AddStateButton, deleteStateButton, stateNameLabel, stateNameTextfield, stateValueLabel, stateValueTextfield, stateURILabel, stateURITextfield, horizontalLine, vBox1, o.getParameter1())); addDeleteStateListener(stateRepresentation); listOfStateRepresentations.add(stateRepresentation); pane.revalidate(); pane.repaint(); } }); c.gridy++; c.gridx = 0; JLabel parameter2Label = new JLabel("Parameter 2 Type:"); pane.add(parameter2Label, c); JComboBox parameter2comboBox = new JComboBox(parameterTypes); c.gridx++; c.gridx++; pane.add(parameter2comboBox, c); JLabel parameter2UnitLabel = new JLabel("Set Parameter 2 Unit: "); c.gridx++; pane.add(parameter2UnitLabel, c); JTextField parameter2UnitTextField = new JTextField(o.getParameter2().getParameterUnit()); parameter2UnitTextField.setPreferredSize(new Dimension(500, 20)); parameter2UnitTextField.setMinimumSize(new Dimension(500, 20)); c.gridx++; pane.add(parameter2UnitTextField, c); JLabel parameter2ValueTypeLabel = new JLabel("valueType: " + o.getParameter2().getValueType()); c.gridx++; pane.add(parameter2ValueTypeLabel, c); JButton param2AddStateButton = new JButton("Add State"); Box vBox2 = Box.createVerticalBox(); vBox2.setBorder(BorderFactory.createLineBorder(Color.black)); int param2UnitLabelxPosition = c.gridx; int param2UnitLabelyPosition = c.gridy; addParameterBoxListener( parameter2comboBox, param2UnitLabelxPosition, param2UnitLabelyPosition, parameter2UnitLabel, parameter2UnitTextField, pane, param2AddStateButton, vBox2); /** Add state to parameter 2 function listener */ param2AddStateButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JLabel stateNameLabel = new JLabel("State Name: "); JTextField stateNameTextfield = new JTextField(20); vBox2.add(stateNameLabel); vBox2.add(stateNameTextfield); JLabel stateValueLabel = new JLabel("State Value: "); JTextField stateValueTextfield = new JTextField(20); vBox2.add(stateValueLabel); vBox2.add(stateValueTextfield); JLabel stateURILabel = new JLabel("State URI: "); JTextField stateURITextfield = new JTextField(20); vBox2.add(stateURILabel); vBox2.add(stateURITextfield); JButton deleteStateButton = new JButton("Delete State"); vBox2.add(deleteStateButton); JSeparator horizontalLine = new JSeparator(JSeparator.HORIZONTAL); vBox2.add(horizontalLine); vBox2.add(horizontalLine); StateRepresentation stateRepresentation = (new StateRepresentation( param2AddStateButton, deleteStateButton, stateNameLabel, stateNameTextfield, stateValueLabel, stateValueTextfield, stateURILabel, stateURITextfield, horizontalLine, vBox2, o.getParameter2())); addDeleteStateListener(stateRepresentation); listOfStateRepresentations.add(stateRepresentation); pane.revalidate(); pane.repaint(); } }); parameter1comboBox.setSelectedItem(o.getParameter1().getParameterType()); parameter2comboBox.setSelectedItem(o.getParameter2().getParameterType()); representationRows.add( new RepresentationRow( o, parameter1comboBox, parameter2comboBox, parameter1UnitTextField, parameter2UnitTextField)); } JButton acceptButton = new JButton("Accept"); c.insets = new Insets(50, 0, 0, 0); c.gridwidth = 10; c.gridx = 0; c.gridy++; pane.add(acceptButton, c); /** Accept button listener */ Action acceptAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { for (StateRepresentation s : listOfStateRepresentations) { if (s.getStateNameTextField().getText().isEmpty() || s.getStateUriTextField().getText().isEmpty() || s.getStateValueTextField().getText().isEmpty()) { JOptionPane.showMessageDialog( null, "Each state parameter field must contain a text! " + "There are some empty parameter fields, please change them before proceeding."); return; } } for (ObixObject o : chosenComponents) { o.getParameter1().getStateDescriptions().clear(); o.getParameter2().getStateDescriptions().clear(); } for (StateRepresentation s : listOfStateRepresentations) { // Save created State ArrayList<String> types = new ArrayList<String>(); types.add("&colibri;AbsoluteState"); types.add("&colibri;DiscreteState"); Value val = new Value(); val.setValue(s.getStateValueTextField().getText()); val.setDatatype(s.getParameter().getValueType()); Name name = new Name(); name.setName(s.getStateNameTextField().getText()); StateDescription state = new StateDescription(s.getStateUriTextField().getText(), types, val, name); s.getParameter().addStateDescription(state); } List<ObixObject> chosenObjects = Collections.synchronizedList(new ArrayList<>()); for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { r.getObixObject() .getParameter1() .setParameterType((String) r.getParam1TypeComboBox().getSelectedItem()); r.getObixObject() .getParameter2() .setParameterType((String) r.getParam2TypeComboBox().getSelectedItem()); chosenObjects.add(r.getObixObject()); if (!r.getParam1UnitTextField().getText().isEmpty()) { r.getObixObject() .getParameter1() .setParameterUnit(r.getParam1UnitTextField().getText()); } if (!r.getParam2UnitTextField().getText().isEmpty()) { r.getObixObject() .getParameter2() .setParameterUnit(r.getParam2UnitTextField().getText()); } } representationRows.clear(); cards.removeAll(); JScrollPane scrollPane = new JScrollPane(interactionWindow(chosenObjects)); scrollPane.getVerticalScrollBar().setUnitIncrement(16); scrollPane.setBorder(new EmptyBorder(20, 20, 20, 20)); cards.add(scrollPane); // Display the window. mainFrame.pack(); } }; acceptButton.addActionListener(acceptAction); return pane; }
/** * This method represents the window in which the preferred obix components can be chosen. * * @return The container in which the preferred obix components can be chosen. */ private Container chooseComponents() { Container pane = new Container(); pane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 1; c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; c.insets = new Insets(5, 5, 5, 5); registeredColibriChannelCheckBox = new JCheckBox("IS REGISTERD ON COLIBRI SEMANTIC CORE"); commandFactory.addCommand( () -> registeredColibriChannelCheckBox.setSelected( connector.getColibriChannel().getRegistered())); Font regF = new Font("Courier", Font.BOLD, 40); registeredColibriChannelCheckBox.setFont(regF); /** * Listener for the checkbox which indicates, if the obix connector is registered at colibri. */ registeredColibriChannelCheckBox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (!connector.getColibriChannel().getRegistered()) { connector.getColibriChannel().send(ColibriMessage.createRegisterMessage(connector)); } } else { if (connector.getColibriChannel().getRegistered()) { connector .getColibriChannel() .send(ColibriMessage.createDeregisterMessage(connector)); } } } }); pane.add(registeredColibriChannelCheckBox, c); Font titelF = new Font("Courier", Font.BOLD, 30); title = new JLabel("Please choose the components you want to work with"); title.setFont(titelF); c.gridy++; pane.add(title, c); JTextField searchTextField = new JTextField("Search for a component"); c.weightx = 1; c.weighty = 1; c.gridx++; pane.add(searchTextField, c); c.weightx = 0.25; c.weighty = 0.25; c.gridwidth = 1; c.gridx++; JButton searchButton = new JButton("Search"); pane.add(searchButton, c); JCheckBox markAllCheckbox = new JCheckBox("Mark all components"); c.gridy++; c.gridy++; pane.add(markAllCheckbox, c); for (String s : lobby.getObservedObjectsLists().keySet()) { if (!s.equals("all")) { List<ObixObject> objects = lobby.getObservedObjectsLists().get(s); JLabel header = new JLabel(s); Font headerF = new Font("Courier", Font.BOLD, 25); header.setFont(headerF); c.gridx = 0; c.gridy++; pane.add(header, c); for (ObixObject o : objects) { JCheckBox chooseCheckBox = new JCheckBox(o.getObixUri()); JPanel innerPanel = new JPanel(); innerPanel.setLayout(new FlowLayout(0, 0, 0)); innerPanel.add(chooseCheckBox); c.gridx = 0; c.gridwidth = 10; c.gridy++; pane.add(innerPanel, c); representationRows.add(new RepresentationRow(o, chooseCheckBox)); } } } JButton acceptButton = new JButton("Accept"); c.gridx = 0; c.gridy++; pane.add(acceptButton, c); /** Accept button listener */ Action acceptAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { List<ObixObject> chosenObjects = Collections.synchronizedList(new ArrayList<>()); ; for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { if (r.getChooseCheckbox().isSelected()) { chosenObjects.add(r.getObixObject()); } } representationRows.clear(); cards.removeAll(); JScrollPane scrollPane = new JScrollPane(chooseParameters(chosenObjects)); scrollPane.getVerticalScrollBar().setUnitIncrement(16); scrollPane.setBorder(new EmptyBorder(20, 20, 20, 20)); cards.add(scrollPane); // Display the window. mainFrame.pack(); } }; acceptButton.addActionListener(acceptAction); /** Search function listener */ Action searchAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { String searchText = searchTextField.getText(); for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { if (r.getChooseCheckbox().getText().contains(searchText)) { r.getChooseCheckbox().setForeground(Color.blue); } else { r.getChooseCheckbox().setForeground(Color.black); } r.getChooseCheckbox().revalidate(); r.getChooseCheckbox().repaint(); } } }; searchTextField.addActionListener(searchAction); searchButton.addActionListener(searchAction); /** Mark all components function listener */ Action markAllAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) { r.getChooseCheckbox().setSelected(true); } } }; markAllCheckbox.addActionListener(markAllAction); return pane; }
public static void addComponentsToPane(Container pane) { if (RIGHT_TO_LEFT) { pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); } String sample = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " + "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi" + " ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit" + " in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur " + "sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit " + "anim id est laborum."; JButton button; pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); if (shouldFill) { // natural height, maximum width c.fill = GridBagConstraints.HORIZONTAL; } button = new JButton("Button 1"); if (shouldWeightX) { c.weightx = 0.5; } c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; pane.add(button, c); button = new JButton("Button 2"); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5; c.gridx = 1; c.gridy = 0; pane.add(button, c); /*button = new JButton("Button 3"); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0.5; c.gridx = 2; c.gridy = 0; pane.add(button, c);*/ button = new JButton("Long-Named Button 4"); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 40; // make this component tall c.weightx = 0.0; c.gridwidth = 2; c.gridx = 0; c.gridy = 1; pane.add(button, c); button = new JButton("5"); c.fill = GridBagConstraints.HORIZONTAL; c.ipady = 0; // reset to default c.weighty = 1.0; // request any extra vertical space c.anchor = GridBagConstraints.PAGE_END; // bottom of space c.insets = new Insets(10, 0, 0, 0); // top padding c.gridx = 1; // aligned with button 2 c.gridwidth = 2; // 2 columns wide c.gridy = 2; // third row pane.add(button, c); JTextArea twitArea = new JTextArea(sample, 6, 20); twitArea.setFont(new Font("Roman", Font.BOLD, 20)); twitArea.setLineWrap(true); twitArea.setWrapStyleWord(true); twitArea.setOpaque(false); twitArea.setEditable(false); twitArea.setForeground(Color.white); GridBagConstraints twitc = new GridBagConstraints(); twitc.gridy = 0; twitc.gridx = 2; twitc.gridheight = 2; pane.add(twitArea, twitc); }
public static void addComponentsToPane(Container pane) { if (RIGHT_TO_LEFT) { pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); } int fila = 0; pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); // c.insets = new Insets(10,10,10,10); //top padding c.insets = new Insets(5, 5, 5, 5); // top padding if (shouldFill) { // natural height, maximum width c.fill = GridBagConstraints.HORIZONTAL; } label = new JLabel("Acuerdo:"); GridBagConstraints c1 = (GridBagConstraints) c.clone(); c1.fill = GridBagConstraints.HORIZONTAL; c1.gridx = 0; c1.gridy = fila; label.setBounds(0, 0, 100, 60); pane.add(label, c1); jtf = new JTextField(); GridBagConstraints c2 = (GridBagConstraints) c.clone(); c2.fill = GridBagConstraints.HORIZONTAL; c2.gridx = 1; c2.gridy = fila; jtf.setBounds(0, 0, 100, 60); pane.add(jtf, c2); fila++; jtaFicheros = new JTextArea(5, 30); GridBagConstraints c3 = (GridBagConstraints) c.clone(); c3.fill = GridBagConstraints.HORIZONTAL; c3.gridx = 0; c3.gridwidth = 2; c3.gridy = fila; jtaFicheros.setBounds(0, 0, 100, 60); scrollingFiles = new JScrollPane(jtaFicheros); pane.add(scrollingFiles, c3); btnClear = new JButton("Borra ficheros a tratar"); GridBagConstraints c4 = (GridBagConstraints) c.clone(); c4.fill = GridBagConstraints.HORIZONTAL; c4.gridx = 2; // aligned with button 2 c4.gridwidth = 1; // 2 columns wide c4.gridy = fila; // third row btnClear.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { jtaFicheros.setText(""); } }); pane.add(btnClear, c4); btnGetFiles = new JButton("Localizar ficheros..."); GridBagConstraints c5 = (GridBagConstraints) c.clone(); c5.fill = GridBagConstraints.HORIZONTAL; c5.weightx = 0.5; c5.gridx = 3; c5.gridy = fila; btnGetFiles.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { localizarFicheros(); // code to execute when button is pressed } private void localizarFicheros() { JFileChooser chooser; String choosertitle = "Pepe"; chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle(choosertitle); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(true); // // disable the "All files" option. // chooser.setAcceptAllFileFilterUsed(false); // if (chooser.showOpenDialog(btnGetFiles) == JFileChooser.APPROVE_OPTION) { System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); // System.out.println("getSelectedFile() : " + // chooser.getSelectedFile()); File[] ficheros = chooser.getSelectedFiles(); for (int i = 0; i < ficheros.length; i++) { System.out.println("getSelectedFiles() : " + ficheros[i].getAbsolutePath()); jtaFicheros.append(ficheros[i].getAbsolutePath() + "\n"); } // System.out.println("getSelectedFile() : " + // chooser.getSelectedFiles()); } else { System.out.println("No Selection "); } } }); pane.add(btnGetFiles, c5); fila++; jcbBorrarTablas = new JCheckBox("Borrar Tablas"); GridBagConstraints c6 = (GridBagConstraints) c.clone(); c6.fill = GridBagConstraints.HORIZONTAL; c6.gridx = 0; // aligned with button 2 c6.gridwidth = 4; // 2 columns wide c6.gridy = fila; // third row // pane.add(jcbBorrarTablas, c); // fila++; jcbDetalleLlamadas = new JCheckBox("Incluir detalle de llamadas? (Reg.702010)"); GridBagConstraints c7 = (GridBagConstraints) c.clone(); c7.fill = GridBagConstraints.HORIZONTAL; c7.gridx = 0; // aligned with button 2 c7.gridwidth = 4; // 2 columns wide c7.gridy = fila; // third row pane.add(jcbDetalleLlamadas, c7); fila++; jcbDetalleLlamadasRI = new JCheckBox("Incluir detalle de llamadas Red Inteligente? (Reg.702020)"); GridBagConstraints c8 = (GridBagConstraints) c.clone(); c8.fill = GridBagConstraints.HORIZONTAL; c8.gridx = 0; // aligned with button 2 c8.gridwidth = 4; // 2 columns wide c8.gridy = fila; // third row pane.add(jcbDetalleLlamadasRI, c8); fila++; jtaResultado = new JTextArea(6, 50); GridBagConstraints c9 = (GridBagConstraints) c.clone(); c9.fill = GridBagConstraints.HORIZONTAL; c9.gridx = 0; c9.gridwidth = 3; c9.gridy = fila; jtaResultado.setBounds(0, 0, 100, 60); // jtaResultado. scrollingResult = new JScrollPane( jtaResultado, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); pane.add(scrollingResult, c9); fila++; jlbHost = new JLabel("Host"); GridBagConstraints c10 = (GridBagConstraints) c.clone(); c10.fill = GridBagConstraints.HORIZONTAL; c10.gridx = 0; c10.gridwidth = 1; c10.gridy = fila; jlbHost.setBounds(0, 0, 100, 40); pane.add(jlbHost, c10); jlbDB = new JLabel("DB"); GridBagConstraints c11 = (GridBagConstraints) c.clone(); c11.fill = GridBagConstraints.HORIZONTAL; c11.gridx = 1; c11.gridwidth = 1; c11.gridy = fila; jlbDB.setBounds(0, 0, 100, 40); pane.add(jlbDB, c11); jlbUser = new JLabel("Usuario"); GridBagConstraints c12 = (GridBagConstraints) c.clone(); c12.fill = GridBagConstraints.HORIZONTAL; c12.gridx = 2; c12.gridwidth = 1; c12.gridy = fila; jlbUser.setBounds(0, 0, 100, 40); pane.add(jlbUser, c12); jlbPass = new JLabel("Contraseña"); GridBagConstraints c13 = (GridBagConstraints) c.clone(); c13.fill = GridBagConstraints.HORIZONTAL; c13.gridx = 3; c13.gridwidth = 1; c13.gridy = fila; jlbPass.setBounds(0, 0, 100, 40); pane.add(jlbPass, c13); fila++; jtfHost = new JTextField(iniValues.getProperty("host")); GridBagConstraints c14 = (GridBagConstraints) c.clone(); c14.fill = GridBagConstraints.HORIZONTAL; c14.gridx = 0; c14.gridwidth = 1; c14.gridy = fila; jtfHost.setBounds(0, 0, 100, 60); pane.add(jtfHost, c14); jtfDB = new JTextField(iniValues.getProperty("db")); GridBagConstraints c15 = (GridBagConstraints) c.clone(); c15.fill = GridBagConstraints.HORIZONTAL; c15.gridx = 1; c15.gridwidth = 1; c15.gridy = fila; jtfDB.setBounds(0, 0, 100, 60); pane.add(jtfDB, c15); jtfUser = new JTextField(iniValues.getProperty("user")); GridBagConstraints c16 = (GridBagConstraints) c.clone(); c16.fill = GridBagConstraints.HORIZONTAL; c16.gridx = 2; c16.gridwidth = 1; c16.gridy = fila; jtfUser.setBounds(0, 0, 100, 60); pane.add(jtfUser, c16); jpfPass = new JPasswordField(iniValues.getProperty("pass")); GridBagConstraints c17 = (GridBagConstraints) c.clone(); c17.fill = GridBagConstraints.HORIZONTAL; c17.gridx = 3; c17.gridwidth = 1; c17.gridy = fila; jpfPass.setBounds(0, 0, 100, 60); pane.add(jpfPass, c17); fila++; btnExecute = new JButton("Ejecuta"); GridBagConstraints c18 = (GridBagConstraints) c.clone(); c18.fill = GridBagConstraints.HORIZONTAL; c18.gridx = 3; // aligned with button 2 c18.gridwidth = 1; // 2 columns wide c18.gridy = fila; // third row btnExecute.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { procesaFicheros(); } private void procesaFicheros() { try { Split977 sp = new Split977(); sp.setAcuerdo(jtf.getText()); String[] f = jtaFicheros.getText().split("\n"); JOptionPane.showMessageDialog(frame, "Número de ficheros:" + f.length); sp.setFicheros(f); sp.setBorrarTablas(jcbBorrarTablas.isSelected()); sp.setDetalleLlamadas(jcbDetalleLlamadas.isSelected()); sp.setDetalleLlamadasRI(jcbDetalleLlamadasRI.isSelected()); for (int i = 0; i < f.length; i++) { jtaResultado.append(f[i] + "\n"); } sp.setDbHost(jtfHost.getText()); sp.setDbName(jtfDB.getText()); sp.setDbUser(jtfUser.getText()); String pass = new String(jpfPass.getPassword()); sp.setDbPass(pass); System.out.println(pass); jtaResultado.append(sp.execute()); // JOptionPane.showConfirmDialog(frame, "Finito!"); JOptionPane.showMessageDialog(frame, "Finito!"); } catch (Exception e) { // TODO: handle exception } } }); pane.add(btnExecute, c18); }