Search in sources :

Example 6 with ConfigurationManager

use of com.biglybt.core.config.impl.ConfigurationManager in project BiglyBT by BiglySoftware.

the class PluginConfigSourceImpl method initialize.

@Override
public void initialize() {
    shouldBeInitialised(false);
    this.initialised = true;
    this.data_map = FileUtil.readResilientFile(this.source_file.getParentFile(), this.source_file.getName(), true);
    this.key_prefix = plugin_config.getPluginConfigKeyPrefix();
    Map.Entry entry;
    String key;
    Iterator itr = this.data_map.entrySet().iterator();
    ConfigurationManager config = ConfigurationManager.getInstance();
    while (itr.hasNext()) {
        entry = (Map.Entry) itr.next();
        key = this.key_prefix + (String) entry.getKey();
        this.params_monitored.add(key);
        config.registerTransientParameter(key);
        config.setParameterRawNoNotify(key, entry.getValue());
        config.addParameterListener(key, this);
    }
    config.addListener(this);
}
Also used : Iterator(java.util.Iterator) Map(java.util.Map) ConfigurationManager(com.biglybt.core.config.impl.ConfigurationManager) COConfigurationManager(com.biglybt.core.config.COConfigurationManager)

Example 7 with ConfigurationManager

use of com.biglybt.core.config.impl.ConfigurationManager in project BiglyBT by BiglySoftware.

the class TabbedMDI method minimize.

private void minimize() {
    minimized = true;
    tabFolder.setMinimized(true);
    CTabItem[] items = tabFolder.getItems();
    String tt = MessageText.getString("label.click.to.restore");
    for (int i = 0; i < items.length; i++) {
        CTabItem tabItem = items[i];
        tabItem.setToolTipText(tt);
        Control control = tabItem.getControl();
        if (control != null && !control.isDisposed()) {
            tabItem.getControl().setVisible(false);
        }
    }
    tabFolder.getParent().notifyListeners(SWT.Resize, null);
    showEntry(null);
    ConfigurationManager configMan = ConfigurationManager.getInstance();
    configMan.setParameter(props_prefix + ".subViews.minimized", true);
}
Also used : COConfigurationManager(com.biglybt.core.config.COConfigurationManager) ConfigurationManager(com.biglybt.core.config.impl.ConfigurationManager)

Example 8 with ConfigurationManager

use of com.biglybt.core.config.impl.ConfigurationManager in project BiglyBT by BiglySoftware.

the class TabbedMDI method restore.

private void restore() {
    minimized = false;
    tabFolder.setMinimized(false);
    CTabItem selection = tabFolder.getSelection();
    if (selection != null) {
        TabbedEntry tabbedEntry = getEntryFromTabItem(selection);
        showEntry(tabbedEntry);
        /* Already done by TabbedEntry.swt_build
			Control control = selection.getControl();
			if (control == null || control.isDisposed()) {
				selectedView.initialize(tabFolder);
				selection.setControl(selectedView.getComposite());
				control = selection.getControl();
				triggerTabViewDataSourceChanged(selectedView, tv, new Object[][] {
					null,
					null
				});
			}
			selection.getControl().setVisible(true);
			*/
        tabbedEntry.updateUI();
    }
    if (tabFolder.getMaximizeVisible()) {
        CTabItem[] items = tabFolder.getItems();
        String tt = MessageText.getString("label.dblclick.to.min");
        for (int i = 0; i < items.length; i++) {
            CTabItem tabItem = items[i];
            tabItem.setToolTipText(tt);
        }
    }
    tabFolder.getParent().notifyListeners(SWT.Resize, null);
    ConfigurationManager configMan = ConfigurationManager.getInstance();
    configMan.setParameter(props_prefix + ".subViews.minimized", false);
}
Also used : COConfigurationManager(com.biglybt.core.config.COConfigurationManager) ConfigurationManager(com.biglybt.core.config.impl.ConfigurationManager)

Example 9 with ConfigurationManager

use of com.biglybt.core.config.impl.ConfigurationManager in project BiglyBT by BiglySoftware.

the class FileLogging method checkLoggingConfig.

