List of usage examples for javax.swing JScrollPane getViewport
public JViewport getViewport()
JViewport
. From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDoseResponseController.java
/** * Initialize main view//from w ww .j av a2s . c o m */ @Override protected void initMainView() { genericDRParentPanel = new GenericDRParentPanel(); dRPanel = new DRPanel(); //buttons disabled at start genericDRParentPanel.getCancelButton().setEnabled(false); genericDRParentPanel.getNextButton().setEnabled(false); getCardLayout().first(genericDRParentPanel.getContentPanel()); onCardSwitch(); //create a ButtonGroup for the radioButtons used for analysis ButtonGroup mainDRRadioButtonGroup = new ButtonGroup(); //adding buttons to a ButtonGroup automatically deselect one when another one gets selected mainDRRadioButtonGroup.add(dRPanel.getInputDRButton()); mainDRRadioButtonGroup.add(dRPanel.getInitialPlotDRButton()); mainDRRadioButtonGroup.add(dRPanel.getNormalizedPlotDRButton()); mainDRRadioButtonGroup.add(dRPanel.getResultsDRButton()); //select as default first button dRPanel.getInputDRButton().setSelected(true); //init dataTable dataTable = new JTable(); JScrollPane scrollPane = new JScrollPane(dataTable); //the table will take all the viewport height available dataTable.setFillsViewportHeight(true); scrollPane.getViewport().setBackground(Color.white); dataTable.getTableHeader().setReorderingAllowed(false); //row and column selection must be false //dataTable.setColumnSelectionAllowed(false); //dataTable.setRowSelectionAllowed(false); dRPanel.getDatatableDRPanel().add(scrollPane, BorderLayout.CENTER); setLogTransform(true); /** * Action listeners for uppermost panel. */ //this button is ONLY used when going from the loading to the analysis genericDRParentPanel.getNextButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { genericDRParentPanel.getNextButton().setEnabled(false); genericDRParentPanel.getCancelButton().setEnabled(true); //save any metadata that was provided manually loadGenericDRDataController.setManualMetaData(importedDRDataHolder); //switch between child panels getCardLayout().next(genericDRParentPanel.getContentPanel()); onCardSwitch(); } }); genericDRParentPanel.getCancelButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // warn the user and reset everything Object[] options = { "Yes", "No" }; int showOptionDialog = JOptionPane.showOptionDialog(null, "Current analysis won't be saved. Continue?", "", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]); if (showOptionDialog == 0) { // reset everything resetOnCancel(); } } }); /** * Action listeners for shared panel. When button is selected, switch * view to corresponding subview */ dRPanel.getInputDRButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //switch shared table view updateModelInTable(dRInputController.getTableModel()); updateTableInfoMessage("This table contains all conditions and their respective responses"); /** * for (int columnIndex = 0; columnIndex < * dataTable.getColumnCount(); columnIndex++) { * GuiUtils.packColumn(dataTable, columnIndex); } */ dataTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); //remove other panels dRInitialController.getInitialChartPanel().setChart(null); dRNormalizedController.getNormalizedChartPanel().setChart(null); dRResultsController.getDupeInitialChartPanel().setChart(null); dRResultsController.getDupeNormalizedChartPanel().setChart(null); dRPanel.getGraphicsDRParentPanel().removeAll(); dRPanel.getGraphicsDRParentPanel().revalidate(); dRPanel.getGraphicsDRParentPanel().repaint(); //add panel to view dRPanel.getGraphicsDRParentPanel().add(dRInputController.getdRInputPanel(), gridBagConstraints); } }); dRPanel.getInitialPlotDRButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dRAnalysisGroup != null) { if (isFirstFitting()) { initFirstFitting(); setFirstFitting(false); } //switch shared table view updateModelInTable(dRInitialController.getTableModel()); updateTableInfoMessage( "If you checked the box at the import screen, the doses have been log-transformed. Responses have not been changed"); /** * for (int columnIndex = 0; columnIndex < * dataTable.getColumnCount(); columnIndex++) { * GuiUtils.packColumn(dataTable, columnIndex); } */ dataTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); //remove other panels dRNormalizedController.getNormalizedChartPanel().setChart(null); dRResultsController.getDupeInitialChartPanel().setChart(null); dRResultsController.getDupeNormalizedChartPanel().setChart(null); dRPanel.getGraphicsDRParentPanel().removeAll(); dRPanel.getGraphicsDRParentPanel().revalidate(); dRPanel.getGraphicsDRParentPanel().repaint(); dRPanel.getGraphicsDRParentPanel().add(dRInitialController.getDRInitialPlotPanel(), gridBagConstraints); //Plot fitted data in dose-response curve, along with R annotation plotDoseResponse(dRInitialController.getInitialChartPanel(), dRInitialController.getDRInitialPlotPanel().getDoseResponseChartParentPanel(), getDataToFit(false), getdRAnalysisGroup(), false); } } }); dRPanel.getNormalizedPlotDRButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dRAnalysisGroup != null) { //in case user skips "initial" subview and goes straight to normalization if (isFirstFitting()) { initFirstFitting(); setFirstFitting(false); } //switch shared table view updateModelInTable(dRNormalizedController.getTableModel()); updateTableInfoMessage( "Potentially log-transformed doses with their normalized responses per replicate"); /** * for (int columnIndex = 0; columnIndex < * dataTable.getColumnCount(); columnIndex++) { * GuiUtils.packColumn(dataTable, columnIndex); } */ dataTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); //remove other panels dRInitialController.getInitialChartPanel().setChart(null); dRResultsController.getDupeInitialChartPanel().setChart(null); dRResultsController.getDupeNormalizedChartPanel().setChart(null); dRPanel.getGraphicsDRParentPanel().removeAll(); dRPanel.getGraphicsDRParentPanel().revalidate(); dRPanel.getGraphicsDRParentPanel().repaint(); dRPanel.getGraphicsDRParentPanel().add(dRNormalizedController.getDRNormalizedPlotPanel(), gridBagConstraints); //Plot fitted data in dose-response curve, along with R annotation plotDoseResponse(dRNormalizedController.getNormalizedChartPanel(), dRNormalizedController.getDRNormalizedPlotPanel().getDoseResponseChartParentPanel(), getDataToFit(true), getdRAnalysisGroup(), true); } } }); dRPanel.getResultsDRButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dRAnalysisGroup != null) { //switch shared table view: create and set new table model with most recent statistical values // (these values get recalculated after each new fitting) dRResultsController.setTableModel(dRResultsController.reCreateTableModel(dRAnalysisGroup)); updateModelInTable(dRResultsController.getTableModel()); updateTableInfoMessage( "Statistical values from the curve fit of the initial and normalized data."); //remove other panels dRInitialController.getInitialChartPanel().setChart(null); dRNormalizedController.getNormalizedChartPanel().setChart(null); dRPanel.getGraphicsDRParentPanel().removeAll(); dRPanel.getGraphicsDRParentPanel().revalidate(); dRPanel.getGraphicsDRParentPanel().repaint(); dRPanel.getGraphicsDRParentPanel().add(dRResultsController.getdRResultsPanel(), gridBagConstraints); //plot curves dRResultsController.plotCharts(); } } }); //add views to parent panels cellMissyController.getCellMissyFrame().getDoseResponseAnalysisParentPanel().add(genericDRParentPanel, gridBagConstraints); genericDRParentPanel.getDataLoadingPanel().add(loadGenericDRDataController.getDataLoadingPanel(), gridBagConstraints); genericDRParentPanel.getDoseResponseParentPanel().add(dRPanel, gridBagConstraints); }
From source file:edu.ku.brc.stats.StatGroupTable.java
/** * Constructor with the localized name of the Group * @param name name of the group (already been localized) * @param useSeparator use non-border separator titles *//*from w w w . j a v a 2 s . co m*/ public StatGroupTable(final String name, final String[] columnNames, final boolean useSeparator, final int numRows) { this.name = name; this.useSeparator = useSeparator; this.skinItem = SkinsMgr.getSkinItem("StatGroup"); if (progressIcon == null) { progressIcon = IconManager.getIcon("Progress", IconManager.IconSize.Std16); } setLayout(new BorderLayout()); setBackground(Color.WHITE); model = new StatGroupTableModel(this, columnNames); //table = numRows > SCROLLPANE_THRESOLD ? (new SortableJTable(new SortableTableModel(model))) : (new JTable(model)); if (numRows > SCROLLPANE_THRESOLD) { table = new SortableJTable(new SortableTableModel(model)) { protected void configureEnclosingScrollPane() { Container p = getParent(); if (p instanceof JViewport) { Container gp = p.getParent(); if (gp instanceof JScrollPane) { JScrollPane scrollPane = (JScrollPane) gp; // Make certain we are the viewPort's view and not, for // example, the rowHeaderView of the scrollPane - // an implementor of fixed columns might do this. JViewport viewport = scrollPane.getViewport(); if (viewport == null || viewport.getView() != this) { return; } // scrollPane.setColumnHeaderView(getTableHeader()); //scrollPane.getViewport().setBackingStoreEnabled(true); scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder")); } } } }; } else { table = new JTable(model) { protected void configureEnclosingScrollPane() { Container p = getParent(); if (p instanceof JViewport) { Container gp = p.getParent(); if (gp instanceof JScrollPane) { JScrollPane scrollPane = (JScrollPane) gp; // Make certain we are the viewPort's view and not, for // example, the rowHeaderView of the scrollPane - // an implementor of fixed columns might do this. JViewport viewport = scrollPane.getViewport(); if (viewport == null || viewport.getView() != this) { return; } // scrollPane.setColumnHeaderView(getTableHeader()); //scrollPane.getViewport().setBackingStoreEnabled(true); scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder")); } } } }; } table.setShowVerticalLines(false); table.setShowHorizontalLines(false); if (SkinsMgr.shouldBeOpaque(skinItem)) { table.setOpaque(false); setOpaque(false); } else { table.setOpaque(true); setOpaque(true); } table.addMouseMotionListener(new TableMouseMotion()); table.addMouseListener(new LinkListener()); if (table.getColumnModel().getColumnCount() == 1) { table.getColumnModel().getColumn(0) .setCellRenderer(new StatGroupTableCellRenderer(SwingConstants.CENTER, 1)); } else { table.getColumnModel().getColumn(0) .setCellRenderer(new StatGroupTableCellRenderer(SwingConstants.LEFT, 2)); table.getColumnModel().getColumn(1) .setCellRenderer(new StatGroupTableCellRenderer(SwingConstants.RIGHT, 2)); } //table.setRowSelectionAllowed(true); if (numRows > SCROLLPANE_THRESOLD) { scrollPane = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); if (table instanceof SortableJTable) { ((SortableJTable) table).installColumnHeaderListeners(); } scrollPane.setOpaque(false); scrollPane.getViewport().setOpaque(false); scrollPane.setBorder(BorderFactory.createEmptyBorder()); //scrollPane.getViewport().setBorder(BorderFactory.createEmptyBorder()); } if (useSeparator) { setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); CellConstraints cc = new CellConstraints(); if (StringUtils.isNotEmpty(name)) { builder.addSeparator(name, cc.xy(1, 1)); } builder.add(scrollPane != null ? scrollPane : table, cc.xy(1, 2)); builder.getPanel().setOpaque(false); add(builder.getPanel()); } else { setBorder(BorderFactory.createEmptyBorder(15, 2, 2, 2)); setBorder(BorderFactory.createCompoundBorder(new CurvedBorder(new Color(160, 160, 160)), getBorder())); add(scrollPane != null ? scrollPane : table, BorderLayout.CENTER); } }
From source file:sk.uniza.fri.pds.spotreba.energie.gui.MainGui.java
private void showJTable(Class clazz, List data) throws HeadlessException { JScrollPane jScrollPane = new JScrollPane(); Dimension dimension = new Dimension(1200, 400); jScrollPane.setSize(dimension);//from w w w . j a v a2 s. co m jScrollPane.setPreferredSize(dimension); final BeanTableModel beanTableModel = new BeanTableModel(clazz, data); beanTableModel.sortColumnNames(); JTable jTable = new JTable(beanTableModel); jScrollPane.getViewport().add(jTable); JOptionPane.showMessageDialog(null, jScrollPane); }
From source file:edu.ucla.stat.SOCR.applications.demo.BinomialTradingApplication.java
void updateGraph() { //This method will later update/redraw/repaint the (Node, Edge)-Graph // For now, we just print out the results in JTextArea // Price of the Stock Price[k][l] is the price of the stock at level k (0<=k<=n) // and outcome l (0<=l<n+1) GraphModel model = new DefaultGraphModel(); jgraph = new JGraph(model); cells = new DefaultGraphCell[((n + 1) * (n + 2) / 2) * 3]; cellCount = 0;//from ww w .jav a2 s.c o m int XSpace = 130; int YSpace = 30; int YMiddle = 20 + n * YSpace; //150 for (int k = 0; k <= n; k++) { //System.out.println("============Start-of-level("+k+")=================="); for (int l = 0; l <= k; l++) { // Print to GraphPanel's JTextArea int j = -k + l * 2; if (choice.charAt(9) == 'P') { //For put option if (k == n) { // For the last column, k=n, (in the money), // we need to color GREEN or BLUE the node-background // to indicate if the Call Price (C) is > 0 (green) or // <= 0 (blue) if (j < 0) { if (Diff[k][l] > 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace - 20), Color.green); else addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace - 20), Color.blue); } else if (j > 0) { if (Diff[k][l] > 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace + 20), Color.green); else addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace + 20), Color.blue); } else { if (Diff[k][l] > 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle, Color.green); else addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle, Color.blue); } } else { // For all columns before the last (in the money) column, k<n)! if (j < 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace - 20)); else if (j > 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace + 20)); else addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle); } } else { //For call option if (k == n) { // For the last column, k=n, (in the money), // we need to color GREEN or BLUE the node-background // to indicate if the Call Price (C) is > 0 (green) or // <= 0 (blue) if (j < 0) { if (Diff[k][l] > 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace - 20), Color.green); else addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace - 20), Color.blue); } else if (j > 0) { if (Diff[k][l] > 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace + 20), Color.green); else addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace + 20), Color.blue); } else { if (Diff[k][l] > 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle, Color.green); else addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle, Color.blue); } } else if (choice.charAt(0) == 'A' && Diff[k][l] == Math.abs(Price[k][l] - EP)) { // For all columns before the last (in the money) column, k<n)! and possibly exercised early if (j < 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace - 20), Color.magenta); else if (j > 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace + 20), Color.magenta); else addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle, Color.magenta); } else { // For all columns before the last (in the money) column, k<n)! if (j < 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace - 20)); else if (j > 0) addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), (YMiddle + j * YSpace + 20)); else addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle); // Also Print to STD_OUT // System.out.println("j="+j); // System.out.println("Price["+k+"]["+l+"]="+Price[k][l]); // System.out.println("Diff["+k+"]["+l+"]="+Diff[k][l]); } } } //System.out.println("============End-of-level("+k+")==================\n"); } //System.out.println("cellCount="+cellCount); for (int k = 0; k < n; k++) { //System.out.println("============Start-of-level("+k+")=================="); for (int l = 0; l <= k; l++) { // System.out.println((k*(k+1)/2+l)+"->"+((k+1)*(k+2)/2+l) ); addEdge((k * (k + 1) / 2 + l), ((k + 1) * (k + 2) / 2 + l)); //System.out.println((k*(k+1)/2+l)+"->"+((k+1)*(k+2)/2+l+1) ); addEdge((k * (k + 1) / 2 + l), ((k + 1) * (k + 2) / 2 + l + 1)); } // System.out.println("============End-of-level("+k+")==================\n"); } // System.out.println("cellCount="+cellCount); DefaultGraphCell[] cellsCache = new DefaultGraphCell[cellCount]; for (int i = 0; i < cellCount; i++) cellsCache[i] = cells[i]; jgraph.getGraphLayoutCache().insert(cellsCache); Dimension d = jgraph.getPreferredSize(); //System.out.println(d.width +","+d.height); jgraph.setPreferredSize(new Dimension(d.width + 150, d.height)); jgraphPanel.removeAll(); JScrollPane jsp = new JScrollPane(jgraph); jgraphPanel.add(jsp); jgraphPanel.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y)); JViewport jv = jsp.getViewport(); jv.setViewPosition(new Point(0, YMiddle - 150)); jgraphPanel.validate(); }
From source file:com.jvms.i18neditor.editor.Editor.java
private void setupUI() { Color borderColor = Colors.scale(UIManager.getColor("Panel.background"), .8f); setTitle(TITLE);/*w w w . j a v a 2 s. co m*/ setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new EditorWindowListener()); setIconImages(Lists.newArrayList("512", "256", "128", "64", "48", "32", "24", "20", "16").stream() .map(size -> Images.loadFromClasspath("images/icon-" + size + ".png").getImage()) .collect(Collectors.toList())); translationTree = new TranslationTree(); translationTree.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); translationTree.addTreeSelectionListener(new TranslationTreeNodeSelectionListener()); translationTree.addMouseListener(new TranslationTreeMouseListener()); translationField = new TranslationField(); translationField.addKeyListener(new TranslationFieldKeyListener()); translationField.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 1, borderColor), ((CompoundBorder) translationField.getBorder()).getInsideBorder())); JScrollPane translationsScrollPane = new JScrollPane(translationTree); translationsScrollPane.getViewport().setOpaque(false); translationsScrollPane.setOpaque(false); translationsScrollPane.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, borderColor)); translationsPanel = new JPanel(new BorderLayout()); translationsPanel.add(translationsScrollPane); translationsPanel.add(translationField, BorderLayout.SOUTH); resourcesPanel = new JScrollablePanel(true, false); resourcesPanel.setLayout(new BoxLayout(resourcesPanel, BoxLayout.Y_AXIS)); resourcesPanel.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); resourcesPanel.setOpaque(false); resourcesPanel.addMouseListener(new ResourcesPaneMouseListener()); resourcesScrollPane = new JScrollPane(resourcesPanel); resourcesScrollPane.getViewport().setOpaque(false); resourcesScrollPane.setOpaque(false); resourcesScrollPane.setBorder(null); resourcesScrollPane.addMouseListener(new ResourcesPaneMouseListener()); contentPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, translationsPanel, resourcesScrollPane); contentPane.setBorder(null); contentPane.setDividerSize(10); // Style the split pane divider if possible SplitPaneUI splitPaneUI = contentPane.getUI(); if (splitPaneUI instanceof BasicSplitPaneUI) { BasicSplitPaneDivider divider = ((BasicSplitPaneUI) splitPaneUI).getDivider(); divider.setBorder(null); resourcesPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 20)); } introText = new JLabel("<html><body style=\"text-align:center; padding:30px;\">" + MessageBundle.get("core.intro.text") + "</body></html>"); introText.setOpaque(true); introText.setFont(introText.getFont().deriveFont(28f)); introText.setHorizontalTextPosition(JLabel.CENTER); introText.setVerticalTextPosition(JLabel.BOTTOM); introText.setHorizontalAlignment(JLabel.CENTER); introText.setVerticalAlignment(JLabel.CENTER); introText.setForeground(getBackground().darker()); introText.setIcon(Images.loadFromClasspath("images/icon-intro.png")); Container container = getContentPane(); container.add(introText); editorMenu = new EditorMenuBar(this, translationTree); setJMenuBar(editorMenu); }
From source file:captureplugin.CapturePlugin.java
/** * Check the programs after data update. *///from ww w. j a v a2s . c o m public void handleTvDataUpdateFinished() { mNeedsUpdate = true; if (mAllowedToShowDialog) { mNeedsUpdate = false; DeviceIf[] devices = mConfig.getDeviceArray(); final DefaultTableModel model = new DefaultTableModel() { public boolean isCellEditable(int row, int column) { return false; } }; model.setColumnCount(5); model.setColumnIdentifiers(new String[] { mLocalizer.msg("device", "Device"), Localizer.getLocalization(Localizer.I18N_CHANNEL), mLocalizer.msg("date", "Date"), ProgramFieldType.START_TIME_TYPE.getLocalizedName(), ProgramFieldType.TITLE_TYPE.getLocalizedName() }); JTable table = new JTable(model); table.getTableHeader().setReorderingAllowed(false); table.getTableHeader().setResizingAllowed(false); table.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable renderTable, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(renderTable, value, isSelected, hasFocus, row, column); if (value instanceof DeviceIf) { if (((DeviceIf) value).getDeleteRemovedProgramsAutomatically() && !isSelected) { c.setForeground(Color.red); } } return c; } }); int[] columnWidth = new int[5]; for (int i = 0; i < columnWidth.length; i++) { columnWidth[i] = UiUtilities.getStringWidth(table.getFont(), model.getColumnName(i)) + 10; } for (DeviceIf device : devices) { Program[] deleted = device.checkProgramsAfterDataUpdateAndGetDeleted(); if (deleted != null && deleted.length > 0) { for (Program p : deleted) { if (device.getDeleteRemovedProgramsAutomatically() && !p.isExpired() && !p.isOnAir()) { device.remove(UiUtilities.getLastModalChildOf(getParentFrame()), p); } else { device.removeProgramWithoutExecution(p); } if (!p.isExpired()) { Object[] o = new Object[] { device, p.getChannel().getName(), p.getDateString(), p.getTimeString(), p.getTitle() }; for (int i = 0; i < columnWidth.length; i++) { columnWidth[i] = Math.max(columnWidth[i], UiUtilities.getStringWidth(table.getFont(), o[i].toString()) + 10); } model.addRow(o); } } } device.getProgramList(); } if (model.getRowCount() > 0) { int sum = 0; for (int i = 0; i < columnWidth.length; i++) { table.getColumnModel().getColumn(i).setPreferredWidth(columnWidth[i]); if (i < columnWidth.length - 1) { table.getColumnModel().getColumn(i).setMaxWidth(columnWidth[i]); } sum += columnWidth[i]; } JScrollPane scrollPane = new JScrollPane(table); scrollPane.setPreferredSize(new Dimension(450, 250)); if (sum > 500) { table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); scrollPane.getViewport().setPreferredSize( new Dimension(sum, scrollPane.getViewport().getPreferredSize().height)); } JButton export = new JButton(mLocalizer.msg("exportList", "Export list")); export.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.setDialogType(JFileChooser.SAVE_DIALOG); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { return f.isDirectory() || f.toString().toLowerCase().endsWith(".txt"); } public String getDescription() { return "*.txt"; } }); chooser.setSelectedFile(new File("RemovedPrograms.txt")); if (chooser.showSaveDialog( UiUtilities.getLastModalChildOf(getParentFrame())) == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) { String file = chooser.getSelectedFile().getAbsolutePath(); if (!file.toLowerCase().endsWith(".txt") && file.indexOf('.') == -1) { file = file + ".txt"; } if (file.indexOf('.') != -1) { try { RandomAccessFile write = new RandomAccessFile(file, "rw"); write.setLength(0); String eolStyle = File.separator.equals("/") ? "\n" : "\r\n"; for (int i = 0; i < model.getRowCount(); i++) { StringBuilder line = new StringBuilder(); for (int j = 0; j < model.getColumnCount(); j++) { line.append(model.getValueAt(i, j)).append(' '); } line.append(eolStyle); write.writeBytes(line.toString()); } write.close(); } catch (Exception ee) { } } } } } }); Object[] message = { mLocalizer.msg("deletedText", "The data was changed and the following programs were deleted:"), scrollPane, export }; JOptionPane pane = new JOptionPane(); pane.setMessage(message); pane.setMessageType(JOptionPane.PLAIN_MESSAGE); final JDialog d = pane.createDialog(UiUtilities.getLastModalChildOf(getParentFrame()), mLocalizer.msg("CapturePlugin", "CapturePlugin") + " - " + mLocalizer.msg("deletedTitle", "Deleted programs")); d.setResizable(true); d.setModal(false); SwingUtilities.invokeLater(new Runnable() { public void run() { d.setVisible(true); } }); } } }
From source file:gdt.jgui.tool.JEntityEditor.java
private void save() { try {//from ww w .j ava 2 s . c o m int eCnt = tabbedPane.getComponentCount(); Sack candidate = new Sack(); String element$; JScrollPane scrollPane; JTable table; int rCnt; Core row; TableModel model; for (int i = 0; i < eCnt; i++) { element$ = tabbedPane.getTitleAt(i); candidate.createElement(element$); scrollPane = (JScrollPane) tabbedPane.getComponentAt(i); table = (JTable) scrollPane.getViewport().getView(); rCnt = table.getRowCount(); model = table.getModel(); for (int j = 0; j < rCnt; j++) { row = new Core((String) model.getValueAt(j, 0), (String) model.getValueAt(j, 1), (String) model.getValueAt(j, 2)); if ("attributes".equals(element$)) candidate.putAttribute(row); else candidate.putElementItem(element$, row); } } candidate.setKey(entityKey$); candidate.saveXML(entihome$ + "/" + Entigrator.ENTITY_BASE + "/data/" + entityKey$); } catch (Exception e) { LOGGER.severe(e.toString()); } }
From source file:src.gui.ItTabbedPane.java
public void stateChanged(ChangeEvent e) { // TODO Auto-generated method stub selectedTabIndex = getSelectedIndex(); // this is done because the sizes may be different // they are different when a tab is closed // TODO deal the tab closing case if (selectedTabIndex > -1 && openTabs.getChildren().size() == getTabCount()) { Element selectedTab = (Element) openTabs.getChildren().get(selectedTabIndex); Element project = ItSIMPLE.getInstance().getItTree() .getProject(selectedTab.getAttributeValue("projectID")); String type = selectedTab.getChildText("type"); if (type.equals("objectDiagram")) { Element diagram = null; try { XPath path = new JDOMXPath("diagrams/planningDomains/domain[@id='" + selectedTab.getChildText("domain") + "']/planningProblems/problem[@id='" + selectedTab.getChildText("problem") + "']/objectDiagrams/objectDiagram[@id='" + selectedTab.getAttributeValue("diagramID") + "']"); diagram = (Element) path.selectSingleNode(project); } catch (JaxenException e2) { e2.printStackTrace();// w w w .ja va 2s . c o m } if (diagram != null) { // get the current jgraph JRootPane panel = (JRootPane) getComponentAt(selectedTabIndex); JScrollPane scroll = (JScrollPane) panel.getComponent(3);// don't know exactly why the scrool pane is added in this position ItGraph graph = (ItGraph) scroll.getViewport().getView(); AdditionalPropertiesTabbedPane.getInstance().showAdditionalProperties(diagram, graph); } } else { AdditionalPropertiesTabbedPane.getInstance().setNoSelection(); } } }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.AngleDirectController.java
/** * Initialize the main view.// ww w .j a va 2 s . c o m */ private void initAngleDirectPanel() { // initialize the main view angleDirectPanel = new AngleDirectPanel(); // initialize the dataTable dataTable = new JTable(); JScrollPane scrollPane = new JScrollPane(dataTable); //the table will take all the viewport height available dataTable.setFillsViewportHeight(true); scrollPane.getViewport().setBackground(Color.white); dataTable.getTableHeader().setReorderingAllowed(false); //row selection must be false && column selection true to be able to select through columns dataTable.setColumnSelectionAllowed(true); dataTable.setRowSelectionAllowed(false); angleDirectPanel.getDataTablePanel().add(scrollPane); //create a ButtonGroup for the radioButtons used for analysis ButtonGroup radioButtonGroup = new ButtonGroup(); //adding buttons to a ButtonGroup automatically deselect one when another one gets selected radioButtonGroup.add(angleDirectPanel.getInstTurnAngleRadioButton()); radioButtonGroup.add(angleDirectPanel.getTrackTurnAngleRadioButton()); // radioButtonGroup.add(angleDirectPanel.getDynamicDirectRatioRadioButton()); // radioButtonGroup.add(angleDirectPanel.getEndPointDirectRatioRadioButton()); /** * Add action listeners */ // show instantaneous turning angles angleDirectPanel.getInstTurnAngleRadioButton().addActionListener((ActionEvent e) -> { PlateCondition currentCondition = singleCellPreProcessingController.getCurrentCondition(); //check that a condition is selected if (currentCondition != null) { showInstAngleInTable(currentCondition); plotHistTA(currentCondition); plotPolarTA(currentCondition); plotRoseTA(currentCondition); plotCompassTA(currentCondition); } }); // show and plot averaged-track turning angles angleDirectPanel.getTrackTurnAngleRadioButton().addActionListener((ActionEvent e) -> { PlateCondition currentCondition = singleCellPreProcessingController.getCurrentCondition(); //check that a condition is selected if (currentCondition != null) { showTrackAngleInTable(currentCondition); plotHistTrackTA(currentCondition); plotPolarTrackTA(currentCondition); plotRoseTrackTA(currentCondition); plotCompassTrackTA(currentCondition); } }); /** * */ angleDirectPanel.getSaveChartToPdfButton().addActionListener((ActionEvent e) -> { ChartPanel chartPanel = rosePlotChartPanels.get(2); JFreeChart chart = chartPanel.getChart(); if (chart != null) { try { // create the PDF report file createPdf(chart); } catch (IOException ex) { LOG.error(ex.getMessage(), ex); } } }); // // show dynamic directionality ratios // angleDirectPanel.getDynamicDirectRatioRadioButton().addActionListener((ActionEvent e) -> { // PlateCondition currentCondition = singleCellPreProcessingController.getCurrentCondition(); // //check that a condition is selected // if (currentCondition != null) { // // } // }); // // // show end-point directionality ratios // angleDirectPanel.getEndPointDirectRatioRadioButton().addActionListener((ActionEvent e) -> { // PlateCondition currentCondition = singleCellPreProcessingController.getCurrentCondition(); // //check that a condition is selected // if (currentCondition != null) { // // } // }); //select as default first button angleDirectPanel.getInstTurnAngleRadioButton().setSelected(true); // add view to parent panel singleCellPreProcessingController.getSingleCellAnalysisPanel().getAngleDirectParentPanel() .add(angleDirectPanel, gridBagConstraints); angleDirectPanel.getTurningAngleParentPanel().add(turningAnglePanel, gridBagConstraints); }
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();/* w ww. ja va2 s .c om*/ 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))); }