List of usage examples for javax.swing JTextArea setTabSize
@BeanProperty(preferred = true, description = "the number of characters to expand tabs to") public void setTabSize(int size)
From source file:Main.java
public static void main(String[] argv) { JTextArea textarea = new JTextArea(); // Get the default tab size int tabSize = textarea.getTabSize(); // 8 // Change the tab size tabSize = 4;/* ww w. ja v a 2s .c om*/ textarea.setTabSize(tabSize); Font font = textarea.getFont(); System.out.println(font); }
From source file:com.clank.launcher.swing.SwingHelper.java
/** * Show a message dialog using/*from www.j av a 2s . c om*/ * {@link javax.swing.JOptionPane#showMessageDialog(java.awt.Component, Object, String, int)}. * * <p>The dialog will be shown from the Event Dispatch Thread, regardless of the * thread it is called from. In either case, the method will block until the * user has closed the dialog (or dialog creation fails for whatever reason).</p> * * @param parentComponent the frame from which the dialog is displayed, otherwise * null to use the default frame * @param message the message to display * @param title the title string for the dialog * @param messageType see {@link javax.swing.JOptionPane#showMessageDialog(java.awt.Component, Object, String, int)} * for available message types */ public static void showMessageDialog(final Component parentComponent, @NonNull final String message, @NonNull final String title, final String detailsText, final int messageType) { if (SwingUtilities.isEventDispatchThread()) { // To force the label to wrap, convert the message to broken HTML String htmlMessage = "<html><div style=\"width: 250px\">" + htmlEscape(message); JPanel panel = new JPanel(new BorderLayout(0, detailsText != null ? 20 : 0)); // Add the main message panel.add(new JLabel(htmlMessage), BorderLayout.NORTH); // Add the extra details if (detailsText != null) { JTextArea textArea = new JTextArea(_("errors.reportErrorPreface") + detailsText); JLabel tempLabel = new JLabel(); textArea.setFont(tempLabel.getFont()); textArea.setBackground(tempLabel.getBackground()); textArea.setTabSize(2); textArea.setEditable(false); textArea.setComponentPopupMenu(TextFieldPopupMenu.INSTANCE); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setPreferredSize(new Dimension(350, 120)); panel.add(scrollPane, BorderLayout.CENTER); } JOptionPane.showMessageDialog(parentComponent, panel, title, messageType); } else { // Call method again from the Event Dispatch Thread try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { showMessageDialog(parentComponent, message, title, detailsText, messageType); } }); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } }
From source file:net.sf.firemox.deckbuilder.DeckRules.java
/** * Create a new instance of DeckRules//from w w w .j av a 2s .c o m * * @param parent */ public DeckRules(JFrame parent) { super(LanguageManager.getString("jdeckrules", MdbLoader.getTbsFullName()), LanguageManager.getString("jdeckrules.tooltip", MdbLoader.getTbsFullName()), "wiz_library_wiz.png", LanguageManager.getString("close"), 490, 300); // ... Set initial text, scrolling, and border. final JTextArea textRules = new JTextArea(); textRules.setEditable(false); textRules.setLineWrap(true); textRules.setWrapStyleWord(true); textRules.setAutoscrolls(true); textRules.setTabSize(2); textRules.setText("No defined rules"); BufferedReader inGPL = null; try { inGPL = new BufferedReader(new FileReader(MToolKit.getTbsFile( "decks/DECK_CONSTRAINTS-" + LanguageManager.getLanguage().getLocale() + "-lang.info"))); textRules.read(inGPL, "Deck constraints"); } catch (IOException e) { // Ignore this error } finally { IOUtils.closeQuietly(inGPL); } final JScrollPane scrollingArea = new JScrollPane(textRules); gameParamPanel.add(scrollingArea); pack(); }
From source file:net.sf.firemox.ui.component.SplashScreen.java
/** * Create a new instance of this class./* w w w.j ava 2 s . co m*/ * * @param filename * the picture filename. * @param parent * the splash screen's parent. * @param waitTime * the maximum time before the screen is hidden. */ public SplashScreen(String filename, Frame parent, int waitTime) { super(parent); getContentPane().setLayout(null); toFront(); final JLabel l = new JLabel(new ImageIcon(filename)); final Dimension labelSize = l.getPreferredSize(); l.setLocation(0, 0); l.setSize(labelSize); setSize(labelSize); final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setLocation(screenSize.width / 2 - labelSize.width / 2, screenSize.height / 2 - labelSize.height / 2); final JLabel mp = new JLabel(IdConst.PROJECT_DISPLAY_NAME); mp.setLocation(30, 305); mp.setSize(new Dimension(300, 30)); final JLabel version = new JLabel(IdConst.VERSION); version.setLocation(235, 418); version.setSize(new Dimension(300, 30)); final JTextArea disclaimer = new JTextArea(); disclaimer.setEditable(false); disclaimer.setLineWrap(true); disclaimer.setWrapStyleWord(true); disclaimer.setAutoscrolls(true); disclaimer.setFont(MToolKit.defaultFont); disclaimer.setTabSize(2); // Then try and read it locally Reader inGPL = null; try { inGPL = new BufferedReader(new InputStreamReader(MToolKit.getResourceAsStream(IdConst.FILE_LICENSE))); disclaimer.read(inGPL, ""); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(inGPL); } final JScrollPane disclaimerSPanel = new JScrollPane(); disclaimerSPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); disclaimerSPanel.setViewportView(disclaimer); disclaimerSPanel.setLocation(27, 340); disclaimerSPanel.setPreferredSize(new Dimension(283, 80)); disclaimerSPanel.setSize(disclaimerSPanel.getPreferredSize()); getContentPane().add(disclaimerSPanel); getContentPane().add(version); getContentPane().add(mp); getContentPane().add(l); final int pause = waitTime; final Runnable waitRunner = new Runnable() { public void run() { try { Thread.sleep(pause); while (!bKilled) { Thread.sleep(200); } } catch (InterruptedException e) { // Ignore this error } setVisible(false); dispose(); MagicUIComponents.magicForm.toFront(); } }; // setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { setVisible(false); dispose(); if (MagicUIComponents.magicForm != null) MagicUIComponents.magicForm.toFront(); } }); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { setVisible(false); dispose(); MagicUIComponents.magicForm.toFront(); } } }); setVisible(true); start(waitRunner); }
From source file:net.sf.firemox.ui.wizard.About.java
/** * Creates a new instance of About <br> * // w w w . java 2 s . c o m * @param parent */ public About(JFrame parent) { super(LanguageManager.getString("wiz_about.title"), LanguageManager.getString("wiz_about.description"), "mp64.gif", LanguageManager.getString("close"), 420, 620); JPanel thanksPanel = new JPanel(); thanksPanel.setLayout(new BoxLayout(thanksPanel, BoxLayout.X_AXIS)); thanksPanel.setMaximumSize(new Dimension(32767, 26)); thanksPanel.setOpaque(false); JLabel jLabel5 = new JLabel(LanguageManager.getString("version") + " : "); jLabel5.setFont(MToolKit.defaultFont); jLabel5.setHorizontalAlignment(SwingConstants.RIGHT); jLabel5.setMaximumSize(new Dimension(100, 16)); jLabel5.setMinimumSize(new Dimension(100, 16)); jLabel5.setPreferredSize(new Dimension(100, 16)); thanksPanel.add(jLabel5); jLabel5 = new JLabel(IdConst.VERSION); thanksPanel.add(jLabel5); gameParamPanel.add(thanksPanel); thanksPanel = new JPanel(); thanksPanel.setLayout(new BoxLayout(thanksPanel, BoxLayout.X_AXIS)); thanksPanel.setOpaque(false); JPanel thanksPanelLeft = new JPanel(new FlowLayout(FlowLayout.LEADING)); thanksPanelLeft.setLayout(new BoxLayout(thanksPanelLeft, BoxLayout.Y_AXIS)); thanksPanelLeft.setMaximumSize(new Dimension(100, 2000)); thanksPanelLeft.setMinimumSize(new Dimension(100, 16)); jLabel5 = new JLabel(LanguageManager.getString("thanks") + " : "); jLabel5.setFont(MToolKit.defaultFont); jLabel5.setHorizontalAlignment(SwingConstants.RIGHT); jLabel5.setMaximumSize(new Dimension(100, 16)); jLabel5.setMinimumSize(new Dimension(100, 16)); jLabel5.setPreferredSize(new Dimension(100, 16)); thanksPanelLeft.add(jLabel5); thanksPanel.add(thanksPanelLeft); thanksPanelLeft = new JPanel(); thanksPanelLeft.setLayout(new BoxLayout(thanksPanelLeft, BoxLayout.Y_AXIS)); StringBuilder contributors = new StringBuilder(); addContributor(contributors, "Fabrice Daugan", "developper", "france"); addContributor(contributors, "Hoani Cross", "developper", "frenchpolynesia"); addContributor(contributors, "nico100", "graphist", "france"); addContributor(contributors, "seingalt_tm", "graphist", "france"); addContributor(contributors, "surtur2", "tester", null); addContributor(contributors, "Jan Blaha", "developper", "cz"); addContributor(contributors, "Tureba", "developper", "brazil"); addContributor(contributors, "hakvf", "tester", "france"); addContributor(contributors, "Stefano \"Kismet\" Lenzi", "developper", "italian"); jLabel5 = new JLabel(contributors.toString()); jLabel5.setFont(MToolKit.defaultFont); jLabel5.setHorizontalAlignment(SwingConstants.LEFT); thanksPanelLeft.add(jLabel5); jLabel5 = new JLink("http://obsidiurne.free.fr", "morgil has designed the splash screen"); jLabel5.setFont(MToolKit.defaultFont); thanksPanelLeft.add(jLabel5); thanksPanel.add(thanksPanelLeft); gameParamPanel.add(thanksPanel); thanksPanel = new JPanel(); thanksPanel.setLayout(new BoxLayout(thanksPanel, BoxLayout.X_AXIS)); thanksPanel.setMaximumSize(new Dimension(32767, 26)); thanksPanel.setOpaque(false); JLabel blanklbl = new JLabel(); blanklbl.setHorizontalAlignment(SwingConstants.RIGHT); blanklbl.setMaximumSize(new Dimension(100, 16)); blanklbl.setMinimumSize(new Dimension(100, 16)); blanklbl.setPreferredSize(new Dimension(100, 16)); thanksPanel.add(blanklbl); jLabel5 = new JLink( "http://sourceforge.net/tracker/?func=add&group_id=" + IdConst.PROJECT_ID + "&atid=601043", LanguageManager.getString("joindev")); jLabel5.setFont(MToolKit.defaultFont); thanksPanel.add(jLabel5); gameParamPanel.add(thanksPanel); thanksPanel = new JPanel(); thanksPanel.setLayout(new BoxLayout(thanksPanel, BoxLayout.X_AXIS)); thanksPanel.setOpaque(false); jLabel5 = new JLabel(LanguageManager.getString("projecthome") + " : "); jLabel5.setFont(MToolKit.defaultFont); jLabel5.setHorizontalAlignment(SwingConstants.RIGHT); jLabel5.setMaximumSize(new Dimension(100, 16)); jLabel5.setMinimumSize(new Dimension(100, 16)); jLabel5.setPreferredSize(new Dimension(100, 16)); thanksPanel.add(jLabel5); jLabel5 = new JLink(IdConst.MAIN_PAGE, IdConst.MAIN_PAGE); jLabel5.setFont(MToolKit.defaultFont); thanksPanel.add(jLabel5); gameParamPanel.add(thanksPanel); // forum francais thanksPanel = new JPanel(); thanksPanel.setLayout(new BoxLayout(thanksPanel, BoxLayout.X_AXIS)); thanksPanel.setOpaque(false); jLabel5 = new JLabel(LanguageManager.getString("othersites") + " : "); jLabel5.setFont(MToolKit.defaultFont); jLabel5.setHorizontalAlignment(SwingConstants.RIGHT); jLabel5.setMaximumSize(new Dimension(100, 16)); jLabel5.setMinimumSize(new Dimension(100, 16)); jLabel5.setPreferredSize(new Dimension(100, 16)); thanksPanel.add(jLabel5); jLabel5 = new JLink("http://www.Firemox.fr.st", UIHelper.getIcon("mpfrsml.gif"), SwingConstants.LEFT); jLabel5.setToolTipText(LanguageManager.getString("frenchforum.tooltip")); thanksPanel.add(jLabel5); jLabel5 = new JLabel(); jLabel5.setMaximumSize(new Dimension(1000, 16)); thanksPanel.add(jLabel5); gameParamPanel.add(thanksPanel); JTextArea disclaimer = new JTextArea(); disclaimer.setEditable(false); disclaimer.setLineWrap(true); disclaimer.setWrapStyleWord(true); disclaimer.setAutoscrolls(true); disclaimer.setTabSize(2); disclaimer.setFont(new Font("Arial", 0, 10)); // Then try and read it locally BufferedReader inGPL = null; try { inGPL = new BufferedReader(new InputStreamReader(MToolKit.getResourceAsStream(IdConst.FILE_LICENSE))); disclaimer.read(inGPL, ""); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(inGPL); } JScrollPane disclaimerSPanel = new JScrollPane(); disclaimerSPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); MToolKit.addOverlay(disclaimerSPanel); disclaimerSPanel.setViewportView(disclaimer); gameParamPanel.add(disclaimerSPanel); }
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 www .j av 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"); } }