diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form index 9013c01ff47..5dfc2743e95 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form @@ -55,7 +55,7 @@ - + @@ -88,7 +88,6 @@ - @@ -119,13 +118,15 @@ - - - - + + + + + + @@ -156,12 +157,10 @@ - - - + - + @@ -175,7 +174,7 @@ - + @@ -282,8 +281,6 @@ - - diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java index e4e0b73c63e..c67d33e6476 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java @@ -39,7 +39,7 @@ import mage.Constants.RangeOfInfluence; import mage.cards.decks.importer.DeckImporterUtil; import mage.client.MageFrame; import mage.client.components.MageComponents; -import mage.client.table.TablePlayerPanel; +import mage.client.table.*; import mage.client.util.Event; import mage.client.util.Listener; import mage.game.match.MatchOptions; @@ -534,4 +534,4 @@ public class NewTableDialog extends MageDialog { private javax.swing.JTextField txtName; // End of variables declaration//GEN-END:variables -} +} \ No newline at end of file diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form index 8b31b07b896..c272d80d090 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form @@ -37,13 +37,13 @@ - - + + - + @@ -82,7 +82,7 @@ - + @@ -110,7 +110,7 @@ - + @@ -164,7 +164,7 @@ - + @@ -262,7 +262,7 @@ - + @@ -334,7 +334,7 @@ - + @@ -432,9 +432,12 @@ - + - + + + + @@ -444,7 +447,9 @@ - + + + @@ -487,7 +492,7 @@ - + @@ -547,6 +552,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -567,7 +715,7 @@ - + @@ -578,7 +726,7 @@ - + @@ -641,7 +789,7 @@ - + @@ -716,7 +864,7 @@ - + @@ -824,12 +972,12 @@ - + - + diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index f836ad8f5ca..3248afeff32 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -42,6 +42,7 @@ import org.apache.log4j.Logger; import javax.swing.*; import javax.swing.border.Border; +import javax.swing.filechooser.FileFilter; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -71,6 +72,12 @@ public class PreferencesDialog extends javax.swing.JDialog { public static final String KEY_CARD_IMAGES_PATH = "cardImagesPath"; public static final String KEY_CARD_IMAGES_CHECK = "cardImagesCheck"; public static final String KEY_CARD_IMAGES_SAVE_TO_ZIP = "cardImagesSaveToZip"; + + public static final String KEY_BACKGROUND_IMAGE = "backgroundImage"; + public static final String KEY_BATTLEFIELD_IMAGE = "battlefieldImage"; + public static final String KEY_BACKGROUND_IMAGE_DEFAULT = "backgroundImagedDefault"; + public static final String KEY_BATTLEFIELD_IMAGE_RANDOM = "battlefieldImagerandom"; + public static final String KEY_BATTLEFIELD_IMAGE_DEFAULT = "battlefieldImageDefault"; public static final String KEY_SOUNDS_ON = "soundsOn"; public static final String KEY_MUSICS_ON = "MusicsOn"; @@ -143,7 +150,47 @@ public class PreferencesDialog extends javax.swing.JDialog { { fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } + + private final JFileChooser fc_i = new JFileChooser(); + { + fc_i.setAcceptAllFileFilterUsed(false); + fc_i.addChoosableFileFilter(new ImageFileFilter(".jpg")); + fc_i.addChoosableFileFilter(new ImageFileFilter(".jpeg")); + fc_i.addChoosableFileFilter(new ImageFileFilter(".png")); + fc_i.addChoosableFileFilter(new ImageFileFilter(".bmp")); + } + private static class ImageFileFilter extends FileFilter{ + String extend; + public ImageFileFilter(String extend){ + this.extend = extend; + } + + @Override + public boolean accept(File f) { + String filename = f.getName(); + if(f.isDirectory()) return true; + if(filename != null){ + if(filename.endsWith(extend)){ + return true; + } + } + return false; + } + + @Override + public String getDescription() { + if(extend.equals(".png") || extend.equals(".bmp")) + return "Image File(*.png, *.bmp)"; + if(extend.equals(".jpg") || extend.equals(".jpg")) + return "JEGP file(*.jpg,*.jepg)"; + return ""; + } + + } + + + /** Creates new form PreferencesDialog */ public PreferencesDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); @@ -201,6 +248,16 @@ public class PreferencesDialog extends javax.swing.JDialog { browseButton = new javax.swing.JButton(); checkForNewImages = new javax.swing.JCheckBox(); saveToZipFiles = new javax.swing.JCheckBox(); + jPanel23 = new javax.swing.JPanel(); + useDefaultBackground = new javax.swing.JCheckBox(); + BackgroundImagePath = new javax.swing.JTextField(); + BackgroundBrowseButton = new javax.swing.JButton(); + BattlefieldImagePath = new javax.swing.JTextField(); + BattlefieldBrowseButton = new javax.swing.JButton(); + useDefaultBattleImage = new javax.swing.JCheckBox(); + useRandomBattleImage = new javax.swing.JCheckBox(); + jLabel14 = new javax.swing.JLabel(); + jLabel15 = new javax.swing.JLabel(); jPanel22 = new javax.swing.JPanel(); jEnableSounds = new javax.swing.JCheckBox(); jEnableMusics = new javax.swing.JCheckBox(); @@ -268,7 +325,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(showToolTipsInAnyZone) .addComponent(displayBigCardsInHand)) - .addContainerGap(166, Short.MAX_VALUE)) + .addContainerGap(164, Short.MAX_VALUE)) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -296,7 +353,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addGroup(jPanel7Layout.createSequentialGroup() .addContainerGap() .addComponent(nonLandPermanentsInOnePile) - .addContainerGap(204, Short.MAX_VALUE)) + .addContainerGap(202, Short.MAX_VALUE)) ); jPanel7Layout.setVerticalGroup( jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -325,7 +382,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(92, Short.MAX_VALUE)) + .addContainerGap(230, Short.MAX_VALUE)) ); jTabbedPane1.addTab("Main", jPanel1); @@ -398,7 +455,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1))) - .addContainerGap(105, Short.MAX_VALUE)) + .addContainerGap(103, Short.MAX_VALUE)) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -453,7 +510,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addComponent(checkBoxEndTurnYou) .addComponent(jLabel8) .addComponent(checkBoxEndTurnOthers)) - .addContainerGap(24, Short.MAX_VALUE)) + .addContainerGap(162, Short.MAX_VALUE)) ); jTabbedPane1.addTab("Phases", jPanel2); @@ -508,7 +565,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addGroup(jPanel5Layout.createSequentialGroup() .addContainerGap() .addComponent(saveToZipFiles))) - .addContainerGap(15, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel5Layout.setVerticalGroup( jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -526,13 +583,122 @@ public class PreferencesDialog extends javax.swing.JDialog { .addContainerGap(22, Short.MAX_VALUE)) ); + jPanel23.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Background images setting:")); + + useDefaultBackground.setText("use default image"); + useDefaultBackground.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + useDefaultBackgroundActionPerformed(evt); + } + }); + + BackgroundImagePath.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + BackgroundImagePathActionPerformed(evt); + } + }); + + BackgroundBrowseButton.setText("Browse..."); + BackgroundBrowseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + BackgroundBrowseButtonActionPerformed(evt); + } + }); + + BattlefieldImagePath.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + BattlefieldImagePathActionPerformed(evt); + } + }); + + BattlefieldBrowseButton.setText("Browse..."); + BattlefieldBrowseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + BattlefieldBrowseButtonActionPerformed(evt); + } + }); + + useDefaultBattleImage.setText("default battlefield image"); + useDefaultBattleImage.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + useDefaultBattleImageActionPerformed(evt); + } + }); + + useRandomBattleImage.setText("random battlefield image"); + useRandomBattleImage.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + useRandomBattleImageActionPerformed(evt); + } + }); + + jLabel14.setText("Background:"); + + jLabel15.setText("Battlefield:"); + + javax.swing.GroupLayout jPanel23Layout = new javax.swing.GroupLayout(jPanel23); + jPanel23.setLayout(jPanel23Layout); + jPanel23Layout.setHorizontalGroup( + jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel23Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel23Layout.createSequentialGroup() + .addComponent(useDefaultBackground) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel23Layout.createSequentialGroup() + .addGroup(jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(jPanel23Layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(jLabel14) + .addGap(18, 18, 18) + .addComponent(BackgroundImagePath, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(BackgroundBrowseButton)) + .addGroup(jPanel23Layout.createSequentialGroup() + .addComponent(jLabel15) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(BattlefieldImagePath, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(BattlefieldBrowseButton))) + .addGap(18, 18, 18)) + .addGroup(jPanel23Layout.createSequentialGroup() + .addGroup(jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(useDefaultBattleImage) + .addComponent(useRandomBattleImage)) + .addGap(0, 0, Short.MAX_VALUE)))) + ); + jPanel23Layout.setVerticalGroup( + jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel23Layout.createSequentialGroup() + .addContainerGap() + .addComponent(useDefaultBackground) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(BackgroundImagePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(BackgroundBrowseButton) + .addComponent(jLabel14)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(useDefaultBattleImage) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(useRandomBattleImage) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(BattlefieldImagePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(BattlefieldBrowseButton) + .addComponent(jLabel15)) + .addContainerGap(21, Short.MAX_VALUE)) + ); + javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel4Layout.createSequentialGroup() + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup() .addContainerGap() - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jPanel23, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); jPanel4Layout.setVerticalGroup( @@ -540,7 +706,9 @@ public class PreferencesDialog extends javax.swing.JDialog { .addGroup(jPanel4Layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(96, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jPanel23, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(39, Short.MAX_VALUE)) ); jTabbedPane1.addTab("Images", jPanel4); @@ -568,7 +736,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jEnableSounds) .addComponent(jEnableMusics)) - .addContainerGap(325, Short.MAX_VALUE)) + .addContainerGap(323, Short.MAX_VALUE)) ); jPanel22Layout.setVerticalGroup( jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -577,7 +745,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addComponent(jEnableSounds) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jEnableMusics) - .addContainerGap(194, Short.MAX_VALUE)) + .addContainerGap(332, Short.MAX_VALUE)) ); jTabbedPane1.addTab("Sounds", jPanel22); @@ -645,7 +813,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(txtPasswordField, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtProxyUserName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(txtProxyServer, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)) + .addComponent(txtProxyServer, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)) .addContainerGap()) ); pnlProxyLayout.setVerticalGroup( @@ -715,7 +883,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addComponent(cbProxyType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pnlProxySettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(40, Short.MAX_VALUE)) + .addContainerGap(178, Short.MAX_VALUE)) ); pnlProxySettings.getAccessibleContext().setAccessibleDescription(""); @@ -960,11 +1128,11 @@ public class PreferencesDialog extends javax.swing.JDialog { jPanel8.setLayout(jPanel8Layout); jPanel8Layout.setHorizontalGroup( jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 437, Short.MAX_VALUE) ); jPanel8Layout.setVerticalGroup( jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE) ); jTabbedPane1.addTab("Avatars", jPanel8); @@ -998,12 +1166,12 @@ public class PreferencesDialog extends javax.swing.JDialog { layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 430, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(exitButton) .addComponent(saveButton)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap(18, Short.MAX_VALUE)) ); pack(); @@ -1039,6 +1207,10 @@ public class PreferencesDialog extends javax.swing.JDialog { saveImagesPath(prefs); save(prefs, dialog.checkForNewImages, KEY_CARD_IMAGES_CHECK, "true", "false", UPDATE_CACHE_POLICY); save(prefs, dialog.saveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true", "false", UPDATE_CACHE_POLICY); + + save(prefs, dialog.useDefaultBackground, KEY_BACKGROUND_IMAGE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.useDefaultBattleImage, KEY_BATTLEFIELD_IMAGE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY); + save(prefs, dialog.useRandomBattleImage, KEY_BATTLEFIELD_IMAGE_RANDOM, "true", "false", UPDATE_CACHE_POLICY); // sounds save(prefs, dialog.jEnableSounds, KEY_SOUNDS_ON, "true", "false", UPDATE_CACHE_POLICY); @@ -1103,7 +1275,7 @@ public class PreferencesDialog extends javax.swing.JDialog { private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed int returnVal = fc.showOpenDialog(PreferencesDialog.this); - + if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); imageFolderPath.setText(file.getAbsolutePath()); @@ -1141,6 +1313,100 @@ public class PreferencesDialog extends javax.swing.JDialog { private void jEnableMusicsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jEnableMusicsActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jEnableMusicsActionPerformed + + private void useDefaultBackgroundActionPerformed(java.awt.event.ActionEvent evt) { + if(useDefaultBackground.isSelected()){ + useDefualtBackgroundImage(); + }else{ + useSelectBackgroundImage(); + } + } + + private void useDefualtBackgroundImage(){ + BackgroundImagePath.setEnabled(false); + BackgroundBrowseButton.setEnabled(false); + BackgroundImagePath.setText(""); + } + + private void useSelectBackgroundImage(){ + String path = cache.get(KEY_BACKGROUND_IMAGE); + dialog.BackgroundImagePath.setText(path); + BackgroundImagePath.setEnabled(true); + BackgroundBrowseButton.setEnabled(true); + } + + private void useDefaultBattleImageActionPerformed(java.awt.event.ActionEvent evt) { + if(useDefaultBattleImage.isSelected()){ + useDefaultBattlefield(); + }else{ + useSelectedOrRandom(); + } + } + + private void useDefaultBattlefield(){ + useRandomBattleImage.setEnabled(false); + BattlefieldImagePath.setEnabled(false); + BattlefieldBrowseButton.setEnabled(false); + } + + private void useSelectedOrRandom(){ + useRandomBattleImage.setEnabled(true); + String temp = cache.get(KEY_BATTLEFIELD_IMAGE_RANDOM); + if(temp != null){ + if(temp.equals("true")){ + useRandomBattleField(); + useRandomBattleImage.setSelected(true); + }else{ + useSelectedBattleField(); + useRandomBattleImage.setSelected(false); + } + }else{ + useSelectedBattleField(); + useRandomBattleImage.setSelected(false); + } + } + + private void useRandomBattleImageActionPerformed(java.awt.event.ActionEvent evt) { + if(useRandomBattleImage.isSelected()){ + useRandomBattleField(); + }else{ + useSelectedBattleField(); + } + } + + private void useRandomBattleField(){ + BattlefieldImagePath.setEnabled(false); + BattlefieldBrowseButton.setEnabled(false); + } + + private void useSelectedBattleField(){ + BattlefieldImagePath.setEnabled(true); + BattlefieldBrowseButton.setEnabled(true); + } + + private void BackgroundBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) { + int returnVal = fc_i.showOpenDialog(PreferencesDialog.this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc_i.getSelectedFile(); + BackgroundImagePath.setText(file.getAbsolutePath()); + } + } + + private void BattlefieldBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) { + int returnVal = fc_i.showOpenDialog(PreferencesDialog.this); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc_i.getSelectedFile(); + BattlefieldImagePath.setText(file.getAbsolutePath()); + } + } + + private void BackgroundImagePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BackgroundImagePathActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_BackgroundImagePathActionPerformed + + private void BattlefieldImagePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BattlefieldImagePathActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_BattlefieldImagePathActionPerformed private void showProxySettings() { if (cbProxyType.getSelectedItem() == Connection.ProxyType.SOCKS) { @@ -1240,6 +1506,39 @@ public class PreferencesDialog extends javax.swing.JDialog { } load(prefs, dialog.checkForNewImages, KEY_CARD_IMAGES_CHECK, "true"); load(prefs, dialog.saveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true"); + //add background load precedure + prop = prefs.get(KEY_BACKGROUND_IMAGE_DEFAULT, "true"); + if(prop.equals("true")){ + dialog.useDefaultBackground.setSelected(true); + dialog.useDefualtBackgroundImage(); + }else{ + dialog.useDefaultBackground.setSelected(false); + dialog.useSelectBackgroundImage(); + String path = prefs.get(KEY_BACKGROUND_IMAGE, ""); + dialog.BackgroundImagePath.setText(path); + updateCache(KEY_BACKGROUND_IMAGE, path); + } + prop = prefs.get(KEY_BATTLEFIELD_IMAGE_DEFAULT, "true"); + if(prop.equals("true")){ + dialog.useDefaultBattleImage.setSelected(true); + dialog.useDefaultBattlefield(); + }else{ + dialog.useDefaultBattleImage.setSelected(false); + dialog.useSelectedOrRandom(); + } + prop = prefs.get(KEY_BATTLEFIELD_IMAGE_RANDOM, "true"); + + if(dialog.useRandomBattleImage.isEnabled()) + if(prop.equals("true")){ + dialog.useRandomBattleImage.setSelected(true); + dialog.useRandomBattleField(); + }else{ + dialog.useRandomBattleImage.setSelected(false); + dialog.useSelectedBattleField(); + String path = prefs.get(KEY_BATTLEFIELD_IMAGE, ""); + dialog.BattlefieldImagePath.setText(path); + updateCache(KEY_BATTLEFIELD_IMAGE, path); + } } private static void loadSoundSettings(Preferences prefs) { @@ -1298,13 +1597,23 @@ public class PreferencesDialog extends javax.swing.JDialog { } - private static void saveImagesPath(Preferences prefs) { if (!dialog.useDefaultImageFolder.isSelected()) { String path = dialog.imageFolderPath.getText(); prefs.put(KEY_CARD_IMAGES_PATH, path); updateCache(KEY_CARD_IMAGES_PATH, path); } + // background path save precedure + if(!dialog.useDefaultBackground.isSelected()){ + String path = dialog.BackgroundImagePath.getText(); + prefs.put(KEY_BACKGROUND_IMAGE, path); + updateCache(KEY_BACKGROUND_IMAGE, path); + } + if(!dialog.useDefaultBattleImage.isSelected() && !dialog.useRandomBattleImage.isSelected()){ + String path = dialog.BattlefieldImagePath.getText(); + prefs.put(KEY_BATTLEFIELD_IMAGE, path); + updateCache(KEY_BATTLEFIELD_IMAGE, path); + } } public static boolean isSaveImagesToZip() { @@ -1453,6 +1762,10 @@ public class PreferencesDialog extends javax.swing.JDialog { } // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton BackgroundBrowseButton; + private javax.swing.JTextField BackgroundImagePath; + private javax.swing.JButton BattlefieldBrowseButton; + private javax.swing.JTextField BattlefieldImagePath; private javax.swing.JButton browseButton; private javax.swing.JComboBox cbProxyType; private javax.swing.JCheckBox checkBoxBeforeCOthers; @@ -1480,6 +1793,8 @@ public class PreferencesDialog extends javax.swing.JDialog { private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; + private javax.swing.JLabel jLabel14; + private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; @@ -1503,6 +1818,7 @@ public class PreferencesDialog extends javax.swing.JDialog { private javax.swing.JPanel jPanel20; private javax.swing.JPanel jPanel21; private javax.swing.JPanel jPanel22; + private javax.swing.JPanel jPanel23; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; @@ -1528,7 +1844,10 @@ public class PreferencesDialog extends javax.swing.JDialog { private javax.swing.JTextField txtProxyPort; private javax.swing.JTextField txtProxyServer; private javax.swing.JTextField txtProxyUserName; + private javax.swing.JCheckBox useDefaultBackground; + private javax.swing.JCheckBox useDefaultBattleImage; private javax.swing.JCheckBox useDefaultImageFolder; + private javax.swing.JCheckBox useRandomBattleImage; // End of variables declaration//GEN-END:variables private static final PreferencesDialog dialog = new PreferencesDialog(new javax.swing.JFrame(), true); diff --git a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java index 75a0e149e32..b5dae389280 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java +++ b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java @@ -21,6 +21,7 @@ import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.impl.PluginManagerFactory; import org.apache.log4j.Logger; import org.mage.plugins.card.CardPluginImpl; +import org.mage.plugins.theme.ThemePluginImpl; import javax.swing.*; import java.awt.*; @@ -54,7 +55,8 @@ public class Plugins implements MagePlugins { pm.addPluginsFrom(new File(PLUGINS_DIRECTORY).toURI()); this.cardPlugin = new CardPluginImpl(); this.counterPlugin = pm.getPlugin(CounterPlugin.class); - this.themePlugin = pm.getPlugin(ThemePlugin.class); + //this.themePlugin = pm.getPlugin(ThemePlugin.class); + this.themePlugin = new ThemePluginImpl(); logger.info("Done."); } diff --git a/Mage.Client/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java b/Mage.Client/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java new file mode 100644 index 00000000000..f2a10884a10 --- /dev/null +++ b/Mage.Client/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java @@ -0,0 +1,210 @@ +package org.mage.plugins.theme; + +import mage.components.ImagePanel; +import mage.interfaces.plugin.ThemePlugin; +import mage.client.dialog.PreferencesDialog; +import net.xeoh.plugins.base.annotations.PluginImplementation; +import net.xeoh.plugins.base.annotations.events.Init; +import net.xeoh.plugins.base.annotations.events.PluginLoaded; +import net.xeoh.plugins.base.annotations.meta.Author; +import org.apache.log4j.Logger; + +import javax.imageio.ImageIO; +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.*; +import java.io.InputStream; +import java.util.Map; + +@PluginImplementation +@Author(name = "nantuko") +public class ThemePluginImpl implements ThemePlugin { + + private static final Logger log = Logger.getLogger(ThemePluginImpl.class); + private static BufferedImage background; + private List flist = new List(); + private String BackgroundDir = "plugins" + File.separator + "plugin.data" + File.separator + + "background" + File.separator; + @Init + public void init() { + } + + @PluginLoaded + public void newPlugin(ThemePlugin plugin) { + log.info(plugin.toString() + " has been loaded."); + } + + public String toString() { + return "[Theme plugin, version 0.5]"; + } + + public boolean loadimages(){ + File filedir = new File(BackgroundDir); + File[] filelist = filedir.listFiles(); + if(filelist == null) return false; + if(filelist.length == 0) return false; + for(File f:filelist){ + String filename = f.getName().toLowerCase(); + if(filename != null && (filename.endsWith(".png") || filename.endsWith(".jpg") + || filename.endsWith(".bmp"))){ + flist.add(filename); + } + } + if(flist.getItemCount() == 0) return false; + return true; + } + + public void applyInGame(Map ui) { + BufferedImage background; + try { + + if(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE_DEFAULT, + "true").equals("true")){ + + background = loadbuffer_default(); + + }else if(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE_RANDOM, + "true").equals("true")){ + + background = loadbuffer_random(); + + }else if(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE, "") != null){ + + background = loadbuffer_selected(); + + }else{ + background = loadbuffer_default(); + } + + + + /* + if(loadimages()){ + int it = (int)Math.abs(Math.random()*(flist.getItemCount())); + filename = BackgroundDir + flist.getItem(it); + background = ImageIO.read(new File(filename)); + }else{ + filename = "/dragon.png"; + InputStream is = this.getClass().getResourceAsStream(filename); + if (is == null) + throw new FileNotFoundException("Couldn't find " + filename + " in resources."); + background = ImageIO.read(is); + } + */ + if (background == null) { + throw new FileNotFoundException("Couldn't find background file in resources."); + } + + if (ui.containsKey("gamePanel") && ui.containsKey("jLayeredPane")) { + ImagePanel bgPanel = new ImagePanel(background, ImagePanel.TILED); + + unsetOpaque(ui.get("jSplitPane1")); + unsetOpaque(ui.get("pnlBattlefield")); + unsetOpaque(ui.get("jPanel3")); + unsetOpaque(ui.get("hand")); + unsetOpaque(ui.get("gameChatPanel")); + unsetOpaque(ui.get("userChatPanel")); + + ui.get("gamePanel").remove(ui.get("jLayeredPane")); + bgPanel.add(ui.get("jLayeredPane")); + ui.get("gamePanel").add(bgPanel); + } else { + log.error("error: no components"); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + return; + } + } + + + private BufferedImage loadbuffer_default() throws IOException{ + String filename = "/dragon.png"; + BufferedImage res; + InputStream is = this.getClass().getResourceAsStream(filename); + res = ImageIO.read(is); + return res; + } + + private BufferedImage loadbuffer_random() throws IOException{ + BufferedImage res; + if(loadimages()){ + int it = (int)Math.abs(Math.random()*(flist.getItemCount())); + String filename = BackgroundDir + flist.getItem(it); + res = ImageIO.read(new File(filename)); + return res; + } + return null; + } + + private BufferedImage loadbuffer_selected() throws IOException{ + BufferedImage res; + String path = PreferencesDialog.getCachedValue(PreferencesDialog. + KEY_BATTLEFIELD_IMAGE, ""); + if(path != null){ + res = ImageIO.read(new File(path)); + return res; + } + return null; + } + + + public JComponent updateTable(Map ui) { + ImagePanel bgPanel = createImagePanelInstance(); + + unsetOpaque(ui.get("jScrollPane1")); + unsetOpaque(ui.get("jPanel1")); + unsetOpaque(ui.get("tablesPanel")); + JComponent viewport = ui.get("jScrollPane1ViewPort"); + if (viewport != null) { + viewport.setBackground(new Color(255,255,255,50)); + } + return bgPanel; + } + + private ImagePanel createImagePanelInstance() { + if (background == null) { + synchronized (ThemePluginImpl.class) { + if (background == null) { + String filename = "/background.png"; + try { + if(PreferencesDialog.getCachedValue(PreferencesDialog. + KEY_BACKGROUND_IMAGE_DEFAULT, "true").equals("true")){ + InputStream is = this.getClass().getResourceAsStream(filename); + if (is == null) + throw new FileNotFoundException("Couldn't find " + filename + " in resources."); + background = ImageIO.read(is); + }else if(PreferencesDialog.getCachedValue(PreferencesDialog. + KEY_BACKGROUND_IMAGE, "") != null){ + String path = PreferencesDialog.getCachedValue(PreferencesDialog. + KEY_BATTLEFIELD_IMAGE, ""); + if(path != null){ + background = ImageIO.read(new File(path)); + }else{ + InputStream is = this.getClass().getResourceAsStream(filename); + if (is == null) + throw new FileNotFoundException("Couldn't find " + filename + " in resources."); + background = ImageIO.read(is); + } + } + + if (background == null) + throw new FileNotFoundException("Couldn't find " + filename + " in resources."); + } catch (Exception e) { + log.error(e.getMessage(), e); + return null; + } + } + } + } + return new ImagePanel(background, ImagePanel.SCALED); + } + + private void unsetOpaque(JComponent c) { + if (c != null) { + c.setOpaque(false); + } + } +} diff --git a/Mage.Client/src/main/resources/background.png b/Mage.Client/src/main/resources/background.png new file mode 100644 index 00000000000..01acc151f2c Binary files /dev/null and b/Mage.Client/src/main/resources/background.png differ diff --git a/Mage.Client/src/main/resources/dk_gray.jpg b/Mage.Client/src/main/resources/dk_gray.jpg new file mode 100644 index 00000000000..2e0776d6068 Binary files /dev/null and b/Mage.Client/src/main/resources/dk_gray.jpg differ diff --git a/Mage.Client/src/main/resources/dragon.png b/Mage.Client/src/main/resources/dragon.png new file mode 100644 index 00000000000..634f56c21c8 Binary files /dev/null and b/Mage.Client/src/main/resources/dragon.png differ diff --git a/Mage.Client/src/main/resources/green.jpg b/Mage.Client/src/main/resources/green.jpg new file mode 100644 index 00000000000..f5705253297 Binary files /dev/null and b/Mage.Client/src/main/resources/green.jpg differ diff --git a/Mage.Plugins/Mage.Theme.Plugin/pom.xml b/Mage.Plugins/Mage.Theme.Plugin/pom.xml index 967df3d3d43..b94a79649fe 100644 --- a/Mage.Plugins/Mage.Theme.Plugin/pom.xml +++ b/Mage.Plugins/Mage.Theme.Plugin/pom.xml @@ -32,6 +32,11 @@ 1.2.9 provided + + ${project.groupId} + mage-client + 1.0.3 + diff --git a/Mage.Plugins/Mage.Theme.Plugin/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java b/Mage.Plugins/Mage.Theme.Plugin/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java index 3fecc7dee55..f2a10884a10 100644 --- a/Mage.Plugins/Mage.Theme.Plugin/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java +++ b/Mage.Plugins/Mage.Theme.Plugin/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java @@ -2,6 +2,7 @@ package org.mage.plugins.theme; import mage.components.ImagePanel; import mage.interfaces.plugin.ThemePlugin; +import mage.client.dialog.PreferencesDialog; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.events.Init; import net.xeoh.plugins.base.annotations.events.PluginLoaded; @@ -13,7 +14,7 @@ import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; -import java.io.FileNotFoundException; +import java.io.*; import java.io.InputStream; import java.util.Map; @@ -53,11 +54,33 @@ public class ThemePluginImpl implements ThemePlugin { } if(flist.getItemCount() == 0) return false; return true; - } + } + public void applyInGame(Map ui) { - String filename; BufferedImage background; - try { + try { + + if(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE_DEFAULT, + "true").equals("true")){ + + background = loadbuffer_default(); + + }else if(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE_RANDOM, + "true").equals("true")){ + + background = loadbuffer_random(); + + }else if(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE, "") != null){ + + background = loadbuffer_selected(); + + }else{ + background = loadbuffer_default(); + } + + + + /* if(loadimages()){ int it = (int)Math.abs(Math.random()*(flist.getItemCount())); filename = BackgroundDir + flist.getItem(it); @@ -69,9 +92,9 @@ public class ThemePluginImpl implements ThemePlugin { throw new FileNotFoundException("Couldn't find " + filename + " in resources."); background = ImageIO.read(is); } - + */ if (background == null) { - throw new FileNotFoundException("Couldn't find " + filename + " in resources."); + throw new FileNotFoundException("Couldn't find background file in resources."); } if (ui.containsKey("gamePanel") && ui.containsKey("jLayeredPane")) { @@ -95,6 +118,37 @@ public class ThemePluginImpl implements ThemePlugin { return; } } + + + private BufferedImage loadbuffer_default() throws IOException{ + String filename = "/dragon.png"; + BufferedImage res; + InputStream is = this.getClass().getResourceAsStream(filename); + res = ImageIO.read(is); + return res; + } + + private BufferedImage loadbuffer_random() throws IOException{ + BufferedImage res; + if(loadimages()){ + int it = (int)Math.abs(Math.random()*(flist.getItemCount())); + String filename = BackgroundDir + flist.getItem(it); + res = ImageIO.read(new File(filename)); + return res; + } + return null; + } + + private BufferedImage loadbuffer_selected() throws IOException{ + BufferedImage res; + String path = PreferencesDialog.getCachedValue(PreferencesDialog. + KEY_BATTLEFIELD_IMAGE, ""); + if(path != null){ + res = ImageIO.read(new File(path)); + return res; + } + return null; + } public JComponent updateTable(Map ui) { @@ -116,13 +170,26 @@ public class ThemePluginImpl implements ThemePlugin { if (background == null) { String filename = "/background.png"; try { - InputStream is = this.getClass().getResourceAsStream(filename); - - if (is == null) + if(PreferencesDialog.getCachedValue(PreferencesDialog. + KEY_BACKGROUND_IMAGE_DEFAULT, "true").equals("true")){ + InputStream is = this.getClass().getResourceAsStream(filename); + if (is == null) throw new FileNotFoundException("Couldn't find " + filename + " in resources."); - - background = ImageIO.read(is); - + background = ImageIO.read(is); + }else if(PreferencesDialog.getCachedValue(PreferencesDialog. + KEY_BACKGROUND_IMAGE, "") != null){ + String path = PreferencesDialog.getCachedValue(PreferencesDialog. + KEY_BATTLEFIELD_IMAGE, ""); + if(path != null){ + background = ImageIO.read(new File(path)); + }else{ + InputStream is = this.getClass().getResourceAsStream(filename); + if (is == null) + throw new FileNotFoundException("Couldn't find " + filename + " in resources."); + background = ImageIO.read(is); + } + } + if (background == null) throw new FileNotFoundException("Couldn't find " + filename + " in resources."); } catch (Exception e) {