List of usage examples for javax.swing JScrollPane getViewport
public JViewport getViewport()
JViewport
. From source file:de.uka.aifb.com.systemDynamics.gui.ModelExecutionChartPanel.java
/** * Creates panel.//from w w w . ja v a 2 s. c o m */ private void createPanel() { setLayout(new BorderLayout()); // CENTER: chart ChartPanel chartPanel = new ChartPanel(createChart()); // no context menu chartPanel.setPopupMenu(null); // not zoomable chartPanel.setMouseZoomable(false); add(chartPanel, BorderLayout.CENTER); // LINE_END: series table JPanel tablePanel = new JPanel(new GridBagLayout()); String[] columnNames = { messages.getString("ModelExecutionChartPanel.Table.ColumnNames.ExtraAxis"), messages.getString("ModelExecutionChartPanel.Table.ColumnNames.LevelNode") }; final MyTableModel tableModel = new MyTableModel(columnNames, xySeriesArray.length); for (int i = 0; i < xySeriesArray.length; i++) { tableModel.addEntry((String) xySeriesArray[i].getKey()); } JTable table = new JTable(tableModel); table.setRowSelectionAllowed(false); JScrollPane tableScrollPane = new JScrollPane(table); int width = (int) Math.min(300, table.getPreferredSize().getWidth()); int height = (int) Math.min(200, table.getPreferredSize().getHeight()); tableScrollPane.getViewport().setPreferredSize(new Dimension(width, height)); tableScrollPane.setMaximumSize(tableScrollPane.getViewport().getPreferredSize()); axesButton = new JButton(messages.getString("ModelExecutionChartPanel.AxesButton.Text")); axesButton.setToolTipText(messages.getString("ModelExecutionChartPanel.AxesButton.ToolTipText")); axesButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // create XYSeriesCollections (and renderer) XYSeriesCollection standardData = new XYSeriesCollection(); XYLineAndShapeRenderer standardRenderer = new XYLineAndShapeRenderer(true, false); LinkedList<XYSeriesCollection> extraDataList = new LinkedList<XYSeriesCollection>(); LinkedList<XYLineAndShapeRenderer> extraRendererList = new LinkedList<XYLineAndShapeRenderer>(); for (int i = 0; i < tableModel.getRowCount(); i++) { if (tableModel.getValueAt(i, 0).equals(Boolean.FALSE)) { standardData.addSeries(xySeriesArray[i]); standardRenderer.setSeriesPaint(standardData.getSeriesCount() - 1, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]); } else { // extra axis XYSeriesCollection extraData = new XYSeriesCollection(); extraData.addSeries(xySeriesArray[i]); extraDataList.add(extraData); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); extraRendererList.add(renderer); renderer.setSeriesPaint(0, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]); } } LinkedList<XYSeriesCollection> dataList = new LinkedList<XYSeriesCollection>(); LinkedList<XYLineAndShapeRenderer> rendererList = new LinkedList<XYLineAndShapeRenderer>(); if (!standardData.getSeries().isEmpty()) { dataList.add(standardData); rendererList.add(standardRenderer); } for (XYSeriesCollection data : extraDataList) { dataList.add(data); } for (XYLineAndShapeRenderer renderer : extraRendererList) { rendererList.add(renderer); } // creates axes LinkedList<NumberAxis> axesList = new LinkedList<NumberAxis>(); if (!standardData.getSeries().isEmpty()) { NumberAxis axis = new NumberAxis(messages.getString("ModelExecutionChartPanel.Value")); axis.setNumberFormatOverride(NumberFormat.getInstance(locale)); axesList.add(axis); } for (XYSeriesCollection data : extraDataList) { NumberAxis axis = new NumberAxis((String) data.getSeries(0).getKey()); axis.setNumberFormatOverride(NumberFormat.getInstance(locale)); axesList.add(axis); } // store data and axes in plot XYPlot plot = chart.getXYPlot(); plot.clearRangeAxes(); plot.setRangeAxes(axesList.toArray(new NumberAxis[0])); for (int i = 0; i < plot.getDatasetCount(); i++) { plot.setDataset(i, null); } int datasetIndex = 0; Iterator<XYSeriesCollection> datasetIterator = dataList.iterator(); Iterator<XYLineAndShapeRenderer> rendererIterator = rendererList.iterator(); while (datasetIterator.hasNext()) { plot.setDataset(datasetIndex, datasetIterator.next()); plot.setRenderer(datasetIndex, rendererIterator.next()); datasetIndex++; } for (int i = 0; i < plot.getDatasetCount(); i++) { plot.mapDatasetToRangeAxis(i, i); } } }); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.gridx = 0; c.gridy = 0; c.insets = new Insets(0, 0, 10, 0); tablePanel.add(tableScrollPane, c); c.gridx = 0; c.gridy = 1; tablePanel.add(axesButton, c); add(tablePanel, BorderLayout.LINE_END); // PAGE_END: number of rounds and execution button JPanel commandPanel = new JPanel(); commandPanel.add(new JLabel(messages.getString("ModelExecutionChartPanel.NumberRounds"))); final JTextField numberRoundsField = new JTextField("1", 5); numberRoundsField.addFocusListener(this); commandPanel.add(numberRoundsField); executionButton = new JButton(messages.getString("ModelExecutionChartPanel.ExecutionButton.Text")); executionButton.setToolTipText(messages.getString("ModelExecutionChartPanel.ExecutionButton.ToolTipText")); executionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int numberRounds = 0; boolean correctNumber = false; try { numberRounds = integerNumberFormatter.parse(numberRoundsField.getText()).intValue(); } catch (ParseException parseExcep) { // do nothing } if (numberRounds >= 1) { correctNumber = true; } if (correctNumber) { ModelExecutionThread executionThread = new ModelExecutionThread(numberRounds); executionThread.start(); } else { JOptionPane.showMessageDialog(null, messages.getString("ModelExecutionChartPanel.Error.Message"), messages.getString("ModelExecutionChartPanel.Error.Title"), JOptionPane.ERROR_MESSAGE); } } }); commandPanel.add(executionButton); add(commandPanel, BorderLayout.PAGE_END); }
From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheet.java
protected void configureEnclosingScrollPane() { super.configureEnclosingScrollPane(); Container p = getParent();//from www .j av a 2 s. c om if (p instanceof JViewport) { Container gp = p.getParent(); if (gp instanceof JScrollPane) { JScrollPane scrollPane = (JScrollPane) gp; JViewport viewport = scrollPane.getViewport(); if (viewport == null || viewport.getView() != this) return; configureScrollPaneHeaders(scrollPane); Border border = scrollPane.getBorder(); if (border == null || border instanceof UIResource) { scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder")); } } } }
From source file:gdt.jgui.tool.JEntityEditor.java
private void addRow() { try {/*w w w. ja v a 2 s . c om*/ JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent(); JTable table = (JTable) scrollPane.getViewport().getView(); DefaultTableModel model = (DefaultTableModel) table.getModel(); model.addRow(new String[] { null, "Name" + String.valueOf(model.getRowCount()), "Value" }); } catch (Exception e) { LOGGER.severe(e.toString()); } }
From source file:gdt.jgui.tool.JEntityEditor.java
private boolean hasEditingCell() { try {/*from w w w.ja va2 s . co m*/ JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent(); JTable table = (JTable) scrollPane.getViewport().getView(); // System.out.println("Entityeditor:hasEditingCell:x="+table.getEditingRow()+" y="+table.getEditingColumn()); if (table.getEditingColumn() > -1 && table.getEditingRow() > -1) return true; } catch (Exception e) { LOGGER.severe(e.toString()); } return false; }
From source file:gdt.jgui.tool.JEntityEditor.java
private boolean hasSelectedRows() { try {//ww w.j a v a 2 s . c o m JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent(); JTable table = (JTable) scrollPane.getViewport().getView(); int[] i = table.getSelectedRows(); if (i.length > 0) return true; return false; } catch (Exception e) { LOGGER.severe(e.toString()); return false; } }
From source file:gdt.jgui.tool.JEntityEditor.java
private void pasteTable(Core[] ca) { try {// w w w .java 2s . c om JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent(); JTable table = (JTable) scrollPane.getViewport().getView(); DefaultTableModel model = (DefaultTableModel) table.getModel(); int cnt = ca.length; if (cnt < 1) return; for (int i = 0; i < cnt; i++) model.addRow(new String[] { ca[i].type, ca[i].name, ca[i].value }); } catch (Exception e) { LOGGER.severe(e.toString()); } }
From source file:gdt.jgui.tool.JEntityEditor.java
private void replaceTable(Core[] ca) { try {/* ww w .j a v a 2 s. c o m*/ JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent(); JTable table = (JTable) scrollPane.getViewport().getView(); DefaultTableModel model = (DefaultTableModel) table.getModel(); while (model.getRowCount() > 0) model.removeRow(0); int cnt = ca.length; if (cnt < 1) return; for (int i = 0; i < cnt; i++) model.addRow(new String[] { ca[i].type, ca[i].name, ca[i].value }); } catch (Exception e) { LOGGER.severe(e.toString()); } }
From source file:gdt.jgui.tool.JEntityEditor.java
private Core[] getContent(boolean selected) { try {/* w w w . ja v a 2 s.com*/ JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent(); JTable table = (JTable) scrollPane.getViewport().getView(); DefaultTableModel model = (DefaultTableModel) table.getModel(); ListSelectionModel listModel = table.getSelectionModel(); int cnt = model.getRowCount(); if (cnt < 1) return null; ArrayList<Core> cl = new ArrayList<Core>(); for (int i = 0; i < cnt; i++) { if (selected) if (!listModel.isSelectedIndex(i)) continue; cl.add(new Core((String) model.getValueAt(i, 0), (String) model.getValueAt(i, 1), (String) model.getValueAt(i, 2))); } return cl.toArray(new Core[0]); } catch (Exception e) { LOGGER.severe(e.toString()); } return null; }
From source file:gdt.jgui.tool.JEntityEditor.java
private String getEditCellLocator() { try {//w w w. j a v a 2s . com save(); JTextEditor textEditor = new JTextEditor(); String locator$ = textEditor.getLocator(); locator$ = Locator.merge(getLocator(), locator$); JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent(); JTable table = (JTable) scrollPane.getViewport().getView(); int i = tabbedPane.getSelectedIndex(); String element$ = tabbedPane.getTitleAt(i); int x = table.getEditingRow(); int y = table.getEditingColumn(); String cellField$ = CELL_FIELD_TYPE; if (y == 1) cellField$ = CELL_FIELD_NAME; else if (y == 2) cellField$ = CELL_FIELD_VALUE; TableModel model = table.getModel(); String text$ = (String) model.getValueAt(x, y); text$ = Locator.compressText(text$); locator$ = Locator.append(locator$, JTextEditor.IS_BASE64, Locator.LOCATOR_TRUE); String coreName$ = (String) model.getValueAt(x, 1); locator$ = Locator.append(locator$, JTextEditor.TEXT, text$); locator$ = Locator.append(locator$, ELEMENT, element$); locator$ = Locator.append(locator$, CELL_FIELD, cellField$); locator$ = Locator.append(locator$, CORE_NAME, coreName$); locator$ = Locator.append(locator$, JRequester.REQUESTER_ACTION, ACTION_EDIT_CELL); locator$ = Locator.append(locator$, Locator.LOCATOR_TITLE, "Edit item"); locator$ = Locator.append(locator$, BaseHandler.HANDLER_CLASS, JTextEditor.class.getName()); return locator$; } catch (Exception e) { LOGGER.severe(e.toString()); return null; } }
From source file:gdt.jgui.tool.JEntityEditor.java
private void deleteRows() { try {/* w w w .j av a 2 s. c o m*/ JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent(); JTable table = (JTable) scrollPane.getViewport().getView(); DefaultTableModel tableModel = (DefaultTableModel) table.getModel(); ListSelectionModel listModel = table.getSelectionModel(); int rCnt = table.getRowCount(); ArrayList<Integer> srl = new ArrayList<Integer>(); for (int i = 0; i < rCnt; i++) if (listModel.isSelectedIndex(i)) { srl.add(new Integer(i)); } Integer[] sra = srl.toArray(new Integer[0]); ArrayList<Core> ol = new ArrayList<Core>(); Core row; boolean skip; for (int i = 0; i < rCnt; i++) { skip = false; for (int aSra : sra) { if (i == aSra) { skip = true; break; } } if (!skip) { row = new Core((String) tableModel.getValueAt(i, 0), (String) tableModel.getValueAt(i, 1), (String) tableModel.getValueAt(i, 2)); ol.add(row); } } Core[] ra = ol.toArray(new Core[0]); while (tableModel.getRowCount() > 0) tableModel.removeRow(0); for (Core aRa : ra) { tableModel.addRow(new String[] { aRa.type, aRa.name, aRa.value }); } } catch (Exception e) { LOGGER.severe(e.toString()); } }