public DatabaseTab(final UISubsystem ui) throws Exception { init(ui.getRl(), ui.getRl().getResourceStream("xui/optionstabs/databasetab.xui.xml")); this.ui = ui; Language.translateXUIElements(getClass(), xui.getXUIComponents()); SubstanceThemeHelper.setButtonsToGeneralArea(xui.getXUIComponents()); tab = (JPanel) xui.getComponent("databasetab"); tab.setName(Language.getLocalizedString(getClass(), "title")); tab.setToolTipText(Language.getLocalizedString(getClass(), "tooltip")); }
public WelcomeMDIWindow(UISubsystem ui) throws Exception { super(ui.getMainWindow().getMDIManager(), "welcome", ui); this.ui = ui; Language.translateXUIElements(getClass(), xui.getXUIComponents()); BufferedReader r = new BufferedReader(new InputStreamReader(ui.getRl().getResourceStream("welcome.html"))); StringBuffer data = new StringBuffer(); String line = null; while ((line = r.readLine()) != null) { data.append(line); } setTitle(Language.getLocalizedString(getClass(), "title")); label = (JHtmlLabel) xui.getComponent("label"); label.setText(data.toString()); postInit(); }
private void unloadUI() { try { if (ui == null) { if (T.t) { T.info("Subsystem already unloaded."); } return; } if (tray != null && ti != null) { ti.displayMessage( "", Language.getLocalizedString(getClass(), "unloading"), TrayIcon.MessageType.NONE); balloonClickHandler = null; } core.restartProgram(false); } catch (Exception t) { core.reportError(t, this); } }
@Override public synchronized void shutdown() { if (tray != null && ti != null) { ti.displayMessage( "", Language.getLocalizedString(getClass(), "shutting"), TrayIcon.MessageType.NONE); balloonClickHandler = null; } if (ui != null) { ui.shutdown(); ui = null; } if (core != null) { core.shutdown(); core = null; } if (tray != null) { tray.remove(ti); } System.exit(0); }
public void EVENT_browse(ActionEvent e) throws Exception { JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setAcceptAllFileFilterUsed(false); fc.addChoosableFileFilter( new FileFilter() { @Override public boolean accept(File pathname) { if ((pathname.toString().contains("alliance-script-") && pathname.toString().endsWith(".zip")) || pathname.isDirectory()) { return true; } else { return false; } } @Override public String getDescription() { return ("DB Script"); } }); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { String path = fc.getSelectedFile().getPath(); ui.getCore() .getFileManager() .getDbCore() .connect(ui.getCore().getFileManager().prepareToRestore(path)); ui.getCore().getFileManager().getFileDatabase().updateCacheCounters(); OptionDialog.showInformationDialog( this, Language.getLocalizedString(getClass(), "restoreok")); } }
private void initTray() throws Exception { tray = SystemTray.getSystemTray(); PopupMenu m = new PopupMenu(); Font f = new Font("Tahoma", 0, 11); m.setFont(f); MenuItem mi = new MenuItem(Language.getLocalizedString(getClass(), "menuopen")); mi.setFont(f); mi.setFont( new Font( mi.getFont().getName(), mi.getFont().getStyle() | Font.BOLD, mi.getFont().getSize())); mi.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openUI(); } }); m.add(mi); m.addSeparator(); mi = new MenuItem(Language.getLocalizedString(getClass(), "menuunload")); mi.setFont(f); mi.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { unloadUI(); } }); m.add(mi); m.addSeparator(); mi = new MenuItem(Language.getLocalizedString(getClass(), "menuexit")); mi.setFont(f); mi.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { shutdown(); } }); m.add(mi); Toolkit.getDefaultToolkit().getSystemEventQueue().push(new PopupFixQueue(m)); int[] imageSizes = {16, 24, 32, 48, 64, 128}; for (int size : imageSizes) { if (size - tray.getTrayIconSize().getWidth() < 0) { continue; } else { ti = new TrayIcon( Toolkit.getDefaultToolkit() .getImage(rl.getResource("gfx/icons/alliance" + size + ".png")), "Alliance", m); break; } } ti.setImageAutoSize(true); ti.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openUI(); } }); tray.add(ti); ti.addActionListener( new ActionListener() { private long lastClickAt; @Override public void actionPerformed(ActionEvent e) { if (System.currentTimeMillis() - lastClickAt < 1000) { openUI(); } lastClickAt = System.currentTimeMillis(); } }); // Update tooltip periodically with current transfer rates Thread t = new Thread( new Runnable() { @Override public void run() { try { while (true) { ti.setToolTip( "Alliance v" + Version.VERSION + " build " + Version.BUILD_NUMBER + "\nDownload: " + core.getNetworkManager().getBandwidthIn().getCPSHumanReadable() + "\nUpload: " + core.getNetworkManager().getBandwidthOut().getCPSHumanReadable() + "\nOnline: " + core.getFriendManager().getNFriendsConnected() + "/" + core.getFriendManager().getNFriends() + " (" + TextUtils.formatByteSize( core.getFriendManager().getTotalBytesShared()) + ")"); Thread.sleep(5000); } } catch (InterruptedException e) { } catch (NullPointerException e) { } } }); t.setDaemon(true); t.start(); }
public DatabaseTab(String loading) { tab = new JPanel(); tab.add(new JLabel(loading)); tab.setName(Language.getLocalizedString(getClass(), "title")); tab.setToolTipText(Language.getLocalizedString(getClass(), "tooltip")); }
private void init( String title, String message, int dialogType, int buttonType, boolean customTitle) throws Exception { if (customTitle) { setTitle(title); } else { setTitle(Language.getLocalizedString(getClass(), title)); } setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, 0)); this.keyListener = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { String event = OptionDialog.this.eventKeyMap.get(Character.valueOf(e.getKeyChar())); if (event != null) { OptionDialog.this.actionPerformed(new ActionEvent(e.getSource(), e.getID(), event)); } } }; panel.addKeyListener(this.keyListener); if (imageIcons != null) { JLabel l = new JLabel(imageIcons[dialogType]); l.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); panel.add(l); panel.add(Box.createVerticalStrut(5)); } JHtmlLabel l = new JHtmlLabel() { @Override public Dimension getPreferredSize() { return new Dimension(400, super.getPreferredSize().height); } }; l.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); message = message.replace('[', '<'); message = message.replace(']', '>'); message = message.replaceAll("\r\n", "<br>"); message = message.replaceAll("\r", "<br>"); message = message.replaceAll("\n", "<br>"); l.setText(message); panel.add(l); add(panel, "Center"); panel = new JPanel(); panel.setLayout(new FlowLayout(1, 5, 5)); switch (buttonType) { case 0: panel.add(createButton(Language.getLocalizedString(getClass(), "ok"), "ok", "o", true)); break; case 1: panel.add(createButton(Language.getLocalizedString(getClass(), "yes"), "yes", "y", true)); panel.add(createButton(Language.getLocalizedString(getClass(), "no"), "no", "n", false)); break; case 2: panel.add(createButton(Language.getLocalizedString(getClass(), "yes"), "yes", "y", true)); panel.add(createButton(Language.getLocalizedString(getClass(), "no"), "no", "n", false)); panel.add( createButton(Language.getLocalizedString(getClass(), "cancel"), "cancel", "c", false)); break; case 3: panel.add(createButton(Language.getLocalizedString(getClass(), "ok"), "ok", "o", true)); panel.add( createButton(Language.getLocalizedString(getClass(), "cancel"), "cancel", "c", false)); } add(panel, "South"); setResizable(false); }