/** 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."); } } } }); }
/** * Méthode de création du panelInit * * @return */ private JPanel createPanelInit() { JPanel panRight = new JPanel(); panRight.setLayout(new BoxLayout(panRight, BoxLayout.Y_AXIS)); butListParty = new JButton("Liste des parties"); butListParty.addActionListener(this); JPanel panCreate = new JPanel(); panCreate.setLayout(new BoxLayout(panCreate, BoxLayout.X_AXIS)); textCreate = new JTextField("", 40); textCreate.setMaximumSize(textCreate.getPreferredSize()); butCreateParty = new JButton("Creation de parties "); butCreateParty.addActionListener(this); SpinnerModel model = new SpinnerNumberModel(3, 2, 8, 1); spinNbPlayer = new JSpinner(model); spinNbPlayer.setMaximumSize(spinNbPlayer.getPreferredSize()); panCreate.add(new JLabel("Nouveau nom de partie : ")); panCreate.add(textCreate); panCreate.add(Box.createHorizontalStrut(20)); panCreate.add(new JLabel("Nombres de joueurs : ")); panCreate.add(spinNbPlayer); panCreate.add(butCreateParty); JPanel panJoin = new JPanel(); panJoin.setLayout(new BoxLayout(panJoin, BoxLayout.X_AXIS)); textJoin = new JTextField("", 2); textJoin.setMaximumSize(textJoin.getPreferredSize()); butJoinParty = new JButton("Rejoindre la partie "); butJoinParty.addActionListener(this); panJoin.add(new JLabel("Num Partie : ")); panJoin.add(textJoin); panJoin.add(butJoinParty); panRight.add(butListParty); panRight.add(panCreate); panRight.add(panJoin); panRight.add(Box.createVerticalGlue()); textInfoInit = new JTextArea(20, 100); textInfoInit.setLineWrap(true); JScrollPane scroll = new JScrollPane( textInfoInit, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); JPanel panAll = new JPanel(); panAll.setLayout(new BoxLayout(panAll, BoxLayout.X_AXIS)); panAll.add(scroll); panAll.add(panRight); return panAll; }
private void configureSpinnerFloat(JSpinner spinner) { JSpinner.NumberEditor editor = (JSpinner.NumberEditor) spinner.getEditor(); DecimalFormat format = editor.getFormat(); format.setMinimumFractionDigits(3); format.setMinimumIntegerDigits(1); editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER); Dimension d = spinner.getPreferredSize(); d.width = 60; spinner.setPreferredSize(d); spinner.addChangeListener(this); spinner.setMaximumSize(d); }
@Override protected JSpinner createSpinner(int b) { JSpinner spinner = new JSpinner(); SpinnerListModel model = new SpinnerListModel(_keyList); spinner.setModel(model); ((JSpinner.ListEditor) spinner.getEditor()).getTextField().setEditable(false); model.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { update(); } }); Dimension d = new Dimension(40, spinner.getPreferredSize().height); spinner.setMinimumSize(d); spinner.setPreferredSize(d); return spinner; }
/** 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); }
private void setUpA1(List<DataSet> dataSets, Box a1) { int[] shifts = params.getShifts(); if (shifts.length != dataSets.get(0).getNumColumns()) { shifts = new int[dataSets.get(0).getNumColumns()]; params.setShifts(shifts); } final int[] _shifts = shifts; for (int i = 0; i < dataSets.get(0).getNumColumns(); i++) { Node node = dataSets.get(0).getVariable(i); Box a5 = Box.createHorizontalBox(); SpinnerModel shiftModel = new SpinnerNumberModel(_shifts[i], -50, 50, 1); JSpinner shiftSpinner = new JSpinner(shiftModel); shiftSpinner.setMaximumSize(shiftSpinner.getPreferredSize()); final int nodeIndex = i; shiftSpinner.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); SpinnerNumberModel model = (SpinnerNumberModel) spinner.getModel(); int value = (Integer) model.getValue(); _shifts[nodeIndex] = value; params.setShifts(_shifts); } }); a5.add(new JLabel(" Shift for ")); a5.add(new JLabel(node.getName())); a5.add(new JLabel(" is ")); a5.add(shiftSpinner); a5.add(Box.createHorizontalGlue()); a1.add(a5); } }
public LingDisplay(final Ling.StoredGraphs storedGraphs) { this.storedGraphs = storedGraphs; if (storedGraphs.getNumGraphs() == 0) { workbench = new GraphWorkbench(); } else { workbench = new GraphWorkbench(storedGraphs.getGraph(0)); } subsetIndices = getStableIndices(storedGraphs); final SpinnerNumberModel model = new SpinnerNumberModel(subsetIndices.size() == 0 ? 0 : 1, 0, subsetIndices.size(), 1); model.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { int index = model.getNumber().intValue(); workbench.setGraph(storedGraphs.getGraph(subsetIndices.get(index - 1))); } }); spinner = new JSpinner(); subsetCombo = new JComboBox(new String[] {"Show Stable", "Show Unstable", "Show All"}); subsetCombo.setSelectedItem("Show Stable"); spinner.setModel(model); totalLabel = new JLabel(" of " + subsetIndices.size()); subsetCombo.setMaximumSize(subsetCombo.getPreferredSize()); subsetCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { resetDisplay(); } }); spinner.setPreferredSize(new Dimension(50, 20)); spinner.setMaximumSize(spinner.getPreferredSize()); Box b = Box.createVerticalBox(); Box b1 = Box.createHorizontalBox(); // b1.add(Box.createHorizontalGlue()); // b1.add(Box.createHorizontalStrut(10)); b1.add(subsetCombo); b1.add(Box.createHorizontalGlue()); b1.add(new JLabel("DAG ")); b1.add(spinner); b1.add(totalLabel); b.add(b1); Box b2 = Box.createHorizontalBox(); JPanel graphPanel = new JPanel(); graphPanel.setLayout(new BorderLayout()); JScrollPane jScrollPane = new JScrollPane(workbench); // jScrollPane.setPreferredSize(new Dimension(400, 400)); graphPanel.add(jScrollPane); // graphPanel.setBorder(new TitledBorder("DAG")); b2.add(graphPanel); b.add(b2); setLayout(new BorderLayout()); // add(menuBar(), BorderLayout.NORTH); add(b, BorderLayout.CENTER); }
public DetectPolygonControlPanel(DetectBlackPolygonApp owner) { this.owner = owner; imageView = new JComboBox(); imageView.addItem("Input"); imageView.addItem("Binary"); imageView.addItem("Black"); imageView.addActionListener(this); imageView.setMaximumSize(imageView.getPreferredSize()); selectZoom = new JSpinner(new SpinnerNumberModel(1, 0.1, 50, 1)); selectZoom.addChangeListener(this); selectZoom.setMaximumSize(selectZoom.getPreferredSize()); showCorners = new JCheckBox("Corners"); showCorners.addActionListener(this); showCorners.setSelected(bShowCorners); showLines = new JCheckBox("Lines"); showLines.setSelected(bShowLines); showLines.addActionListener(this); showContour = new JCheckBox("Contour"); showContour.addActionListener(this); showContour.setSelected(bShowContour); threshold = new ThresholdControlPanel(owner); refineChoice = new JComboBox(); for (PolygonRefineType n : PolygonRefineType.values()) { refineChoice.addItem(n.name()); } refineChoice.setSelectedIndex(refineType.ordinal()); refineChoice.addActionListener(this); refineChoice.setMaximumSize(refineChoice.getPreferredSize()); spinnerMinContourSize = new JSpinner(new SpinnerNumberModel(config.minContourImageWidthFraction, 0.0, 0.2, 0.01)); configureSpinnerFloat(spinnerMinContourSize); spinnerMinSides = new JSpinner(new SpinnerNumberModel(minSides, 3, 20, 1)); spinnerMinSides.setMaximumSize(spinnerMinSides.getPreferredSize()); spinnerMinSides.addChangeListener(this); spinnerMaxSides = new JSpinner(new SpinnerNumberModel(maxSides, 3, 20, 1)); spinnerMaxSides.setMaximumSize(spinnerMaxSides.getPreferredSize()); spinnerMaxSides.addChangeListener(this); spinnerMinEdge = new JSpinner(new SpinnerNumberModel(config.minimumEdgeIntensity, 0.0, 255.0, 1.0)); spinnerMinEdge.setMaximumSize(spinnerMinEdge.getPreferredSize()); spinnerMinEdge.addChangeListener(this); spinnerContourSplit = new JSpinner(new SpinnerNumberModel(config.contour2Poly_splitFraction, 0.0, 1.0, 0.01)); configureSpinnerFloat(spinnerContourSplit); spinnerContourMinSplit = new JSpinner( new SpinnerNumberModel(config.contour2Poly_minimumSideFraction, 0.0, 1.0, 0.001)); configureSpinnerFloat(spinnerContourMinSplit); spinnerContourSplit.addChangeListener(this); spinnerContourIterations = new JSpinner(new SpinnerNumberModel(config.contour2Poly_iterations, 1, 200, 1)); spinnerContourIterations.setMaximumSize(spinnerContourIterations.getPreferredSize()); spinnerContourIterations.addChangeListener(this); spinnerSplitPenalty = new JSpinner(new SpinnerNumberModel(config.splitPenalty, 0.0, 100.0, 1.0)); configureSpinnerFloat(spinnerSplitPenalty); setConvex = new JCheckBox("Convex"); setConvex.addActionListener(this); setConvex.setSelected(config.convex); setBorder = new JCheckBox("Image Border"); setBorder.addActionListener(this); setBorder.setSelected(config.canTouchBorder); spinnerLineSamples = new JSpinner(new SpinnerNumberModel(configLine.lineSamples, 5, 100, 1)); spinnerLineSamples.setMaximumSize(spinnerLineSamples.getPreferredSize()); spinnerLineSamples.addChangeListener(this); spinnerCornerOffset = new JSpinner(new SpinnerNumberModel(configLine.cornerOffset, 0, 10, 1)); spinnerCornerOffset.setMaximumSize(spinnerCornerOffset.getPreferredSize()); spinnerCornerOffset.addChangeListener(this); spinnerSampleRadius = new JSpinner(new SpinnerNumberModel(configLine.sampleRadius, 0, 10, 1)); spinnerSampleRadius.setMaximumSize(spinnerCornerOffset.getPreferredSize()); spinnerSampleRadius.addChangeListener(this); spinnerRefineMaxIterations = new JSpinner(new SpinnerNumberModel(configLine.maxIterations, 0, 200, 1)); spinnerRefineMaxIterations.setMaximumSize(spinnerRefineMaxIterations.getPreferredSize()); spinnerRefineMaxIterations.addChangeListener(this); spinnerConvergeTol = new JSpinner(new SpinnerNumberModel(configLine.convergeTolPixels, 0.0, 2.0, 0.005)); configureSpinnerFloat(spinnerConvergeTol); spinnerMaxCornerChange = new JSpinner(new SpinnerNumberModel(configLine.maxCornerChangePixel, 0.0, 50.0, 1.0)); configureSpinnerFloat(spinnerMaxCornerChange); addLabeled(imageView, "View: ", this); addLabeled(selectZoom, "Zoom", this); addAlignLeft(showCorners, this); addAlignLeft(showLines, this); addAlignLeft(showContour, this); add(threshold); addLabeled(spinnerMinContourSize, "Min Contour Size: ", this); addLabeled(spinnerMinSides, "Minimum Sides: ", this); addLabeled(spinnerMaxSides, "Maximum Sides: ", this); addLabeled(spinnerMinEdge, "Edge Intensity: ", this); addAlignLeft(setConvex, this); addAlignLeft(setBorder, this); addCenterLabel("Contour", this); addLabeled(spinnerContourSplit, "Split Fraction: ", this); addLabeled(spinnerContourMinSplit, "Min Split: ", this); addLabeled(spinnerContourIterations, "Max Iterations: ", this); addLabeled(spinnerSplitPenalty, "Split Penalty: ", this); addCenterLabel("Refinement", this); addLabeled(refineChoice, "Refine: ", this); addLabeled(spinnerLineSamples, "Line Samples: ", this); addLabeled(spinnerCornerOffset, "Corner Offset: ", this); addLabeled(spinnerSampleRadius, "Sample Radius: ", this); addLabeled(spinnerRefineMaxIterations, "Iterations: ", this); addLabeled(spinnerConvergeTol, "Converge Tol Pixels: ", this); addLabeled(spinnerMaxCornerChange, "Max Corner Change: ", this); addVerticalGlue(this); }
@Override public Component getComponent() { if (dockableComponent == null) { JScrollPane scrollPane = new ExtendedJScrollPane(this); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); scrollPane.setBorder(null); dockableComponent = new JPanel(new BorderLayout()); JPanel toolBarPanel = new JPanel(new BorderLayout()); ViewToolBar toolBar = new ViewToolBar(); JToggleButton toggleExpertModeButton = mainFrame.TOGGLE_EXPERT_MODE_ACTION.createToggleButton(); toggleExpertModeButton.setText(null); toolBar.add(toggleExpertModeButton); Action infoOperatorAction = new InfoOperatorAction() { private static final long serialVersionUID = 6758272768665592429L; @Override protected Operator getOperator() { return mainFrame.getFirstSelectedOperator(); } }; toolBar.add(infoOperatorAction); JToggleButton enableOperatorButton = new ToggleActivationItem(mainFrame.getActions()).createToggleButton(); enableOperatorButton.setText(null); toolBar.add(enableOperatorButton); Action renameOperatorAction = new ResourceAction(true, "rename_in_processrenderer") { { setCondition(OPERATOR_SELECTED, MANDATORY); } private static final long serialVersionUID = -3104160320178045540L; @Override public void actionPerformed(ActionEvent e) { Operator operator = mainFrame.getFirstSelectedOperator(); String name = SwingTools.showInputDialog("rename_operator", operator.getName()); if (name != null && name.length() > 0) { operator.rename(name); } } }; toolBar.add(renameOperatorAction); toolBar.add(new DeleteOperatorAction()); breakpointButton.addToToolBar(toolBar); // toolBar.add(mainFrame.getActions().MAKE_DIRTY_ACTION); toolBarPanel.add(toolBar, BorderLayout.NORTH); JPanel headerPanel = new JPanel(); headerPanel.setBackground(SwingTools.LIGHTEST_BLUE); headerPanel.add(headerLabel); headerPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY)); toolBarPanel.add(headerPanel, BorderLayout.SOUTH); dockableComponent.add(toolBarPanel, BorderLayout.NORTH); dockableComponent.add(scrollPane, BorderLayout.CENTER); // compatibility level and warnings JPanel southPanel = new JPanel(new BorderLayout()); southPanel.add(expertModeHintLabel, BorderLayout.CENTER); compatibilityLabel.setLabelFor(compatibilityLevelSpinner); compatibilityLevelSpinner.setPreferredSize( new Dimension(80, (int) compatibilityLevelSpinner.getPreferredSize().getHeight())); compatibilityPanel.add(compatibilityLabel); compatibilityPanel.add(compatibilityLevelSpinner); southPanel.add(compatibilityPanel, BorderLayout.SOUTH); dockableComponent.add(southPanel, BorderLayout.SOUTH); } return dockableComponent; }
public void setPreferredWidth(int width) { spinner.setPreferredSize(new Dimension(width, spinner.getPreferredSize().height)); }
private JToolBar makeToolBar() { JToolBar tool = new JToolBar(); tool.setFloatable(false); // Setup the buttons save.setRequestFocusEnabled(false); tool.add(save); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontNames = ge.getAvailableFontFamilyNames(); tool.addSeparator(); cbFonts = new JComboBox(fontNames); cbFonts.setRequestFocusEnabled(false); cbFonts.setMaximumSize(cbFonts.getPreferredSize()); cbFonts.setEditable(true); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { if (fFamilyChange) { fFamilyChange = false; return; } editor.grabFocus(); setSelectionAttribute(StyleConstants.Family, cbFonts.getSelectedItem().toString()); } }; cbFonts.addActionListener(lst); tool.add(cbFonts); tool.addSeparator(); sSizes = new JSpinner(new SpinnerNumberModel(12, 1, 100, 1)); sSizes.setRequestFocusEnabled(false); sSizes.setMaximumSize(sSizes.getPreferredSize()); sSizes.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (fSizeChange) { fSizeChange = false; return; } setSelectionAttribute(StyleConstants.Size, sSizes.getValue()); editor.grabFocus(); } }); tool.add(sSizes); tool.addSeparator(); tbBold = new JToggleButton(LGM.getIconForKey("GameInformationFrame.BOLD")); // $NON-NLS-1$ tbBold.setRequestFocusEnabled(false); lst = new ActionListener() { public void actionPerformed(ActionEvent arg0) { setSelectionAttribute(StyleConstants.Bold, tbBold.isSelected()); } }; tbBold.addActionListener(lst); tool.add(tbBold); tbItalic = new JToggleButton(LGM.getIconForKey("GameInformationFrame.ITALIC")); // $NON-NLS-1$ tbItalic.setRequestFocusEnabled(false); lst = new ActionListener() { public void actionPerformed(ActionEvent arg0) { setSelectionAttribute(StyleConstants.Italic, tbItalic.isSelected()); } }; tbItalic.addActionListener(lst); tool.add(tbItalic); tbUnderline = new JToggleButton(LGM.getIconForKey("GameInformationFrame.UNDERLINED")); // $NON-NLS-1$ tbUnderline.setRequestFocusEnabled(false); lst = new ActionListener() { public void actionPerformed(ActionEvent arg0) { setSelectionAttribute(StyleConstants.Underline, tbUnderline.isSelected()); } }; tbUnderline.addActionListener(lst); tool.add(tbUnderline); tool.addSeparator(); JButton butFontColor = new JButton(LGM.getIconForKey("GameInformationFrame.FONTCOLOR")); // $NON-NLS-1$ butFontColor.setRequestFocusEnabled(false); butFontColor.setActionCommand("GameInformationFrame.FONTCOLOR"); // $NON-NLS-1$ butFontColor.addActionListener(this); tool.add(butFontColor); JButton but = new JButton(LGM.getIconForKey("GameInformationFrame.COLOR")); // $NON-NLS-1$ but.setRequestFocusEnabled(false); but.setActionCommand("GameInformationFrame.COLOR"); // $NON-NLS-1$ but.addActionListener(this); tool.add(but); return tool; }
/** * Constructs the dialog window * * @param p Parent GUI */ public RegionEditorDialog(MapEditorGUI p) { parent = p; setLayout(null); /* * Initialize naming field */ JLabel l = new JLabel("Name"); l.setSize(l.getPreferredSize()); l.setLocation(10, 10); nameField = new JTextField("plains"); nameField.setSize(200, 24); nameField.setLocation(10, 32); add(l); add(nameField); /* * Initialize encounter spinner */ l = new JLabel("Encounter rate"); l.setSize(l.getPreferredSize()); l.setLocation(10, 64); eRateSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 20, 1)); eRateSpinner.setSize(eRateSpinner.getPreferredSize()); eRateSpinner.setLocation(210 - eRateSpinner.getWidth(), 62); add(l); add(eRateSpinner); /* * Initialize Terrain selector */ l = new JLabel("Terrain"); l.setSize(l.getPreferredSize()); l.setLocation(10, 96); terrain = new JComboBox(ToolKit.terrains); terrain.setSize(200, 24); terrain.setLocation(10, 120); add(l); add(terrain); /* * Initialize formation list */ l = new JLabel("Formations"); l.setSize(l.getPreferredSize()); l.setLocation(10, 156); fList = new JList(formations); fPane = new JScrollPane(fList); fPane.setSize(200, 160); fPane.setLocation(10, 172); add(l); add(fPane); /* * Initialize buttons */ okButton = new JButton("OK"); okButton.setSize(80, 24); okButton.setLocation(20, 380); okButton.addActionListener(this); cancelButton = new JButton("Cancel"); cancelButton.setSize(80, 24); cancelButton.setLocation(120, 380); cancelButton.addActionListener(this); add(okButton); add(cancelButton); fRemButton = new JButton("-"); fRemButton.setSize(fRemButton.getPreferredSize()); fRemButton.setLocation(210 - fRemButton.getWidth(), 335); fAddButton = new JButton("+"); fAddButton.setSize(fAddButton.getPreferredSize()); fAddButton.setLocation(fRemButton.getX() - fAddButton.getWidth(), 335); fEdtButton = new JButton("Edit"); fEdtButton.setSize(100, 24); fEdtButton.setLocation(10, 335); fAddButton.addActionListener(this); fRemButton.addActionListener(this); fEdtButton.addActionListener(this); add(fAddButton); add(fRemButton); add(fEdtButton); /* * Initialize dialog window */ setSize(230, 450); setVisible(true); setModal(true); setResizable(false); setTitle("Region Editor"); setLocationRelativeTo(parent); }
/** Builds the panel. */ public void setup() { DataModelList dataModelList = null; for (Object parentModel : parentModels) { if (parentModel instanceof DataWrapper) { DataWrapper dataWrapper = (DataWrapper) parentModel; dataModelList = dataWrapper.getDataModelList(); } } if (dataModelList == null) { throw new NullPointerException("Null data model list."); } for (DataModel model : dataModelList) { if (!(model instanceof DataSet)) { JOptionPane.showMessageDialog( JOptionUtils.centeringComp(), "For the shift search, all of the data in the data box must be in the form of data sets."); return; } } final List<DataSet> dataSets = new ArrayList<DataSet>(); for (Object aDataModelList : dataModelList) { dataSets.add((DataSet) aDataModelList); } SpinnerModel maxVarsModel = new SpinnerNumberModel( Preferences.userRoot().getInt("shiftSearchMaxNumShifts", 3), 1, 50, 1); JSpinner maxVarsSpinner = new JSpinner(maxVarsModel); maxVarsSpinner.setMaximumSize(maxVarsSpinner.getPreferredSize()); maxVarsSpinner.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); SpinnerNumberModel model = (SpinnerNumberModel) spinner.getModel(); int value = (Integer) model.getValue(); Preferences.userRoot().putInt("shiftSearchMaxNumShifts", value); } }); SpinnerModel maxShiftModel = new SpinnerNumberModel(Preferences.userRoot().getInt("shiftSearchMaxShift", 2), 1, 50, 1); JSpinner maxShiftSpinner = new JSpinner(maxShiftModel); maxShiftSpinner.setMaximumSize(maxShiftSpinner.getPreferredSize()); maxShiftSpinner.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); SpinnerNumberModel model = (SpinnerNumberModel) spinner.getModel(); int value = (Integer) model.getValue(); Preferences.userRoot().putInt("shiftSearchMaxShift", value); } }); JButton searchButton = new JButton("Search"); final JButton stopButton = new JButton("Stop"); final JTextArea textArea = new JTextArea(); JScrollPane textScroll = new JScrollPane(textArea); textScroll.setPreferredSize(new Dimension(500, 200)); searchButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { final Thread thread = new Thread() { public void run() { textArea.setText(""); doShiftSearch(dataSets, textArea); } }; thread.start(); } }); stopButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (search != null) { search.stop(); } } }); JComboBox directionBox = new JComboBox(new String[] {"forward", "backward"}); directionBox.setSelectedItem(params.isForwardSearch() ? "forward" : "backward"); directionBox.setMaximumSize(directionBox.getPreferredSize()); directionBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JComboBox source = (JComboBox) actionEvent.getSource(); String selected = (String) source.getSelectedItem(); params.setForwardSearch("forward".equals(selected)); } }); Box b1 = Box.createVerticalBox(); Box b2 = Box.createHorizontalBox(); b2.add(new JLabel("Maximum number of variables in shift set is: ")); b2.add(maxVarsSpinner); b2.add(Box.createHorizontalGlue()); b1.add(b2); Box b3 = Box.createHorizontalBox(); b3.add(new JLabel("Maximum ")); b3.add(directionBox); b3.add(new JLabel(" shift: ")); b3.add(maxShiftSpinner); b3.add(Box.createHorizontalGlue()); b1.add(b3); Box b4 = Box.createHorizontalBox(); b4.add(new JLabel("Output:")); b4.add(Box.createHorizontalGlue()); b1.add(b4); Box b5 = Box.createHorizontalBox(); b5.add(textScroll); b1.add(b5); Box b6 = Box.createHorizontalBox(); b6.add(searchButton); b6.add(stopButton); b1.add(b6); final Box a1 = Box.createVerticalBox(); Box a2 = Box.createHorizontalBox(); a2.add(new JLabel("Specify the shift (positive or negative) for each variable:")); a2.add(Box.createHorizontalGlue()); a1.add(a2); a1.add(Box.createVerticalStrut(20)); setUpA1(dataSets, a1); JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab("Shift", new JScrollPane(a1)); tabbedPane.addTab("Search", new JScrollPane(b1)); add(tabbedPane, BorderLayout.CENTER); tabbedPane.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { System.out.println("a1 shown"); a1.removeAll(); setUpA1(dataSets, a1); } }); }
private JToolBar makeToolBar() { JToolBar tool = new JToolBar(); tool.setFloatable(false); // Setup the buttons save.setRequestFocusEnabled(false); tool.add(save); tool.addSeparator(); JButton button; button = addToolButton("GameInformationFrame.CUT"); // $NON-NLS-1$ tool.add(button); button = addToolButton("GameInformationFrame.COPY"); // $NON-NLS-1$ tool.add(button); button = addToolButton("GameInformationFrame.PASTE"); // $NON-NLS-1$ tool.add(button); tool.addSeparator(); button = new JButton(undoManager.getUndoAction()); button.setText(""); button.setToolTipText(Messages.getString("GameInformationFrame.UNDO")); // $NON-NLS-1$ tool.add(button); button = new JButton(undoManager.getRedoAction()); button.setText(""); button.setToolTipText(Messages.getString("GameInformationFrame.REDO")); // $NON-NLS-1$ tool.add(button); tool.addSeparator(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontNames = ge.getAvailableFontFamilyNames(); cbFonts = new JComboBox<String>(fontNames); cbFonts.setRequestFocusEnabled(false); cbFonts.setMaximumSize(cbFonts.getPreferredSize()); cbFonts.setEditable(true); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { if (fFamilyChange) { fFamilyChange = false; return; } editor.grabFocus(); setSelectionAttribute(StyleConstants.Family, cbFonts.getSelectedItem().toString()); } }; cbFonts.addActionListener(lst); tool.add(cbFonts); tool.addSeparator(); sSizes = new JSpinner(new SpinnerNumberModel(12, 1, 100, 1)); sSizes.setRequestFocusEnabled(false); sSizes.setMaximumSize(sSizes.getPreferredSize()); sSizes.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (fSizeChange) { fSizeChange = false; return; } setSelectionAttribute(StyleConstants.Size, sSizes.getValue()); editor.grabFocus(); } }); tool.add(sSizes); tool.addSeparator(); tbBold = addToggleButton("GameInformationFrame.BOLD"); // $NON-NLS-1$ tbBold.setRequestFocusEnabled(false); tool.add(tbBold); tbItalic = addToggleButton("GameInformationFrame.ITALIC"); // $NON-NLS-1$ tbItalic.setRequestFocusEnabled(false); tool.add(tbItalic); tbUnderline = addToggleButton("GameInformationFrame.UNDERLINE"); // $NON-NLS-1$ tbUnderline.setRequestFocusEnabled(false); tool.add(tbUnderline); tool.addSeparator(); tbLeft = addToggleButton("GameInformationFrame.ALIGN_LEFT"); // $NON-NLS-1$ tbLeft.setRequestFocusEnabled(false); tbLeft.setSelected(true); tool.add(tbLeft); tbCenter = addToggleButton("GameInformationFrame.ALIGN_CENTER"); // $NON-NLS-1$ tbCenter.setRequestFocusEnabled(false); tool.add(tbCenter); tbRight = addToggleButton("GameInformationFrame.ALIGN_RIGHT"); // $NON-NLS-1$ tbRight.setRequestFocusEnabled(false); tool.add(tbRight); tool.addSeparator(); JButton butFontColor = new JButton(LGM.getIconForKey("GameInformationFrame.FONTCOLOR")); // $NON-NLS-1$ butFontColor.setRequestFocusEnabled(false); butFontColor.setActionCommand("GameInformationFrame.FONTCOLOR"); // $NON-NLS-1$ butFontColor.addActionListener(this); butFontColor.setToolTipText( Messages.getString("GameInformationFrame.FONTCOLOR")); // $NON-NLS-1$ tool.add(butFontColor); JButton but = new JButton(LGM.getIconForKey("GameInformationFrame.COLOR")); // $NON-NLS-1$ but.setRequestFocusEnabled(false); but.setActionCommand("GameInformationFrame.COLOR"); // $NON-NLS-1$ but.addActionListener(this); but.setToolTipText(Messages.getString("GameInformationFrame.COLOR")); // $NON-NLS-1$ tool.add(but); return tool; }
/** Construct a new font selector. */ public FontSelector() { Dimension d; // Widgets are laid out horizontally. setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); // Set up font family names and a 12-point normal font for each family. myFontFamilies = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); // Set up combo box for font family name. myFontFamilyComboBox = new JComboBox(myFontFamilies); d = myFontFamilyComboBox.getPreferredSize(); myFontFamilyComboBox.setMinimumSize(d); myFontFamilyComboBox.setMaximumSize(d); myFontFamilyComboBox.setPreferredSize(d); myFontFamilyComboBox.setEditable(false); myFontFamilyComboBox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { updateSelectedFont(); } } }); add(myFontFamilyComboBox); add(Box.createHorizontalStrut(GAP)); // Set up combo box for font style. myFontStyleComboBox = new JComboBox(new String[] {"Plain", "Bold", "Italic", "Bold Italic"}); d = myFontStyleComboBox.getPreferredSize(); myFontStyleComboBox.setMinimumSize(d); myFontStyleComboBox.setMaximumSize(d); myFontStyleComboBox.setPreferredSize(d); myFontStyleComboBox.setEditable(false); myFontStyleComboBox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { updateSelectedFont(); } } }); add(myFontStyleComboBox); add(Box.createHorizontalStrut(GAP)); // Set up spinner for font size. myFontSizeSpinner = new JSpinner(new SpinnerNumberModel(12, 1, 144, 1)); d = myFontSizeSpinner.getPreferredSize(); myFontSizeSpinner.setMinimumSize(d); myFontSizeSpinner.setMaximumSize(d); myFontSizeSpinner.setPreferredSize(d); myFontSizeSpinner.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { updateSelectedFont(); } }); add(myFontSizeSpinner); add(Box.createHorizontalStrut(GAP)); // Set up text sample. myTextSample = new JLabel("Quick Brown Fox 123"); d = myTextSample.getPreferredSize(); myTextSample.setMinimumSize(d); myTextSample.setMaximumSize(d); myTextSample.setPreferredSize(d); add(myTextSample); // Set default selected font. setSelectedFont(new Font("SansSerif", Font.PLAIN, 12)); }
private void initializeComponents() { this.setTitle("Configuration"); this.setResizable(false); setLayout(new BorderLayout(20, 20)); JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS)); mainPanel.setBorder(new LineBorder(mainPanel.getBackground(), 10)); add(mainPanel, BorderLayout.CENTER); GridBagConstraints labelConstraints = new GridBagConstraints(); labelConstraints.gridx = 0; labelConstraints.anchor = GridBagConstraints.WEST; labelConstraints.insets = new Insets(5, 5, 5, 5); GridBagConstraints inputConstraints = new GridBagConstraints(); inputConstraints.gridx = 1; inputConstraints.anchor = GridBagConstraints.EAST; inputConstraints.weightx = 1; inputConstraints.insets = new Insets(5, 5, 5, 5); JPanel evolutionOptionsPanel = new JPanel(); evolutionOptionsPanel.setBorder(new TitledBorder("Evolution")); evolutionOptionsPanel.setLayout(new BoxLayout(evolutionOptionsPanel, BoxLayout.Y_AXIS)); mainPanel.add(evolutionOptionsPanel); // world size JPanel worldSizePanel = new JPanel(new GridBagLayout()); evolutionOptionsPanel.add(worldSizePanel); JLabel worldSizeLabel = new JLabel("World Size"); worldSizeLabel.setToolTipText("Size of the world in pixels. Width x Height."); worldSizePanel.add(worldSizeLabel, labelConstraints); JPanel worldSizeInputPanel = new JPanel(); worldSizeInputPanel.setLayout(new GridBagLayout()); final AutoSelectOnFocusSpinner worldSizeWidthSpinner = new AutoSelectOnFocusSpinner( new SpinnerNumberModel(config.getDimension().width, 1, Integer.MAX_VALUE, 1)); final AutoSelectOnFocusSpinner worldSizeHeightSpinner = new AutoSelectOnFocusSpinner( new SpinnerNumberModel(config.getDimension().height, 1, Integer.MAX_VALUE, 1)); worldSizeInputPanel.add(worldSizeWidthSpinner); JLabel separatorLabel = new JLabel("x"); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(0, 5, 0, 5); worldSizeInputPanel.add(separatorLabel, c); worldSizeInputPanel.add(worldSizeHeightSpinner); worldSizePanel.add(worldSizeInputPanel, inputConstraints); // starting energy JPanel startingEnergyPanel = new JPanel(new GridBagLayout()); evolutionOptionsPanel.add(startingEnergyPanel); JLabel startingEnergyLabel = new JLabel("Starting Energy"); startingEnergyLabel.setToolTipText( "<html>The amount of energy all newly painted pixels start out with.<br />Note that changing this will not affect already painted pixels.</html>"); startingEnergyPanel.add(startingEnergyLabel, labelConstraints); final AutoSelectOnFocusSpinner startingEnergySpinner = new AutoSelectOnFocusSpinner( new SpinnerNumberModel(config.startingEnergy, 1, Integer.MAX_VALUE, 1)); startingEnergyPanel.add(startingEnergySpinner, inputConstraints); // mutation rate JPanel mutationRatePanel = new JPanel(new GridBagLayout()); evolutionOptionsPanel.add(mutationRatePanel); JLabel mutationRateLabel = new JLabel("Mutation Rate"); mutationRateLabel.setToolTipText( "<html>Chance for a mutation to occur during copy or mixing operations.<br />A value of 0.01 means a 1% chance, a value of 0 disables mutation.</html>"); mutationRatePanel.add(mutationRateLabel, labelConstraints); final JSpinner mutationRateSpinner = new JSpinner(new SpinnerNumberModel(config.mutationRate, 0.0, 1.0, 0.01)); mutationRateSpinner.setEditor( new JSpinner.NumberEditor(mutationRateSpinner, "#.##############")); mutationRateSpinner.setPreferredSize( new Dimension(180, mutationRateSpinner.getPreferredSize().height)); final JFormattedTextField mutationRateSpinnerText = ((JSpinner.NumberEditor) mutationRateSpinner.getEditor()).getTextField(); mutationRateSpinnerText.addFocusListener( new FocusListener() { public void focusGained(FocusEvent e) { SwingUtilities.invokeLater( new Runnable() { public void run() { mutationRateSpinnerText.selectAll(); } }); } public void focusLost(FocusEvent e) {} }); mutationRatePanel.add(mutationRateSpinner, inputConstraints); JPanel guiOptionsPanel = new JPanel(); guiOptionsPanel.setBorder(new TitledBorder("GUI")); guiOptionsPanel.setLayout(new BoxLayout(guiOptionsPanel, BoxLayout.Y_AXIS)); mainPanel.add(guiOptionsPanel); // background color JPanel backgroundColorPanel = new JPanel(new GridBagLayout()); guiOptionsPanel.add(backgroundColorPanel, labelConstraints); JLabel backgroundColorLabel = new JLabel("Background Color"); backgroundColorLabel.setToolTipText( "<html>Pick the background color.<br />If you have a lot of dark pixels, you might want to set this to a light color.</html>"); backgroundColorPanel.add(backgroundColorLabel, labelConstraints); backgroundColor = new PixelColor(config.backgroundColor); JPanel backgroundColorAlignmentPanel = new JPanel(); backgroundColorAlignmentPanel.setLayout(new GridBagLayout()); backgroundColorAlignmentPanel.setPreferredSize(mutationRateSpinner.getPreferredSize()); final ColorChooserLabel backgroundColorChooserLabel = new ColorChooserLabel(backgroundColor); backgroundColorAlignmentPanel.add(backgroundColorChooserLabel); backgroundColorPanel.add(backgroundColorAlignmentPanel, inputConstraints); // FPS JPanel fpsPanel = new JPanel(new GridBagLayout()); guiOptionsPanel.add(fpsPanel); JLabel fpsLabel = new JLabel("FPS"); fpsLabel.setToolTipText( "<html>The repaint interval in frames per second (FPS).<br />Set this to a lower value to save a few CPU cycles.</html>"); fpsPanel.add(fpsLabel, labelConstraints); final AutoSelectOnFocusSpinner fpsSpinner = new AutoSelectOnFocusSpinner(new SpinnerNumberModel(config.fps, 1, Integer.MAX_VALUE, 1)); fpsPanel.add(fpsSpinner, inputConstraints); // paint history size JPanel paintHistorySizePanel = new JPanel(new GridBagLayout()); guiOptionsPanel.add(paintHistorySizePanel); JLabel paintHistorySizeLabel = new JLabel("Paint-History Size"); paintHistorySizeLabel.setToolTipText( "<html>Sets the number of entries in the paint history.<br />In case you have not found it yet: the paint history is the little menu that appears when you right-click on the image.</html>"); paintHistorySizePanel.add(paintHistorySizeLabel, labelConstraints); final AutoSelectOnFocusSpinner paintHistorySizeSpinner = new AutoSelectOnFocusSpinner( new SpinnerNumberModel(config.paintHistorySize, 1, Integer.MAX_VALUE, 1)); paintHistorySizePanel.add(paintHistorySizeSpinner, inputConstraints); JPanel videoOptionsPanel = new JPanel(); videoOptionsPanel.setBorder(new TitledBorder("Video Recording")); videoOptionsPanel.setLayout(new BoxLayout(videoOptionsPanel, BoxLayout.Y_AXIS)); mainPanel.add(videoOptionsPanel); // FPS video JPanel fpsVideoPanel = new JPanel(new GridBagLayout()); videoOptionsPanel.add(fpsVideoPanel); JLabel fpsVideoLabel = new JLabel("FPS of videos"); fpsVideoLabel.setToolTipText("The number of frames per second (FPS) in recorded videos."); fpsVideoPanel.add(fpsVideoLabel, labelConstraints); final AutoSelectOnFocusSpinner fpsVideoSpinner = new AutoSelectOnFocusSpinner( new SpinnerNumberModel(config.fpsVideo, 1, Integer.MAX_VALUE, 1)); fpsVideoPanel.add(fpsVideoSpinner, inputConstraints); // video encoder command JPanel videoEncoderPanel = new JPanel(new GridBagLayout()); videoOptionsPanel.add(videoEncoderPanel); JLabel videoEncoderLabel = new JLabel("Video Encoder"); videoEncoderLabel.setToolTipText( "<html>The command to invoke your video encoder.<br />Use the tokens INPUT_FILE and OUTPUT_FILE to denote input and output files of your encoder.</html>"); videoEncoderPanel.add(videoEncoderLabel, labelConstraints); final JTextArea videoEncoderTextArea = new JTextArea(Configuration.ENCODER_COMMAND); videoEncoderTextArea.setLineWrap(true); videoEncoderTextArea.setWrapStyleWord(true); JScrollPane videoEncoderScrollPane = new JScrollPane( videoEncoderTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); videoEncoderScrollPane.setViewportBorder(null); videoEncoderScrollPane.setPreferredSize( new Dimension(worldSizeInputPanel.getPreferredSize().width, 100)); videoEncoderPanel.add(videoEncoderScrollPane, inputConstraints); JPanel controlPanel = new JPanel(); add(controlPanel, BorderLayout.SOUTH); JButton okButton = new JButton("OK"); okButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new Thread() { @Override public void run() { config.world.addChangeListener( new IChangeListener() { public void changed() { int i, j; double d; String s; // evolution i = (Integer) worldSizeWidthSpinner.getValue(); j = (Integer) worldSizeHeightSpinner.getValue(); if (config.getDimension().width != i || config.getDimension().height != i) { config.setDimension(new Dimension(i, j)); } i = (Integer) startingEnergySpinner.getValue(); if (config.startingEnergy != i) { config.startingEnergy = i; } d = (Double) mutationRateSpinner.getValue(); if (config.mutationRate != d) { config.mutationRate = d; } // gui i = backgroundColor.getInteger(); if (config.backgroundColor != i) { config.backgroundColor = i; } i = (Integer) fpsSpinner.getValue(); if (config.fps != i) { config.fps = i; } i = (Integer) paintHistorySizeSpinner.getValue(); if (config.paintHistorySize != i) { config.paintHistorySize = i; } // video recording i = (Integer) fpsVideoSpinner.getValue(); if (config.fpsVideo != i) { config.fpsVideo = i; } s = videoEncoderTextArea.getText(); if (false == Configuration.ENCODER_COMMAND.equals(s)) { Configuration.ENCODER_COMMAND = s; } dispose(); } }); } }.start(); } }); controlPanel.add(okButton); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); controlPanel.add(cancelButton); pack(); }
private JComponent getButtonPanel() { JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); choiceType = new JComboBox<PersonTypeItem>(); choiceType.setMaximumSize( new Dimension(Short.MAX_VALUE, (int) choiceType.getPreferredSize().getHeight())); DefaultComboBoxModel<PersonTypeItem> personTypeModel = new DefaultComboBoxModel<>(); personTypeModel.addElement( new PersonTypeItem(resourceMap.getString("primaryRole.choice.text"), null)); // $NON-NLS-1$ for (int i = 1; i < Person.T_NUM; ++i) { personTypeModel.addElement( new PersonTypeItem(Person.getRoleDesc(i, campaign.getFaction().isClan()), i)); } personTypeModel.addElement( new PersonTypeItem(Person.getRoleDesc(0, campaign.getFaction().isClan()), 0)); // Add "none" for generic AsTechs choiceType.setModel(personTypeModel); choiceType.setSelectedIndex(0); choiceType.addActionListener( e -> { personnelFilter.setPrimaryRole(((PersonTypeItem) choiceType.getSelectedItem()).id); updatePersonnelTable(); }); panel.add(choiceType); choiceExp = new JComboBox<PersonTypeItem>(); choiceExp.setMaximumSize( new Dimension(Short.MAX_VALUE, (int) choiceType.getPreferredSize().getHeight())); DefaultComboBoxModel<PersonTypeItem> personExpModel = new DefaultComboBoxModel<>(); personExpModel.addElement( new PersonTypeItem(resourceMap.getString("experience.choice.text"), null)); // $NON-NLS-1$ for (int i = 0; i < 5; ++i) { personExpModel.addElement(new PersonTypeItem(SkillType.getExperienceLevelName(i), i)); } choiceExp.setModel(personExpModel); choiceExp.setSelectedIndex(0); choiceExp.addActionListener( e -> { personnelFilter.setExpLevel(((PersonTypeItem) choiceExp.getSelectedItem()).id); updatePersonnelTable(); }); panel.add(choiceExp); choiceSkill = new JComboBox<String>(); choiceSkill.setMaximumSize( new Dimension(Short.MAX_VALUE, (int) choiceSkill.getPreferredSize().getHeight())); DefaultComboBoxModel<String> personSkillModel = new DefaultComboBoxModel<>(); personSkillModel.addElement(choiceNoSkill); for (String skill : SkillType.getSkillList()) { personSkillModel.addElement(skill); } choiceSkill.setModel(personSkillModel); choiceSkill.setSelectedIndex(0); choiceSkill.addActionListener( e -> { if (choiceNoSkill.equals(choiceSkill.getSelectedItem())) { personnelFilter.setSkill(null); ((SpinnerNumberModel) skillLevel.getModel()).setMaximum(10); buttonSpendXP.setEnabled(false); } else { String skillName = (String) choiceSkill.getSelectedItem(); personnelFilter.setSkill(skillName); int maxSkillLevel = SkillType.getType(skillName).getMaxLevel(); int currentLevel = (Integer) skillLevel.getModel().getValue(); ((SpinnerNumberModel) skillLevel.getModel()).setMaximum(maxSkillLevel); if (currentLevel > maxSkillLevel) { skillLevel.getModel().setValue(Integer.valueOf(maxSkillLevel)); } buttonSpendXP.setEnabled(true); } updatePersonnelTable(); }); panel.add(choiceSkill); panel.add(Box.createRigidArea(new Dimension(10, 10))); panel.add(new JLabel(resourceMap.getString("targetSkillLevel.text"))); // $NON-NLS-1$ skillLevel = new JSpinner(new SpinnerNumberModel(10, 0, 10, 1)); skillLevel.setMaximumSize( new Dimension(Short.MAX_VALUE, (int) skillLevel.getPreferredSize().getHeight())); skillLevel.addChangeListener( e -> { personnelFilter.setMaxSkillLevel((Integer) skillLevel.getModel().getValue()); updatePersonnelTable(); }); panel.add(skillLevel); allowPrisoners = new JCheckBox(resourceMap.getString("allowPrisoners.text")); // $NON-NLS-1$ allowPrisoners.setHorizontalAlignment(SwingConstants.LEFT); allowPrisoners.setMaximumSize( new Dimension(Short.MAX_VALUE, (int) allowPrisoners.getPreferredSize().getHeight())); allowPrisoners.addChangeListener( e -> { personnelFilter.setAllowPrisoners(allowPrisoners.isSelected()); updatePersonnelTable(); }); JPanel allowPrisonersPanel = new JPanel(new GridLayout(1, 1)); allowPrisonersPanel.setAlignmentY(JComponent.LEFT_ALIGNMENT); allowPrisonersPanel.add(allowPrisoners); allowPrisonersPanel.setMaximumSize( new Dimension(Short.MAX_VALUE, (int) allowPrisonersPanel.getPreferredSize().getHeight())); panel.add(allowPrisonersPanel); panel.add(Box.createVerticalGlue()); matchedPersonnelLabel = new JLabel(""); // $NON-NLS-1$ matchedPersonnelLabel.setMaximumSize( new Dimension(Short.MAX_VALUE, (int) matchedPersonnelLabel.getPreferredSize().getHeight())); panel.add(matchedPersonnelLabel); JPanel buttons = new JPanel(new FlowLayout()); buttons.setMaximumSize( new Dimension(Short.MAX_VALUE, (int) buttons.getPreferredSize().getHeight())); buttonSpendXP = new JButton(resourceMap.getString("spendXP.text")); // $NON-NLS-1$ buttonSpendXP.setEnabled(false); buttonSpendXP.addActionListener(e -> spendXP()); buttons.add(buttonSpendXP); JButton button = new JButton(resourceMap.getString("close.text")); // $NON-NLS-1$ button.addActionListener(e -> setVisible(false)); buttons.add(button); panel.add(buttons); panel.setMaximumSize(new Dimension((int) panel.getPreferredSize().getWidth(), Short.MAX_VALUE)); panel.setMinimumSize(new Dimension((int) panel.getPreferredSize().getWidth(), 300)); return panel; }
private JPanel generateConfigPanel() { final JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(3, 3, 3, 3); final JSpinner spinnerThreshold = new JSpinner(new SpinnerNumberModel(getThreshold(), 0.0, Double.MAX_VALUE, 0.1)); final JSpinner spinnerLowValue = new JSpinner( new SpinnerNumberModel(getLowValue(), -Double.MAX_VALUE, Double.MAX_VALUE, 0.1)); final JSpinner spinnerHighValue = new JSpinner( new SpinnerNumberModel(getHighValue(), -Double.MAX_VALUE, Double.MAX_VALUE, 0.1)); Dimension prefSize = new Dimension(120, spinnerThreshold.getPreferredSize().height); spinnerThreshold.setPreferredSize(prefSize); spinnerLowValue.setPreferredSize(prefSize); spinnerHighValue.setPreferredSize(prefSize); spinnerThreshold.setEditor(new JSpinner.NumberEditor(spinnerThreshold, "0.00")); spinnerLowValue.setEditor(new JSpinner.NumberEditor(spinnerLowValue, "0.00")); spinnerHighValue.setEditor(new JSpinner.NumberEditor(spinnerHighValue, "0.00")); gbc.gridx = 1; gbc.gridy = 1; panel.add(new JLabel(" Threshold: "), gbc); gbc.gridx++; panel.add(spinnerThreshold, gbc); gbc.gridx++; panel.add(new JLabel(" Low value: "), gbc); gbc.gridx++; panel.add(spinnerLowValue, gbc); gbc.gridx++; panel.add(new JLabel(" High value: "), gbc); gbc.gridx++; panel.add(spinnerHighValue, gbc); spinnerThreshold.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { setThreshold( ((SpinnerNumberModel) spinnerThreshold.getModel()).getNumber().doubleValue()); panel.firePropertyChange(DataGenerator.property, 0, System.currentTimeMillis()); } }); spinnerLowValue.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { setLowValue( ((SpinnerNumberModel) spinnerLowValue.getModel()).getNumber().doubleValue()); panel.firePropertyChange(DataGenerator.property, 0, System.currentTimeMillis()); } }); spinnerHighValue.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { setHighValue( ((SpinnerNumberModel) spinnerHighValue.getModel()).getNumber().doubleValue()); panel.firePropertyChange(DataGenerator.property, 0, System.currentTimeMillis()); } }); return panel; }