List of usage examples for java.beans PropertyChangeListener PropertyChangeListener
PropertyChangeListener
From source file:EditorPaneExample19.java
public EditorPaneExample19() { super("JEditorPane Example 19"); pane = new JEditorPane(); pane.setEditable(true); // Editable getContentPane().add(new JScrollPane(pane), "Center"); // Add a menu bar menuBar = new JMenuBar(); setJMenuBar(menuBar);/*from w ww . ja v a2 s. c o m*/ // Populate it createMenuBar(); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1; c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridy = 5; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; editableBox = new JCheckBox("Editable JEditorPane"); panel.add(editableBox, c); editableBox.setSelected(true); editableBox.setForeground(typeLabel.getForeground()); c.gridy = 6; c.weightx = 0.0; JButton saveButton = new JButton("Save"); panel.add(saveButton, c); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { EditorKit kit = pane.getEditorKit(); try { if (kit instanceof RTFEditorKit) { kit.write(System.out, pane.getDocument(), 0, pane.getDocument().getLength()); System.out.flush(); } else { if (writer == null) { writer = new OutputStreamWriter(System.out); pane.write(writer); writer.flush(); } kit.write(writer, pane.getDocument(), 0, pane.getDocument().getLength()); writer.flush(); } } catch (Exception e) { System.out.println("Write failed"); } } }); c.gridx = 1; c.gridy = 0; c.weightx = 1.0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Register a custom EditorKit for HTML ClassLoader loader = getClass().getClassLoader(); if (loader != null) { // Java 2 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.EnhancedHTMLEditorKit", loader); } else { // JDK 1.1 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.EnhancedHTMLEditorKit"); } // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Change editability based on the checkbox editableBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editableBox.isSelected()); pane.revalidate(); pane.repaint(); } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); createMenuBar(); enableMenuBar(true); getRootPane().revalidate(); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:EditorPaneExample17.java
public EditorPaneExample17() { super("JEditorPane Example 17"); pane = new JEditorPane(); pane.setEditable(true); // Editable getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;/*ww w . j av a2 s .com*/ c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridy = 5; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; editableBox = new JCheckBox("Editable JEditorPane"); panel.add(editableBox, c); editableBox.setSelected(true); editableBox.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Register a custom EditorKit for HTML ClassLoader loader = getClass().getClassLoader(); if (loader != null) { // Java 2 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit", loader); } else { // JDK 1.1 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit"); } // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Change editability based on the checkbox editableBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editableBox.isSelected()); pane.revalidate(); pane.repaint(); } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:VASSAL.build.module.GlobalOptions.java
public void addTo(Buildable parent) { instance = this; final GameModule gm = GameModule.getGameModule(); final Prefs prefs = gm.getPrefs(); // should this moudule use a combined main window? final BooleanConfigurer combConf = new BooleanConfigurer(SINGLE_WINDOW, Resources.getString("GlobalOptions.use_combined"), //$NON-NLS-1$ Boolean.TRUE);/*from w w w .ja v a 2 s. c o m*/ prefs.addOption(combConf); useSingleWindow = !Boolean.FALSE.equals(combConf.getValue()); // the initial heap size for this module final IntConfigurer initHeapConf = new IntConfigurer(INITIAL_HEAP, Resources.getString("GlobalOptions.initial_heap"), //$NON-NLS-1$ Integer.valueOf(256)); prefs.addOption(initHeapConf); // the maximum heap size for this module final IntConfigurer maxHeapConf = new IntConfigurer(MAXIMUM_HEAP, Resources.getString("GlobalOptions.maximum_heap"), //$NON-NLS-1$ Integer.valueOf(512)); prefs.addOption(maxHeapConf); // Bug 10295: Sometimes, for unknown reasons, the native drag handler // fails to draw images properly on Windows. This lets the user select // the drag handler to use. if (SystemUtils.IS_OS_WINDOWS) { final BooleanConfigurer bug10295Conf = new BooleanConfigurer(BUG_10295, Resources.getString("GlobalOptions.bug10295"), Boolean.FALSE); if (Boolean.TRUE.equals(bug10295Conf.getValue()) && !(PieceMover.AbstractDragHandler .getTheDragHandler() instanceof PieceMover.DragHandlerNoImage)) { PieceMover.AbstractDragHandler.setTheDragHandler(new PieceMover.DragHandlerNoImage()); } bug10295Conf.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { PieceMover.AbstractDragHandler.setTheDragHandler( (Boolean.TRUE.equals(e.getNewValue()) || !DragSource.isDragImageSupported()) ? new PieceMover.DragHandlerNoImage() : new PieceMover.DragHandler()); } }); prefs.addOption(bug10295Conf); } validator = new SingleChildInstance(gm, getClass()); }
From source file:org.openmicroscopy.shoola.agents.imviewer.util.saver.ImgSaver.java
/** * Notifies that the image has been saved locally. * /* w w w . ja va 2s.c o m*/ * @param name The path to the local file. */ private void notifySave(String name) { NotificationDialog dialog = new NotificationDialog(this, "Save Image", getSaveMessage(name), true); dialog.addPropertyChangeListener(new PropertyChangeListener() { /** * Opens the image with default viewer. */ public void propertyChange(PropertyChangeEvent evt) { if (NotificationDialog.HYPERLINK_OPEN_PROPERTY.equals(evt.getPropertyName())) { UserNotifier un = ImViewerAgent.getRegistry().getUserNotifier(); un.openApplication(null, (String) evt.getNewValue()); } } }); dialog.pack(); UIUtilities.centerAndShow(dialog); }
From source file:com.mirth.connect.client.ui.browsers.event.EventBrowser.java
public void initComponentsManual() { this.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { if (evt.isPopupTrigger()) { parent.eventPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); }/*from w ww . j av a 2s . c o m*/ } public void mouseReleased(java.awt.event.MouseEvent evt) { if (evt.isPopupTrigger()) { parent.eventPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }); pageSizeField.setDocument(new MirthFieldConstraints(3, false, false, true)); pageNumberField.setDocument(new MirthFieldConstraints(7, false, false, true)); LineBorder lineBorder = new LineBorder(new Color(0, 0, 0)); TitledBorder titledBorder = new TitledBorder("Current Search"); titledBorder.setBorder(lineBorder); lastSearchCriteriaPane.setBorder(titledBorder); lastSearchCriteriaPane.setBackground(Color.white); lastSearchCriteria.setBackground(Color.white); startDatePicker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent arg0) { allDayCheckBox.setEnabled(startDatePicker.getDate() != null || endDatePicker.getDate() != null); startTimePicker.setEnabled(startDatePicker.getDate() != null && !allDayCheckBox.isSelected()); } }); endDatePicker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent arg0) { allDayCheckBox.setEnabled(startDatePicker.getDate() != null || endDatePicker.getDate() != null); endTimePicker.setEnabled(endDatePicker.getDate() != null && !allDayCheckBox.isSelected()); } }); pageNumberField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_ENTER && pageGoButton.isEnabled()) { jumpToPageNumber(); } } }); updateCachedUserMap(); advancedSearchPopup = new EventBrowserAdvancedFilter(parent, "Advanced Search Filter", true, userMapById); advancedSearchPopup.setVisible(false); eventSplitPane.setDividerLocation(0.8); this.addAncestorListener(new AncestorListener() { @Override public void ancestorAdded(AncestorEvent event) { } @Override public void ancestorMoved(AncestorEvent event) { } @Override public void ancestorRemoved(AncestorEvent event) { // Stop waiting for event browser requests when the event browser // is no longer being displayed parent.mirthClient.getServerConnection().abort(getAbortOperations()); // Clear the event cache when leaving the event browser. parent.eventBrowser.clearCache(); } }); }
From source file:com.konifar.material_icon_generator.MaterialDesignIconGenerateDialog.java
private void initDpComboBox() { comboBoxDp.addActionListener(new ActionListener() { @Override//from w w w .j a va 2 s. co m public void actionPerformed(ActionEvent event) { model.setDpAndFileName((String) comboBoxDp.getSelectedItem()); textFieldFileName.setText(model.getFileName()); showIconPreview(); } }); comboBoxDp.getAccessibleContext().addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (AccessibleContext.ACCESSIBLE_STATE_PROPERTY.equals(event.getPropertyName()) && AccessibleState.FOCUSED.equals(event.getNewValue()) && comboBoxDp.getAccessibleContext().getAccessibleChild(0) instanceof ComboPopup) { ComboPopup popup = (ComboPopup) comboBoxDp.getAccessibleContext().getAccessibleChild(0); JList list = popup.getList(); comboBoxDp.setSelectedItem(String.valueOf(list.getSelectedValue())); } } }); }
From source file:uk.ac.gda.client.plotting.ScanDataPlotterComposite.java
private void setupDataSelection() { rootDataNode.getChildren().addListChangeListener(new IListChangeListener() { @Override//from www . ja v a 2 s. co m public void handleListChange(ListChangeEvent event) { event.diff.accept(new ListDiffVisitor() { @Override public void handleRemove(int index, Object element) { // } @Override public void handleAdd(int index, Object element) { if (clearPlotOnStartOfScan) { for (Object obj : dataTreeViewer.getCheckedElements()) { dataTreeViewer.updateCheckSelection(obj, false); } } } }); } }); rootDataNode.addPropertyChangeListener(Node.DATA_ADDED_PROP_NAME, new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { Node node = (Node) evt.getNewValue(); dataTreeViewer.expandToLevel(node.getParent(), AbstractTreeViewer.ALL_LEVELS); if (node instanceof LineTraceProviderNode && dataTreeViewer.getChecked(node)) { addTrace((LineTraceProviderNode) node); } } }); rootDataNode.addPropertyChangeListener(Node.SCAN_ADDED_PROP_NAME, new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { Node node = (Node) evt.getNewValue(); dataTreeViewer.setSelection(new StructuredSelection(node), true); } }); rootDataNode.addPropertyChangeListener(Node.DATA_CHANGED_PROP_NAME, new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { Node node = (Node) evt.getNewValue(); if (node instanceof LineTraceProviderNode && dataTreeViewer.getChecked(node)) { updateTrace((LineTraceProviderNode) node); } } }); }
From source file:ui.frame.UILogin.java
public UILogin() { super("Login"); Label l = new Label(); setLayout(new BorderLayout()); this.setPreferredSize(new Dimension(400, 300)); Panel p = new Panel(); loginPanel = p.createPanel(Layouts.grid, 4, 2); loginPanel.setBorder(new EmptyBorder(25, 25, 0, 25)); lblUser = l.createLabel("Username:"); lblPassword = l.createLabel("Password:"); lblURL = l.createLabel("Server URL"); lblBucket = l.createLabel("Bucket"); tfURL = new JTextField(); tfURL.setText("kaiup.kaisquare.com"); tfBucket = new JTextField(); PromptSupport.setPrompt("BucketName", tfBucket); tfUser = new JTextField(); PromptSupport.setPrompt("Username", tfUser); pfPassword = new JPasswordField(); PromptSupport.setPrompt("Password", pfPassword); buttonPanel = p.createPanel(Layouts.flow); buttonPanel.setBorder(new EmptyBorder(0, 0, 25, 0)); Button b = new Button(); JButton btnLogin = b.createButton("Login"); JButton btnExit = b.createButton("Exit"); btnLogin.setPreferredSize(new Dimension(150, 50)); btnExit.setPreferredSize(new Dimension(150, 50)); Component[] arrayBtn = { btnExit, btnLogin }; p.addComponentsToPanel(buttonPanel, arrayBtn); Component[] arrayComponents = { lblURL, tfURL, lblBucket, tfBucket, lblUser, tfUser, lblPassword, pfPassword };/* ww w . java2 s. c o m*/ p.addComponentsToPanel(loginPanel, arrayComponents); add(loginPanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); pack(); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); btnLogin.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { if (tfUser.getText().equals("") || String.valueOf(pfPassword.getPassword()).equals("") || tfBucket.getText().equals("")) { JOptionPane.showMessageDialog(Data.mainFrame, "Please fill up all the fields", "Error", JOptionPane.ERROR_MESSAGE); } else { String username = tfUser.getText(); String password = String.valueOf(pfPassword.getPassword()); Data.URL = Data.protocol + tfURL.getText(); Data.targetURL = Data.protocol + tfURL.getText() + "/api/" + tfBucket.getText() + "/"; String response = api.loginBucket(Data.targetURL, username, password); try { if (DesktopAppMain.checkResult(response)) { JSONObject responseJSON = new JSONObject(response); Data.sessionKey = responseJSON.get("session-key").toString(); response = api.getUserFeatures(Data.targetURL, Data.sessionKey); if (checkFeatures(response)) { Data.mainFrame = new KAIQRFrame(); Data.mainFrame.uiInventorySelect = new UIInventorySelect(); Data.mainFrame.addPanel(Data.mainFrame.uiInventorySelect, "inventory"); Data.mainFrame.showPanel("inventory"); Data.mainFrame.pack(); setVisible(false); Data.mainFrame.setVisible(true); } else { JOptionPane.showMessageDialog(Data.loginFrame, "User does not have necessary features", "Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(Data.loginFrame, "Wrong username/password", "Error", JOptionPane.ERROR_MESSAGE); } } catch (JSONException e1) { e1.printStackTrace(); } } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Login", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Logging in .........."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); btnExit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); }
From source file:EditorPaneExample10.java
public EditorPaneExample10() { super("JEditorPane Example 10"); pane = new JEditorPane(); pane.setEditable(false); // Read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;/* w ww.java 2s. c o m*/ c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); try { // Check if the new page and the old // page are the same. URL url; if (selection instanceof URL) { url = (URL) selection; } else { url = new URL((String) selection); } URL loadedURL = pane.getPage(); if (loadedURL != null && loadedURL.sameFile(url)) { return; } // Try to display the page urlCombo.setEnabled(false); // Disable input urlCombo.paintImmediately(0, 0, urlCombo.getSize().width, urlCombo.getSize().height); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // Busy cursor loadingState.setText("Loading..."); loadingState.paintImmediately(0, 0, loadingState.getSize().width, loadingState.getSize().height); loadedType.setText(""); loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height); timeLabel.setText(""); timeLabel.paintImmediately(0, 0, timeLabel.getSize().width, timeLabel.getSize().height); startTime = System.currentTimeMillis(); // Choose the loading method if (onlineLoad.isSelected()) { // Usual load via setPage pane.setPage(url); loadedType.setText(pane.getContentType()); } else { pane.setContentType("text/html"); loadedType.setText(pane.getContentType()); if (loader == null) { loader = new HTMLDocumentLoader(); } HTMLDocument doc = loader.loadDocument(url); loadComplete(); pane.setDocument(doc); displayLoadTime(); populateCombo(findLinks(doc, null)); enableInput(); } } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", selection.toString() }, "File Open Error", JOptionPane.ERROR_MESSAGE); loadingState.setText("Failed"); enableInput(); } } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); enableInput(); } } }); }
From source file:edu.ku.brc.specify.web.HttpLargeFileTransfer.java
/** * @param infileName//from ww w . java 2 s .com * @param outFileName * @param changeListener * @return */ public boolean compressFile(final String infileName, final String outFileName, final PropertyChangeListener propChgListener) { final File file = new File(infileName); if (file.exists()) { long fileSize = file.length(); if (fileSize > 0) { SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() { protected String errorMsg = null; protected FileInputStream fis = null; protected GZIPOutputStream fos = null; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { try { Thread.sleep(100); long totalSize = file.length(); long bytesCnt = 0; FileInputStream fis = new FileInputStream(infileName); GZIPOutputStream fos = new GZIPOutputStream(new FileOutputStream(outFileName)); byte[] bytes = new byte[BUFFER_SIZE * 10]; while (true) { int len = fis.read(bytes); if (len > 0) { fos.write(bytes, 0, len); bytesCnt += len; firePropertyChange("MEGS", 0, (int) (((double) bytesCnt / (double) totalSize) * 100.0)); } else { break; } } fis.close(); fos.close(); } catch (Exception ex) { ex.printStackTrace(); errorMsg = ex.toString(); } finally { try { if (fis != null) { fis.close(); } if (fos != null) { fos.close(); } } catch (IOException ex) { errorMsg = ex.toString(); } } firePropertyChange("MEGS", 0, 100); return null; } @Override protected void done() { super.done(); UIRegistry.getStatusBar().setProgressDone(HttpLargeFileTransfer.class.toString()); //UIRegistry.clearSimpleGlassPaneMsg(); if (StringUtils.isNotEmpty(errorMsg)) { UIRegistry.showError(errorMsg); } if (propChgListener != null) { propChgListener.propertyChange( new PropertyChangeEvent(HttpLargeFileTransfer.this, "Done", 0, 1)); } } }; final JStatusBar statusBar = UIRegistry.getStatusBar(); statusBar.setIndeterminate(HttpLargeFileTransfer.class.toString(), true); UIRegistry.writeSimpleGlassPaneMsg(getLocalizedMessage("Compressing Backup..."), 24); backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if ("MEGS".equals(evt.getPropertyName())) { Integer value = (Integer) evt.getNewValue(); double val = value / 10.0; statusBar .setText(UIRegistry.getLocalizedMessage("MySQLBackupService.BACKUP_MEGS", val)); } } }); backupWorker.execute(); } else { // file doesn't exist } } else { // file doesn't exist } return false; }