Example usage for java.beans PropertyChangeEvent getNewValue

List of usage examples for java.beans PropertyChangeEvent getNewValue

Introduction

In this page you can find the example usage for java.beans PropertyChangeEvent getNewValue.

Prototype

public Object getNewValue() 

Source Link

Document

Gets the new value for the property, expressed as an Object.

Usage

From source file:edu.ku.brc.specify.tasks.subpane.VisualQueryPanel.java

/**
 * @throws IOException //  ww w  .  j a  v a2 s. com
 * 
 */
private void doSearch() throws IOException {
    final String CNT = "CNT";

    UIFieldFormatterIFace fieldFmt = null;
    if (typeCBX.getSelectedIndex() == 0) {
        fieldFmt = DBTableIdMgr.getFieldFormatterFor(CollectionObject.class, "catalogNumber");
    }

    final StringBuilder pmStr = new StringBuilder();
    final String placeMark = " <Placemark><name>%s - %d / %d</name><Point><coordinates>%8.5f, %8.5f, 5</coordinates></Point></Placemark>\n";

    polySB.setLength(0);
    boxSB.setLength(0);

    final JStatusBar statusBar = UIRegistry.getStatusBar();
    final UIFieldFormatterIFace fldFmt = fieldFmt;
    SwingWorker<Integer, Integer> worker = new SwingWorker<Integer, Integer>() {
        @Override
        protected Integer doInBackground() throws Exception {
            // fills pntList from polyline
            // polyline was filled via clicks on WorldWind
            totalNumRecords = BasicSQLUtils.getCountAsInt(buildSQL(true));

            availPoints.clear();
            model = (DefaultListModel) dbObjList.getModel();
            model.removeAllElements();
            topIdHash.clear();

            markers.clear();

            polygon = new Polyline(polyline.getPositions());
            polygon.setClosed(true);

            for (Position p : polyline.getPositions()) {
                polySB.append(String.format("    %8.5f, %8.5f, 20\n", p.longitude.degrees, p.latitude.degrees));
            }

            int maxThreshold = 1000;
            int index = 0;
            Connection conn = null;
            Statement stmt = null;
            try {
                conn = DBConnection.getInstance().createConnection();
                stmt = conn.createStatement();

                int currCnt = 0;
                ResultSet rs = stmt.executeQuery(buildSQL(false));
                while (rs.next()) {
                    if (currCnt < maxThreshold) {
                        double lat = rs.getBigDecimal(2).doubleValue();
                        double lon = rs.getBigDecimal(3).doubleValue();

                        Position pos = Position.fromDegrees(lat, lon, 0.0);
                        // ZZZ                            
                        //                            if (GeometryMath.isLocationInside(pos, polygon.getPositions()))
                        //                            {
                        //                                LatLonPoint llp = new LatLonPoint(rs.getInt(1), lat, lon);
                        //                                String title = rs.getString(4);
                        //                                if (title != null)
                        //                                {
                        //                                    title = (fldFmt != null ? fldFmt.formatToUI(title) :title).toString();
                        //                                } else
                        //                                {
                        //                                    title = "N/A";
                        //                                }
                        //                                llp.setTitle(title);
                        //                                llp.setIndex(index++);
                        //                                availPoints.add(llp);
                        //                                markers.add(llp);
                        //                                topIdHash.add(llp.getLocId());
                        //                                System.out.println(index+" / "+currCnt+" In:      "+lat+",  "+lon);
                        //                                pmStr.append(String.format(placeMark, "In: ",index, currCnt, lon, lat));
                        //                                
                        //                            } else
                        //                            {
                        //                                System.out.println(index+" / "+currCnt+" Tossing: "+lat+",  "+lon);
                        //                                pmStr.append(String.format(placeMark, "Tossing: ", index, currCnt, lon, lat));
                        //                            }
                    }
                    currCnt++;
                    if (currCnt % 100 == 0) {
                        firePropertyChange(CNT, 0, currCnt);
                    }
                }
                rs.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
                /*UsageTracker.incrSQLUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BaseTreeTask.class, ex);
                log.error("SQLException: " + ex.toString()); //$NON-NLS-1$
                lo .error(ex.getMessage());*/

            } finally {
                try {
                    if (stmt != null)
                        stmt.close();
                    if (conn != null)
                        conn.close();
                } catch (Exception ex) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BaseTreeTask.class, ex);
                    ex.printStackTrace();
                }
            }

            return null;
        }

        /* (non-Javadoc)
         * @see javax.swing.SwingWorker#done()
         */
        @Override
        protected void done() {
            super.done();

            if (doDebug) {
                try {
                    final String template = FileUtils.readFileToString(new File("template.kml"));
                    final PrintWriter pw = new PrintWriter(new File("debug.kml"));

                    String str = StringUtils.replace(template, "<!-- BOX -->", boxSB.toString());
                    str = StringUtils.replace(str, "<!-- POLYGON -->", polySB.toString());
                    str = StringUtils.replace(str, "<!-- PLACEMARKS -->", pmStr.toString());
                    pw.println(str);
                    pw.flush();
                    pw.close();
                } catch (IOException ex) {
                }
            }

            UIRegistry.clearSimpleGlassPaneMsg();
            statusBar.setProgressDone(STATUSBAR_NAME);

            for (LatLonPlacemarkIFace llp : markers) {
                model.addElement(llp);
            }

            if (markers.size() > 0) {
                wwPanel.placeMarkers(markers, null);
                searchBtn.setEnabled(false);

            } else {
                doClearAll(true);
                startBtn.setEnabled(false);
            }
            clearAllBtn.setEnabled(true);
            clearSearchBtn.setEnabled(true);
        }
    };

    statusBar.setIndeterminate(STATUSBAR_NAME, false);
    statusBar.setProgressRange(STATUSBAR_NAME, 0, 100);

    final SimpleGlassPane glassPane = UIRegistry
            .writeSimpleGlassPaneMsg(getLocalizedMessage("MySQLBackupService.BACKINGUP", "XXX"), 24);

    worker.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(final PropertyChangeEvent evt) {
            if (CNT.equals(evt.getPropertyName())) {
                int value = (Integer) evt.getNewValue();
                int progress = (int) (((double) value / (double) totalNumRecords) * 100.0);
                glassPane.setProgress(progress);
                statusBar.setValue(STATUSBAR_NAME, progress);
            }
        }
    });
    worker.execute();
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.EditorControl.java

