private void jbInit() throws Exception { box1 = Box.createVerticalBox(); this.getContentPane().setLayout(borderLayout1); close.setText("Close"); close.addActionListener(new CellHelpWindow_close_actionAdapter(this)); jLabel1.setText("Recommendation"); jLabel2.setText("Description"); jPanel1.setLayout(borderLayout2); jPanel2.setLayout(borderLayout3); description.setText("jTextPane1"); description.setContentType("text/html"); scp1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scp1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); scp1.setToolTipText(""); recom.setText(""); recom.setContentType("text/html"); this.getContentPane().add(box1, BorderLayout.CENTER); box1.add(jPanel1, null); box1.add(jPanel2, null); this.getContentPane().add(jPanel3, BorderLayout.SOUTH); jPanel3.add(close, null); jPanel2.add(jLabel1, BorderLayout.NORTH); jPanel2.add(scp2, BorderLayout.CENTER); scp2.getViewport().add(recom, null); jPanel2.add(scp2, BorderLayout.CENTER); jPanel1.add(jLabel2, BorderLayout.NORTH); jPanel1.add(scp1, BorderLayout.CENTER); scp1.getViewport().add(description, null); }
/** 生成面板内容 */ private void createContent() { contentPanel = new JPanel(new BorderLayout()); panel.add(contentPanel, BorderLayout.CENTER); Box message = Box.createVerticalBox(); message.setBorder(BorderFactory.createEtchedBorder()); dateImg = new JLabel(new ImageIcon(TMFrame.class.getResource("/images/calendar.gif"))); String today = Today.getYear() + "年" + Today.getMonth() + "月" + Today.getDate() + "日"; date = new JLabel(today); date.setFont(font); week = new JLabel(Today.getWeek()); week.setFont(font); nameImg = new JLabel(new ImageIcon(TMFrame.class.getResource("/images/role.png"))); name = new JLabel(staffInfo.getStaffName()); name.setFont(font); role = new JLabel("总经理"); role.setFont(font); Box messageTop = Box.createVerticalBox(); Box messageCenter = Box.createHorizontalBox(); Box messageBottom = Box.createVerticalBox(); messageTop.add(Box.createVerticalStrut(1)); messageCenter.add(Box.createHorizontalStrut(5)); messageCenter.add(dateImg); messageCenter.add(Box.createHorizontalStrut(2)); messageCenter.add(date); messageCenter.add(Box.createHorizontalStrut(20)); messageCenter.add(week); messageCenter.add(Box.createHorizontalStrut(50)); messageCenter.add(nameImg); messageCenter.add(Box.createHorizontalStrut(2)); messageCenter.add(name); messageCenter.add(Box.createHorizontalStrut(20)); messageCenter.add(role); messageCenter.add(Box.createHorizontalGlue()); messageBottom.add(Box.createVerticalStrut(1)); message.add(messageTop); message.add(messageCenter); message.add(messageBottom); contentPanel.add(message, BorderLayout.NORTH); }
// Center given button in a box, centered vertically and 6 pixels on left and right private Box createBoxForButton(JButton button) { Box buttonRow = Box.createHorizontalBox(); buttonRow.add(Box.createHorizontalStrut(6)); buttonRow.add(button); buttonRow.add(Box.createHorizontalStrut(6)); Box buttonBox = Box.createVerticalBox(); buttonBox.add(Box.createVerticalGlue()); buttonBox.add(buttonRow); buttonBox.add(Box.createVerticalGlue()); return buttonBox; }
// Method to build the dialog box for help. private void buildDialogBox() { // Set the JDialog window properties. setTitle("Stack Trace Detail"); setResizable(false); setSize(dialogWidth, dialogHeight); // Append the stack trace output to the display area. displayArea.append(eStackTrace); // Create horizontal and vertical scrollbars for box. displayBox = Box.createHorizontalBox(); displayBox = Box.createVerticalBox(); // Add a JScrollPane to the Box. displayBox.add(new JScrollPane(displayArea)); // Define behaviors of container. c.setLayout(null); c.add(displayBox); c.add(okButton); // Set scroll pane bounds. displayBox.setBounds( (dialogWidth / 2) - ((displayAreaWidth / 2) + 2), (top + (offsetMargin / 2)), displayAreaWidth, displayAreaHeight); // Set the behaviors, bounds and action listener for the button. okButton.setBounds( (dialogWidth / 2) - (buttonWidth / 2), (displayAreaHeight + offsetMargin), buttonWidth, buttonHeight); // Set the font to the platform default Font for the object with the // properties of bold and font size of 11. okButton.setFont(new Font(okButton.getFont().getName(), Font.BOLD, 11)); // The class implements the ActionListener interface and therefore // provides an implementation of the actionPerformed() method. When a // class implements ActionListener, the instance handler returns an // ActionListener. The ActionListener then performs actionPerformed() // method on an ActionEvent. okButton.addActionListener(this); // Set the screen and display dialog window in relation to screen size. setLocation((dim.width / 2) - (dialogWidth / 2), (dim.height / 2) - (dialogHeight / 2)); // Display JDialog. show(); } // End of buildDialogBox method.
private JPanel createSelectOutputDirectoryUI() { JPanel container = new JPanel(new BorderLayout()); setupFileChooser(); outputFileLocation = new FileSelectionPanel("", fileChooser); Box fileLocationContainer = Box.createVerticalBox(); fileLocationContainer.add( UIHelper.wrapComponentInPanel(new JLabel(chooseOutputLocation, JLabel.LEFT))); fileLocationContainer.add(Box.createVerticalStrut(5)); fileLocationContainer.add(outputFileLocation); container.add(fileLocationContainer, BorderLayout.NORTH); return container; }
private JComponent createToolPanel() { JComponent box = Box.createVerticalBox(); JCheckBox button = new JCheckBox(disablingItem.getText()); button.setModel(disablingItem.getModel()); box.add(Box.createGlue()); box.add(button); box.add(Box.createGlue()); JRadioButton blur = new JRadioButton(blurItem.getText()); blur.setModel(blurItem.getModel()); box.add(blur); JRadioButton emboss = new JRadioButton(embossItem.getText()); emboss.setModel(embossItem.getModel()); box.add(emboss); JRadioButton translucent = new JRadioButton(busyPainterItem.getText()); translucent.setModel(busyPainterItem.getModel()); box.add(translucent); box.add(Box.createGlue()); return box; }
public java.awt.Container createControlPanel() { java.awt.Container panel2 = Box.createVerticalBox(); panel2 = super.createControlPanel(); brainPlay = new JCheckBox("Brain Play", false); if (testMode) brainPlay.setSelected(true); panel2.add(brainPlay); JPanel row2 = new JPanel(); // ADVERSARY slider row2.add(Box.createVerticalStrut(12)); row2.add(new JLabel("Adversary:")); adversary = new JSlider(0, 100, 0); // min, max, current adversary.setPreferredSize(new Dimension(100, 15)); row2.add(adversary); JPanel text = new JPanel(); text.add(adStat = new JLabel(adversaryOff)); panel2.add(text); panel2.add(row2); JPanel row3 = new JPanel(); // Mr. Happy slider row3.add(Box.createVerticalStrut(12)); row3.add(new JLabel("CELAB")); happy = new JSlider(0, 100, 0); // min, max, current happy.setPreferredSize(new Dimension(100, 15)); row3.add(happy); JPanel text2 = new JPanel(); text2.add(adHappy = new JLabel(happyOff)); panel2.add(text2); panel2.add(row3); return (panel2); }
public MainPanel() { super(new BorderLayout()); l1.setToolTipText("Test1"); l2.setToolTipText("Test2"); l3.setToolTipText("<html><img src='" + url + "'>Test3</html>"); JPanel p1 = new JPanel(new BorderLayout()); p1.setBorder(BorderFactory.createTitledBorder("javax.swing.Timer")); p1.add(l1); JPanel p2 = new JPanel(new BorderLayout()); p2.setBorder(BorderFactory.createTitledBorder("Animated Gif")); p2.add(l2, BorderLayout.NORTH); p2.add(l3, BorderLayout.SOUTH); Box box = Box.createVerticalBox(); box.add(p1); box.add(Box.createVerticalStrut(20)); box.add(p2); box.add(Box.createVerticalGlue()); add(box); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setPreferredSize(new Dimension(320, 240)); }
public MainPanel() { super(new BorderLayout()); setSilderUI(slider1); setSilderUI(slider2); Box box1 = Box.createHorizontalBox(); box1.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); box1.add(new JSlider(SwingConstants.VERTICAL, 0, 1000, 100)); box1.add(Box.createHorizontalStrut(20)); box1.add(slider1); box1.add(Box.createHorizontalGlue()); Box box2 = Box.createVerticalBox(); box2.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 20)); box2.add(makeTitledPanel("Default", new JSlider(0, 1000, 100))); box2.add(Box.createVerticalStrut(20)); box2.add(makeTitledPanel("Jump to clicked position", slider2)); box2.add(Box.createVerticalGlue()); add(box1, BorderLayout.WEST); add(box2); // setBorder(BorderFactory.createEmptyBorder(5, 20, 5, 10)); setPreferredSize(new Dimension(320, 240)); }
public CPLayersPalette(CPCommonController controller) { super(controller); title = "Layers"; // Widgets creation Image icons = controller.loadImage("smallicons.png"); addButton = new CPIconButton(icons, 16, 16, 0, 1); addButton.addController(this); addButton.setCPActionCommand(CPCommandId.AddLayer); removeButton = new CPIconButton(icons, 16, 16, 1, 1); removeButton.addController(this); removeButton.setCPActionCommand(CPCommandId.RemoveLayer); alphaSlider = new CPAlphaSlider(); blendCombo = new JComboBox<String>(modeNames); blendCombo.addActionListener(this); lw = new CPLayerWidget(); renameField = new CPRenameField(); lw.add(renameField); scrollPane = new JScrollPane(lw); cbSampleAllLayers = new JCheckBox("Sample All Layers"); cbSampleAllLayers.setSelected(controller.artwork.isSampleAllLayers()); cbSampleAllLayers.addItemListener(this); cbLockAlpha = new JCheckBox("Lock Alpha"); cbLockAlpha.setSelected(controller.artwork.isLockAlpha()); cbLockAlpha.addItemListener(this); // Layout // Add/Remove Layer Box hb = Box.createHorizontalBox(); hb.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); hb.add(addButton); hb.add(Box.createRigidArea(new Dimension(5, 0))); hb.add(removeButton); hb.add(Box.createHorizontalGlue()); // blend mode blendCombo.setPreferredSize(new Dimension(100, 16)); Box hb2 = Box.createHorizontalBox(); hb2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); hb2.add(blendCombo); hb2.add(Box.createHorizontalGlue()); // layer opacity alphaSlider.setPreferredSize(new Dimension(100, 16)); alphaSlider.setMaximumSize(new Dimension(100, 16)); Box hb3 = Box.createHorizontalBox(); hb3.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); hb3.add(alphaSlider); hb3.add(Box.createRigidArea(new Dimension(0, 16))); hb3.add(Box.createHorizontalGlue()); Box hb4 = Box.createHorizontalBox(); hb4.add(cbSampleAllLayers); hb4.add(Box.createHorizontalGlue()); Box hb5 = Box.createHorizontalBox(); hb5.add(cbLockAlpha); hb5.add(Box.createHorizontalGlue()); Box vb = Box.createVerticalBox(); vb.add(hb2); vb.add(hb3); vb.add(hb4); vb.add(hb5); setLayout(new BorderLayout()); add(scrollPane, BorderLayout.CENTER); add(vb, BorderLayout.PAGE_START); add(hb, BorderLayout.PAGE_END); // Set initial values CPArtwork artwork = controller.getArtwork(); alphaSlider.setValue(artwork.getActiveLayer().getAlpha()); // add listeners addListener(); // validate(); // pack(); }
/** 人员管理 */ private void DMManage() { print.setEnabled(true); printAction.setEnabled(true); // 删除原有内容 if (displayPanel != null && tips != null) { contentPanel.remove(displayPanel); contentPanel.remove(tips); validate(); repaint(); } staffContent = GetInfo.getStaffInfo(); staffTitle = GetInfo.getStaffTitle(); content = VectorFilter.doubleFilter(VectorFilter.STAFFFILTER, staffContent); content = VectorFilter.dataFilter(1, staffInfo.getStaffName(), content); // 过滤自己 content = VectorFilter.positionFilter(4, "部门经理", content); // 过滤得到部门经理 header = VectorFilter.singleFilter(VectorFilter.STAFFFILTER, staffTitle); // 建立显示区面板 displayPanel = new JPanel(new BorderLayout()); displayPanel.setBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "人员管理")); // 加入JTable setTable(content, header); scrollPanel = new JScrollPane(table); displayPanel.add(scrollPanel, BorderLayout.CENTER); // 加入功能区 Box functionBox = Box.createVerticalBox(); Box functionTop = Box.createVerticalBox(); Box functionCenter = Box.createHorizontalBox(); Box functionUnderCenterTop = Box.createVerticalBox(); Box functionUnderCenter = Box.createHorizontalBox(); Box functionBottom = Box.createVerticalBox(); functionTop.add(Box.createVerticalStrut(10)); functionUnderCenterTop.add(Box.createVerticalStrut(10)); functionBottom.add(Box.createVerticalStrut(20)); JLabel sift = new JLabel("筛选"); sift.setFont(font); siftKey.setText(""); JLabel fun = new JLabel("功能"); fun.setFont(font); viewDM.setText("查看"); viewDM.setFont(font); addDM.setText("增加"); addDM.setFont(font); deleteDM.setText("删除"); deleteDM.setFont(font); modifyDM.setText("修改"); modifyDM.setFont(font); modifyDMPassword.setText("设置密码"); modifyDMPassword.setFont(font); hideOutDate.setFont(font); functionCenter.add(Box.createHorizontalStrut(2)); functionCenter.add(sift); functionCenter.add(Box.createHorizontalStrut(10)); functionCenter.add(siftKey); functionCenter.add(Box.createHorizontalStrut(100)); functionCenter.add(hideOutDate); functionCenter.add(Box.createHorizontalStrut(180)); functionUnderCenter.add(Box.createHorizontalStrut(2)); functionUnderCenter.add(fun); functionUnderCenter.add(Box.createHorizontalStrut(10)); functionUnderCenter.add(viewDM); functionUnderCenter.add(Box.createHorizontalStrut(10)); functionUnderCenter.add(addDM); functionUnderCenter.add(Box.createHorizontalStrut(10)); functionUnderCenter.add(deleteDM); functionUnderCenter.add(Box.createHorizontalStrut(10)); functionUnderCenter.add(modifyDM); functionUnderCenter.add(Box.createHorizontalStrut(10)); functionUnderCenter.add(modifyDMPassword); functionUnderCenter.add(Box.createHorizontalGlue()); functionBox.add(functionTop); functionBox.add(functionCenter); functionBox.add(functionUnderCenterTop); functionBox.add(functionUnderCenter); functionBox.add(functionBottom); displayPanel.add(functionBox, BorderLayout.SOUTH); // 建立提示区面板 tips = Box.createHorizontalBox(); tips.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "系统提示")); tips.add(Box.createHorizontalStrut(200)); // 加入系统提示 // TODO 加入系统提示信息 contentPanel.add(displayPanel, BorderLayout.CENTER); contentPanel.add(tips, BorderLayout.EAST); validate(); }
private void createUI() { try { this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); Border border = BorderFactory.createEmptyBorder(5, 5, 5, 5); this.setBorder(border); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); Box box = Box.createVerticalBox(); String[] args = new String[7]; args[0] = "fileSelector"; // Name args[1] = "file selector"; // Description args[2] = "Input shapefile:"; // getTextValue(el, "LabelText"); args[3] = Integer.toString(DialogFile.MODE_OPEN); args[4] = "true"; // getTextValue(el, "ShowButton").toLowerCase(); args[5] = "ShapeFile (*.shp), SHP"; // getTextValue(el, "Filter"); args[6] = "false"; // getTextValue(el, "MakeOptional").toLowerCase(); df = new DialogFile(hostDialog); df.setArgs(args); df.addPropertyChangeListener("value", this); df.setTextFieldActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { okPressed(); } }); box.add(df); // list.addListSelectionListener(this); Box hbox = Box.createHorizontalBox(); lbl = new JLabel(label); hbox.add(lbl); hbox.add(Box.createHorizontalGlue()); box.add(hbox); box.add(Box.createHorizontalStrut(5)); list = new JList(); if (!multiSelect) { list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else { // true list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } updateList(); JScrollPane scroller1 = new JScrollPane(list); box.add(scroller1); box.setToolTipText(description); this.setToolTipText(description); list.setToolTipText(description); lbl.setToolTipText(description); panel.add(box); this.add(panel); this.add(Box.createHorizontalGlue()); this.setMaximumSize(new Dimension(2500, 140)); this.setPreferredSize(new Dimension(350, 140)); } catch (Exception e) { System.out.println(e.getCause()); } }
public TestXEmbedServer(boolean manual) { // Enable testing extensions in XEmbed server System.setProperty("sun.awt.xembed.testing", "true"); f = new Frame("Main frame"); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { synchronized (TestXEmbedServer.this) { TestXEmbedServer.this.notifyAll(); } dummy.dispose(); f.dispose(); } }); f.setLayout(new BorderLayout()); Container bcont = new Container(); toFocus = new Button("Click to focus server"); final TextField tf = new TextField(20); tf.setName("0"); DragSource ds = new DragSource(); final DragSourceListener dsl = new DragSourceAdapter() { public void dragDropEnd(DragSourceDropEvent dsde) {} }; final DragGestureListener dgl = new DragGestureListener() { public void dragGestureRecognized(DragGestureEvent dge) { dge.startDrag(null, new StringSelection(tf.getText()), dsl); } }; ds.createDefaultDragGestureRecognizer(tf, DnDConstants.ACTION_COPY, dgl); final DropTargetListener dtl = new DropTargetAdapter() { public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_COPY); try { tf.setText( tf.getText() + (String) dtde.getTransferable().getTransferData(DataFlavor.stringFlavor)); } catch (Exception e) { } } }; final DropTarget dt = new DropTarget(tf, dtl); Button b_add = new Button("Add client"); b_add.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { addClient(); } }); Button b_remove = new Button("Remove client"); b_remove.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (clientCont.getComponentCount() != 0) { clientCont.remove(clientCont.getComponentCount() - 1); } } }); b_close = new JButton("Close modal dialog"); b_close.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { modal_d.dispose(); } }); b_modal = new Button("Show modal dialog"); b_modal.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { modal_d = new JDialog(f, "Modal dialog", true); modal_d.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); modal_d.setBounds(0, 100, 200, 50); modal_d.getContentPane().add(b_close); modal_d.validate(); modal_d.show(); } }); bcont.add(tf); bcont.add(toFocus); bcont.add(b_add); bcont.add(b_remove); bcont.add(b_modal); if (manual) { Button pass = new Button("Pass"); pass.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { passed = true; synchronized (TestXEmbedServer.this) { TestXEmbedServer.this.notifyAll(); } } }); bcont.add(pass); Button fail = new Button("Fail"); fail.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { passed = false; synchronized (TestXEmbedServer.this) { TestXEmbedServer.this.notifyAll(); } } }); bcont.add(fail); } b_modal.setName("2"); bcont.setLayout(new FlowLayout()); f.add(bcont, BorderLayout.NORTH); clientCont = Box.createVerticalBox(); f.add(clientCont, BorderLayout.CENTER); dummy = new JFrame("Dummy"); dummy.getContentPane().add(new JButton("Button")); dummy.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); dummy.setBounds(0, VERTICAL_POSITION, 100, 100); dummy.setVisible(true); f.setBounds(300, VERTICAL_POSITION, 800, 300); f.setVisible(true); }
/** * 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; }
/** Install the Rotate-Button into the toolbar */ private void installRotateButton() { URL imgURL = ClassLoader.getSystemResource("ch/tbe/pics/rotate.gif"); ImageIcon rotateIcon = new ImageIcon(imgURL); rotate = new JButton(rotateIcon); rotate.setEnabled(false); rotatePanel = new JToolBar(); rotatePanel.setOrientation(1); rotatePanel.setLayout(new BorderLayout(0, 1)); rotateSlider = new JSlider(); rotateSlider.setMaximum(359); rotateSlider.setMinimum(0); rotateSlider.setMaximumSize(new Dimension(100, 100)); rotateSlider.setOrientation(1); Box box = Box.createVerticalBox(); sliderValue.setPreferredSize(new Dimension(30, 20)); rotateSlider.setAlignmentY(Component.TOP_ALIGNMENT); box.add(sliderValue); box.add(rotateSlider); sliderValue.setAlignmentY(Component.TOP_ALIGNMENT); rotatePanel.add(box, BorderLayout.NORTH); sliderValue.addFocusListener( new FocusListener() { private int oldValue = 0; public void focusGained(FocusEvent arg0) { oldValue = Integer.parseInt(sliderValue.getText()); } public void focusLost(FocusEvent arg0) { int newValue = 0; try { newValue = Integer.parseInt(sliderValue.getText()); } catch (Exception ex) { sliderValue.setText(Integer.toString(oldValue)); } if (newValue >= 0 && newValue <= 359) { RotateCommand rc = new RotateCommand(board.getSelectedItems()); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(rc); TBE.getInstance().addCommands(actCommands); rotateSlider.setValue(newValue); } else { sliderValue.setText(Integer.toString(oldValue)); } } }); rotateSlider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (board.getSelectionCount() == 1 && board.getSelectionCells()[0] instanceof ShapeItem) { sliderValue.setText(Integer.toString(rotateSlider.getValue())); ShapeItem s = (ShapeItem) board.getSelectionCells()[0]; board.removeItem(new ItemComponent[] {s}); s.setRotation(rotateSlider.getValue()); board.addItem(s); } } }); rotateSlider.addMouseListener( new MouseAdapter() { private int value; public void mousePressed(MouseEvent e) { value = rotateSlider.getValue(); } public void mouseReleased(MouseEvent e) { if (value != rotateSlider.getValue()) { RotateCommand rc = new RotateCommand(board.getSelectedItems()); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(rc); TBE.getInstance().addCommands(actCommands); rc.setRotation(value); } } }); rotate.setToolTipText(workingViewLabels.getString("rotate")); rotate.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (board.getSelectionCount() == 1 && board.getSelectedItems()[0] instanceof ShapeItem) { rotateSlider.setValue(((ShapeItem) board.getSelectedItems()[0]).getRotation()); } rotatePanel.setVisible(!rotatePanel.isVisible()); showRotate = !showRotate; } }); rotate.setContentAreaFilled(false); rotate.setBorderPainted(false); toolbar.add(rotate); rotatePanel.setVisible(false); this.add(rotatePanel, BorderLayout.EAST); }
/** Initializes all GUI components */ private void initComponents() { mainPanel = new JPanel(); editPanel = new JPanel(); editPanelLeft = new JPanel(); editPanelCenter = new JPanel(); editPanelRight = new JPanel(); tablePanel = new JPanel(); companyIdTextField = new JTextField(); companyIdTextField.setEditable(false); companyNameTextField = new JTextField(); urlTextField = new JTextField(); insuranceTypesTextField = new JTextField(); telephoneTextField = new JTextField(); percentageTextField = new JTextField(); percentageTextField.setToolTipText("<html>Only <b>numerical</b> values allowed</html>"); searchTextField = new JTextField(); searchTextField.setToolTipText( "<html>Use either <b>AND</b> or <b>OR</b> for combined search queries<br>You can also use <b>spaces</b> instead of <b>OR</b></html>"); generalDescriptionTextField = new JTextField(); companyIdLabel = new InsuranceCompanyLabel("ID"); companyNameLabel = new InsuranceCompanyLabel("Company"); urlLabel = new InsuranceCompanyLabel("Website"); insuranceTypesLabel = new InsuranceCompanyLabel("Insurance Types"); telephoneLabel = new InsuranceCompanyLabel("Telephone"); percentageLabel = new InsuranceCompanyLabel("Broker Percentage"); searchLabel = new InsuranceCompanyLabel("Search Insurance Types"); generalDescriptionLabel = new InsuranceCompanyLabel("General Description"); sortLabel = new InsuranceCompanyLabel("Sorting"); addInsuranceCompanyButton = new InsuranceCompanyButton("New Insurance Company", 190, 45); addInsuranceCompanyButton.setToolTipText( "<html>Create a new <b>empty</b> Insurance Company</html>"); saveInsuranceCompanyButton = new InsuranceCompanyButton("Save Insurance Company", 190, 45); saveInsuranceCompanyButton.setToolTipText( "<html>Save the <b>selected</b> Insurance Company<br>Hint: Press <b>Enter</b> to quickly save an entry</html>"); saveInsuranceCompanyButton.setDefaultCapable(true); getRootPane() .setDefaultButton( saveInsuranceCompanyButton); // Set the save button as default button, so quicker // editing by pressing Enter is possible deleteInsuranceCompanyButton = new InsuranceCompanyButton("Delete Insurance Company", 190, 45); deleteInsuranceCompanyButton.setToolTipText( "<html>Delete the <b>selected</b> Insurance Company</html>"); clearSearchButton = new InsuranceCompanyButton("x", 40, 35); clearSearchButton.setToolTipText("<html>Click to <b>clear</b> the search field</html>"); String[] sortStrategies = {"ID", "Company Name", "Percentage"}; sortComboBox = new JComboBox(sortStrategies); tableData = new InsuranceCompanyTableModel(model.getInsuranceCompanies()); insuranceCompaniesTable = new JTable(); insuranceCompanyScrollPane = new JScrollPane(insuranceCompaniesTable); // Set layout and add components to panels setLayout(new BorderLayout()); add(mainPanel, BorderLayout.CENTER); mainPanel.setLayout(new BorderLayout()); mainPanel.add(editPanel, BorderLayout.NORTH); editPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); editPanel.setLayout(new BorderLayout()); editPanel.add(editPanelLeft, BorderLayout.CENTER); editPanelLeft.setBorder(new EmptyBorder(0, 0, 5, 15)); editPanelLeft.setLayout(new GridLayout(4, 4, 5, 0)); editPanelLeft.add(companyIdLabel); editPanelLeft.add(companyNameLabel); editPanelLeft.add(urlLabel); editPanelLeft.add(telephoneLabel); editPanelLeft.add(companyIdTextField); editPanelLeft.add(companyNameTextField); editPanelLeft.add(urlTextField); editPanelLeft.add(telephoneTextField); editPanelLeft.add(percentageLabel); editPanelLeft.add(searchLabel); editPanelLeft.add(new JLabel()); editPanelLeft.add(sortLabel); editPanelLeft.add(percentageTextField); editPanelLeft.add(searchTextField); Container searchBox = Box.createVerticalBox(); searchBox.add(clearSearchButton); editPanelLeft.add(searchBox); editPanelLeft.add(sortComboBox); editPanel.add(editPanelRight, BorderLayout.EAST); Container box = Box.createVerticalBox(); box.add(saveInsuranceCompanyButton); box.add(Box.createVerticalStrut(5)); box.add(addInsuranceCompanyButton); box.add(Box.createVerticalStrut(5)); box.add(deleteInsuranceCompanyButton); editPanelRight.add(box); editPanel.add(editPanelCenter, BorderLayout.SOUTH); editPanelCenter.setLayout(new GridLayout(4, 1)); editPanelCenter.add(insuranceTypesLabel); editPanelCenter.add(insuranceTypesTextField); editPanelCenter.add(generalDescriptionLabel); editPanelCenter.add(generalDescriptionTextField); mainPanel.add(tablePanel, BorderLayout.CENTER); tablePanel.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEmptyBorder(10, 10, 10, 10), "Insurance Companies Overview")); tablePanel.setLayout(new BorderLayout()); tablePanel.add(insuranceCompanyScrollPane, BorderLayout.CENTER); setMinimumSize(new Dimension(800, 600)); setPreferredSize(new Dimension(900, 600)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); }
/** * Window for Control Monitor display in the Simulator. * * @author Alex Kurzhanskiy * @version $Id: WindowMonitorController.java 38 2010-02-08 22:59:00Z akurzhan $ */ public final class WindowMonitorController extends JInternalFrame implements ActionListener, ChangeListener { private static final long serialVersionUID = -4670962979656887216L; private MonitorControllerHWC myMonitor; private AbstractControllerComplex myController = null; private TreePane treePane; private JCheckBox cbEnabled = new JCheckBox("Enabled"); private boolean enabled = true; private JTable montable; private MonTableModel montablemodel = new MonTableModel(); private JTable ctrltable; private CtrlTableModel ctrltablemodel = new CtrlTableModel(); private JComboBox listCControllers; private JButton buttonProp = new JButton("Properties"); private static final String cmdCtrlList = "pressedCtrlList"; private static final String cmdCtrlProp = "pressedCtrlProp"; private Box confPanel = Box.createVerticalBox(); public WindowMonitorController() {} public WindowMonitorController(MonitorControllerHWC mntr, TreePane tpane) { super("Monitor: " + mntr.toString(), true, true, true, true); myMonitor = mntr; myController = myMonitor.getMyController(); treePane = tpane; enabled = myMonitor.isEnabled(); setSize(400, 500); int n = treePane.getInternalFrameCount(); setLocation(20 * n, 20 * n); AdapterWindowMonitorController listener = new AdapterWindowMonitorController(); addInternalFrameListener(listener); addComponentListener(listener); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); fillConfigurationPanel(); tabbedPane.add("Configuration", new JScrollPane(confPanel)); getContentPane().add(tabbedPane); } /** Generates Configuration tab. */ private void fillConfigurationPanel() { JPanel desc = new JPanel(new GridLayout(2, 0)); desc.setBorder(BorderFactory.createTitledBorder("Description")); desc.add( new JLabel("<html><font color=\"blue\">" + myMonitor.getDescription() + "</font></html>")); desc.add(cbEnabled); cbEnabled.setSelected(enabled); cbEnabled.addChangeListener(this); confPanel.add(desc); JPanel mlpanel = new JPanel(new GridLayout(1, 0)); mlpanel.setBorder(BorderFactory.createTitledBorder("Monitored Network Elements")); montable = new JTable(montablemodel); montable.setPreferredScrollableViewportSize(new Dimension(200, 100)); montable.getColumnModel().getColumn(0).setPreferredWidth(140); montable.getColumnModel().getColumn(1).setPreferredWidth(60); montable.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int row = montable.rowAtPoint(new Point(e.getX(), e.getY())); AbstractNetworkElement ne = null; if ((row >= 0) && (row < myMonitor.getPredecessors().size())) ne = myMonitor.getPredecessors().get(row); else return; treePane.actionSelected(ne, true); } return; } }); mlpanel.add(new JScrollPane(montable)); confPanel.add(mlpanel); JPanel cpanel = new JPanel(new GridLayout(1, 0)); cpanel.setBorder(BorderFactory.createTitledBorder("Controlleded Network Elements")); ctrltable = new JTable(ctrltablemodel); ctrltable.setPreferredScrollableViewportSize(new Dimension(200, 100)); ctrltable.getColumnModel().getColumn(0).setPreferredWidth(140); ctrltable.getColumnModel().getColumn(1).setPreferredWidth(60); ctrltable.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int row = ctrltable.rowAtPoint(new Point(e.getX(), e.getY())); AbstractNetworkElement ne = null; if ((row >= 0) && (row < myMonitor.getSuccessors().size())) ne = myMonitor.getSuccessors().get(row); else return; treePane.actionSelected(ne, true); } return; } }); cpanel.add(new JScrollPane(ctrltable)); confPanel.add(cpanel); JPanel pcl = new JPanel(new FlowLayout()); // controller list buttonProp.setEnabled(false); buttonProp.setActionCommand(cmdCtrlProp); buttonProp.addActionListener(this); pcl.setBorder(BorderFactory.createTitledBorder("Complex Controller")); buttonProp.setEnabled(false); listCControllers = new JComboBox(); listCControllers.addItem("None"); String[] ctrlClasses = myMonitor.getComplexControllerClasses(); for (int i = 0; i < ctrlClasses.length; i++) { if ((myController != null) && (myController.getClass().getName().compareTo(ctrlClasses[i]) == 0)) { listCControllers.addItem(myController); listCControllers.setSelectedIndex(i + 1); buttonProp.setEnabled(true); } else { try { Class cl = Class.forName(ctrlClasses[i]); AbstractControllerComplex cc = (AbstractControllerComplex) cl.newInstance(); cc.setMyMonitor(myMonitor); cc.initialize(); listCControllers.addItem(cc); } catch (Exception e) { } } } listCControllers.setActionCommand(cmdCtrlList); listCControllers.addActionListener(this); pcl.add(listCControllers); pcl.add(buttonProp); confPanel.add(pcl); return; } /** Action performed before closing the frame. */ private void close() { treePane.removeFrame(this); return; } /** Reaction to buttons and combo boxes. */ public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmdCtrlProp.equals(cmd)) { try { Class c = Class.forName("aurora.hwc.control.Panel" + myController.getClass().getSimpleName()); AbstractPanelController cp = (AbstractPanelController) c.newInstance(); cp.initialize(myController, null); } catch (Exception ex) { } } if (cmdCtrlList.equals(cmd)) { JComboBox cb = (JComboBox) e.getSource(); if (cb.getSelectedIndex() > 0) { myController = (AbstractControllerComplex) listCControllers.getSelectedItem(); buttonProp.setEnabled(true); } else { buttonProp.setEnabled(false); myController = null; } myMonitor.setMyController(myController); } return; } /** Reaction to checkbox changes. */ public void stateChanged(ChangeEvent e) { if (myMonitor.getMyNetwork().getContainer().getMyStatus().isStopped()) { enabled = cbEnabled.isSelected(); myMonitor.setEnabled(enabled); } else cbEnabled.setSelected(enabled); return; } /** Class needed for proper closing of internal Monitor windows. */ private class AdapterWindowMonitorController extends InternalFrameAdapter implements ComponentListener { /** * Function that is called when user closes the window. * * @param e internal frame event. */ public void internalFrameClosing(InternalFrameEvent e) { close(); return; } public void componentHidden(ComponentEvent e) { return; } public void componentMoved(ComponentEvent e) { return; } public void componentResized(ComponentEvent e) { return; } public void componentShown(ComponentEvent e) { return; } } /** Class needed for monitored Network Elements in a table. */ private class MonTableModel extends AbstractTableModel { private static final long serialVersionUID = -7601588619466450570L; public String getColumnName(int col) { switch (col) { case 0: return "Name"; default: return "Type"; } } public int getColumnCount() { return 2; } public int getRowCount() { return myMonitor.getPredecessors().size(); } public Object getValueAt(int row, int column) { if ((row < 0) || (row >= myMonitor.getPredecessors().size())) return null; switch (column) { case 0: return myMonitor.getPredecessors().get(row); default: return TypesHWC.typeString(myMonitor.getPredecessors().get(row).getType()); } } public boolean isCellEditable(int row, int column) { return false; } } /** Class needed for controlled Network Elements in a table. */ private class CtrlTableModel extends AbstractTableModel { private static final long serialVersionUID = 2990798418405255672L; public String getColumnName(int col) { switch (col) { case 0: return "Name"; default: return "Type"; } } public int getColumnCount() { return 2; } public int getRowCount() { return myMonitor.getSuccessors().size(); } public Object getValueAt(int row, int column) { if ((row < 0) || (row >= myMonitor.getSuccessors().size())) return null; switch (column) { case 0: return myMonitor.getSuccessors().get(row); default: return TypesHWC.typeString(myMonitor.getSuccessors().get(row).getType()); } } public boolean isCellEditable(int row, int column) { return false; } } }
/** * Creates the appropriate object to represent <code>msg</code> and places it into <code>container * </code>. If <code>msg</code> is an instance of Component, it is added directly, if it is an * Icon, a JLabel is created to represent it, otherwise a JLabel is created for the string, if * <code>d</code> is an Object[], this method will be recursively invoked for the children. <code> * internallyCreated</code> is true if Objc is an instance of Component and was created internally * by this method (this is used to correctly set hasCustomComponents only if !internallyCreated). */ protected void addMessageComponents( Container container, GridBagConstraints cons, Object msg, int maxll, boolean internallyCreated) { if (msg == null) { return; } if (msg instanceof Component) { // To workaround problem where Gridbad will set child // to its minimum size if its preferred size will not fit // within allocated cells if (msg instanceof JScrollPane || msg instanceof JPanel) { cons.fill = GridBagConstraints.BOTH; cons.weighty = 1; } else { cons.fill = GridBagConstraints.HORIZONTAL; } cons.weightx = 1; container.add((Component) msg, cons); cons.weightx = 0; cons.weighty = 0; cons.fill = GridBagConstraints.NONE; cons.gridy++; if (!internallyCreated) { hasCustomComponents = true; } } else if (msg instanceof Object[]) { Object[] msgs = (Object[]) msg; for (Object o : msgs) { addMessageComponents(container, cons, o, maxll, false); } } else if (msg instanceof Icon) { JLabel label = new JLabel((Icon) msg, SwingConstants.CENTER); configureMessageLabel(label); addMessageComponents(container, cons, label, maxll, true); } else { String s = msg.toString(); int len = s.length(); if (len <= 0) { return; } int nl; int nll = 0; if ((nl = s.indexOf(newline)) >= 0) { nll = newline.length(); } else if ((nl = s.indexOf("\r\n")) >= 0) { nll = 2; } else if ((nl = s.indexOf('\n')) >= 0) { nll = 1; } if (nl >= 0) { // break up newlines if (nl == 0) { JPanel breakPanel = new JPanel() { public Dimension getPreferredSize() { Font f = getFont(); if (f != null) { return new Dimension(1, f.getSize() + 2); } return new Dimension(0, 0); } }; breakPanel.setName("OptionPane.break"); addMessageComponents(container, cons, breakPanel, maxll, true); } else { addMessageComponents(container, cons, s.substring(0, nl), maxll, false); } addMessageComponents(container, cons, s.substring(nl + nll), maxll, false); } else if (len > maxll) { Container c = Box.createVerticalBox(); c.setName("OptionPane.verticalBox"); burstStringInto(c, s, maxll); addMessageComponents(container, cons, c, maxll, true); } else { JLabel label; label = new JLabel(s, JLabel.LEADING); label.setName("OptionPane.label"); configureMessageLabel(label); addMessageComponents(container, cons, label, maxll, true); } } }
private void buildKitData(Kits selectedKit) { final int ST_SPACE = 25; kitDataPanel.removeAll(); Box container = Box.createVerticalBox(); setComponentSize(container, 400, PAGE_HEIGHT); JLabel kitID = new JLabel(Integer.toString(selectedKit.getKitID())); JLabel kitName = new JLabel(selectedKit.getName()); JLabel kitDesc = new JLabel(selectedKit.getDescription()); JLabel lp = new JLabel("----- Listed Parts -----"); // align elements to the left collum // all the arguments can be left as KitID.LEFT because we only need any instance of a JComponent // to use the LEFT keyword kitID.setHorizontalAlignment(kitID.LEFT); kitName.setHorizontalAlignment(kitID.LEFT); kitDesc.setHorizontalAlignment(kitID.LEFT); lp.setHorizontalAlignment(kitID.LEFT); // add elements to container container.add(kitID); container.add(kitName); container.add(kitDesc); container.add(Box.createVerticalStrut(ST_SPACE)); container.add(lp); // add part data TreeMap<Integer, Parts> kitParts = selectedKit.getListOfParts(); for (Integer i : kitParts.keySet()) { Parts selectedPart = kitParts.get(i); Box holder = Box.createHorizontalBox(); Box section1 = Box.createVerticalBox(); Box section2 = Box.createVerticalBox(); int imageIndex = selectedPart.getImageIndex(); String PID = Integer.toString(selectedPart.getPartNumber()); String PName = selectedPart.getName(); String PDesc = selectedPart.getDesc(); setComponentSize(holder, 400, 60); // add elements to section1 section1.add(new JLabel("Part " + i)); section1.add(new JLabel(images.getIcon(imageIndex - 1))); // add elements to section2 section2.add(new JLabel("Part #: " + PID)); section2.add(new JLabel("Part name: " + PName)); section2.add(new JLabel("Part desc: " + PDesc)); // add sections to holder holder.add(section1); holder.add(Box.createHorizontalStrut(ST_SPACE)); holder.add(section2); // add holder to container container.add(holder); } // add the build items to the container buildQuantity = new JTextField("Enter number of kits to build"); build = new JButton("Add to build queue"); setComponentSize(buildQuantity, 400, 20); setComponentSize(buildQuantity, 400, 20); build.addActionListener(this); container.add(buildQuantity); container.add(build); // add container to kitDataPanel kitDataPanel.add(container); kitDataPanel.revalidate(); }
public DisplayDetailsPanel(int dn) { setBackground(varsOrange); JLabel stimJL = new JLabel("Stimulus" + dn + ":", JLabel.RIGHT); stimJL.setFont(f12b); String[] stims = {"word", "picture", "sound", "video", "blank"}; stimtypeJCB = new JComboBox(stims); stimtypeJCB.setSelectedIndex(0); stimJTF = new JTextField("", 10); stimJTF.setMaximumSize(new Dimension(stimJTF.getPreferredSize())); String[] locs = {"center", "random", "position"}; stimlocJCB = new JComboBox(locs); stimlocJCB.setSelectedIndex(0); JLabel xJL = new JLabel("x: ", JLabel.RIGHT); xJL.setFont(f12b); xJTF = new JTextField("", 3); xJTF.setMaximumSize(new Dimension(xJTF.getPreferredSize())); xJTF.setEditable(false); JLabel yJL = new JLabel("y: ", JLabel.RIGHT); yJL.setFont(f12b); yJTF = new JTextField("", 3); yJTF.setMaximumSize(new Dimension(yJTF.getPreferredSize())); yJTF.setEditable(false); AbstractAction stimlocJCBaction = new AbstractAction() { public void actionPerformed(ActionEvent ae) { if (stimlocJCB.getSelectedIndex() == 2) { xJTF.setEditable(true); yJTF.setEditable(true); } else { xJTF.setText(""); yJTF.setText(""); xJTF.setEditable(false); yJTF.setEditable(false); } } }; stimlocJCB.addActionListener(stimlocJCBaction); JLabel durJL = new JLabel("Duration(sec):", JLabel.RIGHT); durJTF = new JTextField("", 3); durJTF.setMaximumSize(new Dimension(durJTF.getPreferredSize())); AbstractAction stimtypeJCBaction = new AbstractAction() { public void actionPerformed(ActionEvent ae) { if (stimtypeJCB.getSelectedIndex() == 3) { stimJTF.setText(""); stimJTF.setEditable(false); stimlocJCB.setEnabled(false); xJTF.setText(""); xJTF.setEditable(false); yJTF.setText(""); yJTF.setEditable(false); durJTF.setEditable(true); } else { if (stimtypeJCB.getSelectedIndex() == 2) { stimJTF.setEditable(true); stimlocJCB.setEnabled(false); xJTF.setText(""); xJTF.setEditable(false); yJTF.setText(""); yJTF.setEditable(false); durJTF.setText(""); durJTF.setEditable(false); } else { stimJTF.setEditable(true); stimlocJCB.setEnabled(true); durJTF.setEditable(true); } } } }; stimtypeJCB.addActionListener(stimtypeJCBaction); ddhbox = Box.createHorizontalBox(); ddhbox.add(Box.createHorizontalStrut(10)); ddhbox.add(stimtypeJCB); ddhbox.add(Box.createHorizontalStrut(10)); ddhbox.add(stimJTF); ddhbox.add(Box.createHorizontalStrut(10)); ddhbox.add(stimlocJCB); ddhbox.add(Box.createHorizontalStrut(5)); ddhbox.add(xJL); ddhbox.add(xJTF); ddhbox.add(Box.createHorizontalStrut(5)); ddhbox.add(yJL); ddhbox.add(yJTF); ddhbox.add(Box.createHorizontalStrut(10)); ddhbox.add(durJL); ddhbox.add(durJTF); ddvbox = Box.createVerticalBox(); ddvbox.add(stimJL); stimJL.setAlignmentX(Component.LEFT_ALIGNMENT); ddvbox.add(Box.createVerticalStrut(5)); ddvbox.add(ddhbox); ddhbox.setAlignmentX(Component.LEFT_ALIGNMENT); add(ddvbox); }