public void init(List<T> sources) { this.sources = sources; consoles = new HashMap<T, ConsolePanel>(); singleNodeGUIS = new ArrayList<JComponent>(); // setPreferredSize(new Dimension(1000,700)); JSplitPane[] leftAndRight = new JSplitPane[] { new JSplitPane(JSplitPane.VERTICAL_SPLIT), new JSplitPane(JSplitPane.VERTICAL_SPLIT) }; for (int i = 0; i < sources.size(); i++) { T t = sources.get(i); Box box = Box.createVerticalBox(); ConsolePanel console = createConsole(); consoles.put(t, console); JScrollPane jsp = new JScrollPane(console); jsp.setMinimumSize(new Dimension(600, 300)); jsp.setPreferredSize(new Dimension(600, 300)); jsp.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); box.add(jsp); // box.add(Box.createVerticalGlue()); box.add(createInputTF(t)); box.add(Box.createVerticalStrut(3)); box.setBorder(BorderFactory.createTitledBorder(String.valueOf(t))); singleNodeGUIS.add(box); leftAndRight[i / 2].add(box); } add(leftAndRight[0]); add(leftAndRight[1]); }
private MainPanel() { super(new BorderLayout()); StringBuffer buf = new StringBuffer(); for (int i = 0; i < 100; i++) { String s = i + LF; buf.append(s); } final JScrollPane scrollPane = new JScrollPane(new JTextArea(buf.toString())); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); JSpinner spinner = new JSpinner( new SpinnerNumberModel( scrollPane.getVerticalScrollBar().getUnitIncrement(1), 1, 100000, 1)); spinner.setEditor(new JSpinner.NumberEditor(spinner, "#####0")); spinner.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner s = (JSpinner) e.getSource(); scrollPane.getVerticalScrollBar().setUnitIncrement((Integer) s.getValue()); } }); Box box = Box.createHorizontalBox(); box.add(new JLabel("Unit Increment:")); box.add(Box.createHorizontalStrut(2)); box.add(spinner); box.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(box, BorderLayout.NORTH); add(scrollPane); setPreferredSize(new Dimension(320, 240)); }
/** Performs the action of loading a session from a file. */ public void actionPerformed(ActionEvent e) { DataModel dataModel = getDataEditor().getSelectedDataModel(); if (!(dataModel instanceof DataSet)) { JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Must be a tabular data set."); return; } this.dataSet = (DataSet) dataModel; SpinnerNumberModel spinnerNumberModel = new SpinnerNumberModel(getNumLags(), 0, 20, 1); JSpinner jSpinner = new JSpinner(spinnerNumberModel); jSpinner.setPreferredSize(jSpinner.getPreferredSize()); spinnerNumberModel.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { SpinnerNumberModel model = (SpinnerNumberModel) e.getSource(); setNumLags(model.getNumber().intValue()); } }); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); Box b = Box.createVerticalBox(); Box b1 = Box.createHorizontalBox(); b1.add(new JLabel("Number of time lags: ")); b1.add(Box.createHorizontalGlue()); b1.add(Box.createHorizontalStrut(15)); b1.add(jSpinner); b1.setBorder(new EmptyBorder(10, 10, 10, 10)); b.add(b1); panel.add(b, BorderLayout.CENTER); EditorWindow editorWindow = new EditorWindow(panel, "Create time series data", "Save", true); DesktopController.getInstance().addEditorWindow(editorWindow); editorWindow.setVisible(true); editorWindow.addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameClosed(InternalFrameEvent e) { EditorWindow window = (EditorWindow) e.getSource(); if (!window.isCanceled()) { if (dataSet.isContinuous()) { createContinuousTimeSeriesData(); } else if (dataSet.isDiscrete()) { createDiscreteTimeSeriesData(); } else { JOptionPane.showMessageDialog( JOptionUtils.centeringComp(), "Data set must be either continuous or discrete."); } } } }); }
/** * Constructor of class Wizard * * @param parent the parent frame * @param name the title of the dialog * @param modal whether the dialog should be modal */ public Wizard(JFrame parent, String name, boolean modal) { super(parent, name, modal); // Code inspired by http://java.sun.com/developer/technicalArticles/GUI/swing/wizard/ listeners = new LinkedList<WizardListener>(); returnCode = -1; this.parent = parent; panelMap = new HashMap<Object, WizardPanel>(); panels = new Vector<WizardPanel>(); firstPanel = null; currentPanel = null; handler = new EventHandler(); // Create the main panel JPanel buttonPanel = new JPanel(); Box buttonBox = new Box(BoxLayout.X_AXIS); cardPanel = new JPanel(); cardPanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10))); cardLayout = new CardLayout(); cardPanel.setLayout(cardLayout); backButton = new JButton("Back"); nextButton = new JButton("Next"); cancelButton = new JButton("Cancel"); backButton.addActionListener(handler); nextButton.addActionListener(handler); cancelButton.addActionListener(handler); backButton.setEnabled(false); buttonPanel.setLayout(new BorderLayout()); buttonPanel.add(new JSeparator(), BorderLayout.NORTH); buttonBox.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10))); buttonBox.add(backButton); buttonBox.add(Box.createHorizontalStrut(10)); buttonBox.add(nextButton); buttonBox.add(Box.createHorizontalStrut(30)); buttonBox.add(cancelButton); buttonPanel.add(buttonBox, java.awt.BorderLayout.EAST); getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH); getContentPane().add(cardPanel, java.awt.BorderLayout.CENTER); pack(); }
public AppFrame() { JButton button = new JButton("Open VPF Database"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { showOpenDialog(); } }); Box box = Box.createHorizontalBox(); box.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30)); // top, left, bottom, right box.add(button); this.getLayerPanel().add(box, BorderLayout.SOUTH); }
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 void addOptionsPage(OptionsPage page, String tabName) { // If the page does not exist, add it, and add the component // to the page. Component c = getTab(tabName); if (c == null) { // Create a new Page Box box = new Box(BoxLayout.Y_AXIS); box.add(page); box.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); tabPane.add(tabName, box); optionPages.add(page); } else { Box box = (Box) c; box.add(Box.createVerticalStrut(7)); box.add(page); optionPages.add(page); } pack(); }
/** Constructs a new GraphEditor for the given EdgeListGraph. */ public TimeLagGraphEditor(TimeLagGraph graph) { setLayout(new BorderLayout()); this.workbench = new TimeLagGraphWorkbench(graph); DagGraphToolbar toolbar = new DagGraphToolbar(getWorkbench()); JMenuBar menuBar = createGraphMenuBar(); JScrollPane scroll = new JScrollPane(getWorkbench()); scroll.setPreferredSize(new Dimension(450, 450)); add(scroll, BorderLayout.CENTER); add(toolbar, BorderLayout.WEST); add(menuBar, BorderLayout.NORTH); JLabel label = new JLabel("Double click variable to change name."); label.setFont(new Font("SansSerif", Font.PLAIN, 12)); Box b = Box.createHorizontalBox(); b.add(Box.createHorizontalStrut(2)); b.add(label); b.add(Box.createHorizontalGlue()); b.setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY)); add(b, BorderLayout.SOUTH); this.getWorkbench() .addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if ("graph".equals(propertyName)) { TimeLagGraph _graph = (TimeLagGraph) evt.getNewValue(); if (getWorkbench() != null) { getGraphWrapper().setGraph(_graph); } } } }); }
/** Builds the panel. */ public void setup() { SpinnerNumberModel model = new SpinnerNumberModel(this.params.getInt("numTimeLags", 1), 0, Integer.MAX_VALUE, 1); JSpinner jSpinner = new JSpinner(model); jSpinner.setPreferredSize(jSpinner.getPreferredSize()); model.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { SpinnerNumberModel model = (SpinnerNumberModel) e.getSource(); params.set("numTimeLags", model.getNumber().intValue()); } }); Box b1 = Box.createHorizontalBox(); b1.add(new JLabel("Number of lags: ")); b1.add(Box.createHorizontalGlue()); b1.add(Box.createHorizontalStrut(15)); b1.add(jSpinner); b1.setBorder(new EmptyBorder(10, 10, 10, 10)); add(b1, BorderLayout.CENTER); }
/** Create and layout the visual components. */ private void initComponents() { setTitle("Chart Settings"); setSize(new Dimension(450, 375)); setResizable(false); addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(evt); } }); Box mainView = new Box(VERTICAL); getContentPane().add(mainView); Box row; Box yAxisView = new Box(VERTICAL); yAxisView.setBorder(border); mainView.add(yAxisView); yAutoScaleCheckbox = new JCheckBox("Auto Scale"); yAutoScaleCheckbox.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { yAutoScaleCheckboxActionPerformed(evt); } }); row = new Box(HORIZONTAL); row.add(Box.createHorizontalGlue()); row.add(yAutoScaleCheckbox); yAxisView.add(row); yAxisMinValueField = new JTextField(10); yAxisMinValueField.setMaximumSize(yAxisMinValueField.getPreferredSize()); yAxisMinValueField.setHorizontalAlignment(javax.swing.JTextField.RIGHT); yAxisMinValueField.addFocusListener( new FocusAdapter() { public void focusGained(FocusEvent event) { yAxisMinValueField.selectAll(); } public void focusLost(FocusEvent event) { yAxisMinValueField.setCaretPosition(0); yAxisMinValueField.moveCaretPosition(0); } }); row = new Box(HORIZONTAL); row.add(Box.createHorizontalGlue()); row.add(new JLabel("Min:")); row.add(yAxisMinValueField); yAxisView.add(row); yAxisMaxValueField = new JTextField(10); yAxisMaxValueField.setMaximumSize(yAxisMaxValueField.getPreferredSize()); yAxisMaxValueField.setHorizontalAlignment(javax.swing.JTextField.RIGHT); yAxisMaxValueField.addFocusListener( new FocusAdapter() { public void focusGained(FocusEvent event) { yAxisMaxValueField.selectAll(); } public void focusLost(FocusEvent event) { yAxisMaxValueField.setCaretPosition(0); yAxisMaxValueField.moveCaretPosition(0); } }); row = new Box(HORIZONTAL); row.add(Box.createHorizontalGlue()); row.add(new JLabel("Max:")); row.add(yAxisMaxValueField); yAxisView.add(row); yAxisDivisionsField = new JTextField(10); yAxisDivisionsField.setMaximumSize(yAxisDivisionsField.getPreferredSize()); yAxisDivisionsField.setHorizontalAlignment(JTextField.RIGHT); yAxisDivisionsField.addFocusListener( new FocusAdapter() { public void focusGained(FocusEvent event) { yAxisDivisionsField.selectAll(); } public void focusLost(FocusEvent event) { yAxisDivisionsField.setCaretPosition(0); yAxisDivisionsField.moveCaretPosition(0); } }); row = new Box(HORIZONTAL); row.add(Box.createHorizontalGlue()); row.add(new JLabel("Major Divisions:")); row.add(yAxisDivisionsField); yAxisView.add(row); Box buttonView = new Box(HORIZONTAL); mainView.add(buttonView); buttonView.add(Box.createHorizontalGlue()); JButton revertButton = new JButton("Revert"); revertButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { revertButtonActionPerformed(event); } }); buttonView.add(revertButton); JButton applyButton = new JButton("Apply"); applyButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { applyButtonActionPerformed(event); } }); buttonView.add(applyButton); pack(); }
/** Fills the panel with event specific fields. */ protected void fillPanel() { JLabel l; Box fdp = Box.createVerticalBox(); fdp.setBorder(BorderFactory.createTitledBorder("Fundamental Diagram")); fdChart = makeFDChart(); ChartPanel cp = new ChartPanel(fdChart); cp.setMinimumDrawWidth(100); cp.setMinimumDrawHeight(60); cp.setPreferredSize(new Dimension(250, 80)); fdp.add(new JScrollPane(cp)); JPanel prmp = new JPanel(new SpringLayout()); l = new JLabel("Capacity:", JLabel.TRAILING); prmp.add(l); spinMaxFlow = new JSpinner(new SpinnerNumberModel(mf, 0, 99999, 1.0)); spinMaxFlow.setEditor(new JSpinner.NumberEditor(spinMaxFlow, "####0.00")); spinMaxFlow.addChangeListener(this); spinMaxFlow.setName(nmSpinMaxFlow); l.setLabelFor(spinMaxFlow); prmp.add(spinMaxFlow); l = new JLabel("Cap.Drop:", JLabel.TRAILING); prmp.add(l); spinCapDrop = new JSpinner(new SpinnerNumberModel(drp, 0, 99999, 1.0)); spinCapDrop.setEditor(new JSpinner.NumberEditor(spinCapDrop, "####0.00")); spinCapDrop.addChangeListener(this); spinCapDrop.setName(nmSpinCapDrop); l.setLabelFor(spinCapDrop); prmp.add(spinCapDrop); l = new JLabel("C.Density:", JLabel.TRAILING); prmp.add(l); spinCritDen = new JSpinner(new SpinnerNumberModel(cd, 0, 99999, 1.0)); spinCritDen.setEditor(new JSpinner.NumberEditor(spinCritDen, "####0.00")); spinCritDen.addChangeListener(this); spinCritDen.setName(nmSpinCritDen); l.setLabelFor(spinCritDen); prmp.add(spinCritDen); l = new JLabel(" V:", JLabel.TRAILING); prmp.add(l); spinVff = new JSpinner(new SpinnerNumberModel(mf / cd, 0, 200, 1.0)); spinVff.setEditor(new JSpinner.NumberEditor(spinVff, "#0.00")); spinVff.addChangeListener(this); spinVff.setName(nmSpinVff); l.setLabelFor(spinVff); prmp.add(spinVff); l = new JLabel("J.Density:", JLabel.TRAILING); prmp.add(l); spinJamDen = new JSpinner(new SpinnerNumberModel(jd, 0, 99999, 1.0)); spinJamDen.setEditor(new JSpinner.NumberEditor(spinJamDen, "####0.00")); spinJamDen.addChangeListener(this); spinJamDen.setName(nmSpinJamDen); l.setLabelFor(spinJamDen); prmp.add(spinJamDen); l = new JLabel(" W:", JLabel.TRAILING); prmp.add(l); if (jd == cd) jd = cd + 1; int ulim = (int) Math.max(Math.ceil(mf / (jd - cd)), 999); spinWc = new JSpinner(new SpinnerNumberModel(mf / (jd - cd), 0, ulim, 1.0)); spinWc.setEditor(new JSpinner.NumberEditor(spinWc, "#0.00")); spinWc.addChangeListener(this); spinWc.setName(nmSpinWc); l.setLabelFor(spinWc); prmp.add(spinWc); SpringUtilities.makeCompactGrid(prmp, 3, 4, 2, 2, 2, 2); fdp.add(prmp); // add(new JScrollPane(fdp)); add(fdp); return; }
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(); }
/** * 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; }
public AuthDialog(final JFrame parent, String title, boolean modal) { super(parent, title, modal); // Set up close behaviour setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { if (!okButtonClicked) System.exit(0); } }); // Set up OK button behaviour JButton okButton = new JButton("OK"); okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (getUserName().length() == 0) { showMessageDialog( AuthDialog.this, "Please enter a username", "Format Error", ERROR_MESSAGE); return; } if (getDatabasePassword().length() == 0) { showMessageDialog( AuthDialog.this, "Please enter a password", "Format Error", ERROR_MESSAGE); return; } okButtonClicked = true; setVisible(false); } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); // Set up dialog contents labelPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 5, 5)); inputPanel.setBorder(BorderFactory.createEmptyBorder(20, 5, 5, 20)); labelPanel.setLayout(new GridLayout(2, 1)); labelPanel.add(new JLabel("User Name: ")); labelPanel.add(new JLabel("Password:"******"ESCAPE"), "exitAction"); actionMap.put( "exitAction", new AbstractAction() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); // Pack it all pack(); // Center on the screen setLocationRelativeTo(null); }
public WizardStep getStage(String stage) { final WhatsNew _this = this; WizardStep ws = new WizardStep(); int ind = stage.indexOf(":"); Version v = new Version(stage.substring(0, ind)); int lind = Integer.parseInt(stage.substring(ind + 1)); java.util.List<WhatsNewItem> its = this.items.get(v); if (its == null) { return null; } WhatsNewItem item = its.get(lind); if (item == null) { return null; } ws.title = item.title; ws.helpText = this.getFirstHelpText(); if ((item.description != null) || (item.component != null)) { final Box b = new Box(BoxLayout.Y_AXIS); if (item.description != null) { JTextPane hp = UIUtils.createHelpTextPane(item.description, this.projectViewer); hp.setBorder(null); hp.setSize(new Dimension(UIUtils.getPopupWidth() - 25, 500)); Box hpb = new Box(BoxLayout.Y_AXIS); hpb.add(hp); hpb.setMaximumSize(hpb.getPreferredSize()); hpb.setBorder(UIUtils.createPadding(0, 5, 0, 0)); b.add(hpb); } if (item.component != null) { if (item.description != null) { b.add(Box.createVerticalStrut(5)); } item.component.setAlignmentY(Component.TOP_ALIGNMENT); item.component.setBorder(UIUtils.createPadding(5, 10, 0, 0)); b.add(item.component); } b.add(Box.createVerticalGlue()); ws.panel = b; } return ws; }
/** * Constructs a new session toolbar. * * @param workbench the workbench this toolbar controls. */ public SessionEditorToolbar(final SessionEditorWorkbench workbench) { if (workbench == null) { throw new NullPointerException("Workbench must not be null."); } this.workbench = workbench; // Set up panel. Box buttonsPanel = Box.createVerticalBox(); // buttonsPanel.setBackground(new Color(198, 232, 252)); buttonsPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); // Create buttons. /* Node infos for all of the nodes. */ ButtonInfo[] buttonInfos = new ButtonInfo[] { new ButtonInfo( "Select", "Select and Move", "move", "<html>Select and move nodes or groups of nodes " + "<br>on the workbench.</html>"), new ButtonInfo( "Edge", "Draw Edge", "flow", "<html>Add an edge from one node to another to declare" + "<br>that the object in the first node should be used " + "<br>to construct the object in the second node." + "<br>As a shortcut, hold down the Control key." + "</html>"), new ButtonInfo( "Data", "Data & Simulation", "data", "<html>Add a node for a data object.</html>"), new ButtonInfo( "Search", "Search", "search", "<html>Add a node for a search algorithm.</html>"), new ButtonInfo( "Comparison", "Comparison", "compare", "<html>Add a node to compare graphs or SEM IM's.</html>"), new ButtonInfo("Graph", "Graph", "graph", "<html>Add a graph node.</html>"), new ButtonInfo( "PM", "Parametric Model", "pm", "<html>Add a node for a parametric model.</html>"), new ButtonInfo( "IM", "Instantiated Model", "im", "<html>Add a node for an instantiated model.</html>"), new ButtonInfo( "Estimator", "Estimator", "estimator", "<html>Add a node for an estimator.</html>"), new ButtonInfo( "Updater", "Updater", "updater", "<html>Add a node for an updater.</html>"), new ButtonInfo( "Classify", "Classify", "search", "<html>Add a node for a classifier.</html>"), new ButtonInfo( "Regression", "Regression", "regression", "<html>Add a node for a regression.</html>"), new ButtonInfo( "Knowledge", "Knowledge", "knowledge", "<html>Add a knowledge box node.</html>"), new ButtonInfo("Note", "Note", "note", "<html>Add a note to the session.</html>") }; JToggleButton[] buttons = new JToggleButton[buttonInfos.length]; for (int i = 0; i < buttonInfos.length; i++) { buttons[i] = constructButton(buttonInfos[i]); } // Add all buttons to a button group. ButtonGroup buttonGroup = new ButtonGroup(); for (int i = 0; i < buttonInfos.length; i++) { buttonGroup.add(buttons[i]); } // This seems to be fixed. Now creating weirdness. jdramsey 3/4/2014 // // Add a focus listener to help buttons not deselect when the // // mouse slides away from the button. // FocusListener focusListener = new FocusAdapter() { // public void focusGained(FocusEvent e) { // JToggleButton component = (JToggleButton) e.getComponent(); // component.getModel().setSelected(true); // } // }; // // for (int i = 0; i < buttonInfos.length; i++) { // buttons[i].addFocusListener(focusListener); // } // Add an action listener to help send messages to the // workbench. ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent e) { JToggleButton _button = (JToggleButton) e.getSource(); if (_button.getModel().isSelected()) { setWorkbenchMode(_button); // setCursor(workbench.getCursor()); } } }; for (int i = 0; i < buttonInfos.length; i++) { buttons[i].addChangeListener(changeListener); } // Select the Select button. JToggleButton button = getButtonForType(this.selectType); button.getModel().setSelected(true); // Add the buttons to the workbench. for (int i = 0; i < buttonInfos.length; i++) { buttonsPanel.add(buttons[i]); buttonsPanel.add(Box.createVerticalStrut(5)); } // Put the panel in a scrollpane. this.setLayout(new BorderLayout()); JScrollPane scroll = new JScrollPane(buttonsPanel); scroll.setPreferredSize(new Dimension(130, 1000)); add(scroll, BorderLayout.CENTER); // Add property change listener so that selection can be moved // back to "SELECT_MOVE" after an action. workbench.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if (!isRespondingToEvents()) { return; } String propertyName = e.getPropertyName(); if ("nodeAdded".equals(propertyName)) { if (!isShiftDown()) { resetSelectMove(); } } } }); KeyboardFocusManager.getCurrentKeyboardFocusManager() .addKeyEventDispatcher( new KeyEventDispatcher() { public boolean dispatchKeyEvent(KeyEvent e) { int keyCode = e.getKeyCode(); int id = e.getID(); if (keyCode == KeyEvent.VK_SHIFT) { if (id == KeyEvent.KEY_PRESSED) { setShiftDown(true); } else if (id == KeyEvent.KEY_RELEASED) { setShiftDown(false); resetSelectMove(); } } return false; } }); resetSelectMove(); }
// // Build installer window // public static void showInstallerWindow() { _installerFrame = new JFrame(Config.getWindowTitle()); Container cont = _installerFrame.getContentPane(); cont.setLayout(new BorderLayout()); // North pane Box topPane = new Box(BoxLayout.X_AXIS); JLabel title = new JLabel(Config.getWindowHeading()); Font titleFont = new Font("SansSerif", Font.BOLD, 22); title.setFont(titleFont); title.setForeground(Color.black); // Create Sun logo URL urlLogo = Main.class.getResource(Config.getWindowLogo()); Image img = Toolkit.getDefaultToolkit().getImage(urlLogo); MediaTracker md = new MediaTracker(_installerFrame); md.addImage(img, 0); try { md.waitForAll(); } catch (Exception ioe) { Config.trace(ioe.toString()); } if (md.isErrorID(0)) Config.trace("Error loading image"); Icon sunLogo = new ImageIcon(img); JLabel logoLabel = new JLabel(sunLogo); logoLabel.setOpaque(true); topPane.add(topPane.createHorizontalStrut(5)); topPane.add(title); topPane.add(topPane.createHorizontalGlue()); topPane.add(logoLabel); topPane.add(topPane.createHorizontalStrut(5)); // West Pane Box westPane = new Box(BoxLayout.X_AXIS); westPane.add(westPane.createHorizontalStrut(10)); // South Pane Box bottomPane = new Box(BoxLayout.X_AXIS); bottomPane.add(bottomPane.createHorizontalGlue()); JButton abortButton = new JButton(Config.getWindowAbortButton()); abortButton.setMnemonic(Config.getWindowAbortMnemonic()); bottomPane.add(abortButton); bottomPane.add(bottomPane.createHorizontalGlue()); bottomPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); // Center Pane Box centerPane = new Box(BoxLayout.Y_AXIS); JLabel hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); _stepLabels = new JLabel[5]; for (int i = 0; i < _stepLabels.length; i++) { _stepLabels[i] = new JLabel(Config.getWindowStep(i)); _stepLabels[i].setEnabled(false); centerPane.add(_stepLabels[i]); // install label's length will expand,so set a longer size. if (i == STEP_INSTALL) { Dimension dim = new JLabel(Config.getWindowStepWait(STEP_INSTALL)).getPreferredSize(); _stepLabels[i].setPreferredSize(dim); } } hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); // Setup box layout cont.add(topPane, "North"); cont.add(westPane, "West"); cont.add(bottomPane, "South"); cont.add(centerPane, "Center"); _installerFrame.pack(); Dimension dim = _installerFrame.getSize(); // hard code to ensure title is completely visible on Sol/lin. if (dim.width < 400) { dim.width = 400; _installerFrame.setSize(dim); } Rectangle size = _installerFrame.getBounds(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); size.width = Math.min(screenSize.width, size.width); size.height = Math.min(screenSize.height, size.height); // Put window at 1/4, 1/4 of screen resoluion _installerFrame.setBounds( (screenSize.width - size.width) / 4, (screenSize.height - size.height) / 4, size.width, size.height); // Setup event listners _installerFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { installFailed("Window closed", null); } }); abortButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { installFailed("Abort pressed", null); } }); // Show window _installerFrame.show(); }