/** Brings up the folder chooser to select where to save the files. 
 * //from w w w .j a v a2 s .co  m
 * @param format One of the formats defined by <code>FigureParam</code>.
 * @see org.openmicroscopy.shoola.env.data.model.FigureParam
 */
void saveAs(final int format) {
    String v = FigureParam.FORMATS.get(format);
    JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
    List<FileFilter> filters = new ArrayList<FileFilter>();
    switch (format) {
    case FigureParam.JPEG:
        filters.add(new JPEGFilter());
        break;
    case FigureParam.PNG:
        filters.add(new PNGFilter());
        break;
    case FigureParam.TIFF:
        filters.add(new TIFFFilter());
    }
    FileChooser chooser = new FileChooser(f, FileChooser.FOLDER_CHOOSER, "Save As",
            "Select where to save locally the images as " + v, filters);
    try {
        File file = UIUtilities.getDefaultFolder();
        if (file != null)
            chooser.setCurrentDirectory(file);
    } catch (Exception ex) {
    }
    String s = UIUtilities.removeFileExtension(view.getRefObjectName());
    if (s != null && s.trim().length() > 0)
        chooser.setSelectedFile(s);
    chooser.setApproveButtonText("Save");
    IconManager icons = IconManager.getInstance();
    chooser.setTitleIcon(icons.getIcon(IconManager.SAVE_AS_48));
    chooser.addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
                String value = (String) evt.getNewValue();
                File folder = null;
                if (StringUtils.isEmpty(value))
                    folder = UIUtilities.getDefaultFolder();
                else
                    folder = new File(value);
                Object src = evt.getSource();
                if (src instanceof FileChooser) {
                    ((FileChooser) src).setVisible(false);
                    ((FileChooser) src).dispose();
                }
                model.saveAs(folder, format);
            }
        }
    });
    chooser.centerDialog();
}

From source file:org.openmicroscopy.shoola.env.ui.ActivityComponent.java