void checkLoggingConfig() {
    try {
        // Shorten from COConfigurationManager To make code more readable
        final ConfigurationManager config = ConfigurationManager.getInstance();
        String timeStampFormat;
        boolean overrideLog = System.getProperty(SystemProperties.SYSPROP_OVERRIDELOG) != null;
        if (overrideLog) {
            // Don't set this - reloadLogToFileParam will do it.
            // bLogToFile = true;
            sLogDir = System.getProperty(SystemProperties.SYSPROP_OVERRIDELOGDIR, ".");
            iLogFileMaxMB = 2;
            timeStampFormat = "HH:mm:ss.SSS ";
            for (int i = 0; i < ignoredComponents.length; i++) {
                ignoredComponents[i].clear();
            }
            reloadLogToFileParam();
        } else {
            reloadLogToFileParam();
            sLogDir = config.getStringParameter("Logging Dir", "");
            iLogFileMaxMB = config.getIntParameter("Logging Max Size");
            timeStampFormat = config.getStringParameter("Logging Timestamp") + " ";
            for (int i = 0; i < ignoredComponents.length; i++) {
                ignoredComponents[i].clear();
                int logType = indexToLogType(i);
                for (int j = 0; j < configurableLOGIDs.length; j++) {
                    if (!config.getBooleanParameter("bLog." + logType + "." + configurableLOGIDs[j], true))
                        ignoredComponents[i].add(configurableLOGIDs[j]);
                }
            }
        }
        synchronized (Logger.class) {
            // Create the date format first *before* we do checkAndSwapLog,
            // just in case we end up invoking logToFile...
            format = new SimpleDateFormat(timeStampFormat);
            checkAndSwapLog();
        }
    } catch (Throwable t) {
        Debug.printStackTrace(t);
    }
}
Also used : ConfigurationManager(com.biglybt.core.config.impl.ConfigurationManager) SimpleDateFormat(java.text.SimpleDateFormat)

Example 10 with ConfigurationManager

use of com.biglybt.core.config.impl.ConfigurationManager in project BiglyBT by BiglySoftware.

the class Legend method createLegendComposite.

