public void changeLAF(int iLAFIndex) { try { // Change LAF if (iLAFIndex >= marrLaf.length) iLAFIndex = marrLaf.length - 1; UIManager.setLookAndFeel( (LookAndFeel) Class.forName(marrLaf[iLAFIndex].getClassName()).newInstance()); // Update UI ((JMenuItem) mvtLAFItem.elementAt(iLAFIndex)).setSelected(true); SwingUtilities.updateComponentTreeUI(this); SwingUtilities.updateComponentTreeUI(mnuMain); WindowManager.updateLookAndField(); // Store config try { Hashtable prt = Global.loadHashtable(Global.FILE_CONFIG); prt.put("LAF", String.valueOf(iLAFIndex)); Global.storeHashtable(prt, Global.FILE_CONFIG); } catch (Exception e) { } } catch (Exception e) { e.printStackTrace(); MessageBox.showMessageDialog(this, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE); } }
@Override public void run() { try { // initialize the statusbar status.removeAll(); JProgressBar progress = new JProgressBar(); progress.setMinimum(0); progress.setMaximum((int) f.length()); status.add(progress); status.revalidate(); // try to start reading Reader in = new FileReader(f); char[] buff = new char[4096]; int nch; while ((nch = in.read(buff, 0, buff.length)) != -1) { doc.insertString(doc.getLength(), new String(buff, 0, nch), null); progress.setValue(progress.getValue() + nch); } } catch (IOException e) { final String msg = e.getMessage(); SwingUtilities.invokeLater( new Runnable() { public void run() { JOptionPane.showMessageDialog( getFrame(), "Could not open file: " + msg, "Error opening file", JOptionPane.ERROR_MESSAGE); } }); } catch (BadLocationException e) { System.err.println(e.getMessage()); } doc.addUndoableEditListener(undoHandler); // we are done... get rid of progressbar status.removeAll(); status.revalidate(); resetUndoManager(); if (elementTreePanel != null) { SwingUtilities.invokeLater( new Runnable() { public void run() { elementTreePanel.setEditor(getEditor()); } }); } }
public void updateUI() { super.updateUI(); if (pmn != null) { SwingUtilities.updateComponentTreeUI(pmn); Skin.applySkin(pmn); } }
public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) { HyperlinkEvent.EventType type = hyperlinkEvent.getEventType(); final URL url = hyperlinkEvent.getURL(); // if (type == HyperlinkEvent.EventType.ENTERED) { // Utility.debugPrintln("patterns","Entered " + url.toString()); // } else if (type == HyperlinkEvent.EventType.EXITED) { // Utility.debugPrintln("patterns","Exited"); // } if (type == HyperlinkEvent.EventType.ACTIVATED) { // Utility.debugPrintln("Activated"); Runnable runner = new Runnable() { public void run() { // Retain reference to original Document doc = editorPane.getDocument(); try { editorPane.setPage(url); } catch (IOException ioException) { JOptionPane.showMessageDialog( frame, "Error following link " + url.toString(), "GIPO Error", JOptionPane.ERROR_MESSAGE); editorPane.setDocument(doc); } } }; SwingUtilities.invokeLater(runner); } }
/** * Shows the given error message. * * @param text the text of the error */ private void showErrorMessage(String text) { errorPane.setText(text); if (errorPane.getParent() == null) add(errorPane, BorderLayout.NORTH); SwingUtilities.getWindowAncestor(CreateSip2SipAccountForm.this).pack(); }
// Able to type stuff private void ableToType(final boolean tof) { SwingUtilities.invokeLater( new Runnable() { public void run() { userText.setEditable(tof); } }); }
public static void setStepText(final int step, final String text) { SwingUtilities.invokeLater( new Runnable() { public void run() { _stepLabels[step].setText(text); } }); }
// Update chat window private void showMessage(final String text) { SwingUtilities.invokeLater( new Runnable() { public void run() { chatWindow.append(text); } }); }
public void showCommunicationErrorDialogLater( final Exception e, final String message, final Object... args) { SwingUtilities.invokeLater( new Runnable() { public void run() { showCommunicationErrorDialog(e, message, args); } }); }
public static void main(String args[]) { // Create the frame on the event dispatching thread. SwingUtilities.invokeLater( new Runnable() { public void run() { new Slideshow(imagePaths); } }); }
public static void enableStep(final int s) { SwingUtilities.invokeLater( new Runnable() { public void run() { for (int i = 0; i < _stepLabels.length; i++) { _stepLabels[i].setEnabled(i == s); } } }); }
// For compatibility with writers when talking to the JVM. public void write(char[] buffer, int offset, int length) { String text = new String(buffer, offset, length); SwingUtilities.invokeLater( () -> { try { pane.getDocument().insertString(pane.getDocument().getLength(), text, properties); } catch (Exception e) { } }); }
/** * 弹出对话框,显示报错 * * @param message 报错信息 */ public static void errorMessage(String message) { final String final_msg = message; SwingUtilities.invokeLater( new Runnable() { @Override public void run() { JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), final_msg); } }); }
/** Invoked when the installer has failed. */ public static void installFailed(final String description, Throwable th) { Config.trace("installFailed: " + description + " " + th); if (SwingUtilities.isEventDispatchThread()) { Config.getInstallService().installFailed(); System.exit(-1); } else { try { SwingUtilities.invokeAndWait( new Runnable() { public void run() { Config.getInstallService().installFailed(); System.exit(-1); } }); } catch (java.lang.reflect.InvocationTargetException ite) { Config.trace("Unexpected exception: " + ite); } catch (InterruptedException ie) { Config.trace("Unexpected exception: " + ie); } } }
@Override @SuppressWarnings("SleepWhileHoldingLock") public void run() { try { // initialize the statusbar status.removeAll(); JProgressBar progress = new JProgressBar(); progress.setMinimum(0); progress.setMaximum(doc.getLength()); status.add(progress); status.revalidate(); // start writing Writer out = new FileWriter(f); Segment text = new Segment(); text.setPartialReturn(true); int charsLeft = doc.getLength(); int offset = 0; while (charsLeft > 0) { doc.getText(offset, Math.min(4096, charsLeft), text); out.write(text.array, text.offset, text.count); charsLeft -= text.count; offset += text.count; progress.setValue(offset); try { Thread.sleep(10); } catch (InterruptedException e) { Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, e); } } out.flush(); out.close(); } catch (IOException e) { final String msg = e.getMessage(); SwingUtilities.invokeLater( new Runnable() { public void run() { JOptionPane.showMessageDialog( getFrame(), "Could not save file: " + msg, "Error saving file", JOptionPane.ERROR_MESSAGE); } }); } catch (BadLocationException e) { System.err.println(e.getMessage()); } // we are done... get rid of progressbar status.removeAll(); status.revalidate(); }
public void processMessage(DataInputStream dataIn) throws IOException { count = 0; int msgsize = dataIn.readInt(); count = 1; int msgtype = 0; if (msgsize >= 2) msgtype = dataIn.readUnsignedShort(); else { if (msgsize == 1) dataIn.readByte(); ExpCoordinator.printer.print( new String("ERROR:NCCPConnection.run msgsize(" + msgsize + ") < 2 msgtype = " + msgtype)); ExpCoordinator.printer.printHistory(); return; } count = 2; switch (msgtype) { case NCCP.MessageResponse: ExpCoordinator.print( new String( "NCCPConnection::run message is NCCP.MessageResponse " + msgsize + " " + msgtype), 3); MessageRunnable tmp_msg = new MessageRunnable(msgsize, msgtype, dataIn); tmp_msg.print(5); SwingUtilities.invokeLater(tmp_msg); break; case NCCP.MessagePeriodic: ExpCoordinator.printer.print( new String( "NCCPConnection::run message is NCCP.MessagePeriodic " + msgsize + " " + msgtype), 3); processPeriodicMsg(msgsize, msgtype, dataIn); break; default: ExpCoordinator.printer.print( new String("NCCPConnection::run message is Other " + msgsize + " " + msgtype)); SwingUtilities.invokeLater(new MessageRunnable(msgsize, msgtype, dataIn)); } }
public void actionPerformed(ActionEvent event) { Window window; String msg; if (model.isZoomUndoStackEmpty()) { window = SwingUtilities.windowForComponent((JToolBar) toolbar); msg = "Zoom Undo Stack is empty"; Dialogs.warn(window, msg); } else model.zoomUndo(); // Set toolbar buttons to reflect status if (toolbar != null) toolbar.resetZoomButtons(); if (Debug.isActive()) Debug.println("Action for Zoom Undo button."); }
public static void main(String[] args) { SwingUtilities.invokeLater( new Runnable() { public void run() { JFrame f = new JFrame("SVGDraw Applet"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SVGApplet a = new SVGApplet(); f.getContentPane().add(a); a.init(); f.setSize(500, 300); f.setVisible(true); a.start(); } }); }
// The thread-safe way to change the GUI components while // changing state private static void changeStatusTS(int newConnectStatus, boolean noError) { // Change state if valid state if (newConnectStatus != NULL) { connectionStatus = newConnectStatus; } // If there is no error, display the appropriate status message if (noError) { statusString = statusMessages[connectionStatus]; } // Otherwise, display error message else { statusString = statusMessages[NULL]; } // Call the run() routine (Runnable interface) on the // error-handling and GUI-update thread SwingUtilities.invokeLater(tcpObj); }
// {{{ handleClient() method private boolean handleClient(final Socket client, DataInputStream in) throws Exception { int key = in.readInt(); if (key != authKey) { Log.log( Log.ERROR, this, client + ": wrong" + " authorization key (got " + key + ", expected " + authKey + ")"); in.close(); client.close(); return false; } else { // Reset the timeout client.setSoTimeout(0); Log.log(Log.DEBUG, this, client + ": authenticated" + " successfully"); final String script = in.readUTF(); Log.log(Log.DEBUG, this, script); SwingUtilities.invokeLater( new Runnable() { public void run() { try { NameSpace ns = new NameSpace(BeanShell.getNameSpace(), "EditServer namespace"); ns.setVariable("socket", client); BeanShell.eval(null, ns, script); } catch (org.gjt.sp.jedit.bsh.UtilEvalError e) { Log.log(Log.ERROR, this, e); } finally { try { BeanShell.getNameSpace().setVariable("socket", null); } catch (org.gjt.sp.jedit.bsh.UtilEvalError e) { Log.log(Log.ERROR, this, e); } } } }); return true; } } // }}}
/** Invoked when the install finishes. */ public static void finishedInstall(final String execPath) { // Use a runnable as more than likely we've queued up a bunch of // Runnables try { SwingUtilities.invokeAndWait( new Runnable() { public void run() { // do nothing } }); } catch (java.lang.reflect.InvocationTargetException ite) { Config.trace("Unexpected exception: " + ite); } catch (InterruptedException ie) { Config.trace("Unexpected exception: " + ie); } String platformVersion = Config.getPlatformVersion(); Config.getInstallService().setJREInfo(platformVersion, execPath); Config.getInstallService() .installSucceeded(Config.isWindowsInstall() && WindowsInstaller.IsRebootNecessary()); }
/** * 当前的报表运行环境切换到env * * @param env 需要切换去的环境 */ public static void switchToEnv(Env env) { if (env == null) { return; } Env oldEnv = FRContext.getCurrentEnv(); String oldEnvPath = oldEnv == null ? null : oldEnv.getPath(); // 看一下这个env在DesignerEnvManager里面有没有对应的,有的话就setCurrentEnvName DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); java.util.Iterator<String> nameIt = envManager.getEnvNameIterator(); while (nameIt.hasNext()) { String name = nameIt.next(); if (ComparatorUtils.equals(envManager.getEnv(name), env)) { envManager.setCurEnvName(name); break; } } // 更新CurrentEnv于FRContext & DesignerEnvManager FRContext.setCurrentEnv(env); final Env run_env = env; // 刷新DesignerFrame里面的面板 SwingUtilities.invokeLater( new Runnable() { public void run() { if (DesignerContext.getDesignerFrame() == null) { return; } DesignerContext.getDesignerFrame().refreshEnv(run_env); DesignerContext.getDesignerFrame().repaint(); // kunsnat: 切换环境后 刷新下 报表. 比如图表某些风格改变. } }); // 当换了运行环境,重置服务器,让它下次预览时重启 if (env instanceof LocalEnv && !ComparatorUtils.equals(env.getPath(), oldEnvPath)) { StartServer.currentEnvChanged(); } }
public void start(String appConfigurationLocation, Dimension appSize) throws Exception { this.appTitle = Configuration.getStringValue(Constants.APPLICATION_DISPLAY_NAME); this.appSize = appSize; this.unitsFormat = new WWOUnitsFormat(); this.unitsFormat.setShowUTM(true); this.unitsFormat.setShowWGS84(true); this.appConfigurationLocation = appConfigurationLocation; final AppConfiguration appConfig = new AppConfiguration(); appConfig.initialize(this); appConfig.configure(this.appConfigurationLocation); SwingUtilities.invokeLater( new Runnable() { public void run() { redraw(); } }); }
public static void main(String[] args) throws Exception { if (args.length > 0 && args[0].equals(EXIT_AFTER_PAINT)) { exitAfterFirstPaint = true; } SwingUtilities.invokeAndWait( new Runnable() { public void run() { JFrame frame = new JFrame(); frame.setTitle(resources.getString("Title")); frame.setBackground(Color.lightGray); frame.getContentPane().setLayout(new BorderLayout()); Notepad notepad = new Notepad(); frame.getContentPane().add("Center", notepad); frame.setJMenuBar(notepad.createMenubar()); frame.addWindowListener(new AppCloser()); frame.pack(); frame.setSize(500, 600); frame.setVisible(true); } }); }
public void valueChanged(final long bid) { super.valueChanged(bid); SwingUtilities.invokeLater( new Runnable() { public void run() { try { for (Iterator it = components.iterator(); it.hasNext(); ) { JCMAdmin cmAdmin = (JCMAdmin) it.next(); Bundle[] bl = bc.getBundles(); for (int i = 0; i < bl.length; i++) { if (bundleSelModel.isSelected(bl[i].getBundleId())) { cmAdmin.setBundle(bl[i]); } } } } catch (Exception e) { e.printStackTrace(); } } }); }
public void run() { while (connected) { try { Object obj = in.readObject(); if (obj.toString().equals("-101")) { connected = false; in.close(); out.close(); socket.close(); SwingUtilities.invokeLater( new Runnable() { public void run() { Cashier.closee = true; JOptionPane.showMessageDialog( null, "Disconnected from server. Please Restart", "Error:", JOptionPane.PLAIN_MESSAGE); try { m.stop(); } catch (Exception w) { } } }); } else if (obj.toString().split("::")[0].equals("broadcast")) { // System.out.println("braodcast received"); bc.run(obj.toString().substring(obj.toString().indexOf("::") + 2)); } else if (obj.toString().split("::")[0].equals("chat")) { // System.out.println("chat received: // "+obj.toString().substring(obj.toString().indexOf("::")+2)); cc.run(obj.toString().substring(obj.toString().indexOf("::") + 2)); } else if (obj.toString().split("::")[0].equals("rankings")) { String hhh = obj.toString().split("::")[1]; final JDialog jd = new JDialog(); jd.setUndecorated(false); JPanel pan = new JPanel(new BorderLayout()); JLabel ppp = new JLabel(); ppp.setFont(new Font("Arial", Font.BOLD, 20)); ppp.setText( "<html><pre>Thanks for playing !!!<br/>1st: " + hhh.split(":")[0] + "<br/>2nd: " + hhh.split(":")[1] + "<br/>3rd: " + hhh.split(":")[2] + "</pre></html>"); pan.add(ppp, BorderLayout.CENTER); JButton ok = new JButton("Ok"); ok.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { jd.setVisible(false); try { m.stop(); } catch (Exception w) { } } }); pan.add(ok, BorderLayout.SOUTH); jd.setContentPane(pan); jd.setModalityType(JDialog.ModalityType.APPLICATION_MODAL); jd.pack(); jd.setLocationRelativeTo(null); jd.setVisible(true); } else if (obj.toString().split("::")[0].equals("rank")) { rc.run(obj.toString().substring(obj.toString().indexOf("::") + 2)); } else { User hhh = null; try { hhh = (User) obj; /*if(usrD==1) { reply=obj; ccl.interrupt(); } else*/ { try { m.ur.changeData((User) obj); } catch (Exception w) { try { maain.ur.changeData((User) obj); } catch (Exception ppp) { ppp.printStackTrace(); } } } } catch (Exception p) { int iid = -1; try { iid = Integer.parseInt(obj.toString()); obj = in.readObject(); if (obj.toString().equals("-102")) { // ccl.interrupt(); SwingUtilities.invokeLater( new Runnable() { public void run() { Cashier.closee = true; JOptionPane.showMessageDialog( null, "Server Not Running.", "Error:", JOptionPane.PLAIN_MESSAGE); } }); } // Thread th = ((Thread)rev.remove(iid)); rev2.put(iid, obj); // System.out.println("Put: "+iid+" : "+obj.toString()+" : // "+Thread.currentThread()); // th.interrupt(); // ccl.interrupt(); } catch (Exception ppp) { /*ppp.printStackTrace();*/ System.out.println( "Shit: " + iid + " : " + obj.toString() + " : " + Thread.currentThread()); } } } try { Thread.sleep(500); } catch (Exception n) { } } catch (Exception m) { } } }
public void login() { mbAutoLogIn = false; while (!mbAutoLogIn) { try { // Confirm logout if (isOpen()) { if (MessageBox.showConfirmDialog( this, MonitorDictionary.getString("Confirm.Exit"), Global.APP_NAME, MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION) return; // Disconnect from server disconnect(); } // Login DialogLogin dlgLogin = new DialogLogin(this); WindowManager.centeredWindow(dlgLogin); if (dlgLogin.miReturn == JOptionPane.OK_OPTION) { // Update UI SwingUtilities.updateComponentTreeUI(pnlUser); SwingUtilities.updateComponentTreeUI(pnlThread); // Request to connect Socket sck = new Socket(dlgLogin.mstrHost, Integer.parseInt(dlgLogin.mstrPort)); sck.setSoLinger(true, 0); // Start up a channel thread that reads messages from the server channel = new SocketTransmitter(sck) { public void close() { if (msckMain != null) { super.close(); closeAll(); if (mbAutoLogIn) login(); } } }; channel.setUserName(dlgLogin.mstrUserName); channel.setPackage("com.fss.thread."); channel.start(); // Request to Server DDTP request = new DDTP(); request.setRequestID(String.valueOf(System.currentTimeMillis())); request.setString("UserName", dlgLogin.mstrUserName); request.setString("Password", dlgLogin.mstrPassword); // Response from Server DDTP response = channel.sendRequest("ThreadProcessor", "login", request); mstrThreadAppName = response.getString("strThreadAppName"); mstrThreadAppVersion = response.getString("strThreadAppVersion"); mstrAppName = response.getString("strAppName"); mstrAppVersion = response.getString("strAppVersion"); if (response != null) { if (response.getString("PasswordExpired") != null) { DialogChangePassword frm = new DialogChangePassword(this, channel); WindowManager.centeredWindow(frm); if (frm.miReturnValue != JOptionPane.OK_OPTION) throw new AppException("FSS-10003"); } String strLog = StringUtil.nvl(response.getString("strLog"), ""); showResult(txtBoard, strLog); Vector vtThread = response.getVector("vtThread"); updateTabBar(vtThread); mstrChannel = response.getString("strChannel"); if (mstrChannel != null) removeUser(mstrChannel); } btnRefresh.doClick(); pnlThread.setVisible(true); pnlUser.setVisible(true); setResizeWeight(1); setDividerLocation((int) (getSize().getHeight() - 160)); } mbAutoLogIn = true; updateLanguage(); } catch (Exception e) { e.printStackTrace(); MessageBox.showMessageDialog(this, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE); // Disconnect from server mstrChannel = null; disconnect(); } } }