List of usage examples for javax.swing Box createHorizontalBox
public static Box createHorizontalBox()
Box
that displays its components from left to right. From source file:econtroller.gui.ControllerGUI.java
private void createSenseSlider() { Box hbox = Box.createHorizontalBox(); senseLabel = new JLabel("Sense every ", JLabel.CENTER); senseValueLabel = new JLabel(String.valueOf(SENSE_INIT), JLabel.CENTER); senseSecondLabel = new JLabel(" (s)", JLabel.CENTER); senseSlider = new JSlider(JSlider.HORIZONTAL, SENSE_MIN, SENSE_MAX, SENSE_INIT); senseSlider.setMajorTickSpacing(20); senseSlider.setMinorTickSpacing(5);/*w ww. j av a 2 s . c om*/ senseSlider.setPaintLabels(true); senseSlider.setPaintTicks(true); senseSlider.setPaintTrack(true); senseSlider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent changeEvent) { JSlider source = (JSlider) changeEvent.getSource(); int value = source.getValue(); senseValueLabel.setText(String.valueOf(value)); } }); hbox.add(senseLabel); hbox.add(senseValueLabel); hbox.add(senseSecondLabel); controllerDesignPanel.add(hbox); controllerDesignPanel.add(senseSlider); }
From source file:cellularAutomata.analysis.PricingDistributionAnalysis.java
/** * Create the panel used to display the pricing statistics. *//*w w w.j a v a2 s . c o m*/ private void createDisplayPanel() { int displayWidth = CAFrame.tabbedPaneDimension.width; int displayHeight = 600 + (100 * numberOfStates); // create the display panel if (displayPanel == null) { displayPanel = new JPanel(new GridBagLayout()); displayPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); displayPanel.setPreferredSize(new Dimension(displayWidth, displayHeight)); } else { displayPanel.removeAll(); } if (isCompatibleRule && (numberOfStates <= MAX_NUMBER_OF_STATES)) { // create a panel that displays messages JPanel messagePanel = createMessagePanel(); // create the labels for the display createDataDisplayLabels(); JLabel generationLabel = new JLabel("Generation: "); JLabel stateLabel = new JLabel("State:"); JLabel numStateLabel = new JLabel("Number:"); JLabel percentOccupiedLabel = new JLabel("Kurtosis:"); // create boxes for each column of the display (a Box uses the // BoxLayout, so it is handy for laying out components) Box boxOfStateLabels = Box.createVerticalBox(); Box boxOfNumberLabels = Box.createVerticalBox(); Box boxOfPercentLabels = Box.createVerticalBox(); // the amount of vertical space to put between components int verticalSpace = 5; // add the states to the first vertical box boxOfStateLabels.add(stateLabel); boxOfStateLabels.add(Box.createVerticalStrut(verticalSpace)); for (int state = 0; state < numberOfStates; state++) { boxOfStateLabels.add(new JLabel("" + state)); boxOfStateLabels.add(Box.createVerticalStrut(verticalSpace)); } // add the numbers (in each state) to the second vertical box boxOfNumberLabels.add(numStateLabel); boxOfNumberLabels.add(Box.createVerticalStrut(verticalSpace)); for (int i = 0; i < numberOfStates; i++) { boxOfNumberLabels.add(numberOccupiedByStateDataLabel[i]); boxOfNumberLabels.add(Box.createVerticalStrut(verticalSpace)); } // add the percents (in each state) to the third vertical box boxOfPercentLabels.add(percentOccupiedLabel); boxOfPercentLabels.add(Box.createVerticalStrut(verticalSpace)); for (int i = 0; i < numberOfStates; i++) { boxOfPercentLabels.add(percentOccupiedByStateDataLabel[i]); boxOfPercentLabels.add(Box.createVerticalStrut(verticalSpace)); } // create another box that holds all of the label boxes Box boxOfLabels = Box.createHorizontalBox(); boxOfLabels.add(boxOfStateLabels); boxOfLabels.add(boxOfNumberLabels); boxOfLabels.add(boxOfPercentLabels); boxOfLabels.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7)); // put the boxOfLabels in a scrollPane -- with many states, will get // very large JScrollPane stateScroller = new JScrollPane(boxOfLabels); int scrollPaneWidth = (int) (displayWidth * 0.8); int scrollPaneHeight = displayHeight / 4; stateScroller.setPreferredSize(new Dimension(scrollPaneWidth, scrollPaneHeight)); stateScroller.setMinimumSize(new Dimension(scrollPaneWidth, scrollPaneHeight)); stateScroller.setMaximumSize(new Dimension(scrollPaneWidth, scrollPaneHeight)); stateScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); // create a "plot zero state" check box plotZeroStateCheckBox = new JCheckBox(PLOT_ZERO_STATE); plotZeroStateCheckBox.setSelected(true); plotZeroStateCheckBox.setToolTipText(PLOT_ZERO_STATE_TOOLTIP); plotZeroStateCheckBox.setActionCommand(PLOT_ZERO_STATE); plotZeroStateCheckBox.addActionListener(this); JPanel plotZeroStatePanel = new JPanel(new BorderLayout()); plotZeroStatePanel.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7)); plotZeroStatePanel.add(BorderLayout.CENTER, plotZeroStateCheckBox); // create a "save data" check box saveDataCheckBox = new JCheckBox(SAVE_DATA); saveDataCheckBox.setToolTipText(SAVE_DATA_TOOLTIP); saveDataCheckBox.setActionCommand(SAVE_DATA); saveDataCheckBox.addActionListener(this); JPanel saveDataPanel = new JPanel(new BorderLayout()); saveDataPanel.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7)); saveDataPanel.add(BorderLayout.CENTER, saveDataCheckBox); // create a panel that plots the data plot = new SimplePlot(); // add all the components to the panel int row = 0; displayPanel.add(messagePanel, new GBC(1, row).setSpan(4, 1).setFill(GBC.BOTH).setWeight(1.0, 1.0) .setAnchor(GBC.WEST).setInsets(1)); row++; displayPanel.add(plot, new GBC(1, row).setSpan(4, 1).setFill(GBC.BOTH).setWeight(10.0, 10.0) .setAnchor(GBC.WEST).setInsets(1)); row++; for (int i = 0; i < numberOfStates; i++) { timeSeriesPlot[i] = new SimplePlot(); displayPanel.add(timeSeriesPlot[i], new GBC(1, row).setSpan(4, 1).setFill(GBC.BOTH) .setWeight(10.0, 10.0).setAnchor(GBC.WEST).setInsets(1)); row++; } displayPanel.add(plotZeroStatePanel, new GBC(1, row).setSpan(4, 1).setFill(GBC.NONE).setWeight(1.0, 1.0) .setAnchor(GBC.CENTER).setInsets(1)); row++; displayPanel.add(generationLabel, new GBC(1, row).setSpan(1, 1).setFill(GBC.NONE).setWeight(1.0, 1.0) .setAnchor(GBC.EAST).setInsets(1)); displayPanel.add(generationDataLabel, new GBC(2, row).setSpan(1, 1).setFill(GBC.NONE) .setWeight(1.0, 1.0).setAnchor(GBC.WEST).setInsets(1)); row++; displayPanel.add(stateScroller, new GBC(1, row).setSpan(4, 1).setFill(GBC.BOTH).setWeight(1.0, 1.0) .setAnchor(GBC.WEST).setInsets(1)); row++; displayPanel.add(saveDataPanel, new GBC(1, row).setSpan(4, 1).setFill(GBC.NONE).setWeight(1.0, 1.0) .setAnchor(GBC.CENTER).setInsets(1)); } else { int row = 0; displayPanel.add(createWarningMessagePanel(), new GBC(1, row).setSpan(4, 1).setFill(GBC.BOTH) .setWeight(1.0, 1.0).setAnchor(GBC.WEST).setInsets(1)); } }
From source file:com.diversityarrays.kdxplore.trials.TrialSelectionDialog.java
@Override protected Component createBottomRowComponent() { Box buttons = Box.createHorizontalBox(); buttons.add(Box.createHorizontalStrut(10)); buttons.add(wantTrialUnits);//from www .j a v a2 s.c o m if (RunMode.getRunMode().isDeveloper()) { wantTrialUnits.setSelected(true); } buttons.add(new JButton(findTrialRecords)); buttons.add(Box.createHorizontalGlue()); buttons.add(new JButton(getOkAction())); buttons.add(new JButton(getCancelAction())); buttons.add(Box.createHorizontalStrut(10)); return buttons; }
From source file:econtroller.gui.ControllerGUI.java
private void createActSlider() { Box hbox = Box.createHorizontalBox(); actLabel = new JLabel("Act every ", JLabel.CENTER); actValueLabel = new JLabel(String.valueOf(ACT_INIT), JLabel.CENTER); actSecondLabel = new JLabel(" (s)", JLabel.CENTER); actSlider = new JSlider(); actSlider = new JSlider(JSlider.HORIZONTAL, ACT_MIN, ACT_MAX, ACT_INIT); actSlider.setMajorTickSpacing(20);/* w w w . j a va 2 s. co m*/ actSlider.setMinorTickSpacing(5); actSlider.setPaintLabels(true); actSlider.setPaintTicks(true); actSlider.setPaintTrack(true); actSlider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent changeEvent) { JSlider source = (JSlider) changeEvent.getSource(); int value = source.getValue(); actValueLabel.setText(String.valueOf(value)); } }); hbox.add(actLabel); hbox.add(actValueLabel); hbox.add(actSecondLabel); controllerDesignPanel.add(hbox); controllerDesignPanel.add(actSlider); }
From source file:com.diversityarrays.kdxplore.trials.AddScoringSetDialog.java
public AddScoringSetDialog(Window owner, KdxploreDatabase kdxdb, Trial trial, Map<Trait, List<TraitInstance>> instancesByTrait, SampleGroup curatedSampleGroup) { super(owner, Msg.TITLE_ADD_SCORING_SET(), ModalityType.APPLICATION_MODAL); setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.kdxploreDatabase = kdxdb; this.trial = trial; this.curatedSampleGroupId = curatedSampleGroup == null ? 0 : curatedSampleGroup.getSampleGroupId(); Map<Trait, List<TraitInstance>> noCalcs = instancesByTrait.entrySet().stream() .filter(e -> TraitDataType.CALC != e.getKey().getTraitDataType()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); Map<Trait, List<TraitInstance>> noCalcsSorted = new TreeMap<>(TRAIT_COMPARATOR); noCalcsSorted.putAll(noCalcs);/*from w ww. j ava 2 s. c o m*/ BiFunction<Trait, TraitInstance, String> parentNameProvider = new BiFunction<Trait, TraitInstance, String>() { @Override public String apply(Trait t, TraitInstance ti) { if (ti == null) { List<TraitInstance> list = noCalcsSorted.get(t); if (list == null || list.size() != 1) { OptionalInt opt = traitInstanceChoiceTreeModel.getChildChosenCountIfNotAllChosen(t); StringBuilder sb = new StringBuilder(t.getTraitName()); if (opt.isPresent()) { // only some of the children are chosen int childChosenCount = opt.getAsInt(); if (childChosenCount > 0) { sb.append(" (").append(childChosenCount).append(" of ").append(list.size()) .append(")"); } } else { // all of the children are chosen if (list != null) { sb.append(" (").append(list.size()).append(")"); } } return sb.toString(); } } return t.getTraitName(); } }; Optional<List<TraitInstance>> opt = noCalcsSorted.values().stream().filter(list -> list.size() > 1) .findFirst(); String heading1 = opt.isPresent() ? "Trait/Instance" : "Trait"; traitInstanceChoiceTreeModel = new ChoiceTreeTableModel<>(heading1, "Use?", //$NON-NLS-1$ noCalcsSorted, parentNameProvider, childNameProvider); // traitInstanceChoiceTreeModel = new TTChoiceTreeTableModel(instancesByTrait); traitInstanceChoiceTreeModel.addChoiceChangedListener(new ChoiceChangedListener() { @Override public void choiceChanged(Object source, ChoiceNode[] changedNodes) { updateCreateAction("choiceChanged"); treeTable.repaint(); } }); traitInstanceChoiceTreeModel.addTreeModelListener(new TreeModelListener() { @Override public void treeStructureChanged(TreeModelEvent e) { } @Override public void treeNodesRemoved(TreeModelEvent e) { } @Override public void treeNodesInserted(TreeModelEvent e) { } @Override public void treeNodesChanged(TreeModelEvent e) { updateCreateAction("treeNodesChanged"); } }); warningMsg.setText(PLEASE_PROVIDE_A_DESCRIPTION); warningMsg.setForeground(Color.RED); Container cp = getContentPane(); Box sampleButtons = null; if (curatedSampleGroup != null && curatedSampleGroup.getAnyScoredSamples()) { sampleButtons = createWantSampleButtons(curatedSampleGroup); } Box top = Box.createVerticalBox(); if (sampleButtons == null) { top.add(new JLabel(Msg.MSG_THERE_ARE_NO_CURATED_SAMPLES())); } else { top.add(sampleButtons); } top.add(descriptionField); cp.add(top, BorderLayout.NORTH); descriptionField.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { updateCreateAction("documentListener"); } @Override public void insertUpdate(DocumentEvent e) { updateCreateAction("documentListener"); } @Override public void changedUpdate(DocumentEvent e) { updateCreateAction("documentListener"); } }); updateCreateAction("init"); // KDClientUtils.initAction(ImageId.`CHECK_ALL, useAllAction, "Click to Use All"); treeTable = new JXTreeTable(traitInstanceChoiceTreeModel); treeTable.setAutoResizeMode(JXTreeTable.AUTO_RESIZE_ALL_COLUMNS); TableCellRenderer renderer = treeTable.getDefaultRenderer(Integer.class); if (renderer instanceof JLabel) { ((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER); } Box buttons = Box.createHorizontalBox(); buttons.add(new JButton(useAllAction)); buttons.add(new JButton(useNoneAction)); buttons.add(Box.createHorizontalGlue()); buttons.add(warningMsg); buttons.add(new JButton(cancelAction)); buttons.add(Box.createHorizontalStrut(10)); buttons.add(new JButton(createAction)); cp.add(new JScrollPane(treeTable), BorderLayout.CENTER); cp.add(buttons, BorderLayout.SOUTH); pack(); }
From source file:com.diversityarrays.kdxplore.trials.TrialSelectionDialog.java
@SuppressWarnings("rawtypes") @Override//w w w .j a va 2 s. c o m protected Component createMainPanel() { CheckSelectionButtonsPanel csbp = new CheckSelectionButtonsPanel(CheckSelectionButtonsPanel.ALL, trialRecordTable); csbp.addUncheckAllActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trialRecordTableModel.clearChosen(); } }); csbp.addCheckAllActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trialRecordTableModel.chooseAll(); } }); csbp.addCheckSelectedActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Integer> selectedModelRows = GuiUtil.getSelectedModelRows(trialRecordTable); trialRecordTableModel.addChosenRows(selectedModelRows); } }); csbp.addCheckUnselectedActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Set<Integer> selectedModelRows = new HashSet<>(GuiUtil.getSelectedModelRows(trialRecordTable)); if (selectedModelRows.isEmpty()) { trialRecordTableModel.chooseAll(); } else { List<Integer> rowsToChoose = new ArrayList<>(); for (int mrow = trialRecordTable.getRowCount(); --mrow >= 0;) { if (!selectedModelRows.contains(mrow)) { rowsToChoose.add(mrow); } } trialRecordTableModel.addChosenRows(rowsToChoose); } } }); Box buttons = Box.createHorizontalBox(); buttons.add(Box.createHorizontalGlue()); buttons.add(new JLabel("Select one or more and click '" + USE_TRIALS + "'")); buttons.add(csbp); buttons.add(Box.createHorizontalGlue()); List<TableColumn> columns = DartEntityTableModel.collectNamedColumns(trialRecordTable, trialRecordTableModel, true, "TrialName", "Site", "# Plots", "# Measurements", "Design", "Manager", "TrialType", "Project", "Start Date"); // List<TableColumn> columns = DartEntityTableModel.collectNonExpertColumns(trialRecordTable, trialRecordTableModel, true); Map<String, TableColumn[]> choices = new HashMap<>(); choices.put(INITIAL_COLUMNS_TAGNAME, columns.toArray(new TableColumn[columns.size()])); TableColumnSelectionButton tcsb = new TableColumnSelectionButton(trialRecordTable, choices); tcsb.setSelectedColumns(INITIAL_COLUMNS_TAGNAME); trialRecordTable.setRowSorter(new TableRowSorter<DartEntityTableModel>(trialRecordTableModel)); JScrollPane scrollPane = new JScrollPane(trialRecordTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, tcsb); JPanel trialsPanel = new JPanel(new BorderLayout()); trialsPanel.add(messageLabel, BorderLayout.NORTH); trialsPanel.add(scrollPane, BorderLayout.CENTER); trialsPanel.add(buttons, BorderLayout.SOUTH); cardPanel.add(helpInstructions, CARD_HELP); cardPanel.add(trialsPanel, CARD_TRIALS); cardLayout.show(cardPanel, CARD_HELP); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, searchOptionsPanel.getViewComponent(), cardPanel); return splitPane; }
From source file:com.diversityarrays.kdxplore.trials.AddScoringSetDialog.java
private Box createWantSampleButtons(SampleGroup curatedSampleGroup) { Box result = null;//from w w w . j a v a2 s . c om ActionListener rbListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { wantSampleValues = noSampleValuesButton != e.getSource(); } }; result = Box.createHorizontalBox(); String noSampleValues = Msg.OPTION_NO_SAMPLE_VALUES(); ButtonGroup bg = new ButtonGroup(); for (String rbname : new String[] { noSampleValues, Msg.OPTION_CURATED_SAMPLE_VALUES() }) { JRadioButton rb = new JRadioButton(rbname); result.add(rb); bg.add(rb); rb.addActionListener(rbListener); if (noSampleValues.equals(rbname)) { noSampleValuesButton = rb; } else { rb.doClick(); } } result.add(Box.createHorizontalGlue()); return result; }
From source file:metdemo.Finance.SHNetworks.java
/** * //from ww w. j a v a 2 s . c o m * @param jp * @param usersarray * @param viphm_hashmap */ protected void addBottomControls(final JPanel jp, String[] usersarray) { // create the control panel which will hold settings and picked list final JPanel control_panel = new JPanel(); jp.add(control_panel, BorderLayout.SOUTH); control_panel.setLayout(new BorderLayout()); // create the settings panel which will hold all of the settings Box settings_box = Box.createVerticalBox(); settings_box.setBorder(BorderFactory.createTitledBorder("Display Settings")); control_panel.add(settings_box, BorderLayout.NORTH); JPanel settings_panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10)); // add the zoom controls to the settings panel JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // call listener in GraphMouse instead of manipulating vv scale // directly // this is so the crossover from zoom to scale works with the // buttons // as well as with the mouse wheel Dimension d = m_visualizationview.getSize(); m_graphmouse.mouseWheelMoved( new MouseWheelEvent(m_visualizationview, MouseEvent.MOUSE_WHEEL, System.currentTimeMillis(), 0, d.width / 2, d.height / 2, 1, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, 1)); } }); JButton minus = new JButton(" - "); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // call listener in GraphMouse instead of manipulating vv scale // directly // this is so the crossover from zoom to scale works with the // buttons // as well as with the mouse wheel Dimension d = m_visualizationview.getSize(); m_graphmouse.mouseWheelMoved( new MouseWheelEvent(m_visualizationview, MouseEvent.MOUSE_WHEEL, System.currentTimeMillis(), 0, d.width / 2, d.height / 2, 1, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, -1)); } }); Box zoomPanel = Box.createHorizontalBox(); zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom")); minus.setAlignmentX(Component.LEFT_ALIGNMENT); plus.setAlignmentX(Component.RIGHT_ALIGNMENT); zoomPanel.add(minus); zoomPanel.add(plus); settings_panel.add(zoomPanel); // add the mouse mode combo box to the settings panel JComboBox modeBox = m_graphmouse.getModeComboBox(); modeBox.setAlignmentX(Component.CENTER_ALIGNMENT); m_graphmouse.setMode(ModalGraphMouse.Mode.PICKING); JPanel modePanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return getPreferredSize(); } }; modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modePanel.add(modeBox); settings_panel.add(modePanel); // add the display type combo box to the settings panel String[] layoutTypeStrings = { "OrgChart Layout", "FR Layout" }; layoutTypeBox = new JComboBox(layoutTypeStrings); layoutTypeBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (layoutTypeBox.getSelectedIndex() == 0) moveVertices();//viphm_hashmap); else m_visualizationview.restart(); } }); layoutTypeBox.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel displayTypePanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return getPreferredSize(); } }; displayTypePanel.setBorder(BorderFactory.createTitledBorder("Display Type")); displayTypePanel.add(layoutTypeBox); settings_panel.add(displayTypePanel); // add user search to the panel - SHLOMO JPanel searchPanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return getPreferredSize(); } }; // take the users and organize it sorted /* * ArrayList<String> ta = new ArrayList<String>(userlist); String [] * usersarray = (String[]) ta.toArray(new String[ta.size()]); */Arrays.sort(usersarray); usercombolist = new JComboBox(usersarray); usercombolist.insertItemAt("Anyone", 0); usercombolist.setSelectedIndex(0);// show only anyone choice // lets add all current users to the list searchPanel.setBorder(BorderFactory.createTitledBorder("Search User")); searchPanel.add(usercombolist); //add a check box to show not show labels on all vertices m_showLabels = new JCheckBox("Show name?", false); settings_panel.add(m_showLabels); settings_panel.add(searchPanel); usercombolist.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // will need to react to the choice list if (usercombolist.getSelectedIndex() == 0) { // might have to reset something in case they move back PickedState picked_state = m_visualizationview.getPickedState(); picked_state.clearPickedVertices(); return; } String username = (String) usercombolist.getSelectedItem(); for (Iterator walker = m_layout.getVertexIterator(); walker.hasNext();) { VIPVertex V = (VIPVertex) walker.next(); // Integer indexNum = (Integer)index.getNumber(V); String seeName = V.getAcct();// accounts_arraylist.get(indexNum); if (username.equals(seeName)) { PickedState picked_state = m_visualizationview.getPickedState(); picked_state.clearPickedVertices(); picked_state.pick(V, true); /* * int x= (int)m_layout.getX(V); int y= * (int)m_layout.getY(V); //lets trigger the event * m_graphmouse.mousePressed(new * MouseEvent(m_visualizationview,MouseEvent.MOUSE_CLICKED,System.currentTimeMillis(),0,x,y,2,false)); */return; } } } }); // add the settings panel to the settings box settings_box.add(settings_panel); // add the vip table to the control panel SortTableModel model = new SortTableModel(); model.addColumn("Account"); model.addColumn("ResponseScore"); model.addColumn("SocialScore"); m_timeTable = new JTable(model); model.addMouseListenerToHeaderInTable(m_timeTable); m_timeTable.setRowSelectionAllowed(true); m_timeTable.setColumnSelectionAllowed(false); m_timeTable.getTableHeader().setReorderingAllowed(false); m_timeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); m_timeTable.setDefaultRenderer(model.getColumnClass(1), md5Renderer); tablePane = new JScrollPane(m_timeTable); tablePane.setPreferredSize(new Dimension(300, 150)); control_panel.add(tablePane, BorderLayout.SOUTH); }
From source file:sim.util.media.chart.ChartGenerator.java
/** Generates a new ChartGenerator with a blank chart. Before anything else, buildChart() is called. */ public ChartGenerator() { // create the chart buildChart();// ww w . jav a 2s. co m chart.getPlot().setBackgroundPaint(Color.WHITE); chart.setAntiAlias(true); JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); split.setBorder(new EmptyBorder(0, 0, 0, 0)); JScrollPane scroll = new JScrollPane(); JPanel b = new JPanel(); b.setLayout(new BorderLayout()); b.add(seriesAttributes, BorderLayout.NORTH); b.add(new JPanel(), BorderLayout.CENTER); scroll.getViewport().setView(b); scroll.setBackground(getBackground()); scroll.getViewport().setBackground(getBackground()); JPanel p = new JPanel(); p.setLayout(new BorderLayout()); LabelledList list = new LabelledList("Chart Properties"); DisclosurePanel pan1 = new DisclosurePanel("Chart Properties", list); globalAttributes.add(pan1); JLabel j = new JLabel("Right-Click or Control-Click"); j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC)); list.add(j); j = new JLabel("on Chart for More Options"); j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC)); list.add(j); titleField = new PropertyField() { public String newValue(String newValue) { setTitle(newValue); getChartPanel().repaint(); return newValue; } }; titleField.setValue(chart.getTitle().getText()); list.add(new JLabel("Title"), titleField); buildGlobalAttributes(list); final JCheckBox legendCheck = new JCheckBox(); ItemListener il = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LegendTitle title = new LegendTitle(chart.getPlot()); title.setLegendItemGraphicPadding(new org.jfree.ui.RectangleInsets(0, 8, 0, 4)); chart.addLegend(title); } else { chart.removeLegend(); } } }; legendCheck.addItemListener(il); list.add(new JLabel("Legend"), legendCheck); legendCheck.setSelected(true); /* final JCheckBox aliasCheck = new JCheckBox(); aliasCheck.setSelected(chart.getAntiAlias()); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { chart.setAntiAlias( e.getStateChange() == ItemEvent.SELECTED ); } }; aliasCheck.addItemListener(il); list.add(new JLabel("Antialias"), aliasCheck); */ JPanel pdfButtonPanel = new JPanel(); pdfButtonPanel.setBorder(new javax.swing.border.TitledBorder("Chart Output")); DisclosurePanel pan2 = new DisclosurePanel("Chart Output", pdfButtonPanel); pdfButtonPanel.setLayout(new BorderLayout()); Box pdfbox = new Box(BoxLayout.Y_AXIS); pdfButtonPanel.add(pdfbox, BorderLayout.WEST); JButton pdfButton = new JButton("Save as PDF"); pdfbox.add(pdfButton); pdfButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog(frame, "Choose PDF file...", FileDialog.SAVE); fd.setFile(chart.getTitle().getText() + ".pdf"); fd.setVisible(true); String fileName = fd.getFile(); if (fileName != null) { Dimension dim = chartPanel.getPreferredSize(); PDFEncoder.generatePDF(chart, dim.width, dim.height, new File(fd.getDirectory(), Utilities.ensureFileEndsWith(fd.getFile(), ".pdf"))); } } }); movieButton = new JButton("Create a Movie"); pdfbox.add(movieButton); pdfbox.add(Box.createGlue()); movieButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (movieMaker == null) startMovie(); else stopMovie(); } }); globalAttributes.add(pan2); // we add into an outer box so we can later on add more global seriesAttributes // as the user instructs and still have glue be last Box outerAttributes = Box.createVerticalBox(); outerAttributes.add(globalAttributes); outerAttributes.add(Box.createGlue()); p.add(outerAttributes, BorderLayout.NORTH); p.add(scroll, BorderLayout.CENTER); p.setMinimumSize(new Dimension(0, 0)); p.setPreferredSize(new Dimension(200, 0)); split.setLeftComponent(p); // Add scale and proportion fields Box header = Box.createHorizontalBox(); final double MAXIMUM_SCALE = 8; fixBox = new JCheckBox("Fill"); fixBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFixed(fixBox.isSelected()); } }); header.add(fixBox); fixBox.setSelected(true); // add the scale field scaleField = new NumberTextField(" Scale: ", 1.0, true) { public double newValue(double newValue) { if (newValue <= 0.0) newValue = currentValue; if (newValue > MAXIMUM_SCALE) newValue = currentValue; scale = newValue; resizeChart(); return newValue; } }; scaleField.setToolTipText("Zoom in and out"); scaleField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); scaleField.setEnabled(false); scaleField.setText(""); header.add(scaleField); // add the proportion field proportionField = new NumberTextField(" Proportion: ", 1.5, true) { public double newValue(double newValue) { if (newValue <= 0.0) newValue = currentValue; proportion = newValue; resizeChart(); return newValue; } }; proportionField.setToolTipText("Change the chart proportions (ratio of width to height)"); proportionField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); header.add(proportionField); chartHolder.setMinimumSize(new Dimension(0, 0)); chartHolder.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); chartHolder.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); chartHolder.getViewport().setBackground(Color.gray); JPanel p2 = new JPanel(); p2.setLayout(new BorderLayout()); p2.add(chartHolder, BorderLayout.CENTER); p2.add(header, BorderLayout.NORTH); split.setRightComponent(p2); setLayout(new BorderLayout()); add(split, BorderLayout.CENTER); // set the default to be white, which looks good when printed chart.setBackgroundPaint(Color.WHITE); // JFreeChart has a hillariously broken way of handling font scaling. // It allows fonts to scale independently in X and Y. We hack a workaround here. chartPanel.setMinimumDrawHeight((int) DEFAULT_CHART_HEIGHT); chartPanel.setMaximumDrawHeight((int) DEFAULT_CHART_HEIGHT); chartPanel.setMinimumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion)); chartPanel.setMaximumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion)); chartPanel.setPreferredSize(new java.awt.Dimension((int) (DEFAULT_CHART_HEIGHT * DEFAULT_CHART_PROPORTION), (int) (DEFAULT_CHART_HEIGHT))); }
From source file:edu.gmu.cs.sim.util.media.chart.ChartGenerator.java
/** Generates a new ChartGenerator with a blank chart. Before anything else, buildChart() is called. */ public ChartGenerator() { // create the chart buildChart();// www . j a v a2 s . c o m chart.getPlot().setBackgroundPaint(Color.WHITE); chart.setAntiAlias(true); JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); split.setBorder(new EmptyBorder(0, 0, 0, 0)); JScrollPane scroll = new JScrollPane(); JPanel b = new JPanel(); b.setLayout(new BorderLayout()); b.add(seriesAttributes, BorderLayout.NORTH); b.add(new JPanel(), BorderLayout.CENTER); scroll.getViewport().setView(b); scroll.setBackground(getBackground()); scroll.getViewport().setBackground(getBackground()); JPanel p = new JPanel(); p.setLayout(new BorderLayout()); LabelledList list = new LabelledList("Chart Properties"); DisclosurePanel pan1 = new DisclosurePanel("Chart Properties", list); globalAttributes.add(pan1); JLabel j = new JLabel("Right-Click or Control-Click"); j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC)); list.add(j); j = new JLabel("on Chart for More Options"); j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC)); list.add(j); titleField = new PropertyField() { public String newValue(String newValue) { setTitle(newValue); getChartPanel().repaint(); return newValue; } }; titleField.setValue(chart.getTitle().getText()); list.add(new JLabel("Title"), titleField); buildGlobalAttributes(list); final JCheckBox legendCheck = new JCheckBox(); ItemListener il = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LegendTitle title = new LegendTitle(chart.getPlot()); title.setLegendItemGraphicPadding(new org.jfree.ui.RectangleInsets(0, 8, 0, 4)); chart.addLegend(title); } else { chart.removeLegend(); } } }; legendCheck.addItemListener(il); list.add(new JLabel("Legend"), legendCheck); legendCheck.setSelected(true); /* final JCheckBox aliasCheck = new JCheckBox(); aliasCheck.setSelected(chart.getAntiAlias()); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { chart.setAntiAlias( e.getStateChange() == ItemEvent.SELECTED ); } }; aliasCheck.addItemListener(il); list.add(new JLabel("Antialias"), aliasCheck); */ JPanel pdfButtonPanel = new JPanel(); pdfButtonPanel.setBorder(new javax.swing.border.TitledBorder("Chart Output")); DisclosurePanel pan2 = new DisclosurePanel("Chart Output", pdfButtonPanel); pdfButtonPanel.setLayout(new BorderLayout()); Box pdfbox = new Box(BoxLayout.Y_AXIS); pdfButtonPanel.add(pdfbox, BorderLayout.WEST); JButton pdfButton = new JButton("Save as PDF"); pdfbox.add(pdfButton); pdfButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog(frame, "Choose PDF file...", FileDialog.SAVE); fd.setFile(chart.getTitle().getText() + ".pdf"); fd.setVisible(true); String fileName = fd.getFile(); if (fileName != null) { Dimension dim = chartPanel.getPreferredSize(); PDFEncoder.generatePDF(chart, dim.width, dim.height, new File(fd.getDirectory(), Utilities.ensureFileEndsWith(fd.getFile(), ".pdf"))); } } }); movieButton = new JButton("Create a Movie"); pdfbox.add(movieButton); pdfbox.add(Box.createGlue()); movieButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (movieMaker == null) { startMovie(); } else { stopMovie(); } } }); globalAttributes.add(pan2); // we add into an outer box so we can later on add more global seriesAttributes // as the user instructs and still have glue be last Box outerAttributes = Box.createVerticalBox(); outerAttributes.add(globalAttributes); outerAttributes.add(Box.createGlue()); p.add(outerAttributes, BorderLayout.NORTH); p.add(scroll, BorderLayout.CENTER); p.setMinimumSize(new Dimension(0, 0)); p.setPreferredSize(new Dimension(200, 0)); split.setLeftComponent(p); // Add scale and proportion fields Box header = Box.createHorizontalBox(); final double MAXIMUM_SCALE = 8; fixBox = new JCheckBox("Fill"); fixBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFixed(fixBox.isSelected()); } }); header.add(fixBox); fixBox.setSelected(true); // add the scale field scaleField = new NumberTextField(" Scale: ", 1.0, true) { public double newValue(double newValue) { if (newValue <= 0.0) { newValue = currentValue; } if (newValue > MAXIMUM_SCALE) { newValue = currentValue; } scale = newValue; resizeChart(); return newValue; } }; scaleField.setToolTipText("Zoom in and out"); scaleField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); scaleField.setEnabled(false); scaleField.setText(""); header.add(scaleField); // add the proportion field proportionField = new NumberTextField(" Proportion: ", 1.5, true) { public double newValue(double newValue) { if (newValue <= 0.0) { newValue = currentValue; } proportion = newValue; resizeChart(); return newValue; } }; proportionField.setToolTipText("Change the chart proportions (ratio of width to height)"); proportionField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); header.add(proportionField); chartHolder.setMinimumSize(new Dimension(0, 0)); chartHolder.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); chartHolder.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); chartHolder.getViewport().setBackground(Color.gray); JPanel p2 = new JPanel(); p2.setLayout(new BorderLayout()); p2.add(chartHolder, BorderLayout.CENTER); p2.add(header, BorderLayout.NORTH); split.setRightComponent(p2); setLayout(new BorderLayout()); add(split, BorderLayout.CENTER); // set the default to be white, which looks good when printed chart.setBackgroundPaint(Color.WHITE); // JFreeChart has a hillariously broken way of handling font scaling. // It allows fonts to scale independently in X and Y. We hack a workaround here. chartPanel.setMinimumDrawHeight((int) DEFAULT_CHART_HEIGHT); chartPanel.setMaximumDrawHeight((int) DEFAULT_CHART_HEIGHT); chartPanel.setMinimumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion)); chartPanel.setMaximumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion)); chartPanel.setPreferredSize(new java.awt.Dimension((int) (DEFAULT_CHART_HEIGHT * DEFAULT_CHART_PROPORTION), (int) (DEFAULT_CHART_HEIGHT))); }