images plugin now part of a CE
[fedora-idea.git] / images / src / org / intellij / images / ui / ThumbnailComponent.java
blob953bae78b7d78d1b61e0e8ee4e59c25d41482d6f
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /** $Id$ */
19 package org.intellij.images.ui;
21 import com.intellij.openapi.util.text.StringUtil;
22 import org.jetbrains.annotations.NonNls;
24 import javax.swing.*;
26 /**
27 * Thumbnail component.
29 * @author <a href="mailto:aefimov.box@gmail.com">Alexey Efimov</a>
31 public class ThumbnailComponent extends JComponent {
32 @NonNls
33 private static final String FORMAT_PROP = "format";
34 @NonNls
35 private static final String FILE_SIZE_PROP = "fileSize";
36 @NonNls
37 private static final String FILE_NAME_PROP = "fileName";
38 @NonNls
39 private static final String DIRECTORY_PROP = "directory";
40 @NonNls
41 private static final String IMAGES_COUNT_PROP = "imagesCount";
43 /**
44 * @see #getUIClassID
45 * @see #readObject
47 @NonNls
48 private static final String uiClassID = "ThumbnailComponentUI";
50 static {
51 UIManager.getDefaults().put(uiClassID, ThumbnailComponentUI.class.getName());
54 /**
55 * Image component for rendering thumbnail image.
57 private final ImageComponent imageComponent = new ImageComponent();
59 private String format;
60 private long fileSize;
61 private String fileName;
62 private boolean directory;
63 private int imagesCount;
65 public ThumbnailComponent() {
66 updateUI();
69 public ImageComponent getImageComponent() {
70 return imageComponent;
73 public String getFormat() {
74 return format;
77 public void setFormat(String format) {
78 String oldValue = this.format;
79 if (oldValue != null && !oldValue.equals(format) || oldValue == null && format != null) {
80 this.format = format;
81 firePropertyChange(FORMAT_PROP, oldValue, this.format);
85 public long getFileSize() {
86 return fileSize;
89 public void setFileSize(long fileSize) {
90 long oldValue = this.fileSize;
91 if (oldValue != fileSize) {
92 this.fileSize = fileSize;
93 firePropertyChange(FILE_SIZE_PROP, new Long(oldValue), new Long(this.fileSize));
97 public String getFileName() {
98 return fileName;
101 public void setFileName(String fileName) {
102 String oldValue = this.fileName;
103 if (oldValue != null && !oldValue.equals(fileName) || oldValue == null && fileName != null) {
104 this.fileName = fileName;
105 firePropertyChange(FILE_NAME_PROP, oldValue, this.fileName);
109 public boolean isDirectory() {
110 return directory;
113 public void setDirectory(boolean directory) {
114 boolean oldValue = this.directory;
115 if (oldValue != directory) {
116 this.directory = directory;
117 firePropertyChange(DIRECTORY_PROP, oldValue, this.directory);
121 public int getImagesCount() {
122 return imagesCount;
125 public void setImagesCount(int imagesCount) {
126 int oldValue = this.imagesCount;
127 if (oldValue != imagesCount) {
128 this.imagesCount = imagesCount;
129 firePropertyChange(IMAGES_COUNT_PROP, oldValue, this.imagesCount);
133 public String getFileSizeText() {
134 return StringUtil.formatFileSize(fileSize);
137 public void updateUI() {
138 setUI(UIManager.getUI(this));
141 public String getUIClassID() {
142 return uiClassID;