/** 
 * Downloads the passed object is supported.
 * /* w  ww.j  a  va  2s.c o m*/
 * @param text   The text used if the object is not loaded.
 * @param object The object to handle.
 * @param folder Indicates where to download the file or <code>null</code>.
 */
void download(String text, Object object, File folder) {
    if (!(object instanceof FileAnnotationData || object instanceof OriginalFile))
        return;
    int index = -1;
    if (text == null)
        text = "";
    String name = "";
    String description = "";
    long dataID = -1;
    OriginalFile of = null;
    if (object instanceof FileAnnotationData) {
        FileAnnotationData data = (FileAnnotationData) object;
        if (data.isLoaded()) {
            name = data.getFileName();
            description = data.getDescription();
            of = (OriginalFile) data.getContent();
        } else {
            of = null;
            dataID = data.getId();
            index = DownloadActivityParam.FILE_ANNOTATION;
            if (text.length() == 0)
                text = "Annotation";
            name = text + "_" + dataID;
        }
    } else {
        of = (OriginalFile) object;
        if (!of.isLoaded()) {
            dataID = of.getId().getValue();
            index = DownloadActivityParam.ORIGINAL_FILE;
            if (text.length() == 0)
                text = "File";
            name = text + "_" + dataID;
            of = null;
        }
    }
    final OriginalFile original = of;
    final int type = index;
    final String desc = description;
    final long id = dataID;
    if (folder != null) {
        if (original == null && type == -1)
            return;
        DownloadActivityParam activity;
        IconManager icons = IconManager.getInstance(registry);
        if (original != null) {
            activity = new DownloadActivityParam(original, folder, icons.getIcon(IconManager.DOWNLOAD_22));

        } else {
            activity = new DownloadActivityParam(id, type, folder, icons.getIcon(IconManager.DOWNLOAD_22));
        }
        activity.setLegend(desc);
        activity.setUIRegister(false);
        viewer.notifyActivity(ctx, activity);
        return;
    }
    JFrame f = registry.getTaskBar().getFrame();
    FileChooser chooser = new FileChooser(f, FileChooser.SAVE, "Download", "Select where to download the file.",
            null, true, true);
    IconManager icons = IconManager.getInstance(registry);
    chooser.setTitleIcon(icons.getIcon(IconManager.DOWNLOAD_48));
    chooser.setSelectedFileFull(name);
    chooser.setApproveButtonText("Download");
    chooser.addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
                File[] files = (File[]) evt.getNewValue();
                File folder = files[0];
                if (original == null && type == -1)
                    return;
                IconManager icons = IconManager.getInstance(registry);
                DownloadActivityParam activity;
                if (original != null) {
                    activity = new DownloadActivityParam(original, folder,
                            icons.getIcon(IconManager.DOWNLOAD_22));

                } else {
                    activity = new DownloadActivityParam(id, type, folder,
                            icons.getIcon(IconManager.DOWNLOAD_22));
                }
                activity.setLegend(desc);
                viewer.notifyActivity(ctx, activity);
            }
        }
    });
    chooser.centerDialog();
}

From source file:org.talend.designer.runprocess.ui.TraceDebugProcessComposite.java

private void runProcessContextChanged(final PropertyChangeEvent evt) {
    String propName = evt.getPropertyName();
    if (ProcessMessageManager.PROP_MESSAGE_ADD.equals(propName)
            || ProcessMessageManager.PROP_DEBUG_MESSAGE_ADD.equals(propName)) {
        IProcessMessage psMess = (IProcessMessage) evt.getNewValue();

        if (errorMessMap.size() <= CorePlugin.getDefault().getPreferenceStore()
                .getInt(ITalendCorePrefConstants.PREVIEW_LIMIT)) {
            if (!(LanguageManager.getCurrentLanguage().equals(ECodeLanguage.PERL))) {
                getAllErrorMess(psMess);
            } else {
                addPerlMark(psMess);//w w  w  .  ja v  a 2 s . co m
            }
        }
        appendToConsole(psMess);
    } else if (ProcessMessageManager.PROP_MESSAGE_CLEAR.equals(propName)) {
        getShell().getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                if (!consoleText.isDisposed()) {
                    consoleText.setText(""); //$NON-NLS-1$
                }
            }
        });
    } else if (RunProcessContext.PROP_MONITOR.equals(propName)) {
        // perfBtn.setSelection(((Boolean) evt.getNewValue()).booleanValue());
    } else if (RunProcessContext.TRACE_MONITOR.equals(propName)) {
        // traceBtn.setSelection(((Boolean) evt.getNewValue()).booleanValue());
    } else if (RunProcessContext.PROP_RUNNING.equals(propName)) {
        getShell().getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                if (isDisposed()) {
                    return;
                }
                boolean running = ((Boolean) evt.getNewValue()).booleanValue();
                setRunnable(!running);
                killBtn.setEnabled(running);
                // previousRow.setEnabled(running);
                // nextRow.setEnabled(running);
                // nextBreakPoint.setEnabled(running);
            }
        });
    }
}