public static Composite createLegendComposite(final Composite panel, final Color[] blockColors, final String[] keys, final String[] key_texts, Object layoutData, boolean horizontal, final LegendListener listener) {
    final ConfigurationManager config = ConfigurationManager.getInstance();
    if (blockColors.length != keys.length)
        return null;
    final Color[] defaultColors = new Color[blockColors.length];
    final ParameterListener[] paramListeners = new ParameterListener[keys.length];
    System.arraycopy(blockColors, 0, defaultColors, 0, blockColors.length);
    Composite legend = new Composite(panel, SWT.NONE);
    if (layoutData != null)
        legend.setLayoutData(layoutData);
    RowLayout layout = new RowLayout(horizontal ? SWT.HORIZONTAL : SWT.VERTICAL);
    layout.wrap = true;
    layout.marginBottom = 0;
    layout.marginTop = 0;
    layout.marginLeft = 0;
    layout.marginRight = 0;
    layout.spacing = 0;
    legend.setLayout(layout);
    RowData data;
    final int[] hover_state = { -1, 0 };
    for (int i = 0; i < blockColors.length; i++) {
        int r = config.getIntParameter(keys[i] + ".red", -1);
        if (r >= 0) {
            int g = config.getIntParameter(keys[i] + ".green");
            int b = config.getIntParameter(keys[i] + ".blue");
            Color color = ColorCache.getColor(panel.getDisplay(), r, g, b);
            blockColors[i] = color;
        }
        Composite colorSet = new Composite(legend, SWT.NONE);
        Utils.setLayout(colorSet, new RowLayout(SWT.HORIZONTAL));
        final Canvas cColor = new Canvas(colorSet, SWT.BORDER);
        cColor.setData("Index", new Integer(i));
        Messages.setLanguageTooltip(cColor, "label.click.to.change.tooltip");
        // XXX Use paint instead of setBackgrond, because OSX does translucent
        // crap
        cColor.addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                int i = ((Integer) cColor.getData("Index")).intValue();
                e.gc.setBackground(blockColors[i]);
                e.gc.fillRectangle(e.x, e.y, e.width, e.height);
            }
        });
        cColor.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseUp(MouseEvent e) {
                Integer iIndex = (Integer) cColor.getData("Index");
                if (iIndex == null)
                    return;
                int index = iIndex.intValue();
                if (e.button == 1) {
                    RGB rgb = Utils.showColorDialog(panel, blockColors[index].getRGB());
                    if (rgb != null) {
                        config.setRGBParameter(keys[index], rgb.red, rgb.green, rgb.blue);
                    }
                } else {
                    config.removeRGBParameter(keys[index]);
                }
            }
        });
        final Label lblDesc = new Label(colorSet, SWT.NULL);
        if (key_texts == null) {
            Messages.setLanguageText(lblDesc, keys[i]);
        } else {
            lblDesc.setText(key_texts[i]);
        }
        if (listener != null) {
            Messages.setLanguageTooltip(lblDesc, "label.click.to.showhide.tooltip");
            final int f_i = i;
            lblDesc.addMouseListener(new MouseAdapter() {

                @Override
                public void mouseUp(MouseEvent e) {
                    boolean vis = !config.getBooleanParameter(keys[f_i] + ".vis", true);
                    config.setParameter(keys[f_i] + ".vis", vis);
                    listener.visibilityChange(vis, f_i);
                    lblDesc.setForeground(vis ? Colors.getSystemColor(lblDesc.getDisplay(), SWT.COLOR_BLACK) : Colors.grey);
                }
            });
            boolean vis = config.getBooleanParameter(keys[f_i] + ".vis", true);
            if (!vis) {
                listener.visibilityChange(vis, i);
                lblDesc.setForeground(Colors.grey);
            }
        }
        data = new RowData();
        data.width = 20;
        data.height = lblDesc.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 3;
        cColor.setLayoutData(data);
        // If color changes, update our legend
        config.addParameterListener(keys[i], paramListeners[i] = new ParameterListener() {

            @Override
            public void parameterChanged(String parameterName) {
                for (int j = 0; j < keys.length; j++) {
                    if (keys[j].equals(parameterName)) {
                        final int index = j;
                        final int r = config.getIntParameter(keys[j] + ".red", -1);
                        if (r >= 0) {
                            final int g = config.getIntParameter(keys[j] + ".green");
                            final int b = config.getIntParameter(keys[j] + ".blue");
                            Utils.execSWTThread(new AERunnable() {

                                @Override
                                public void runSupport() {
                                    if (panel == null || panel.isDisposed())
                                        return;
                                    Color color = ColorCache.getColor(panel.getDisplay(), r, g, b);
                                    blockColors[index] = color;
                                    cColor.redraw();
                                }
                            });
                        } else {
                            Utils.execSWTThread(new AERunnable() {

                                @Override
                                public void runSupport() {
                                    if (panel == null || panel.isDisposed())
                                        return;
                                    blockColors[index] = defaultColors[index];
                                    cColor.redraw();
                                }
                            });
                        }
                    }
                }
            }
        });
        if (listener != null) {
            final int f_i = i;
            Control[] controls = { colorSet, cColor, lblDesc };
            MouseTrackListener ml = new MouseTrackListener() {

                @Override
                public void mouseEnter(MouseEvent e) {
                    handleHover(listener, true, f_i, hover_state);
                }

                @Override
                public void mouseExit(MouseEvent e) {
                    handleHover(listener, false, f_i, hover_state);
                }

                @Override
                public void mouseHover(MouseEvent e) {
                }
            };
            for (Control c : controls) {
                c.addMouseTrackListener(ml);
            }
        }
    }
    legend.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            // We don't want to give them disposed colors
            // Restore defaults in case blockColors is a static or is used
            // afterwards, or if the view wants to dispose of the old colors.
            System.arraycopy(defaultColors, 0, blockColors, 0, blockColors.length);
            for (int i = 0; i < keys.length; i++) config.removeParameterListener(keys[i], paramListeners[i]);
        }
    });
    return legend;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) Label(org.eclipse.swt.widgets.Label) RowData(org.eclipse.swt.layout.RowData) Control(org.eclipse.swt.widgets.Control) RowLayout(org.eclipse.swt.layout.RowLayout) ConfigurationManager(com.biglybt.core.config.impl.ConfigurationManager) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) Canvas(org.eclipse.swt.widgets.Canvas) RGB(org.eclipse.swt.graphics.RGB) ParameterListener(com.biglybt.core.config.ParameterListener)

Aggregations

ConfigurationManager (com.biglybt.core.config.impl.ConfigurationManager)10 COConfigurationManager (com.biglybt.core.config.COConfigurationManager)5 ParameterListener (com.biglybt.core.config.ParameterListener)3 Composite (org.eclipse.swt.widgets.Composite)2 COConfigurationListener (com.biglybt.core.config.COConfigurationListener)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 AERunnable (com.biglybt.core.util.AERunnable)1 UIFunctions (com.biglybt.ui.UIFunctions)1 TableView (com.biglybt.ui.common.table.TableView)1 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)1 TabbedMdiMaximizeListener (com.biglybt.ui.swt.mdi.TabbedMdiMaximizeListener)1 UISWTInstance (com.biglybt.ui.swt.pif.UISWTInstance)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Color (org.eclipse.swt.graphics.Color)1 RGB (org.eclipse.swt.graphics.RGB)1