List of usage examples for javax.swing.text DefaultStyledDocument DefaultStyledDocument
public DefaultStyledDocument()
From source file:org.executequery.gui.editor.QueryEditorTextPane.java
public void disableUpdates(boolean disable) { String text = getText();// w w w . j ava2s . c om if (disable) { setDocument(new DefaultStyledDocument()); setText(text); disableCaretUpdate(true); } else { setDocument(document); setText(text); disableCaretUpdate(false); } }
From source file:org.executequery.gui.editor.QueryEditorTextPane.java
private void loadDummyDocument() { setDocument(new DefaultStyledDocument()); }
From source file:org.mutoss.gui.dialogs.AboutDialog.java
private DefaultStyledDocument getDocument() { DefaultStyledDocument doc = new DefaultStyledDocument(); logger.info("Creating About-Text."); try {/*from w w w .jav a 2 s .c om*/ doc.insertString(doc.getLength(), "Crossover " + Configuration.getInstance().getGeneralConfig().getVersionNumber() + "\n\n", getH1()); doc.insertString(doc.getLength(), "by Kornelius Rohmeyer is distributed under GPL 2.0.\n\n", getT()); doc.insertString(doc.getLength(), "This program uses the libraries log4j, jxlayer,\n " + "swingworker, commons logging/lang, JRI and JGoodies Forms.\n", getT()); doc.insertString(doc.getLength(), "\n" + "This program is free software; you can redistribute it and/or\n" + "modify it under the terms of the GNU General Public License\n" + "as published by the Free Software Foundation, Version 2.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details. It is included\n" + "in the R distribution (in directory share/licenses) or can be\n" + "found at: http://www.gnu.org/licenses/\n", getT()); doc.setParagraphAttributes(0, doc.getLength(), getC(), true); } catch (BadLocationException ble) { logger.error("BadLocationException was thrown. Should never happen.", ble); } return doc; }
From source file:org.opendatakit.appengine.updater.UpdaterWindow.java
/** * Create the application.//from www . j a v a 2s . com */ public UpdaterWindow(CommandLine cmd) { super(); AnnotationProcessor.process(this);// if not using AOP this.cmd = cmd; frame = new JFrame(); frame.setBounds(100, 100, isLinux() ? 720 : 680, 595); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosing(WindowEvent e) { } @Override public void windowClosed(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }); JLabel lblEmail = new JLabel(t(TranslatedStrings.EMAIL_LABEL)); txtEmail = new JTextField(); txtEmail.setFocusable(true); txtEmail.setEditable(true); txtEmail.setColumns(60); txtEmail.setMaximumSize(txtEmail.getPreferredSize()); if (cmd.hasOption(ArgumentNameConstants.EMAIL)) { txtEmail.setText(cmd.getOptionValue(ArgumentNameConstants.EMAIL)); } lblEmail.setLabelFor(txtEmail); JLabel lblToken = new JLabel(t(TranslatedStrings.TOKEN_GRANTING_LABEL)); txtToken = new JTextField(); txtToken.setColumns(60); txtToken.setMaximumSize(txtToken.getPreferredSize()); txtToken.setFocusable(false); txtToken.setEditable(false); if (cmd.hasOption(ArgumentNameConstants.TOKEN_GRANTING_CODE)) { txtToken.setText(cmd.getOptionValue(ArgumentNameConstants.TOKEN_GRANTING_CODE)); } lblToken.setLabelFor(txtToken); // set up listener for updating warning message txtEmail.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { updateUI(); } @Override public void removeUpdate(DocumentEvent e) { updateUI(); } @Override public void changedUpdate(DocumentEvent e) { updateUI(); } }); // set up listener for updating warning message txtToken.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { updateUI(); } @Override public void removeUpdate(DocumentEvent e) { updateUI(); } @Override public void changedUpdate(DocumentEvent e) { updateUI(); } }); if ((txtEmail.getText().length() > 0) && ((txtToken.getText().length() > 0) || perhapsHasToken())) { lblWarning = new JLabel(t(TranslatedStrings.WARNING_ERRANT_LABEL)); } else { lblWarning = new JLabel(t(TranslatedStrings.WARNING_REDIRECT_LABEL)); } JLabel outputArea = new JLabel(t(TranslatedStrings.OUTPUT_LBL)); editorArea = new JTextPane(new DefaultStyledDocument()); editorArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); //Put the editor pane in a scroll pane. editorScrollPane = new JScrollPane(editorArea); editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setPreferredSize(new Dimension(400, 300)); editorScrollPane.setMinimumSize(new Dimension(10, 10)); outputArea.setLabelFor(editorScrollPane); // Create a container so that we can add a title around // the scroll pane. Can't add a title directly to the // scroll pane because its background would be white. // Lay out the label and scroll pane from top to bottom. JPanel listPane = new JPanel(); listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); listPane.add(outputArea); listPane.add(Box.createRigidArea(new Dimension(0, 5))); listPane.add(editorScrollPane); listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); btnDeleteToken = new JButton(t(TranslatedStrings.DELETE_TOKEN_LABEL)); btnDeleteToken.addActionListener(new DeleteTokenActionListener()); btnDeleteToken.setEnabled(perhapsHasToken()); btnChoose = new JButton(t(TranslatedStrings.GET_TOKEN_LABEL)); if ((txtEmail.getText().length() > 0) && (txtToken.getText().length() > 0) || perhapsHasToken()) { if (perhapsHasToken()) { btnChoose.setText(t(TranslatedStrings.VERIFY_TOKEN_LABEL)); } else { btnChoose.setText(t(TranslatedStrings.SET_TOKEN_LABEL)); } } else { btnChoose.setText(t(TranslatedStrings.GET_TOKEN_LABEL)); } btnChoose.addActionListener(new GetTokenActionListener()); btnChoose.setEnabled(txtEmail.getText().length() > 0); btnUpload = new JButton(t(TranslatedStrings.UPLOAD_LABEL)); btnUpload.addActionListener(new UploadActionListener()); btnUpload.setEnabled((txtEmail.getText().length() > 0) && perhapsHasToken()); btnRollback = new JButton(t(TranslatedStrings.ROLLBACK_LABEL)); btnRollback.addActionListener(new RollbackActionListener()); btnRollback.setEnabled((txtEmail.getText().length() > 0) && perhapsHasToken()); GroupLayout groupLayout = new GroupLayout(frame.getContentPane()); groupLayout .setHorizontalGroup( groupLayout.createSequentialGroup().addContainerGap() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(lblEmail) .addComponent(txtEmail).addComponent(lblToken).addComponent(txtToken) .addComponent(lblWarning).addComponent(listPane) .addGroup(groupLayout.createSequentialGroup().addComponent(btnDeleteToken) .addGap(3 * HorizontalSpacing).addComponent(btnChoose) .addGap(HorizontalSpacing).addComponent(btnUpload) .addGap(3 * HorizontalSpacing, 4 * HorizontalSpacing, Short.MAX_VALUE) .addComponent(btnRollback))) .addContainerGap()); groupLayout.setVerticalGroup(groupLayout.createSequentialGroup().addContainerGap().addComponent(lblEmail) .addPreferredGap(ComponentPlacement.RELATED).addComponent(txtEmail) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(lblToken) .addPreferredGap(ComponentPlacement.RELATED).addComponent(txtToken) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(lblWarning) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(listPane) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(btnDeleteToken) .addComponent(btnChoose).addComponent(btnUpload).addComponent(btnRollback)) .addContainerGap()); frame.getContentPane().setLayout(groupLayout); frame.addWindowListener(this); }
From source file:org.rockyroadshub.planner.core.gui.calendar.FormPane.java
private void initDocuments() { documentEvt = new DefaultStyledDocument(); documentEvt.setDocumentFilter(new TextLimiter(Globals.EVENT_TITLE_SIZE)); documentEvt.addDocumentListener(document); formatEvt = Utilities.stamp(Globals.EVENT_TITLE_SIZE); eventInput.setFont(font);// ww w . j av a2 s . c om eventInput.setDocument(documentEvt); eventInput.setName(EVT_INPUT); eventLimit.setText(String.format(formatEvt, 0)); documentDsc = new DefaultStyledDocument(); documentDsc.setDocumentFilter(new TextLimiter(Globals.EVENT_DESCR_SIZE)); documentDsc.addDocumentListener(document); formatDsc = Utilities.stamp(Globals.EVENT_DESCR_SIZE); descriptionInput.setFont(font); descriptionInput.setDocument(documentDsc); descriptionInput.setName(DSC_INPUT); descriptionLimit.setText(String.format(formatDsc, 0)); descriptionInput.setLineWrap(true); documentLoc = new DefaultStyledDocument(); documentLoc.setDocumentFilter(new TextLimiter(Globals.EVENT_LOCAT_SIZE)); documentLoc.addDocumentListener(document); formatLoc = Utilities.stamp(Globals.EVENT_LOCAT_SIZE); locationInput.setFont(font); locationInput.setDocument(documentLoc); locationInput.setName(LOC_INPUT); locationLimit.setText(String.format(formatLoc, 0)); locationInput.setLineWrap(true); }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Builds the GUI for the application// w w w.j a v a 2s. c o m */ private void setup() { JPanel panel; JPanel gridPanel; JPanel outerPanel; JPanel flowPanel; JPanel boxedPanel; ButtonGroup bGroup; MaxHeightJScrollPane maxHeightJScrollPane; setupComponents(); getContentPane().setLayout(new BorderLayout()); // table.getTableHeader().setFont(new Font(table.getTableHeader().getFont(). // getName(), table.getTableHeader().getFont().getStyle(), // MessageStyleFactory.instance().getFontSize())); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); panel = new JPanel(); panel.setLayout(new BorderLayout()); outerPanel = new JPanel(); outerPanel.setLayout(new BorderLayout()); gridPanel = new JPanel(); gridPanel.setLayout(new GridLayout(0, 1)); gridPanel.add(connectString = new JComboBox()); connectString.setEditable(true); gridPanel.add(querySelection = new JComboBox()); querySelection.setEditable(false); querySelection.addActionListener(this); outerPanel.add(gridPanel, BorderLayout.NORTH); outerPanel.add(new JScrollPane(queryText = new JTextArea(QUERY_AREA_ROWS, QUERY_AREA_COLUMNS)), BorderLayout.SOUTH); queryText.setLineWrap(true); queryText.setWrapStyleWord(true); queryText.addKeyListener(this); panel.add(outerPanel, BorderLayout.CENTER); outerPanel = new JPanel(); outerPanel.setLayout(new BorderLayout()); boxedPanel = new JPanel(); boxedPanel.setLayout(new GridLayout(0, 2)); boxedPanel.add(new JLabel(Resources.getString("proUserId"))); boxedPanel.add(userId = new JTextField(10)); boxedPanel.add(new JLabel(Resources.getString("proPassword"))); boxedPanel.add(password = new JPasswordField(10)); outerPanel.add(boxedPanel, BorderLayout.WEST); // Prev/Next and the checkboxes are all on the flowPanel - Center of // outerPanel flowPanel = new JPanel(); flowPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); // Previous/Next buttons boxedPanel = new JPanel(); boxedPanel.setLayout(new FlowLayout()); boxedPanel.add(previousQuery = new JButton(Resources.getString("ctlPrev"), new ImageIcon(ImageUtility.getImageAsByteArray("ArrowLeftGreen.gif")))); previousQuery.setToolTipText(Resources.getString("tipPrev")); previousQuery.addActionListener(this); boxedPanel.add(nextQuery = new JButton(Resources.getString("ctlNext"), new ImageIcon(ImageUtility.getImageAsByteArray("ArrowRightGreen.gif")))); nextQuery.setToolTipText(Resources.getString("tipNext")); nextQuery.addActionListener(this); flowPanel.add(boxedPanel); // Checkboxes: Autocommit, Read Only and Pooling boxedPanel = new JPanel(); boxedPanel.setLayout(new FlowLayout()); boxedPanel.setBorder(getStandardBorder()); boxedPanel.add(autoCommit = new JCheckBox(Resources.getString("ctlAutoCommit"), true)); boxedPanel.add(readOnly = new JCheckBox(Resources.getString("ctlReadOnly"), false)); boxedPanel.add(poolConnect = new JCheckBox(Resources.getString("ctlConnPool"), false)); poolConnect.setEnabled(false); flowPanel.add(boxedPanel); outerPanel.add(flowPanel, BorderLayout.CENTER); boxedPanel = new JPanel(); boxedPanel.setLayout(new GridLayout(0, 1)); boxedPanel.setBorder(getStandardBorder()); boxedPanel.add(runIndicator = new JLabel(Resources.getString("ctlRunning"), JLabel.CENTER)); runIndicator.setForeground(Color.lightGray); boxedPanel.add(timeIndicator = new JLabel("", JLabel.RIGHT)); outerPanel.add(boxedPanel, BorderLayout.EAST); panel.add(outerPanel, BorderLayout.NORTH); flowPanel = new JPanel(); flowPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); boxedPanel = new JPanel(); boxedPanel.setLayout(new FlowLayout()); boxedPanel.setBorder(getStandardBorder()); boxedPanel.add(new JLabel(Resources.getString("proQueryType"))); boxedPanel.add(asQuery = new JRadioButton(Resources.getString("ctlSelect"), true)); boxedPanel.add(asUpdate = new JRadioButton(Resources.getString("ctlUpdate"))); boxedPanel.add(asDescribe = new JRadioButton(Resources.getString("ctlDescribe"))); bGroup = new ButtonGroup(); bGroup.add(asQuery); bGroup.add(asUpdate); bGroup.add(asDescribe); asQuery.addActionListener(this); asUpdate.addActionListener(this); asDescribe.addActionListener(this); flowPanel.add(boxedPanel); flowPanel.add(new JLabel(" ")); boxedPanel = new JPanel(); boxedPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); boxedPanel.setBorder(getStandardBorder()); boxedPanel.add(new JLabel(Resources.getString("proMaxRows"))); boxedPanel.add(maxRows); flowPanel.add(boxedPanel); flowPanel.add(new JLabel(" ")); flowPanel.add(execute = new JButton(Resources.getString("ctlExecute"))); execute.addActionListener(this); flowPanel.add(remove = new JButton(Resources.getString("ctlRemove"))); remove.addActionListener(this); flowPanel.add(commentToggle = new JButton(Resources.getString("ctlComment"))); commentToggle.addActionListener(this); flowPanel.add(nextInList = new JButton(Resources.getString("ctlDown"))); nextInList.addActionListener(this); panel.add(flowPanel, BorderLayout.SOUTH); getContentPane().add(panel, BorderLayout.NORTH); getRootPane().setDefaultButton(execute); messageDocument = new DefaultStyledDocument(); getContentPane().add( maxHeightJScrollPane = new MaxHeightJScrollPane(message = new JTextPane(messageDocument)), BorderLayout.SOUTH); message.setEditable(false); loadedDBDriver = false; loadMenu(); setupTextStyles(); loadProperties(); setupUserDefinedColoring(); setupResultsTableColoring(); loadConfig(); loadConnectStrings(); loadQueries(); loadDrivers(); // Check for avail of pool - enable/disable pooling option as appropriate // Not really useful until we get the pooling classes out of this code try { new GenericObjectPool(null); poolConnect.setEnabled(true); poolConnect.setSelected(true); } catch (Throwable any) { // No Apache Commons DB Pooling Library Found (DBCP) LOGGER.error(Resources.getString("errNoPoolLib"), any); } setDefaults(); maxHeightJScrollPane.lockHeight(getHeight() / MAX_SCROLL_PANE_DIVISOR_FOR_MAX_HEIGHT); // Font setFontFromConfig(Configuration.instance()); setVisible(true); }