From source file:net.sourceforge.vulcan.core.support.StateManagerImpl.java

public void start() throws StoreException {
    try {/*w  w  w .  ja  v  a2s.c om*/
        writeLock.lock();

        config = configurationStore.loadConfiguration();

        applyPluginConfigurations();

        final BuildManagerConfigDto buildManagerConfig = config.getBuildManagerConfig();

        buildManagerConfig.addPropertyChangeListener("enabled", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                final Object newValue = evt.getNewValue();
                if (!evt.getOldValue().equals(newValue)) {
                    if (Boolean.TRUE.equals(newValue)) {
                        startSchedulers();
                    } else {
                        stopSchedulers();
                    }
                }
            }
        });
        buildManager.init(buildManagerConfig);

        running = true;

        if (buildManagerConfig.isEnabled()) {
            startSchedulers();
        }

        startBuildDaemons();

        eventHandler.reportEvent(new InfoEvent(this, "messages.startup"));
    } finally {
        writeLock.unlock();
    }
}

From source file:net.sf.jabref.EntryEditor.java

/**
 * Update the JTextArea when a field has changed.
 * /* w  ww  .  j a v  a  2 s .  c  o  m*/
 * @see java.beans.VetoableChangeListener#vetoableChange(java.beans.PropertyChangeEvent)
 */
public void vetoableChange(PropertyChangeEvent e) {
    String newValue = ((e.getNewValue() != null) ? e.getNewValue().toString() : "");
    setField(e.getPropertyName(), newValue);
}

From source file:com.haulmont.cuba.web.toolkit.ui.CubaSideMenu.java

@SuppressWarnings("unchecked")
protected void menuItemPropertyChanged(PropertyChangeEvent event) {
    if (event.getPropertyName() == null) {
        return;//from  w  w w . j a  v  a2  s .com
    }

    if (!structureChanged && MENU_ITEM_BADGE_TEXT.equals(event.getPropertyName())) {
        badgeUpdates.add((MenuItem) event.getSource());
        markAsDirty();
    }

    if (MENU_ITEM_CHILDREN.equals(event.getPropertyName())) {
        List<MenuItem> oldItems = (List<MenuItem>) event.getOldValue();
        List<MenuItem> newItems = (List<MenuItem>) event.getNewValue();

        if (oldItems != null) {
            for (MenuItem oldItem : oldItems) {
                oldItem.removePropertyChangeListener(itemsPropertyChangeListener);
            }
        }
        if (newItems != null) {
            for (MenuItem newItem : newItems) {
                newItem.addPropertyChangeListener(itemsPropertyChangeListener);
            }
        }
    }

    switch (event.getPropertyName()) {
    case MENU_ITEM_CAPTION:
    case MENU_ITEM_DESCRIPTION:
    case MENU_ITEM_ICON:
    case MENU_ITEM_CHILDREN:
    case MENU_ITEM_STYLE_NAME:
    case MENU_ITEM_VISIBLE:
    case MENU_ITEM_ENABLED:
    case MENU_ITEM_CAPTION_AS_HTML:
    case MENU_ITEM_CUBA_ID:
    case MENU_ITEM_EXPANDED:
        markMenuStructureAsDirty();
        break;
    }
}

From source file:edu.ku.brc.specify.config.init.secwiz.DatabasePanel.java

/**
 * /*  w  w  w .j a v a  2s.c o  m*/
 */
