List of usage examples for javax.swing JPanel setPreferredSize
@BeanProperty(preferred = true, description = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize)
From source file:fuel.gui.stats.MotorStatsPanel.java
private void refreshGraphs(Motorcycle motor) { graphContainer.removeAll();// ww w . ja v a2s .c o m if (motor != null) { DefaultPieDataset usageDataset = new DefaultPieDataset(); try { ResultSet thisMotor = database .Query("SELECT SUM(distance) FROM fuelrecords WHERE motorcycleId = " + motor.getId(), true); ResultSet otherMotors = database.Query( "SELECT SUM(distance) FROM fuelrecords WHERE NOT motorcycleId = " + motor.getId(), true); thisMotor.next(); otherMotors.next(); usageDataset.setValue(motor.toString(), thisMotor.getInt("1")); usageDataset.setValue("Andere motoren", otherMotors.getInt("1")); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause()); } JFreeChart usagePiechart = ChartFactory.createPieChart3D("", usageDataset, true, true, false); PiePlot3D plot3 = (PiePlot3D) usagePiechart.getPlot(); plot3.setForegroundAlpha(0.6f); //plot3.setCircular(true); JPanel usagePiechartPanel = new ChartPanel(usagePiechart); usagePiechartPanel .setBorder(BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Motorgebruik"))); usagePiechartPanel.setPreferredSize(new java.awt.Dimension(240, 240)); usagePiechartPanel.setLayout(new BorderLayout()); DefaultPieDataset stationDataset = new DefaultPieDataset(); try { for (Station station : database.getStations()) { ResultSet numberStations = database.Query( "SELECT DISTINCT stationId FROM fuelrecords WHERE stationId = " + station.getId(), true); if (numberStations.next()) { ResultSet otherMotors = database.Query("SELECT COUNT(*) FROM fuelrecords WHERE stationId = " + station.getId() + " AND motorcycleId = " + motor.getId(), true); otherMotors.next(); if (otherMotors.getInt("1") > 0) { stationDataset.setValue(station.toString(), otherMotors.getInt("1")); } } } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause()); } JFreeChart stationPiechart = ChartFactory.createPieChart3D("", stationDataset, true, true, false); PiePlot3D plot2 = (PiePlot3D) stationPiechart.getPlot(); plot2.setForegroundAlpha(0.6f); //plot3.setCircular(true); JPanel stationPiechartPanel = new ChartPanel(stationPiechart); stationPiechartPanel.setBorder( BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Tankstation verhouding"))); stationPiechartPanel.setPreferredSize(new java.awt.Dimension(240, 240)); stationPiechartPanel.setLayout(new BorderLayout()); DefaultPieDataset fuelDataset = new DefaultPieDataset(); try { ResultSet numberResults = database.Query("SELECT DISTINCT typeOfGas FROM fuelrecords", true); while (numberResults.next()) { ResultSet thisStation = database.Query( "SELECT SUM(liter) FROM fuelrecords WHERE typeOfGas = '" + numberResults.getString("typeOfGas") + "'AND motorcycleId = " + motor.getId(), true); thisStation.next(); if (thisStation.getDouble("1") > 0) { fuelDataset.setValue(numberResults.getString("TYPEOFGAS"), thisStation.getDouble("1")); } } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause()); } JFreeChart fuelPieChart = ChartFactory.createPieChart3D("", fuelDataset, true, true, false); PiePlot3D plot1 = (PiePlot3D) fuelPieChart.getPlot(); plot1.setForegroundAlpha(0.6f); //plot3.setCircular(true); JPanel fuelPieChartPanel = new ChartPanel(fuelPieChart); fuelPieChartPanel.setBorder( BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Brandstof verhouding"))); fuelPieChartPanel.setPreferredSize(new java.awt.Dimension(240, 240)); DefaultCategoryDataset barDataset = new DefaultCategoryDataset(); try { ResultSet motorThing = database .Query("SELECT distance/liter,date FROM fuelrecords WHERE motorcycleId = " + motor.getId() + " ORDER BY date ASC", true); while (motorThing.next()) { barDataset.addValue(motorThing.getDouble("1"), motorThing.getString("DATE"), "Verbruik"); } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause()); } JFreeChart barChart = ChartFactory.createBarChart3D("", // chart title "", // domain axis label "Aantal", // range axis label barDataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips? false // URLs? ); CategoryPlot plot = barChart.getCategoryPlot(); BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer(); renderer.setDrawBarOutline(false); ChartPanel barChartPanel = new ChartPanel(barChart); barChartPanel.getChartRenderingInfo().setEntityCollection(null); barChartPanel.setBorder(BorderFactory.createTitledBorder("Verbruik")); barChartPanel.setPreferredSize(new java.awt.Dimension(320, 240)); barChartPanel.setLayout(new BorderLayout()); JPanel piePanel = new JPanel(new GridLayout(0, 3)); piePanel.add(usagePiechartPanel); piePanel.add(stationPiechartPanel); piePanel.add(fuelPieChartPanel); //uitgaven DefaultPieDataset expensesDataset = new DefaultPieDataset(); try { Map<String, ResultSet> allCosts = new HashMap<String, ResultSet>(); ResultSet fuelCosts = database .Query("SELECT SUM(cost) FROM fuelrecords WHERE motorcycleId = " + motor.getId(), true); allCosts.put("Brandstof", fuelCosts); ResultSet expenses = database.Query("SELECT DISTINCT categoryid FROM expenses", true); while (expenses.next()) { ResultSet set = database.Query("SELECT SUM(costs) FROM expenses WHERE categoryid = " + expenses.getInt("categoryid") + " AND motorcycleid = " + motor.getId(), true); ResultSet set2 = database .Query("SELECT name FROM categories WHERE id = " + expenses.getInt("categoryid"), true); set2.next(); allCosts.put(set2.getString("name"), set); } for (Map.Entry<String, ResultSet> element : allCosts.entrySet()) { element.getValue().next(); if (element.getValue().getInt("1") > 0) { expensesDataset.setValue(element.getKey(), element.getValue().getInt("1")); } } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause()); } JFreeChart expensesPiechart = ChartFactory.createPieChart3D("", expensesDataset, true, true, false); PiePlot3D plot4 = (PiePlot3D) expensesPiechart.getPlot(); plot4.setForegroundAlpha(0.6f); JPanel expensesPiePanel = new ChartPanel(expensesPiechart); expensesPiePanel .setBorder(BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Uitgaven"))); expensesPiePanel.setPreferredSize(new java.awt.Dimension(240, 240)); expensesPiePanel.setLayout(new BorderLayout()); graphContainer.add(piePanel); graphContainer.add(barChartPanel); graphContainer.add(expensesPiePanel); } revalidate(); repaint(); }
From source file:ListSelectionDemo.java
public ListSelectionDemo() { super(new BorderLayout()); String[] listData = { "one", "two", "three", "four", "five", "six", "seven" }; String[] columnNames = { "French", "Spanish", "Italian" }; list = new JList(listData); listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); JScrollPane listPane = new JScrollPane(list); JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2);/*from ww w .j a va 2 s . co m*/ comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); // Build output area. output = new JTextArea(1, 10); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); listContainer.setBorder(BorderFactory.createTitledBorder("List")); listContainer.add(listPane); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); // topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(100, 50)); topHalf.setPreferredSize(new Dimension(100, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.PAGE_START); bottomHalf.add(outputPane, BorderLayout.CENTER); // XXX: next line needed if bottomHalf is a scroll pane: // bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 135)); splitPane.add(bottomHalf); }
From source file:charts.Chart.java
public static void PlotParallelCoordinates(String title, String x_axis_label, String y_axis_label, float[][] Md, int classes, int[] features, Vector featurestitles, Vector datatitles) { JFrame chartwindow = new JFrame(title); JFreeChart jfreechart = ChartFactory.createLineChart(title, x_axis_label, y_axis_label, null, PlotOrientation.VERTICAL, true, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setRangeGridlinePaint(Color.black); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); int lines = Md.length; int columns = Md[0].length; LineAndShapeRenderer[] lineandshaperenderer = new LineAndShapeRenderer[classes]; for (int i = 0; i < lineandshaperenderer.length; i++) { lineandshaperenderer[i] = new LineAndShapeRenderer(); lineandshaperenderer[i].setShapesVisible(true); lineandshaperenderer[i].setDrawOutlines(true); lineandshaperenderer[i].setUseFillPaint(true); lineandshaperenderer[i].setFillPaint(Color.white); lineandshaperenderer[i].setBaseStroke(new BasicStroke(2.0f)); }/*w w w . jav a 2s . c om*/ int count = 0; for (int i = 0; i < lines; i++) { int classe = ((int) Md[i][columns - 1]); DefaultKeyedValues2DDataset dataset = new DefaultKeyedValues2DDataset(); int j = 0; double value = 0; while (j < features.length) { /*value recebe o valor da linha i e da coluna especificada pelo usuario, por meio do parametro de chegada features[]*/ value = Md[i][features[j]]; String strclasse = String.valueOf(classe); //especifico Marie-Anne /* if (classe == 0) { strclasse = "thi1"; lineandshaperenderer[classe].setSeriesPaint(0, Color.RED); Shape s0 = new Rectangle2D.Float(-3f, -3f, 6f, 6f); lineandshaperenderer[classe].setSeriesShape(0, s0); } else if (classe == 1) { strclasse = "controle"; lineandshaperenderer[classe].setSeriesPaint(0, Color.PINK); Shape s1 = new Ellipse2D.Float(-3f, -3f, 6f, 6f); lineandshaperenderer[classe].setSeriesShape(0, s1); } else if (classe == 2) { strclasse = "fotossntese"; lineandshaperenderer[classe].setSeriesPaint(0, Color.GREEN); int[] x = {-3, 0, 3}; int[] y = {-3, 3, -3}; int n = 3; Shape s2 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesShape(0, s2); } else if (classe == 3) { strclasse = "respirao"; int[] x = {-3, 0, 3}; int[] y = {3, -3, 3}; int n = 3; Shape s3 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesShape(0, s3); lineandshaperenderer[classe].setSeriesPaint(0, Color.BLUE); } else if (classe == 4) { strclasse = "sntese de tiamina"; lineandshaperenderer[classe].setSeriesPaint(0, Color.BLACK); Shape s4 = new Rectangle2D.Float(-1f, -3f, 1f, 6f); lineandshaperenderer[classe].setSeriesShape(0, s4); } else if (classe == 5) { strclasse = "gliclise"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesPaint(0, Color.ORANGE); lineandshaperenderer[classe].setSeriesShape(0, s5); } else if (classe == 6) { strclasse = "AT4G34200"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesPaint(0, Color.MAGENTA); lineandshaperenderer[classe].setSeriesShape(0, s5); } else if (classe == 7) { strclasse = "AT2G36530"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesPaint(0, Color.CYAN); lineandshaperenderer[classe].setSeriesShape(0, s5); } */ if (featurestitles != null) { if (datatitles != null) { dataset.addValue(value, strclasse, (String) featurestitles.get(features[j] + 1)); //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c + 1)); } else { dataset.addValue(value, strclasse, (String) featurestitles.get(features[j])); //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c)); } } else { dataset.addValue(value, strclasse, String.valueOf(features[j])); //datasets[i].addValue(Mo[lineindex[i]][c], label, String.valueOf(c)); } //dataset.addValue(value, String.valueOf(classe), String.valueOf(features[j])); j++; } categoryplot.setDataset(count, dataset); categoryplot.setRenderer(count, lineandshaperenderer[classe]); count++; } LegendItemCollection legends = categoryplot.getLegendItems(); LegendItemCollection newlegends = new LegendItemCollection(); for (int i = 0; i < classes; i++) { int l = 0; //especifico Marie-Anne String label1 = null; if (i == 0) { label1 = "thi1"; } else if (i == 1) { label1 = "controle"; } else if (i == 2) { label1 = "fotossntese"; } else if (i == 3) { label1 = "respirao"; } else if (i == 4) { label1 = "sntese de tiamina"; } else if (i == 5) { label1 = "gliclise"; } else if (i == 6) { label1 = "AT4G34200"; } else if (i == 7) { label1 = "AT2G36530"; } //String label1 = String.valueOf(i); String label2 = null; boolean found = false; do { label2 = legends.get(l).getLabel(); if (label1.equalsIgnoreCase(label2)) { found = true; } else { l++; } } while (!found && (l < lines)); if (found) { //newlegends.add(legends.get(l)); LegendItem li = new LegendItem(legends.get(l).getLabel(), legends.get(l).getDescription(), legends.get(l).getToolTipText(), legends.get(l).getURLText(), legends.get(l).isShapeVisible(), legends.get(l).getShape(), legends.get(l).isShapeFilled(), legends.get(l).getFillPaint(), legends.get(l).isShapeOutlineVisible(), legends.get(l).getOutlinePaint(), legends.get(l).getOutlineStroke(), legends.get(l).isLineVisible(), legends.get(l).getLine(), legends.get(l).getLineStroke(), legends.get(l).getLinePaint()); newlegends.add(li); } } categoryplot.setFixedLegendItems(newlegends); JPanel jpanel = new ChartPanel(jfreechart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); chartwindow.setContentPane(jpanel); chartwindow.pack(); RefineryUtilities.centerFrameOnScreen(chartwindow); chartwindow.setVisible(true); }
From source file:ja.lingo.application.gui.main.settings.dictionaries.add.AddPanel.java
public AddPanel(JDialog parentDialog, IEngine engine) { Arguments.assertNotNull("parentDialog", parentDialog); Arguments.assertNotNull("engine", engine); this.parentDialog = parentDialog; this.engine = engine; fileChooser = new FileChooser(); encodingComboBox = new JComboBox(); encodingAutoComboBox = new JComboBox(new String[] { resources.text("encoding_auto") }); encodingAutoComboBox.setEnabled(false); encodingCardPanel = new CardPanel(); encodingCardPanel.add(encodingComboBox); encodingCardPanel.add(encodingAutoComboBox); readerList = Components//from w w w.j ava 2 s . c o m .list(new StaticListModel<IDictionaryReader>(new ReaderLabelBuilder(), engine.getReaders())); readerList.setSelectedIndex(0); editorPane = Components.editorPane(); editorPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { Browser.openUrl(e.getURL().toExternalForm()); } } }); continueButton = Buttons.continue1(); continueButton.setDefaultCapable(true); closeButton = Buttons.cancel(); JPanel buttonPanel = new JPanel(new GridLayout(1, 2, GAP5, GAP5)); buttonPanel.add(continueButton); buttonPanel.add(closeButton); JPanel listReaderPanel = new JPanel(new BorderLayout()); listReaderPanel.add(resources.label("reader"), BorderLayout.NORTH); listReaderPanel.add(new JScrollPane(readerList), BorderLayout.CENTER); readerList.setPreferredSize(new Dimension(50, 50)); listReaderPanel.setPreferredSize(new Dimension(100, 100)); JPanel descriptionReaderPanel = new JPanel(new BorderLayout()); descriptionReaderPanel.add(resources.label("readerDescription"), BorderLayout.NORTH); descriptionReaderPanel.add(new JScrollPane(editorPane), BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listReaderPanel, descriptionReaderPanel); splitPane.setContinuousLayout(true); splitPane.setDividerLocation(130); gui = new JPanel(new TableLayout(new double[][] { { TableLayout.PREFERRED, GAP5, TableLayout.FILL }, { TableLayout.FILL, // 0: reader panel GAP5, TableLayout.PREFERRED, // 2: file GAP5, TableLayout.PREFERRED, // 4: encoding GAP5 * 2, TableLayout.PREFERRED // 6: button panel } })); gui.add(splitPane, "0, 0, 2, 0"); gui.add(resources.label("file"), "0, 2"); gui.add(fileChooser.getGui(), "2, 2"); gui.add(resources.label("encoding"), "0, 4"); gui.add(encodingCardPanel.getGui(), "2, 4"); gui.add(buttonPanel, "0, 6, 2, 6, right, center"); Gaps.applyBorder7(gui); ActionBinder.bind(this); if (encodingComboBox.getModel().getSize() > 0) { encodingComboBox.setSelectedIndex(0); } // filters for (IDictionaryReader reader : engine.getReaders()) { fileChooser.getChooser().addChoosableFileFilter(reader.getFileFilter()); } onReaderSelected(); onFileFieldEdited(); }
From source file:com.tascape.qa.th.android.driver.App.java
/** * The method starts a GUI to let an user inspect element tree and take screenshot when the user is interacting * with the app-under-test manually. Please make sure to set timeout long enough for manual interaction. * * @param timeoutMinutes timeout in minutes to fail the manual steps * * @throws Exception if case of error/*from w w w .j a v a 2 s . c om*/ */ public void interactManually(int timeoutMinutes) throws Exception { LOG.info("Start manual UI interaction"); long end = System.currentTimeMillis() + timeoutMinutes * 60000L; AtomicBoolean visible = new AtomicBoolean(true); AtomicBoolean pass = new AtomicBoolean(false); String tName = Thread.currentThread().getName() + "m"; SwingUtilities.invokeLater(() -> { JDialog jd = new JDialog((JFrame) null, "Manual Device UI Interaction - " + device.getProductDetail()); jd.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); JPanel jpContent = new JPanel(new BorderLayout()); jd.setContentPane(jpContent); jpContent.setPreferredSize(new Dimension(1088, 828)); jpContent.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel jpInfo = new JPanel(); jpContent.add(jpInfo, BorderLayout.PAGE_START); jpInfo.setLayout(new BorderLayout()); { JButton jb = new JButton("PASS"); jb.setForeground(Color.green.darker()); jb.setFont(jb.getFont().deriveFont(Font.BOLD)); jpInfo.add(jb, BorderLayout.LINE_START); jb.addActionListener(event -> { pass.set(true); jd.dispose(); visible.set(false); }); } { JButton jb = new JButton("FAIL"); jb.setForeground(Color.red); jb.setFont(jb.getFont().deriveFont(Font.BOLD)); jpInfo.add(jb, BorderLayout.LINE_END); jb.addActionListener(event -> { pass.set(false); jd.dispose(); visible.set(false); }); } JLabel jlTimeout = new JLabel("xxx seconds left", SwingConstants.CENTER); jpInfo.add(jlTimeout, BorderLayout.CENTER); jpInfo.add(jlTimeout, BorderLayout.CENTER); new SwingWorker<Long, Long>() { @Override protected Long doInBackground() throws Exception { while (System.currentTimeMillis() < end) { Thread.sleep(1000); long left = (end - System.currentTimeMillis()) / 1000; this.publish(left); } return 0L; } @Override protected void process(List<Long> chunks) { Long l = chunks.get(chunks.size() - 1); jlTimeout.setText(l + " seconds left"); if (l < 850) { jlTimeout.setForeground(Color.red); } } }.execute(); JPanel jpResponse = new JPanel(new BorderLayout()); JPanel jpProgress = new JPanel(new BorderLayout()); jpResponse.add(jpProgress, BorderLayout.PAGE_START); JTextArea jtaJson = new JTextArea(); jtaJson.setEditable(false); jtaJson.setTabSize(4); Font font = jtaJson.getFont(); jtaJson.setFont(new Font("Courier New", font.getStyle(), font.getSize())); JTree jtView = new JTree(); JTabbedPane jtp = new JTabbedPane(); jtp.add("tree", new JScrollPane(jtView)); jtp.add("json", new JScrollPane(jtaJson)); jpResponse.add(jtp, BorderLayout.CENTER); JPanel jpScreen = new JPanel(); jpScreen.setMinimumSize(new Dimension(200, 200)); jpScreen.setLayout(new BoxLayout(jpScreen, BoxLayout.PAGE_AXIS)); JScrollPane jsp1 = new JScrollPane(jpScreen); jpResponse.add(jsp1, BorderLayout.LINE_START); JPanel jpJs = new JPanel(new BorderLayout()); JTextArea jtaJs = new JTextArea(); jpJs.add(new JScrollPane(jtaJs), BorderLayout.CENTER); JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jpResponse, jpJs); jSplitPane.setResizeWeight(0.88); jpContent.add(jSplitPane, BorderLayout.CENTER); JPanel jpLog = new JPanel(); jpLog.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); jpLog.setLayout(new BoxLayout(jpLog, BoxLayout.LINE_AXIS)); JCheckBox jcbTap = new JCheckBox("Enable Click", null, false); jpLog.add(jcbTap); jpLog.add(Box.createHorizontalStrut(8)); JButton jbLogUi = new JButton("Log Screen"); jpResponse.add(jpLog, BorderLayout.PAGE_END); { jpLog.add(jbLogUi); jbLogUi.addActionListener((ActionEvent event) -> { jtaJson.setText("waiting for screenshot..."); Thread t = new Thread(tName) { @Override public void run() { LOG.debug("\n\n"); try { WindowHierarchy wh = device.loadWindowHierarchy(); jtView.setModel(getModel(wh)); jtaJson.setText(""); jtaJson.append(wh.root.toJson().toString(2)); jtaJson.append("\n"); File png = device.takeDeviceScreenshot(); BufferedImage image = ImageIO.read(png); int w = device.getDisplayWidth(); int h = device.getDisplayHeight(); BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = resizedImg.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(image, 0, 0, w, h, null); g2.dispose(); JLabel jLabel = new JLabel(new ImageIcon(resizedImg)); jpScreen.removeAll(); jsp1.setPreferredSize(new Dimension(w + 30, h)); jpScreen.add(jLabel); jLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { LOG.debug("clicked at {},{}", e.getPoint().getX(), e.getPoint().getY()); if (jcbTap.isSelected()) { device.click(e.getPoint().x, e.getPoint().y); device.waitForIdle(); jbLogUi.doClick(); } } }); } catch (Exception ex) { LOG.error("Cannot log screen", ex); jtaJson.append("Cannot log screen"); } jtaJson.append("\n\n\n"); LOG.debug("\n\n"); jd.setSize(jd.getBounds().width + 1, jd.getBounds().height + 1); jd.setSize(jd.getBounds().width - 1, jd.getBounds().height - 1); } }; t.start(); }); } jpLog.add(Box.createHorizontalStrut(38)); { JButton jbLogMsg = new JButton("Log Message"); jpLog.add(jbLogMsg); JTextField jtMsg = new JTextField(10); jpLog.add(jtMsg); jtMsg.addFocusListener(new FocusListener() { @Override public void focusLost(final FocusEvent pE) { } @Override public void focusGained(final FocusEvent pE) { jtMsg.selectAll(); } }); jtMsg.addKeyListener(new KeyAdapter() { @Override public void keyPressed(java.awt.event.KeyEvent e) { if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) { jbLogMsg.doClick(); } } }); jbLogMsg.addActionListener(event -> { Thread t = new Thread(tName) { @Override public void run() { String msg = jtMsg.getText(); if (StringUtils.isNotBlank(msg)) { LOG.info("{}", msg); jtMsg.selectAll(); } } }; t.start(); try { t.join(); } catch (InterruptedException ex) { LOG.error("Cannot take screenshot", ex); } jtMsg.requestFocus(); }); } jpLog.add(Box.createHorizontalStrut(38)); { JButton jbClear = new JButton("Clear"); jpLog.add(jbClear); jbClear.addActionListener(event -> { jtaJson.setText(""); }); } JPanel jpAction = new JPanel(); jpContent.add(jpAction, BorderLayout.PAGE_END); jpAction.setLayout(new BoxLayout(jpAction, BoxLayout.LINE_AXIS)); jpJs.add(jpAction, BorderLayout.PAGE_END); jd.pack(); jd.setVisible(true); jd.setLocationRelativeTo(null); jbLogUi.doClick(); }); while (visible.get()) { if (System.currentTimeMillis() > end) { LOG.error("Manual UI interaction timeout"); break; } Thread.sleep(500); } if (pass.get()) { LOG.info("Manual UI Interaction returns PASS"); } else { Assert.fail("Manual UI Interaction returns FAIL"); } }
From source file:events.TableListSelectionDemo.java
public TableListSelectionDemo() { super(new BorderLayout()); String[] columnNames = { "French", "Spanish", "Italian" }; String[][] tableData = { { "un", "uno", "uno" }, { "deux", "dos", "due" }, { "trois", "tres", "tre" }, { "quatre", "cuatro", "quattro" }, { "cinq", "cinco", "cinque" }, { "six", "seis", "sei" }, { "sept", "siete", "sette" } }; table = new JTable(tableData, columnNames); listSelectionModel = table.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); table.setSelectionModel(listSelectionModel); JScrollPane tablePane = new JScrollPane(table); //Build control area (use default FlowLayout). JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2);// w ww . jav a2 s. c om comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); //Build output area. output = new JTextArea(1, 10); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); JPanel tableContainer = new JPanel(new GridLayout(1, 1)); tableContainer.setBorder(BorderFactory.createTitledBorder("Table")); tableContainer.add(tablePane); tablePane.setPreferredSize(new Dimension(420, 130)); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(250, 50)); topHalf.setPreferredSize(new Dimension(200, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.PAGE_START); bottomHalf.add(outputPane, BorderLayout.CENTER); //XXX: next line needed if bottomHalf is a scroll pane: //bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 110)); splitPane.add(bottomHalf); }
From source file:TableSelectionDemo.java
public TableSelectionDemo() { super(new BorderLayout()); String[] columnNames = { "French", "Spanish", "Italian" }; String[][] tableData = { { "un", "uno", "uno" }, { "deux", "dos", "due" }, { "trois", "tres", "tre" }, { "quatre", "cuatro", "quattro" }, { "cinq", "cinco", "cinque" }, { "six", "seis", "sei" }, { "sept", "siete", "sette" } }; table = new JTable(tableData, columnNames); listSelectionModel = table.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); table.setSelectionModel(listSelectionModel); JScrollPane tablePane = new JScrollPane(table); // Build control area (use default FlowLayout). JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2);/* ww w. ja v a 2 s . c o m*/ comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); // Build output area. output = new JTextArea(1, 10); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); JPanel tableContainer = new JPanel(new GridLayout(1, 1)); tableContainer.setBorder(BorderFactory.createTitledBorder("Table")); tableContainer.add(tablePane); tablePane.setPreferredSize(new Dimension(420, 130)); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(250, 50)); topHalf.setPreferredSize(new Dimension(200, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.PAGE_START); bottomHalf.add(outputPane, BorderLayout.CENTER); // XXX: next line needed if bottomHalf is a scroll pane: // bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 110)); splitPane.add(bottomHalf); }
From source file:com.haulmont.cuba.desktop.App.java
protected JComponent createBottomPane() { JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createLineBorder(Color.gray)); panel.setPreferredSize(new Dimension(0, 20)); ServerSelector serverSelector = AppBeans.get(ServerSelector.NAME); String url = serverSelector.getUrl(serverSelector.initContext()); if (url == null) url = "?"; final JLabel connectionStateLab = new JLabel( messages.formatMainMessage("statusBar.connected", getUserFriendlyConnectionUrl(url))); panel.add(connectionStateLab, BorderLayout.WEST); JPanel rightPanel = new JPanel(); BoxLayout rightLayout = new BoxLayout(rightPanel, BoxLayout.LINE_AXIS); rightPanel.setLayout(rightLayout);/*from www . jav a 2 s . c o m*/ UserSession session = connection.getSession(); JLabel userInfoLabel = new JLabel(); String userInfo = messages.formatMainMessage("statusBar.user", session.getUser().getName(), session.getUser().getLogin()); userInfoLabel.setText(userInfo); rightPanel.add(userInfoLabel); JLabel timeZoneLabel = null; if (session.getTimeZone() != null) { timeZoneLabel = new JLabel(); String timeZone = messages.formatMainMessage("statusBar.timeZone", AppBeans.get(TimeZones.class).getDisplayNameShort(session.getTimeZone())); timeZoneLabel.setText(timeZone); rightPanel.add(Box.createRigidArea(new Dimension(5, 0))); rightPanel.add(timeZoneLabel); } panel.add(rightPanel, BorderLayout.EAST); if (isTestMode()) { panel.setName("bottomPane"); userInfoLabel.setName("userInfoLabel"); if (timeZoneLabel != null) timeZoneLabel.setName("timeZoneLabel"); connectionStateLab.setName("connectionStateLab"); } return panel; }
From source file:wef.articulab.view.ui.CombinedBNXYPlot.java
/** * Creates a new demo instance.//from ww w . j av a 2 s . c o m */ public CombinedBNXYPlot(String name1, String name2, String title1, String title2, String[] series1, String[] series2, boolean shouldPlot) { super("Social Reasoner"); Container content = getContentPane(); content.setLayout(new GridBagLayout()); JPanel chartCSPanel = null; JPanel chartPhasePanel = null; if (shouldPlot) { chartContainer1 = new ChartContainer(name1, title1, series1); chartCSPanel = createChartPanel(chartContainer1); if (name2 != null) { chartContainer2 = new ChartContainer(name2, title2, series2); chartPhasePanel = createChartPanel(chartContainer2); } else { chartCSPanel.setPreferredSize(new Dimension(970, 750)); } } inputPanel = createInputPanel(); outputPanel = createOutputPanel(); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; add(outputPanel, gbc); add(Box.createRigidArea(new Dimension(0, 40))); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; add(inputPanel, gbc); if (shouldPlot) { if (chartPhasePanel != null) { gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 0; add(chartCSPanel, gbc); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 1; add(chartPhasePanel, gbc); } else { gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 0; gbc.gridheight = 2; add(chartCSPanel, gbc); } } pack(); setVisible(true); setResizable(false); }
From source file:net.pandoragames.far.ui.swing.RenameFilesPanel.java
private void init(SwingConfig config, ComponentRepository componentRepository) { this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.setBorder( BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING)); this.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); JLabel patternLabel = new JLabel(localizer.localize("label.find-pattern")); this.add(patternLabel); filenamePattern = new JTextField(); filenamePattern.setPreferredSize(/*from www . j ava2 s . c om*/ new Dimension(SwingConfig.COMPONENT_WIDTH_LARGE, config.getStandardComponentHight())); filenamePattern .setMaximumSize(new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, config.getStandardComponentHight())); filenamePattern.setAlignmentX(Component.LEFT_ALIGNMENT); UndoHistory findUndoManager = new UndoHistory(); findUndoManager.registerUndoHistory(filenamePattern); findUndoManager.registerSnapshotHistory(filenamePattern); componentRepository.getReplaceCommand().addResetable(findUndoManager); filenamePattern.getDocument().addDocumentListener(new DocumentChangeListener() { public void documentUpdated(DocumentEvent e, String text) { dataModel.setPatternString(text); updateFileTable(); } }); componentRepository.getResetDispatcher().addToBeCleared(filenamePattern); this.add(filenamePattern); JCheckBox caseBox = new JCheckBox(localizer.localize("label.ignore-case")); caseBox.setSelected(true); caseBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { dataModel.setIgnoreCase((ItemEvent.SELECTED == event.getStateChange())); updateFileTable(); } }); this.add(caseBox); JCheckBox regexBox = new JCheckBox(localizer.localize("label.regular-expression")); regexBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { dataModel.setRegexPattern((ItemEvent.SELECTED == event.getStateChange())); updateFileTable(); } }); this.add(regexBox); JPanel extensionPanel = new JPanel(); extensionPanel.setBorder(BorderFactory.createTitledBorder(localizer.localize("label.modify-extension"))); extensionPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); extensionPanel.setAlignmentX(Component.LEFT_ALIGNMENT); extensionPanel.setPreferredSize(new Dimension(SwingConfig.COMPONENT_WIDTH_LARGE, 60)); extensionPanel.setMaximumSize(new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, 100)); ButtonGroup extensionGroup = new ButtonGroup(); JRadioButton protectButton = new JRadioButton(localizer.localize("label.protect-extension")); protectButton.setSelected(true); protectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { dataModel.setProtectExtension(true); updateFileTable(); } }); extensionGroup.add(protectButton); extensionPanel.add(protectButton); JRadioButton includeButton = new JRadioButton(localizer.localize("label.include-extension")); includeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { dataModel.setExtensionOnly(false); dataModel.setProtectExtension(false); updateFileTable(); } }); extensionGroup.add(includeButton); extensionPanel.add(includeButton); JRadioButton onlyButton = new JRadioButton(localizer.localize("label.only-extension")); onlyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { dataModel.setExtensionOnly(true); updateFileTable(); } }); extensionGroup.add(onlyButton); extensionPanel.add(onlyButton); this.add(extensionPanel); this.add(Box.createVerticalGlue()); this.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); // replace JLabel replaceLabel = new JLabel(localizer.localize("label.replacement-pattern")); this.add(replaceLabel); replacePattern = new JTextField(); replacePattern.setPreferredSize( new Dimension(SwingConfig.COMPONENT_WIDTH_LARGE, config.getStandardComponentHight())); replacePattern .setMaximumSize(new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, config.getStandardComponentHight())); replacePattern.setAlignmentX(Component.LEFT_ALIGNMENT); UndoHistory undoManager = new UndoHistory(); undoManager.registerUndoHistory(replacePattern); undoManager.registerSnapshotHistory(replacePattern); componentRepository.getReplaceCommand().addResetable(undoManager); replacePattern.getDocument().addDocumentListener(new DocumentChangeListener() { public void documentUpdated(DocumentEvent e, String text) { dataModel.setReplacementString(text); updateFileTable(); } }); componentRepository.getResetDispatcher().addToBeCleared(replacePattern); this.add(replacePattern); // treat case JPanel modifyCasePanel = new JPanel(); modifyCasePanel.setBorder(BorderFactory.createTitledBorder(localizer.localize("label.modify-case"))); modifyCasePanel.setLayout(new BoxLayout(modifyCasePanel, BoxLayout.Y_AXIS)); modifyCasePanel.setAlignmentX(Component.LEFT_ALIGNMENT); modifyCasePanel.setPreferredSize(new Dimension(SwingConfig.COMPONENT_WIDTH_LARGE, 100)); modifyCasePanel.setMaximumSize(new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, 200)); ButtonGroup modifyCaseGroup = new ButtonGroup(); ActionListener radioButtonListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); dataModel.setTreatCase(RenameForm.CASEHANDLING.valueOf(cmd)); updateFileTable(); } }; JRadioButton lowerButton = new JRadioButton(localizer.localize("label.to-lower-case")); lowerButton.setActionCommand(RenameForm.CASEHANDLING.LOWER.name()); lowerButton.addActionListener(radioButtonListener); modifyCaseGroup.add(lowerButton); modifyCasePanel.add(lowerButton); JRadioButton upperButton = new JRadioButton(localizer.localize("label.to-upper-case")); upperButton.setActionCommand(RenameForm.CASEHANDLING.UPPER.name()); upperButton.addActionListener(radioButtonListener); modifyCaseGroup.add(upperButton); modifyCasePanel.add(upperButton); JRadioButton keepButton = new JRadioButton(localizer.localize("label.preserve-case")); keepButton.setActionCommand(RenameForm.CASEHANDLING.PRESERVE.name()); keepButton.setSelected(true); keepButton.addActionListener(radioButtonListener); modifyCaseGroup.add(keepButton); modifyCasePanel.add(keepButton); this.add(modifyCasePanel); // prevent case conflict JCheckBox caseConflictBox = new JCheckBox(localizer.localize("label.prevent-case-conflict")); caseConflictBox.setAlignmentX(Component.LEFT_ALIGNMENT); caseConflictBox.setSelected(true); caseConflictBox.setEnabled(!SwingConfig.isWindows()); // disabled on windows caseConflictBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { dataModel.setPreventCaseConflict((ItemEvent.SELECTED == event.getStateChange())); updateFileTable(); } }); this.add(caseConflictBox); this.add(Box.createVerticalGlue()); }