public void createDB() {
    getValues(properties);

    final String databaseName = dbNameTxt.getText();
    final String dbUserName = usernameTxt.getText();
    final String dbPwd = passwordTxt.getText();
    final String hostName = hostNameTxt.getText();

    if (isMobile()) {
        DBConnection.clearMobileMachineDir();
        File tmpDir = DBConnection.getMobileMachineDir(databaseName);
        setEmbeddedDBPath(tmpDir.getAbsolutePath());
    }

    final DatabaseDriverInfo driverInfo = (DatabaseDriverInfo) drivers.getSelectedItem();
    String connStrInitial = driverInfo.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, hostName,
            databaseName, dbUserName, dbPwd, driverInfo.getName());
    //System.err.println(connStrInitial);

    DBConnection.checkForEmbeddedDir("createDB - " + connStrInitial);

    DBConnection.getInstance().setDriverName(driverInfo.getName());
    DBConnection.getInstance().setServerName(hostName);

    VerifyStatus status = verifyDatabase(properties);
    if ((isOK == null || !isOK) && status == VerifyStatus.OK) {
        progressBar.setIndeterminate(true);
        progressBar.setVisible(true);

        label.setText(getResourceString("CONN_DB"));

        setUIEnabled(false);

        DatabasePanel.this.label.setForeground(Color.BLACK);

        SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
            /* (non-Javadoc)
             * @see javax.swing.SwingWorker#doInBackground()
             */
            @Override
            protected Object doInBackground() throws Exception {
                isOK = false;

                DBMSUserMgr mgr = DBMSUserMgr.getInstance();

                boolean dbmsOK = false;
                if (driverInfo.isEmbedded()) {
                    if (checkForProcesses) {
                        SpecifyDBSecurityWizardFrame.checkForMySQLProcesses();
                        checkForProcesses = false;
                    }

                    if (isMobile()) {
                        File mobileTmpDir = DBConnection.getMobileMachineDir();
                        if (!mobileTmpDir.exists()) {
                            if (!mobileTmpDir.mkdirs()) {
                                System.err.println(
                                        "Dir[" + mobileTmpDir.getAbsolutePath() + "] didn't get created!");
                                // throw exception
                            }
                            DBConnection.setCopiedToMachineDisk(true);
                        }
                    }

                    String newConnStr = driverInfo.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open,
                            hostName, databaseName, dbUserName, dbPwd, driverInfo.getName());
                    if (driverInfo.isEmbedded()) {
                        //System.err.println(newConnStr);
                        try {
                            Class.forName(driverInfo.getDriverClassName());

                            // This call will create the database if it doesn't exist
                            DBConnection testDB = DBConnection.createInstance(driverInfo.getDriverClassName(),
                                    driverInfo.getDialectClassName(), databaseName, newConnStr, dbUserName,
                                    dbPwd);
                            testDB.getConnection(); // Opens the connection

                            if (testDB != null) {
                                testDB.close();
                            }
                            dbmsOK = true;

                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                        DBConnection.getInstance().setDatabaseName(null);
                    }
                } else if (mgr.connectToDBMS(dbUserName, dbPwd, hostName)) {
                    mgr.close();
                    dbmsOK = true;
                }

                if (dbmsOK) {
                    firePropertyChange(PROPNAME, 0, 1);

                    try {
                        SpecifySchemaGenerator.generateSchema(driverInfo, hostName, databaseName, dbUserName,
                                dbPwd); // false means create new database, true means update

                        String connStr = driverInfo.getConnectionStr(DatabaseDriverInfo.ConnectionType.Create,
                                hostName, databaseName);
                        if (connStr == null) {
                            connStr = driverInfo.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open,
                                    hostName, databaseName);
                        }

                        firePropertyChange(PROPNAME, 0, 2);

                        // tryLogin sets up DBConnection
                        if (UIHelper.tryLogin(driverInfo.getDriverClassName(), driverInfo.getDialectClassName(),
                                dbNameTxt.getText(), connStr, dbUserName, dbPwd)) {

                            if (!checkEngineCharSet(properties)) {
                                return false;
                            }
                            isOK = true;

                            firePropertyChange(PROPNAME, 0, 3);

                            Thumbnailer thumb = Thumbnailer.getInstance();
                            File thumbFile = XMLHelper.getConfigDir("thumbnail_generators.xml");
                            thumb.registerThumbnailers(thumbFile);
                            thumb.setQuality(.5f);
                            thumb.setMaxSize(128, 128);

                            File attLoc = getAppDataSubDir("AttachmentStorage", true);
                            AttachmentManagerIface attachMgr = new FileStoreAttachmentManager(attLoc);
                            AttachmentUtils.setAttachmentManager(attachMgr);
                            AttachmentUtils.setThumbnailer(thumb);

                        } else {
                            errorKey = "NO_LOGIN_ROOT";
                        }
                    } catch (Exception ex) {
                        errorKey = "DB_UNRECOVERABLE";
                    }
                } else {
                    errorKey = "NO_CONN_ROOT";
                    mgr.close();
                }
                return null;
            }

            /* (non-Javadoc)
             * @see javax.swing.SwingWorker#done()
             */
            @Override
            protected void done() {
                super.done();

                setUIEnabled(true);

                progressBar.setIndeterminate(false);
                progressBar.setVisible(false);

                updateBtnUI();

                if (isOK) {
                    label.setText(getResourceString("DB_CREATED"));
                    setUIEnabled(false);

                } else {
                    label.setText(getResourceString(errorKey != null ? errorKey : "ERR_CRE_DB"));
                    showLocalizedError(errorKey != null ? errorKey : "ERR_CRE_DB");
                }
            }
        };

        worker.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(final PropertyChangeEvent evt) {
                if (PROPNAME.equals(evt.getPropertyName())) {
                    String key = null;
                    switch ((Integer) evt.getNewValue()) {
                    case 1:
                        key = "BLD_SCHEMA";
                        break;
                    case 2:
                        key = "DB_FRST_LOGIN";
                        break;
                    case 3:
                        key = "BLD_CACHE";
                        break;
                    default:
                        break;
                    }
                    if (key != null) {
                        DatabasePanel.this.label.setText(getResourceString(key));
                    }
                }
            }
        });
        worker.execute();

    } else if (status == VerifyStatus.ERROR) {
        errorKey = "NO_LOGIN_ROOT";
        DatabasePanel.this.label.setText(getResourceString(errorKey));
        DatabasePanel.this.label.setForeground(Color.RED);

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                getTopWindow().pack();
            }
        });
    }
}

From source file:org.executequery.base.DockedTabContainer.java

/**
 * Provides notification of split pane divider movement events.
 *
 * @param the change event/*www  .  j  a  v a 2 s.com*/
 */
public void propertyChange(PropertyChangeEvent e) {
    String name = e.getPropertyName();
    if ("dividerLocation".equals(name)) {
        String value = e.getNewValue().toString();
        desktopMediator.splitPaneDividerMoved(orientation, Integer.parseInt(value));
        /*
        Log.debug("property change: " + e.getPropertyName() +
        " old value: " + e.getOldValue() + " new value: " + e.getNewValue());
        */
    }
}

From source file:org.tinymediamanager.ui.movies.MoviePanel.java

/**
 * further initializations.//from  ww w  .  j a v a 2s . c  o  m
 */
private void init() {
    // build menu
    buildMenu();

    // moviename column
    table.getColumnModel().getColumn(0).setCellRenderer(new BorderCellRenderer());
    table.getColumnModel().getColumn(0).setIdentifier("title"); //$NON-NLS-1$

    // year column
    int width = table.getFontMetrics(table.getFont()).stringWidth(" 2000");
    int titleWidth = table.getFontMetrics(table.getFont()).stringWidth(BUNDLE.getString("metatag.year")); //$NON-NLS-1$
    if (titleWidth > width) {
        width = titleWidth;
    }
    table.getTableHeader().getColumnModel().getColumn(1).setPreferredWidth(width);
    table.getTableHeader().getColumnModel().getColumn(1).setMinWidth(width);
    table.getTableHeader().getColumnModel().getColumn(1).setMaxWidth((int) (width * 1.5));
    table.getTableHeader().getColumnModel().getColumn(1).setIdentifier("year"); //$NON-NLS-1$

    // rating column
    width = table.getFontMetrics(table.getFont()).stringWidth(" 10.0");
    titleWidth = table.getFontMetrics(table.getFont()).stringWidth(BUNDLE.getString("metatag.rating")); //$NON-NLS-1$
    if (titleWidth > width) {
        width = titleWidth;
    }
    table.getTableHeader().getColumnModel().getColumn(2).setPreferredWidth((int) (width * 1.2));
    table.getTableHeader().getColumnModel().getColumn(2).setMinWidth((int) (width * 1.2));
    table.getTableHeader().getColumnModel().getColumn(2).setMaxWidth((int) (width * 1.5));
    table.getTableHeader().getColumnModel().getColumn(2).setIdentifier("rating"); //$NON-NLS-1$

    // date added column
    width = table.getFontMetrics(table.getFont()).stringWidth("01. Jan. 2000");
    titleWidth = table.getFontMetrics(table.getFont()).stringWidth(BUNDLE.getString("metatag.dateadded")); //$NON-NLS-1$
    if (titleWidth > width) {
        width = titleWidth;
    }
    table.getTableHeader().getColumnModel().getColumn(3).setPreferredWidth((int) (width * 1.2));
    table.getTableHeader().getColumnModel().getColumn(3).setMinWidth((int) (width * 1.2));
    table.getTableHeader().getColumnModel().getColumn(3).setMaxWidth((int) (width * 1.2));
    table.getTableHeader().getColumnModel().getColumn(3).setIdentifier("dateadded"); //$NON-NLS-1$

    // NFO column
    table.getTableHeader().getColumnModel().getColumn(4)
            .setHeaderRenderer(new IconRenderer(BUNDLE.getString("tmm.nfo"))); //$NON-NLS-1$
    table.getTableHeader().getColumnModel().getColumn(4).setMaxWidth(20);
    table.getColumnModel().getColumn(4).setHeaderValue(IconManager.INFO);
    table.getTableHeader().getColumnModel().getColumn(4).setIdentifier("nfo"); //$NON-NLS-1$

    // Meta data column
    table.getTableHeader().getColumnModel().getColumn(5)
            .setHeaderRenderer(new IconRenderer(BUNDLE.getString("tmm.metadata"))); //$NON-NLS-1$
    table.getTableHeader().getColumnModel().getColumn(5).setMaxWidth(20);
    table.getColumnModel().getColumn(5).setHeaderValue(IconManager.SEARCH);
    table.getTableHeader().getColumnModel().getColumn(5).setIdentifier("metadata"); //$NON-NLS-1$

    // Images column
    table.getTableHeader().getColumnModel().getColumn(6)
            .setHeaderRenderer(new IconRenderer(BUNDLE.getString("tmm.images"))); //$NON-NLS-1$
    table.getTableHeader().getColumnModel().getColumn(6).setMaxWidth(20);
    table.getColumnModel().getColumn(6).setHeaderValue(IconManager.IMAGE);
    table.getTableHeader().getColumnModel().getColumn(6).setIdentifier("images"); //$NON-NLS-1$

    // trailer column
    table.getTableHeader().getColumnModel().getColumn(7)
            .setHeaderRenderer(new IconRenderer(BUNDLE.getString("tmm.trailer"))); //$NON-NLS-1$
    table.getTableHeader().getColumnModel().getColumn(7).setMaxWidth(20);
    table.getColumnModel().getColumn(7).setHeaderValue(IconManager.CLAPBOARD);
    table.getTableHeader().getColumnModel().getColumn(7).setIdentifier("trailer"); //$NON-NLS-1$

    // subtitles column
    table.getTableHeader().getColumnModel().getColumn(8)
            .setHeaderRenderer(new IconRenderer(BUNDLE.getString("tmm.subtitles"))); //$NON-NLS-1$
    table.getTableHeader().getColumnModel().getColumn(8).setMaxWidth(20);
    table.getColumnModel().getColumn(8).setHeaderValue(IconManager.SUBTITLE);
    table.getTableHeader().getColumnModel().getColumn(8).setIdentifier("subtitle"); //$NON-NLS-1$

    // watched column
    table.getTableHeader().getColumnModel().getColumn(9)
            .setHeaderRenderer(new IconRenderer(BUNDLE.getString("metatag.watched"))); //$NON-NLS-1$
    table.getTableHeader().getColumnModel().getColumn(9).setMaxWidth(20);
    table.getColumnModel().getColumn(9).setHeaderValue(IconManager.PLAY_SMALL);
    table.getTableHeader().getColumnModel().getColumn(9).setIdentifier("watched"); //$NON-NLS-1$

    table.setSelectionModel(movieSelectionModel.getSelectionModel());
    // selecting first movie at startup
    if (movieList.getMovies() != null && movieList.getMovies().size() > 0) {
        ListSelectionModel selectionModel = table.getSelectionModel();
        if (selectionModel.isSelectionEmpty()) {
            selectionModel.setSelectionInterval(0, 0);
        }
    }

    // hide columns if needed
    if (!MovieModuleManager.MOVIE_SETTINGS.isYearColumnVisible()) {
        table.hideColumn("year"); //$NON-NLS-1$
    }
    if (!MovieModuleManager.MOVIE_SETTINGS.isRatingColumnVisible()) {
        table.hideColumn("rating"); //$NON-NLS-1$
    }
    if (!MovieModuleManager.MOVIE_SETTINGS.isDateAddedColumnVisible()) {
        table.hideColumn("dateadded"); //$NON-NLS-1$
    }
    if (!MovieModuleManager.MOVIE_SETTINGS.isNfoColumnVisible()) {
        table.hideColumn("nfo"); //$NON-NLS-1$
    }
    if (!MovieModuleManager.MOVIE_SETTINGS.isMetadataColumnVisible()) {
        table.hideColumn("metadata"); //$NON-NLS-1$
    }
    if (!MovieModuleManager.MOVIE_SETTINGS.isImageColumnVisible()) {
        table.hideColumn("images"); //$NON-NLS-1$
    }
    if (!MovieModuleManager.MOVIE_SETTINGS.isTrailerColumnVisible()) {
        table.hideColumn("trailer"); //$NON-NLS-1$
    }
    if (!MovieModuleManager.MOVIE_SETTINGS.isSubtitleColumnVisible()) {
        table.hideColumn("subtitle"); //$NON-NLS-1$
    }
    if (!MovieModuleManager.MOVIE_SETTINGS.isWatchedColumnVisible()) {
        table.hideColumn("watched"); //$NON-NLS-1$
    }

    // and add a propertychangelistener to the columnhider
    PropertyChangeListener settingsPropertyChangeListener = new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getSource() instanceof MovieSettings) {
                if ("yearColumnVisible".equals(evt.getPropertyName())) {
                    setColumnVisibility("year", (Boolean) evt.getNewValue()); //$NON-NLS-1$
                }
                if ("ratingColumnVisible".equals(evt.getPropertyName())) {
                    setColumnVisibility("rating", (Boolean) evt.getNewValue()); //$NON-NLS-1$
                }
                if ("nfoColumnVisible".equals(evt.getPropertyName())) {
                    setColumnVisibility("nfo", (Boolean) evt.getNewValue());
                }
                if ("metadataColumnVisible".equals(evt.getPropertyName())) {
                    setColumnVisibility("metadata", (Boolean) evt.getNewValue());
                }
                if ("dateAddedColumnVisible".equals(evt.getPropertyName())) {
                    setColumnVisibility("dateadded", (Boolean) evt.getNewValue());
                }
                if ("imageColumnVisible".equals(evt.getPropertyName())) {
                    setColumnVisibility("images", (Boolean) evt.getNewValue()); //$NON-NLS-1$
                }
                if ("trailerColumnVisible".equals(evt.getPropertyName())) {
                    setColumnVisibility("trailer", (Boolean) evt.getNewValue()); //$NON-NLS-1$
                }
                if ("subtitleColumnVisible".equals(evt.getPropertyName())) {
                    setColumnVisibility("subtitle", (Boolean) evt.getNewValue()); //$NON-NLS-1$
                }
                if ("watchedColumnVisible".equals(evt.getPropertyName())) {
                    setColumnVisibility("watched", (Boolean) evt.getNewValue()); //$NON-NLS-1$
                }
            }
        }

        private void setColumnVisibility(Object identifier, Boolean visible) {
            if (visible) {
                table.showColumn(identifier);
            } else {
                table.hideColumn(identifier);
            }

        }
    };

    MovieModuleManager.MOVIE_SETTINGS.addPropertyChangeListener(settingsPropertyChangeListener);

    // initialize filteredCount
    lblMovieCountFiltered.setText(String.valueOf(movieTableModel.getRowCount()));

    addKeyListener();
}